to improve code
This commit is contained in:
parent
1cfb30faea
commit
b09db9ae35
@ -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)
|
target_link_libraries(MicroPBR PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib)
|
||||||
|
|
||||||
add_executable(YUVTest YUVTest.cpp YUV.cpp SpheremapNormal.cpp ${ILIMAGE_SOURCE})
|
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})
|
add_executable(NormalTest NormalTest.cpp SpheremapNormal.cpp ${ILIMAGE_SOURCE})
|
||||||
target_link_libraries(NormalTest PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib)
|
target_link_libraries(NormalTest PRIVATE CMCore CMPlatform CMUtil DevIL ILU MathGeoLib)
|
121
MicroPBR.cpp
121
MicroPBR.cpp
@ -3,6 +3,7 @@
|
|||||||
#include<ILImage.h>
|
#include<ILImage.h>
|
||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
#include<hgl/util/cmd/CmdParse.h>
|
#include<hgl/util/cmd/CmdParse.h>
|
||||||
|
#include<hgl/type/Smart.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::util;
|
using namespace hgl::util;
|
||||||
@ -93,9 +94,40 @@ namespace hgl
|
|||||||
|
|
||||||
uint8 *GetRGB(){return (uint8 *)img.GetRGB(IL_UNSIGNED_BYTE);}
|
uint8 *GetRGB(){return (uint8 *)img.GetRGB(IL_UNSIGNED_BYTE);}
|
||||||
uint8 *GetLum(){return (uint8 *)img.GetLum(IL_UNSIGNED_BYTE);}
|
uint8 *GetLum(){return (uint8 *)img.GetLum(IL_UNSIGNED_BYTE);}
|
||||||
|
|
||||||
bool SaveFile(const OSString &fn){return img.SaveFile(fn);}
|
|
||||||
};//class PBRComponent
|
};//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<uint8> pixels=new uint8[w*h*3];
|
||||||
|
|
||||||
|
MixRGBA<uint8>(pixels,r,g,b,a,w*h);
|
||||||
|
|
||||||
|
if(SaveImageToFile(out_filename,w,h,4,IL_UNSIGNED_BYTE,pixels))
|
||||||
|
{
|
||||||
|
std_cout<<OS_TEXT("Output ")+flag+OS_TEXT(": ")<<out_filename.c_str()<<std::endl;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
bool SaveRGBFile(const OSString &filename,const uint w,const uint h,const uint8 *r,const uint8 *g,const uint8 *b,const OSString &flag)
|
||||||
|
{
|
||||||
|
const OSString out_filename=OSString(filename)+OS_TEXT("_")+flag+OS_TEXT(".png");
|
||||||
|
|
||||||
|
AutoDeleteArray<uint8> pixels=new uint8[w*h*3];
|
||||||
|
|
||||||
|
MixRGB<uint8>(pixels,r,g,b,w*h);
|
||||||
|
|
||||||
|
if(SaveImageToFile(out_filename,w,h,3,IL_UNSIGNED_BYTE,pixels))
|
||||||
|
{
|
||||||
|
std_cout<<OS_TEXT("Output ")<<flag.c_str()<<OS_TEXT(": ")<<out_filename.c_str()<<std::endl;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
|
||||||
#if HGL_OS == HGL_OS_Windows
|
#if HGL_OS == HGL_OS_Windows
|
||||||
@ -162,7 +194,7 @@ namespace hgl
|
|||||||
roughness.Resize(half_w,half_h);
|
roughness.Resize(half_w,half_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 *y,*u,*v,*nx,*ny;
|
AutoDeleteArray<uint8> y,u,v,nx,ny;
|
||||||
|
|
||||||
y=new uint8[pixel_total];
|
y=new uint8[pixel_total];
|
||||||
u=new uint8[half_pixel_total];
|
u=new uint8[half_pixel_total];
|
||||||
@ -170,88 +202,41 @@ namespace hgl
|
|||||||
nx=new uint8[pixel_total];
|
nx=new uint8[pixel_total];
|
||||||
ny=new uint8[pixel_total];
|
ny=new uint8[pixel_total];
|
||||||
|
|
||||||
|
// BaseColor Y + Normal XY
|
||||||
|
{
|
||||||
RGB2YUV(y,u,v,color.GetRGB(),w,h);
|
RGB2YUV(y,u,v,color.GetRGB(),w,h);
|
||||||
normal_compress(nx,ny,normal.GetRGB(),w*h);
|
normal_compress(nx,ny,normal.GetRGB(),w*h);
|
||||||
|
|
||||||
// BaseColor Y + Normal XY
|
SaveRGBFile( argv[1],
|
||||||
{
|
w,h,
|
||||||
ILImage img;
|
y,nx,ny,
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_YN.png");
|
OS_TEXT("YN"));
|
||||||
|
|
||||||
uint8 *pixels=new uint8[pixel_total*3];
|
|
||||||
|
|
||||||
MixRGB<uint8>(pixels,y,nx,ny,pixel_total);
|
|
||||||
|
|
||||||
img.Create(w,h,3,IL_UNSIGNED_BYTE,pixels);
|
|
||||||
|
|
||||||
delete[] pixels;
|
|
||||||
|
|
||||||
if(img.SaveFile(out_filename))
|
|
||||||
std_cout<<OS_TEXT("Output 1: ")<<out_filename.c_str()<<std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(metallic.isHas()&&roughness.isHas())
|
if(metallic.isHas()&&roughness.isHas())
|
||||||
{
|
{
|
||||||
ILImage img;
|
SaveRGBAFile(argv[1],
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVMR.png");
|
half_w,half_h,
|
||||||
|
u,v,metallic.GetLum(),roughness.GetLum(),
|
||||||
const uint8 *m=metallic.GetLum();
|
OS_TEXT("UVMR"));
|
||||||
const uint8 *r=roughness.GetLum();
|
|
||||||
|
|
||||||
uint8 *pixels=new uint8[half_pixel_total*4];
|
|
||||||
|
|
||||||
MixRGBA<uint8>(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<<OS_TEXT("Output 2: ")<<out_filename.c_str()<<std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(metallic.isHas())
|
if(metallic.isHas())
|
||||||
{
|
{
|
||||||
ILImage img;
|
SaveRGBFile( argv[1],
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVM.png");
|
half_w,half_h,
|
||||||
|
u,v,metallic.GetLum(),
|
||||||
uint8 *pixels=new uint8[half_pixel_total*3];
|
OS_TEXT("UVM"));
|
||||||
const uint8 *m=metallic.GetLum();
|
|
||||||
|
|
||||||
MixRGB<uint8>(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<<OS_TEXT("Output 2: ")<<out_filename.c_str()<<std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(roughness.isHas())
|
if(roughness.isHas())
|
||||||
{
|
{
|
||||||
ILImage img;
|
SaveRGBFile( argv[1],
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVR.png");
|
half_w,half_h,
|
||||||
|
u,v,roughness.GetLum(),
|
||||||
uint8 *pixels=new uint8[half_pixel_total*3];
|
OS_TEXT("UVR"));
|
||||||
const uint8 *r=roughness.GetLum();
|
|
||||||
|
|
||||||
MixRGB<uint8>(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<<OS_TEXT("Output 2: ")<<out_filename.c_str()<<std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] y;
|
|
||||||
delete[] u;
|
|
||||||
delete[] v;
|
|
||||||
delete[] nx;
|
|
||||||
delete[] ny;
|
|
||||||
|
|
||||||
ilShutDown();
|
ilShutDown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ int main(int argc,char **argv)
|
|||||||
|
|
||||||
filename+=OS_TEXT("_XY.png");
|
filename+=OS_TEXT("_XY.png");
|
||||||
|
|
||||||
if(rgb_image.SaveFile(filename))
|
if(SaveImageToFile(filename,rgb_image.width(),rgb_image.height(),3,IL_UNSIGNED_BYTE,rgb))
|
||||||
std_cout<<OS_TEXT("Save To ")<<filename.c_str()<<OS_TEXT(" successed!")<<std::endl;
|
std_cout<<OS_TEXT("Save To ")<<filename.c_str()<<OS_TEXT(" successed!")<<std::endl;
|
||||||
|
|
||||||
ilShutDown();
|
ilShutDown();
|
||||||
|
@ -57,10 +57,9 @@ int main(int argc,char **argv)
|
|||||||
OSString filename;
|
OSString filename;
|
||||||
|
|
||||||
filename=ClipFileMainname<os_char>(argv[1]);
|
filename=ClipFileMainname<os_char>(argv[1]);
|
||||||
|
|
||||||
filename+=OS_TEXT("_YUV.png");
|
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<<OS_TEXT("Save To ")<<filename.c_str()<<OS_TEXT(" successed!")<<std::endl;
|
std_cout<<OS_TEXT("Save To ")<<filename.c_str()<<OS_TEXT(" successed!")<<std::endl;
|
||||||
|
|
||||||
ilShutDown();
|
ilShutDown();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user