16 #include <mrpt/otherlibs/do_opencv_includes.h> 33 #define mrpt_jpeg_source_mgr jpeg_source_mgr 47 #define OUTPUT_BUF_SIZE 4096 61 dest->
buffer = (JOCTET*)(*cinfo->mem->alloc_small)(
120 if (datacount > 0) dest->
out->
Write(dest->
buffer, (
int)datacount);
134 if (cinfo->dest ==
nullptr)
161 #define INPUT_BUF_SIZE 4096 223 if (
src->start_of_file)
229 src->buffer[0] = (JOCTET)0xFF;
234 src->pub.next_input_byte =
src->buffer;
235 src->pub.bytes_in_buffer = nbytes;
264 while (num_bytes > (
long)
src->pub.bytes_in_buffer)
266 num_bytes -= (long)
src->
pub.bytes_in_buffer;
272 src->pub.next_input_byte += (size_t)num_bytes;
273 src->pub.bytes_in_buffer -= (size_t)num_bytes;
319 if (cinfo->src ==
nullptr)
324 src->buffer = (JOCTET*)(*cinfo->mem->alloc_small)(
333 src->pub.resync_to_restart =
334 jpeg_resync_to_restart;
337 src->pub.bytes_in_buffer = 0;
338 src->pub.next_input_byte =
nullptr;
358 const IplImage* ipl =
static_cast<const IplImage*
>(
img);
360 const unsigned int nCols = ipl->width;
361 const unsigned int nRows = ipl->height;
362 const bool is_color = (ipl->nChannels == 3);
365 ASSERT_(nCols >= 1 && nRows >= 1);
367 ASSERT_(ipl->nChannels == 1 || ipl->nChannels == 3);
371 cinfo.err = jpeg_std_error(&jerr);
385 jpeg_set_defaults(&cinfo);
391 &cinfo, jpeg_quality ,
396 jpeg_start_compress(&cinfo,
TRUE);
403 row_pointer[0] = (
JSAMPROW)
new char[ipl->widthStep];
405 for (
unsigned int row = 0;
row < nRows;
row++)
409 if (ipl->origin == 0)
410 src = &ipl->imageData[
row * ipl->widthStep];
412 src = &ipl->imageData[(nRows - 1 -
row) * ipl->widthStep];
413 char* target = (
char*)row_pointer[0];
414 for (
unsigned int col = 0; col < nCols; col++)
424 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
430 delete[] row_pointer[0];
436 for (
unsigned int row = 0;
row < nRows;
row++)
438 if (ipl->origin == 0)
444 ->imageData[(nRows - 1 -
row) * ipl->widthStep];
447 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
456 jpeg_finish_compress(&cinfo);
457 jpeg_destroy_compress(&cinfo);
478 cinfo.err = jpeg_std_error(&jerr);
487 jpeg_read_header(&cinfo,
TRUE);
492 jpeg_start_decompress(&cinfo);
513 IplImage* ipl =
static_cast<IplImage*
>(
img);
524 for (
unsigned int row = 0;
row < nRows;
row++)
530 jpeg_read_scanlines(&cinfo,
buffer, 1);
536 char* target = &ipl->imageData[
row * ipl->widthStep];
538 for (
unsigned int col = 0; col < nCols; col++)
552 &ipl->imageData[
row * ipl->widthStep],
buffer[0], row_stride);
558 jpeg_finish_decompress(&cinfo);
566 jpeg_destroy_decompress(&cinfo);
my_source_mgr * my_src_ptr
init_destination(j_compress_ptr cinfo)
void changeSize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Resize the buffers in "img" to accomodate a new image size and/or format.
#define THROW_EXCEPTION(msg)
virtual size_t Read(void *Buffer, size_t Count)=0
Introduces a pure virtual method responsible for reading from the stream.
struct jpeg_common_struct * j_common_ptr
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it...
mrpt::io::CStream CStream
init_source(j_decompress_ptr cinfo)
fill_input_buffer(j_decompress_ptr cinfo)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
J_COLOR_SPACE in_color_space
#define ASSERT_(f)
Defines an assertion mechanism.
jpeg_stdio_src(j_decompress_ptr cinfo, CStream *in)
term_source(j_decompress_ptr cinfo)
struct jpeg_destination_mgr pub
void saveToStreamAsJPEG(mrpt::io::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
term_destination(j_compress_ptr cinfo)
void loadFromStreamAsJPEG(mrpt::io::CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
#define jpeg_create_decompress(cinfo)
#define mrpt_jpeg_source_mgr
jpeg_stdio_dest(j_compress_ptr cinfo, CStream *out)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
virtual size_t Write(const void *Buffer, size_t Count)=0
Introduces a pure virtual method responsible for writing to the stream.
GLenum GLenum GLvoid * row
mrpt_destination_mgr * mrpt_dest_ptr
JOCTET * next_output_byte
#define jpeg_create_compress(cinfo)
empty_output_buffer(j_compress_ptr cinfo)
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
skip_input_data(j_decompress_ptr cinfo, long num_bytes)
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
void * img
The internal IplImage pointer to the actual image content.