aboutsummaryrefslogtreecommitdiff
path: root/tiff.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-06 12:59:54 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-06 12:59:54 +0000
commitae299885d5bb3001dd7d6105d12ecbce2b06f13b (patch)
treefb0e4a21fab4bdc3b5fe273dc5d7eb0506aef462 /tiff.c
parentf18d3f357d22445ef58d4ec34532985c925ad408 (diff)
downloadimv-ae299885d5bb3001dd7d6105d12ecbce2b06f13b.tar.gz
Add TIFF support
Diffstat (limited to 'tiff.c')
-rw-r--r--tiff.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tiff.c b/tiff.c
new file mode 100644
index 0000000..eb38c4d
--- /dev/null
+++ b/tiff.c
@@ -0,0 +1,26 @@
+#include <SDL2/SDL.h>
+#include <tiffio.h>
+
+SDL_Texture* imv_load_tiff(SDL_Renderer *r, const char* path)
+{
+ TIFF* tif = TIFFOpen(path, "r");
+ if(!tif) {
+ return NULL;
+ }
+ SDL_Texture *img = NULL;
+ uint32 w, h;
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
+ size_t npixels = w * h;
+ uint32 *pixels = (uint32*) malloc(npixels * sizeof (uint32));
+ if (TIFFReadRGBAImageOriented(tif, w, h, pixels, ORIENTATION_TOPLEFT, 0)) {
+ img = SDL_CreateTexture(r,
+ SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, w, h);
+ SDL_Rect area = {0,0,w,h};
+ SDL_UpdateTexture(img, &area, pixels, sizeof(uint32) * w);
+ }
+ free(pixels);
+ TIFFClose(tif);
+ return img;
+}
+