Allow netcams with modulo 8 dimensions

This commit is contained in:
Mr Dave
2014-10-21 19:26:45 -07:00
parent 9479d910f2
commit bfbfebadcc
4 changed files with 44 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
Summary of Changes
* Revised picture.c to allow for modulo 8 pictures and adjusted netcam modules accordingly as well.
* Changes to ffmpeg.h/ffmpeg.c to allow for compiling without ffmpeg/libav or with older versions.
* Merge mymalloc, free and casting changes from Alfred Klomp
* Merge bug fix for sizeof from Alfred Klomp

View File

@@ -2666,7 +2666,7 @@ int netcam_next(struct context *cnt, unsigned char *image)
*
* Returns: 0 on success
* -1 on any failure
* -3 image dimensions are not modulo 16
* -3 image dimensions are not modulo 8
*/
int netcam_start(struct context *cnt)
@@ -2865,17 +2865,17 @@ int netcam_start(struct context *cnt)
}
/*
* Motion currently requires that image height and width is a
* multiple of 16. So we check for this.
* multiple of 8. So we check for this.
*/
if (netcam->width % 16) {
if (netcam->width % 8) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)"
" is not modulo 16", netcam->width);
" is not modulo 8", netcam->width);
return -3;
}
if (netcam->height % 16) {
if (netcam->height % 8) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)"
" is not modulo 16", netcam->height);
" is not modulo 8", netcam->height);
return -3;
}

View File

@@ -853,15 +853,15 @@ int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url){
/*
* Warn and fix dimensions as needed.
*/
if (netcam->cnt->conf.width % 16) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Image width (%d) requested is not modulo 16.", netcam->cnt->conf.width);
netcam->cnt->conf.width = netcam->cnt->conf.width - (netcam->cnt->conf.width % 16) + 16;
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Adjusting width to next higher multiple of 16 (%d).", netcam->cnt->conf.width);
if (netcam->cnt->conf.width % 8) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Image width (%d) requested is not modulo 8.", netcam->cnt->conf.width);
netcam->cnt->conf.width = netcam->cnt->conf.width - (netcam->cnt->conf.width % 8) + 8;
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Adjusting width to next higher multiple of 8 (%d).", netcam->cnt->conf.width);
}
if (netcam->cnt->conf.height % 16) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Image height (%d) requested is not modulo 16.", netcam->cnt->conf.height);
netcam->cnt->conf.height = netcam->cnt->conf.height - (netcam->cnt->conf.height % 16) + 16;
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Adjusting height to next higher multiple of 16 (%d).", netcam->cnt->conf.height);
if (netcam->cnt->conf.height % 8) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Image height (%d) requested is not modulo 8.", netcam->cnt->conf.height);
netcam->cnt->conf.height = netcam->cnt->conf.height - (netcam->cnt->conf.height % 8) + 8;
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Adjusting height to next higher multiple of 8 (%d).", netcam->cnt->conf.height);
}
av_register_all();

View File

@@ -452,21 +452,30 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size,
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, tm, 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++) {
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);
}
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);
}
@@ -594,12 +603,18 @@ static void put_jpeg_yuv420p_file(FILE *fp,
for (j = 0; j < height; j += 16) {
for (i = 0; i < 16; i++) {
y[i] = image + width * (i + j);
if (i % 2 == 0) {
cb[i / 2] = image + width * height + width / 2 * ((i + j) / 2);
cr[i / 2] = image + width * height + width * height / 4 + width / 2 * ((i + j) / 2);
}
}
if ((width * (i + j)) < (width * height)) {
y[i] = image + width * (i + j);
if (i % 2 == 0) {
cb[i / 2] = image + width * height + width / 2 * ((i + j) / 2);
cr[i / 2] = 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);
}