Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:20

0001 
0002 #include <csignal>
0003 #include "spath.h"
0004 #include "sdirectory.h"
0005 
0006 #include "SPPM.hh"
0007 #include "OPTICKS_LOG.hh"
0008 
0009 
0010 void test_MakeTestImage()
0011 {
0012     const char* path = spath::Resolve("$TMP/SPPMTest/SPPMTest_MakeTestImage.ppm") ;
0013     sdirectory::MakeDirsForFile(path); 
0014 
0015     const char* config = "vertical_gradient" ; 
0016 
0017     const int width = 1024 ; 
0018     const int height = 512 ; 
0019     const int ncomp = 3 ;    
0020     const bool yflip = true ; 
0021     const int size = height*width*ncomp ; 
0022 
0023     LOG(info) 
0024          << " path " << path 
0025          << " width " << width
0026          << " height " << height
0027          << " size " << size
0028          << " yflip " << yflip
0029          << " config " << config
0030          ;    
0031 
0032     unsigned char* imgdata = SPPM::MakeTestImage(width, height, ncomp, yflip, config);
0033 
0034     SPPM::write(path, imgdata, width, height, ncomp, yflip );
0035 
0036     SPPM::dumpHeader(path); 
0037 }
0038 
0039 
0040 void test_MakeWriteRead()
0041 {
0042     const char* path = spath::Resolve("$TMP/SPPMTest/SPPMTest.ppm") ;
0043     sdirectory::MakeDirsForFile(path); 
0044 
0045     //const char* config = "checkerboard" ; 
0046     //const char* config = "horizontal_gradient" ; 
0047     //const char* config = "vertical_gradient" ; 
0048     const char* config = "vertical_gradient,add_border,add_midline,add_quadline" ; 
0049 
0050     const int width = 1024 ; 
0051     const int height = 512 ; 
0052     const int ncomp = 3 ;    
0053     const bool yflip = true ; 
0054     const int size = height*width*ncomp ; 
0055 
0056     LOG(info) 
0057          << " path " << path 
0058          << " width " << width
0059          << " height " << height
0060          << " size " << size
0061          << " yflip " << yflip
0062          << " config " << config
0063          ;    
0064 
0065     unsigned char* imgdata = SPPM::MakeTestImage(width, height, ncomp, yflip, config);
0066 
0067     SPPM::write(path, imgdata, width, height, ncomp, yflip );
0068 
0069     SPPM::dumpHeader(path); 
0070 
0071     std::vector<unsigned char> img ; 
0072     unsigned width2(0); 
0073     unsigned height2(0); 
0074 
0075     int rc = SPPM::read( path, img, width2, height2, ncomp, yflip ); 
0076 
0077     assert( rc == 0 ); 
0078     if(rc!=0) std::raise(SIGINT); 
0079 
0080 
0081     assert( width2 == width ); 
0082     assert( height2 == height ); 
0083 
0084 
0085     unsigned char* imgdata2 = img.data(); 
0086     unsigned mismatch = SPPM::ImageCompare( height, width, ncomp, imgdata, imgdata2 ); 
0087     LOG(info) << " mismatch " << mismatch ; 
0088 
0089     assert( mismatch == 0 ); 
0090 }
0091 
0092 
0093 
0094 
0095 int main(int argc, char** argv)
0096 {   
0097     OPTICKS_LOG(argc, argv);
0098 
0099     test_MakeTestImage();      
0100     test_MakeWriteRead();      
0101 
0102     return 0 ; 
0103 }