diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1030b50..d14840a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,16 +3,14 @@ gradle-starter = "0.67.0" gradle-doctor = "0.9.1" maven-junit = "5.10.1" maven-assertj = "3.24.2" -maven-commons = "2.15.1" maven-binarycompatiblity = "0.13.2" maven-dokka = "1.9.10" [libraries] -kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "maven-junit" } junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "maven-junit" } +junit-jupiter-platform = { module = "org.junit.platform:junit-platform-launcher" } assertj-core = { module = "org.assertj:assertj-core", version.ref = "maven-assertj" } -commons-io = { module = "commons-io:commons-io", version.ref = "maven-commons" } jetbrains-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "maven-dokka" } [plugins] diff --git a/webp-imageio/build.gradle b/webp-imageio/build.gradle index 7258f5c..0655b4f 100644 --- a/webp-imageio/build.gradle +++ b/webp-imageio/build.gradle @@ -58,5 +58,6 @@ tasks.named("processResources") { dependencies { testImplementation(libs.assertj.core) testRuntimeOnly(libs.junit.jupiter.engine) + testRuntimeOnly(libs.junit.jupiter.platform) testImplementation(libs.junit.jupiter.api) } diff --git a/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/WebPImageWriterSpi.kt b/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/WebPImageWriterSpi.kt index c32e0cc..12869b5 100644 --- a/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/WebPImageWriterSpi.kt +++ b/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/WebPImageWriterSpi.kt @@ -67,10 +67,6 @@ public open class WebPImageWriterSpi : return false } } - val colorSpace = colorModel.colorSpace - if (!colorSpace.isCS_sRGB) { - return false - } val sampleSize = sampleModel.sampleSize for (i in sampleSize.indices) { if (sampleSize[i] > 8) { diff --git a/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/internal/WebPWriter.kt b/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/internal/WebPWriter.kt index 20e5207..4463867 100644 --- a/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/internal/WebPWriter.kt +++ b/webp-imageio/src/main/kotlin/com/luciad/imageio/webp/internal/WebPWriter.kt @@ -97,7 +97,8 @@ internal class WebPWriter(originatingProvider: ImageWriterSpi?) : ImageWriter(or val width = aRi.width val height = aRi.height val colorModel = aRi.colorModel - return if (colorModel is ComponentColorModel) { + val colorSpace = colorModel.colorSpace + return if (colorSpace.isCS_sRGB && colorModel is ComponentColorModel) { val sampleModel = aRi.sampleModel as ComponentSampleModel when (sampleModel.transferType) { DataBuffer.TYPE_BYTE -> extractComponentRGBByte( @@ -116,7 +117,7 @@ internal class WebPWriter(originatingProvider: ImageWriterSpi?) : ImageWriter(or else -> throw IOException("Incompatible image: $aRi") } - } else if (colorModel is DirectColorModel) { + } else if (colorSpace.isCS_sRGB && colorModel is DirectColorModel) { val sampleModel = aRi.sampleModel as SinglePixelPackedSampleModel val type = sampleModel.transferType if (type == DataBuffer.TYPE_INT) { diff --git a/webp-imageio/src/test/kotlin/com/luciad/imageio/webp/WebPTest.kt b/webp-imageio/src/test/kotlin/com/luciad/imageio/webp/WebPTest.kt index 3482fc2..996720e 100644 --- a/webp-imageio/src/test/kotlin/com/luciad/imageio/webp/WebPTest.kt +++ b/webp-imageio/src/test/kotlin/com/luciad/imageio/webp/WebPTest.kt @@ -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 @@ -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) diff --git a/webp-imageio/src/test/resources/non_rgb_1.jpg b/webp-imageio/src/test/resources/non_rgb_1.jpg new file mode 100644 index 0000000..a489c0d Binary files /dev/null and b/webp-imageio/src/test/resources/non_rgb_1.jpg differ diff --git a/webp-imageio/src/test/resources/non_rgb_2.jpeg b/webp-imageio/src/test/resources/non_rgb_2.jpeg new file mode 100644 index 0000000..6ee2d69 Binary files /dev/null and b/webp-imageio/src/test/resources/non_rgb_2.jpeg differ