Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » BITMAP quality gets reduced

This thread is locked; no one can reply to it. rss feed Print
BITMAP quality gets reduced
Doctor Cop
Member #16,833
April 2018
avatar

When I loaded a jpeg image just to test how would background saturation work, I found that the loaded bitmap was of low quality.

Why?

Loaded Bitmap :
{"name":"611992","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/9\/f971ae09ba823aa93534e6a40129591b.png","w":810,"h":629,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/9\/f971ae09ba823aa93534e6a40129591b"}611992

Original Bitmap :
{"name":"611993","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/1\/312fce8349c30c06f886f11d9de7ddfb.jpg","w":4896,"h":3264,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/1\/312fce8349c30c06f886f11d9de7ddfb"}611993

Elias
Member #358
May 2000

The scaling algorithm. The original is 4896x3264 pixel, your screenshot is 810x629 pixel. I assume you are drawing it with al_draw_scaled_bitmap?

In that case try calling this before loading the bitmap:

al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR);

That should make Allegro use linear scaling.

--
"Either help out or stop whining" - Evert

Doctor Cop
Member #16,833
April 2018
avatar

This didn't work.

al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR);

didn't do anything. Do I need to convert my image file's size?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I can't even tell the difference between the two images. :/

Allegro will load the file at the same resolution it is in.

ALLEGRO_MIN_LINEAR will make allegro use linear filtering when reducing the image size. This can look better than nearest neighbor.

Show more code.

Doctor Cop
Member #16,833
April 2018
avatar

#SelectExpand
1#include <allegro5/allegro_image.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4#include <allegro5/keyboard.h> 5#include <allegro5/mouse.h> 6 7#define MAXWIDTH 800 8#define MAXHEIGHT 600 9 10int main() 11{ 12 al_init(); 13 al_init_primitives_addon(); 14 al_init_image_addon(); 15 al_init_font_addon(); 16 al_init_ttf_addon(); 17 al_install_keyboard(); 18 al_install_mouse(); 19 20 ALLEGRO_DISPLAY *display = al_create_display(MAXWIDTH, MAXHEIGHT); 21 ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); 22 ALLEGRO_TIMER *timer = al_create_timer(2.0/60.0); 23 ALLEGRO_COLOR black = al_map_rgb(0, 0, 0); 24 ALLEGRO_FONT *font = al_load_ttf_font("res/L.ttf", 14, 1); 25 ALLEGRO_BITMAP *background = al_load_bitmap("res/background.jpg"); 26 int x=0, y=0, main_loop = true; 27 28 al_register_event_source(queue, al_get_display_event_source(display)); 29 al_register_event_source(queue, al_get_mouse_event_source()); 30 al_register_event_source(queue, al_get_keyboard_event_source()); 31 al_register_event_source(queue, al_get_timer_event_source(timer)); 32 33 al_start_timer(timer); 34 35 while(main_loop) 36 { 37 ALLEGRO_EVENT event; 38 39 //if(al_is_event_queue_empty(queue)) 40 al_wait_for_event(queue, &event); 41 42 if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 43 main_loop = false; 44 45 if(event.type == ALLEGRO_EVENT_TIMER) 46 { 47 al_clear_to_color(al_map_rgb(218, 112, 214)); 48 49 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR); 50 51 al_draw_scaled_bitmap(background, 0, 0, 4896, 3264, 0, 0, 800, 600, 0); 52 //al_draw_rounded_rectangle(400-100 + x, 300-20, 400+100 + x, 300+20, 20, 20, al_map_rgb(70, 60, 100), 2); 53 //al_draw_filled_rectangle(0, 0, 50, 50, al_map_rgb(255, 255, 255)); 54 //al_draw_filled_rectangle(0, 50, 50, MAXHEIGHT, al_map_rgb(255, 0, 255)); 55 //al_draw_line(50, 0, 50, MAXHEIGHT, black, 1); 56 57 58 al_flip_display(); 59 al_rest(0.02); 60 } 61 62 if(event.type == ALLEGRO_EVENT_KEY_DOWN) 63 { 64 switch(event.keyboard.keycode) 65 { 66 case ALLEGRO_KEY_ESCAPE : 67 exit(1); 68 break; 69 } 70 } 71 72 } 73 74 al_destroy_display(display); 75 al_destroy_event_queue(queue); 76 return 0; 77}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Doctor Cop
Member #16,833
April 2018
avatar

Thanks, Edgar, it worked just fine. although there is still some noise but its smoother than before.

Elias
Member #358
May 2000

Yes, linear scaling is not the highest quality. If this is for something like background pictures for a game you could maybe provide pre-scaled versions for smaller resolutions. At least then you'd only have to use a little bit of linear scaling - I imagine that would still look better than scaling down from the 4K resolution (not completely sure - but easy to try).

--
"Either help out or stop whining" - Evert

Go to: