News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Alpha channel images

Started by Siekmanski, October 30, 2016, 09:11:34 PM

Previous topic - Next topic

Siekmanski

I'm working on a tool to crunch alpha channel .png .bmp .tif files.

My question:

If you load only the RGB values, you often see multiple colors left at the alpha regions.
Are those colors used for other purposes or just left overs of the alpha image processing software ?
Is it save to reduce those colors to one RGB value ?
My goal is to make the files as small as possible and remove those colors.

Example of an alpha .png



Example of the same image showing the "unused" colors in the alpha region.


Creative coders use backward thinking techniques as a strategy.

hutch--

You can see a bit of this if you load an RGB/A image in an RGB application. I would suggest that if you worked on the original RGB image and did a single fill of the areas that you wanted to be transparent, converted it to RGB/A then re-filled that filler colour with the alpha channel transparency you may get a reduction in size. I think this is perhaps that way that Windows loads an RGB image into a toolbar and makes the background of the filler colour transparent.

Siekmanski

Hi Hutch,

Here I have replaced the unused RGB values of the ALPHA area with the color red.
Now I can get a better size reduction of the RGB area and will insert the alpha values back to make it transparent again.
All channels will be crunched to a smaller size and will be reconstructed when loaded as a real transparent image.

Creative coders use backward thinking techniques as a strategy.

GuruSR

I was doing some image manipulation (basically border finding in images) and I had to deal with RGBA.  The A is the saturation of the RGB color over the background, as easy as I can state it, there are websites out there that probably explain it better.  And the weirdness you see in the "unused" colors as you list it, is actually the saturation of the RGB color, which is nothing (black presumed), most likely the image software did that.  IIRC, A of 0 meant background and as you progressed to FF, would produce more of the RGB over top of the background.  And for toolbars, controls, etc, Windows uses Purple (RGBA = 0xFF00FFFF) as a mask, but may not read the A (as it's replaced with the Aero alpha when used).

GuruSR.
Learned 68k Motorola Asm instruction set in 30 minutes on the way to an Amiga Developer's Forum meeting.
Following week wrote a kernel level memory pool manager in 68k assembler for fun.

Siekmanski

Hi GuruSR,

QuoteWindows uses Purple (RGBA = 0xFF00FFFF) as a mask, but may not read the A (as it's replaced with the Aero alpha when used).

It is called the colorkey, you pick one color to be transparent.

The alpha channel of the "unused" colors are all 0 and, thus, are fully transparent ( no color is shown ).
So, I was wondering why are there different RGB values in the colors that have an alpha value of 0.
Before I remove them in my program I need to know if they have some kind of a function.
I think not, but just to be sure I asked this if any of you, knows something about this.

Creative coders use backward thinking techniques as a strategy.

dawnraider

The RGB values left in the pixels when the alpha is zero looks like garbage left over from when the image was being created.
It is an artefact of the application that was used to create it.

Typically, this is the result of an optimisation during image processing where if the alpha channel is zero then there is no point
in reading or writing the rest of the pixel. Such optimisations are common. I use them myself in algorithms I have developed for
the image processing products my company makes. It is a perfectly valid technique when adding pure transparency to images.

In this case, correcting the colour channels to a single value to get a better compression ratio is OK to do and won't affect any
cases where the image is blended with another image.

Where it becomes an issue is if you raise the alpha channel on such pixels and expect the output to go translucent black as a
result: it won't, as the colour channels contain random values and not black.

GuruSR

Dawnrider, you beat me to that one.    :greenclp:  I was just writing a similar note to that, as I've run into processing images like that.

Quote from: Siekmanski on October 31, 2016, 09:15:27 AM
QuoteWindows uses Purple (RGBA = 0xFF00FFFF) as a mask, but may not read the A (as it's replaced with the Aero alpha when used).

It is called the colorkey, you pick one color to be transparent.

The alpha channel of the "unused" colors are all 0 and, thus, are fully transparent ( no color is shown ).
So, I was wondering why are there different RGB values in the colors that have an alpha value of 0.
Before I remove them in my program I need to know if they have some kind of a function.
I think not, but just to be sure I asked this if any of you, knows something about this.

Actually, the "colorkey" is a Microsoft name (depreciated), though when you said colorkey, I immediately referred it to: https://en.wikipedia.org/wiki/Color_key

In doing my border detection, I had to deal with RGBA directly because if an image has it, and I only look at the RGB, I can be border detecting pixels that shouldn't be visible.   And it also looks like my math is off on it, seems it's cutting a 'border" off on the left side of the image I have, and not the right and the image shouldn't be cut off that much...  I was tweaking values, seems I have to look at the intensity of those pixels again and see if my threshold for variances between the two points is too loose.

GuruSR.
Learned 68k Motorola Asm instruction set in 30 minutes on the way to an Amiga Developer's Forum meeting.
Following week wrote a kernel level memory pool manager in 68k assembler for fun.

Siekmanski

dawnraider,

Thanks, that convinced me to replace all RGBA values with alpha 0 to RGBA(0,0,0,0).

GuruSR,

The term Color-key/Chroma-key was also used in the early days on the Amiga.
Creative coders use backward thinking techniques as a strategy.

dawnraider

#8
You're welcome. Glad to be of some help.

GuruSR

Quote from: Siekmanski on November 01, 2016, 06:48:07 AM
dawnraider,

Thanks, that convinced me to replace all RGBA values with alpha 0 to RGBA(0,0,0,0).

GuruSR,

The term Color-key/Chroma-key was also used in the early days on the Amiga.

Amiga, gee, think I had one or two of those and a few pieces of hardware that let me do overlays onto video...  And yes, know what Color and Chroma keys are, but what Windows calls them, isn't that, hence why I was trying to separate them, because what Microsoft says is a Color-key, isn't...  Reminds me, need to reinstall my video software on this new PC, been forgetting to (just too much to re-do lately).  As the mask color for Microsoft is RGBA(FF,00,FF,FF), the video software actually included it in the Chroma key lists, so Green, Blue and Purple are now offered, doubt the actual television industry has offered it, but the commercial ones seem to be.

GuruSR.
Learned 68k Motorola Asm instruction set in 30 minutes on the way to an Amiga Developer's Forum meeting.
Following week wrote a kernel level memory pool manager in 68k assembler for fun.