Unicode Exif User Comment bad printing

Reported bugs that have been closed and/or resolved

Moderators: helmut, XnTriq, xnview, Dreamer

Post Reply
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Unicode Exif User Comment bad printing

Post by TesteurXnView »

XnView: MP 1.5.1 64 bit
OS: Windows

Unicode Exif User Comment(s) are printed as random Chinese characters (maybe a bad Unicode/UTF8 conversion ?) while ExifTool 12.51 prints the same information correctly.

Effect: The user can't see Exif user comment in explorer window.

To reproduce:
1. Add in Tools/Parameters/Explorer/Vignette the item "EXIF: User Comment"
2. Browse any PNG or JPG file with an Unicode Exif User Comment (as an example, download any image from https://image.civitai.com)

Actual behaviour (bug): Exif User Comment is displayed as random Chinese characters :bug:

Expected behaviour: The user comment is normaly displayed (as in the ExifTool 12.51).
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

please send us the file, i can't connect to your url
Pierre.
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Re: Unicode Exif User Comment bad printing

Post by TesteurXnView »

Hi Pierre,

I send you just 3 different files (the others are too big to be attached):

1. The first is a PNG image "00000-1192013237.png" with a Unicode tag "User Comment" and a ASCII/ANSI tag "Parameters" correctly shown both in ExifTool panel, just "User Comment" shown in Properties panel, and wrongly displayed in EXIF panel and vignette item "EXIF: User Comment" which apparently use both the EXIF module. In this case the "User Comment" is an "eXIf" chunk (in UNICODE format) and "Parameters" is an "tExt" chunk (in ASCII/ANSI format).

2. The second is a JPG image "geraldW3_prew1.jpg" with a Unicode tag "User Comment" correctly shown in ExifTool panel, not shown in Properties panel, and wrongly displayed in EXIF panel and vignette item "EXIF: User Comment" which apparently used both EXIF module.

3. The third is an PNG image "00088-3421647346.png" with a Unicode tag "Parameters" correctly shown in Properties panel (Extra->parameters") but there is no EXIF panel, correctly displayed by ExifTool panel (PNG->Parameters) and nothing to display as custom text of vignette. "Parameters" tag uses an "iTXt" chunk.

As I said, the error maybe come from EXIF module after a missing Unicode->UTF8 conversion...
These 3 files are typical files produced by almost all AI software nowadays and all these files have this kind of tags.
In all cases, ExifTool always gives the right answer!

Thank you for your time and your smart tool,
Chris

P.S. Additionally, you will see another small display bug for the third file in Properties panel, between "anatomy)" and "easynegative" as Extra->parameters Unicode tag uses some SC (simplified Chinese) characters and the default font used by Properties/ExifTools/EXIF panels do no have these characters: there is any way to change the default font used by these panels ? This is *only* a graphical bug, because when you copy the entry to Notepad++ or any browser you can see correctly all text.

P.S.2. Why "Extra->parameters" line in "Properties" panel is "auto-multi-line" (which is the smart way to print for the user) and the same information displayed in the "ExifTool" panel "PNG->Parameters" doesn't? Maybe a different way to deal with CR('\n') character...
Attachments
PNG file with Unicode tag "Parameters"
PNG file with Unicode tag "Parameters"
00088-3421647346.png (425.51 KiB) Viewed 10077 times
PNG file with Unicode tag "User Comment" and ASCII/ANSI tag "Parameters"
PNG file with Unicode tag "User Comment" and ASCII/ANSI tag "Parameters"
00000-1192013237.png (365.19 KiB) Viewed 10077 times
JPG file with Unicode tag "User Comment"
JPG file with Unicode tag "User Comment"
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

TesteurXnView wrote: Sat Jul 22, 2023 12:35 pm As I said, the error maybe come from EXIF module after a missing Unicode->UTF8 conversion...
These 3 files are typical files produced by almost all AI software nowadays and all these files have this kind of tags.
In all cases, ExifTool always gives the right answer!
The User Comment is not correct, EXIF is little endian and UserComment is big endian. I'll check how to detect if it's BE or LE order...
Pierre.
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Re: Unicode Exif User Comment bad printing

Post by TesteurXnView »

Hi Pierre,
YES, you're right: "geraltW3_prew1.jpg" is an "hybrid" file as it has a JFIF segment FFE0 and an EXIF segment FFE1. And in EXIF segment the "User comment" is in BE format. The same format as in PNG file "00000-1192013237.png".

I send you my screenshots for these 3 images.

As I said, and as you can see in these screenshots, ExifTools always gives the right answer for all tags ("User comment" and "parameters"). And I tested ExifTool separately in Windows console: same behavior as in XnView panel. The default output is in UTF8 format, independently of the original format ANSI/UTF8/Unicode BE/LE inside the image. Additionally, this matches with the native format of QString...

The only problem is just the EXIF module. And here, as I suppose this module is internal to XnView, I don't have the source code to help you. A "quick and dirty" way is to test if the majority of WCHARs in "User Comment" have a null LSB, in this case you switch between LSB/MSB... Or maybe, you can consider to enable ExifTool outputs for vignette items instead of EXIF module ? In Properties Panel you use ExifTool output too.

Chris
Attachments
ExifTool Panel for 00000-1192013237.png
ExifTool Panel for 00000-1192013237.png
EXIF Panel for 00000-1192013237.png
EXIF Panel for 00000-1192013237.png
Properties Panel for 00000-1192013237.png
Properties Panel for 00000-1192013237.png
ExifTool Panel for 00088-3421647346.png
ExifTool Panel for 00088-3421647346.png
Properties Panel for 00088-3421647346.png
Properties Panel for 00088-3421647346.png
ExifTool Panel for geraltW3_prew1.jpg
ExifTool Panel for geraltW3_prew1.jpg
EXIF Panel for geraltW3_prew1.jpg
EXIF Panel for geraltW3_prew1.jpg
Properties Panel for geraltW3_prew1.jpg
Properties Panel for geraltW3_prew1.jpg
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

TesteurXnView wrote: Mon Jul 24, 2023 1:28 pm The only problem is just the EXIF module. And here, as I suppose this module is internal to XnView, I don't have the source code to help you. A "quick and dirty" way is to test if the majority of WCHARs in "User Comment" have a null LSB, in this case you switch between LSB/MSB...
yes i'll try like that, but null LSB doesn't work for asian chars for example....
Pierre.
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Re: Unicode Exif User Comment bad printing

Post by TesteurXnView »

OK, then something more sophisticated:
This function computes the sum of absolute distance for successive Unicode characters (from input buffer) in both ways then compares results:

===========================
inline uint16_t SwapBytes(const uint16_t wch) { return uint16_t((wch >> 8) | (wch << 8)); }

inline bool IsUnicodeLE(const uint16_t* buf, size_t len)
{
uint32_t diffLE=0, diffBE=0;
uint16_t lastLE=buf[0], lastBE=SwapBytes(buf[0]);
for(size_t i=1; i<len; i++)
{
diffLE += (buf[i]<lastLE) ? (lastLE-buf[i]) : (buf[i]-lastLE);
uint16_t valBE=SwapBytes(buf[i]);
diffBE += (valBE<lastBE) ? (lastBE-valBE) : (valBE-lastBE);
lastLE=buf[i]; lastBE=valBE;
}
return diffLE<diffBE;
}
============================

For usual comments I think it works well (English, French, Chinese etc.)

Chris
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

See issue
Pierre.
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

This problem is supposed to be fixed in XnView MP 1.5.4. Please check and confirm the bug fix here.
Pierre.
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Re: Unicode Exif User Comment bad printing

Post by TesteurXnView »

Hi Pierre, and sorry for my late answer.

I checked on version 1.5.5: the Unicode Exif user comment is now correctly printed in EXIF panel (as it was in ExifTool panel)

BUT

the same user comment is always bad printed as vignette description if someone select user comment (the 2 Unicode bytes are wrongly swapped as in all previous versions of XnViewMP). You can use the same files I send to you in July ("00000-1192013237.png" and "geraltW3_prew1.jpg").

Bon courage,
Chris
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

issue reopened
Pierre.
User avatar
xnview
Author of XnView
Posts: 46235
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Unicode Exif User Comment bad printing

Post by xnview »

This problem is supposed to be fixed in XnView MP 1.6.0. Please check and confirm the bug fix here.
Pierre.
TesteurXnView
Posts: 9
Joined: Thu Jul 20, 2023 12:28 pm

Re: Unicode Exif User Comment bad printing

Post by TesteurXnView »

Hi Pierre,
I confirm that Unicode Exif user comments are now correctly displayed also as vignette/thumbnail labels in XnView MP version 1.6.0.
I discovered some other small bugs in Parameters/vignette/labels dialog box (non-releated to the current bug) so I will create another report.

Thank you again,
Chris
Post Reply