Пример #1
0
                /// <summary>
                /// Traverse the tree, building up the color palette
                /// </summary>
                /// <param name="palette">The palette</param>
                /// <param name="index">The current palette index</param>
                public void ConstructPalette(TPixel[] palette, ref int index)
                {
                    if (this.leaf)
                    {
                        // This seems faster than using Vector4
                        byte r = (this.red / this.pixelCount).ToByte();
                        byte g = (this.green / this.pixelCount).ToByte();
                        byte b = (this.blue / this.pixelCount).ToByte();

                        // And set the color of the palette entry
                        TPixel pixel = default(TPixel);
                        pixel.PackFromBytes(r, g, b, 255);
                        palette[index] = pixel;

                        // Consume the next palette index
                        this.paletteIndex = index++;
                    }
                    else
                    {
                        // Loop through children looking for leaves
                        for (int i = 0; i < 8; i++)
                        {
                            if (this.children[i] != null)
                            {
                                this.children[i].ConstructPalette(palette, ref index);
                            }
                        }
                    }
                }
Пример #2
0
            public override Image <TPixel> GetImage()
            {
                Image <TPixel> image = base.GetImage();
                TPixel         color = default(TPixel);

                color.PackFromBytes(this.r, this.g, this.b, this.a);

                return(image.Fill(color));
            }