Solved

URGENT- Change a buffer - URGENT

Posted on 1998-12-16
5
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Title # Comments Views Activity
maze travler 6 72
Embarcadero C++ Builder XE2 TDateTime 8 90
C++ help/ Toy problem 19 69
cmake and message 1 19
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.
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.

738 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