Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderJpg() color is bluer than expected #3203

Closed
jdenisgiguere opened this issue Mar 16, 2020 · 5 comments · Fixed by #3278
Closed

renderJpg() color is bluer than expected #3203

jdenisgiguere opened this issue Mar 16, 2020 · 5 comments · Fixed by #3278
Assignees
Labels

Comments

@jdenisgiguere
Copy link

Current situation

With I use rendegJpg() on a Multiband Tille, the color is not as expected. It is bluer than expected.

renderPng() return an image of the expected color.

See renderJpg() result
renderJpg

and renderPng() result
renderPng

Expected situation

repnderPng() and renderJpg() should return similar image.

@pomadchin
Copy link
Member

Hi! Thanks for reporting, it is a duplicate of #3151; could you upload an original small image that you use to generate pngs / jpgs so we can test against it?

@pomadchin pomadchin added the bug label Mar 16, 2020
@jdenisgiguere
Copy link
Author

Thanks for the super quick follow up!

See:
tiled_U-19OrthoSectorTile1_2012x2012.zip

@pomadchin
Copy link
Member

@jdenisgiguere thanks!

@esmeetu
Copy link
Contributor

esmeetu commented Mar 19, 2020

Same here.

Problem here might be ImageIO recieve a ARGB while geotrellis give us a RGBA.
And i found a workaround:

  def renderJpg(img: MultibandTile) = {
    // get a rgba tile
    val coloredImg = img.color()

    // begin translate from rgba to argb
    val (cols, rows) = (img.cols, img.rows)
    val bi = new BufferedImage(cols, rows, BufferedImage.TYPE_INT_ARGB)
    cfor(0)(_ < cols, _ + 1) { x =>
      cfor(0)(_ < rows, _ + 1) { y =>
        val v = coloredImg.get(x, y)
        val r = (v >> 24) & 0xFF
        val g = (v >> 16) & 0xFF
        val b = (v >> 8) & 0xFF
        val a = v & 0xFF
        bi.setRGB(x, y, a << 24 | r << 16 | g << 8 | b)
      }
    }
    val result = ImageIO.write(bi, "png", new File("img.png"))
    print(result)
  }

here i use BufferedImage.TYPE_INT_ARGB to keep alpha band. However when i write to jpg format, it will output a weird cmyk format and black image. Using png format works well and saves the alpha info.

In the end, i think it had better to make a change in the method toBufferedImage of file ColorMethods. In case we know that tile is RGBA format, we should make a trans in that method. Like this:

  def toBufferedImage: BufferedImage = {
    val bi = new BufferedImage(self.cols, self.rows, BufferedImage.TYPE_INT_ARGB)
    cfor(0)(_ < self.cols, _ + 1) { x =>
      cfor(0)(_ < self.rows, _ + 1) { y =>
        val v = self.get(x, y)
        val r = (v >> 24) & 0xFF
        val g = (v >> 16) & 0xFF
        val b = (v >> 8) & 0xFF
        val a = v & 0xFF
        bi.setRGB(x, y, a << 24 | r << 16 | g << 8 | b)
      }
    }
    bi
  }

but i cannot get a good jpg file. Might be my jvm or library goes wrong, hoping you guys make a try.

@pomadchin
Copy link
Member

pomadchin commented Aug 3, 2020

Hi @esmeetu that was exactly it! Should be fixed in terms of #3278 now.

cc @jdenisgiguere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants