Skip to content

Commit

Permalink
Add dummy test case ensuring non-rgb color spaces can be written to
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski committed Dec 24, 2023
1 parent 535a33f commit 05121c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions webp-imageio/src/test/kotlin/com/luciad/imageio/webp/WebPTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.luciad.imageio.webp.utils.requireWebpImageWriter
import com.luciad.imageio.webp.utils.writeWebpImage
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledOnJre
import org.junit.jupiter.api.condition.JRE
import org.junit.jupiter.api.io.TempDir
import java.awt.image.BufferedImage
import java.awt.image.DataBufferInt
Expand Down Expand Up @@ -83,6 +85,25 @@ class WebPTest {
assertThat(image.height).isEqualTo(301)
}

@Test
@DisabledOnJre(JRE.JAVA_9) // for some reason Java 9 can't read JPEGs with indexed colors
fun nonRgbColorSpace(@TempDir tempDir: Path) {
val inputImage1 = ImageIO.read(readResource("non_rgb_1.jpg").inputStream())
val inputImage2 = ImageIO.read(readResource("non_rgb_2.jpeg").inputStream())
val outputFile1 = tempDir.resolve("out_1.webp").toFile()
val outputFile2 = tempDir.resolve("out_2.webp").toFile()

ImageIO.write(inputImage1, "webp", outputFile1).let(::check)
ImageIO.write(inputImage2, "webp", outputFile2).let(::check)
val outputImage1 = readImage(webp = outputFile1.readBytes())
val outputImage2 = readImage(webp = outputFile2.readBytes())

assertThat(outputImage1.width).isEqualTo(500)
assertThat(outputImage1.height).isEqualTo(333)
assertThat(outputImage2.width).isEqualTo(1000)
assertThat(outputImage2.height).isEqualTo(1000)
}

@Test
fun testCompress() {
val image = BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB)
Expand Down
Binary file added webp-imageio/src/test/resources/non_rgb_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webp-imageio/src/test/resources/non_rgb_2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 05121c6

Please sign in to comment.