png2c script failed

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3607
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

png2c script failed

Post by ONEEYEMAN » Mon Jun 17, 2019 4:51 am

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.
Attachments
bold.png
bold.png (116 Bytes) Viewed 792 times

User avatar
doublemax
Moderator
Moderator
Posts: 14320
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: png2c script failed

Post by doublemax » Mon Jun 17, 2019 8:30 am

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.
Use the source, Luke!

alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 292
Joined: Tue Oct 18, 2016 2:31 pm

Re: png2c script failed

Post by alys666 » Mon Jun 17, 2019 8:37 am

There are online png->c converters, may be make a try with them. Maybe this script has some limitations for png format?
ubuntu 16.04, wxWidgets 3.0.4

DavidHart
Site Admin
Site Admin
Posts: 3907
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: png2c script failed

Post by DavidHart » Mon Jun 17, 2019 9:11 am

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

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3607
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: png2c script failed

Post by ONEEYEMAN » Tue Jun 18, 2019 12:09 am

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.

DavidHart
Site Admin
Site Admin
Posts: 3907
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: png2c script failed

Post by DavidHart » Tue Jun 18, 2019 9:43 am

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.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3607
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: png2c script failed

Post by ONEEYEMAN » Tue Jun 18, 2019 3:17 pm

David,
Thx for confirming.

User avatar
Deluge
Earned some good credits
Earned some good credits
Posts: 122
Joined: Fri Apr 30, 2010 4:52 am
Location: USA
Contact:

Re: png2c script failed

Post by Deluge » Fri Jun 21, 2019 4:20 am

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.
Projects:
Debreate
MyABCs
Stendhal

OSes:
Windows 10 Home (missing my Linux & Freebsd :()

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3607
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: png2c script failed

Post by ONEEYEMAN » Fri Jun 21, 2019 4:26 am

Hi,
PR had been applied.

Thx for testing.

Post Reply