Error saving PNG

Bugs found in XnView Classic. Please report only one bug per topic!

Moderators: XnTriq, helmut, xnview

User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Error saving PNG

Post by Ty »

Hi Pierre or whomever--

I just downloaded XnView/Win version 2.33 and immediately had a problem that I've never seen before--and I've been using XnView a long time.

When trying to save a newly-scanned image as a .PNG file, I get the message "Error writing the file <C:\Users\OneDrive\Desktop\test3.png>"

I can save as JPG okay.

I can open an existing image and save it as PNG okay.

I've attached the actual Windows (8.1, 64-bit) error message, and would be happy to do some more research if you want to suggest something.

But I have never had any any trouble saving a PNG image under any circumstances in the past many years.
You do not have the required permissions to view the files attached to this post.
User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Re: Error saving PNG

Post by Ty »

I've also tested saving to a more conventional directory, such as c:\ashell, and had the same results. So the problem is NOT some weird thing involving OneDrive.
User avatar
XnTriq
Moderator & Librarian
Posts: 6388
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Error saving PNG

Post by XnTriq »

I'm not able to reproduce this problem :?
XnView v2.33 ([color=green]I[u]n[/u]fo[/color] » [color=green]About...[/color]) wrote:The PNG functions are based in part on the work of the Group 42, Inc
According to XnView's changelog (WhatsNew.txt), libpng was last updated in v2.10.
We've had a report that “certain PNGs cannot be saved” due to a “known incorrect sRGB profile”, but the issue was fixed in v2.13.
cday
XnThusiast
Posts: 4187
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Error saving PNG

Post by cday »

Ty wrote:When trying to save a newly-scanned image as a .PNG file, I get the message "Error writing the file <C:\Users\OneDrive\Desktop\test3.png>"

...

I've attached the actual Windows (8.1, 64-bit) error message, and would be happy to do some more research if you want to suggest something
Are you able to confirm that the issue is specific to Windows 8.1?
User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Re: Error saving PNG

Post by Ty »

HI cday and XnTriq, thanks for the replies. No, cday, I can't confirm that this is a Win 8.1 problem; that's the only environment I have. I did discover that the problem seems to be related to some characteristics of the original file. In other words, if I open an existing JPG file in XnView and then try to save it as a PNG, I sometimes experience the problem, other times don't. My experimenting has led to the discovery of another problem, which presumably is related: XnView sometimes gives the error "Error opening the file <filename>" when opening PNGs. This new behavior also, have never seen this in many years of using XnView.

I think something weird is going on here, it may not be an XnView problem. Perhaps there is a problem in the installation program, or some registry values got messed up on the re-install, or something. XnView has always been very "well behaved" and now it's acting oddly, maybe there's something about my environment that's the problem. I'll post more info if I discover anything of interest or value, but I think you should not spend any more time on this. The circumstances are too odd!

Thanks very much for your comments.
User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Re: Error saving PNG

Post by Ty »

PS. One thing I can confirm is definitely a bug: when I get the error message when trying to save an image as PNG, XnView creates a file anyway. It has nothing in it, 0 bytes, and of course gives an error when I try to open it with XnView or any other image program. This is definitely a bug--no program should write known-to-be-bad files to disk.
005.png
You do not have the required permissions to view the files attached to this post.
User avatar
XnTriq
Moderator & Librarian
Posts: 6388
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Error saving PNG

Post by XnTriq »

