Solved

URGENT- Change a buffer - URGENT

Posted on 1998-12-16
5
199 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 79
TTimer no longer functioning 7 85
Visual c++ and text files 7 60
How can i compile this github project?? 2 75
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now