Skip to content

Commit

Permalink
Fix loading of jpeg files not supported by standard java ImageIO (Kot…
Browse files Browse the repository at this point in the history
…lin#384)

* Add TwelveMonkeys ImageIO plugin

* Add IO test with images from COCO 2017 test set, which failed to load using standard java ImageIO
  • Loading branch information
ermolenkodev committed Jul 12, 2022
1 parent 24a38cc commit 2658d8e
Show file tree
Hide file tree
Showing 77 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions dataset/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project.setDescription("A KotlinDL library provides Dataset API and DSL to build

dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21'
implementation 'com.twelvemonkeys.imageio:imageio-jpeg:3.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions examples/src/test/kotlin/examples/io/IOTestSuite.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package examples.io

import examples.transferlearning.getFileFromResource
import org.jetbrains.kotlinx.dl.dataset.image.ImageConverter
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import javax.imageio.ImageIO
import javax.imageio.ImageReader


class IOTestSuite {
private val unsupportedJpegsFolder = getFileFromResource("jpeg_unsupported")

@Test
fun testJvmUnsupportedJpegLoading() {
val imageFiles = unsupportedJpegsFolder.walk().filter { it.isFile }

for (imageFile in imageFiles) {
assertDoesNotThrow("Failed to load image file $imageFile") {
imageFile.inputStream().use { inputStream -> ImageConverter.toBufferedImage(inputStream) }
}
}
}

@Test
fun testImageioJpegPluginIsUsed() {
val readers: Iterator<ImageReader> = ImageIO.getImageReadersByFormatName("JPEG")
val defaultReader = readers.next()
assert("com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader" in defaultReader.toString()) { "Default jpeg reader should be com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader" }
}
}

0 comments on commit 2658d8e

Please sign in to comment.