Jump to content
  • Advertisement

Archived

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

Afterlife

drawing with Allegro using 32bit block reads / writes

This topic is 6094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
// 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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!