/**
         * Rebuild a font subset.
         */
        protected override void BuildSubset(Bytes.Buffer ttfSubset, string tag, Dictionary <int, int> gidToCid)
        {
            // build CID2GIDMap, because the content stream has been written with the old GIDs
            Dictionary <int, int> cidToGid = new Dictionary <int, int>(gidToCid.Count);

            foreach (var entry in gidToCid)
            {
                //(newGID, oldGID)->
                cidToGid[entry.Value] = entry.Key;
            }

            // build unicode mapping before subsetting as the subsetted font won't have a cmap
            BuildToUnicodeCMap(gidToCid);
            // build vertical metrics before subsetting as the subsetted font won't have vhea, vmtx
            if (vertical)
            {
                BuildVerticalMetrics(cidToGid);
            }
            // rebuild the relevant part of the font
            BuildFontFile2(ttfSubset);
            AddNameTag(tag);
            BuildWidths(cidToGid);
            BuildCIDToGIDMap(cidToGid);
            BuildCIDSet(cidToGid);
        }
Exemplo n.º 2
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Value = System.Text.Encoding.ASCII.GetString(buffer.ReadBytes((int)Table.ElementSize - 8));
 }
Exemplo n.º 3
0
        public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            var jbig2Image = new Jbig2Image();

            var chunks = new List <ImageChunk>();

            if (parameters is PdfDictionary parametersDict)
            {
                var globalsStream = parametersDict.Resolve(PdfName.JBIG2Globals);
                if (globalsStream is PdfStream pdfStream)
                {
                    var globals = pdfStream.ExtractBody(true).GetBuffer();
                    chunks.Add(new ImageChunk(data: globals, start: 0, end: globals.Length));
                }
            }
            var buffer = data.GetBuffer();

            chunks.Add(new ImageChunk(data: buffer, start: 0, end: buffer.Length));
            var imageData  = jbig2Image.ParseChunks(chunks);
            var dataLength = imageData.Length;

            // JBIG2 had black as 1 and white as 0, inverting the colors
            for (var i = 0; i < dataLength; i++)
            {
                imageData[i] ^= 0xff;
            }
            return(imageData);
        }
Exemplo n.º 4
0
 internal void Load(Bytes.Buffer buffer)
 {
     SettingId = (ICCDeviceSettingsIds)buffer.ReadUnsignedInt();
     Size      = buffer.ReadUnsignedInt();
     Count     = buffer.ReadUnsignedInt();
     Values    = new ICCDeviceSettingValue[Count];
     for (int i = 0; i < Count; i++)
     {
         var settingValue = (ICCDeviceSettingValue)null;
         if (SettingId == ICCDeviceSettingsIds.Resolution)
         {
             settingValue = new ICCDeviceSettingResolutiuon();
         }
         if (SettingId == ICCDeviceSettingsIds.MediaType)
         {
             settingValue = new ICCDeviceSettingMediaType();
         }
         if (SettingId == ICCDeviceSettingsIds.Halftone)
         {
             settingValue = new ICCDeviceSettingHalftone();
         }
         settingValue.Load(buffer);
         Values[i] = settingValue;
     }
 }
Exemplo n.º 5
0
        /**
         * Constructs a new Type1Font object from a .pfb stream.
         *
         * @param pfbStream .pfb input stream, including headers
         * @return a type1 font
         *
         * @throws IOException if something went wrong
         */
        public static Type1Font CreateWithPFB(Bytes.Buffer pfbStream)
        {
            PfbParser   pfb    = new PfbParser(pfbStream);
            Type1Parser parser = new Type1Parser();

            return(parser.Parse(pfb.GetSegment1().ToArray(), pfb.GetSegment2().ToArray()));
        }
Exemplo n.º 6
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Value.Load(buffer);
 }
