Cropping a Bitmap (Allegro 5)
hdlopesrocha

Hello again, I am having troubles with cropping a bitmap

#define MAGENTA al_map_rgb(255,0,255)

void crop_bmp(ALLEGRO_BITMAP ** bmp, int ix, int iy, int fx , int iy){
ALLEGRO_BITMAP * temp;
ALLEGRO_DISPLAY * display=al_get_current_display();
temp = al_create_bitmap(fx-ix, fy-iy);
al_set_target_bitmap(temp);
al_clear_to_color(MAGENTA);
al_draw_bitmap(*bmp, -ix, -iy, 0);
al_destroy_bitmap(*bmp);
*bmp = temp;
al_set_target_bitmap(al_get_backbuffer(display));
}

this is the error (it's in Portuguese):
era: /home/henriquerocha/allegro-5.0/src/display.c:187: al_clear_to_color: Asserção `target' falhou.

What is wrong? I don't want to create a sub bitmap. Just making a new one but shorter.

Thanks ;)

Arthur Kalliokoski

void crop_bmp(ALLEGRO_BITMAP ** bmp, int ix, int iy, int fx , int iy)

temp = al_create_bitmap(fx-ix, fy-iy)

Where does the second line get fy from?

hdlopesrocha

sorry It was a mistake when I was writting here,

void crop_bmp(BITMAP ** bmp, int ix, int iy, int fx, int fy)

the error is the same.

Arthur Kalliokoski

For one thing, you don't pass the contents of a bitmap to al_draw_bitmap() and friends, you just pass the pointer.

al_draw_bitmap(*bmp, -ix, -iy, 0);
should be
al_draw_bitmap(bmp, -ix, -iy, 0);

and you're not checking return values

temp = al_create_bitmap(fx-ix, fy-iy);
al_set_target_bitmap(temp);

should be more like

temp = al_create_bitmap(fx-ix, fy-iy);
if(!temp)
{
 put some sort of error message here
 return 1;
}
al_set_target_bitmap(temp);

SiegeLord

Perhaps ix is greater than fx (or the same for y) and your al_create_bitmap call is failing?

hdlopesrocha

void crop_bmp(ALLEGRO_BITMAP ** bmp, int ix, int iy, int fx , int iy)

al_draw_bitmap(*bmp, -ix, -iy, 0);
I think this line is correct, bmp is **, the goal is to replace the image for the cropped image, that's why I use double pointer.

The strange is that with allegro 4.2.2 works great.

#SelectExpand
1void crop_bmp(BITMAP ** bmp, int ix, int iy, int fx , int fy){ 2 BITMAP * temp; 3 4 temp = create_bitmap(fx-ix, fy-iy); 5 clear_to_color(temp, MAGENTA); 6 7 draw_sprite(temp,*bmp,-ix,-iy); 8 9 destroy_bitmap(*bmp); 10 *bmp = temp; 11}

But I am trying to convert it for allegro 5.

PS: Sorry problem is not here.

pixel = al_get_pixel(bmp,x,y);
printf("%f.%f.%f\n",pixel.r,pixel.g,pixel.b);

The bitmap is MAGENTA but that printf is always
"0,000000.0,000000.0,000000"

I am using getpixel to calculate ix and fx

PS: Problem solved! Thanks for your support ;)

Thread #607897. Printed from Allegro.cc