コード例 #1
0
        protected override void Populate(Stream stream, int offset, TgaHeaderDirectory directory)
        {
            var reader = new IndexedSeekingReader(stream, isMotorolaByteOrder: false);

            PopulateHeader(reader, directory, out var idLength, out var colormapInfo);

            if (idLength > 0)
            {
                var id = reader.GetBytes(HeaderSize, idLength);
                directory.Set(TgaHeaderDirectory.TagId, id);
            }

            if (colormapInfo.Type > 0)
            {
                var colormapLength = colormapInfo.Length * (Math.Max(colormapInfo.Depth / 3, 8) / 8);
                var colormap       = reader.GetBytes(HeaderSize + idLength, colormapLength);
                directory.Set(TgaHeaderDirectory.TagColormap, colormap);
            }
        }
コード例 #2
0
        protected override void Populate(Stream stream, int offset, TgaDeveloperDirectory directory)
        {
            var reader = new IndexedSeekingReader(stream, isMotorolaByteOrder: false);
            var pos    = stream.Position;
            var tags   = new TgaTagReader().Extract(stream);

            stream.Seek(pos - offset, SeekOrigin.Begin);
            foreach (var tag in tags)
            {
                var bytes = reader.GetBytes(tag.Offset, tag.Size);
                directory.Set(tag.Id, bytes);
            }
        }
コード例 #3
0
        public DirectoryList Extract(Stream inputStream)
        {
            IndexedReader reader         = new IndexedSeekingReader(inputStream);
            var           directory      = new EpsDirectory();
            var           epsDirectories = new List <Directory>()
            {
                directory
            };

            // 0xC5D0D3C6 signifies an EPS Header block which contains 32-bytes of basic information
            // 0x25215053 (%!PS) signifies an EPS File and leads straight into the PostScript

            int startingPosition = (int)inputStream.Position;

            switch (reader.GetInt32(0))
            {
            case unchecked ((int)0xC5D0D3C6):
                reader = reader.WithByteOrder(isMotorolaByteOrder: false);
                int postScriptOffset = reader.GetInt32(4);
                int postScriptLength = reader.GetInt32(8);
                int wmfOffset        = reader.GetInt32(12);
                int wmfSize          = reader.GetInt32(16);
                int tifOffset        = reader.GetInt32(20);
                int tifSize          = reader.GetInt32(24);
                //int checkSum = reader.getInt32(28);

                // Get Tiff/WMF preview data if applicable
                if (tifSize != 0)
                {
                    directory.Set(EpsDirectory.TagTiffPreviewSize, tifSize);
                    directory.Set(EpsDirectory.TagTiffPreviewOffset, tifOffset);
                    // Get Tiff metadata
                    try
                    {
                        ByteArrayReader byteArrayReader = new(reader.GetBytes(tifOffset, tifSize));
                        TiffReader.ProcessTiff(byteArrayReader, new PhotoshopTiffHandler(epsDirectories));
                    }
                    catch (TiffProcessingException ex)
                    {
                        directory.AddError("Unable to process TIFF data: " + ex.Message);
                    }
                }
                else if (wmfSize != 0)
                {
                    directory.Set(EpsDirectory.TagWmfPreviewSize, wmfSize);
                    directory.Set(EpsDirectory.TagWmfPreviewOffset, wmfOffset);
                }

                // TODO avoid allocating byte array here -- read directly from InputStream
                Extract(directory, epsDirectories, new SequentialByteArrayReader(reader.GetBytes(postScriptOffset, postScriptLength)));
                break;

            case 0x25215053:
                inputStream.Position = startingPosition;
                Extract(directory, epsDirectories, new SequentialStreamReader(inputStream));
                break;

            default:
                directory.AddError("File type not supported.");
                break;
            }

            return(epsDirectories);
        }