Exemplo n.º 7
0
        public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            // get decode parameters
            PdfDictionary decodeParms    = parameters as PdfDictionary;
            var           ccittFaxParams = new CCITTFaxParams(
                K: decodeParms.GetInt(PdfName.K),
                endOfLine: decodeParms.GetBool(PdfName.EndOfLine),
                encodedByteAlign: decodeParms.GetBool(PdfName.EncodedByteAlign),
                columns: decodeParms.GetInt(PdfName.Columns),
                rows: decodeParms.GetInt(PdfName.Rows),
                endOfBlock: decodeParms.GetBool(PdfName.EndOfBlock),
                blackIs1: decodeParms.GetBool(PdfName.BlackIs1)
                );
            var decoder = new CCITTFaxDecoder(data, ccittFaxParams);

            using (var output = new Bytes.Buffer())
            {
                var currentByte = 0;
                while ((currentByte = decoder.ReadNextChar()) > -1)
                {
                    output.Append(FiltersExtension.ToByte(currentByte));
                }
                return(output.GetBuffer());
            }
        }
        private void BuildToUnicodeCMap(Dictionary <int, int> newGIDToOldCID)
        {
            ToUnicodeWriter toUniWriter   = new ToUnicodeWriter();
            bool            hasSurrogates = false;

            for (int gid = 1, max = ttf.MaximumProfile.NumGlyphs; gid <= max; gid++)
            {
                // optional CID2GIDMap for subsetting
                int cid;
                if (newGIDToOldCID != null)
                {
                    if (!newGIDToOldCID.TryGetValue(gid, out cid))
                    {
                        continue;
                    }
                }
                else
                {
                    cid = gid;
                }

                // skip composite glyph components that have no code point
                List <int> codes = cmapLookup.GetCharCodes(cid); // old GID -> Unicode
                if (codes != null)
                {
                    // use the first entry even for ambiguous mappings
                    int codePoint = codes[0];
                    if (codePoint > 0xFFFF)
                    {
                        hasSurrogates = true;
                    }
                    toUniWriter.Add(cid, new string(new char[] { (char)codePoint }, 0, 1));
                }
            }

            using (var output = new MemoryStream())
            {
                toUniWriter.WriteTo(output);
                var cMapStream = new Bytes.Buffer(output.ToArray());

                var header = new PdfDictionary()
                {
                    { PdfName.Length, PdfInteger.Get(cMapStream.Length) }
                };
                PdfStream stream = new PdfStream(header, cMapStream);

                // surrogate code points, requires PDF 1.5
                if (hasSurrogates)
                {
                    var version = document.Version;
                    if (version.GetFloat() < 1.5)
                    {
                        document.Version = new Version(1, 5);
                    }
                }

                dict[PdfName.ToUnicode] = document.File.Register(stream);
            }
        }
Exemplo n.º 9
0
        public override void Load(Bytes.Buffer buffer)
        {
            buffer.Seek(Table.Offset);
            buffer.ReadUnsignedInt();
            buffer.ReadUnsignedInt();
            var count = (int)Table.ElementSize - 8;

            Value = buffer.ReadBytes(count);
        }
Exemplo n.º 10
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Illuminant.Load(buffer);
     Surround.Load(buffer);
     MeasurmentType = buffer.ReadUnsignedInt();
 }
 public void Load(Bytes.Buffer buffer)
 {
     DeviceManufacturer = buffer.ReadUnsignedInt();
     DeviceModel        = buffer.ReadUnsignedInt();
     DeviceAttributes.Load(buffer);
     DeviceTechnology        = buffer.ReadUnsignedInt();
     ManufacturerDescription = System.Text.Encoding.ASCII.GetString(buffer.ReadNullTermitaded());
     ModelDescription        = System.Text.Encoding.ASCII.GetString(buffer.ReadNullTermitaded());
 }
Exemplo n.º 12
0
 public void Load(Bytes.Buffer buffer)
 {
     Year    = buffer.ReadUnsignedShort();
     Month   = buffer.ReadUnsignedShort();
     Day     = buffer.ReadUnsignedShort();
     Hours   = buffer.ReadUnsignedShort();
     Minutes = buffer.ReadUnsignedShort();
     Seconds = buffer.ReadUnsignedShort();
 }