Ty wrote:when I get the error message when trying to save an image as PNG, XnView creates a file anyway. It has nothing in it, 0 bytes, and of course gives an error when I try to open it with XnView or any other image program.
May I ask what model your scanner is? Do you save scanned images via Save As... or Export...?
unkhum ([url=http://newsgroup.xnview.com/viewtopic.php?p=115670#p115670]2.12 XnView: PNG resize[/url]) wrote:I have a PNG file and I need to change the resolution. When I save the modified file (in PNG, as original), its size is 0 byte :(
User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Re: Error saving PNG

Post by Ty »

Of course you may ask! I use three different scanners: Epson XP410 all-in-one, Epson Perfection V300, and a Fujitsu ScanSnap 1300. Having never had any problems with them in several years' use, and using them with other programs besides XnView, I would say there is no reason to suspect them of contributing any problems. And just to add a friendly reminder, my problems began ONLY when I installed XnView/Win 2.33 yesterday.

But please, as I said, don't waste any time on this. Something weird--possibly environmental--is going on, and I'll probably discover what it is. Eventually. Maybe. :)
User avatar
XnTriq
Moderator & Librarian
Posts: 6388
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Error saving PNG

Post by XnTriq »

Okey-dokey, let's leave it at that for now. :mrgreen:
Just for the record: Zero-length output is a known issue with libpng, and I was assuming that this had been fixed in a previous release of XnView.
cday
XnThusiast
Posts: 4187
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Error saving PNG

Post by cday »

XnTriq wrote:
ArchWiki ([url=https://wiki.archlinux.org/index.php/Libpng_errors]Libpng errors[/url]) wrote:Some changes in libpng 1.6+ cause it issue warning or even not work correctly with the original HP/MS sRGB profile.
The LibPNG home page contains this text:
The current public release, libpng 1.6.17 ... fixes an incorrect alpha calculation in 8-bit-linear to sRGB conversion ...
So updating libpng may fix that part of the problem.

The current version is in fact the recently released 1.6.18, which can be downloaded from Sourceforge .
User avatar
Ty
Posts: 152
Joined: Thu Feb 23, 2006 3:18 am
Location: San Luis Obispo, California

Re: Error saving PNG

Post by Ty »

Here's one test that's easy and quick: see attached file.

When I open the JPG file with XnView and then try to save it as PNG, I get an error every time. Perhaps if you get the same error, or don't get it, that will tell us something. This file was NOT originally created by XnView, but rather by the program "VueScan."
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 4187
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Error saving PNG

Post by cday »

Ty wrote:Here's one test that's easy and quick: see attached file.

When I open the JPG file with XnView and then try to save it as PNG, I get an error every time. Perhaps if you get the same error, or don't get it, that will tell us something. This file was NOT originally created by XnView, but rather by the program "VueScan."
I don't seem to have any problem saving the above JPG in various versions of XnView on Windows 7 x64...
file_php_XnView_2.33_ZIP.png
Did you see my previous post about a LibPNG update that may be relevant to one of your problems?
You do not have the required permissions to view the files attached to this post.
User avatar
XnTriq
Moderator & Librarian
Posts: 6388
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Error saving PNG

Post by XnTriq »

Thanks for providing us with a sample, Ty.
As expected, 2015-07-25-0001.jpg uses one of those ICC profiles which are considered “incorrect” by libpng v1.6+: HP's sRGB IEC61966-2.1 (tested with Jeffrey Friedl's Image Metadata Viewer and confirmed with PhotoME + Stuffware Photo Studio).
p126891.png
Recommended workaround (until we have a fix):
XnTriq ([url=http://newsgroup.xnview.com/viewtopic.php?p=123257#p123257]certain PNGs cannot be saved[/url]) wrote:XnView will resave sample.png without error, if Use ICC Embedded Profile (JPEG/TIFF) - Very slow (Tools » Options... » General » ICC) is activated.
This will also allow the conversion of your VueScan JPEG to PNG.
cday wrote:The LibPNG home page contains this text:
The current public release, libpng 1.6.17 ... fixes an incorrect alpha calculation in 8-bit-linear to sRGB conversion ...
So updating libpng may fix that part of the problem.
I'm not sure that'll do the trick:
[color=green]libpng-1.6.17-README.txt[/color] wrote:Fixed simplified 8-bit-linear to sRGB alpha. The calculated alpha value was wrong. It's not clear if this affected the final stored value; in the obvious code path the upper and lower 8-bits of the alpha value were identical and the alpha was truncated to 8-bits rather than dividing by 257 (John Bowler).
John Bowler (GNOME Bugzilla » [url=http://bugzilla.gnome.org/show_bug.cgi?id=721135#c45]Unable to export to .png - libpng error: known incorrect sRGB profile[/url]) wrote:It needs to go to the discussion list because you and Graeme are questioning policy decisions. Libpng bug reports can't handle such things.

(1) When we encounter the old HP/MS profile that was written on the assumption that the user was adapted to D50 light do we regard it as sRGB, warn about it, refuse to allow it to be written out again by default? (We currently warn on read and error on app (benign) error on write, that's a warning with gimp.)

(2) When we encounter a profile that has the MD5 signature of one of the new ICC ones do we validate the profile checksum (which we use for older v2 profiles) and if we do and get a mismatch, do we issue a warning or an error and, if so, what is the wording? The current behavior is to issue a chunk error which can be ignored (and currently is by gimp.)

View the libpng home page for more information (http://www.libpng.org)
glennrp (ImageMagick Forums » [url=http://www.imagemagick.org/discourse-server/viewtopic.php?t=23214&p=97353#p97353]libpng-1.6.x rejects the sRGB profile in logo[/url]) wrote:Libpng-1.6.x does more checking of ICC profiles and in particular rejects some "sRGB" profiles that were previously acceptable to ImageMagick. The profile embedded in "logo:" is among them.

[…]

I'm getting more than just a warning. "convert" doesn't write an output PNG. I got the same behavior with ImageMagick built with libpng-1.6.1 and running with the 1.6.2beta02 shared library.

I have checked in a simple fix (adding a call to png_set_benign_errors()) that causes IM to issue a warning instead of an error.

With the fix […] logo.png is written without an iCCP chunk.
You do not have the required permissions to view the files attached to this post.
User avatar
XnTriq
Moderator & Librarian
Posts: 6388
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Error saving PNG

Post by XnTriq »

I run into the same problem (“Error writing the file”) if Use ICC Embedded Profile (JPEG/TIFF) is deactivated and I try to save layers (Tools » Multipage file » Extract All Into...) from a color-managed PSD (sRGB IEC61966-2.1) in PNG format.

xnview.ini for v2.33:

Code: Select all

[Cache]
IsActive=0
SavingMode=1

[Start]
ParamsSavingMode=1
SavingMode=1
p127249.zip
Glenn Randers-Pehrson ([url=http://www.stackoverflow.com/questions/30709056#30710304]libpng warning: iCCP: Not recognizing known sRGB profile that has been edited[/url]) wrote:As the warnings say, you have a bunch of PNG files with invalid color profiles. Libpng16 issues warnings about them. Your application treats warnings as errors.

To work around this, you can do one or more of the following:
  • Use a PNG editor to remove the iCCP chunk from the PNG files listed in the error report, e.g., with ImageMagick's "convert -define png:exclude-chunk=iCCP,zCCP"
  • Use a PNG editor to remove all ancillary chunks, e.g., convert -strip
  • Downgrade your libpng to version 1.5.x (currently libpng-1.5.23)
  • Reinstall libpng-1.6.x (currently libpng-1.6.17) with "-DPNG_sRGB_PROFILE_CHECKS=-1"
  • Find out if there is a way to have your application treat warnings as warnings, not errors, and do that.
Stack Overflow (User profile for [url=http://stackoverflow.com/users/2031419]Glenn Randers-Pehrson[/url]) wrote:Coauthor of PNG spec, developer/maintainer of libpng, on development teams for ImageMagick and GraphicsMagick. Author of pngcrush. Maintains PNG support in Firefox.
You do not have the required permissions to view the files attached to this post.
User avatar
xnview
Author of XnView
Posts: 44926
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Error saving PNG

Post by xnview »

LIBPNG check for old bad icc profile now. i'll skip it
Pierre.