From 492dd591643666dd55c1a8d07913bfce0839195a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 17 May 2016 21:38:51 +0200 Subject: [PATCH] Hook up BMP image loading - color channels swapped - RGBA to ARGB conversion won't work here --- gfx/video_texture_image.c | 10 +++++++++- libretro-common/formats/bmp/rbmp.c | 4 ++++ libretro-common/formats/image_transfer.c | 18 ++++++++++++++++++ libretro-common/include/formats/image.h | 3 ++- menu/menu_displaylist.c | 2 +- tasks/task_image.c | 2 ++ 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/gfx/video_texture_image.c b/gfx/video_texture_image.c index 945e739df4..1d7499d158 100644 --- a/gfx/video_texture_image.c +++ b/gfx/video_texture_image.c @@ -37,7 +37,8 @@ enum video_image_format IMAGE_FORMAT_NONE = 0, IMAGE_FORMAT_TGA, IMAGE_FORMAT_PNG, - IMAGE_FORMAT_JPEG + IMAGE_FORMAT_JPEG, + IMAGE_FORMAT_BMP }; bool video_texture_image_set_color_shifts( @@ -175,6 +176,8 @@ static bool video_texture_image_load_internal( #else return false; #endif + case IMAGE_TYPE_BMP: + break; default: break; } @@ -243,6 +246,8 @@ static enum video_image_format video_texture_image_get_type(const char *path) return IMAGE_FORMAT_PNG; if (strstr(path, ".jpg") || strstr(path, ".jpeg")) return IMAGE_FORMAT_JPEG; + if (strstr(path, ".bmp")) + return IMAGE_FORMAT_BMP; return IMAGE_FORMAT_NONE; } @@ -254,6 +259,8 @@ static enum image_type_enum video_texture_image_convert_fmt_to_type(enum video_i return IMAGE_TYPE_PNG; case IMAGE_FORMAT_JPEG: return IMAGE_TYPE_JPEG; + case IMAGE_FORMAT_BMP: + return IMAGE_TYPE_BMP; default: case IMAGE_FORMAT_NONE: break; @@ -302,6 +309,7 @@ bool video_texture_image_load(struct texture_image *out_img, goto success; #endif break; + case IMAGE_FORMAT_BMP: case IMAGE_FORMAT_PNG: case IMAGE_FORMAT_JPEG: if (video_texture_image_load_internal( diff --git a/libretro-common/formats/bmp/rbmp.c b/libretro-common/formats/bmp/rbmp.c index acfbb9b79e..002af001b0 100644 --- a/libretro-common/formats/bmp/rbmp.c +++ b/libretro-common/formats/bmp/rbmp.c @@ -573,13 +573,16 @@ int rbmp_process_image(rbmp_t *rbmp, void **buf_data, size_t size, unsigned *width, unsigned *height) { int comp; +#if 0 unsigned size_tex = 0; +#endif if (!rbmp) return IMAGE_PROCESS_ERROR; rbmp->output_image = (uint32_t*)rbmp_load_from_memory(rbmp->buff_data, size, width, height, &comp, 4); *buf_data = rbmp->output_image; +#if 0 size_tex = (*width) * (*height); /* Convert RGBA to ARGB */ @@ -592,6 +595,7 @@ int rbmp_process_image(rbmp_t *rbmp, void **buf_data, unsigned int R = texel & 0x000000FF; ((unsigned int*)rbmp->output_image)[size_tex] = A | (R << 16) | G | (B >> 16); }while(size_tex--); +#endif return IMAGE_PROCESS_END; } diff --git a/libretro-common/formats/image_transfer.c b/libretro-common/formats/image_transfer.c index 5814e309a6..35acca23fa 100644 --- a/libretro-common/formats/image_transfer.c +++ b/libretro-common/formats/image_transfer.c @@ -8,6 +8,7 @@ #ifdef HAVE_RJPEG #include #endif +#include #include @@ -25,6 +26,9 @@ void image_transfer_free(void *data, enum image_type_enum type) rjpeg_free((rjpeg_t*)data); #endif break; + case IMAGE_TYPE_BMP: + rbmp_free((rbmp_t*)data); + break; case IMAGE_TYPE_NONE: break; } @@ -46,6 +50,8 @@ void *image_transfer_new(enum image_type_enum type) #else break; #endif + case IMAGE_TYPE_BMP: + return rbmp_alloc(); default: break; } @@ -71,6 +77,8 @@ bool image_transfer_start(void *data, enum image_type_enum type) return true; #endif break; + case IMAGE_TYPE_BMP: + return true; case IMAGE_TYPE_NONE: break; } @@ -96,6 +104,8 @@ bool image_transfer_is_valid( #else break; #endif + case IMAGE_TYPE_BMP: + return true; case IMAGE_TYPE_NONE: break; } @@ -120,6 +130,9 @@ void image_transfer_set_buffer_ptr( rjpeg_set_buf_ptr((rjpeg_t*)data, (uint8_t*)ptr); #endif break; + case IMAGE_TYPE_BMP: + rbmp_set_buf_ptr((rbmp_t*)data, (uint8_t*)ptr); + break; case IMAGE_TYPE_NONE: break; } @@ -151,6 +164,9 @@ int image_transfer_process( #else break; #endif + case IMAGE_TYPE_BMP: + return rbmp_process_image((rbmp_t*)data, + (void**)buf, len, width, height); case IMAGE_TYPE_NONE: break; } @@ -175,6 +191,8 @@ bool image_transfer_iterate(void *data, enum image_type_enum type) #else break; #endif + case IMAGE_TYPE_BMP: + return false; case IMAGE_TYPE_NONE: return false; } diff --git a/libretro-common/include/formats/image.h b/libretro-common/include/formats/image.h index dd11a96fdb..b54c72a96c 100644 --- a/libretro-common/include/formats/image.h +++ b/libretro-common/include/formats/image.h @@ -44,7 +44,8 @@ enum image_type_enum { IMAGE_TYPE_NONE = 0, IMAGE_TYPE_PNG, - IMAGE_TYPE_JPEG + IMAGE_TYPE_JPEG, + IMAGE_TYPE_BMP }; bool video_texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift, diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 080bff2eb9..7712bfce44 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -4011,7 +4011,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) break; case DISPLAYLIST_IMAGES: info->type_default = MENU_FILE_IMAGE; - strlcpy(info->exts, "png|jpg|jpeg", sizeof(info->exts)); + strlcpy(info->exts, "png|jpg|jpeg|bmp", sizeof(info->exts)); break; case DISPLAYLIST_AUDIO_FILTERS: info->type_default = MENU_FILE_AUDIOFILTER; diff --git a/tasks/task_image.c b/tasks/task_image.c index 6768b41433..196615e227 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -364,6 +364,8 @@ bool rarch_task_push_image_load(const char *fullpath, nbio->image_type = IMAGE_TYPE_PNG; else if (strstr(fullpath, ".jpeg") || strstr(fullpath, ".jpg")) nbio->image_type = IMAGE_TYPE_JPEG; + else if (strstr(fullpath, ".bmp")) + nbio->image_type = IMAGE_TYPE_BMP; switch (cb_type_hash) {