DirectXTex icon indicating copy to clipboard operation
DirectXTex copied to clipboard

Darkening when converting to BC7

Open Dimoks opened this issue 11 months ago • 7 comments

PNG with:

Results by item (  1) and mip (  1)

 Minimum - (0,000000 0,000000 0,000000 1,000000)
          Average - (0,453539 0,328506 0,274346 1,000000)
          Maximum - (1,000000 1,000000 1,000000 1,000000)
         Variance - (10361,523438 7514,796875 3659,034424 0,000000)
          Std Dev - (101,791565 86,687927 60,489952 0,000000)
        Luminance - 1,000000 (maximum)

texconv -y -f BC7_UNORM -ft dds -m 1 image.png

DDS:

Results by item (  1) and mip (  1)

          Minimum - (0,000000 0,000000 0,000000 0,984314)
          Average - (0,265290 0,151262 0,089996 0,999930)
          Maximum - (1,000000 1,000000 1,000000 1,000000)
         Variance - (10718,610352 5891,852539 1872,661865 0,038926)
          Std Dev - (103,530724 76,758400 43,274261 0,197297)
        Luminance - 1,000000 (maximum)
                Compression - BC7_UNORM
               Total blocks - 8025
             Mode 01 blocks - 3977
             Mode 03 blocks - 2185
             Mode 04 blocks - 549
             Mode 05 blocks - 450
             Mode 06 blocks - 832
             Mode 07 blocks - 32

Dimoks avatar Feb 23 '25 05:02 Dimoks

This seems like an issue related to SRGB vs. Linear. Is the BC7_UNORM content being rendered as SRGB or as Linear?

walbourn avatar Feb 24 '25 20:02 walbourn

texconv -y -f BC7_UNORM -ft dds -m 1 -srgbo image.png

Results by item ( 1) and mip ( 1)

      Minimum - (0,000000 0,000000 0,000000 0,984314)
      Average - (0,453349 0,328474 0,274358 0,999889)
      Maximum - (1,000000 1,000000 1,000000 1,000000)
     Variance - (10363,500977 7532,208984 3677,713623 0,076049)
      Std Dev - (101,801285 86,788300 60,644157 0,275769)
    Luminance - 1,000000 (maximum)
            Compression - BC7_UNORM
           Total blocks - 8025
         Mode 01 blocks - 5219
         Mode 03 blocks - 1278
         Mode 04 blocks - 761
         Mode 05 blocks - 228
         Mode 06 blocks - 470
         Mode 07 blocks - 69

Why doesn't it detect the output format automatically? This is very inconvenient for batch processing. Some images become lighter with -srgbo.

Dimoks avatar Feb 24 '25 22:02 Dimoks

Can you attach the image.png in question? You probably need to be using BC7_UNORM_SRGB as your output format.

walbourn avatar Feb 26 '25 01:02 walbourn

texconv -y -f BC7_UNORM_SRGB -ft dds -m 1 image.png

Results by item (  1) and mip (  1)

          Minimum - (0,000000 0,000000 0,000000 0,984314)
          Average - (0,265700 0,151264 0,090136 0,999889)
          Maximum - (1,000000 1,000000 1,000000 1,000000)
         Variance - (10710,864258 5889,501953 1871,927856 0,076049)
          Std Dev - (103,493309 76,743088 43,265781 0,275769)
        Luminance - 1,000000 (maximum)
                Compression - BC7_UNORM_SRGB
               Total blocks - 8025
             Mode 01 blocks - 5219
             Mode 03 blocks - 1278
             Mode 04 blocks - 761
             Mode 05 blocks - 228
             Mode 06 blocks - 470
             Mode 07 blocks - 69

Dimoks avatar Feb 26 '25 05:02 Dimoks

Declaring the sRGB format in image.png seems to correct the color in dds.

magick image.png -set colorspace sRGB image.png

texconv -y -f BC7_UNORM -ft dds -m 1 image.png

Results by item (  1) and mip (  1)

          Minimum - (0,000000 0,000000 0,000000 0,984314)
          Average - (0,460786 0,335521 0,280488 0,999896)
          Maximum - (1,000000 1,000000 1,000000 1,000000)
         Variance - (10343,784180 7622,896973 3820,479492 0,072577)
          Std Dev - (101,704399 87,309204 61,810028 0,269401)
        Luminance - 1,000000 (maximum)
                Compression - BC7_UNORM
               Total blocks - 8025
             Mode 01 blocks - 5370
             Mode 03 blocks - 1157
             Mode 04 blocks - 850
             Mode 05 blocks - 201
             Mode 06 blocks - 381
             Mode 07 blocks - 66

Dimoks avatar Feb 26 '25 07:02 Dimoks

Images with such exif became darker:

ExifTool	
ExifTool Version Number 	 12.85	
Warning 	 [minor] Trailer data after PNG IEND chunk	

