Discussion:
PNG file corrupted by ASCII conversion
Edzard Egberts
2012-05-04 07:53:44 UTC
Permalink
I'm not sure, whether this problem comes from fltk, but maybe someone
knows it:

I'm using a write_png() function and it works under Linux. But after
compiling it for MS-Windows, the software also writes png-files, but
it's not possible to open them - "PNG file corrupted...".

The only difference regards the libraries for "#include <zlib.h>" and
"#include <png.h>". For Linux it uses the libraries from system and
includes "libpng.a" and "libz.a". For MS-Windows it uses the header
files from "fltk/png" and "fltk/zlib" and it includes "libfltk_png.a"
and "libfltk_zlib.a".

Where could the problem come from? Maybe related to utf8? How to go on?
Albrecht Schlosser
2012-05-04 08:47:57 UTC
Permalink
Post by Edzard Egberts
I'm not sure, whether this problem comes from fltk, but maybe someone
I'm using a write_png() function and it works under Linux. But after
compiling it for MS-Windows, the software also writes png-files, but
it's not possible to open them - "PNG file corrupted...".
The only difference regards the libraries for "#include <zlib.h>" and
"#include <png.h>". For Linux it uses the libraries from system and
includes "libpng.a" and "libz.a". For MS-Windows it uses the header
files from "fltk/png" and "fltk/zlib" and it includes "libfltk_png.a"
and "libfltk_zlib.a".
Where could the problem come from? Maybe related to utf8? How to go on?
How did you open the file? On Windows you must open a file explicitly
as text or binary - one of them is the default, but who knows ? ;-)
I'd guess the default is text, and you need the binary open for PNG
files, like

outfile = fopen (filename, "wb");

Otherwise all LF characters (binary 10) would be converted to CR/LF
on write.

Albrecht
Edzard Egberts
2012-05-04 09:27:20 UTC
Permalink
Post by Albrecht Schlosser
Post by Edzard Egberts
I'm not sure, whether this problem comes from fltk, but maybe someone
Where could the problem come from? Maybe related to utf8? How to go on?
How did you open the file? On Windows you must open a file explicitly
as text or binary - one of them is the default, but who knows ? ;-)
Hmpf - the default is text and I know this, but forgot to take care
about. Very stupid, of course it works now...
MacArthur, Ian (SELEX GALILEO, UK)
2012-05-04 09:36:23 UTC
Permalink
Post by Edzard Egberts
Hmpf - the default is text and I know this, but forgot to take care
about. Very stupid, of course it works now...
For what it's worth, I just use "rb" and "wb" regardless of platform since the *nix versions ignore the "b" anyway...



SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Edzard Egberts
2012-05-04 12:25:57 UTC
Permalink
Post by MacArthur, Ian (SELEX GALILEO, UK)
Post by Edzard Egberts
Hmpf - the default is text and I know this, but forgot to take
care about. Very stupid, of course it works now...
For what it's worth, I just use "rb" and "wb" regardless of platform
since the *nix versions ignore the "b" anyway...
This doesn't seem to work for me. I'm writing scientific software for
1,5 years now and all the files had been textfiles. So normally the same
code works for Linux and MS-Windows, but if using "b" option, the line
end is wrong for MS-Windows (just tried it).

Anyway it's my job to take care of such details and I should have seen
it for myself. :o/
MacArthur, Ian (SELEX GALILEO, UK)
2012-05-04 12:38:23 UTC
Permalink
Post by Edzard Egberts
Post by MacArthur, Ian (SELEX GALILEO, UK)
For what it's worth, I just use "rb" and "wb" regardless of platform
since the *nix versions ignore the "b" anyway...
This doesn't seem to work for me. I'm writing scientific software for
1,5 years now and all the files had been textfiles. So normally the same
code works for Linux and MS-Windows, but if using "b" option, the line
end is wrong for MS-Windows (just tried it).
Ah, sorry, I was too vague; I should have said *for any binary file* regardless of platform... Sorry...




SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Greg Ercolano
2012-05-04 15:58:11 UTC
Permalink
Post by MacArthur, Ian (SELEX GALILEO, UK)
Post by Edzard Egberts
Hmpf - the default is text and I know this, but forgot to take care
about. Very stupid, of course it works now...
For what it's worth, I just use "rb" and "wb" regardless of
platform since the *nix versions ignore the "b" anyway...
I like to put the #ifdef in there just so that, someday,
the code could read:

// OBSOLETE
// Microsoft was purchased by Apple, and replaced with Unix. - 02/24/2016
//
//#ifdef _WIN32
// fp = fopen(filename, "wb");
//#endif
fp = fopen(filename, "w");
//#else
Edzard Egberts
2012-05-07 06:59:41 UTC
Permalink
Post by Greg Ercolano
Post by MacArthur, Ian (SELEX GALILEO, UK)
Post by Edzard Egberts
Hmpf - the default is text and I know this, but forgot to take care
about. Very stupid, of course it works now...
For what it's worth, I just use "rb" and "wb" regardless of
platform since the *nix versions ignore the "b" anyway...
I like to put the #ifdef in there just so that, someday,
// OBSOLETE
// Microsoft was purchased by Apple, and replaced with Unix. - 02/24/2016
I don't think, Steve Jobs will come back to save Apple a third time.
Anyway Windows 8 will be an operating system for mobile phones (that's
funny, we will need to boot and shutdown our phones :o), so Unix/Linux
will be the last remaining PC operating system (Matthew 20:16 "So the
last will be first, and the first will be last." :o)
MacArthur, Ian (SELEX GALILEO, UK)
2012-05-07 09:58:27 UTC
Permalink
Post by Edzard Egberts
I don't think, Steve Jobs will come back to save Apple a third time.
Though I guess we'd be pretty impressed if he did. And perhaps a little surprised... and a bit freaked out...
Post by Edzard Egberts
Anyway Windows 8 will be an operating system for mobile phones (that's
funny, we will need to boot and shutdown our phones :o), so Unix/Linux
will be the last remaining PC operating system (Matthew 20:16 "So the
last will be first, and the first will be last." :o)
SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Loading...