//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // //===========================================================================// #include #include #include #include #include #include "bitmap/float_bm.h" static float ScaleValue(float f, float overbright) { // map a value between 0..255 to the scale factor int ival=f; return ival*(overbright/255.0); } static float IScaleValue(float f, float overbright) { f*=(1.0/overbright); int ival=min(255,(int)ceil(f*255.0)); return ival; } void MaybeSetScaleVaue(FloatBitMap_t const &orig, FloatBitMap_t &newbm, int x, int y, float newscale, float overbright) { // clamp the given scale value to the legal range for that pixel and regnerate the rgb // components. float maxc=max(max(orig.Pixel(x,y,0),orig.Pixel(x,y,1)),orig.Pixel(x,y,2)); if (maxc==0.0) { // pixel is black. any scale value is fine. newbm.Pixel(x,y,3)=newscale; for(int c=0;c<3;c++) newbm.Pixel(x,y,c)=0; } else { // float desired_floatscale=maxc; float scale_we_will_get=ScaleValue(newscale,overbright); // if (scale_we_will_get >= desired_floatscale ) { newbm.Pixel(x,y,3)=newscale; for(int c=0;c<3;c++) newbm.Pixel(x,y,c)=orig.Pixel(x,y,c)/(scale_we_will_get); } } } void FloatBitMap_t::Uncompress(float overbright) { for(int y=0;y