Solved

URGENT- Change a buffer - URGENT

Posted on 1998-12-16
5
217 Views
Last Modified: 2010-04-02
I have a buffer defined as:                   

buf = (unsigned long*)malloc(imageWidth*imageLength*SamplePerPixel);

Where SamplePerPixel is 4 (A,G,B,R; four components defining a pixel, the RGB components and the alpha channel)

Then, this buffer has this structure: A,G,B,R,A,G,B,R,....

Now, i want to store in a supplied buffer, called dest,  ONLY this information of the pixel: R,G,B...

Then, Dest will have this structure: G,B,R,G,B,R,G,B,R..

What must i do??
0
Comment
Question by:Sol
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1180346
I think what you want:
1. allocate a 2nd buffer if you don't have it.  
2. You can calculate the size of the 2nd buffer by multiplying the orig size by 3/4 (round up as you may have partial bits)
3. Do you have 4 of A, 4 bits of G, 4 bits of B, etc.  or it is 4 bits per pixel total ?

In either case use shifts (<<) and & to rearrange the layout byte by byte.

If you explain what you mean (Item 3) then I or others can give you the exact shifts etc. required
0
 
LVL 22

Expert Comment

by:nietod
ID: 1180347
How many bits in each component?  that makes a huge difference.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1180348
Given malloc(imageWidth*imageLength*SamplePerPixel), and  SamplePerPixel is 4,
it would imply that each component is one char.
But what do you want it to be in dest?  (unsigned long*) may not match well with malloc(imageWidth*imageLength*3)
0
 

Author Comment

by:Sol
ID: 1180349
Hi!!

The buffer called buf is assumed to be an array of imagewidth times imageheight 32 bit entries, then, buf pixels are 8-bit packed red, green, blue and alpha samples.

Now, i want to store in dest ONLY 3 samples per pixel. Dest pixels must be 8-bit packed red, green, blue samples.

If dest could be allocated as: (LPBYTE)malloc(ImageWidth, ImageHeight,SamplePerpixel), it would be PERFECT!!!

(LPBYTE) means pointer to byte.

THANKS ALL!!

0
 
LVL 22

Accepted Solution

by:
nietod earned 70 total points
ID: 1180350
It sounds like you have these color components in a single byte and want to keep them that way, but remove the one component (alpha) is that right?  I think that is what you want but there are little things in there that don't completely mesh with that, so I'm not sure.  Assuming that is it.

unsigned char destPtr = new char [imageWidth*imageLength*3];
const int PixCnt = imageWidth*imageHeight;

unsigned char * dPtr = destPtr;
unsigned char * sPtr = ????; // your source data.
for (int i = 0; i < PixCnt; ++i)
{
   sPtr++; // Skip A
   *dPtr ++ = *sPtr++; // copy G
   *dPtr ++ = *sPtr++; // copy B
   *dPtr ++ = *sPtr++; // copy R
}
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question