17 #include <mrpt/3rdparty/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 179 src->start_of_file = TRUE;
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;
238 src->start_of_file = FALSE;
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;
320 if (cinfo->src ==
nullptr)
325 src->
buffer = (JOCTET*)(*cinfo->mem->alloc_small)(
334 src->
pub.resync_to_restart =
335 jpeg_resync_to_restart;
338 src->
pub.bytes_in_buffer = 0;
339 src->
pub.next_input_byte =
nullptr;
358 const auto& img =
m_impl->img;
360 const unsigned int nCols = img.cols, nRows = img.rows;
361 const bool is_color = (img.channels() == 3);
364 ASSERT_(nCols >= 1 && nRows >= 1);
365 ASSERT_(img.channels() == 1 || img.channels() == 3);
369 cinfo.err = jpeg_std_error(&jerr);
383 jpeg_set_defaults(&cinfo);
389 &cinfo, jpeg_quality ,
394 jpeg_start_compress(&cinfo, TRUE);
401 row_pointer[0] =
new uint8_t[img.step[0]];
403 for (
unsigned int row = 0; row < nRows; row++)
406 const uint8_t* src = img.ptr<uint8_t>(row);
407 uint8_t* target = row_pointer[0];
408 for (
unsigned int col = 0; col < nCols; col++)
418 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
424 delete[] row_pointer[0];
430 for (
unsigned int row = 0; row < nRows; row++)
432 row_pointer[0] =
const_cast<JSAMPROW>(img.ptr<uint8_t>(row));
435 if (1 != jpeg_write_scanlines(&cinfo, row_pointer, 1))
444 jpeg_finish_compress(&cinfo);
445 jpeg_destroy_compress(&cinfo);
465 cinfo.err = jpeg_std_error(&jerr);
474 jpeg_read_header(&cinfo, TRUE);
479 jpeg_start_decompress(&cinfo);
493 JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)(
510 for (
unsigned int row = 0; row < nRows; row++)
516 jpeg_read_scanlines(&cinfo, buffer, 1);
522 auto target = img.ptr<uint8_t>(row);
523 const auto* src = buffer[0];
524 for (
unsigned int col = 0; col < nCols; col++)
537 std::memcpy(img.ptr<uint8_t>(row), buffer[0], row_stride);
543 jpeg_finish_decompress(&cinfo);
551 jpeg_destroy_decompress(&cinfo);
term_source([[maybe_unused]] j_decompress_ptr 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...
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.
mrpt::vision::TStereoCalibResults out
mrpt_destination_mgr * mrpt_dest_ptr
MRPT_TODO("toPointCloud / calibration")
#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)