Skip to content

Commit

Permalink
Fix test as the gif buffer was also used in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Jan 15, 2024
1 parent 7015703 commit c236227
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class FrameBuffer(

internal var buffer: ByteArray = ByteArray(height * width * PixelFormat.RGBA)

internal var gifBuffer: IntArray = IntArray(0)

internal val clipper: Clipper = Clipper(width, height)

internal val blender = Blender(gamePalette)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.test.assertTrue

class PixelArrayTest {

private val blender: (Array<Int>, Pixel, Pixel) -> Array<Int> = { c, _, _ ->
private val blender: (ByteArray, Pixel, Pixel) -> ByteArray = { c, _, _ ->
c
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class PixelArrayTest {
source.set(0, 0, 9)
val result = source.get(0, 0)
assertTrue(result.size == 1)
assertTrue(result[0] == 9)
assertTrue(result[0] == 9.toByte())
}

@Test
Expand All @@ -79,10 +79,10 @@ class PixelArrayTest {
source.set(0, 0, 1, 2, 3, 4)
val result = source.get(0, 0)
assertTrue(result.size == 4)
assertTrue(result[0] == 1)
assertTrue(result[1] == 2)
assertTrue(result[2] == 3)
assertTrue(result[3] == 4)
assertTrue(result[0] == 1.toByte())
assertTrue(result[1] == 2.toByte())
assertTrue(result[2] == 3.toByte())
assertTrue(result[3] == 4.toByte())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class GfxLibTest {

dither.call(valueOf(0xA5A5))

val a = mockResources.frameBuffer.blender.mix(arrayOf(1), 0, 0, null)?.get(0) ?: 0
val b = mockResources.frameBuffer.blender.mix(arrayOf(1), 1, 0, null)?.get(0) ?: 0
val c = mockResources.frameBuffer.blender.mix(arrayOf(1), 0, 1, null)?.get(0) ?: 0
val d = mockResources.frameBuffer.blender.mix(arrayOf(1), 1, 1, null)?.get(0) ?: 0
val a = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 0, 0, null)?.get(0) ?: 0
val b = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 1, 0, null)?.get(0) ?: 0
val c = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 0, 1, null)?.get(0) ?: 0
val d = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 1, 1, null)?.get(0) ?: 0

assertEquals(1, a)
assertEquals(0, b)
Expand All @@ -57,10 +57,10 @@ class GfxLibTest {

dither.call(valueOf(0xFFFF))

val a = mockResources.frameBuffer.blender.mix(arrayOf(1), 0, 0, null)?.get(0) ?: 0
val b = mockResources.frameBuffer.blender.mix(arrayOf(1), 1, 0, null)?.get(0) ?: 0
val c = mockResources.frameBuffer.blender.mix(arrayOf(1), 0, 1, null)?.get(0) ?: 0
val d = mockResources.frameBuffer.blender.mix(arrayOf(1), 1, 1, null)?.get(0) ?: 0
val a = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 0, 0, null)?.get(0) ?: 0
val b = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 1, 0, null)?.get(0) ?: 0
val c = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 0, 1, null)?.get(0) ?: 0
val d = mockResources.frameBuffer.blender.mix(byteArrayOf(1), 1, 1, null)?.get(0) ?: 0

assertEquals(1, a)
assertEquals(1, b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ actual fun toGif(name: String, animation: List<FrameBuffer>) {
}
FileOutputStream("build/test-results/jvmTest/$name.gif").use { out ->
val reference = animation.first()

fun convert(data: ByteArray): IntArray {
val result = IntArray(data.size)
val colorPalette = reference.gamePalette
data.forEachIndexed { index, byte ->
result[index] = colorPalette.getRGAasInt(byte.toInt())
}
return result
}

val encoder = FastGifEncoder(
out,
reference.width,
Expand All @@ -21,7 +31,7 @@ actual fun toGif(name: String, animation: List<FrameBuffer>) {
)

animation.forEach { img ->
encoder.addImage(img.gifBuffer, reference.width, options)
encoder.addImage(convert(img.generateBuffer()), reference.width, options)
}
encoder.finishEncoding()
}
Expand Down

0 comments on commit c236227

Please sign in to comment.