色フォーマット |
public static System.Drawing.Color Rgb565ToRgb888(int rgb565) { int red = rgb565 & 0x1F; int green = (rgb565 >> 5) & 0x3F; int blue = (rgb565 >> 11) & 0x1F; // Normalization red = (red << 3) | (red >> 2); green = (green << 2) | (green >> 4); blue = (blue << 3) | (blue >> 2); return System.Drawing.Color.FromArgb(255, red, green, blue); }
色相 | 色見本 | RGB |
---|---|---|
0°
|
(255, 0, 0)
|
|
30°
|
(255, 127, 0)
|
|
60°
|
(255, 255, 0)
|
|
90°
|
(127, 255, 0)
|
|
120°
|
(0, 255, 0)
|
|
150°
|
(0, 255, 127)
|
|
180°
|
(0, 255, 255)
|
|
210°
|
(0, 127, 255)
|
|
240°
|
(0, 0, 255)
|
|
270°
|
(127, 0, 255)
|
|
300°
|
(255, 0, 255)
|
|
330°
|
(255, 0, 127)
|
|
360°
|
(255, 0, 0)
|
彩度 | 色見本 | RGB |
---|---|---|
100%
|
(255, 0, 0)
|
|
90%
|
(242, 12, 12)
|
|
80%
|
(229, 25, 25)
|
|
70%
|
(216 38, 38)
|
|
60%
|
(204, 51, 51)
|
|
50%
|
(191, 63, 63)
|
|
40%
|
(178, 76, 76)
|
|
30%
|
(165, 89, 89)
|
|
20%
|
(153, 102, 102)
|
|
10%
|
(140, 114, 114)
|
|
0%
|
(127, 127, 127)
|
輝度 | 色見本 | RGB |
---|---|---|
100%
|
(255, 255, 255)
|
|
90%
|
(255, 204, 204)
|
|
80%
|
(255, 153, 153)
|
|
70%
|
(255 101, 101)
|
|
60%
|
(255, 50, 50)
|
|
50%
|
(255, 0, 0)
|
|
40%
|
(204, 0, 0)
|
|
30%
|
(153, 0, 0)
|
|
20%
|
(102, 0, 0)
|
|
10%
|
(51, 0, 0)
|
|
0%
|
(0, 0, 0)
|
/// <summary> /// Convert HSL color model to RGB888 color model. /// </summary> /// <returns> /// RGB888 value. (red, green, blue) /// </returns> /// <exception cref="System.ArgumentException"> /// Hue is less than 0 or greater than 360, or saturation or brightness is less than 0 or greater than 100. /// </exception> public static (int, int, int) HslToRgb888(int hue, int saturaiton, int brightness) { if (hue < 0 || hue > 360) throw new System.ArgumentException("Hue value must be in 0 to 360."); if (saturation < 0 || saturation > 100) throw new System.ArgumentException("Saturation value must be in 0 to 100."); if (brightness < 0 || brightness > 100) throw new System.ArgumentException("Brightness value must be in 0 to 100."); int red, green, blue; double max, min; if (brightness < 50) { max = 2.55 * (brightness + brightness * saturation / 100.0); min = 2.55 * (brightness - brightness * saturation / 100.0); } else { max = 2.55 * (brightness + (100 - brightness) * saturation / 100.0); min = 2.55 * (brightness - (100 - brightness) * saturation / 100.0); } if (hue < 60) { red = (int)max; blue = (int)min; green = (int)((hue / 60.0) * (max - min) + min); } else if (hue < 120) { green = (int)max; blue = (int)min; red = (int)(((120 - hue) / 60.0) * (max - min) + min); } else if (hue < 180) { green = (int)max; red = (int)min; blue = (int)(((hue - 120) / 60.0) * (max - min) + min); } else if (hue < 240) { blue = (int)max; red = (int)min; red = (int)(((240 - hue) / 60.0) * (max - min) + min); } else if (hue < 300) { blue = (int)max; green = (int)min; red = (int)(((hue - 240) / 60.0) * (max - min) + min); } else { red = (int)max; green = (int)min; blue = (int)(((360 - hue) / 60.0) * (max - min) + min); } return (red, green, blue); } /// <summary> /// Convert RGB888 color model to HSL color model. /// </summary> /// <returns> /// HSL value. (hue, saturation, brightness) /// </returns> /// <exception cref="System.ArgumentException"> /// Red, green or blue is less than 0 or greater than 255. /// </exception> public static (int, int, int) Rgb888ToHsl(int red, int green, int blue) { if (red < 0 || red > 255) throw new System.ArgumentException("Red value must be in 0 to 255."); if (green < 0 || green > 255) throw new System.ArgumentException("Green value must be in 0 to 255."); if (blue < 0 || blue > 255) throw new System.ArgumentException("Blue value must be in 0 to 255."); int hue, saturation, brightness, max, min; if (red == green && green == blue) { hue = 0; max = min = red; } else if (red >= green && red >= blue) { max = red; min = System.Math.Min(green, blue); hue = 60 * ((green - blue) / (max - min)); } else if (green >= red && green >= blue) { max = green; min = System.Math.Min(red, blue); hue = 60 * ((blue - red) / (max - min)) + 120; } else { max = blue; min = System.Math.Min(red, green); hue = 60 * ((red - green) / (max - min)) + 240; } while (hue < 0) hue += 360; brightness = (max + min) / 2; if (brightness < 128) saturation = (max - min) / (max + min); else saturation = (max - min) / (510 - max - min); return (hue, saturation, brightness); }
public static System.Drawing.Color DecodeDirectColor(byte color, ushort tilemap) { /* SNES Direct Color * color = BBGGGRRR * aditionalColorBits = bgr * red = RRRr0 * green = GGGg0 * blue = BBb00 * */ int additionalColorBits = (tilemap >> 10) & 0x7; int red = color & 0x7; int green = (color >> 3) & 0x7; int blue = (color >> 6) & 0x3; red |= additionalColorBits & 0x1; green |= (additionalColorBits >> 1) & 0x1; blue |= (additionalColorBits >> 2) & 0x1; red <<= 1; green <<= 1; blue <<= 2; // Normalization red |= red >> 2; green |= green >> 2; blue |= blue >> 2; return System.Drawing.Color.FromArgb(255, red, green, blue); }