public unsafe void PopulateCharColorData(CharInfo ci, IFontProvider font)
        {
            ColorF charRGB = ColorF.Init;

            for (int ty = 0; ty < LumaTiles.Height; ++ty)
            {
                for (int tx = 0; tx < LumaTiles.Width; ++tx)
                {
                    Size  tileSize;
                    Point tilePos;

                    GetTileInfo(font.CharSizeNoPadding, LumaTiles, tx, ty, out tilePos, out tileSize);
                    // process this single tile of this char.
                    // grab all pixels for this tile and calculate Y component for each
                    ColorF tileRGB = font.GetRegionColor(ci.srcIndex, tilePos, tileSize, LumaTiles, tx, ty);

                    charRGB = charRGB.Add(tileRGB);
                    LCCColorDenorm tileLAB = Colorspace.RGBToLCC(tileRGB);
                    ci.actualValues.DenormalizedValues[GetValueLIndex(tx, ty)] = (float)tileLAB.L;
                    ci.actualValues.NormalizedValues[GetValueLIndex(tx, ty)]   = (float)Colorspace.NormalizeL(ci.actualValues.DenormalizedValues[GetValueLIndex(tx, ty)]);
                }
            }

            if (UseChroma)
            {
                charRGB = charRGB.Div(Utils.Product(LumaTiles));
                LCCColorDenorm charLAB = Colorspace.RGBToLCC(charRGB);
                ci.actualValues.DenormalizedValues[GetValueC1Index()] = (float)charLAB.C1;
                ci.actualValues.DenormalizedValues[GetValueC2Index()] = (float)charLAB.C2;
                ci.actualValues.NormalizedValues[GetValueC1Index()]   = (float)Colorspace.NormalizeC1(ci.actualValues.DenormalizedValues[GetValueC1Index()]);
                ci.actualValues.NormalizedValues[GetValueC2Index()]   = (float)Colorspace.NormalizeC2(ci.actualValues.DenormalizedValues[GetValueC2Index()]);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This function allocates and initializes an incremental-decoder object, which
        /// will output the RGB/A samples specified by '<paramref name="colorspace"/>' into a preallocated
        /// buffer '<paramref name="output_buffer"/>'. The size of this buffer is at least
        /// '<paramref name="output_buffer_size"/>' and the stride (distance in bytes between two scanlines)
        /// is specified by '<paramref name="output_stride"/>'
        /// </summary>
        /// <remarks>
        /// Additionally, <paramref name="output_buffer"/> can be passed NULL in which case the output
        /// buffer will be allocated automatically when the decoding starts. The
        /// '<paramref name="colorspace"/>' is taken into account for allocating this buffer. All other
        /// parameters are ignored.
        /// </remarks>
        /// <exception cref="InvalidProgramException">Unknown error occured.</exception>
        /// <exception cref="NotSupportedException"><paramref name="colorspace"/> is not RGB(A) colorspace</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="colorspace"/> is not a valid value</exception>
        /// <returns><see cref="WebpImageDecoder"/></returns>
        public static WebpImageDecoder CreateDecoderForRGBX(ILibwebp library, Colorspace colorspace, IntPtr output_buffer, UIntPtr output_buffer_size, int output_stride)
        {
            WebpImageDecoder result;

            if (colorspace >= Colorspace.MODE_LAST)
            {
                throw new ArgumentOutOfRangeException(nameof(colorspace));
            }
            if (colorspace == Colorspace.MODE_YUVA || colorspace == Colorspace.MODE_YUV)
            {
                throw new NotSupportedException();
            }
            else
            {
                var ptr = library.WebPINewRGB(colorspace, output_buffer, output_buffer_size, output_stride);
                if (ptr == IntPtr.Zero)
                {
                    throw new Exception();
                }
                else
                {
                    result         = new WebpImageDecoder(library, false);
                    result.decoder = ptr;
                }
            }
            if (result == null)
            {
                throw new InvalidProgramException();
            }
            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the Bytescout.PDF.ColorRGB class.
 /// </summary>
 /// <param name="red" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The red component value.</param>
 /// <param name="green" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The green component value.</param>
 /// <param name="blue" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The blue component value.</param>
 public ColorRGB(byte red, byte green, byte blue)
 {
     _r          = red;
     _g          = green;
     _b          = blue;
     _colorspace = new DeviceRGBColorspace();
 }
Esempio n. 4
0
        /// <summary>
        /// Creates <see cref="JpegImage"/> from file with an arbitrary image
        /// </summary>
        /// <param name="fileName">Path to file with image in
        /// arbitrary format (BMP, Jpeg, GIF, PNG, TIFF, e.t.c)</param>
        //public JpegImage(string fileName)
        //{
        //	if (fileName == null)
        //		throw new ArgumentNullException("fileName");

        //	using (FileStream input = new FileStream(fileName, FileMode.Open))
        //		createFromStream(input);
        //}

        /// <summary>
        /// Creates <see cref="JpegImage"/> from pixels
        /// </summary>
        /// <param name="sampleData">Description of pixels.</param>
        /// <param name="colorspace">Colorspace of image.</param>
        /// <seealso cref="SampleRow"/>
        public JpegImage(SampleRow[] sampleData, Colorspace colorspace)
        {
            if (sampleData == null)
            {
                throw new ArgumentNullException("sampleData");
            }

            if (sampleData.Length == 0)
            {
                throw new ArgumentException("sampleData must be no empty");
            }

            if (colorspace == Colorspace.Unknown)
            {
                throw new ArgumentException("Unknown colorspace");
            }

            m_rows = new List <SampleRow>(sampleData);

            SampleRow firstRow = m_rows[0];

            m_width  = firstRow.Length;
            m_height = m_rows.Count;

            Sample firstSample = firstRow[0];

            m_bitsPerComponent    = firstSample.BitsPerComponent;
            m_componentsPerSample = firstSample.ComponentCount;
            m_colorspace          = colorspace;
        }
Esempio n. 5
0
        /// <summary>
        /// Creates <see cref="JpegImage"/> from pixels
        /// </summary>
        /// <param name="sampleData">Description of pixels.</param>
        /// <param name="colorspace">Colorspace of image.</param>
        /// <seealso cref="SampleRow"/>
        public JpegImage(SampleRow[] sampleData, Colorspace colorspace)
        {
            if (sampleData is null)
            {
                throw new ArgumentNullException(nameof(sampleData));
            }

            if (sampleData.Length == 0)
            {
                throw new ArgumentException("sampleData must be no empty");
            }

            if (colorspace == Colorspace.Unknown)
            {
                throw new ArgumentException("Unknown colorspace");
            }

            m_rows = new List <SampleRow>(sampleData);

            var firstRow = m_rows[0];

            Width  = firstRow.Length;
            Height = m_rows.Count;

            var firstSample = firstRow[0];

            BitsPerComponent    = firstSample.BitsPerComponent;
            ComponentsPerSample = firstSample.ComponentCount;
            Colorspace          = colorspace;
        }
Esempio n. 6
0
 internal RawImage(List <SampleRow> samples, Colorspace colorspace)
 {
     Debug.Assert(samples != null);
     Debug.Assert(samples.Count > 0);
     Debug.Assert(colorspace != Colorspace.Unknown);
     _samples    = samples;
     _colorspace = colorspace;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the Bytescout.PDF.ColorCMYK class.
 /// </summary>
 /// <param name="cyan" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The cyan component value.</param>
 /// <param name="magenta" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The magenta component value.</param>
 /// <param name="yellow" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The yellow component value.</param>
 /// <param name="key" href="http://msdn.microsoft.com/en-us/library/system.byte.aspx">The key component value.</param>
 public ColorCMYK(byte cyan, byte magenta, byte yellow, byte key)
 {
     _c          = cyan;
     _m          = magenta;
     _y          = yellow;
     _k          = key;
     _colorspace = new DeviceCMYKColorspace();
 }
Esempio n. 8
0
 internal override bool WriteChangesForNotStroking(Colorspace newCS, MemoryStream stream, Resources resources)
 {
     if (!(newCS is DeviceGrayColorspace))
     {
         WriteColorSpaceForNotStroking(stream, resources);
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        internal RawImage(List <SampleRow> samples, Colorspace colorspace)
        {
            Debug.Assert(samples is object);
            Debug.Assert(samples.Count > 0);
            Debug.Assert(colorspace != Colorspace.Unknown);

            m_samples  = samples;
            Colorspace = colorspace;
        }
Esempio n. 10
0
        public override void Unequal()
        {
            var cs1 = new Colorspace(Whitepoint.A);
            var cs2 = new Colorspace(Whitepoint.A);
            var cs3 = new Colorspace(Whitepoint.B);

            Assert.IsFalse(cs1 != cs2);
            Assert.IsTrue(cs1 != cs3);
        }
Esempio n. 11
0
 Colormap(Name name, float[,] colors, Colorspace colorspace, bool smooth)
 {
     this.ColormapName       = name;
     this.Colors             = colors;
     this.NColors            = colors.GetLength(0);
     this.NComponents        = colors.GetLength(1);
     this.ColormapColorspace = colorspace;
     this.Smooth             = smooth;
 }
Esempio n. 12
0
        internal RawImage(List<SampleRow> samples, Colorspace colorspace)
        {
            Debug.Assert(samples != null);
            Debug.Assert(samples.Count > 0);
            Debug.Assert(colorspace != Colorspace.Unknown);

            m_samples = samples;
            m_colorspace = colorspace;
        }
Esempio n. 13
0
        public override void IsEqualSame()
        {
            var cs1 = new Colorspace();
            var cs2 = new Colorspace();

            bool cmp1 = cs1 == cs2;
            bool cmp2 = cs1.Equals(cs2);

            Assert.IsTrue(cmp1 == cmp2);
        }
        public LCCColorNorm RGBToNormalizedLCC(ColorF c)
        {
            LCCColorDenorm d = Colorspace.RGBToLCC(c);
            LCCColorNorm   ret;

            ret.L  = Colorspace.NormalizeL(d.L);
            ret.C1 = Colorspace.NormalizeC1(d.C1);
            ret.C2 = Colorspace.NormalizeC2(d.C2);
            return(ret);
        }
Esempio n. 15
0
        /// <summary>
        /// Creates a new instance of the <see cref="ConversionData"/> class
        /// </summary>
        /// <param name="inColor">The input color</param>
        /// <param name="outColor">The output color</param>
        public ConversionData(Color inColor, Color outColor)
        {
            if (inColor == null || outColor == null)
            {
                throw new ArgumentNullException();
            }

            Type inColorType  = inColor.GetType();
            Type outColorType = inColor.GetType();

            Colorspace inSpace  = inColor.Space;
            Colorspace outSpace = outColor.Space;

            Type inSpaceType  = inSpace.GetType();
            Type outSpaceType = outSpace.GetType();

            IsCARequired  = !inSpace.Equals(outSpace);
            IsDifferentWP = inSpace.ReferenceWhite != outSpace.ReferenceWhite;
            InTransform   = inSpace.GetTransformation(true);
            OutTransform  = outSpace.GetTransformation(false);

            _InSpaceData  = inSpace.GetData(true);
            _OutSpaceData = outSpace.GetData(false);
            if (_InSpaceData != null)
            {
                InSpaceData = _InSpaceData.DataPointer;
            }
            if (_OutSpaceData != null)
            {
                OutSpaceData = _OutSpaceData.DataPointer;
            }

            ColVars1Handle = GCHandle.Alloc(ColVars1Array, GCHandleType.Pinned);
            ColVars2Handle = GCHandle.Alloc(ColVars2Array, GCHandleType.Pinned);
            VarsHandle     = GCHandle.Alloc(VarsArray, GCHandleType.Pinned);
            InWPHandle     = GCHandle.Alloc(inSpace.ReferenceWhite.XYZ, GCHandleType.Pinned);
            OutWPHandle    = GCHandle.Alloc(outSpace.ReferenceWhite.XYZ, GCHandleType.Pinned);
            InWPCrHandle   = GCHandle.Alloc(inSpace.ReferenceWhite.Cxy, GCHandleType.Pinned);
            OutWPCrHandle  = GCHandle.Alloc(outSpace.ReferenceWhite.Cxy, GCHandleType.Pinned);

            ColVars1 = (double *)ColVars1Handle.AddrOfPinnedObject();
            ColVars2 = (double *)ColVars2Handle.AddrOfPinnedObject();
            Vars     = (double *)VarsHandle.AddrOfPinnedObject();
            InWP     = (double *)InWPHandle.AddrOfPinnedObject();
            OutWP    = (double *)OutWPHandle.AddrOfPinnedObject();
            InWPCr   = (double *)InWPCrHandle.AddrOfPinnedObject();
            OutWPCr  = (double *)OutWPCrHandle.AddrOfPinnedObject();

            AdditionalDataHandle = new List <ArrayData>();
        }
Esempio n. 16
0
        private static JpegImage createImageFromPixels()
        {
            byte[] rowData = new byte[96];
            for (int i = 0; i < rowData.Length; ++i)
            {
                if (i < 5)
                {
                    rowData[i] = 0xE4;
                }
                else if (i < 15)
                {
                    rowData[i] = 0xAB;
                }
                else if (i < 35)
                {
                    rowData[i] = 0x00;
                }
                else if (i < 55)
                {
                    rowData[i] = 0x65;
                }
                else
                {
                    rowData[i] = 0xF0;
                }
            }

            const int        width               = 24;
            const int        height              = 25;
            const byte       bitsPerComponent    = 8;
            const byte       componentsPerSample = 4;
            const Colorspace colorspace          = Colorspace.CMYK;

            SampleRow row = new SampleRow(rowData, width, bitsPerComponent, componentsPerSample);

            SampleRow[] rows = new SampleRow[height];
            for (int i = 0; i < rows.Length; ++i)
            {
                rows[i] = row;
            }

            JpegImage jpegImage = new JpegImage(rows, colorspace);

            Assert.AreEqual(jpegImage.Width, width);
            Assert.AreEqual(jpegImage.Height, rows.Length);
            Assert.AreEqual(jpegImage.BitsPerComponent, bitsPerComponent);
            Assert.AreEqual(jpegImage.ComponentsPerSample, componentsPerSample);
            Assert.AreEqual(jpegImage.Colorspace, colorspace);
            return(jpegImage);
        }
        public ValueArray Denormalize(ValueArray va)
        {
            ValueArray ret = ValueArray.Init(this.DimensionCount);

            if (UseChroma)
            {
                ret[GetValueC1Index()] = (float)Colorspace.DenormalizeC1(va[GetValueC1Index()]);
                ret[GetValueC2Index()] = (float)Colorspace.DenormalizeC2(va[GetValueC2Index()]);
            }
            for (int i = 0; i < LumaComponentCount; ++i)
            {
                ret[i] = (float)Colorspace.DenormalizeL(va[i]);
            }
            return(ret);
        }
        public unsafe void PopulateCharColorData(CharInfo ci, IFontProvider font)
        {
            ColorF charRGB = ColorF.Init;

            ColorF[] lumaRGB     = new ColorF[LumaComponentCount];
            int[]    pixelCounts = new int[LumaComponentCount];
            for (int i = 0; i < LumaComponentCount; ++i)
            {
                lumaRGB[i]     = ColorF.Init;
                pixelCounts[i] = 0;
            }

            for (int py = 0; py < font.CharSizeNoPadding.Height; ++py)
            {
                for (int px = 0; px < font.CharSizeNoPadding.Width; ++px)
                {
                    ColorF pc = font.GetPixel(ci.srcIndex, px, py);
                    charRGB = charRGB.Add(pc);
                    int lumaIdx = Tessellator.GetLumaTileIndexOfPixelPosInCell(px, py, font.CharSizeNoPadding);
                    lumaRGB[lumaIdx] = lumaRGB[lumaIdx].Add(pc);
                    pixelCounts[lumaIdx]++;
                }
            }

            for (int i = 0; i < LumaComponentCount; ++i)
            {
                var pc = pixelCounts[i];
                var lc = lumaRGB[i];
                if (pixelCounts[i] < 1)
                {
                    throw new Exception("!!!!!! Your fonts are just too small; i can't sample them properly.");
                }
                lc = lc.Div(pc);
                LCCColorDenorm lccc = Colorspace.RGBToLCC(lc);
                ci.actualValues.DenormalizedValues[i] = (float)lccc.L;
                ci.actualValues.NormalizedValues[i]   = (float)Colorspace.NormalizeL(ci.actualValues.DenormalizedValues[i]);
            }

            if (UseChroma)
            {
                charRGB = charRGB.Div(Utils.Product(font.CharSizeNoPadding));
                LCCColorDenorm charLAB = Colorspace.RGBToLCC(charRGB);
                ci.actualValues.DenormalizedValues[GetValueC1Index()] = (float)charLAB.C1;
                ci.actualValues.DenormalizedValues[GetValueC2Index()] = (float)charLAB.C2;
                ci.actualValues.NormalizedValues[GetValueC1Index()]   = (float)Colorspace.NormalizeC1(ci.actualValues.DenormalizedValues[GetValueC1Index()]);
                ci.actualValues.NormalizedValues[GetValueC2Index()]   = (float)Colorspace.NormalizeC2(ci.actualValues.DenormalizedValues[GetValueC2Index()]);
            }
        }
Esempio n. 19
0
        internal override bool WriteChangesForStroking(Colorspace newCS, MemoryStream stream, Resources resources)
        {
            _name = resources.AddResources(ResourceType.Pattern, _streamDict);
            if (newCS is ColoredTilingPatternColorspace)
            {
                if (!_name.Equals((newCS as ColoredTilingPatternColorspace)._name))
                {
                    newCS.WriteColorSpaceForStroking(stream, resources);
                    return(true);
                }
            }
            else
            {
                newCS.WriteColorSpaceForStroking(stream, resources);
                return(true);
            }

            return(false);
        }
Esempio n. 20
0
        private void processPixelFormat(PixelFormat pixelFormat)
        {
            //See GdiPlusPixelFormats.h for details

            if (pixelFormat == PixelFormat.Format16bppGrayScale)
            {
                m_bitsPerComponent    = 16;
                m_componentsPerSample = 1;
                m_colorspace          = Colorspace.Grayscale;
                return;
            }

            byte formatIndexByte = (byte)((int)pixelFormat & 0x000000FF);
            byte pixelSizeByte   = (byte)((int)pixelFormat & 0x0000FF00);

            if (pixelSizeByte == 32 && formatIndexByte == 15) //PixelFormat32bppCMYK (15 | (32 << 8))
            {
                m_bitsPerComponent    = 8;
                m_componentsPerSample = 4;
                m_colorspace          = Colorspace.CMYK;
                return;
            }

            m_bitsPerComponent    = 8;
            m_componentsPerSample = 3;
            m_colorspace          = Colorspace.RGB;

            if (pixelSizeByte == 16)
            {
                m_bitsPerComponent = 6;
            }
            else if (pixelSizeByte == 24 || pixelSizeByte == 32)
            {
                m_bitsPerComponent = 8;
            }
            else if (pixelSizeByte == 48 || pixelSizeByte == 64)
            {
                m_bitsPerComponent = 16;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Creates <see cref="JpegImage"/> from pixels
        /// </summary>
        /// <param name="sampleData">Description of pixels.</param>
        /// <param name="colorspace">Colorspace of image.</param>
        /// <seealso cref="SampleRow"/>
        public JpegImage(SampleRow[] sampleData, Colorspace colorspace)
        {
            if (sampleData == null)
                throw new ArgumentNullException("sampleData");

            if (sampleData.Length == 0)
                throw new ArgumentException("sampleData must be no empty");

            if (colorspace == Colorspace.Unknown)
                throw new ArgumentException("Unknown colorspace");

            m_rows = new List<SampleRow>(sampleData);

            SampleRow firstRow = m_rows[0];
            m_width = firstRow.Length;
            m_height = m_rows.Count;

            Sample firstSample = firstRow[0];
            m_bitsPerComponent = firstSample.BitsPerComponent;
            m_componentsPerSample = firstSample.ComponentCount;
            m_colorspace = colorspace;
        }
Esempio n. 22
0
        internal override bool WriteChangesForNotStroking(Colorspace newCS, MemoryStream stream, Resources resources)
        {
            PDFArray array = new PDFArray();

            array.AddItem(new PDFName(Name));
            array.AddItem(_dict);
            _name = resources.AddResources(ResourceType.ColorSpace, array);
            if (newCS is ICCBasedColorspace)
            {
                if (!_name.Equals((newCS as ICCBasedColorspace)._name))
                {
                    IPDFPageOperation operation = new ColorSpaceForNonStroking((newCS as ICCBasedColorspace)._name);
                    operation.WriteBytes(stream);
                }
            }
            else
            {
                newCS.WriteColorSpaceForNotStroking(stream, resources);
                return(true);
            }
            return(false);
        }
Esempio n. 23
0
        /// <summary>
        /// An internal function to actually create the pixbuf. This
        /// method also adds it to the cache.
        /// </summary>
        protected virtual Pixbuf CreatePixbuf(
            DrawableState state,
            string cacheKey)
        {
            // Create the image from the disk. If we are exactly the
            // right size, return it immediately.
            Pixbuf image = new Pixbuf(file.FullName);

            if (image.Width == state.Width && image.Height == state.Height)
            {
                return(image);
            }

            // Create a pixbuf of the given size
            Colorspace colorspace    = image.Colorspace;
            bool       hasAlpha      = image.HasAlpha;
            int        bitsPerSample = image.BitsPerSample;
            Pixbuf     p             = new Pixbuf(
                colorspace, hasAlpha, bitsPerSample, state.Width, state.Height);

            // Scale copy it in
            image.Composite(
                p,
                0,
                0,
                state.Width,
                state.Height,
                0,
                0,
                image.Width / state.Width,
                image.Height / state.Height,
                InterpType.Bilinear,
                255);

            // Cache and return
            PixbufCache[cacheKey] = p;
            return(p);
        }
        public int GetMapIndexOfRegion(Bitmap img, int x, int y, Size sz)
        {
            ColorF         rgb  = ColorF.Init;
            LCCColorDenorm lab  = LCCColorDenorm.Init;
            LCCColorNorm   norm = LCCColorNorm.Init;

            float[] vals    = new float[DimensionCount];
            ColorF  charRGB = ColorF.Init;

            for (int ty = LumaTiles.Height - 1; ty >= 0; --ty)
            {
                for (int tx = LumaTiles.Width - 1; tx >= 0; --tx)
                {
                    Point tilePos = GetTileOrigin(sz, LumaTiles, tx, ty);
                    // YES this just gets 1 pixel per char-sized area.
                    rgb = ColorF.From(img.GetPixel(x + tilePos.X, y + tilePos.Y));
                    lab = Colorspace.RGBToLCC(rgb);

                    norm = RGBToNormalizedLCC(rgb);
                    vals[GetValueLIndex(tx, ty)] = (float)norm.L;
                    charRGB = charRGB.Add(rgb);
                }
            }

            if (UseChroma)
            {
                int numTiles = Utils.Product(LumaTiles);
                charRGB = charRGB.Div(numTiles);
                norm    = RGBToNormalizedLCC(charRGB);
                vals[GetValueC1Index()] = (float)norm.C1;
                vals[GetValueC2Index()] = (float)norm.C2;
            }

            int ID = NormalizedValueSetToMapID(vals);

            return(ID);
        }
Esempio n. 25
0
        internal override bool WriteChangesForStroking(Colorspace newCS, MemoryStream stream, Resources resources)
        {
            _name = resources.AddResources(ResourceType.Pattern, _streamDict);
            if (newCS is UncoloredTilingPatternColorspace)
            {
                if (!_name.Equals((newCS as UncoloredTilingPatternColorspace)._name))
                {
                    newCS.WriteColorSpaceForStroking(stream, resources);
                }
                else if (!_color.Equals((newCS as UncoloredTilingPatternColorspace)._color))
                {
                    IPDFPageOperation operation = new ColorForStrokingEx((newCS as UncoloredTilingPatternColorspace)._color.ToArray(), (newCS as UncoloredTilingPatternColorspace)._name);
                    operation.WriteBytes(stream);
                    return(true);
                }
            }
            else
            {
                newCS.WriteColorSpaceForStroking(stream, resources);
                return(true);
            }

            return(false);
        }
Esempio n. 26
0
        private void processPixelFormat(PixelFormat pixelFormat)
        {
            //See GdiPlusPixelFormats.h for details

            if (pixelFormat == PixelFormat.Format16bppGrayScale)
            {
                m_bitsPerComponent = 16;
                m_componentsPerSample = 1;
                m_colorspace = Colorspace.Grayscale;
                return;
            }

            byte formatIndexByte = (byte)((int)pixelFormat & 0x000000FF);
            byte pixelSizeByte = (byte)((int)pixelFormat & 0x0000FF00);

            if (pixelSizeByte == 32 && formatIndexByte == 15) //PixelFormat32bppCMYK (15 | (32 << 8))
            {
                m_bitsPerComponent = 8;
                m_componentsPerSample = 4;
                m_colorspace = Colorspace.CMYK;
                return;
            }

            m_bitsPerComponent = 8;
            m_componentsPerSample = 3;
            m_colorspace = Colorspace.RGB;
            
            if (pixelSizeByte == 16)
                m_bitsPerComponent = 6;
            else if (pixelSizeByte == 24 || pixelSizeByte == 32)
                m_bitsPerComponent = 8;
            else if (pixelSizeByte == 48 || pixelSizeByte == 64)
                m_bitsPerComponent = 16;
        }
Esempio n. 27
0
 public ColorspaceConversion(Colorspace from, Colorspace to)
 {
     this.from = from;
     this.to   = to;
 }
Esempio n. 28
0
        /// <summary>
        /// Retrieve information about a JPEG image without decompressing it.
        /// </summary>
        /// <param name="jpegBuf">A buffer containing a JPEG image.</param>
        /// <param name="width">An output variable that will receive the width (in pixels) of the JPEG image.</param>
        /// <param name="height">An output variable that will receive the height (in pixels) of the JPEG image.</param>
        /// <param name="subsamp">An output variable that will receive the the level of chrominance subsampling used when compressing the JPEG image.</param>
        /// <param name="colorspace">An output variable that will receive one of the JPEG <see cref="Colorspace"/> constants, indicating the colorspace of the JPEG image.</param>
        public void DecompressHeader(byte[] jpegBuf, out int width, out int height, out ChrominanceSubsampling subsamp, out Colorspace colorspace)
        {
            if (jpegBuf == null)
                throw new ArgumentNullException(nameof (jpegBuf));

            Library.tjDecompressHeader3(_handle, jpegBuf, out width, out height, out subsamp, out colorspace);
        }
Esempio n. 29
0
 internal abstract bool WriteChangesForNotStroking(Colorspace newCS, MemoryStream stream, Resources resources);
Esempio n. 30
0
        private static extern int tjDecompressHeader3_64(IntPtr handle,
			byte [] jpegBuf, ulong jpegSize, out int width, out int height,
			out ChrominanceSubsampling jpegSubsamp, out Colorspace jpegColorspace);
Esempio n. 31
0
        /// <summary>Decode webp data into pixel buffer.</summary>
        /// <param name="input_buffer">The pointer to the memory contains the webp data.</param>
        /// <param name="input_buffer_size">The size of the memory contains the webp data.</param>
        /// <param name="output_colorspace">The colorspace (or pixel format) of the output pixel buffer.</param>
        /// <param name="output_buffer">The memory to write the output pixel data.</param>
        /// <param name="output_buffer_size">The size of the memory to write the output pixel data.</param>
        /// <param name="options">The options which will be used to configure the decoder.</param>
        /// <remarks>The memory must be pinned until the decoding operation finishes.</remarks>
        /// <exception cref="WebpDecodeException">Error occured during decoding operation in the native library. Check the <seealso cref="WebpDecodeException.ErrorCode"/> to see the error.</exception>
        public void DecodeRGB(IntPtr input_buffer, UIntPtr input_buffer_size, IntPtr output_buffer, UIntPtr output_buffer_size, Colorspace output_colorspace, DecoderOptions options)
        {
            this.ThrowIfDisposed();
            int bpp;

            switch (output_colorspace)
            {
            case Colorspace.MODE_ARGB:
            case Colorspace.MODE_Argb:
            case Colorspace.MODE_BGRA:
            case Colorspace.MODE_bgrA:
            case Colorspace.MODE_RGBA:
            case Colorspace.MODE_rgbA:
                bpp = 4;
                break;

            case Colorspace.MODE_RGB:
            case Colorspace.MODE_BGR:
                bpp = 3;
                break;

            case Colorspace.MODE_LAST:
                throw new ArgumentException(nameof(output_colorspace));

            default:
                throw new NotSupportedException();
            }

            var           decodeConf = new WebPDecoderConfig();
            VP8StatusCode errorCode;

            // this.library.WebPInitDecoderConfig(ref decodeConf) != 0
            errorCode = this.library.WebPGetFeatures(input_buffer, input_buffer_size, ref decodeConf.input);
            if (errorCode != VP8StatusCode.VP8_STATUS_OK)
            {
                throw new WebpDecodeException(errorCode);
            }
            try
            {
                int width, height;

                var opts = options ?? DecoderOptions.Default;
                opts.ApplyOptions(ref decodeConf);
                decodeConf.output.colorspace         = output_colorspace;
                decodeConf.output.is_external_memory = 1;

                if (decodeConf.options.use_scaling != 0)
                {
                    width  = decodeConf.options.scaled_width;
                    height = decodeConf.options.scaled_height;
                }
                else if (decodeConf.options.use_cropping != 0)
                {
                    width  = decodeConf.options.crop_width;
                    height = decodeConf.options.crop_height;
                }
                else
                {
                    width  = decodeConf.input.width;
                    height = decodeConf.input.height;
                }

                decodeConf.output.width  = width;
                decodeConf.output.height = height;

                decodeConf.output.u.RGBA.rgba = output_buffer;
                decodeConf.output.u.RGBA.size = output_buffer_size;
                if (bpp == 4)
                {
                    decodeConf.output.u.RGBA.stride = width * 4;
                }
                else
                {
                    decodeConf.output.u.RGBA.stride = (width * bpp) + (width % 4);
                }

                errorCode = this.library.WebPDecode(input_buffer, input_buffer_size, ref decodeConf);
                if (errorCode != VP8StatusCode.VP8_STATUS_OK)
                {
                    throw new WebpDecodeException(errorCode);
                }
            }
            finally
            {
                this.library.WebPFreeDecBuffer(ref decodeConf.output);
            }
        }
Esempio n. 32
0
 /// <summary>
 /// This function allocates and initializes an incremental-decoder object, which
 /// will output the RGB/A samples specified by '<paramref name="colorspace"/>' into a preallocated internal buffer.
 /// </summary>
 /// <remarks>
 /// Equivalent to <seealso cref="CreateDecoderForRGBX(Colorspace, IntPtr, UIntPtr, int)"/>, with 'output_buffer' is NULL.
 /// Use <seealso cref="WebpImageDecoder.GetDecodedImage(ref int, out int, out int, out int, out IntPtr)"/> or <seealso cref="WebpImageDecoder.GetDecodedImage(ref int, out int, out int, out int, out ReadOnlySpan{byte})"/>
 /// to obtain the decoded data.
 /// </remarks>
 /// <exception cref="InvalidProgramException">Unknown error occured.</exception>
 /// <exception cref="NotSupportedException"><paramref name="colorspace"/> is not RGB(A) colorspace</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="colorspace"/> is not a valid value</exception>
 /// <returns><see cref="WebpImageDecoder"/></returns>
 public WebpImageDecoder CreateDecoderForRGBX(Colorspace colorspace)
 {
     this.ThrowIfDisposed();
     return(WebpImageDecoder.CreateDecoderForRGBX(this.library, colorspace));
 }
Esempio n. 33
0
 /// <summary>
 /// This function allocates and initializes an incremental-decoder object, which
 /// will output the RGB/A samples specified by '<paramref name="colorspace"/>' into a preallocated
 /// buffer '<paramref name="output_buffer"/>'. The size of this buffer is at least
 /// '<paramref name="output_buffer_size"/>' and the stride (distance in bytes between two scanlines)
 /// is specified by '<paramref name="output_stride"/>'
 /// </summary>
 /// <remarks>
 /// Additionally, <paramref name="output_buffer"/> can be passed NULL in which case the output
 /// buffer will be allocated automatically when the decoding starts. The
 /// '<paramref name="colorspace"/>' is taken into account for allocating this buffer. All other
 /// parameters are ignored.
 /// </remarks>
 /// <exception cref="InvalidProgramException">Unknown error occured.</exception>
 /// <exception cref="NotSupportedException"><paramref name="colorspace"/> is not RGB(A) colorspace</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="colorspace"/> is not a valid value</exception>
 /// <returns><see cref="WebpImageDecoder"/></returns>
 public WebpImageDecoder CreateDecoderForRGBX(Colorspace colorspace, IntPtr output_buffer, UIntPtr output_buffer_size, int output_stride)
 {
     this.ThrowIfDisposed();
     return(WebpImageDecoder.CreateDecoderForRGBX(this.library, colorspace, output_buffer, output_buffer_size, output_stride));
 }
Esempio n. 34
0
        /// <summary>
        /// Retrieve information about a JPEG image without decompressing it.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG decompressor or transformer instance.</param>
        /// <param name="jpegBuf">pointer to a buffer containing a JPEG image.</param>
        /// <param name="width">an integer variable that will receive the width (in pixels) of the JPEG image.</param>
        /// <param name="height">an integer variable that will receive the height (in pixels) of the JPEG image.</param>
        /// <param name="jpegSubsamp">
        /// an integer variable that will receive the
        /// level of chrominance subsampling used when the JPEG image was compressed
        /// (see <see cref="ChrominanceSubsampling"/> .)
        /// </param>
        /// <param name="jpegColorspace">
        /// an integer variable that will receive one
        /// of the JPEG colorspace constants, indicating the colorspace of the JPEG
        /// image (see <see cref="Colorspace"/>.)
        /// </param>
        /// <returns>0 if successful, or -1 if an error occurred (see <see cref="tjGetErrorStr"/>.)</returns>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle,
        ///   const unsigned char* jpegBuf, unsigned long jpegSize, int* width,
        ///   int* height, int* jpegSubsamp, int* jpegColorspace);
        /// </remarks>
        internal static void tjDecompressHeader3(IntPtr handle, byte [] jpegBuf,
		                                          out int width, out int height,
		                                          out ChrominanceSubsampling jpegSubsamp, out Colorspace jpegColorspace)
        {
            int retval;
            if (IsLP64)
                retval = tjDecompressHeader3_64 (handle, jpegBuf, (ulong)jpegBuf.Length, out width, out height, out jpegSubsamp, out jpegColorspace);
            else
                retval = tjDecompressHeader3_32 (handle, jpegBuf, (uint)jpegBuf.Length, out width, out height, out jpegSubsamp, out jpegColorspace);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
Esempio n. 35
0
 public TestColor(double val1, double val2, double val3, Colorspace space)
     : base(space, val1, val2, val3)
 {
 }
Esempio n. 36
0
 public TestColor(Colorspace space)
     : base(space, 0, 0, 0)
 {
 }