From 334adcf9c0637c66400e060ccaa5c3d270ea89ab Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 1 Mar 2012 22:34:19 +0100 Subject: [PATCH] fixes for scaling performance --- src/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 1939edc..10d112d 100644 --- a/src/main.c +++ b/src/main.c @@ -128,9 +128,11 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) { return; } int x, y; - for (y = 0; y <= height; y++) { + al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); + al_lock_bitmap(source, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); + for (y = 0; y < height; y++) { float pixy = ((float)y / height) * al_get_bitmap_height(source); - for (x = 0; x <= width; x++) { + for (x = 0; x < width; x++) { float pixx = ((float)x / width) * al_get_bitmap_width(source); ALLEGRO_COLOR a = al_get_pixel(source, pixx-val, pixy-val); ALLEGRO_COLOR b = al_get_pixel(source, pixx+val, pixy-val); @@ -142,9 +144,11 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) { (a.b+b.g+c.b+d.b) / 4, (a.a+b.a+c.a+d.a) / 4 ); - al_draw_pixel(x, y, result); + al_put_pixel(x, y, result); } } + al_unlock_bitmap(al_get_target_bitmap()); + al_unlock_bitmap(source); } ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int height) {