File tree Expand file tree Collapse file tree 5 files changed +51
-16
lines changed
main/kotlin/com/luciad/imageio/webp/internal
test/kotlin/com/luciad/imageio/webp Expand file tree Collapse file tree 5 files changed +51
-16
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ internal object WebPWrapper {
1616
1717 private var NATIVE_LIBRARY_LOADED = false
1818
19+ init {
20+ loadNativeLibrary()
21+ }
22+
1923 @JvmStatic
2024 @Synchronized
2125 fun loadNativeLibrary () {
Original file line number Diff line number Diff line change 1+ package com.luciad.imageio.webp
2+
3+ import com.luciad.imageio.webp.utils.readImage
4+ import com.luciad.imageio.webp.utils.readResource
5+ import org.assertj.core.api.Assertions.assertThat
6+ import org.junit.jupiter.api.Test
7+
8+ class SimpleTest {
9+
10+ /* *
11+ * For some reason this reproduces the issue from https://github.com/usefulness/webp-imageio/issues/111
12+ */
13+ @Test
14+ fun readLossy () {
15+ val image = readImage(readResource(" lossy.webp" ))
16+
17+ assertThat(image.width).isEqualTo(1024 )
18+ assertThat(image.height).isEqualTo(752 )
19+ }
20+ }
Original file line number Diff line number Diff line change 11package com.luciad.imageio.webp
22
3+ import com.luciad.imageio.webp.utils.getResourceStream
4+ import com.luciad.imageio.webp.utils.readImage
5+ import com.luciad.imageio.webp.utils.readResource
6+ import com.luciad.imageio.webp.utils.requireWebpImageReader
7+ import com.luciad.imageio.webp.utils.requireWebpImageWriter
8+ import com.luciad.imageio.webp.utils.writeWebpImage
39import org.assertj.core.api.Assertions.assertThat
410import org.junit.jupiter.api.Test
511import org.junit.jupiter.api.io.TempDir
Original file line number Diff line number Diff line change 1+ package com.luciad.imageio.webp.utils
2+
3+ import java.io.ByteArrayOutputStream
4+
5+ private object ResourcesLoader
6+
7+ internal fun readResource (resource : String ) = getResourceStream(resource).use { stream ->
8+ ByteArrayOutputStream ().use { out ->
9+ stream.copyTo(out )
10+ out .toByteArray()
11+ }
12+ }
13+
14+ internal fun getResourceStream (resource : String ) = checkNotNull(ResourcesLoader ::class .java.classLoader.getResourceAsStream(resource)) {
15+ " Could not load resource $resource "
16+ }
Original file line number Diff line number Diff line change 1- package com.luciad.imageio.webp
1+ package com.luciad.imageio.webp.utils
22
3+ import com.luciad.imageio.webp.WebPImageReaderSpi
4+ import com.luciad.imageio.webp.WebPImageWriterSpi
5+ import com.luciad.imageio.webp.WebPWriteParam
36import java.awt.image.BufferedImage
47import java.io.ByteArrayInputStream
5- import java.io.ByteArrayOutputStream
68import java.io.File
79import javax.imageio.IIOImage
810import javax.imageio.ImageIO
@@ -16,20 +18,7 @@ import javax.imageio.stream.MemoryCacheImageInputStream
1618internal fun Iterator<ImageReader>.requireWebpImageReader () = asSequence().single { it.originatingProvider is WebPImageReaderSpi }
1719internal fun Iterator<ImageWriter>.requireWebpImageWriter () = asSequence().single { it.originatingProvider is WebPImageWriterSpi }
1820
19- private object ResourcesLoader
20-
21- internal fun readResource (resource : String ) = getResourceStream(resource).use { stream ->
22- ByteArrayOutputStream ().use { out ->
23- stream.copyTo(out )
24- out .toByteArray()
25- }
26- }
27-
28- internal fun getResourceStream (resource : String ) = checkNotNull(ResourcesLoader ::class .java.classLoader.getResourceAsStream(resource)) {
29- " Could not load resource $resource "
30- }
31-
32- internal fun readImage (webp : ByteArray , param : ImageReadParam ? = null) = checkNotNull(getImageReader(webp))
21+ internal fun readImage (webp : ByteArray , param : ImageReadParam ? = null) = getImageReader(webp)
3322 .apply { input = MemoryCacheImageInputStream (ByteArrayInputStream (webp)) }
3423 .read(0 , param)
3524
You can’t perform that action at this time.
0 commit comments