arrays and pointers indexing

Nov 18, 2011 at 7:45pm
I have a pointer to an array of Gdiplus::Color objects RGB values that are 3 BYTE's in size for each object, just the rgb values 1 BYTE for each. I have another BYTE variable that contains an index in to this array between 0 and 255. I'm trying to get the R G and B value at the specified index. Here's the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Returns a color
Gdiplus::Color& Model3D::GetPaletteColor(BYTE uvCoord) const
{
	Gdiplus::Color texelColor;   // Return color var
	BYTE paletteIndex = *_texture + uvCoord; // _texture is pointer to BYTE array that contains index in to _palette array
        // paletteIndex now contains index in to _palette array
	BYTE paletteStart = (BYTE)*_palette;

        // Times paletteIndex by 3 for each BYTE in a color object????

	texelColor = Color(*_paletteStart + paletteIndex, *_paletteStart + paletteIndex + 1, *_paletteStart + paletteIndex + 2);

	return texelColor;
}


Obviously this is wrong, but you get the idea. Suggestions?
Nov 19, 2011 at 5:36pm
I am not sure it's a good idea to try to memorize the why an object stores its data by using a pointer to it and pointer arithmetic. It's surely machine dependent and not portable (meaning in other environments wont work).

Are you sure there isn't any other way to get the information you want?
I don't know which library you are referring to but I am sure it would provide a better way to do this.
Nov 19, 2011 at 6:59pm
Hi ,

codejunky99 can you explain what this line do ?

texelColor = Color(*_paletteStart + paletteIndex, *_paletteStart + paletteIndex + 1, *_paletteStart + paletteIndex + 2);

As
if you want R, G, B value
hou can get it by
1
2
3
RColor = *_paletteStart + paletteIndex;
GColor = *_paletteStart + paletteIndex + 1;
BColor = *_paletteStart + paletteIndex + 2;
Last edited on Nov 19, 2011 at 7:01pm
Topic archived. No new replies allowed.