aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-14 12:13:14 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-14 12:13:35 +0000
commitf4b81bd693f325819e685ad2b9669e1921e4a3d4 (patch)
tree730b2370df5c266d769e17768d56100cfab655cd /src
parenta8fe29c81311a20c0c6906e6baeb65be6e841f6e (diff)
downloadimv-f4b81bd693f325819e685ad2b9669e1921e4a3d4.tar.gz
Fix PNG transparency
Diffstat (limited to 'src')
-rw-r--r--src/image.c6
-rw-r--r--src/texture.c19
2 files changed, 13 insertions, 12 deletions
diff --git a/src/image.c b/src/image.c
index f4faab5..cd59372 100644
--- a/src/image.c
+++ b/src/image.c
@@ -99,7 +99,6 @@ int imv_image_load(struct imv_image *img, const char* path)
if(!image) {
return 1;
}
- FreeImage_FlipVertical(image);
img->cur_bmp = FreeImage_ConvertTo32Bits(image);
img->width = FreeImage_GetWidth(img->cur_bmp);
img->height = FreeImage_GetHeight(img->cur_bmp);
@@ -125,7 +124,6 @@ void imv_image_load_next_frame(struct imv_image *img)
img->next_frame = (img->cur_frame + 1) % img->num_frames;
FIBITMAP *frame = FreeImage_LockPage(img->mbmp, img->cur_frame);
FIBITMAP *frame32 = FreeImage_ConvertTo32Bits(frame);
- FreeImage_FlipVertical(frame32);
/* First frame is always going to use the raw frame */
if(img->cur_frame > 0) {
@@ -164,9 +162,9 @@ void imv_image_load_next_frame(struct imv_image *img)
RGBQUAD color = {0,0,0,0};
FIBITMAP *expanded = FreeImage_EnlargeCanvas(frame32,
left,
- img->height - FreeImage_GetHeight(frame32) - top,
- img->width - FreeImage_GetWidth(frame32) - left,
top,
+ img->width - FreeImage_GetWidth(frame32) - left,
+ img->height - FreeImage_GetHeight(frame32) - top,
&color,
0);
FreeImage_Unload(frame32);
diff --git a/src/texture.c b/src/texture.c
index a5c5001..ea478af 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -44,11 +44,8 @@ void imv_destroy_texture(struct imv_texture *tex)
int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image)
{
- FIBITMAP *frame = FreeImage_ConvertTo32Bits(image);
- tex->width = FreeImage_GetWidth(frame);
- tex->height = FreeImage_GetHeight(frame);
-
- char* pixels = (char*)FreeImage_GetBits(frame);
+ tex->width = FreeImage_GetWidth(image);
+ tex->height = FreeImage_GetHeight(image);
/* figure out how many chunks are needed, and create them */
if(tex->num_chunks > 0) {
@@ -81,10 +78,12 @@ int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image)
const int is_last_v_chunk = (y == tex->num_chunks_tall - 1);
tex->chunks[x + y * tex->num_chunks_wide] =
SDL_CreateTexture(tex->renderer,
- SDL_PIXELFORMAT_RGB888,
+ SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC,
is_last_h_chunk ? tex->last_chunk_width : tex->chunk_width,
is_last_v_chunk ? tex->last_chunk_height : tex->chunk_height);
+ SDL_SetTextureBlendMode(tex->chunks[x + y * tex->num_chunks_wide],
+ SDL_BLENDMODE_BLEND);
if(tex->chunks[x + y * tex->num_chunks_wide] == NULL) {
failed_at = x + y * tex->num_chunks_wide;
break;
@@ -102,16 +101,21 @@ int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image)
return 1;
}
+ BYTE* pixels = (BYTE*)malloc(4 * tex->width * tex->height);
+ FreeImage_ConvertToRawBits(pixels, image, 4 * tex->width, 32,
+ FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE);
+
for(int y = 0; y < tex->num_chunks_tall; ++y) {
for(int x = 0; x < tex->num_chunks_wide; ++x) {
ptrdiff_t offset = 4 * x * tex->chunk_width +
y * 4 * tex->width * tex->chunk_height;
- char* addr = pixels + offset;
+ BYTE* addr = pixels + offset;
SDL_UpdateTexture(tex->chunks[x + y * tex->num_chunks_wide],
NULL, addr, 4 * tex->width);
}
}
+ free(pixels);
return 0;
}
@@ -119,7 +123,6 @@ void imv_texture_draw(struct imv_texture *tex, int bx, int by, double scale)
{
int offset_x = 0;
int offset_y = 0;
-
for(int y = 0; y < tex->num_chunks_tall; ++y) {
for(int x = 0; x < tex->num_chunks_wide; ++x) {
int img_w, img_h, img_access;