NL3D::CTileLumel Class Reference

#include <tile_lumel.h>


Detailed Description

This class describe an uncompressed lumel for tiles.

Author:
Cyril Corvazier

Nevrax France

Date:
2000

Definition at line 47 of file tile_lumel.h.

Public Member Functions

void createCompressed (uint8 interpolated, uint8 _4bits)
void createUncompressed (uint8 interpolated, uint8 shaded)
bool isShadowed () const
void pack (CStreamBit &stream) const
void unpack (CStreamBit &stream, uint8 interpolated)

Static Public Member Functions

void skip (CStreamBit &stream)

Data Fields

uint8 Shaded
 The shading value [0-255]. Always valid.


Private Attributes

uint8 _ShadowValue
 The shadow 4 bits value [0-15]. 0xff means no shadows.


Member Function Documentation

void NL3D::CTileLumel::createCompressed uint8  interpolated,
uint8  _4bits
[inline]
 

Create a tileLumel with precompressed data.

Parameters:
interpolated is the bilinear interpolated value at this lumel.
_4bits is the 4 bits compressed shadow.

Definition at line 204 of file tile_lumel.h.

References _ShadowValue, Shaded, uint, and uint8.

Referenced by unpack().

00205 {
00206         // Shadow value
00207         _ShadowValue=_4bits;
00208 
00209         // Shading
00210         uint temp=(((uint)interpolated*((uint)_ShadowValue))>>3)+4;
00211         if (temp>255)
00212                 temp=255;
00213 
00214         Shaded=(uint8)temp;
00215 }

void NL3D::CTileLumel::createUncompressed uint8  interpolated,
uint8  shaded
 

Create a tileLumel from uncompressed data.

Parameters:
interpolated is the bilinear interpolated value at this lumel.
shaded is the reel shading value at this lumel.

Definition at line 37 of file tile_lumel.cpp.

References _ShadowValue, NLMISC::clamp(), Shaded, sint, uint, and uint8.

00038 {
00039         // Shading 
00040         Shaded=shaded;
00041 
00042         // Same color ?
00043         if (interpolated!=shaded)
00044         {
00045                 // Compute compressed value
00046                 sint temp=((shaded<<3)/(sint)(interpolated?interpolated:1));
00047                 clamp (temp, 0, 15);
00048 
00049                 // After decompression
00050                 uint decompressed=(((uint)interpolated*((uint)temp))>>3)+4;
00051                 if (decompressed>255)
00052                         decompressed=255;
00053 
00054                 // Need to compress ?
00055                 if (abs((sint)shaded-(sint)decompressed)>=abs((sint)shaded-(sint)interpolated))
00056                 {
00057                         // Shadow not present
00058                         _ShadowValue=0xff;
00059                 }
00060                 else
00061                 {
00062                         // Shadow
00063                         _ShadowValue=temp;
00064                 }
00065         }
00066         else
00067         {
00068                 // Shadow not present
00069                 _ShadowValue=0xff;
00070         }
00071 }

bool NL3D::CTileLumel::isShadowed  )  const [inline]
 

Is shadow are present? return true if this lumel is shadowed, else false.

Parameters:
stream is the bit stream used to pack the lumel.

Definition at line 117 of file tile_lumel.h.

References _ShadowValue.

Referenced by pack().

00118         {
00119                 return (_ShadowValue!=0xff);
00120         }

void NL3D::CTileLumel::pack CStreamBit stream  )  const
 

Pack the lumel from a bit stream.

Parameters:
stream is the bit stream used to pack the lumel.

Definition at line 74 of file tile_lumel.cpp.

References _ShadowValue, isShadowed(), NL3D::CTileLumel::CStreamBit::pushBack4bits(), and NL3D::CTileLumel::CStreamBit::pushBackBool().

00075 {
00076         // There is shadow here ?
00077         if (isShadowed ())
00078         {
00079                 // Put a true
00080                 stream.pushBackBool(true);
00081 
00082                 // Read the shadow value
00083                 stream.pushBack4bits(_ShadowValue);
00084         }
00085         else
00086                 // Put a false
00087                 stream.pushBackBool(false);
00088 }

void NL3D::CTileLumel::skip CStreamBit stream  )  [inline, static]
 

Skip the lumel from a bit stream.

Parameters:
stream is the bit stream used to skip the lumel.

Definition at line 240 of file tile_lumel.h.

References NL3D::CTileLumel::CStreamBit::popBack4bits(), and NL3D::CTileLumel::CStreamBit::popBackBool().

00241 {
00242         // There is shadow here ?
00243         if (stream.popBackBool())
00244         {
00245                 // Read the shadow value
00246                 stream.popBack4bits();
00247         }
00248 }

void NL3D::CTileLumel::unpack CStreamBit stream,
uint8  interpolated
[inline]
 

Unpack the lumel from a bit stream.

Parameters:
interpolated is the bilinear interpolated value at this lumel.
stream is the bit stream used to unpack the lumel.

Definition at line 218 of file tile_lumel.h.

References _ShadowValue, createCompressed(), NL3D::CTileLumel::CStreamBit::popBack4bits(), NL3D::CTileLumel::CStreamBit::popBackBool(), Shaded, uint8, and value.

00219 {
00220         // There is shadow here ?
00221         if (stream.popBackBool())
00222         {
00223                 // Read the shadow value
00224                 uint8 value=stream.popBack4bits();
00225 
00226                 // Unpack it
00227                 createCompressed (interpolated, value);
00228         }
00229         else
00230         {
00231                 // Put a default shading
00232                 Shaded=interpolated;
00233 
00234                 // Shadow not present
00235                 _ShadowValue=0xff;
00236         }
00237 }


Field Documentation

uint8 NL3D::CTileLumel::_ShadowValue [private]
 

The shadow 4 bits value [0-15]. 0xff means no shadows.

Definition at line 127 of file tile_lumel.h.

Referenced by createCompressed(), createUncompressed(), isShadowed(), pack(), and unpack().

uint8 NL3D::CTileLumel::Shaded
 

The shading value [0-255]. Always valid.

Definition at line 124 of file tile_lumel.h.

Referenced by createCompressed(), createUncompressed(), and unpack().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 08:04:56 2004 for NeL by doxygen 1.3.6