コード例 #1
0
        public PageDynamicImaging()
        {
            InitializeComponent();

            EditableImage img = new EditableImage(255, 255);
            for (int i = 0; i < img.Height; ++i)
                for (int j = 0; j < img.Width; ++j)
                    img.SetPixel(i, j, (byte)i, 255, (byte)j, 255);

            BitmapImage bmp = new BitmapImage();
            bmp.SetSource(img.GetStream());
            imgTesting.Source = bmp;
        }
コード例 #2
0
ファイル: BmpDecoder.cs プロジェクト: Titaye/SLExtensions
        private static EditableImage ReadPaletteBmp(byte[] buffer, Color[] palette, BmpInfoHeader header, int bpp)
        {
            int ppb = 8 / bpp;                    // Pixels per byte (bits per pixel)
            int width = (header.Width + ppb - 1) / ppb;
            int alignment = width % 4;          // Rows are aligned on 4 byte boundaries
            int mask = (0xFF >> (8 - bpp));       // Bit mask
            int rowbase;
            int colbase;
            int offset;
            int realRow;
            Color color;

            EditableImage image = new EditableImage(header.Width, header.Height);

            if (alignment != 0)
            {
                alignment = 4 - alignment;                        // Calculate row padding
            }

            for (int row = 0; row < header.Height; row++)
            {
                rowbase = (row * (width + alignment));
                for (int col = 0; col < width; col++)
                {
                    offset = rowbase + col;
                    colbase = col * ppb;
                    realRow = header.Height - row - 1;                  // Reverse row
                    for (int shift = 0; ((shift < ppb) && ((colbase + shift) < header.Width)); shift++)
                    {
                        color = palette[((buffer[offset]) >> (8 - bpp - (shift * bpp))) & mask];
                        image.SetPixel(colbase + shift, realRow, color.R, color.G, color.B, 255);
                    }
                }
            }

            return image;
        }
コード例 #3
0
ファイル: BmpDecoder.cs プロジェクト: Titaye/SLExtensions
        private static EditableImage Read8BitBmp(byte[] buffer, Color[] palette, BmpInfoHeader header)
        {
            int alignment = header.Width % 4;       // Rows are aligned on 4 byte boundaries
            int rowbase = 0;
            int offset;
            int realRow;
            Color color;

            EditableImage image = new EditableImage(header.Width, header.Height);

            if (alignment != 0)
            {
                alignment = 4 - alignment;                        // Calculate row padding
            }

            for (int row = 0; row < header.Height; row++)
            {
                rowbase = (row * (header.Width + alignment));
                for (int col = 0; col < header.Width; col++)
                {
                    offset = rowbase + col;
                    realRow = header.Height - row - 1;          // Reverse row
                    color = palette[buffer[offset]];
                    image.SetPixel(col, realRow, color.R, color.G, color.B, color.A);
                }
            }

            return image;
        }
コード例 #4
0
ファイル: BmpDecoder.cs プロジェクト: Titaye/SLExtensions
        private static EditableImage Read565Bmp(byte[] buffer, BmpInfoHeader header)
        {
            int rowbase = 0;
            int offset;
            int realRow;
            short color;
            byte red;
            byte green;
            byte blue;
            int scaleR = 256 / 32;
            int scaleG = 256 / 64;

            EditableImage image = new EditableImage(header.Width, header.Height);

            for (int row = 0; row < header.Height; row++)
            {
                rowbase = (row * header.Width * 2);
                for (int col = 0; col < header.Width; col++)
                {
                    offset = rowbase + (col * 2);
                    realRow = header.Height - row - 1;          // Reverse row

                    // Get color and convert
                    color = BitConverter.ToInt16(buffer, offset);
                    red = (byte)(((color & _REDMASK) >> 11) * scaleR);
                    green = (byte)(((color & _GREENMASK) >> 5) * scaleG);
                    blue = (byte)(((color & _BLUEMASK)) * scaleR);

                    // Set pixel
                    image.SetPixel(col, realRow, red, green, blue, 255);
                }
            }

            return image;
        }
コード例 #5
0
ファイル: BmpDecoder.cs プロジェクト: Titaye/SLExtensions
        private static EditableImage Read4BitBmp(byte[] buffer, Color[] palette, BmpInfoHeader header)
        {
            int width = (header.Width + 1) / 2;
            int alignment = width % 4;       // Rows are aligned on 4 byte boundaries
            int rowbase = 0;
            int colbase = 0;
            int offset;
            int realRow;
            Color color1;
            Color color2;

            EditableImage image = new EditableImage(header.Width, header.Height);

            if (alignment != 0)
            {
                alignment = 4 - alignment;                        // Calculate row padding
            }

            for (int row = 0; row < header.Height; row++)
            {
                rowbase = (row * (width + alignment));
                for (int col = 0; col < width; col++)
                {
                    colbase = col * 2;
                    offset = rowbase + col;
                    realRow = header.Height - row - 1;          // Reverse row
                    color1 = palette[(buffer[offset]) >> 4];
                    color2 = palette[(buffer[offset]) & 0x0F];
                    image.SetPixel(colbase, realRow, color1.R, color1.G, color1.B, 255);
                    image.SetPixel(colbase + 1, realRow, color2.R, color2.G, color2.B, 255);
                }
            }

            return image;
        }
コード例 #6
0
ファイル: BmpDecoder.cs プロジェクト: Titaye/SLExtensions
        private static EditableImage Read24BitBmp(byte[] buffer, BmpInfoHeader header)
        {
            int alignment = (header.Width * 3) % 4;       // Rows are aligned on 4 byte boundaries
            int rowbase = 0;
            int offset;
            int realRow;

            EditableImage image = new EditableImage(header.Width, header.Height);

            if (alignment != 0)
            {
                alignment = 4 - alignment;                        // Calculate row padding
            }

            for (int row = 0; row < header.Height; row++)
            {
                rowbase = (row * ((header.Width * 3) + alignment));
                for (int col = 0; col < header.Width; col++)
                {
                    offset = rowbase + (col * 3);
                    realRow = header.Height - row - 1;          // Reverse row
                    if (offset >= buffer.Length)
                    {
                        HtmlPage.Window.Alert("Error - outside of bounds and not sure why");
                    }
                    image.SetPixel(col, realRow, buffer[offset + 2], buffer[offset + 1], buffer[offset], 255);
                }
            }

            return image;
        }