예제 #1
0
        public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
        {
            int offset;

            byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline, header.BitDepth);
            if (useAlpha)
            {
                for (int x = 0; x < newScanline.Length; x += 4)
                {
                    offset = row * header.Width + (x >> 2);
                    byte   r     = newScanline[x];
                    byte   g     = newScanline[x + 1];
                    byte   b     = newScanline[x + 2];
                    byte   a     = newScanline[x + 3];
                    Color2 color = Color2.FromArgb(a, r, g, b);
                    pixels[offset] = color;
                }
            }
            else
            {
                for (int x = 0; x < newScanline.Length / 3; x++)
                {
                    offset = (row * header.Width) + x;
                    int    pixelOffset = x * 3;
                    byte   r           = newScanline[pixelOffset];
                    byte   g           = newScanline[pixelOffset + 1];
                    byte   b           = newScanline[pixelOffset + 2];
                    Color2 color       = Color2.FromArgb(r, g, b);
                    pixels[offset] = color;
                }
            }
            row++;
        }
예제 #2
0
        public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
        {
            byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline, header.BitDepth);
            int    offset, index;

            if (paletteAlpha != null && paletteAlpha.Length > 0)
            {
                for (int i = 0; i < header.Width; i++)
                {
                    index  = newScanline[i];
                    offset = (row * header.Width) + i;
                    int    pixelOffset = index * 3;
                    byte   r           = palette[pixelOffset];
                    byte   g           = palette[pixelOffset + 1];
                    byte   b           = palette[pixelOffset + 2];
                    byte   a           = paletteAlpha.Length > index ? paletteAlpha[index] : (byte)255;
                    Color2 color       = Color2.FromArgb(a, r, g, b);
                    pixels[offset] = color;
                }
            }
            else
            {
                for (int i = 0; i < header.Width; i++)
                {
                    index  = newScanline[i];
                    offset = (row * header.Width) + i;
                    int    pixelOffset = index * 3;
                    byte   r           = palette[pixelOffset];
                    byte   g           = palette[pixelOffset + 1];
                    byte   b           = palette[pixelOffset + 2];
                    Color2 color       = Color2.FromArgb(r, g, b);
                    pixels[offset] = color;
                }
            }
            row++;
        }