From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- bitmap/float_bm2.cpp | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 bitmap/float_bm2.cpp (limited to 'bitmap/float_bm2.cpp') diff --git a/bitmap/float_bm2.cpp b/bitmap/float_bm2.cpp new file mode 100644 index 0000000..2e113c7 --- /dev/null +++ b/bitmap/float_bm2.cpp @@ -0,0 +1,144 @@ +//========= 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