118 const std::string & filename,
unsigned z,
121 struct jpeg_compress_struct cinfo;
122 struct jpeg_error_mgr jerr;
125 JSAMPROW row_pointer[1];
127 cinfo.err = jpeg_std_error( &jerr );
128 jpeg_create_compress( &cinfo );
130 cinfo.image_width = thing.
dimX();
131 cinfo.image_height = thing.
dimY();
132 cinfo.in_color_space = (
sizeof( T ) == 3 ? JCS_RGB : JCS_GRAYSCALE );
133 cinfo.input_components = (
sizeof( T ) == 3 ? 3 : 1 );
134 cinfo.input_gamma = 1;
135 jpeg_set_defaults( &cinfo );
136 if(
sizeof( T ) != 3 )
137 cinfo.data_precision = 8 *
sizeof( T );
138 cinfo.smoothing_factor = 0;
139 jpeg_set_quality( &cinfo, 100, TRUE );
140 cinfo.density_unit = 1;
141 cinfo.X_density = (UINT16) ( 25.4 / thing.
sizeX() );
142 cinfo.Y_density = (UINT16) ( 25.4 / thing.
sizeY() );
144 fp = fopen( filename.c_str(),
"wb" );
148 jpeg_stdio_dest( &cinfo, fp );
149 jpeg_start_compress( &cinfo, TRUE );
150 long stride = &thing( 1 ) - &thing( 0 );
151 std::vector<T> buffer;
154 buffer.resize( cinfo.image_width );
156 for( i=0; i<cinfo.image_height; ++i )
160 row_pointer[0] = (JSAMPROW) &thing( 0, i, z, t );
164 const T* p = &thing( 0, i, z, t );
165 for(
long k=0; k<cinfo.image_width; ++k, p+=stride )
167 row_pointer[0] = (JSAMPROW) &buffer[0];
169 jpeg_write_scanlines( &cinfo, row_pointer, 1 );
172 jpeg_finish_compress( &cinfo );
174 jpeg_destroy_compress( &cinfo );
void writeFrame(const AimsData< T > &thing, const std::string &filename, unsigned zfame, unsigned tframe)
called by write(), but you can call it for single frame writing (axial slice)