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 --- utils/Texturesynth/tsynth.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 utils/Texturesynth/tsynth.cpp (limited to 'utils/Texturesynth/tsynth.cpp') diff --git a/utils/Texturesynth/tsynth.cpp b/utils/Texturesynth/tsynth.cpp new file mode 100644 index 0000000..86a634e --- /dev/null +++ b/utils/Texturesynth/tsynth.cpp @@ -0,0 +1,102 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "tier0/platform.h" +#include "bitmap/float_bm.h" +#include "mathlib/mathlib.h" +#include "tier2/tier2.h" +#include "bitmap/tgaloader.h" + +#define NEIGHBORHOOD_SIZE 5 + +void SynthesizeTexture(FloatBitMap_t & output, FloatBitMap_t const & input) +{ + // init output with histogram-equalized random pixels + output.InitializeWithRandomPixelsFromAnotherFloatBM(input); + + // build image pyramids + FloatImagePyramid_t input_pyramid(input,PYRAMID_MODE_GAUSSIAN); + FloatImagePyramid_t output_pyramid(output,PYRAMID_MODE_GAUSSIAN); + + // now, synthesize texture from lowest res to highest + for(int level=min(input_pyramid.m_nLevels,output_pyramid.m_nLevels)-2;level>=0;level--) + { + FloatBitMap_t & output=*(output_pyramid.Level(level)); + FloatBitMap_t & output0=*(output_pyramid.Level(level+1)); + FloatBitMap_t & input=*(input_pyramid.Level(level)); + FloatBitMap_t & input0=*(input_pyramid.Level(level+1)); + if ( + (input.Width < NEIGHBORHOOD_SIZE*3) || + (input.Height < NEIGHBORHOOD_SIZE*3) + ) + { + printf("skip level %d\n",level); + continue; + } + // now, synthesize each pixel + for(int yloop=0;yloop