#include #include #include #include #include #include using namespace hgl; using namespace hgl::util; #if HGL_OS == HGL_OS_Windows #define std_cout std::wcout #else #define std_cout std::cout #endif// namespace hgl { void RGB2YUV(uint8 *y,uint8 *u,uint8 *v,const uint8 *rgb,const uint w,const uint h); void normal_compress(uint8 *x,uint8 *y,const uint8 *rgb,const uint count); template void MixRGB(T *rgb,const T *r,const T *g,const T *b,const uint count) { for(uint i=0;i void MixRGBA(T *rgba,const T *r,const T *g,const T *b,const T *a,const uint count) { for(uint i=0;i 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< /C:BaseColor.png /N:Normal.png /M:Metallic.png /R:Roughness.png"<>1; const uint half_h=h>>1; const uint pixel_total=w*h; const uint half_pixel_total=half_w*half_h; if(metallic.isHas()) { metallic.ToGray(); metallic.Resize(half_w,half_h); } if(roughness.isHas()) { roughness.ToGray(); roughness.Resize(half_w,half_h); } AutoDeleteArray y,u,v,nx,ny; y=new uint8[pixel_total]; u=new uint8[half_pixel_total]; v=new uint8[half_pixel_total]; nx=new uint8[pixel_total]; ny=new uint8[pixel_total]; // BaseColor Y + Normal XY { RGB2YUV(y,u,v,color.GetRGB(),w,h); normal_compress(nx,ny,normal.GetRGB(),w*h); SaveRGBFile( argv[1], w,h, y,nx,ny, OS_TEXT("YN")); } if(metallic.isHas()&&roughness.isHas()) { SaveRGBAFile(argv[1], half_w,half_h, u,v,metallic.GetLum(),roughness.GetLum(), OS_TEXT("UVMR")); } else if(metallic.isHas()) { SaveRGBFile( argv[1], half_w,half_h, u,v,metallic.GetLum(), OS_TEXT("UVM")); } else if(roughness.isHas()) { SaveRGBFile( argv[1], half_w,half_h, u,v,roughness.GetLum(), OS_TEXT("UVR")); } ilShutDown(); return 0; }