Exemplo n.º 1
0
        private void ReadImageFileHeader()
        {
            _reader.Stream.Position = 0;

            short byteOrder = _reader.ReadInt16();

            if (byteOrder == 0x4949)
            {
                _reader.StreamIsLittleEndian = true;
            }
            else if (byteOrder == 0x4d4d)
            {
                _reader.StreamIsLittleEndian = false;
            }
            else
            {
                throw new Exception($"Not a TIFF file: {byteOrder}");
            }

            short meaningOfLife = _reader.ReadInt16();

            if (meaningOfLife == 42)
            {
                _bigTiff = false;
            }
            else if (meaningOfLife == 43)
            {
                _bigTiff = true;
            }
            else
            {
                throw new Exception($"Not a TIFF file. Life: {meaningOfLife}");
            }

            if (_bigTiff)
            {
                if (_reader.ReadUInt16() != 8)
                {
                    throw new Exception("Offset should be size 8 in BigTIFF");
                }
                _reader.ReadUInt16(); // always 0
            }
        }
Exemplo n.º 2
0
        private object ReadFieldValueAsObject(BinaryReader2 reader, FieldType fieldType)
        {
            switch (fieldType)
            {
            case FieldType.Int64:
                return(reader.ReadInt64());

            case FieldType.UInt64:
                return(reader.ReadInt64());

            case FieldType.Int32:
                return(reader.ReadInt32());

            case FieldType.UInt32:
                return(reader.ReadUInt32());

            case FieldType.Int16:
                return(reader.ReadInt16());

            case FieldType.UInt16:
                return(reader.ReadUInt16());

            case FieldType.Byte:
                return(reader.ReadByte());

            case FieldType.SByte:
                return(reader.ReadSByte());

            case FieldType.Float:
                return(reader.ReadSingle());

            case FieldType.Double:
                return(reader.ReadDouble());

            case FieldType.Rational:
                return(new Rational(reader.ReadUInt32(), reader.ReadUInt32()));

            case FieldType.SRational:
                return(new SRational(reader.ReadInt32(), reader.ReadInt32()));
            }
            Console.WriteLine($"Unknown field type {fieldType}");
            return(0);
        }
Exemplo n.º 3
0
        private object[] ReadFieldValuesAsObjects(BinaryReader2 reader, FieldType fieldType, int numValues)
        {
            var array = new object[numValues];

            switch (fieldType)
            {
            case FieldType.Int64:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadInt64();
                }
            }
            break;

            case FieldType.UInt64:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadInt64();
                }
            }
            break;

            case FieldType.Int32:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadInt32();
                }
            }
            break;

            case FieldType.UInt32:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadUInt32();
                }
            }
            break;

            case FieldType.Int16:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadInt16();
                }
            }
            break;

            case FieldType.UInt16:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadUInt16();
                }
            }
            break;

            case FieldType.SByte:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadSByte();
                }
            }
            break;

            case FieldType.Byte:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadByte();
                }
            }
            break;

            case FieldType.Float:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadSingle();
                }
            }
            break;

            case FieldType.Double:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = reader.ReadDouble();
                }
            }
            break;

            case FieldType.Rational:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = new Rational(reader.ReadUInt32(), reader.ReadUInt32());
                }
            }
            break;

            case FieldType.SRational:
            {
                for (int i = 0; i < numValues; i++)
                {
                    array[i] = new SRational(reader.ReadInt32(), reader.ReadInt32());
                }
            }
            break;

            default:
                throw new Exception($"Unknown field type {fieldType}");
            }

            return(array);
        }