aboutsummaryrefslogtreecommitdiff
path: root/loader.c
blob: 916407423a4dce6a661d0f03f6922aabc3d81750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <SDL2/SDL.h>
#include <string.h>

SDL_Texture* imv_load_png(SDL_Renderer *r, const char* path);
SDL_Texture* imv_load_jpeg(SDL_Renderer *r, const char* path);
SDL_Texture* imv_load_tiff(SDL_Renderer *r, const char* path);

SDL_Texture* imv_load_image(SDL_Renderer *r, const char* path)
{
  if(!path)
    return NULL;

  const char* ext = strrchr(path, '.');

  if(!ext)
    return NULL;

  if(strcasecmp(ext, ".png") == 0) {
    return imv_load_png(r, path);
  } else if(strcasecmp(ext, ".jpeg") == 0 || strcasecmp(ext, ".jpg") == 0) {
    return imv_load_jpeg(r, path);
  } else if(strcasecmp(ext, ".tif") == 0 || strcasecmp(ext, ".tiff") == 0) {
    return imv_load_tiff(r, path);
  }

  fprintf(stderr,
      "Could not determine filetype of '%s' from its extension.\n",
      path);
  return NULL;
}