protected override byte QuantizePixel(Color2 pixel) { byte paletteIndex = (byte) colors; if (pixel.ToBytes()[3] > Threshold){ paletteIndex = (byte) octree.GetPaletteIndex(pixel); } return paletteIndex; }
public void Increment(Color2 pixel) { pixelCount++; byte[] components = pixel.ToBytes(); red += components[0]; green += components[1]; blue += components[2]; }
protected override byte QuantizePixel(Color2 pixel) { byte paletteIndex = (byte)colors; if (pixel.ToBytes()[3] > Threshold) { paletteIndex = (byte)octree.GetPaletteIndex(pixel); } return(paletteIndex); }
protected override byte QuantizePixel(Color2 pixel) { byte colorIndex = 0; string colorHash = pixel.ToString(); if (colorMap.ContainsKey(colorHash)) { colorIndex = colorMap[colorHash]; } else { byte[] bytes = pixel.ToBytes(); if (!(bytes[3] > Threshold)) { for (int index = 0; index < colors.Length; index++) { if (colors[index].ToBytes()[3] == 0) { colorIndex = (byte)index; TransparentIndex = colorIndex; break; } } } else { int leastDistance = int.MaxValue; int red = bytes[0]; int green = bytes[1]; int blue = bytes[2]; for (int index = 0; index < colors.Length; index++) { byte[] paletteColor = colors[index].ToBytes(); int redDistance = paletteColor[0] - red; int greenDistance = paletteColor[1] - green; int blueDistance = paletteColor[2] - blue; int distance = (redDistance * redDistance) + (greenDistance * greenDistance) + (blueDistance * blueDistance); if (distance < leastDistance) { colorIndex = (byte)index; leastDistance = distance; if (distance == 0) { break; } } } } colorMap.TryAdd(colorHash, colorIndex); } return(colorIndex); }
public int GetPaletteIndex(Color2 pixel, int level) { int index = paletteIndex; if (!leaf) { int shift = 7 - level; byte[] components = pixel.ToBytes(); int pixelIndex = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) | ((components[0] & Mask[level]) >> shift); if (children[pixelIndex] != null) { index = children[pixelIndex].GetPaletteIndex(pixel, level + 1); } else { throw new Exception($"Cannot retrive a pixel at the given index {pixelIndex}."); } } return(index); }
protected override byte QuantizePixel(Color2 pixel) { byte colorIndex = 0; string colorHash = pixel.ToString(); if (colorMap.ContainsKey(colorHash)){ colorIndex = colorMap[colorHash]; } else{ byte[] bytes = pixel.ToBytes(); if (!(bytes[3] > Threshold)){ for (int index = 0; index < colors.Length; index++){ if (colors[index].ToBytes()[3] == 0){ colorIndex = (byte) index; TransparentIndex = colorIndex; break; } } } else{ int leastDistance = int.MaxValue; int red = bytes[0]; int green = bytes[1]; int blue = bytes[2]; for (int index = 0; index < colors.Length; index++){ byte[] paletteColor = colors[index].ToBytes(); int redDistance = paletteColor[0] - red; int greenDistance = paletteColor[1] - green; int blueDistance = paletteColor[2] - blue; int distance = (redDistance*redDistance) + (greenDistance*greenDistance) + (blueDistance*blueDistance); if (distance < leastDistance){ colorIndex = (byte) index; leastDistance = distance; if (distance == 0){ break; } } } } colorMap.TryAdd(colorHash, colorIndex); } return colorIndex; }
public void AddColor(Color2 pixel, int colorBits, int level, Octree octree) { if (leaf) { Increment(pixel); octree.TrackPrevious(this); } else { int shift = 7 - level; byte[] components = pixel.ToBytes(); int index = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) | ((components[0] & Mask[level]) >> shift); OctreeNode child = children[index]; if (child == null) { child = new OctreeNode(level + 1, colorBits, octree); children[index] = child; } child.AddColor(pixel, colorBits, level + 1, octree); } }
public void Increment(Color2 pixel) { pixelCount++; byte[] components = pixel.ToBytes(); red += components[0]; green += components[1]; blue += components[2]; }
public int GetPaletteIndex(Color2 pixel, int level) { int index = paletteIndex; if (!leaf){ int shift = 7 - level; byte[] components = pixel.ToBytes(); int pixelIndex = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) | ((components[0] & Mask[level]) >> shift); if (children[pixelIndex] != null){ index = children[pixelIndex].GetPaletteIndex(pixel, level + 1); } else{ throw new Exception($"Cannot retrive a pixel at the given index {pixelIndex}."); } } return index; }
public void AddColor(Color2 pixel, int colorBits, int level, Octree octree) { if (leaf){ Increment(pixel); octree.TrackPrevious(this); } else{ int shift = 7 - level; byte[] components = pixel.ToBytes(); int index = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) | ((components[0] & Mask[level]) >> shift); OctreeNode child = children[index]; if (child == null){ child = new OctreeNode(level + 1, colorBits, octree); children[index] = child; } child.AddColor(pixel, colorBits, level + 1, octree); } }