mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-10 07:45:05 -04:00
cache inflated color entries in PackedColor
This commit is contained in:
parent
3c0ee3c731
commit
7b8172af0f
@ -119,6 +119,20 @@ object PackedColor {
|
|||||||
private val greens = 8
|
private val greens = 8
|
||||||
private val blues = 5
|
private val blues = 5
|
||||||
|
|
||||||
|
private val staticPalette = new Array[Int](240)
|
||||||
|
|
||||||
|
{
|
||||||
|
for (index <- staticPalette.indices) {
|
||||||
|
val idxB = index % blues
|
||||||
|
val idxG = (index / blues) % greens
|
||||||
|
val idxR = (index / blues / greens) % reds
|
||||||
|
val r = (idxR * 0xFF / (reds - 1.0) + 0.5).toInt
|
||||||
|
val g = (idxG * 0xFF / (greens - 1.0) + 0.5).toInt
|
||||||
|
val b = (idxB * 0xFF / (blues - 1.0) + 0.5).toInt
|
||||||
|
staticPalette(index) = (r << rShift32) | (g << gShift32) | (b << bShift32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize palette to grayscale, excluding black and white, because
|
// Initialize palette to grayscale, excluding black and white, because
|
||||||
// those are already contained in the normal color cube.
|
// those are already contained in the normal color cube.
|
||||||
for (i <- palette.indices) {
|
for (i <- palette.indices) {
|
||||||
@ -130,16 +144,7 @@ object PackedColor {
|
|||||||
|
|
||||||
override def inflate(value: Int) =
|
override def inflate(value: Int) =
|
||||||
if (isFromPalette(value)) super.inflate(value)
|
if (isFromPalette(value)) super.inflate(value)
|
||||||
else {
|
else staticPalette((value - palette.length) % 240)
|
||||||
val index = value - palette.length
|
|
||||||
val idxB = index % blues
|
|
||||||
val idxG = (index / blues) % greens
|
|
||||||
val idxR = (index / blues / greens) % reds
|
|
||||||
val r = (idxR * 0xFF / (reds - 1.0) + 0.5).toInt
|
|
||||||
val g = (idxG * 0xFF / (greens - 1.0) + 0.5).toInt
|
|
||||||
val b = (idxB * 0xFF / (blues - 1.0) + 0.5).toInt
|
|
||||||
(r << rShift32) | (g << gShift32) | (b << bShift32)
|
|
||||||
}
|
|
||||||
|
|
||||||
override def deflate(value: Color) = {
|
override def deflate(value: Color) = {
|
||||||
val paletteIndex = super.deflate(value)
|
val paletteIndex = super.deflate(value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user