Re: texture modification

New Message Reply Date view Thread view Subject view Author view

From: Marcin Romaszewicz (marcin++at++sgi.com)
Date: 02/28/2002 10:07:57


If it's PFTEX_PACK_8, then it's easy. In this format, each component is
one char in size packed into shorts like this: RGB RGB RGB... If you have
alpha in the texture, it will be RGBA RGBA RGBA.

Here's what your code might look like to access pixel values in a texture
with no alpha:

uint *image;
int comp, width, height, nr;
tex->getImage(&image, &comp, &width, &height, &nr);
char *pixels = (char *)image;

//Compute the index of the pixel at position X,Y in char array
int index = 3 * (width * Y + X)
char red = pixels[index + 0];
char green = pixels[index + 1];
char blue = pixels[index + 2];

If you do have alpha, the index is 4 * (width * Y + X) and alpha is
indexed as pixels[index + 3]

-- Marcin

On Thu, 28 Feb 2002, Boris Mansencal wrote:

> Marcin Romaszewicz wrote:
>
> > On Wed, 27 Feb 2002, Boris Mansencal wrote:
> > > I have a texture that I want to modify.
> > > I load an rgb file (not compressed). I do a pfTexture->getImage()
> > > and I want to access the RGBA values of each pixel.
> > >
> >
> >
> > You should not be setting the external format. The loadFile function does
> > this. You should call getFormat to query the current external format and
> > then use that for your computations. I think that if you are not packing
> > data, each components will be encoded as a ushort. You also have to make
> > accomodations for the presence of an alpha channel.
>
> If I do not set the texture external format, it is PFTEX_PACK_8 by default.
>
> How do I access to the RGBA values of a pixel then ?
>
> It seems that all the formats are for packed data, except
> PFTEX_UNSIGNED_SHORT_5_5_5_1.
> Is that right ?
>
> I have also tried to do a setFromat before loadFile. The format is correctly
> set (I can see it with getFormat),
> but I can still not get a correct result with the following code :
>
> tex = new pfTexture;
> tex->setFormat(PFTEX_EXTERNAL_FORMAT, PFTEX_UNSIGNED_SHORT_5_5_5_1);
> tex->loadFile("test.rgb");
>
> tex->getImage(&bitmap, &comp, &ns, &nt, &nr);
> for(i=0;i<ns*nt*nr; i++)
> {
> printf("Col = %d,%d,%d\n", (bitmap[i] & 0xF800) >> 11,
> (bitmap[i] & 0x07C0) >> 6,
> (bitmap[i] & 0x003E) >> 1);
> }
>
>
> Do you see what's wrong with the previous code ?
>
>
> Boris.
>


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Feb 28 2002 - 10:08:05 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.