POV-Ray : Newsgroups : povray.off-topic : Adventures with digital painting : Re: Adventures with digital painting Server Time
11 Oct 2024 11:09:53 EDT (-0400)
  Re: Adventures with digital painting  
From: Darren New
Date: 11 Mar 2008 22:02:13
Message: <47d747b5$1@news.povray.org>
Warp wrote:
> Another possibility would be to build the word always in the same
> way and have the "compiler reverse it in architectures with the other
> endianess" (if that's even possible in any compiler of any language),
> but that would mean a bunch of extra steps in that other endianess
> architecture, for no good reason.

No, you'd declare a four-byte integer in native endianness, and a 
four-byte word in the buffer in little (or big) endianness, and have the 
compiler either generate code to directly copy (if the native 
architecture's endianness matches the spec's endienness) or have it 
generate the optimal machine code sequence to do the swap if they don't 
match.

The "build four-byte pixels into words" works just fine too.

(I forget the exact syntax, but it's something like)
outint : new integer 0..2^32-1;
outint'endian = little;

buffer : array [0..N] of outint;
buffer[i] = r * 256*256*256 + g * 256 * 256 + b * 256 + a;

If outint is in native form, it does the shifts and stores it, or 
assigns the bytes, or whatever the compiler can come up with.

If outint is in byte-swapped order, the compiler can *also* deduce it 
needs to do the shifts differently, and just assign bytes to the 
appropriate places in the word.

(Note that compilers aren't dumb enough to actually multiply when you 
say r * 256 * 256 * 256.)

Makes it much clearer code, methinks, and no ifdefs.

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.