Page 1 of 1

png2c script failed

Posted: Mon Jun 17, 2019 4:51 am
by ONEEYEMAN
Hi, ALL,
I have another weird issue.

I have an attached png file which I'm trying to process with png2c script.

I am running following:

Code: Select all

[email protected] ~/dbhandler/libdbwindow/res/gui $ python ~/wxFork/misc/scripts/png2c.py bold.png > bold_png.c
[
The content of the bold_png.c file is as follows:
"bold.png" doesn't seem to be a valid PNG file.
I also tried to load it with the image sample and it did load correctly.


Could anyone shed some light?

Thank you.

Re: png2c script failed

Posted: Mon Jun 17, 2019 8:30 am
by doublemax
I assume the script works with other PNGs? Then there must be something special about this particular one. Maybe the script doesn't like the color profile of the PNG.

Re: png2c script failed

Posted: Mon Jun 17, 2019 8:37 am
by alys666
There are online png->c converters, may be make a try with them. Maybe this script has some limitations for png format?

Re: png2c script failed

Posted: Mon Jun 17, 2019 9:11 am
by DavidHart
Hi,

FWIW, I tested the png using the wx3.1.3 png2c.py. With python 2.7 it ran normally and produced sensible output.

Testing with python 3.5, and after fixing several "Missing parentheses in call to 'print'" errors, I got the
"bold.png" doesn't seem to be a valid PNG file.
output. The same happened with all the other pngs that I tested.

So it seems to be a python3 issue. I don't speak python, but maybe the failing line:
if bytes[0:16].tostring() != '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR'
trips over another python 2->3 change...

Regards,

David

Re: png2c script failed

Posted: Tue Jun 18, 2019 12:09 am
by ONEEYEMAN
Hi, David et al,
I fixed the script and submitted the fix as PR.

If you have a chance please grab and test it. Leave a comment.

Thank you.

Re: png2c script failed

Posted: Tue Jun 18, 2019 9:43 am
by DavidHart
I hadn't realised you were already making wx python3-compatible...

I didn't test the PR itself, but I confirm that prefixing 'b' to that string fixes the script for 3.5 without breaking 2.7.

Re: png2c script failed

Posted: Tue Jun 18, 2019 3:17 pm
by ONEEYEMAN
David,
Thx for confirming.

Re: png2c script failed

Posted: Fri Jun 21, 2019 4:20 am
by Deluge
Not sure if it is a better alternative, but there is Binary to Header that converts any file's binary data into a C character array. So it's not limited to PNG images only.

Re: png2c script failed

Posted: Fri Jun 21, 2019 4:26 am
by ONEEYEMAN
Hi,
PR had been applied.

Thx for testing.