Better field names for PaletteEntry.

This commit is contained in:
UnknownShadow200 2016-07-25 22:08:44 +10:00
parent 92b7b6ad60
commit 0be654b006
3 changed files with 13 additions and 13 deletions

View File

@ -148,9 +148,9 @@ namespace MCGalaxy.Commands.Building {
} }
Color col = bmp.GetPixel(xx, yy); Color col = bmp.GetPixel(xx, yy);
cur.r = col.R; cur.g = col.G; cur.b = col.B; cur.R = col.R; cur.G = col.G; cur.B = col.B;
int position; int position;
cur.block = selector.BestMatch(cur, out position); cur.Block = selector.BestMatch(cur, out position);
if (popType == 1 || popType == 3) { if (popType == 1 || popType == 3) {
int threshold = popType == 1 ? 20 : 3; int threshold = popType == 1 ? 20 : 3;
if (position <= threshold) { if (position <= threshold) {
@ -165,8 +165,8 @@ namespace MCGalaxy.Commands.Building {
} }
} }
if (col.A < 20) cur.block = Block.air; if (col.A < 20) cur.Block = Block.air;
p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.block, 0); p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.Block, 0);
} }
if (dArgs.name == "tempImage_" + p.name) if (dArgs.name == "tempImage_" + p.name)

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Drawing {
public void SetAvailableBlocks(PaletteEntry[] blocks) { } public void SetAvailableBlocks(PaletteEntry[] blocks) { }
public byte BestMatch(PaletteEntry cur, out int position) { public byte BestMatch(PaletteEntry cur, out int position) {
int brightness = (cur.r + cur.g + cur.b) / 3; position = -1; int brightness = (cur.R + cur.G + cur.B) / 3; position = -1;
if (brightness < (256 / 4)) if (brightness < (256 / 4))
return Block.obsidian; return Block.obsidian;
else if (brightness >= (256 / 4) && brightness < (256 / 4) * 2) else if (brightness >= (256 / 4) && brightness < (256 / 4) * 2)
@ -58,15 +58,15 @@ namespace MCGalaxy.Drawing {
int minimum = int.MaxValue; position = 0; int minimum = int.MaxValue; position = 0;
for (int i = 0; i < palette.Length; i++) { for (int i = 0; i < palette.Length; i++) {
PaletteEntry pixel = palette[i]; PaletteEntry pixel = palette[i];
int dist = (cur.r - pixel.r) * (cur.r - pixel.r) int dist = (cur.R - pixel.R) * (cur.R - pixel.R)
+ (cur.g - pixel.g) * (cur.g - pixel.g) + (cur.G - pixel.G) * (cur.G - pixel.G)
+ (cur.b - pixel.b) * (cur.b - pixel.b); + (cur.B - pixel.B) * (cur.B - pixel.B);
if (dist < minimum) { if (dist < minimum) {
minimum = dist; position = i; minimum = dist; position = i;
} }
} }
return palette[position].block; return palette[position].Block;
} }
} }
@ -104,7 +104,7 @@ namespace MCGalaxy.Drawing {
LabColor RgbToLab(PaletteEntry block) { LabColor RgbToLab(PaletteEntry block) {
// First convert RGB to CIE-XYZ // First convert RGB to CIE-XYZ
double R = block.r / 255.0, G = block.g / 255.0, B = block.b / 255.0; double R = block.R / 255.0, G = block.G / 255.0, B = block.B / 255.0;
if (R > 0.04045) R = Math.Pow((R + 0.055) / 1.055, 2.4); if (R > 0.04045) R = Math.Pow((R + 0.055) / 1.055, 2.4);
else R = R / 12.92; else R = R / 12.92;
if (G > 0.04045) G = Math.Pow((G + 0.055) / 1.055, 2.4); if (G > 0.04045) G = Math.Pow((G + 0.055) / 1.055, 2.4);
@ -131,7 +131,7 @@ namespace MCGalaxy.Drawing {
lab.L = 116 * Y - 16; lab.L = 116 * Y - 16;
lab.A = 500 * (X - Y); lab.A = 500 * (X - Y);
lab.B = 200 * (Y - Z); lab.B = 200 * (Y - Z);
lab.Block = block.block; lab.Block = block.Block;
return lab; return lab;
} }
} }

View File

@ -137,10 +137,10 @@ namespace MCGalaxy.Drawing {
} }
public struct PaletteEntry { public struct PaletteEntry {
public byte block, r, g, b; public byte R, G, B, Block;
public PaletteEntry(byte r, byte g, byte b, byte block) { public PaletteEntry(byte r, byte g, byte b, byte block) {
this.r = r; this.g = g; this.b = b; this.block = block; R = r; G = g; B = b; Block = block;
} }
} }
} }