What color becomes a transparent area when saved to a non-alpha format?

Older bugs which are supposed to be fixed in 0.84. *** Please try to reproduce your bug and confirm the bug fix. ***

Moderator: Dreamer

Post Reply
dietmar
Posts: 101
Joined: Fri Oct 25, 2013 4:55 pm

What color becomes a transparent area when saved to a non-alpha format?

Post by dietmar » Thu Mar 01, 2018 5:03 pm

Hi Pierre,

I have a bunch of PNGs which need to become JPGs. Many of these PNGs have transparent areas.
JPG doesn't know transparency, so the transparent areas must be colored somehow.
Could you please explain the algorithm used to decide which color is used?
I have some PNGs the transparent background becomes white, others where the transparent background becomes black.
And even more strange is that when you add text during batch convert, you'll get JPG where some parts of the background become black and others become white. Attached is a sample which is completely messed up.

Regads
Dietmar
Attachments
Sheldon_Acetate_Trumbull_st_Ecuadors.jpg
Image after batch converted to JPG with text added
Last edited by dietmar on Mon Mar 12, 2018 12:55 pm, edited 1 time in total.

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Sun Mar 04, 2018 4:57 pm

dietmar wrote: I have some PNGs the transparent background becomes white, others where the transparent background becomes black.
could you post one of each?
And even more strange is that when you add text during batch convert, you'll get JPG where some parts of the background become black and others become white. Attached is a sample which is completely messed up.
do you use alpha for text?
Pierre.

dietmar
Posts: 101
Joined: Fri Oct 25, 2013 4:55 pm

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by dietmar » Sun Mar 04, 2018 5:31 pm

xnview wrote: could you post one of each?
Pierre,
if you take the PNG from my original post, you'll see that the top and bottom parts become black while the center parts become white. If I remember correctly, this is how I had the image in GIMP before making the outer region transparent.
Thus it looks as if this information is still in the PNG and that you simply remove the alpha channel. Might this be? If I remove the alpha channel in GIMP, I'll get a white background, though.
Attached are two small PNGs with transparency in their top right corners. Take each and Convert To JPEG. One background becomes black, the other becomes white.
xnview wrote: do you use alpha for text?
I had used the Text option in Batch Convert. Text opacity 70%, color gray, no border, no fill, no outline, shadow black.
In any case I would expect that the text get's added AFTER the transparency of the original image got lost.

Regards
Dietmar
Attachments
Sheldon_title.png
Sheldon_title.png (155.39 KiB) Viewed 876 times
Sheldon_Promo_label.png
Sheldon_Promo_label.png (30.3 KiB) Viewed 876 times

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Tue Mar 06, 2018 2:26 pm

dietmar wrote: if you take the PNG from my original post, you'll see that the top and bottom parts become black while the center parts become white. If I remember correctly, this is how I had the image in GIMP before making the outer region transparent.
Thus it looks as if this information is still in the PNG and that you simply remove the alpha channel. Might this be? If I remove the alpha channel in GIMP, I'll get a white background, though.
Attached are two small PNGs with transparency in their top right corners. Take each and Convert To JPEG. One background becomes black, the other becomes white.
If you check the picture without alpha channel, you can see that background is not the same
I had used the Text option in Batch Convert. Text opacity 70%, color gray, no border, no fill, no outline, shadow black.
In any case I would expect that the text get's added AFTER the transparency of the original image got lost.
there is an error in the conversion for jpeg, alpha channel is removed not merged...
you can add a 'convert depth'=> truecolor action
Pierre.

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Tue Mar 06, 2018 2:39 pm

:bugconfirmed: Thanks to your detailed description I can reproduce the problem.
Pierre.

dietmar
Posts: 101
Joined: Fri Oct 25, 2013 4:55 pm

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by dietmar » Tue Mar 06, 2018 3:16 pm

xnview wrote::bugconfirmed: Thanks to your detailed description I can reproduce the problem.
Which brings back my original question: "What color becomes a transparent area when saved to non-alpha format?"

If you now correctly merge the alpha channel instead of removing it, there are still multiple options. Given a 100% transparent area as in my examples, saving to a non-alpha-capable format such as JPEG, you need to decide on a background color. You cannot use a background "behind" the completely transparent area as in my PNGs since the user may not even know that there is one. So should a 100% transparent area become white (or black or red or checkered)? In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.

Kind regards
Dietmar

User avatar
XnTriq
Moderator & Librarian
Posts: 5317
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by XnTriq » Tue Mar 06, 2018 10:45 pm

dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
I support Dietmar's request.

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Sat Mar 10, 2018 2:11 pm

XnTriq wrote:
dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
I support Dietmar's request.
Isn't better to use 'change color depth', and add a background color (when converting in 24bits)?
Pierre.

dietmar
Posts: 101
Joined: Fri Oct 25, 2013 4:55 pm

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by dietmar » Sun Mar 11, 2018 8:48 am

xnview wrote:
XnTriq wrote:
dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
I support Dietmar's request.
Isn't better to use 'change color depth', and add a background color (when converting in 24bits)?
Could be. GIMP has a simple function called 'remove alpha channel'. But this also requires the user to select a background color - GIMP's standard background color in this case.

