| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2009.11.03 10:14 "Re: Tiffcrop test suite and logluv issues", by Juergen BuchmuellerOn Mon, 02 Nov 2009 14:59:43 -0700
Richard Nolde <richard.nolde@cybox.com> wrote:
[snap]
> as I suspect, the following code from tif_luv.c doesn't take into
> consideration the fact that the original data is bigendian and I am
> compiling on a little endian host (having just gone through this with
> Toby's patch suggestion.)
[snip]
> for (i = 0; i < npixels && cc > 0; i++) {
> tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2];
> bp += 3;
> cc -= 3;
> }
As Toby said, this is endian safe. We've used it over and over again
when coding CPU emulations for MAME :)
But didn't your compiler warn you about the ambiguity of the
Shift-Left / OR expression? AFAIK one should put parens around the
shifted terms to tell the compiler that the shift has precedence over
the OR. I.e. you don't want bp[0] << (16 | bp[1]), which in theory is a
valid way to reduce the expression.
Alternatively one could write:
tp[i] = 65536 * bp[0] + 256 * bp[1] + bp[2];
Compilers today transform the power-of-two multiplications into rather
effective code (read: shift lefts) and it doesn't require parens.
HTH
Juergen
|
|||||||