Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug 3475 - Remove unnecessary loop from IMG_tif.c
Daniel

This patch removes unnecessary loop from IMG_tif.c by using TIFFReadRGBAImageOriented() with ORIENTATION_TOPLEFT (TIFFReadRGBAImageis just an alias for TIFFReadRGBAImageOriented with ORIENTATION_BOTLEFT).
  • Loading branch information
slouken committed Nov 1, 2016
1 parent 15f68ba commit 0ef4450
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions IMG_tif.c
Expand Up @@ -37,7 +37,7 @@ static struct {
TIFF* (*TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
void (*TIFFClose)(TIFF*);
int (*TIFFGetField)(TIFF*, ttag_t, ...);
int (*TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
int (*TIFFReadRGBAImageOriented)(TIFF*, uint32, uint32, uint32*, int, int);
TIFFErrorHandler (*TIFFSetErrorHandler)(TIFFErrorHandler);
} lib;

Expand Down Expand Up @@ -70,10 +70,10 @@ int IMG_InitTIF()
SDL_UnloadObject(lib.handle);
return -1;
}
lib.TIFFReadRGBAImage =
(int (*)(TIFF*, uint32, uint32, uint32*, int))
SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
if ( lib.TIFFReadRGBAImage == NULL ) {
lib.TIFFReadRGBAImageOriented =
(int (*)(TIFF*, uint32, uint32, uint32*, int, int))
SDL_LoadFunction(lib.handle, "TIFFReadRGBAImageOriented");
if ( lib.TIFFReadRGBAImageOriented == NULL ) {
SDL_UnloadObject(lib.handle);
return -1;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ int IMG_InitTIF()
lib.TIFFClientOpen = TIFFClientOpen;
lib.TIFFClose = TIFFClose;
lib.TIFFGetField = TIFFGetField;
lib.TIFFReadRGBAImage = TIFFReadRGBAImage;
lib.TIFFReadRGBAImageOriented = TIFFReadRGBAImageOriented;
lib.TIFFSetErrorHandler = TIFFSetErrorHandler;
}
++lib.loaded;
Expand Down Expand Up @@ -240,23 +240,9 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
if(!surface)
goto error;

if(!lib.TIFFReadRGBAImage(tiff, img_width, img_height, (uint32 *)surface->pixels, 0))
if(!lib.TIFFReadRGBAImageOriented(tiff, img_width, img_height, (uint32 *)surface->pixels, ORIENTATION_TOPLEFT, 0))
goto error;

/* libtiff loads the image upside-down, flip it back */
half = img_height / 2;
for(y = 0; y < half; y++)
{
Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4;
Uint32 *bot = (Uint32 *)surface->pixels
+ (img_height - y - 1) * surface->pitch/4;
for(x = 0; x < img_width; x++)
{
Uint32 tmp = top[x];
top[x] = bot[x];
bot[x] = tmp;
}
}
lib.TIFFClose(tiff);

return surface;
Expand Down

0 comments on commit 0ef4450

Please sign in to comment.