Exemplo n.º 13
0
        private byte[] DoLZWDecode(Bytes.Buffer input, int earlyChange)
        {
            List <byte[]> codeTable = new List <byte[]>();
            int           chunk     = 9;
            var           decoded   = new Bytes.Buffer();
            long          nextCommand;
            long          prevCommand = -1;

            try
            {
                while ((nextCommand = input.ReadBits(chunk)) != EOD)
                {
                    if (nextCommand == CLEAR_TABLE)
                    {
                        chunk       = 9;
                        codeTable   = CreateCodeTable();
                        prevCommand = -1;
                    }
                    else
                    {
                        if (nextCommand < codeTable.Count)
                        {
                            byte[] data      = codeTable[(int)nextCommand];
                            byte   firstByte = data[0];
                            decoded.Write(data);
                            if (prevCommand != -1)
                            {
                                CheckIndexBounds(codeTable, prevCommand, input);
                                data = codeTable[(int)prevCommand];
                                byte[] newData = data.CopyOf(data.Length + 1);
                                newData[data.Length] = firstByte;
                                codeTable.Add(newData);
                            }
                        }
                        else
                        {
                            CheckIndexBounds(codeTable, prevCommand, input);
                            byte[] data    = codeTable[(int)prevCommand];
                            byte[] newData = data.CopyOf(data.Length + 1);
                            newData[data.Length] = data[0];
                            decoded.Write(newData);
                            codeTable.Add(newData);
                        }

                        chunk       = CalculateChunk(codeTable.Count, earlyChange);
                        prevCommand = nextCommand;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("warn: Premature EOF input LZW stream, EOD code missing " + ex);
            }
            return(decoded.GetBuffer());
        }
Exemplo n.º 14
0
 private void CheckIndexBounds(List <byte[]> codeTable, long index, Bytes.Buffer input)
 {
     if (index < 0)
     {
         throw new IOException($"negative array index: {index} near offset {input.Position}");
     }
     if (index >= codeTable.Count)
     {
         throw new IOException($"array index overflow: {index} >= {codeTable.Count} near offset {input.Position}");
     }
 }
Exemplo n.º 15
0
 public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
 {
     using (MemoryStream outputStream = new MemoryStream())
         using (MemoryStream inputStream = new MemoryStream(data.GetBuffer(), 0, (int)data.Length))
             using (DeflateStream inputFilter = new DeflateStream(inputStream, CompressionMode.Decompress))
             {
                 inputStream.Position = 2; // Skips zlib's 2-byte header [RFC 1950] [FIX:0.0.8:JCT].
                 Transform(inputFilter, outputStream);
                 inputFilter.Close();
                 return(DecodePredictor(outputStream.ToArray(), parameters, header));
             }
 }
Exemplo n.º 16
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     VendorSpecificFlag = buffer.ReadUnsignedInt();
     Count = buffer.ReadUnsignedInt();
     Prefix = System.Text.Encoding.ASCII.GetString(buffer.ReadNullTermitaded());
     Suffix = System.Text.Encoding.ASCII.GetString(buffer.ReadNullTermitaded());
     FirstColor = System.Text.Encoding.ASCII.GetString(buffer.ReadNullTermitaded());
     //....color coordinates. Color space of data
 }
Exemplo n.º 17
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     DataFlag  = buffer.ReadUnsignedInt();
     ByteValue = new byte[Table.ElementSize - 12];
     if (DataFlag == 0x00000000)
     {
         StringValue = System.Text.Encoding.ASCII.GetString(ByteValue);
     }
 }
Exemplo n.º 18
0
 internal void Load(Bytes.Buffer buffer)
 {
     Size      = buffer.ReadUnsignedInt();
     Count     = buffer.ReadUnsignedInt();
     Setttings = new ICCDeviceSetting[Count];
     for (int i = 0; i < Count; i++)
     {
         var setting = new ICCDeviceSetting();
         setting.Load(buffer);
         Setttings[i] = setting;
     }
 }