File	
File Name 	 image.png	
Directory 	 ...
File Size 	 6.5 MB	
File Permissions 	 -rw-rw-rw-	
File Type 	 PNG	
File Type Extension 	 png	
MIME Type 	 image/png	

Composite	
Image Size 	 2576x1816	
Megapixels 	 4.7	

ICC_Profile	
Profile CMM Type 	 Linotronic	
Profile Version 	 2.1.0	
Profile Class 	 Display Device Profile	
Color Space Data 	 RGB	
Profile Connection Space 	 XYZ	
Profile Date Time 	 1998:02:09 06:49:00	
Profile File Signature 	 acsp	
Primary Platform 	 Microsoft Corporation	
CMM Flags 	 Not Embedded, Independent	
Device Manufacturer 	 Hewlett-Packard	
Device Model 	 sRGB	
Device Attributes 	 Reflective, Glossy, Positive, Color	
Rendering Intent 	 Perceptual	
Connection Space Illuminant 	 0.9642 1 0.82491	
Profile Creator 	 Hewlett-Packard	
Profile ID 	 0	
Profile Copyright 	 Copyright (c) 1998 Hewlett-Packard Company	
Profile Description 	 sRGB IEC61966-2.1	
Media White Point 	 0.95045 1 1.08905	
Media Black Point 	 0 0 0	
Red Matrix Column 	 0.43607 0.22249 0.01392	
Green Matrix Column 	 0.38515 0.71687 0.09708	
Blue Matrix Column 	 0.14307 0.06061 0.7141	
Device Mfg Desc 	 IEC http://www.iec.ch	
Device Model Desc 	 IEC 61966-2.1 Default RGB colour space - sRGB	
Viewing Cond Desc 	 Reference Viewing Condition in IEC61966-2.1	
Viewing Cond Illuminant 	 19.6445 20.3718 16.8089	
Viewing Cond Surround 	 3.92889 4.07439 3.36179	
Viewing Cond Illuminant Type 	 D50	
Luminance 	 76.03647 80 87.12462	
Measurement Observer 	 CIE 1931	
Measurement Backing 	 0 0 0	
Measurement Geometry 	 Unknown	
Measurement Flare 	 0.999%	
Measurement Illuminant 	 D65	
Technology 	 Cathode Ray Tube Display	
Red Tone Reproduction Curve 	 (Binary data 2060 bytes, use -b option to extract)	
Green Tone Reproduction Curve 	 (Binary data 2060 bytes, use -b option to extract)	
Blue Tone Reproduction Curve 	 (Binary data 2060 bytes, use -b option to extract)	

PNG	
Image Width 	 2576	
Image Height 	 1816	
Bit Depth 	 8	
Color Type 	 RGB with Alpha	
Compression 	 Deflate/Inflate	
Filter 	 Adaptive	
Interlace 	 Noninterlaced	
Gamma 	 2.2	
Profile Name 	 sRGB IEC61966-2.1	
White Point X 	 0.3127	
White Point Y 	 0.329	
Red X 	 0.64	
Red Y 	 0.33	
Green X 	 0.3	
Green Y 	 0.6	
Blue X 	 0.15	
Blue Y 	 0.06	
Pixels Per Unit X 	 3780	
Pixels Per Unit Y 	 3780	
Pixel Units 	 meters	

After magick image.png -set colorspace sRGB image.png:

ExifTool ExifTool Version Number 12.85 Warning [minor] Text/EXIF chunk(s) found after PNG IDAT (may be ignored by some readers)

File	
File Name 	 image.png	
Directory 	...
File Size 	 5.7 MB	
File Permissions 	 -rw-rw-rw-	
File Type 	 PNG	
File Type Extension 	 png	
MIME Type 	 image/png	

Composite	
Image Size 	 2576x1816	
Megapixels 	 4.7	

PNG	
Image Width 	 2576	
Image Height 	 1816	
Bit Depth 	 8	
Color Type 	 RGB with Alpha	
Compression 	 Deflate/Inflate	
Filter 	 Adaptive	
Interlace 	 Noninterlaced	
White Point X 	 0.3127	
White Point Y 	 0.329	
Red X 	 0.64	
Red Y 	 0.33	
Green X 	 0.3	
Green Y 	 0.6	
Blue X 	 0.15	
Blue Y 	 0.06	
Background Color 	 255 255 255	
Pixels Per Unit X 	 3779	
Pixels Per Unit Y 	 3779	
Pixel Units 	 meters	

Dimoks avatar Feb 26 '25 11:02 Dimoks

It would seem then that you are using DXGI_FORMAT_BC7_UNORM and assuming that data is in linear RGB space, but when you read the PNG file it is missing the sRGB colorspace marker so it's not converting from sRGB to Linear.

Is that correct?

walbourn avatar Feb 26 '25 19:02 walbourn