Skip to content

Commit

Permalink
Tests HEIC loading in apple platforms (#917)
Browse files Browse the repository at this point in the history
* Tests HEIC loading in apple platforms

* Try to use CGColorSpaceCreateDeviceRGB

* It seems that the decoded HEIC image is different on some devices, let's use PSNR instead to be more lax
  • Loading branch information
soywiz committed Nov 22, 2022
1 parent 5656959 commit 6d21234
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ open class CGNativeImageFormatProvider : CGBaseNativeImageFormatProvider() {
} else {

//val colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)
val colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
//val colorSpace = CGColorSpaceCreateDeviceRGB()
//val colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
val colorSpace = CGColorSpaceCreateDeviceRGB()
try {
val realPremultiplied = true
//val realPremultiplied = premultiplied
Expand Down
20 changes: 20 additions & 0 deletions korim/src/darwinTest/kotlin/com/soywiz/korim/format/HEICTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.soywiz.korim.format

import com.soywiz.korim.bitmap.*
import com.soywiz.korio.async.*
import com.soywiz.korio.file.std.*
import kotlin.test.*

class HEICTest {
@Test
fun test() = suspendTest {
val heic = resourcesVfs["heic.heic"].readBitmap().toBMP32().premultiplied()
val png = resourcesVfs["heic.heic.png"].readBitmap(PNG.toProps()).toBMP32().premultiplied()
//localVfs("/tmp/heic.heic.png").writeBitmap(heic, PNG)
assertGreaterOrEqual(30.0, Bitmap32.computePsnr(heic, png), message = "PSNR")
}

fun assertGreaterOrEqual(expected: Double, actual: Double, message: String = "") {
assertTrue("Expected $actual >= $expected : $message") { actual >= expected }
}
}
Binary file added korim/src/darwinTest/resources/heic.heic
Binary file not shown.
Binary file added korim/src/darwinTest/resources/heic.heic.png
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 6d21234

Please sign in to comment.