Archived

This topic is now archived and is closed to further replies.

Afterlife

drawing with Allegro using 32bit block reads / writes

Recommended Posts

I'm a little bit confused with the read_line ect functions. I implemented this snippet from another program code, but it crashes my whole computer. It us supposed to read a bitmap (BITMAP *buffer) and draw it onto the screen.
    
unsigned long ad; unsigned char *temp; //ad is some sort of address

//

temp=(unsigned char *)malloc(sizeof(unsigned char)*buffer->w);
//

for(int y=0;y<buffer->h-1;y++)
{
//gets an address for reading line y:

ad = bmp_read_line(buffer, y);
//reads line in 32 bit chunks:

for (int x=0; x<buffer->w; x += sizeof(unsigned long))
	*((unsigned long *)&temp[x]) = bmp_read32(ad+x);
//this one have got something to do with animation in the original code

for (int x=0; x<buffer->w; x++)
	    if (temp[x] > 0)
	       temp[x]--;
//gets an address for writing line y

ad=bmp_write_line(screen, y);
//writes line in 32 bit chunks

for (int x=0; x<buffer->w; x += sizeof(unsigned long))
	bmp_write32(ad+x, *((unsigned long *)&temp[x]));
}
bmp_unwrite_line(screen);
    
Does anyone make anything out of that? I need some fast way to manipulate pixels fast without using a palette. Edited by - Afterlife on October 18, 2001 10:57:14 AM

Share this post


Link to post
Share on other sites
// sizeof(byte) is 1 and sizeof(long) is 4
typedef unsigned char byte;
typedef unsigned long dword;

dword ad;
byte *btemp;
dword *dtemp;

// btemp seems unnecessary, but I keep it for you to use
dtemp = btemp = (byte*)malloc(buffer->w);

for(int y = 0; y < buffer->h; y++) {
ad = bmp_read_line(buffer, y);
for (int x = 0; x < buffer->w; x += 4) dtemp[x] = bmp_read32(ad + x);

ad = bmp_write_line(screen, y);
for (int x = 0; x < buffer->w; x += 4) bmp_write32(ad + x, dtemp[x]);
}
bmp_unwrite_line(screen);

I haven''t used Allegro, but I think (I hope!) that bmp_read32(address) returns the value from the last used buffer. If it doesn''t, try rewriting a bit more.
You could speed it up a bit, by using a pointer to the buffer increasing for every read. Of course, the image must be linear.

Share this post


Link to post
Share on other sites