From ae019a01faae3b86808befadab158035d524936f Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Fri, 6 Nov 2015 16:18:54 +0000 Subject: Merge freeimage.c into main.c --- freeimage.c | 24 ------------------------ main.c | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 freeimage.c diff --git a/freeimage.c b/freeimage.c deleted file mode 100644 index 6b62751..0000000 --- a/freeimage.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -SDL_Texture* imv_load_freeimage(SDL_Renderer *r, const char* path) -{ - FREE_IMAGE_FORMAT fmt = FreeImage_GetFileType(path,0); - FIBITMAP *image = FreeImage_Load(fmt, path, 0); - FreeImage_FlipVertical(image); - - FIBITMAP* temp = image; - image = FreeImage_ConvertTo32Bits(image); - FreeImage_Unload(temp); - - int w = FreeImage_GetWidth(image); - int h = FreeImage_GetHeight(image); - char* pixels = (char*)FreeImage_GetBits(image); - - SDL_Texture *img = SDL_CreateTexture(r, - SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, w, h); - SDL_Rect area = {0,0,w,h}; - SDL_UpdateTexture(img, &area, pixels, sizeof(unsigned int) * w); - FreeImage_Unload(image); - return img; -} diff --git a/main.c b/main.c index fb77d65..c914ad7 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,6 @@ #include #include - -SDL_Texture* imv_load_freeimage(SDL_Renderer *r, const char* path); +#include struct loop_item_s { struct loop_item_s *prev; @@ -98,6 +97,28 @@ void prev_path() g_path.dir = -1; } +SDL_Texture* load_freeimage(SDL_Renderer *r, const char* path) +{ + FREE_IMAGE_FORMAT fmt = FreeImage_GetFileType(path,0); + FIBITMAP *image = FreeImage_Load(fmt, path, 0); + FreeImage_FlipVertical(image); + + FIBITMAP* temp = image; + image = FreeImage_ConvertTo32Bits(image); + FreeImage_Unload(temp); + + int w = FreeImage_GetWidth(image); + int h = FreeImage_GetHeight(image); + char* pixels = (char*)FreeImage_GetBits(image); + + SDL_Texture *img = SDL_CreateTexture(r, + SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, w, h); + SDL_Rect area = {0,0,w,h}; + SDL_UpdateTexture(img, &area, pixels, sizeof(unsigned int) * w); + FreeImage_Unload(image); + return img; +} + int main(int argc, char** argv) { if(argc < 2) { @@ -177,7 +198,7 @@ int main(int argc, char** argv) SDL_DestroyTexture(img); img = NULL; } - img = imv_load_freeimage(renderer, g_path.cur->path); + img = load_freeimage(renderer, g_path.cur->path); if(img == NULL) { fprintf(stderr, "Ignoring unsupported file: %s\n", g_path.cur->path); remove_current_path(); -- cgit v1.2.3