Esempio n. 1
0
        public EXRPart(EXRVersion version, EXRHeader header, OffsetTable offsets)
        {
            Version = version;
            Header  = header;
            Offsets = offsets;

            if (Version.IsMultiPart)
            {
                Type = header.Type;
            }
            else
            {
                Type = version.IsSinglePartTiled ? PartType.Tiled : PartType.ScanLine;
            }

            DataWindow    = Header.DataWindow;
            FloatChannels = new Dictionary <string, float[]>();
            HalfChannels  = new Dictionary <string, Half[]>();

            foreach (var channel in header.Channels)
            {
                if (channel.Type == PixelType.Float)
                {
                    FloatChannels[channel.Name] = new float[DataWindow.Width * DataWindow.Height];
                }
                else if (channel.Type == PixelType.Half)
                {
                    HalfChannels[channel.Name] = new Half[DataWindow.Width * DataWindow.Height];
                }
                else
                {
                    throw new NotImplementedException("Only 16 and 32 bit floating point EXR images are supported.");
                }
            }
        }
Esempio n. 2
0
        public void Read(IEXRReader reader)
        {
            // first four bytes of an OpenEXR file are always 0x76, 0x2f, 0x31 and 0x01 or 20000630
            var magicNumber = reader.ReadInt32();

            if (magicNumber != 20000630)
            {
                throw new EXRFormatException("Invalid or corrupt EXR layout: First four bytes were not 20000630.");
            }

            var versionValue = reader.ReadInt32();

            Version = new EXRVersion(versionValue);

            Headers = new List <EXRHeader>();
            if (Version.IsMultiPart)
            {
                while (true)
                {
                    var header = new EXRHeader();
                    header.Read(this, reader);
                    if (header.IsEmpty)
                    {
                        break;
                    }
                    Headers.Add(header);
                }
                throw new NotImplementedException("Multi part EXR files are not currently supported");
            }
            else
            {
                if (Version.IsSinglePartTiled)
                {
                    throw new NotImplementedException("Tiled EXR files are not currently supported");
                }

                var header = new EXRHeader();
                header.Read(this, reader);
                Headers.Add(header);
            }

            OffsetTables = new List <OffsetTable>();
            foreach (var header in Headers)
            {
                int offsetTableSize;

                if (Version.IsMultiPart)
                {
                    offsetTableSize = header.ChunkCount;
                }
                else if (Version.IsSinglePartTiled)
                {
                    // TODO: Implement
                    offsetTableSize = 0;
                }
                else
                {
                    var compression   = header.Compression;
                    var dataWindow    = header.DataWindow;
                    var linesPerBlock = GetScanLinesPerBlock(compression);
                    var blockCount    = (int)Math.Ceiling(dataWindow.Height / (double)linesPerBlock);

                    offsetTableSize = blockCount;
                }

                var table = new OffsetTable(offsetTableSize);
                table.Read(reader, offsetTableSize);
                OffsetTables.Add(table);
            }
        }