diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-03 20:48:11 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-03 20:48:11 +0000 |
commit | 8ed155dcc105461fdaff64ad777ebda1e1180b24 (patch) | |
tree | 90b0221cab8239c46dcd51cdeca03bed700c22c9 /test | |
parent | 8eeed8edf478674f24377f1b42d98cb8f169b06e (diff) | |
download | libtiff-git-8ed155dcc105461fdaff64ad777ebda1e1180b24.tar.gz |
Fix raw_decode test so it works on big-endian machines.
The test case was ignoring the documented API for TIFFReadRGBATile,
namely that the output pixels are uint32's and the macros TIFFGetR etc
should be used to fetch the pixel components.
Original patch by Marcus Meissner, somewhat cleaned up by me.
Diffstat (limited to 'test')
-rw-r--r-- | test/raw_decode.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/test/raw_decode.c b/test/raw_decode.c index e73ee486..1521c970 100644 --- a/test/raw_decode.c +++ b/test/raw_decode.c @@ -1,4 +1,4 @@ -/* $Id: raw_decode.c,v 1.1 2012-06-01 21:04:22 fwarmerdam Exp $ */ +/* $Id: raw_decode.c,v 1.2 2012-07-03 20:48:11 tgl Exp $ */ /* * Copyright (c) 2012, Frank Warmerdam <warmerdam@pobox.com> @@ -82,18 +82,20 @@ static int check_rgb_pixel( int pixel, int red, int green, int blue, unsigned ch return 1; } -static int check_rgba_pixel( int pixel, int red, int green, int blue, int alpha, unsigned char *buffer ) { +static int check_rgba_pixel( int pixel, int red, int green, int blue, int alpha, uint32 *buffer ) { /* RGBA images are upside down - adjust for normal ordering */ int adjusted_pixel = pixel % 128 + (127 - (pixel/128)) * 128; - unsigned char *rgba = buffer + 4 * adjusted_pixel; - - if( rgba[0] == red && rgba[1] == green && rgba[2] == blue && rgba[3] == alpha ) { + uint32 rgba = buffer[adjusted_pixel]; + + if( TIFFGetR(rgba) == (uint32) red && TIFFGetG(rgba) == (uint32) green && + TIFFGetB(rgba) == (uint32) blue && TIFFGetA(rgba) == (uint32) alpha ) { return 0; } fprintf( stderr, "Pixel %d did not match expected results.\n", pixel ); fprintf( stderr, "Expect: %3d %3d %3d %3d\n", red, green, blue, alpha ); - fprintf( stderr, " Got: %3d %3d %3d %3d\n", rgba[0], rgba[1], rgba[2], rgba[3] ); + fprintf( stderr, " Got: %3d %3d %3d %3d\n", + TIFFGetR(rgba), TIFFGetG(rgba), TIFFGetB(rgba), TIFFGetA(rgba) ); return 1; } @@ -105,6 +107,7 @@ main(int argc, char **argv) unsigned short h, v; int status; unsigned char *buffer; + uint32 *rgba_buffer; tsize_t sz, szout; (void) argc; @@ -187,10 +190,10 @@ main(int argc, char **argv) */ tif = TIFFOpen(srcfile,"r"); - sz = 128 * 128 * 4; - buffer = (unsigned char *) malloc(sz); + sz = 128 * 128 * sizeof(uint32); + rgba_buffer = (uint32 *) malloc(sz); - if (!TIFFReadRGBATile( tif, 1*128, 2*128, (uint32 *) buffer )) { + if (!TIFFReadRGBATile( tif, 1*128, 2*128, rgba_buffer )) { fprintf( stderr, "TIFFReadRGBATile() returned failure code.\n" ); return 1; } @@ -201,13 +204,13 @@ main(int argc, char **argv) * accomplish it from the YCbCr subsampled buffer ourselves in which * case the results may be subtly different but similar. */ - if (check_rgba_pixel( 0, 15, 0, 18, 255, buffer ) - || check_rgba_pixel( 64, 0, 0, 2, 255, buffer ) - || check_rgba_pixel( 512, 6, 36, 182, 255, buffer ) ) { + if (check_rgba_pixel( 0, 15, 0, 18, 255, rgba_buffer ) + || check_rgba_pixel( 64, 0, 0, 2, 255, rgba_buffer ) + || check_rgba_pixel( 512, 6, 36, 182, 255, rgba_buffer ) ) { exit(1); } - free( buffer ); + free( rgba_buffer ); TIFFClose(tif); exit( 0 ); |