Exemplo n.º 1
0
        public TiffIFD(ref byte[] content, uint adressOffset, bool ISBigEndian)
        {
            uint ifdEnd;

            if (ISBigEndian)
            {
                tagCount      = BitConverter.ToUInt16(new byte[] { content[adressOffset + 1], content[adressOffset] }, 0);
                ifdEnd        = adressOffset + (uint)(tagCount * 12 + 6);
                NextIFDOffset = BitConverter.ToUInt32(new byte[] { content[ifdEnd - 1], content[ifdEnd - 2], content[ifdEnd - 3], content[ifdEnd - 4] }, 0);
            }
            else
            {
                tagCount      = BitConverter.ToUInt16(new byte[] { content[adressOffset], content[adressOffset + 1] }, 0);
                ifdEnd        = adressOffset + (uint)(tagCount * 12 + 6);
                NextIFDOffset = BitConverter.ToUInt32(new byte[] { content[ifdEnd - 4], content[ifdEnd - 3], content[ifdEnd - 2], content[ifdEnd - 1] }, 0);
            }
            tiffTags = new TiffTag[tagCount];


            for (int miind = 0; miind < tagCount; miind++)
            {
                byte[] bArray = new byte[12];
                tiffTags[miind] = new TiffTag(ref content, (uint)(adressOffset + 2 + miind * 12), ISBigEndian);
            }
            var tIFD = (from t in tiffTags where t.TagID == 330 select t).FirstOrDefault();

            HasSubIFD = tIFD != null && tIFD.TagID == 330;
            if (HasSubIFD)
            {
                SubIFDS = new TiffIFD[tIFD.DataCount];
            }
        }
Exemplo n.º 2
0
        public static object getValue(TiffTag tag, ref byte[] binput, bool isBigEndian)
        {
            object objReturn = null;

            switch (tag.DataType)
            {
            case 1:
                if (tag.DataCount * sizeof(byte) <= 4)
                {
                    objReturn = (object)BitConverter.GetBytes(tag.DataOffset);
                }
                else
                {
                    objReturn = getUByte(tag.DataOffset, binput);
                }
                break;

            case 2:
                objReturn = GetString(tag.DataCount, tag.DataOffset, binput, isBigEndian);
                break;

            case 3:
                if (tag.DataCount * sizeof(ushort) <= 4)
                {
                    byte[] bs = BitConverter.GetBytes(tag.DataOffset);
                    if (tag.DataCount == 1)
                    {
                        objReturn = getUShort(0, bs, isBigEndian);
                    }
                    else
                    {
                        ushort[] us = new ushort[2];
                        us[0]     = getUShort(0, bs, isBigEndian);
                        us[1]     = getUShort(1, bs, isBigEndian);
                        objReturn = us;
                    }
                }
                else
                {
                    List <ushort> lstUS = new List <ushort>();
                    for (uint miind = 0; miind < tag.DataCount; miind++)
                    {
                        lstUS.Add(getUShort(tag.DataOffset + miind * sizeof(ushort), binput, isBigEndian));
                    }
                    objReturn = lstUS.ToArray();
                }
                break;

            case 4:
                if (tag.DataCount * sizeof(uint) <= 4)
                {
                    byte[] bs = BitConverter.GetBytes(tag.DataOffset);
                    objReturn = getUInt(0, bs, isBigEndian);
                }
                else
                {
                    List <uint> lstui = new List <uint>();
                    for (uint miind = 0; miind < tag.DataCount; miind++)
                    {
                        lstui.Add(getUInt(tag.DataOffset + miind * sizeof(uint), binput, isBigEndian));
                    }
                    objReturn = lstui.ToArray();
                }
                break;

            case 5:
            {
                List <float> lstul = new List <float>();
                for (uint miind = 0; miind < tag.DataCount; miind++)
                {
                    lstul.Add(getRational(tag.DataOffset + miind * sizeof(long), binput, isBigEndian));
                }
                objReturn = lstul.ToArray();
            }
            break;

            case 6:
                if (tag.DataCount * sizeof(byte) <= 4)
                {
                    objReturn = (object)BitConverter.GetBytes(tag.DataOffset);
                }
                else
                {
                    objReturn = getByte(tag.DataOffset, binput);
                }
                break;

            case 7:
                objReturn = getUndefined(tag.DataOffset, binput, isBigEndian);
                break;

            case 8:
                if (tag.DataCount * sizeof(short) <= 4)
                {
                    byte[] bs = BitConverter.GetBytes(tag.DataOffset);
                    if (tag.DataCount == 1)
                    {
                        objReturn = getShort(0, bs, isBigEndian);
                    }
                    else
                    {
                        short[] us = new short[2];
                        us[0]     = getShort(0, bs, isBigEndian);
                        us[1]     = getShort(1, bs, isBigEndian);
                        objReturn = us;
                    }
                }
                else
                {
                    List <short> lstUS = new List <short>();
                    for (uint miind = 0; miind < tag.DataCount; miind++)
                    {
                        lstUS.Add(getShort(tag.DataOffset + miind * sizeof(ushort), binput, isBigEndian));
                    }
                    objReturn = lstUS.ToArray();
                }
                break;

            case 9:
                if (tag.DataCount * sizeof(int) <= 4)
                {
                    byte[] bs = BitConverter.GetBytes(tag.DataOffset);
                    objReturn = getInt(0, bs, isBigEndian);
                }
                else
                {
                    List <int> lstui = new List <int>();
                    for (uint miind = 0; miind < tag.DataCount; miind++)
                    {
                        lstui.Add(getInt(tag.DataOffset + miind * sizeof(int), binput, isBigEndian));
                    }
                    objReturn = lstui.ToArray();
                }
                break;

            case 10:
            {
                List <float> lstul = new List <float>();
                for (uint miind = 0; miind < tag.DataCount; miind++)
                {
                    lstul.Add(getRational(tag.DataOffset + miind * sizeof(long), binput, isBigEndian));
                }
                objReturn = lstul.ToArray();
            }
            break;

            case 11:
            {
                List <float> lstul = new List <float>();
                for (uint miind = 0; miind < tag.DataCount; miind++)
                {
                    lstul.Add(getFloat(tag.DataOffset + miind * sizeof(long), binput, isBigEndian));
                }
                objReturn = lstul.ToArray();
            }
            break;

            case 12:
                List <double> lstdb = new List <double>();
                for (uint miind = 0; miind < tag.DataCount; miind++)
                {
                    lstdb.Add(getDouble(tag.DataOffset + miind * sizeof(double), binput, isBigEndian));
                }
                objReturn = lstdb.ToArray();
                break;
            }
            return(objReturn);
        }