View Single Post
Old 04-20-2007, 05:22 PM   #18
Well past expiration date
tk102's Avatar
Join Date: Jan 2004
Posts: 5,767
Current Game: FTL
10 year veteran!  Forum Veteran  Helpful!  Notable contributor 
sub reverse_bytes {
	my $in=shift;
	return unpack('V',pack('C4',reverse (unpack('C4',pack('V',$in)))));
It is indeed a reversal of bytes (0xAABBCCDD becomes 0xDDCCBBAA for example).

This is so the $cpx variable in decode_dxt1 can be right shifted 2 bits at a time and disregarded as the new $px is calculated. The blended array is set up in such a way to make sense of the two bits (which are now reversed).

for (my $y=0; $y<4; $y++) {
  for (my $x=0; $x<4; $x++) {
    my $px = $cpx & 3;
    $pixels[($ty-4+$y)*$pitch +($tx+$x)]=$blended[$px];
    $cpx >>=2;

I don't have the tpc2tga source in front of me at the moment so I'm just working off the, btw -- the Perl code was a direct (more or less) translation of the C++.

Edit: crossed out the part about the 2 bits being reversed -- they aren't reversed -- their position within their bytes are unaltered but the bytes themselves are reordered.

Last edited by tk102; 04-20-2007 at 05:44 PM.
tk102 is offline   you may: quote & reply,