17 #include <mrpt/otherlibs/do_opencv_includes.h> 34 #define mrpt_jpeg_source_mgr jpeg_source_mgr 48 #define OUTPUT_BUF_SIZE 4096 62 dest->
buffer =
reinterpret_cast<JOCTET*
>(((*cinfo->mem->alloc_small)(
66 dest->pub.next_output_byte = dest->buffer;
100 dest->pub.next_output_byte = dest->buffer;
122 if (datacount > 0) dest->out->Write(dest->buffer, (
int)datacount);
136 if (cinfo->dest ==
nullptr)
163 #define INPUT_BUF_SIZE 4096 225 if (
src->start_of_file)
231 src->buffer[0] = (JOCTET)0xFF;
236 src->pub.next_input_byte =
src->buffer;
237 src->pub.bytes_in_buffer = nbytes;
266 while (num_bytes > (
long)
src->pub.bytes_in_buffer)
268 num_bytes -= (long)
src->pub.bytes_in_buffer;
274 src->pub.next_input_byte += (size_t)num_bytes;
275 src->pub.bytes_in_buffer -= (size_t)num_bytes;
321 if (cinfo->src ==
nullptr)
326 src->buffer = (JOCTET*)(*cinfo->mem->alloc_small)(
335 src->pub.resync_to_restart =
336 jpeg_resync_to_restart;
339 src->pub.bytes_in_buffer = 0;
340 src->pub.next_input_byte =
nullptr;
361 const unsigned int nCols =
img.cols, nRows =
img.rows;
362 const bool is_color = (
img.channels() == 3);
365 ASSERT_(nCols >= 1 && nRows >= 1);
370 cinfo.err = jpeg_std_error(&jerr);
384 jpeg_set_defaults(&cinfo);
390 &cinfo, jpeg_quality ,
395 jpeg_start_compress(&cinfo,
TRUE);
404 for (
unsigned int row = 0;
row < nRows;
row++)
408 uint8_t* target = row_pointer[0];
409 for (
unsigned int col = 0; col < nCols; col++)
419 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
425 delete[] row_pointer[0];
431 for (
unsigned int row = 0;
row < nRows;
row++)
436 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
445 jpeg_finish_compress(&cinfo);
446 jpeg_destroy_compress(&cinfo);
466 cinfo.err = jpeg_std_error(&jerr);
475 jpeg_read_header(&cinfo,
TRUE);
480 jpeg_start_decompress(&cinfo);
511 for (
unsigned int row = 0;
row < nRows;
row++)
517 jpeg_read_scanlines(&cinfo,
buffer, 1);
525 for (
unsigned int col = 0; col < nCols; col++)
544 jpeg_finish_decompress(&cinfo);
552 jpeg_destroy_decompress(&cinfo);
my_source_mgr * my_src_ptr
init_destination(j_compress_ptr cinfo)
#define THROW_EXCEPTION(msg)
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...
mrpt::pimpl< Impl > m_impl
J_COLOR_SPACE in_color_space
#define ASSERT_(f)
Defines an assertion mechanism.
jpeg_stdio_src(j_decompress_ptr cinfo, CStream *in)
void resize(std::size_t width, std::size_t height, TImageChannels nChannels, PixelDepth depth=PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
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.
GLenum GLenum GLvoid * row
mrpt_destination_mgr * mrpt_dest_ptr
#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.