"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "jpegutils.c" between
motion-release-4.2.2.tar.gz and motion-Release-4.3.0.tar.gz

About: Motion monitors the video signal from one or more cameras and is able to detect motion.

jpegutils.c  (motion-release-4.2.2):jpegutils.c  (motion-Release-4.3.0)
skipping to change at line 55 skipping to change at line 55
* jpgutl_error_exit * jpgutl_error_exit
* jpgutl_emit_message * jpgutl_emit_message
* Exposed Functions * Exposed Functions
* jpgutl_decode_jpeg * jpgutl_decode_jpeg
*/ */
#include "translate.h" #include "translate.h"
#include "config.h" #include "config.h"
#include "motion.h" #include "motion.h"
#include "jpegutils.h" #include "jpegutils.h"
#include "picture.h" /* For the prepare_exif */
#include <setjmp.h> #include <setjmp.h>
/* This is a workaround regarding these defines. The config.h file defines /* This is a workaround regarding these defines. The config.h file defines
* HAVE_STDLIB_H as 1 whereas the jpeglib.h just defines it without a value. * HAVE_STDLIB_H as 1 whereas the jpeglib.h just defines it without a value.
* this causes massive warnings/error on mis-matched definitions. We do not * this causes massive warnings/error on mis-matched definitions. We do not
* control either of these so we have to suffer through this workaround hack * control either of these so we have to suffer through this workaround hack
*/ */
#if (HAVE_STDLIB_H == 1) #if (HAVE_STDLIB_H == 1)
#undef HAVE_STDLIB_H #undef HAVE_STDLIB_H
#define HAVE_STDLIB_H_ORIG 1 #define HAVE_STDLIB_H_ORIG 1
skipping to change at line 347 skipping to change at line 348
* that we are interested in. * that we are interested in.
*/ */
if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && (msg_level < 0) ) { if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && (msg_level < 0) ) {
myerr->warning_seen++ ; myerr->warning_seen++ ;
(*cinfo->err->format_message) (cinfo, buffer); (*cinfo->err->format_message) (cinfo, buffer);
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "msg_level: %d, %s", msg_level , buffer); MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "msg_level: %d, %s", msg_level , buffer);
} }
} }
/*
* The following declarations and 5 functions are jpeg related
* functions used by put_jpeg_grey_memory and put_jpeg_yuv420p_memory.
*/
typedef struct {
struct jpeg_destination_mgr pub;
JOCTET *buf;
size_t bufsize;
size_t jpegsize;
} mem_destination_mgr;
typedef mem_destination_mgr *mem_dest_ptr;
METHODDEF(void) init_destination(j_compress_ptr cinfo)
{
mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;
dest->pub.next_output_byte = dest->buf;
dest->pub.free_in_buffer = dest->bufsize;
dest->jpegsize = 0;
}
METHODDEF(boolean) empty_output_buffer(j_compress_ptr cinfo)
{
mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;
dest->pub.next_output_byte = dest->buf;
dest->pub.free_in_buffer = dest->bufsize;
return FALSE;
ERREXIT(cinfo, JERR_BUFFER_SIZE);
}
METHODDEF(void) term_destination(j_compress_ptr cinfo)
{
mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;
dest->jpegsize = dest->bufsize - dest->pub.free_in_buffer;
}
static GLOBAL(void) _jpeg_mem_dest(j_compress_ptr cinfo, JOCTET* buf, size_t buf
size)
{
mem_dest_ptr dest;
if (cinfo->dest == NULL) {
cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, JPOOL_PERM
ANENT,
sizeof(mem_destination_mgr));
}
dest = (mem_dest_ptr) cinfo->dest;
dest->pub.init_destination = init_destination;
dest->pub.empty_output_buffer = empty_output_buffer;
dest->pub.term_destination = term_destination;
dest->buf = buf;
dest->bufsize = bufsize;
dest->jpegsize = 0;
}
static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo)
{
mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;
return dest->jpegsize;
}
/*
* put_jpeg_exif writes the EXIF APP1 chunk to the jpeg file.
* It must be called after jpeg_start_compress() but before
* any image data is written by jpeg_write_scanlines().
*/
static void put_jpeg_exif(j_compress_ptr cinfo,
const struct context *cnt,
const struct timeval *tv1,
const struct coord *box)
{
unsigned char *exif = NULL;
unsigned exif_len = prepare_exif(&exif, cnt, tv1, box);
if(exif_len > 0) {
/* EXIF data lives in a JPEG APP1 marker */
jpeg_write_marker(cinfo, JPEG_APP0 + 1, exif, exif_len);
free(exif);
}
}
/** /**
* jpgutl_decode_jpeg * jpgutl_decode_jpeg
* Purpose: Decompress the jpeg data_in into the img_out buffer. * Purpose: Decompress the jpeg data_in into the img_out buffer.
* *
* Parameters: * Parameters:
* jpeg_data_in The jpeg data sent in * jpeg_data_in The jpeg data sent in
* jpeg_data_len The length of the jpeg data * jpeg_data_len The length of the jpeg data
* width The width of the image * width The width of the image
* height The height of the image * height The height of the image
* img_out Pointer to the image output * img_out Pointer to the image output
skipping to change at line 457 skipping to change at line 542
/* /*
* If there are too many warnings, this means that * If there are too many warnings, this means that
* only a partial image could be returned which would * only a partial image could be returned which would
* trigger many false positive motion detections * trigger many false positive motion detections
*/ */
if (jerr.warning_seen > 2) return -1; if (jerr.warning_seen > 2) return -1;
return 0; return 0;
} }
int jpgutl_put_yuv420p(unsigned char *dest_image, int image_size,
unsigned char *input_image, int width, int height, int qualit
y,
struct context *cnt, struct timeval *tv1, struct coord *box)
{
int i, j, jpeg_image_size;
JSAMPROW y[16],cb[16],cr[16]; // y[2][5] = color sample of row 2 and pixel c
olumn 5; (one plane)
JSAMPARRAY data[3]; // t[0][2][5] = color sample 0 of row 2 and column 5
struct jpeg_compress_struct cinfo;
struct jpgutl_error_mgr jerr;
data[0] = y;
data[1] = cb;
data[2] = cr;
cinfo.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = jpgutl_error_exit;
/* Also hook the emit_message routine to note corrupt-data warnings. */
jerr.original_emit_message = jerr.pub.emit_message;
jerr.pub.emit_message = jpgutl_emit_message;
jerr.warning_seen = 0;
jpeg_create_compress(&cinfo);
/* Establish the setjmp return context for jpgutl_error_exit to use. */
if (setjmp (jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
jpeg_destroy_compress (&cinfo);
return -1;
}
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
jpeg_set_defaults(&cinfo);
jpeg_set_colorspace(&cinfo, JCS_YCbCr);
cinfo.raw_data_in = TRUE; // Supply downsampled data
#if JPEG_LIB_VERSION >= 70
cinfo.do_fancy_downsampling = FALSE; // Fix segfault with v7
#endif
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
cinfo.comp_info[2].v_samp_factor = 1;
jpeg_set_quality(&cinfo, quality, TRUE);
cinfo.dct_method = JDCT_FASTEST;
_jpeg_mem_dest(&cinfo, dest_image, image_size); // Data written to mem
jpeg_start_compress(&cinfo, TRUE);
put_jpeg_exif(&cinfo, cnt, tv1, box);
/* If the image is not a multiple of 16, this overruns the buffers
* we'll just pad those last bytes with zeros
*/
for (j = 0; j < height; j += 16) {
for (i = 0; i < 16; i++) {
if ((width * (i + j)) < (width * height)) {
y[i] = input_image + width * (i + j);
if (i % 2 == 0) {
cb[i / 2] = input_image + width * height + width / 2 * ((i +
j) /2);
cr[i / 2] = input_image + width * height + width * height /
4 + width / 2 * ((i + j) / 2);
}
} else {
y[i] = 0x00;
cb[i] = 0x00;
cr[i] = 0x00;
}
}
jpeg_write_raw_data(&cinfo, data, 16);
}
jpeg_finish_compress(&cinfo);
jpeg_image_size = _jpeg_mem_size(&cinfo);
jpeg_destroy_compress(&cinfo);
return jpeg_image_size;
}
int jpgutl_put_grey(unsigned char *dest_image, int image_size,
unsigned char *input_image, int width, int height, int qualit
y,
struct context *cnt, struct timeval *tv1, struct coord *box)
{
int y, dest_image_size;
JSAMPROW row_ptr[1];
struct jpeg_compress_struct cjpeg;
struct jpgutl_error_mgr jerr;
cjpeg.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = jpgutl_error_exit;
/* Also hook the emit_message routine to note corrupt-data warnings. */
jerr.original_emit_message = jerr.pub.emit_message;
jerr.pub.emit_message = jpgutl_emit_message;
jerr.warning_seen = 0;
jpeg_create_compress(&cjpeg);
/* Establish the setjmp return context for jpgutl_error_exit to use. */
if (setjmp (jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
jpeg_destroy_compress (&cjpeg);
return -1;
}
cjpeg.image_width = width;
cjpeg.image_height = height;
cjpeg.input_components = 1; /* One colour component */
cjpeg.in_color_space = JCS_GRAYSCALE;
jpeg_set_defaults(&cjpeg);
jpeg_set_quality(&cjpeg, quality, TRUE);
cjpeg.dct_method = JDCT_FASTEST;
_jpeg_mem_dest(&cjpeg, dest_image, image_size); // Data written to mem
jpeg_start_compress (&cjpeg, TRUE);
put_jpeg_exif(&cjpeg, cnt, tv1, box);
row_ptr[0] = input_image;
for (y = 0; y < height; y++) {
jpeg_write_scanlines(&cjpeg, row_ptr, 1);
row_ptr[0] += width;
}
jpeg_finish_compress(&cjpeg);
dest_image_size = _jpeg_mem_size(&cjpeg);
jpeg_destroy_compress(&cjpeg);
return dest_image_size;
}
 End of changes. 3 change blocks. 
0 lines changed or deleted 87 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)