mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
use proper linear filtering for image scaling
This commit is contained in:
parent
d9dd10d063
commit
3828f4136b
2 changed files with 31 additions and 4 deletions
|
@ -79,8 +79,8 @@ void Loading_Load(struct Game *game) {
|
|||
else al_draw_bitmap(game->loading.image, 0, 0, 0);
|
||||
} else GenerateLoadingBitmap();
|
||||
*/
|
||||
game->loading.image = al_load_bitmap( "data/loading.png");
|
||||
//game->loading.image = LoadFromCache(game, "loading.png", al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
//game->loading.image = al_load_bitmap( "data/loading.png");
|
||||
game->loading.image = LoadFromCache(game, "loading.png", al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
|
||||
// Scale "Loading" bitmap
|
||||
al_set_target_bitmap(game->loading.loading_bitmap);
|
||||
|
|
29
src/main.c
29
src/main.c
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "menu.h"
|
||||
#include "loading.h"
|
||||
#include "about.h"
|
||||
|
@ -154,7 +155,33 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) {
|
|||
int x, 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);
|
||||
|
||||
ALLEGRO_COLOR interpolate(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) {
|
||||
return al_map_rgba_f(c1.r + frac * (c2.r - c1.r),
|
||||
c1.g + frac * (c2.g - c1.g),
|
||||
c1.b + frac * (c2.b - c1.b),
|
||||
c1.a + frac * (c2.a - c1.a));
|
||||
}
|
||||
|
||||
for (y = 0; y < height; y++) {
|
||||
float pixy = ((float)y / height) * ((float)al_get_bitmap_height(source) - 1);
|
||||
float pixy_f = floor(pixy);
|
||||
for (x = 0; x < width; x++) {
|
||||
float pixx = ((float)x / width) * ((float)al_get_bitmap_width(source) - 1);
|
||||
float pixx_f = floor(pixx);
|
||||
|
||||
ALLEGRO_COLOR a = al_get_pixel(source, pixx_f, pixy_f);
|
||||
ALLEGRO_COLOR b = al_get_pixel(source, pixx_f + 1, pixy_f);
|
||||
ALLEGRO_COLOR c = al_get_pixel(source, pixx_f, pixy_f + 1);
|
||||
ALLEGRO_COLOR d = al_get_pixel(source, pixx_f + 1, pixy_f + 1);
|
||||
|
||||
ALLEGRO_COLOR ab = interpolate(a, b, pixx - pixx_f);
|
||||
ALLEGRO_COLOR cd = interpolate(c, d, pixx - pixx_f);
|
||||
ALLEGRO_COLOR result = interpolate(ab, cd, pixy - pixy_f);
|
||||
|
||||
al_put_pixel(x, y, result);
|
||||
}
|
||||
/*
|
||||
float pixy = ((float)y / height) * al_get_bitmap_height(source);
|
||||
for (x = 0; x < width; x++) {
|
||||
float pixx = ((float)x / width) * al_get_bitmap_width(source);
|
||||
|
@ -169,7 +196,7 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) {
|
|||
(a.a+b.a+c.a+d.a) / 4
|
||||
);
|
||||
al_put_pixel(x, y, result);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
al_unlock_bitmap(al_get_target_bitmap());
|
||||
al_unlock_bitmap(source);
|
||||
|
|
Loading…
Reference in a new issue