예제 #1
0
        internal TIM2Segment(Image image, IList <Color[]> palettes, TIM2SegmentParameters parameters)
        {
            this.parameters = parameters;
            swizzleFilter   = new SwizzleFilter(parameters.width, parameters.height, parameters.bpp);
            paletteFilter   = new TIM2PaletteFilter(parameters.bpp);

            if (parameters.bpp > 8)                                                                  //true color image
            {
                imageData = GetColorCodec(parameters.colorSize).EncodeColors(image.GetColorArray()); //I love extension methods. Hurray!
            }
            else
            {
                ImageEncoderIndexed encoder;
                if (palettes != null)
                {
                    encoder = new ImageEncoderIndexed(palettes, image, IndexCodec.FromBitPerPixel(parameters.bpp));
                }
                else
                {
                    encoder = new ImageEncoderIndexed(image, IndexCodec.FromBitPerPixel(parameters.bpp), new ARGBColorComparer());
                }

                imageData     = encoder.Encode();
                this.palettes = new List <Color[]>(encoder.Palettes).ToArray();
            }
            CreateImageDecoder(imageData);
        }
예제 #2
0
        internal TIM2Segment(byte[] imageData, byte[] paletteData, uint colorEntries, TIM2SegmentParameters parameters)
        {
            this.imageData  = imageData;
            this.parameters = parameters;
            swizzleFilter   = new SwizzleFilter(parameters.width, parameters.height, parameters.bpp);
            paletteFilter   = new TIM2PaletteFilter(parameters.bpp);

            if (parameters.swizzled)
            {
                this.imageData = swizzleFilter.Defilter(imageData);
            }

            ConstructPalettes(paletteData, colorEntries);
            CreateImageDecoder(imageData);

            if (!parameters.linearPalette)
            {
                for (int i = 0; i < palettes.Length; i++)
                {
                    palettes[i] = paletteFilter.Defilter(palettes[i]);
                }
            }
        }