Esempio n. 1
0
 public void Color_CastColorToNetColor()
 {
     var color = new PixColor(100, 150, 200);
     var castColor = (System.Drawing.Color)color;
     Assert.That(castColor.R, Is.EqualTo(color.Red));
     Assert.That(castColor.G, Is.EqualTo(color.Green));
     Assert.That(castColor.B, Is.EqualTo(color.Blue));
     Assert.That(castColor.A, Is.EqualTo(color.Alpha));
 }
Esempio n. 2
0
        private static unsafe void TransferData32(PixData pixData, BitmapData imgData, int alphaMask)
        {
            var imgFormat = imgData.PixelFormat;
            var height    = imgData.Height;
            var width     = imgData.Width;

            for (int y = 0; y < height; y++)
            {
                byte *imgLine = (byte *)imgData.Scan0 + (y * imgData.Stride);
                uint *pixLine = (uint *)pixData.Data + (y * pixData.WordsPerLine);

                for (int x = 0; x < width; x++)
                {
                    var pixVal = PixColor.FromRgba(pixLine[x]);

                    byte *pixelPtr = imgLine + (x << 2);
                    pixelPtr[0] = pixVal.Blue;
                    pixelPtr[1] = pixVal.Green;
                    pixelPtr[2] = pixVal.Red;
                    pixelPtr[3] = (byte)(alphaMask | pixVal.Alpha); // Allow user to include alpha or not
                }
            }
        }
        private void CopyColormap(Bitmap img, Pix pix)
        {
            var imgPalette        = img.Palette;
            var imgPaletteEntries = imgPalette.Entries;
            var pixColormap       = PixColormap.Create(pix.Depth);

            try
            {
                for (int i = 0; i < imgPaletteEntries.Length; i++)
                {
                    PixColor c = new PixColor(imgPaletteEntries[i].R, imgPaletteEntries[i].G, imgPaletteEntries[i].B);
                    if (!pixColormap.AddColor(c))
                    {
                        throw new InvalidOperationException(String.Format("Failed to add colormap entry {0}.", i));
                    }
                }
                pix.Colormap = pixColormap;
            }
            catch (Exception)
            {
                pixColormap.Dispose();
                throw;
            }
        }
Esempio n. 4
0
 public bool IsUsableColor(PixColor color)
 {
     int usable;
     if (Interop.LeptonicaApi.pixcmapUsableColor(handle, color.Red, color.Green, color.Blue, out usable) == 0) {
         return usable == 1;
     } else {
         throw new InvalidOperationException("Failed to detect if color was usable or not.");
     }
 }
Esempio n. 5
0
 public bool AddNewColor(PixColor color, out int index)
 {
     return Interop.LeptonicaApi.pixcmapAddNewColor(handle, color.Red, color.Green, color.Blue, out index) == 0;
 }
Esempio n. 6
0
 public bool AddColor(PixColor color)
 {
     return Interop.LeptonicaApi.pixcmapAddColor(handle, color.Red, color.Green, color.Blue) == 0;
 }
Esempio n. 7
0
 public static SD.Color ToDrawingColor(this PixColor color)
 {
     return(System.Drawing.Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue));
 }