diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e92650..d920b9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,4 +38,7 @@ add_executable(SplitStringTest SplitStringTest.cpp) cm_example_project(SplitStringTest) add_executable(CreateBinaryH CreateBinaryH.cpp) -cm_example_project(CreateBinaryH) \ No newline at end of file +cm_example_project(CreateBinaryH) + +add_executable(NormalCompressTest NormalCompressTest.cpp) +CM_EXAMPLE_PROJECT(NormalCompressTest) \ No newline at end of file diff --git a/NormalCompressTest.cpp b/NormalCompressTest.cpp new file mode 100644 index 0000000..a36c89e --- /dev/null +++ b/NormalCompressTest.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +using namespace hgl; +using namespace hgl::filesystem; +using namespace hgl::util; + +static uint8 * file_data=nullptr; +static int64 file_length=0; +static TGAHeader * tga_header=nullptr; +static uint8 * bitmap_data=nullptr; +static uint8 * origin_bitmap_data=nullptr; +static uint bitmap_bytes=0; +static uint pixel_count=0; + +void SaveTGA(const os_char *filename) +{ + SaveMemoryToFile(filename,file_data,file_length); +} + +void TwoBytesNormalTest() +{ + uint8 *two_bytes_normal=new uint8[pixel_count*2]; + + Normal3to2(two_bytes_normal,origin_bitmap_data,pixel_count); + + Normal2to3(bitmap_data,two_bytes_normal,pixel_count); + + SaveTGA(OS_TEXT("CompressNormal.tga")); + + { + uint8 *tp=bitmap_data; + uint8 *sp=origin_bitmap_data; + + for(uint i=0;i error!"<bit!=24) + { + std::cerr<<" is not 24bits image!"<width*tga_header->height; + + bitmap_bytes=pixel_count*3; + + origin_bitmap_data=new uint8[bitmap_bytes]; + memcpy(origin_bitmap_data,bitmap_data,bitmap_bytes); + + TwoBytesNormalTest(); + + delete[] origin_bitmap_data; + delete[] file_data; + return 0; +} \ No newline at end of file diff --git a/TestNormal.tga b/TestNormal.tga new file mode 100644 index 0000000..eae878e Binary files /dev/null and b/TestNormal.tga differ