Maybe XNVIEW should also have a selectable 'standard background color'. The draw function has a background color, the rotate function has a background color, the remove alpha channel needs one. Maybe you can place the foreground/background color selection at a more prominent place, e.g. the toolbar, and use the current setting for all functions which need a background color.

Regards
Dietmar

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Sun Mar 11, 2018 10:11 am

i means in batch convert?
Pierre.

dietmar
Posts: 101
Joined: Fri Oct 25, 2013 4:55 pm

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by dietmar » Sun Mar 11, 2018 4:15 pm

xnview wrote:i means in batch convert?
'Change color depth' has the same options in batch convert as in dialog. So a background color selection would be needed for both.

I'm not sure if an ordinary user will understand that saving as JPG implicitly does Change Color Depth to 24-bits, though.

Regards
Dietmar

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Mon Mar 12, 2018 12:30 pm

ok, issue
Pierre.

AlexSikorsky
Posts: 10
Joined: Sat Feb 03, 2018 9:07 am

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by AlexSikorsky » Fri Mar 30, 2018 9:44 pm

How much do you lose, if instead of the range for printing 0 ~ 255 get 0 ~ 254 or 1 ~ 255? especially when you consider that in a number of printers there is white ink that will print white as "white" color! From that, transparency is needed! What do we do for this? we shift the brightness of the entire picture to +1 or -1 and crop the image by an alpha channel or a template file, assigning a transparent black color for the printers, which is printed for white, and white for all others (will printers print a 1% point? inks, that is not present and this color will remain white, and for RGB, this is 254-254-254). Then again we shift the picture, but already in the opposite direction to the lightness, when our file is saved with transparency.

And you can, not move everything, but only replace all the colors 255-255-255. 254-255-255, 255-254-255 and 255-255-254 at 254-254-254, and then what you need to mask assign as 255-255-255, and exactly the opposite, when we do it in black .

This decision, which was applied in practice. To implement it, you need to add an option to add an image to the mask template, i.e. crop and make a certain area transparent if it is * .png or index the colors and assign a transparent color to * .jpg, which is excluded by the alpha channel or mask by the shift method that I described above, but then you need to store and template files - binary or in GrSc, like * .png

In order not to shift the entire range of tones by levels, you can apply the HALD CLUT and change only the white or black color.
*- [ coment ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.bat - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nconvert -icc_bcp -icc_intent 1 -icc_in "C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" -icc_out"C:/Windows/System32/spool/drivers/color/sRGB2014.icc" -dpi 300 [Levels input 255 to 254] -replace 0 0 0 1 1 1 [Mask to img, color W] -replace 255 255 255 0 0 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.xbs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<?xml version="1.0" encoding="UTF-8"?><XnView_script version="1.0" name="Mask_to_iImage">
<ICC_convert input_profile="C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" output_profile="C:/Windows/System32/spool/drivers/color/sRGB2014.icc" rendering="1" ignore_embedded="false" black_compensation="true" active="false"/>
<Set_DPI x="300" y="300" keep="false" active="false"/>
<Levels in_low="0,0,0,0," in_high="255,255,255,255," out_low="0,0,0,0," out_high="254,255,255,255," gamma="1,1,1,1," mode="0"/>
<Replace_color src_color="#000000" dst_color="#010101" tolerance="1"/>
<Add_mask filename="D:/Docs/Downloads/XnViewMP-win-x64/Version090/AddOn/Masks/S-2018-Alfa_MaskP.png" color="#ffffff" opacity="100" blur="false" stretch="true" usealpha="false"/>
<Replace_color src_color="#ffffff" dst_color="#000000" tolerance="0"/>
<Output folder="" filename="{Filename}_1" case="0" startIndex="1" format="PNG">
<Options overwrite="1" orgDate="false" keepMeta="true" keepICC="true" keepFolder="false" keepParentFolder="false" delOrg="false" multipage="false" allPages="false" openExplorer="false" openBrowser="false" clearItems="false"/>
<PNG level="0" interlaced="false" filter="0"/>
</Output>
</XnView_script>
Attachments
00009.PNG
00008.PNG

AlexSikorsky
Posts: 10
Joined: Sat Feb 03, 2018 9:07 am

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by AlexSikorsky » Fri Mar 30, 2018 11:37 pm

result with indexed colors, where black is assigned transparent and with an alpha channel in RGB.

!To ensure that the final file does not have a white edge, in the place where the anti-aliasing was done, the mask should be binary in color.!
Attachments
Screen-GIF-128color_xnv_New.gif
gif-128 index color (gif) sRGB
Screen-256Mask_xnv_New.png
256 index color (png8) sRGB
Screen-RGB_MaskAlpha_xnv_New.png
RGB + Alpha Chenal (png24) sRGB

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

Re: What color becomes a transparent area when saved to a non-alpha format?

Post by xnview » Thu Jun 07, 2018 9:46 am

This problem is supposed to be fixed in XnView MP 0.91. Please check and confirm the bug fix here.
Pierre.

Post Reply