Exemplo n.º 19
0
        public static ICCProfile Load(byte[] data)
        {
            var profile = new ICCProfile();
            var header  = new ICCHeader();
            var buffer  = new Bytes.Buffer(data);

            header.ProfileSize                  = buffer.ReadUnsignedInt();
            header.CMMTypeSignature             = buffer.ReadUnsignedInt();
            header.ProfileVersionNumber.Major   = (byte)buffer.ReadByte();
            header.ProfileVersionNumber.Minor   = (byte)buffer.ReadByte();
            header.ProfileVersionNumber.Reserv1 = (byte)buffer.ReadByte();
            header.ProfileVersionNumber.Reserv2 = (byte)buffer.ReadByte();
            header.ProfileDeviceClassSignature  = (ICCProfileDeviceSignatures)buffer.ReadUnsignedInt();
            header.ColorSpaceOfData             = (ICCColorSpaceSignatures)buffer.ReadUnsignedInt();
            header.ProfileConnectionSpace       = (ICCColorSpaceSignatures)buffer.ReadUnsignedInt();
            header.DateCreated.Load(buffer);
            header.acsp = buffer.ReadUnsignedInt();
            header.PrimaryPlatformSignature = (ICCPrimaryPlatformSignatures)buffer.ReadUnsignedInt();
            header.Flags = (ICCProfileFlags)buffer.ReadUnsignedInt();
            header.DeviceManufacturer = buffer.ReadUnsignedInt();
            header.DeviceModel        = buffer.ReadUnsignedInt();
            header.DeviceAttributes.Load(buffer);
            header.RenderingIntent.Intents  = buffer.ReadUnsignedShort();
            header.RenderingIntent.Reserved = buffer.ReadUnsignedShort();
            header.XYZ.Load(buffer);
            header.ProfileCreatorSignature = buffer.ReadUnsignedInt();
            header.FutureUse = new byte[44];
            buffer.Read(header.FutureUse);
            profile.Header = header;
            var tagCount = buffer.ReadUnsignedInt();

            for (int i = 0; i < tagCount; i++)
            {
                var tag = new ICCTagTable();
                tag.Signature               = (ICCTagTypes)buffer.ReadUnsignedInt();
                tag.Offset                  = buffer.ReadUnsignedInt();
                tag.ElementSize             = buffer.ReadUnsignedInt();
                profile.Tags[tag.Signature] = tag;
            }
            foreach (var tagTable in profile.Tags.Values)
            {
                buffer.Seek(tagTable.Offset);
                var key = buffer.ReadUnsignedInt();
                if (Types.TryGetValue(key, out var type))
                {
                    tagTable.Tag         = (ICCTag)Activator.CreateInstance(type, tagTable);
                    tagTable.Tag.Profile = profile;
                    tagTable.Tag.Load(buffer);
                }
            }
            return(profile);
        }
Exemplo n.º 20
0
        public override byte[] Encode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            byte[] decodedBlock = new byte[4];
            byte[] encodedBlock = new byte[5];

            StringBuilder buffer  = new StringBuilder((int)(data.Length * (encodedBlock.Length / decodedBlock.Length)));
            int           linePos = 0;

            if (EnforceMarks)
            {
                AppendString(buffer, PrefixMark, ref linePos);
            }

            int  count = 0;
            uint tuple = 0;

            foreach (byte dataByte in data.GetBuffer())
            {
                if (count >= decodedBlock.Length - 1)
                {
                    tuple |= dataByte;
                    if (tuple == 0)
                    {
                        AppendChar(buffer, 'z', ref linePos);
                    }
                    else
                    {
                        EncodeBlock(encodedBlock, buffer, ref tuple, ref linePos);
                    }
                    tuple = 0;
                    count = 0;
                }
                else
                {
                    tuple |= (uint)(dataByte << (24 - (count * 8)));
                    count++;
                }
            }

            // if we have some bytes left over at the end..
            if (count > 0)
            {
                EncodeBlock(encodedBlock, count + 1, buffer, ref tuple, ref linePos);
            }

            if (EnforceMarks)
            {
                AppendString(buffer, SuffixMark, ref linePos);
            }

            return(ASCIIEncoding.UTF8.GetBytes(buffer.ToString()));
        }
Exemplo n.º 21
0
        public override void Load(Bytes.Buffer buffer)
        {
            buffer.Seek(Table.Offset);
            buffer.ReadUnsignedInt();
            buffer.ReadUnsignedInt();
            var count = (Table.ElementSize - 8) / 4;

            Value = new float[count];
            for (int i = 0; i < count; i++)
            {
                Value[i] = buffer.ReadFixed32();
            }
        }
