16 #include <mrpt/otherlibs/do_opencv_includes.h>
36 #if MRPT_HAS_JPEG_SYSTEM
41 #define mrpt_jpeg_source_mgr jpeg_source_mgr
45 #define mrpt_jpeg_source_mgr jpeg_source_mgr
58 #define OUTPUT_BUF_SIZE 4096
145 if (cinfo->dest ==
nullptr)
172 #define INPUT_BUF_SIZE 4096
234 if (
src->start_of_file)
245 src->pub.next_input_byte =
src->buffer;
246 src->pub.bytes_in_buffer = nbytes;
275 while (num_bytes > (
long)
src->pub.bytes_in_buffer)
277 num_bytes -= (long)
src->
pub.bytes_in_buffer;
283 src->pub.next_input_byte += (size_t)num_bytes;
284 src->pub.bytes_in_buffer -= (size_t)num_bytes;
330 if (cinfo->src ==
nullptr)
332 cinfo->src = (mrpt_jpeg_source_mgr*)(*cinfo->mem->alloc_small)(
335 src->buffer = (
JOCTET*)(*cinfo->mem->alloc_small)(
344 src->pub.resync_to_restart =
348 src->pub.bytes_in_buffer = 0;
349 src->pub.next_input_byte =
nullptr;
369 const IplImage* ipl =
static_cast<const IplImage*
>(
img);
371 const unsigned int nCols = ipl->width;
372 const unsigned int nRows = ipl->height;
373 const bool is_color = (ipl->nChannels == 3);
376 ASSERT_(nCols >= 1 && nRows >= 1)
378 ASSERT_(ipl->nChannels == 1 || ipl->nChannels == 3)
402 &cinfo, jpeg_quality ,
414 row_pointer[0] = (
JSAMPROW)
new char[ipl->widthStep];
420 if (ipl->origin == 0)
421 src = &ipl->imageData[
row * ipl->widthStep];
423 src = &ipl->imageData[(nRows - 1 -
row) * ipl->widthStep];
424 char* target = (
char*)row_pointer[0];
425 for (
unsigned int col = 0; col < nCols; col++)
441 delete[] row_pointer[0];
447 for (
unsigned int row = 0;
row < nRows;
row++)
449 if (ipl->origin == 0)
455 ->imageData[(nRows - 1 -
row) * ipl->widthStep];
524 IplImage* ipl =
static_cast<IplImage*
>(
img);
535 for (
unsigned int row = 0;
row < nRows;
row++)
547 char* target = &ipl->imageData[
row * ipl->widthStep];
549 for (
unsigned int col = 0; col < nCols; col++)
563 &ipl->imageData[
row * ipl->widthStep],
buffer[0], row_stride);
term_source(j_decompress_ptr cinfo)
my_source_mgr * my_src_ptr
term_destination(j_compress_ptr cinfo)
mrpt_destination_mgr * mrpt_dest_ptr
fill_input_buffer(j_decompress_ptr cinfo)
init_destination(j_compress_ptr cinfo)
empty_output_buffer(j_compress_ptr cinfo)
init_source(j_decompress_ptr cinfo)
skip_input_data(j_decompress_ptr cinfo, long num_bytes)
jpeg_stdio_src(j_decompress_ptr cinfo, CStream *in)
jpeg_stdio_dest(j_compress_ptr cinfo, CStream *out)
void * img
The internal IplImage pointer to the actual image content.
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.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
void loadFromStreamAsJPEG(CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
void saveToStreamAsJPEG(mrpt::utils::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
GLenum GLenum GLvoid * row
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
jpeg_destroy_compress(j_compress_ptr cinfo)
jpeg_finish_compress(j_compress_ptr cinfo)
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
jpeg_set_defaults(j_compress_ptr cinfo)
jpeg_destroy_decompress(j_decompress_ptr cinfo)
jpeg_finish_decompress(j_decompress_ptr cinfo)
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
jpeg_start_decompress(j_decompress_ptr cinfo)
jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
jpeg_std_error(struct jpeg_error_mgr *err)
for(ctr=DCTSIZE;ctr > 0;ctr--)
struct jpeg_common_struct * j_common_ptr
#define jpeg_create_decompress(cinfo)
#define jpeg_create_compress(cinfo)
#define THROW_EXCEPTION(msg)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
J_COLOR_SPACE in_color_space
JOCTET * next_output_byte
struct jpeg_destination_mgr pub