Quote: "
Quote: "... and I think have a different method of manipulating that information, for better or worse. "
Oh? How? Pointers? To Memblock? To Image itself? I've thought about getting a MEMBLOCK pointer and working it raw... definately would be even faster."
I'm basing this mostly on the things I picked up from studying SDL, which does much but at a more primative level. It's closer to Direct X.
AAR, I tend not to think in terms of DWORD. From my perspective it all looks like unsigned int. If I type cast a pointer to the data as a (unsigned int *) I can treat the data in a different way. RGBA becomes
typedef unsigned int dbColor;
dbColor clr;
clr = b + g << 8 + r << 16 + a << 24;
This works if r, g, b and a are known to be restricted to a 0 - 255 range. If not then they need to be masked with 0X0F before they're shifted into position.
The tricky part is using the pointer. It should take into account that the width is actually the image/memblock width divided by 4 since the pointer accounts for the size of the data. Going from memory (I tend to re-invent this particular wheel in each new API) if I were to fill in a box it might look something like this (pseudocode follows
unsigned int *pixies;
int x = 128; // upper left x
int w = 255; // width of rectangle
int y = 20; // upper left y
int h = 30; // height of rectangle
unsigned int *yhold; // tracks pointer to left side of each line
// beginning_of_pixels may need to be type cast
pixies = beginning_of_pixels + y * Width/4;
for (int i = 0; i < h; i++) {
yhold = pixies; // keep track of the beginning of the line
for (int j = 0; j < w; j++){
*pixies = RGBA (255, 0, 0, 255);
}
pixies = yhold + Width/4; // recalculate the start of next line
}
Width is the number of bytes across in the image/memblock.
I tend to agonize over this code since I don't trust myself to steal it from my own code when I go to a new API. The advantage of using the pointer is that you don't have to recalculate the position except when you're dropping on the vertical level. And even that is a quick bit of pointer arithmatic. I could very likely declare pixel and yhold as dbColor *.
Staring at that code makes me think I could get really glib with it by setting yhold before the loop as in
yhold = pixies = beginning_of_pixels + y * Width/4;
and then do
yhold = pixies = yhold + Width/4;
after the inner loop. There's probably no savings there but it make the code look more concise and makes me look clever.
Lilith, Night Butterfly
I'm not a programmer but I play on in the office