/// <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(TColor[] 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(); byte a = (this.alpha / this.pixelCount).ToByte(); // And set the color of the palette entry TColor pixel = default(TColor); pixel.PackFromBytes(r, g, b, a); 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); } } } }
public override Image <TColor> GetImage() { Image <TColor> image = base.GetImage(); TColor color = default(TColor); color.PackFromBytes(this.r, this.g, this.b, this.a); return(image.Fill(color)); }
public override Image <TColor, TPacked> Create() { var image = base.Create(); TColor color = default(TColor); color.PackFromBytes(this.r, this.g, this.b, this.a); return(image.Fill(color)); }