POV-Ray : Newsgroups : povray.general : Possible 16-bit TGA read error (minor) Server Time
27 Dec 2024 05:38:11 EST (-0500)
  Possible 16-bit TGA read error (minor) (Message 1 to 1 of 1)  
From: Ray Gardener
Subject: Possible 16-bit TGA read error (minor)
Date: 1 Mar 2007 04:51:04
Message: <45e6a208$1@news.povray.org>
I have come across some suspicious code in:

   App:    POV-Ray for Windows 3.6
   Module: source/targa.cpp
   Func:   convert_targa_color
   Line:   ~807

The code converts two physical pixel bytes into an IMAGE_COLOUR. 
However, in the 16-bit case the physical-to-logical conversion leaves 
the bottom three bits of each logical 8-bit RGB channel to zero, doing a 
slightly incorrect scaling of the color data from 5 bits to 8 bits. 100% 
white, for example, winds up 97% white.

The code

  tcolor->Red   = ((bytes[1] & 0x7c) << 1);
  tcolor->Green = (((bytes[1] & 0x03) << 3) | ((bytes[0] & 0xe0) >> 5)) 
<< 3;
  tcolor->Blue  = (bytes[0] & 0x1f) << 3;


should possibly read

  #define CVT(_n) (int)(8.22581f * (_n))
  tcolor->Red   = CVT((bytes[1] & 0x7c) >> 2);
  tcolor->Green = CVT(((bytes[1] & 0x03) << 3) | ((bytes[0] & 0xe0) >> 5));
  tcolor->Blue  = CVT(bytes[0] & 0x1f);


-- 
Ray Gardener
Daylon Graphics Ltd.
"Heightfield modeling perfected"


Post a reply to this message

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