예제 #1
0
        public ImageDecoderIndexed(byte[] pixelData, int width, int height, IndexCodec codec, SKColor[] palette = null, ImageFilter imageFilter = null, PaletteFilter paletteFilter = null)
        {
            this.pixelData = pixelData;
            if (imageFilter != null)
            {
                this.pixelData = imageFilter.Defilter(pixelData);
            }

            this.width      = width;
            this.height     = height;
            this.indexCodec = codec;

            grayScale = new SKColor[1 << codec.BitDepth];

            for (int i = 0; i < grayScale.Length; i++)
            {
                grayScale[i] = new SKColor((byte)(i * (256 / grayScale.Length)), (byte)(i * (256 / grayScale.Length)), (byte)(i * (256 / grayScale.Length)));
            }

            if (paletteFilter != null && palette != null)
            {
                Palette = paletteFilter.Defilter(palette);
            }
            else if (palette == null)
            {
                palette = (SKColor[])grayScale.Clone();
                Palette = palette;
            }
            else
            {
                Palette = (SKColor[])palette.Clone();
            }
        }
예제 #2
0
        public override SKColor[] DecodeColors(byte[] colors, int start, int length)
        {
            ImageFilter filter = GetImageFilter();

            BinaryReader reader = null;

            if (filter != null)
            {
                byte[] data = filter.Defilter(colors, start, length);
                reader = new BinaryReader(new MemoryStream(data));
            }
            else
            {
                reader = new BinaryReader(new MemoryStream(colors, start, length));
            }

            SKColor[] decoded = new SKColor[FullWidth * FullHeight];
            SKColor[] tile    = new SKColor[4 * 4];

            for (int y = 0; y < FullHeight; y += 4)
            {
                for (int x = 0; x < FullWidth; x += 4)
                {
                    DecodeDXT1Block(reader, tile);
                    for (int line = 0; line < 4; line++)
                    {
                        int destIndex = FullWidth * (y + line) +
                                        (ByteOrder == ByteOrder.BigEndian ? x : FullWidth - (x + 4));
                        Array.Copy(tile, line * 4, decoded, destIndex, 4);
                    }
                }
            }

            reader.Close();

            if (FullWidth == width && FullHeight == height)
            {
                return(decoded);
            }

            SKColor[] decodedRealSize = new SKColor[width * height];

            int k = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    decodedRealSize[k++] = decoded[y * FullWidth + x];
                }
            }

            return(decodedRealSize);
        }
        public ImageDecoderDirectColor(byte[] pixelData, int width, int height, ColorCodec decoder, ImageFilter imageFilter = null)
        {
            this.pixelData = pixelData;
            if (imageFilter != null)
            {
                this.pixelData = imageFilter.Defilter(pixelData);
            }

            this.width   = width;
            this.height  = height;
            this.decoder = decoder;
        }