From 493fbabb855645e00c304cccaf1dfca764fa5305 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Tue, 19 Feb 2019 12:07:58 +0800 Subject: [PATCH] windowscodecs: Avoid redundant checks when reading a TIFF tile. Signed-off-by: Dmitry Timoshkov Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/windowscodecs/tiffformat.c | 42 ++++++++++++--------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c index 3bc8d696cab..295330aea2c 100644 --- a/dlls/windowscodecs/tiffformat.c +++ b/dlls/windowscodecs/tiffformat.c @@ -974,34 +974,25 @@ static HRESULT WINAPI TiffFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT tile_y) { - HRESULT hr=S_OK; tsize_t ret; int swap_bytes; swap_bytes = pTIFFIsByteSwapped(This->parent->tiff); ret = pTIFFSetDirectory(This->parent->tiff, This->index); + if (ret == -1) + return E_FAIL; + + if (This->decode_info.tiled) + ret = pTIFFReadEncodedTile(This->parent->tiff, tile_x + tile_y * This->decode_info.tiles_across, This->cached_tile, This->decode_info.tile_size); + else + ret = pTIFFReadEncodedStrip(This->parent->tiff, tile_y, This->cached_tile, This->decode_info.tile_size); if (ret == -1) - hr = E_FAIL; - - if (hr == S_OK) - { - if (This->decode_info.tiled) - { - ret = pTIFFReadEncodedTile(This->parent->tiff, tile_x + tile_y * This->decode_info.tiles_across, This->cached_tile, This->decode_info.tile_size); - } - else - { - ret = pTIFFReadEncodedStrip(This->parent->tiff, tile_y, This->cached_tile, This->decode_info.tile_size); - } - - if (ret == -1) - hr = E_FAIL; - } + return E_FAIL; /* 8bpp grayscale with extra alpha */ - if (hr == S_OK && This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32) + if (This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32) { BYTE *src; DWORD *dst, count = This->decode_info.tile_width * This->decode_info.tile_height; @@ -1016,7 +1007,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (hr == S_OK && This->decode_info.reverse_bgr) + if (This->decode_info.reverse_bgr) { if (This->decode_info.bps == 8) { @@ -1027,7 +1018,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (hr == S_OK && swap_bytes && This->decode_info.bps > 8) + if (swap_bytes && This->decode_info.bps > 8) { UINT row, i, samples_per_row; BYTE *sample, temp; @@ -1055,7 +1046,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (hr == S_OK && This->decode_info.invert_grayscale) + if (This->decode_info.invert_grayscale) { BYTE *byte, *end; @@ -1071,13 +1062,10 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT *byte = ~(*byte); } - if (hr == S_OK) - { - This->cached_tile_x = tile_x; - This->cached_tile_y = tile_y; - } + This->cached_tile_x = tile_x; + This->cached_tile_y = tile_y; - return hr; + return S_OK; } static HRESULT WINAPI TiffFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,