77
88#include " SFrameConfig.hh"
99#include " SComp.h"
10- #include " SStr.hh"
1110#include " SPath.hh"
1211#include " SLOG.hh"
1312#include " NP.hh"
1413#include " Frame.h"
1514
16- #define SIMG_IMPLEMENTATION 1
17- #include " SIMG.h"
18-
1915
2016const plog::Severity Frame::LEVEL = SLOG ::EnvLevel(" Frame" , " DEBUG" );
2117
22- unsigned Frame::getNumPixels () const
23- {
24- return num_pixels ;
25- }
26-
2718/* *
2819Frame::Frame
2920--------------
@@ -58,8 +49,6 @@ Frame::Frame(int width_, int height_, int depth_, uchar4* d_pixel_, float4* d_is
5849 height(height_),
5950 depth(depth_),
6051 channels(4 ),
61- jpg_quality(SStr::GetEValue<int >(" QUALITY" , 50 )),
62- img(new SIMG (width, height, channels, nullptr )),
6352 num_pixels(width*height),
6453 d_pixel(d_pixel_ == nullptr ? DeviceAlloc<uchar4>(num_pixels, mask & SCOMP_PIXEL ) : d_pixel_ ),
6554 d_isect(d_isect_ == nullptr ? DeviceAlloc<float4>(num_pixels, mask & SCOMP_ISECT ) : d_isect_ ),
@@ -107,10 +96,8 @@ void Frame::download_(bool flip_vertical)
10796 if (d_fphoton) QU ::Download<quad4>(photon, d_fphoton, num_pixels );
10897#endif
10998
110- if (d_pixel)
111- {
112- img->setData ( getPixelData (), flip_vertical );
113- }
99+ if (d_pixel && flip_vertical)
100+ flipPixelVertical ();
114101}
115102
116103void Frame::download ()
@@ -122,41 +109,24 @@ void Frame::download_inverted()
122109 download_ (false );
123110}
124111
125-
126-
127- unsigned char * Frame::getPixelData () const { return d_pixel ? (unsigned char *)pixel.data () : nullptr ; }
128112float * Frame::getIntersectData () const { return d_isect ? (float *)isect.data () : nullptr ; }
129113#ifdef WITH_FRAME_PHOTON
130114float * Frame::getFPhotonData () const { return d_fphoton ? (float *)fphoton.data () : nullptr ; }
131115#endif
132116
133- void Frame::write (const char * outdir_, int quality) const
134- {
135- const char * outdir = SPath::Resolve (outdir_, DIRPATH );
136- writePNG (outdir, " f_pixels.png" );
137- writeJPG (outdir, " f_pixels.jpg" , quality);
138- writeIsect (outdir, " f_isect.npy" ); // formerly posi.npy
139- #ifdef WITH_FRAME_PHOTON
140- writeFPhoton (outdir, " f_photon.npy" );
141- #endif
142- }
143-
144- void Frame::writePNG (const char * dir, const char * name) const
145- {
146- img->writePNG (dir, name);
147- }
148- void Frame::writePNG (const char * path) const
117+ void Frame::flipPixelVertical ()
149118{
150- img->writePNG (path);
119+ for (int y = 0 ; y < height / 2 ; y++)
120+ for (int x = 0 ; x < width; x++)
121+ {
122+ std::swap (pixel[y * width + x], pixel[(height - 1 - y) * width + x]);
123+ }
151124}
152125
153- void Frame::writeJPG (const char * dir, const char * name, int quality) const
154- {
155- img->writeJPG (dir, name, quality > 0 ? quality : jpg_quality );
156- }
157- void Frame::writeJPG (const char * path, int quality) const
126+ void Frame::writePixels (const char * path) const
158127{
159- img->writeJPG (path, quality > 0 ? quality : jpg_quality );
128+ if (d_pixel)
129+ NP::Write (path, (unsigned char *)pixel.data (), height, width, channels);
160130}
161131
162132
@@ -176,12 +146,11 @@ void Frame::writeFPhoton( const char* dir, const char* name) const
176146
177147void Frame::snap ( const char * path )
178148{
179- LOG (LEVEL ) << " [" ;
180-
181- LOG (LEVEL ) << " [ writeJPG " ;
182- writeJPG ( path );
183- LOG (LEVEL ) << " ] writeJPG " ;
149+ LOG (LEVEL ) << " [" ;
184150
151+ LOG (LEVEL ) << " [ writePixels " ;
152+ writePixels (path);
153+ LOG (LEVEL ) << " ] writePixels " ;
185154
186155 LOG (LEVEL ) << " [ writeIntersectData " ;
187156 const char * fold = SPath::Dirname (path);
0 commit comments