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

Examples: Remove broken iCCP chunks in some PNG files. #28564

Merged
merged 1 commit into from
Jun 8, 2024

Conversation

chirsz-ever
Copy link
Contributor

@chirsz-ever chirsz-ever commented Jun 5, 2024

The modified PNG files had broken iCCP chunks (CRC32 check failed).

All iCCP chunks in the image files are removed.

They are data encoded in textures, so the normal sRGB iCCP chunks are
also be removed.

@WestLangley
Copy link
Collaborator

They have normal iCCP chunks with sRGB colorspace.

The profiles are not honored in three.js, but FWIW, the normal and roughness texture files are assumed to be encoded with a linear transfer function -- not sRGB.

@mrdoob
Copy link
Owner

mrdoob commented Jun 6, 2024

What other colorspaces does iCCP support?

@chirsz-ever
Copy link
Contributor Author

FWIW, the normal and roughness texture files are assumed to be encoded with a linear transfer function -- not sRGB.

Yes, I think the loader read the image as is, and this PR or the sRGB profile would not affect it.

const clearcoatNormalMap = textureLoader.load( 'textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png' );

What other colorspaces does iCCP support?

Any. On the Internet, most of pictures use sRGB colorspace, and sRGB is the default colorspace for images not annotated with colorspace information1. Recently, Display-P3 photos account for a certain proportion. I see Three.js has a wide-gamut example to test Display-P3 colorspace2.

Footnotes

  1. For JPEG this is specified in the standard. For PNG this is the de facto standard: see this issue, the first image looks darker than other images, because it uses linear colorspace without any colorspace annotation, but your browser interprets it as sRGB.

  2. https://github.com/mrdoob/three.js/blob/ec0f9f8acc0b846998c4b9dc1a2afb6e7a66f8a1/examples/webgl_test_wide_gamut.html

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 8, 2024

FWIW, the normal and roughness texture files are assumed to be encoded with a linear transfer function -- not sRGB.

Yes, I think the loader read the image as is, and this PR or the sRGB profile would not affect it.

In this case, can't we just remove the iCCP chunks from both png files? I don't understand the value of adding meta data when they are ignored anyway.

The modified PNG files had broken iCCP chunks (CRC32 check failed).

All iCCP chunks in the image files are removed.

They are data encoded in textures, so the normal sRGB iCCP chunks are
also be removed.
@chirsz-ever chirsz-ever force-pushed the chirsz/fix-png-iccp branch from 255e868 to 2a754f7 Compare June 8, 2024 09:00
@chirsz-ever
Copy link
Contributor Author

chirsz-ever commented Jun 8, 2024

@Mugen87 What you said is very reasonable. Now all iCCP chunks are removed. You can use pnginfo.py in this repo to verify it.

For example, for examples/textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png:

Before:

b'IHDR', offset=8
  Width: 1024
  Height: 1024
  Bit Depth: 8
  Color Type: Truecolor
b'zTXt', offset=33
    Keywords: Raw profile type exif
    Content: (628 bytes)
crc_saved=1202812110, crc_calc=528595506
b'iCCP', offset=277, CRC32 check failed
b'iTXt', offset=8181
b'iCCP', offset=12029
  Profile Name: sRGB
  Compressed Profile: 8440 bytes
  Profile: 8940 bytes
  desc: sRGB
b'IEND', offset=1159550

Now:

b'IHDR', offset=8
  Width: 1024
  Height: 1024
  Bit Depth: 8
  Color Type: Truecolor
b'zTXt', offset=33
    Keywords: Raw profile type exif
    Content: (628 bytes)
b'iTXt', offset=277
b'IEND', offset=1143188

@Mugen87 Mugen87 added this to the r166 milestone Jun 8, 2024
@Mugen87 Mugen87 merged commit 001fd89 into mrdoob:dev Jun 8, 2024
11 checks passed
@Mugen87 Mugen87 changed the title Examples: Fix broken iCCP chunks in some PNG files Examples: Remove broken iCCP chunks in some PNG files. Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants