From 13baf03ffbec87e988eb06dda40f0a44b2d4881a Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 30 Mar 2015 11:22:25 +0200 Subject: [PATCH] Apply bayer dither to TGA16 export for smoother lightmaps --- code/nel/tools/3d/tga_2_dds/tga2dds.cpp | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp index 292280349..19fd70d32 100644 --- a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp +++ b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp @@ -359,6 +359,13 @@ void dividSize (CBitmap &bitmap) } } +const int bayerDiv8[4][4] = { + 0, 4, 1, 5, + 6, 2, 7, 3, + 1, 5, 0, 4, + 7, 3, 6, 2, +}; + // *************************************************************************** int main(int argc, char **argv) { @@ -601,6 +608,26 @@ int main(int argc, char **argv) Reduce--; } + if (algo == TGA16) + { + // Apply bayer dither + CObjectVector &rgba = picSrc.getPixels(0); + const uint32 w = picSrc.getWidth(0); + uint32 x = 0; + uint32 y = 0; + for (uint32 i = 0; i < rgba.size(); i += 4) + { + NLMISC::CRGBA &c = reinterpret_cast(rgba[i]); + c.R = (uint8)std::min(255, (int)c.R + bayerDiv8[x % 4][y % 4]); + c.G = (uint8)std::min(255, (int)c.G + bayerDiv8[x % 4][y % 4]); + c.B = (uint8)std::min(255, (int)c.B + bayerDiv8[x % 4][y % 4]); + ++x; + x %= w; + if (x == 0) + ++y; + } + } + // 8 or 16 bits TGA or PNG ? if ((algo == TGA16) || (algo == TGA8) || (algo == PNG16) || (algo == PNG8)) {