| 1 | // To compile and link with VC++ 8, I did (all in one line): |
|---|
| 2 | // D:\Dev\Projects\PerlTools>cl /EHsc /I../Libs BalanceDetailMap.cpp |
|---|
| 3 | // ..\Libs\build\win32\vc8\release\Bitmap\Bitmap.obj ..\..\ExtLibs\libpng-1.2.8\build\win32\vc8\release\cfs_png.lib |
|---|
| 4 | // ..\..\ExtLibs\libjpeg-6b\build\win32\vc8\release\cfs_jpeg.lib ..\..\ExtLibs\zlib-1.2.2\build\win32\vc8\release\cfs_z.lib |
|---|
| 5 | #include <iostream> |
|---|
| 6 | #include "Bitmap/Bitmap.hpp" |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | int main(int ArgC, const char* ArgV[]) |
|---|
| 10 | { |
|---|
| 11 | if (ArgC!=3) |
|---|
| 12 | { |
|---|
| 13 | std::cout << "Usage: BalanceDetailMap DetailMap BlurredDetailMap\n"; |
|---|
| 14 | return 1; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | BitmapT DetailMap; |
|---|
| 18 | BitmapT BlurredDetailMap; |
|---|
| 19 | |
|---|
| 20 | try |
|---|
| 21 | { |
|---|
| 22 | std::cout << "Reading detail map " << ArgV[1] << "...\n"; |
|---|
| 23 | DetailMap=BitmapT(ArgV[1]); |
|---|
| 24 | } |
|---|
| 25 | catch (const BitmapT::LoadErrorT& E) |
|---|
| 26 | { |
|---|
| 27 | std::cout << "Could not open " << ArgV[1] << "\n"; |
|---|
| 28 | return 1; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | try |
|---|
| 32 | { |
|---|
| 33 | std::cout << "Reading blurred detail map " << ArgV[2] << "...\n"; |
|---|
| 34 | BlurredDetailMap=BitmapT(ArgV[2]); |
|---|
| 35 | } |
|---|
| 36 | catch (const BitmapT::LoadErrorT& E) |
|---|
| 37 | { |
|---|
| 38 | std::cout << "Could not open " << ArgV[2] << "\n"; |
|---|
| 39 | return 1; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if (DetailMap.SizeX!=BlurredDetailMap.SizeX || DetailMap.SizeY!=BlurredDetailMap.SizeY) |
|---|
| 43 | { |
|---|
| 44 | std::cout << "The two input maps are not of the same size!\n"; |
|---|
| 45 | std::cout << ArgV[1] << " is " << DetailMap.SizeX << "*" << DetailMap.SizeY << ",\n"; |
|---|
| 46 | std::cout << ArgV[2] << " is " << BlurredDetailMap.SizeX << "*" << BlurredDetailMap.SizeY << ".\n"; |
|---|
| 47 | return 1; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | BitmapT Out(DetailMap.SizeX, DetailMap.SizeY); |
|---|
| 52 | |
|---|
| 53 | for (unsigned long y=0; y<DetailMap.SizeY; y++) |
|---|
| 54 | for (unsigned long x=0; x<DetailMap.SizeX; x++) |
|---|
| 55 | { |
|---|
| 56 | int r1, g1, b1, a1; |
|---|
| 57 | DetailMap.GetPixel(x, y, r1, g1, b1, a1); |
|---|
| 58 | |
|---|
| 59 | int r2, g2, b2; |
|---|
| 60 | BlurredDetailMap.GetPixel(x, y, r2, g2, b2); |
|---|
| 61 | |
|---|
| 62 | Out.SetPixel(x, y, r1-r2+128, g1-g2+128, b1-b2+128, a1); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | if (!Out.SaveToDisk("FixedDetailMap.png")) |
|---|
| 66 | { |
|---|
| 67 | std::cout << "Could not save the results to FixedDetailMap.png!\n"; |
|---|
| 68 | return 1; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | std::cout << "Results successfully saved to FixedDetailMap.png!\n"; |
|---|
| 73 | return 0; |
|---|
| 74 | } |
|---|