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

gfx4snes corruption for PNG files with a bit depth of 1 #275

Closed
undisbeliever opened this issue Apr 5, 2024 · 1 comment
Closed

gfx4snes corruption for PNG files with a bit depth of 1 #275

undisbeliever opened this issue Apr 5, 2024 · 1 comment

Comments

@undisbeliever
Copy link
Contributor

gfx4snes is not converting this PNG file correctly.

font-2bpp-gimp

Here is the command I am using to convert the file:

gfx4snes -R -s 8 -u 4 -p -t png -i font-2bpp.png

and this is output of a simple Hello World program using consoleInitText() and consoleDrawText().
pv-sound-test_000

I also see the same corruption when converting the file to a 4bpp tile format.


The PNG file was created with GIMP, it contains 2 colours in the colourmap and was exported to PNG using the automatic pixel format option.

Loading the PNG file in Aseprite and saving it to a new file causes gfx4snes to work as expected.

This is the output of the same Hello World program using the png file from Aseprite:
pv-sound-test_001

Comparing the two png files lead me to believe gfx4snes was unable to correctly load PNG files with bit-depth of 1.

ExifTool Version Number         : 12.76
File Name                       : font-2bpp-gimp.png
Directory                       : .
File Size                       : 542 bytes
File Modification Date/Time     : 2024:04:05 17:14:22+10:00
File Access Date/Time           : 2024:04:05 17:14:22+10:00
File Inode Change Date/Time     : 2024:04:05 17:38:06+10:00
File Permissions                : -r--r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 128
Image Height                    : 48
Bit Depth                       : 1
Color Type                      : Palette
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Palette                         : (Binary data 6 bytes, use -b option to extract)
Image Size                      : 128x48
Megapixels                      : 0.006
ExifTool Version Number         : 12.76
File Name                       : font-2bpp-aseprite.png
Directory                       : .
File Size                       : 773 bytes
File Modification Date/Time     : 2024:04:05 18:20:00+10:00
File Access Date/Time           : 2024:04:05 18:20:00+10:00
File Inode Change Date/Time     : 2024:04:05 18:20:00+10:00
File Permissions                : -r--r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 128
Image Height                    : 48
Bit Depth                       : 8
Color Type                      : Palette
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
SRGB Rendering                  : Perceptual
Palette                         : (Binary data 6 bytes, use -b option to extract)
Image Size                      : 128x48
Megapixels                      : 0.006

The following patch fixes gfx4snes for my PNG file. I do not know why pngstate.decoder.color_convert is 0, so I'm writing a bug report instead of submitting a PR.

diff --git a/tools/gfx4snes/src/images.c b/tools/gfx4snes/src/images.c
index c1a1029e..137d2275 100644
--- a/tools/gfx4snes/src/images.c
+++ b/tools/gfx4snes/src/images.c
@@ -106,8 +106,7 @@ void image_load_png(const char *filename, t_image *img, bool isquiet)
     // optionally customize the state
     lodepng_state_init(&pngstate);
 
-    // no conversion of color (to keep palette mode)  
-    pngstate.decoder.color_convert = 0;
+    pngstate.decoder.color_convert = true;
 
 	// always in 8 bits and palette mode
 	pngstate.info_raw.colortype=LCT_PALETTE;

PVSnesLib version: 4.2.0
OS: Linux x64

@alekmaul
Copy link
Owner

alekmaul commented Apr 14, 2024

Thanks, I will try this.
But, if I remember well, the color convert also damages the colors.
We will see.

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

No branches or pull requests

2 participants