From 949eec3f974cd0aeace0bc65654a602e12b09271 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Tue, 23 May 2017 18:58:50 +0100 Subject: [PATCH] code review addressing comments in pull request #390 --- conf.c | 6 +-- motion-dist.conf.in | 4 ++ rotate.c | 102 ++++++++++++++++++++++---------------------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/conf.c b/conf.c index 89e50579..0b64593c 100644 --- a/conf.c +++ b/conf.c @@ -305,10 +305,10 @@ config_param config_params[] = { copy_int, print_int }, - { + { "flip_axis", - "# Flip the image horizontaly (h) or verticaly (v). The filp affects all saved images as\n" - "# well as movies. Valid values: none (default = no flip), h and v.", + "#Flip image over a given axis (vertical or horizontal), vertical means from left to right,\n" + "# horizontal means top to bottom. Valid values: none, v and h.", 0, CONF_OFFSET(flip_axis), copy_string, diff --git a/motion-dist.conf.in b/motion-dist.conf.in index c6a2861f..aee77137 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -71,6 +71,10 @@ power_line_frequency -1 # well as movies. Valid values: 0 (default = no rotation), 90, 180 and 270. rotate 0 +# Flip image over a given axis (vertical or horizontal), vertical means from left to right +# horizontal means top to bottom. Valid values: none, v and h. +flip_axis none + # Image width (pixels). Valid range: Camera dependent, default: 352 width 320 diff --git a/rotate.c b/rotate.c index ae3be7d8..81b98156 100644 --- a/rotate.c +++ b/rotate.c @@ -74,39 +74,39 @@ static void reverse_inplace_quad(unsigned char *src, int size) } static void flip_inplace_horizontal(unsigned char *src, int width, int height) { - uint8_t *nsrc = (uint8_t *)src; + uint8_t *nsrc = (uint8_t *)src; uint8_t *ndst = (uint8_t *)(src + width*(height-1)); - register uint8_t tmp; - unsigned int l,w; + register uint8_t tmp; + unsigned int l,w; - for(l=0; l < height/2; l++) { - for(w=0; w < width; w++) { - tmp =*ndst; - *ndst++ = *nsrc; - *nsrc++ = tmp; - } - nsrc = (uint8_t *)(src + l*width); - ndst = (uint8_t *)(src + (width*(height - l-1))); - } + for(l=0; l < height/2; l++) { + for(w=0; w < width; w++) { + tmp =*ndst; + *ndst++ = *nsrc; + *nsrc++ = tmp; + } + nsrc = (uint8_t *)(src + l*width); + ndst = (uint8_t *)(src + (width*(height - l-1))); + } } static void flip_inplace_vertical(unsigned char *src, int width, int height) { - uint8_t *nsrc = (uint8_t *)src; + uint8_t *nsrc = (uint8_t *)src; uint8_t *ndst = (uint8_t *)(src + width - 1); - register uint8_t tmp; - unsigned int l; + register uint8_t tmp; + unsigned int l; - for(l=0; l < height; l++) { - while (nsrc < ndst) { - tmp =*ndst; - *ndst-- = *nsrc; - *nsrc++ = tmp; - } - nsrc = (uint8_t *)src + l*width; - ndst = nsrc + width - 1; - } + for(l=0; l < height; l++) { + while (nsrc < ndst) { + tmp = *ndst; + *ndst-- = *nsrc; + *nsrc++ = tmp; + } + nsrc = (uint8_t *)src + l*width; + ndst = nsrc + width - 1; + } } /** @@ -208,13 +208,13 @@ void rotate_init(struct context *cnt) cnt->rotate_data.degrees = cnt->conf.rotate_deg % 360; /* Range: 0..359 */ } - if ( strncmp(cnt->conf.flip_axis, "h", 1) == 0 ) { - cnt->rotate_data.axis = FLIP_TYPE_HORIZONTAL; - } else if ( strncmp(cnt->conf.flip_axis, "v", 1) == 0 ) { - cnt->rotate_data.axis = FLIP_TYPE_VERTICAL; - } else { - cnt->rotate_data.axis = FLIP_TYPE_NONE; - } + if ( strncmp(cnt->conf.flip_axis, "h", 1) == 0 ) { + cnt->rotate_data.axis = FLIP_TYPE_HORIZONTAL; + } else if ( strncmp(cnt->conf.flip_axis, "v", 1) == 0 ) { + cnt->rotate_data.axis = FLIP_TYPE_VERTICAL; + } else { + cnt->rotate_data.axis = FLIP_TYPE_NONE; + } /* * Upon entrance to this function, imgs.width and imgs.height contain the @@ -320,11 +320,11 @@ int rotate_map(struct context *cnt, unsigned char *map) */ int wh, wh4 = 0, w2 = 0, h2 = 0; /* width * height, width * height / 4 etc. */ int size, deg; - enum FLIP_TYPE axis; + enum FLIP_TYPE axis; int width, height; deg = cnt->rotate_data.degrees; - axis = cnt->rotate_data.axis; + axis = cnt->rotate_data.axis; width = cnt->rotate_data.cap_width; height = cnt->rotate_data.cap_height; @@ -346,24 +346,24 @@ int rotate_map(struct context *cnt, unsigned char *map) size = wh; } - switch (axis) { - case FLIP_TYPE_HORIZONTAL: - flip_inplace_horizontal(map,width, height); - if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { - flip_inplace_horizontal(map + wh, w2, h2); - flip_inplace_horizontal(map + wh + wh4, w2, h2); - } - break; - case FLIP_TYPE_VERTICAL: - flip_inplace_vertical(map,width, height); - if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { - flip_inplace_vertical(map + wh, w2, h2); - flip_inplace_vertical(map + wh + wh4, w2, h2); - } - break; - default: - break; - } + switch (axis) { + case FLIP_TYPE_HORIZONTAL: + flip_inplace_horizontal(map,width, height); + if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { + flip_inplace_horizontal(map + wh, w2, h2); + flip_inplace_horizontal(map + wh + wh4, w2, h2); + } + break; + case FLIP_TYPE_VERTICAL: + flip_inplace_vertical(map,width, height); + if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { + flip_inplace_vertical(map + wh, w2, h2); + flip_inplace_vertical(map + wh + wh4, w2, h2); + } + break; + default: + break; + } switch (deg) { case 90: