Beispiel #1
0
        public static Pixelmap ConstructFromBitmap(Bitmap bmp, byte[] bitmapData, TangraConfig.ColourChannel channel)
        {
            uint[] pixels = new uint[bmp.Width * bmp.Height];

            byte[] displayBitmapPixels = new byte[bmp.Width * bmp.Height];

            // NOTE: Those 2 for loops are very slow. Need performance improvements
            for (int y = 0; y < bmp.Height; ++y)
            {
                for (int x = 0; x < bmp.Width; ++x)
                {
                    byte val = bitmapData[(x + (bmp.Height - 1 - y) * bmp.Width) * 3];

                    pixels[x + y * bmp.Width] = val;
                    displayBitmapPixels[x + y * bmp.Width] = val;
                }
            }

            return(new Pixelmap(bmp.Width, bmp.Height, 8, pixels, bmp, displayBitmapPixels));
        }
Beispiel #2
0
        public static Pixelmap ConstructFromBitmap(Bitmap bmp, TangraConfig.ColourChannel channel)
        {
            uint[] pixels = new uint[bmp.Width * bmp.Height];
            byte[] displayBitmapPixels = new byte[bmp.Width * bmp.Height];

            // GDI+ still lies to us - the return format is BGR, NOT RGB.
            BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            int stride = bmData.Stride;

            System.IntPtr Scan0 = bmData.Scan0;

            unsafe
            {
                byte *p = (byte *)(void *)Scan0;

                int nOffset = stride - bmp.Width * 3;

                for (int y = 0; y < bmp.Height; ++y)
                {
                    for (int x = 0; x < bmp.Width; ++x)
                    {
                        byte blue  = p[0];
                        byte green = p[1];
                        byte red   = p[2];

                        byte val = GetColourChannelValue(channel, red, green, blue);

                        pixels[x + y * bmp.Width] = val;
                        displayBitmapPixels[x + y * bmp.Width] = val;

                        p += 3;
                    }
                    p += nOffset;
                }
            }

            bmp.UnlockBits(bmData);

            return(new Pixelmap(bmp.Width, bmp.Height, 8, pixels, bmp, displayBitmapPixels));
        }
Beispiel #3
0
        public static byte GetColourChannelValue(TangraConfig.ColourChannel channel, byte red, byte green, byte blue)
        {
            if (channel == TangraConfig.ColourChannel.GrayScale)
            {
                return((byte)(.299 * red + .587 * green + .114 * blue));
            }
            else if (channel == TangraConfig.ColourChannel.Red)
            {
                return(red);
            }
            else if (channel == TangraConfig.ColourChannel.Green)
            {
                return(green);
            }
            else if (channel == TangraConfig.ColourChannel.Blue)
            {
                return(blue);
            }

            throw new ArgumentOutOfRangeException();
        }
Beispiel #4
0
        public static int GetColourByteOffset32bbp(TangraConfig.ColourChannel channel)
        {
            if (channel == TangraConfig.ColourChannel.GrayScale)
            {
                // Special meaning
                return(-1);
            }

            // BGRT
            switch (channel)
            {
            case TangraConfig.ColourChannel.Red:
                return(2);

            case TangraConfig.ColourChannel.Green:
                return(1);

            case TangraConfig.ColourChannel.Blue:
                return(0);
            }

            return(1);
        }