Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » The part enlargement with stretch_blit

This thread is locked; no one can reply to it. rss feed Print
The part enlargement with stretch_blit
Garnet
Member #5,816
May 2005

Using a stretch_blit, when expands bitmap "part" , it becomes stretching wrong w/h ratio and filled many black vertical lines.

for( i = 0; i < 10; i++ ){
 stretch_blit( bitmap , screen,0,i*12,bitmap->w,12,dx,dy,bitmap->w*2,12*2 );
}

This sample is 2times-expanding to screen which per height 12px slice parts from bitmap of source.
but wrong blitting.

I use Allegro 4.2.0 with Mac OSX 10.4.5
This issue occurred all-bit color bitmap.

Your Regards.

Thomas Harte
Member #33
April 2000
avatar

Any chance of a screenshot? And how do you calculate dx, dy? I'm on OS X 10.4.5 also, and tried this:

(EDIT: better example)

1#include "allegro.h"
2 
3int main(int argc, const char *argv[])
4{
5 BITMAP *bitmap;
6 int x, y, i;
7 PALETTE p;
8 allegro_init();
9 install_keyboard();
10
11 if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0)) {
12 allegro_message("Error setting 320x240x8 gfx mode:\n%s\n", allegro_error);
13 return -1;
14 }
15 /* set grey scale palette */
16 for(x = 0; x < 256; x++)
17 {
18 p[x].r = p[x].g = p[x].b = x;
19 }
20 set_palette(p);
21 
22 bitmap = create_bitmap(120, 120);
23 for(y = 0; y < bitmap->h; y++)
24 for(x =0; x < bitmap->w; x++)
25 putpixel(bitmap, x, y, (x+y)&1 ? makecol(y*2, y*2, y*2) : makecol(255 - (y*2), 255 - (y*2), 255 - (y*2)));
26
27 clear_to_color(screen, makecol(255, 255, 255));
28 
29 for(i = 0; i < 10; i++)
30 stretch_blit( bitmap , screen,0,i*12,bitmap->w,12,0,i*24,bitmap->w*2,12*2 );
31 
32 readkey();
33
34 return 0;
35}
36END_OF_MAIN()

Which produced the expected:
{"name":"stretchm.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3ecc2ad1eee483664a9495033b9993c3.png","w":337,"h":279,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3ecc2ad1eee483664a9495033b9993c3"}stretchm.png

Garnet
Member #5,816
May 2005

Thanks Thomas!
I tried write detailed source.
Result , text.bmp and screenshot were attached to file.

1#include <Allegro/allegro.h>
2 
3void enlarge_parts( BITMAP *bitmaps, int p ){
4 int dx =100 , dy = 100;
5 stretch_blit( bitmaps,screen,0,12*p,bitmaps->w,12,dx,dy,bitmaps->w*2,12*2 );
6 }
7 
8int main(int argc, const char *argv[])
9{
10 allegro_init();
11 install_keyboard();
12
13 if (set_gfx_mode(GFX_AUTODETECT, 640, 400, 0, 0)) {
14 allegro_message("Error setting gfx mode:¥n%s¥n", allegro_error);
15 return -1;
16 }
17#ifdef ALLEGRO_MACOSX
18chdir("..");
19#endif
20 
21 set_color_depth(32);
22 BITMAP *image_text;
23 
24 int line = 0;
25 clear_to_color(screen, makecol(255, 255, 255));
26 image_text = load_bitmap("text.bmp", NULL);
27
28 while(!key[KEY_ESC]){
29 if ( key[KEY_Z] ){ line = 0; }
30 if ( key[KEY_X] ){ line = 1; }
31 if ( key[KEY_C] ){ line = 2; }
32 enlarge_parts( image_text , line );
33}
34 destroy_bitmap( image_text );
35 return 0;
36}
37END_OF_MAIN();

Thomas Harte
Member #33
April 2000
avatar

The problem is that stretch_blit cannot convert from one colour depth to another while it is blitting. You place "set_color_depth(32);" after your call to set_gfx_mode, so what you effectively do is enter an 8bpp 640x400 graphics mode, then load your bitmap as a 32bpp image.

This is therefore not a bug in Allegro in the sense of code that doesn't do what it should. The official advice is either to use the same colour depth of graphics mode and source bitmap for stretch blitting (i.e. move your set_color_depth to before your set_gfx_mode or else don't call it at all if you can live in 8bpp all the way through) or to stretch blit to an intermediate buffer that has the same colour depth as your source bitmap. Then blit that to the screen, as ordinary blit can convert from one colour depth to another whereas stretch_blit cannot.

Garnet
Member #5,816
May 2005

Thank you for your helpful advice.
Indeed, as for stretch_blit and blit disposition is different.
When "set_color_depth (32) " was moved before set_gfx_mode, It became correct view.
Thanks :)

Go to: