image_texture_load_buffer

This commit is contained in:
Huw Pascoe 2019-04-17 23:08:53 +01:00
parent 3e350afe93
commit cd714dbd0b
2 changed files with 47 additions and 52 deletions

View File

@ -29,14 +29,27 @@
#include <formats/image.h> #include <formats/image.h>
#include <file/nbio.h> #include <file/nbio.h>
enum video_image_format
enum image_type_enum image_texture_get_type(const char *path)
{ {
IMAGE_FORMAT_NONE = 0, #ifdef HAVE_RTGA
IMAGE_FORMAT_TGA, if (strstr(path, ".tga"))
IMAGE_FORMAT_PNG, return IMAGE_TYPE_TGA;
IMAGE_FORMAT_JPEG, #endif
IMAGE_FORMAT_BMP #ifdef HAVE_RPNG
}; if (strstr(path, ".png"))
return IMAGE_TYPE_PNG;
#endif
#ifdef HAVE_RJPEG
if (strstr(path, ".jpg") || strstr(path, ".jpeg"))
return IMAGE_TYPE_JPEG;
#endif
#ifdef HAVE_RBMP
if (strstr(path, ".bmp"))
return IMAGE_TYPE_BMP;
#endif
return IMAGE_TYPE_NONE;
}
bool image_texture_set_color_shifts( bool image_texture_set_color_shifts(
unsigned *r_shift, unsigned *g_shift, unsigned *b_shift, unsigned *r_shift, unsigned *g_shift, unsigned *b_shift,
@ -214,53 +227,29 @@ void image_texture_free(struct texture_image *img)
img->pixels = NULL; img->pixels = NULL;
} }
static enum video_image_format image_texture_get_type(const char *path) bool image_texture_load_buffer(struct texture_image *out_img,
enum image_type_enum type, void *buffer, size_t buffer_len)
{ {
#ifdef HAVE_RTGA unsigned r_shift, g_shift, b_shift, a_shift;
if (strstr(path, ".tga")) image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift,
return IMAGE_FORMAT_TGA; &a_shift, out_img);
#endif
#ifdef HAVE_RPNG
if (strstr(path, ".png"))
return IMAGE_FORMAT_PNG;
#endif
#ifdef HAVE_RJPEG
if (strstr(path, ".jpg") || strstr(path, ".jpeg"))
return IMAGE_FORMAT_JPEG;
#endif
#ifdef HAVE_RBMP
if (strstr(path, ".bmp"))
return IMAGE_FORMAT_BMP;
#endif
return IMAGE_FORMAT_NONE;
}
static enum image_type_enum image_texture_convert_fmt_to_type(enum video_image_format fmt) if (type != IMAGE_TYPE_NONE)
{
switch (fmt)
{ {
#ifdef HAVE_RPNG if (image_texture_load_internal(
case IMAGE_FORMAT_PNG: type, buffer, buffer_len, out_img,
return IMAGE_TYPE_PNG; a_shift, r_shift, g_shift, b_shift))
#endif {
#ifdef HAVE_RJPEG return true;
case IMAGE_FORMAT_JPEG: }
return IMAGE_TYPE_JPEG;
#endif
#ifdef HAVE_RBMP
case IMAGE_FORMAT_BMP:
return IMAGE_TYPE_BMP;
#endif
#ifdef HAVE_RTGA
case IMAGE_FORMAT_TGA:
return IMAGE_TYPE_TGA;
#endif
case IMAGE_FORMAT_NONE:
default:
break;
} }
return IMAGE_TYPE_NONE; out_img->supports_rgba = false;
out_img->pixels = NULL;
out_img->width = 0;
out_img->height = 0;
return false;
} }
bool image_texture_load(struct texture_image *out_img, bool image_texture_load(struct texture_image *out_img,
@ -270,12 +259,12 @@ bool image_texture_load(struct texture_image *out_img,
size_t file_len = 0; size_t file_len = 0;
struct nbio_t *handle = NULL; struct nbio_t *handle = NULL;
void *ptr = NULL; void *ptr = NULL;
enum video_image_format fmt = image_texture_get_type(path); enum image_type_enum type = image_texture_get_type(path);
image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift, image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift,
&a_shift, out_img); &a_shift, out_img);
if (fmt != IMAGE_FORMAT_NONE) if (type != IMAGE_TYPE_NONE)
{ {
handle = (struct nbio_t*)nbio_open(path, NBIO_READ); handle = (struct nbio_t*)nbio_open(path, NBIO_READ);
if (!handle) if (!handle)
@ -290,7 +279,7 @@ bool image_texture_load(struct texture_image *out_img,
goto error; goto error;
if (image_texture_load_internal( if (image_texture_load_internal(
image_texture_convert_fmt_to_type(fmt), type,
ptr, file_len, out_img, ptr, file_len, out_img,
a_shift, r_shift, g_shift, b_shift)) a_shift, r_shift, g_shift, b_shift))
goto success; goto success;

View File

@ -24,6 +24,7 @@
#define __RARCH_IMAGE_CONTEXT_H #define __RARCH_IMAGE_CONTEXT_H
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
#include <retro_common_api.h> #include <retro_common_api.h>
@ -56,6 +57,8 @@ enum image_type_enum
IMAGE_TYPE_TGA IMAGE_TYPE_TGA
}; };
enum image_type_enum image_texture_get_type(const char *path);
bool image_texture_set_color_shifts(unsigned *r_shift, unsigned *g_shift, bool image_texture_set_color_shifts(unsigned *r_shift, unsigned *g_shift,
unsigned *b_shift, unsigned *a_shift, unsigned *b_shift, unsigned *a_shift,
struct texture_image *out_img); struct texture_image *out_img);
@ -64,6 +67,9 @@ bool image_texture_color_convert(unsigned r_shift,
unsigned g_shift, unsigned b_shift, unsigned a_shift, unsigned g_shift, unsigned b_shift, unsigned a_shift,
struct texture_image *out_img); struct texture_image *out_img);
bool image_texture_load_buffer(struct texture_image *img,
enum image_type_enum type, void *buffer, size_t buffer_len);
bool image_texture_load(struct texture_image *img, const char *path); bool image_texture_load(struct texture_image *img, const char *path);
void image_texture_free(struct texture_image *img); void image_texture_free(struct texture_image *img);