Skip to main content
Participant
August 7, 2013
Answered

Creating premultiplied alpha channels with png and other formats

  • August 7, 2013
  • 2 replies
  • 37739 views

Hello,

I'm in a process of making assets for Unity3D engine and I'm making transparent png's with alpha channels premultiplied with black. My questions:

  1. To this day I've been using superPNG plugin to add alpha channel because it was really hard to find option to do it in Save As... menu. Today very very accidentally I've found Export -> Render Video where I can choose PNG and premultiplication. Am I doing something wrong or is it the proper Photoshop way to export png via video function? It seems really hidden!
  2. I can do the same for TIFF, PICT(i suppose no pict for me because its pure mac extension?), and tga format with one black layer and ticking Alpha Channels box, but its somehow greyed out for PNG? Why is that?

I think its some kind of inconsistency, or am I missing something?

Thank You for your time,

Peter

Correct answer Chris Cox

PNG, the format standard, does not support alpha channels, only a single transparency channel.

PNG only allows 4 channels, and that fourth channel is transparency.

Some video software packages misuse PNG and treat it as premultiplied, even though the file spec. says it must be straight color.

You could save yourself a lot of trouble by skipping the alpha channels and just saving your PNG after step 1.

Yes, if you messed with the alpha channel and color values you might have ended up with a file that looks like premultiplied values (since you wrote all zeros into the color channel, but didn't need to).

2 replies

Participating Frequently
March 10, 2022

The alpha channel of png is just that.  Calling it transparency is just syntax.  We don't need 25 alpha channel support to be added to PNG, we just need the one to work better in Photoshop.   And premultiplied alpha is the norm for internal rendering of Illustrator and most image and vector rendering tools.   Blending is perfectly fine in premultiplied space with all blend modes, but the formulas change (see post on Iggy blend modes).   To suggest otherwise is disingenuous.

 

It's currently unclear that Photoshop does correct srgb premultiplied alpha.  Png import/export ignores sRGB flags, and the values seem to just be treated as srgbColor * a, until export occurs where the layers are converted back to unumultiplied alpha (since PNG doesn't support both forms).  This differs from a more correct form of srgbToLinear( srgbColor ) * alpha, which we get when using the GPU to read these textures.  I assume Photoshop must do this to store the values in 8-bit data instead of promoting it to higher bit-depth.

Bilinear or trilinear sampling is only correct from premultiplied textures, so before the GPU can read from them, something had to convert them regardless.  Photoshop Tiff export, from what I understand, only exports premultiplied data.

 

 

Chris Cox
Legend
August 7, 2013

PNGs are not premultiplied, and are saved as straight color/alpha from Photoshop.

No, it is not normal or expected to export PNG via video.

PNG does not support alpha channels, only transparency.

TIFF can save alpha channels as well as transparency.

But it sounds like you have alpha channels (of which there can be many) confused with transparency (a single channel with specific meaning and relation to the color channels)..

P UchmanAuthor
Participant
August 9, 2013

Hello Mr Cox,

Thank You for your reply.

Chris Cox wrote:

PNGs are not premultiplied, and are saved as straight color/alpha from Photoshop.

PNG does not support alpha channels, only transparency.

Do you mean that PNGs dont support alpha channels at all? Or just in Photoshop? These two sentences are confusing.

I understand that transparency and alpha channels are different thing, but I want to make files transparent and with alpha channels.

If PNG is not premultiplied why video export has an option to premultiply PNG alpha with black/other color? Its really confusing!

What I have been doing to this day:

1) I have made a graphic "x" on transparent background.

2) I selected the layer and ran action "Alpha Channel from Visible Layers".

3) Then I have made full black layer under the graphic "x".

4) Then used superPNG plugin to intergrate Alpha 1 channel(made by action) within png file.

Programmer i work with says that the files I gave him worked like premultiplied alpha pngs, he wrote custom scripts and shaders and he says that these were ok. I am really confused now.

So as You see I'm really torn right now! I have red parts of PNG speciffication, everything on wikipedia about PNGs and alpha composing etc. and some other articles around web and I feel just stupidier. Could You recommend me a good read about this topic or elaborate more? It could be a book or anything.

Best regards,

Peter

Chris Cox
Chris CoxCorrect answer
Legend
August 9, 2013

PNG, the format standard, does not support alpha channels, only a single transparency channel.

PNG only allows 4 channels, and that fourth channel is transparency.

Some video software packages misuse PNG and treat it as premultiplied, even though the file spec. says it must be straight color.

You could save yourself a lot of trouble by skipping the alpha channels and just saving your PNG after step 1.

Yes, if you messed with the alpha channel and color values you might have ended up with a file that looks like premultiplied values (since you wrote all zeros into the color channel, but didn't need to).