Exemplo n.º 22
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Flag             = (ICCScreeningFlag)buffer.ReadUnsignedInt();
     NumberOfChannels = buffer.ReadUnsignedInt();
     Channels         = new ICCScreeningChannel[NumberOfChannels];
     for (int i = 0; i < NumberOfChannels; i++)
     {
         Channels[i].Load(buffer);
     }
 }
Exemplo n.º 23
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Count = buffer.ReadUnsignedInt();
     for (int i = 0; i < Count; i++)
     {
         var structure = new ICCProfileDescriptionStructure();
         structure.Load(buffer);
         Structures.Add(structure);
     }
 }
Exemplo n.º 24
0
 internal void Load(Bytes.Buffer buffer)
 {
     PlatformId           = (ICCPrimaryPlatformSignatures)buffer.ReadUnsignedInt();
     Size                 = buffer.ReadUnsignedInt();
     Count                = buffer.ReadUnsignedInt();
     SetttingCombinations = new ICCDeviceSettingsCombination[Count];
     for (int i = 0; i < Count; i++)
     {
         var setting = new ICCDeviceSettingsCombination();
         setting.Load(buffer);
         SetttingCombinations[i] = setting;
     }
 }
Exemplo n.º 25
0
 public override void Load(Bytes.Buffer buffer)
 {
     buffer.Seek(Table.Offset);
     buffer.ReadUnsignedInt();
     buffer.ReadUnsignedInt();
     Count           = buffer.ReadUnsignedInt();
     Description     = System.Text.Encoding.ASCII.GetString(buffer.ReadBytes((int)Count));
     UnicodeCode     = buffer.ReadUnsignedInt();
     UnicodeCount    = buffer.ReadUnsignedInt();
     ScriptcodeCode  = buffer.ReadUnsignedShort();
     ScriptcodeCount = (byte)buffer.ReadByte();
     MacDescription  = System.Text.Encoding.ASCII.GetString(buffer.ReadBytes(67));
 }
Exemplo n.º 26
0
        public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            var imageParams      = header;
            var dictHeight       = ((IPdfNumber)(header[PdfName.Height] ?? header[PdfName.H])).IntValue;
            var dictWidth        = ((IPdfNumber)(header[PdfName.Width] ?? header[PdfName.W])).IntValue;
            var bitsPerComponent = ((IPdfNumber)imageParams[PdfName.BitsPerComponent])?.IntValue ?? 8;
            var flag             = imageParams[PdfName.ImageMask] as PdfBoolean;
            var jpegOptions      = new JpegOptions(decodeTransform: null, colorTransform: null);

            // Checking if values need to be transformed before conversion.
            var decodeObj = imageParams[PdfName.Decode] ?? imageParams[PdfName.D];
            var decodeArr = decodeObj?.Resolve() as PdfArray;

            if (false && decodeArr != null)
            {
                var decode          = decodeArr.Select(p => ((IPdfNumber)p).IntValue).ToArray();
                var decodeArrLength = decodeArr.Count;
                var transform       = new int[decodeArr.Count];
                var transformNeeded = false;
                var maxValue        = (1 << bitsPerComponent) - 1;
                for (var i = 0; i < decodeArrLength; i += 2)
                {
                    transform[i]     = ((decode[i + 1] - decode[i]) * 256) | 0;
                    transform[i + 1] = (decode[i] * maxValue) | 0;
                    if (transform[i] != 256 || transform[i + 1] != 0)
                    {
                        transformNeeded = true;
                    }
                }
                if (transformNeeded)
                {
                    jpegOptions.DecodeTransform = transform;
                }
            }
            // Fetching the 'ColorTransform' entry, if it exists.
            if (parameters is PdfDictionary paramDict)
            {
                var colorTransform = paramDict[PdfName.ColorTransform];
                if (colorTransform is IPdfNumber number)
                {
                    jpegOptions.ColorTransform = number.IntValue;
                }
            }
            var jpegImage = new JpegImage(jpegOptions);

            jpegImage.Parse(data.GetBuffer());
            var buffer = jpegImage.GetData(width: dictWidth, height: dictHeight, forceRGB: false, isSourcePDF: true);

            return(buffer);
        }
