34 #ifndef AIMS_IO_JPEGW_H
35 #define AIMS_IO_JPEGW_H
66 unsigned zfame,
unsigned tframe );
78 writer.
write( thing );
87 unsigned t, z, dt = thing.
dimT(), dz = thing.
dimZ();
99 hdr.
setProperty(
"file_type", std::string(
"JPEG" ) );
107 for( t=0; t<dt; ++t )
108 for( z=0; z<dz; ++z, ++i )
109 writeFrame( thing, dir + files[i], z, t );
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 );
const aims::Header * header() const
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)
JpegWriter(const std::string &name)
void write(const AimsData< T > &thing)
std::string removeExtension(const std::string &name) const
Return a name without .jpg extension.
static std::string dirname(const std::string &)
static std::string removeExtension(const std::string &)
virtual void setProperty(const std::string &, Object)
The class for EcatSino data write operation.
MotionWriter & operator<<(MotionWriter &writer, const AffineTransformation3d &thing) __attribute__((__deprecated__("OBSOLETE")))
— OBSOLETE —