예제 #1
0
 public static void Unpack8GrayPix(Pix2x8 pix, out byte p0, out byte p1, out byte p2, out byte p3, out byte p4, out byte p5, out byte p6, out byte p7)
 {
     p7 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x0100) >> 7) | ((pix.Value & 0x01) >> 0)));
     p6 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x0200) >> 8) | ((pix.Value & 0x02) >> 1)));
     p5 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x0400) >> 9) | ((pix.Value & 0x04) >> 2)));
     p4 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x0800) >> 10) | ((pix.Value & 0x08) >> 3)));
     p3 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x1000) >> 11) | ((pix.Value & 0x10) >> 4)));
     p2 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x2000) >> 12) | ((pix.Value & 0x20) >> 5)));
     p1 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x4000) >> 13) | ((pix.Value & 0x40) >> 6)));
     p0 = BadgeImage.PixToSrgbGray((byte)(((pix.Value & 0x8000) >> 14) | ((pix.Value & 0x80) >> 7)));
 }
예제 #2
0
        public static void DitherImage(byte[] intermediateImage, int stride, int width, int height)
        {
            for (int y = 0, srcIy = 0; y < height; ++y, srcIy += stride)
            {
                for (int x = 0, srcI = srcIy; x < width; ++x, ++srcI)
                {
                    int p = intermediateImage[srcI];

                    int  withError = p; //p > (255 - 32) ? 255 : p + 32;
                    byte rounded   = BadgeImage.PixToSrgbGray(BadgeImage.SrgbGrayToPix((byte)withError));
                    intermediateImage[srcI] = rounded;

                    int newError    = withError - rounded;
                    int scaledError = (newError << 10) / 42;

                    for (int ei = 0; ei < s_StuckiPattern.Length; ++ei)
                    {
                        var e  = s_StuckiPattern[ei];
                        int ex = x + e.Item1;
                        int ey = y + e.Item2;
                        if (ex >= 0 && ey >= 0 && ex < width && ey < height)
                        {
                            int weightedError = (scaledError * e.Item3) >> 10;
                            int diffusedIndex = ey * stride + ex;

                            int newValue = intermediateImage[diffusedIndex] + weightedError;
                            if (newValue < 0)
                            {
                                intermediateImage[diffusedIndex] = 0;
                            }
                            else if (newValue > 255)
                            {
                                intermediateImage[diffusedIndex] = 255;
                            }
                            else
                            {
                                intermediateImage[diffusedIndex] = (byte)newValue;
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public static Color ColorFromPix(byte value)
        {
            byte g = BadgeImage.PixToSrgbGray(value);

            return(Color.FromRgb(g, g, g));
        }