Exemplo n.º 27
0
        //BEWARE: codeTable must be local to each method, because there is only
        // one instance of each filter

        public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            PdfDictionary decodeParams = (PdfDictionary)parameters;
            int           earlyChange  = decodeParams?.GetInt(PdfName.EarlyChange, 1) ?? 1;

            if (earlyChange != 0 && earlyChange != 1)
            {
                earlyChange = 1;
            }

            var result = DoLZWDecode(data, earlyChange);

            return(DecodePredictor(result, parameters, header));
        }
Exemplo n.º 28
0
 /**
  * Read the pdf input.
  * @param in    The input.
  * @return Returns the pdf-array.
  * @throws IOException if an IO-error occurs.
  */
 private byte[] ReadPfbInput(Bytes.Buffer input)
 {
     // copy into an array
     using (var output = new MemoryStream())
     {
         byte[] tmpbuf     = new byte[BUFFER_SIZE];
         int    amountRead = -1;
         while ((amountRead = input.Read(tmpbuf)) > 0)
         {
             output.Write(tmpbuf, 0, amountRead);
         }
         return(output.ToArray());
     }
 }
Exemplo n.º 29
0
 public override byte[] Encode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
 {
     using (MemoryStream inputStream = new MemoryStream(data.GetBuffer(), 0, (int)data.Length))
         using (MemoryStream outputStream = new MemoryStream())
             using (DeflateStream outputFilter = new DeflateStream(outputStream, CompressionMode.Compress, true))
             {
                 // Add zlib's 2-byte header [RFC 1950] [FIX:0.0.8:JCT]!
                 outputStream.WriteByte(0x78); // CMF = {CINFO (bits 7-4) = 7; CM (bits 3-0) = 8} = 0x78.
                 outputStream.WriteByte(0xDA); // FLG = {FLEVEL (bits 7-6) = 3; FDICT (bit 5) = 0; FCHECK (bits 4-0) = {31 - ((CMF * 256 + FLG - FCHECK) Mod 31)} = 26} = 0xDA.
                 Transform(inputStream, outputFilter);
                 outputFilter.Close();
                 return(outputStream.ToArray());
             }
 }
Exemplo n.º 30
0
        public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header)
        {
            var imageParams = header;
            //var width = imageParams.Resolve(PdfName.Width) as PdfInteger;
            //var height = imageParams.Resolve(PdfName.Height) as PdfInteger;
            var bpp      = imageParams[PdfName.BitsPerComponent] as PdfInteger;
            var flag     = imageParams[PdfName.ImageMask] as PdfBoolean;
            var jpxImage = new JpxImage();

            jpxImage.Parse(data.GetBuffer());

            var width           = jpxImage.width;
            var height          = jpxImage.height;
            var componentsCount = jpxImage.componentsCount;
            var tileCount       = jpxImage.tiles.Count;
            var buffer          = (byte[])null;

            if (tileCount == 1)
            {
                buffer = jpxImage.tiles[0].items;
            }
            else
            {
                buffer = new byte[width * height * componentsCount];

                for (var k = 0; k < tileCount; k++)
                {
                    var tileComponents = jpxImage.tiles[k];
                    var tileWidth      = tileComponents.Width;
                    var tileHeight     = tileComponents.Height;
                    var tileLeft       = tileComponents.Left;
                    var tileTop        = tileComponents.Top;

                    var src          = tileComponents.items;
                    var srcPosition  = 0;
                    var dataPosition = (width * tileTop + tileLeft) * componentsCount;
                    var imgRowSize   = width * componentsCount;
                    var tileRowSize  = tileWidth * componentsCount;

                    for (var j = 0; j < tileHeight; j++)
                    {
                        var rowBytes = src.SubArray(srcPosition, srcPosition + tileRowSize);
                        buffer.Set(rowBytes, dataPosition);
                        srcPosition  += tileRowSize;
                        dataPosition += imgRowSize;
                    }
                }
            }
            return(buffer);
        }