BitMiracle.LibTiff.Classic.FieldValue.ToDoubleArray C# (CSharp) Method

ToDoubleArray() public method

Retrieves value converted to array of double values.

If value is array of double values then it retrieved unaltered.

If value is array of bytes then each 8 bytes are converted to double and added to resulting array. If value contains amount of bytes that can't be divided by 8 without remainder, then null is returned.

If value is array of float values then each element of field value gets converted to double and added to resulting array.

If value is of any other type then null is returned.

public ToDoubleArray ( ) : double[]
return double[]
        public double[] ToDoubleArray()
        {
            if (m_value == null)
                return null;

            Type t = m_value.GetType();
            if (t.IsArray)
            {
                if (m_value is double[])
                    return m_value as double[];
                else if (m_value is float[])
                {
                    float[] temp = m_value as float[];
                    double[] result = new double[temp.Length];
                    for (int i = 0; i < temp.Length; i++)
                        result[i] = (double)temp[i];

                    return result;
                }
                else if (m_value is byte[])
                {
                    byte[] temp = m_value as byte[];
                    if (temp.Length % sizeof(double) != 0)
                        return null;

                    int tempPos = 0;

                    int floatCount = temp.Length / sizeof(double);
                    double[] result = new double[floatCount];

                    for (int i = 0; i < floatCount; i++)
                    {
                        double d = BitConverter.ToDouble(temp, tempPos);
                        result[i] = d;
                        tempPos += sizeof(double);
                    }

                    return result;
                }
            }

            return null;
        }
    }

Usage Example

Exemplo n.º 1
0
        private bool prettyPrintField(Stream fd, TiffTag tag, int value_count, object raw_data)
        {
            FieldValue value = new FieldValue(raw_data);

            short[]  sdata = value.ToShortArray();
            float[]  fdata = value.ToFloatArray();
            double[] ddata = value.ToDoubleArray();

            switch (tag)
            {
            case TiffTag.INKSET:
                if (sdata != null)
                {
                    fprintf(fd, "  Ink Set: ");
                    switch ((InkSet)sdata[0])
                    {
                    case InkSet.CMYK:
                        fprintf(fd, "CMYK\n");
                        break;

                    default:
                        fprintf(fd, "{0} (0x{1:x})\n", sdata[0], sdata[0]);
                        break;
                    }
                    return(true);
                }
                return(false);

            case TiffTag.DOTRANGE:
                if (sdata != null)
                {
                    fprintf(fd, "  Dot Range: {0}-{1}\n", sdata[0], sdata[1]);
                    return(true);
                }
                return(false);

            case TiffTag.WHITEPOINT:
                if (fdata != null)
                {
                    fprintf(fd, "  White Point: {0:G}-{1:G}\n", fdata[0], fdata[1]);
                    return(true);
                }
                return(false);

            case TiffTag.REFERENCEBLACKWHITE:
                if (fdata != null)
                {
                    fprintf(fd, "  Reference Black/White:\n");
                    for (short i = 0; i < 3; i++)
                    {
                        fprintf(fd, "    {0,2:D}: {1,5:G} {2,5:G}\n", i, fdata[2 * i + 0], fdata[2 * i + 1]);
                    }
                    return(true);
                }
                return(false);

            case TiffTag.XMLPACKET:
                string s = raw_data as string;
                if (s != null)
                {
                    fprintf(fd, "  XMLPacket (XMP Metadata):\n");
                    fprintf(fd, s.Substring(0, value_count));
                    fprintf(fd, "\n");
                    return(true);
                }
                return(false);

            case TiffTag.RICHTIFFIPTC:
                // XXX: for some weird reason RichTIFFIPTC tag defined
                // as array of LONG values.
                fprintf(fd, "  RichTIFFIPTC Data: <present>, {0} bytes\n", value_count * 4);
                return(true);

            case TiffTag.PHOTOSHOP:
                fprintf(fd, "  Photoshop Data: <present>, {0} bytes\n", value_count);
                return(true);

            case TiffTag.ICCPROFILE:
                fprintf(fd, "  ICC Profile: <present>, {0} bytes\n", value_count);
                return(true);

            case TiffTag.STONITS:
                if (ddata != null)
                {
                    fprintf(fd, "  Sample to Nits conversion factor: {0:e4}\n", ddata[0]);
                    return(true);
                }
                return(false);
            }

            return(false);
        }
All Usage Examples Of BitMiracle.LibTiff.Classic.FieldValue::ToDoubleArray