Solved

URGENT- Change a buffer - URGENT

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 224
C++ standard library based binary archive format 6 98
IdTCPClient1->Disconnect(); not working 3 66
Path to  STL Map header file 1 57
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

806 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