All pastes #957383 Raw Edit

Something

public text v1 · immutable
#957383 ·published 2008-03-25 22:51 UTC
rendered paste body
Korábban:

        static byte[] div3 = new byte[255 * 3 + 1];

            for (int a = 0; a < 255 * 3 + 1; a++)
            {
                div3[a] = (byte)(a / 3);
            }

És a lényeg, színcsatorna-kiemelés ill. szürkítés:

        public Bitmap eff_extract(Bitmap bm, int channel)
        {
            Bitmap b = new Bitmap(bm);
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int stride = bmData.Stride;
            int color;
            System.IntPtr Scan0 = bmData.Scan0;
            unsafe
            {
                byte* p = (byte*)(void*)Scan0;
                int nOffset = stride - b.Width * 3;
                int nWidth = b.Width * 3;
                for (int y = 0; y < b.Height; y++)
                {
                    for (int x = 0; x < nWidth; x += 3)
                    {
                        if (channel < 3)
                        {
                            color = p[channel];
                        }
                        else
                        {
                            color = div3[p[0] + p[1] + p[2]];
                        }
                        p[0] = (byte)color;
                        p[1] = p[0];
                        p[2] = p[0];
                        p += 3;
                    }
                    p += nOffset;
                }
            }
            b.UnlockBits(bmData);
            return b;
        }