korlibs / korlibs/korge

Colors for grayscale jpg images are wrong

Open
#1,773 1 comment 0 reactions 0 assignees View on GitHub
bug check
Dominant language
Kotlin
Stars
3k
Forks
148
Avg merge
13h 44m
Merged PRs (30d)
1

Description

**LEFT** is using ImageIO.read (correct colors)

**RIGHT** is using Korge's readBitmapNative (colors are faded out, incorrect)

image

I managed to replicate this in jvmMain:

```
object DebugMain {
@JvmStatic
fun main(args: Array) = runBlockingNoJs {
Korge(backgroundColor = Colors["#2b2b2b"], virtualSize = Size(1280, 720)) {
val file = File("C:\\Users\\kietm\\GitHub\\ImageCropper\\src\\commonMain\\resources\\converted.jpg")
val img: BufferedImage = ImageIO.read(file)
val bmp1 = img.toAwtNativeImage()
val img1 = image(bmp1) {
scaleWhileMaintainingAspect(ScalingOption.ByWidthAndHeight(1280.0/ 2, 720.0))
}

val bmp2 = KR.converted.__file.readBitmapNative()
image(bmp2) {
scaleWhileMaintainingAspect(ScalingOption.ByWidthAndHeight(1280.0/ 2, 720.0))
alignLeftToRightOf(img1)
}

}
}
}
```

I'll go ahead and attach the grayscale JPG.

![grayscale_jpg](https://github.com/korlibs/korge/assets/5054996/a3f497a3-91eb-4471-83b3-95523fa646d3)

Original:

![img1](https://github.com/korlibs/korge/assets/5054996/080b9db0-1ed8-42df-907d-093517498adf)

BTW here's how to create your own grayscale images using [ImageMagick](https://imagemagick.org/index.php):

```shell
$ magick.exe convert -colorspace Gray .\original.jpg converted.jpg
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the jvmMain reproduction and compare Korge's readBitmapNative output with ImageIO.read for the attached grayscale JPG. Trace the readBitmapNative path and verify the decoded colors against the reference image. Done means grayscale JPGs render with matching colors rather than appearing faded.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.