mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
Image file type detection fixes/optimisations
This commit is contained in:
parent
00d7c40c7a
commit
d24498bdf1
@ -28,26 +28,51 @@
|
|||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <formats/image.h>
|
#include <formats/image.h>
|
||||||
#include <file/nbio.h>
|
#include <file/nbio.h>
|
||||||
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
enum image_type_enum image_texture_get_type(const char *path)
|
enum image_type_enum image_texture_get_type(const char *path)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_RTGA
|
/* We are comparing against a fixed list of file
|
||||||
if (strstr(path, ".tga"))
|
* extensions, the longest (jpeg) being 4 characters
|
||||||
return IMAGE_TYPE_TGA;
|
* in length. We therefore only need to extract the first
|
||||||
#endif
|
* 5 characters from the extension of the input path
|
||||||
|
* to correctly validate a match */
|
||||||
|
const char *ext = NULL;
|
||||||
|
char ext_lower[6];
|
||||||
|
|
||||||
|
ext_lower[0] = '\0';
|
||||||
|
|
||||||
|
if (string_is_empty(path))
|
||||||
|
return IMAGE_TYPE_NONE;
|
||||||
|
|
||||||
|
/* Get file extension */
|
||||||
|
ext = strrchr(path, '.');
|
||||||
|
|
||||||
|
if (!ext || (*(++ext) == '\0'))
|
||||||
|
return IMAGE_TYPE_NONE;
|
||||||
|
|
||||||
|
/* Copy and convert to lower case */
|
||||||
|
strlcpy(ext_lower, ext, sizeof(ext_lower));
|
||||||
|
string_to_lower(ext_lower);
|
||||||
|
|
||||||
#ifdef HAVE_RPNG
|
#ifdef HAVE_RPNG
|
||||||
if (strstr(path, ".png"))
|
if (string_is_equal(ext_lower, "png"))
|
||||||
return IMAGE_TYPE_PNG;
|
return IMAGE_TYPE_PNG;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_RJPEG
|
#ifdef HAVE_RJPEG
|
||||||
if (strstr(path, ".jpg") || strstr(path, ".jpeg"))
|
if (string_is_equal(ext_lower, "jpg") ||
|
||||||
|
string_is_equal(ext_lower, "jpeg"))
|
||||||
return IMAGE_TYPE_JPEG;
|
return IMAGE_TYPE_JPEG;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_RBMP
|
#ifdef HAVE_RBMP
|
||||||
if (strstr(path, ".bmp"))
|
if (string_is_equal(ext_lower, "bmp"))
|
||||||
return IMAGE_TYPE_BMP;
|
return IMAGE_TYPE_BMP;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_RTGA
|
||||||
|
if (string_is_equal(ext_lower, "tga"))
|
||||||
|
return IMAGE_TYPE_TGA;
|
||||||
|
#endif
|
||||||
|
|
||||||
return IMAGE_TYPE_NONE;
|
return IMAGE_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,21 @@ static INLINE bool string_starts_with(const char *str, const char *prefix)
|
|||||||
return (str && prefix) ? !strncmp(prefix, str, strlen(prefix)) : false;
|
return (str && prefix) ? !strncmp(prefix, str, strlen(prefix)) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static INLINE bool string_ends_with(const char *str, const char *suffix)
|
||||||
|
{
|
||||||
|
size_t str_len;
|
||||||
|
size_t suffix_len;
|
||||||
|
|
||||||
|
if (!str || !suffix)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
str_len = strlen(str);
|
||||||
|
suffix_len = strlen(suffix);
|
||||||
|
|
||||||
|
return (str_len < suffix_len) ? false :
|
||||||
|
!memcmp(suffix, str + (str_len - suffix_len), suffix_len);
|
||||||
|
}
|
||||||
|
|
||||||
#define STRLEN_CONST(x) ((sizeof((x))-1))
|
#define STRLEN_CONST(x) ((sizeof((x))-1))
|
||||||
|
|
||||||
#define string_is_not_equal(a, b) !string_is_equal((a), (b))
|
#define string_is_not_equal(a, b) !string_is_equal((a), (b))
|
||||||
|
@ -422,7 +422,7 @@ bool task_push_image_load(const char *fullpath,
|
|||||||
|
|
||||||
nbio->path = strdup(fullpath);
|
nbio->path = strdup(fullpath);
|
||||||
|
|
||||||
image->type = IMAGE_TYPE_NONE;
|
image->type = image_texture_get_type(fullpath);
|
||||||
image->status = IMAGE_STATUS_WAIT;
|
image->status = IMAGE_STATUS_WAIT;
|
||||||
image->is_blocking = false;
|
image->is_blocking = false;
|
||||||
image->is_blocking_on_processing = false;
|
image->is_blocking_on_processing = false;
|
||||||
@ -439,26 +439,23 @@ bool task_push_image_load(const char *fullpath,
|
|||||||
/* TODO/FIXME - shouldn't we set this ? */
|
/* TODO/FIXME - shouldn't we set this ? */
|
||||||
image->ti.supports_rgba = false;
|
image->ti.supports_rgba = false;
|
||||||
|
|
||||||
if (strstr(fullpath, ".png"))
|
switch (image->type)
|
||||||
{
|
{
|
||||||
|
case IMAGE_TYPE_PNG:
|
||||||
nbio->type = NBIO_TYPE_PNG;
|
nbio->type = NBIO_TYPE_PNG;
|
||||||
image->type = IMAGE_TYPE_PNG;
|
break;
|
||||||
}
|
case IMAGE_TYPE_JPEG:
|
||||||
else if (strstr(fullpath, ".jpeg")
|
|
||||||
|| strstr(fullpath, ".jpg"))
|
|
||||||
{
|
|
||||||
nbio->type = NBIO_TYPE_JPEG;
|
nbio->type = NBIO_TYPE_JPEG;
|
||||||
image->type = IMAGE_TYPE_JPEG;
|
break;
|
||||||
}
|
case IMAGE_TYPE_BMP:
|
||||||
else if (strstr(fullpath, ".bmp"))
|
|
||||||
{
|
|
||||||
nbio->type = NBIO_TYPE_BMP;
|
nbio->type = NBIO_TYPE_BMP;
|
||||||
image->type = IMAGE_TYPE_BMP;
|
break;
|
||||||
}
|
case IMAGE_TYPE_TGA:
|
||||||
else if (strstr(fullpath, ".tga"))
|
|
||||||
{
|
|
||||||
nbio->type = NBIO_TYPE_TGA;
|
nbio->type = NBIO_TYPE_TGA;
|
||||||
image->type = IMAGE_TYPE_TGA;
|
break;
|
||||||
|
default:
|
||||||
|
nbio->type = NBIO_TYPE_NONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbio->data = (struct nbio_image_handle*)image;
|
nbio->data = (struct nbio_image_handle*)image;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user