diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Blitter.scala b/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Blitter.scala index eb7757f6..002162c9 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Blitter.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Blitter.scala @@ -104,9 +104,9 @@ private[graphics] object Blitter { val colorDest = dest.unsafeGetPixel(destX, destY) val factor = 255 - colorSource.a val color = Color( - Math.min(Color.mulDiv255(colorDest.r, factor) + colorSource.r, 255), - Math.min(Color.mulDiv255(colorDest.g, factor) + colorSource.g, 255), - Math.min(Color.mulDiv255(colorDest.b, factor) + colorSource.b, 255) + Math.min((colorDest.r * factor) / 255 + colorSource.r, 255), + Math.min((colorDest.g * factor) / 255 + colorSource.g, 255), + Math.min((colorDest.b * factor) / 255 + colorSource.b, 255) ) dest.unsafePutPixel(destX, destY, color) dx += 1 @@ -254,9 +254,9 @@ private[graphics] object Blitter { val colorDest = dest.unsafeGetPixel(destX, destY) val factor = 255 - colorSource.a val color = Color( - Math.min(Color.mulDiv255(colorDest.r, factor) + colorSource.r, 255), - Math.min(Color.mulDiv255(colorDest.g, factor) + colorSource.g, 255), - Math.min(Color.mulDiv255(colorDest.b, factor) + colorSource.b, 255) + Math.min((colorDest.r * factor) / 255 + colorSource.r, 255), + Math.min((colorDest.g * factor) / 255 + colorSource.g, 255), + Math.min((colorDest.b * factor) / 255 + colorSource.b, 255) ) dest.unsafePutPixel(destX, destY, color) dx += 1 diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Color.scala b/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Color.scala index c71b21cc..d59675a3 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Color.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/graphics/Color.scala @@ -111,9 +111,9 @@ object Color { */ def *(that: Color): Color = Color( - mulDiv255(color.r, that.r), - mulDiv255(color.g, that.g), - mulDiv255(color.b, that.b) + color.r * that.r / 255, + color.g * that.g / 255, + color.b * that.b / 255 ) /** Combines this with another color by multiplying each RGB value (on the [0.0, 1.0] range). @@ -123,9 +123,9 @@ object Color { */ def :*(that: Color): Color = Color( - mulDiv255(color.r, that.r), - mulDiv255(color.g, that.g), - mulDiv255(color.b, that.b), + color.r * that.r / 255, + color.g * that.g / 255, + color.b * that.b / 255, color.a ) @@ -136,9 +136,9 @@ object Color { */ def *:(that: Color): Color = Color( - mulDiv255(color.r, that.r), - mulDiv255(color.g, that.g), - mulDiv255(color.b, that.b), + color.r * that.r / 255, + color.g * that.g / 255, + color.b * that.b / 255, that.a ) @@ -225,12 +225,4 @@ object Color { */ def unapply(color: Color): Some[(Int, Int, Int)] = Some(color.r, color.g, color.b) - - /** Computes (x * y) / 255 - * Based on https://github.com/libsdl-org/SDL/blob/bbc9c75618fbc60583123e03f31f4e856f2654bf/src/video/SDL_blit.h#L524-L530 - */ - inline private[graphics] def mulDiv255(x: Int, y: Int): Int = { - val out = (x * y) + 1 - (out + (out >> 8) >> 8) - } }