dinfo->dct_method = JDCT_FASTEST;
}
-static int __jpeg_decode_get_buffer_size(j_decompress_ptr dinfo, int row_stride, mm_util_color_format_e color_format, size_t *size)
+static int __jpeg_decode_get_buffer_size(j_decompress_ptr dinfo, unsigned int row_stride, mm_util_color_format_e color_format, size_t *size)
{
*size = 0;
int ret = MM_UTIL_ERROR_NONE;
mm_image_info_s *_decoded = (mm_image_info_s *)decoded;
JSAMPROW y[16], cb[16], cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
- JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
+ JSAMPARRAY data[3] = { y, cb, cr }; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
struct jpeg_compress_struct cinfo;
my_error_mgr_s jerr;
- int i, j, flag, _width, _height;
+ unsigned int i, j, flag, _width, _height;
unsigned long size = 0;
- data[0] = y;
- data[1] = cb;
- data[2] = cr;
-
mm_util_retvm_if((control_format != MM_UTIL_JPEG_FILE) && (control_format != MM_UTIL_JPEG_MEM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid control_format [%u]", control_format);
mm_util_retvm_if((control_format == MM_UTIL_JPEG_FILE) && (!fp), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fp");
mm_util_retvm_if((control_format == MM_UTIL_JPEG_MEM) && ((!mem) || (!csize)), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src or csize");
else if (_decoded->color == MM_UTIL_COLOR_RGB24 || _decoded->color == MM_UTIL_COLOR_GRAYSCALE || _decoded->color == MM_UTIL_COLOR_RGBA || _decoded->color == MM_UTIL_COLOR_BGRA || _decoded->color == MM_UTIL_COLOR_ARGB) {
unsigned int row_stride = 0;
JSAMPROW row_pointer[1];
+ JSAMPLE *image_buffer = (JSAMPLE *)_decoded->data;
__jpeg_convert_rgb_colorspace(_decoded->color, &(cinfo.in_color_space), &(cinfo.input_components));
row_stride = _width * cinfo.input_components;
jpeg_start_compress(&cinfo, TRUE);
mm_util_debug("jpeg_start_compress");
- JSAMPLE *image_buffer = (JSAMPLE *)_decoded->data;
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
struct jpeg_decompress_struct dinfo;
my_error_mgr_s jerr;
JSAMPARRAY buffer; /* Output row buffer */
- int row_stride = 0; /* physical row width in output buffer */
+ unsigned int row_stride = 0; /* physical row width in output buffer */
JSAMPROW image, u_image, v_image;
JSAMPROW row; /* point to buffer[0] */
- size_t _size = 0;
- void *_data = NULL;
+ size_t image_buffer_size = 0;
+ void *image_buffer = NULL;
mm_util_fenter();
buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo, JPOOL_IMAGE, row_stride, 1);
mm_util_debug("JPOOL_IMAGE BUFFER (color_format: %d)", color_format);
- ret = __jpeg_decode_get_buffer_size(&dinfo, row_stride, color_format, &_size);
+ ret = __jpeg_decode_get_buffer_size(&dinfo, row_stride, color_format, &image_buffer_size);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__jpeg_decode_calc_buffer_size failed");
goto END;
}
- _data = (void *) calloc(1, _size);
- if (!_data) {
- mm_util_error("_data is NULL");
+ image_buffer = (void *) calloc(1, image_buffer_size);
+ if (!image_buffer) {
+ mm_util_error("image_buf is NULL");
ret = MM_UTIL_ERROR_OUT_OF_MEMORY;
goto END;
}
/* while (scan lines remain to be read) jpeg_read_scanlines(...); */
if (color_format == MM_UTIL_COLOR_YUV420 || color_format == MM_UTIL_COLOR_YUV422 || color_format == MM_UTIL_COLOR_UYVY) {
- image = _data;
+ image = image_buffer;
u_image = image + (dinfo.output_width * dinfo.output_height);
v_image = u_image + (dinfo.output_width*dinfo.output_height)/4;
row = buffer[0];
/* jpeg_read_scanlines expects an array of pointers to scanlines. Here the array is only one element long, but you could ask formore than one scanline at a time if that's more convenient. */
jpeg_read_scanlines(&dinfo, buffer, 1);
- memcpy(_data + state, buffer[0], row_stride);
+ memcpy(image_buffer + state, buffer[0], row_stride);
state += row_stride;
}
mm_util_debug("jpeg_read_scanlines");
}
- ret = mm_image_create_image(dinfo.output_width, dinfo.output_height, color_format, _data, _size, decoded);
- MMUTIL_SAFE_FREE(_data);
+ ret = mm_image_create_image(dinfo.output_width, dinfo.output_height, color_format, image_buffer, image_buffer_size, decoded);
+ MMUTIL_SAFE_FREE(image_buffer);
END:
/* Finish decompression */