Solved

URGENT- Change a buffer - URGENT

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

743 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