//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // // $Header: $ // $NoKeywords: $ //=============================================================================// #ifndef FLOAT_BM_H #define FLOAT_BM_H #ifdef _WIN32 #pragma once #endif #include #include "tier0/dbg.h" #include struct PixRGBAF { float Red; float Green; float Blue; float Alpha; }; struct PixRGBA8 { unsigned char Red; unsigned char Green; unsigned char Blue; unsigned char Alpha; }; inline PixRGBAF PixRGBA8_to_F( PixRGBA8 const &x ) { PixRGBAF f; f.Red = x.Red / 255.f; f.Green = x.Green / 255.f; f.Blue = x.Blue / 255.f; f.Alpha = x.Alpha / 255.f; return f; } inline PixRGBA8 PixRGBAF_to_8( PixRGBAF const &f ) { PixRGBA8 x; x.Red = max( 0.f, min( 255.f,255.f*f.Red ) ); x.Green = max( 0.f, min( 255.f,255.f*f.Green ) ); x.Blue = max( 0.f, min( 255.f,255.f*f.Blue ) ); x.Alpha = max( 0.f, min( 255.f,255.f*f.Alpha ) ); return x; } #define SPFLAGS_MAXGRADIENT 1 // bit flag options for ComputeSelfShadowedBumpmapFromHeightInAlphaChannel: #define SSBUMP_OPTION_NONDIRECTIONAL 1 // generate ambient occlusion only #define SSBUMP_MOD2X_DETAIL_TEXTURE 2 // scale so that a flat unshadowed // value is 0.5, and bake rgb luminance // in. class FloatBitMap_t { public: int Width, Height; // bitmap dimensions float *RGBAData; // actual data FloatBitMap_t(void) // empty one { Width=Height=0; RGBAData=0; } FloatBitMap_t(int width, int height); // make one and allocate space FloatBitMap_t(char const *filename); // read one from a file (tga or pfm) FloatBitMap_t(FloatBitMap_t const *orig); // quantize one to 8 bits bool WriteTGAFile(char const *filename) const; bool LoadFromPFM(char const *filename); // load from floating point pixmap (.pfm) file bool WritePFM(char const *filename); // save to floating point pixmap (.pfm) file void InitializeWithRandomPixelsFromAnotherFloatBM(FloatBitMap_t const &other); inline float & Pixel(int x, int y, int comp) const { Assert((x>=0) && (x=0) && (y= Width) x -= Width; if ( y < 0 ) y+=Height; else if ( y >= Height ) y -= Height; return RGBAData[4*(x+Width*y)+comp]; } inline float & PixelClamped(int x, int y, int comp) const { // like Pixel except wraps around to other side x=clamp(x,0,Width-1); y=clamp(y,0,Height-1); return RGBAData[4*(x+Width*y)+comp]; } inline float & Alpha(int x, int y) const { Assert((x>=0) && (x=0) && (y=0) && (x=0) && (y=0) && (x=0) && (y=0) && (x=0) && (y