diff --git a/CMakeLists.txt b/CMakeLists.txt index b031a0e..a8d13da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ add_executable(MicroPBR MicroPBR.cpp YUV.cpp SpheremapNormal.cpp ${ILIMAGE_SOURC target_link_libraries(MicroPBR PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib) add_executable(YUVTest YUVTest.cpp YUV.cpp SpheremapNormal.cpp ${ILIMAGE_SOURCE}) -target_link_libraries(YUVTest PRIVATE CMCore CMPlatform CMUtil DevIL ILU) +target_link_libraries(YUVTest PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib) add_executable(NormalTest NormalTest.cpp SpheremapNormal.cpp ${ILIMAGE_SOURCE}) target_link_libraries(NormalTest PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib) \ No newline at end of file diff --git a/MicroPBR.cpp b/MicroPBR.cpp index 1a07cff..f4aa9e4 100644 --- a/MicroPBR.cpp +++ b/MicroPBR.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace hgl; using namespace hgl::util; @@ -93,9 +94,40 @@ namespace hgl uint8 *GetRGB(){return (uint8 *)img.GetRGB(IL_UNSIGNED_BYTE);} uint8 *GetLum(){return (uint8 *)img.GetLum(IL_UNSIGNED_BYTE);} - - bool SaveFile(const OSString &fn){return img.SaveFile(fn);} };//class PBRComponent + + bool SaveRGBAFile(const OSString &filename,const uint w,const uint h,const uint8 *r,const uint8 *g,const uint8 *b,const uint8 *a,const OSString &flag) + { + const OSString out_filename=OSString(filename)+OS_TEXT("_")+flag+OS_TEXT(".png"); + + AutoDeleteArray pixels=new uint8[w*h*3]; + + MixRGBA(pixels,r,g,b,a,w*h); + + if(SaveImageToFile(out_filename,w,h,4,IL_UNSIGNED_BYTE,pixels)) + { + std_cout< pixels=new uint8[w*h*3]; + + MixRGB(pixels,r,g,b,w*h); + + if(SaveImageToFile(out_filename,w,h,3,IL_UNSIGNED_BYTE,pixels)) + { + std_cout< y,u,v,nx,ny; y=new uint8[pixel_total]; u=new uint8[half_pixel_total]; @@ -170,88 +202,41 @@ namespace hgl nx=new uint8[pixel_total]; ny=new uint8[pixel_total]; - RGB2YUV(y,u,v,color.GetRGB(),w,h); - normal_compress(nx,ny,normal.GetRGB(),w*h); - // BaseColor Y + Normal XY { - ILImage img; - const OSString out_filename=OSString(argv[1])+OS_TEXT("_YN.png"); + RGB2YUV(y,u,v,color.GetRGB(),w,h); + normal_compress(nx,ny,normal.GetRGB(),w*h); - uint8 *pixels=new uint8[pixel_total*3]; - - MixRGB(pixels,y,nx,ny,pixel_total); - - img.Create(w,h,3,IL_UNSIGNED_BYTE,pixels); - - delete[] pixels; - - if(img.SaveFile(out_filename)) - std_cout<(pixels,u,v,m,r,half_pixel_total); - - img.Create(half_w,half_h,4,IL_UNSIGNED_BYTE,pixels); - - delete[] pixels; - - if(img.SaveFile(out_filename)) - std_cout<(pixels,u,v,m,half_pixel_total); - - img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels); - - delete[] pixels; - - if(img.SaveFile(out_filename)) - std_cout<(pixels,u,v,r,half_pixel_total); - - img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels); - - delete[] pixels; - - if(img.SaveFile(out_filename)) - std_cout<(argv[1]); - filename+=OS_TEXT("_YUV.png"); - if(rgb_image.SaveFile(filename)) + if(SaveImageToFile(filename,rgb_image.width(),rgb_image.height(),3,IL_UNSIGNED_BYTE,rgb)) std_cout<