Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
In my program I have a RGBA pixel buffer, I would like to convert it to RGB buffer without loosing the alpha value.

thanks

What I have tried:

I tried to use the RGBA buffer to create AVI file, but its not working
Posted
Updated 3-Jun-16 5:05am
Comments
OriginalGriff 3-Jun-16 5:21am    
Um...I don't think you have quite thought this through.
RGB is a set of three bytes, each of of which ranges from 0 to 255 and which together specify a unique colour code for a specific pixel. The Alpha information controls the transparency of that pixel. You can't convert from RGBA to RGB and keep the transparency info, because there is nowhere to store it...
I'd suspect that you need to look at whatever you are using to create AVI files from RGB/RGBA pixel buffers and work out exactly what it is expecting.
Philippe Mori 4-Jun-16 8:59am    
This question does not make sense. If you remove the information, you don't have it anymore and it you want to do something specific like creating an image that would look the same at the original image on a white (or any other) background, you need to explicitly say that in your question or if your image only have either 0 or 100% transparency and you maybe want to use an otherwise unused color as a transparency key.

OriginalGriff is right, the alpha is an additional information which belongs to every pixel. If you dont need it, than recode the image data. Here is the outstanding article CxImage which demonstrates a lot of these functions.

The only other way I see is to save the file in RGB and store the alpha-value in approbiate binary format in another file. So you can use it sometimes later.
 
Share this answer
 
The question makes no sense, due to one simple reason: converting RGBA to RGB means exactly that: loosing alpha (which is "A", pixel opacity).

Besides, perhaps you need to know that AVI is badly obsolete; I don't know anyone who still creates new files of this format. How about something more reasonable?

Anyway, I have no idea what do you want to achieve, but I can give you some general advice.

First of all, you have to understand that things are more complicated: there is a number of different media container types, which are roughly equivalent to the concept of "format"; each container supports some subset of media streams of different (many, really many types, each in different versions) working with different kinds of codecs; a number of stream combine in the container with multiplexing:
Digital container format — Wikipedia, the free encyclopedia[^],
Comparison of video container formats — Wikipedia, the free encyclopedia[^],
List of open-source codecs — Wikipedia, the free encyclopedia[^],
List of codecs — Wikipedia, the free encyclopedia[^].

Here is my advice: understand all that but better don't try to dig in it with your own code. Instead, use some available product. I would highly recommend FFMpeg or libav library, open-source products:
FFmpeg — Wikipedia, the free encyclopedia[^],
FFmpeg[^],
libavcodec — Wikipedia, the free encyclopedia[^],
Libav[^].

You can either use the available utilities, by spawning a separate process, or you can link them in your product as library; you always can link them in C++, as they are C libraries.

The products cover nearly everything; I don't know more comprehensive product to cover many different standards, types of conversions and other features.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900