From 9871fe602da48e416f7499f89d83736b8c9df078 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Wed, 16 Sep 2020 13:39:12 +0200 Subject: [PATCH] Improved debayer implementation --- main.c | 10 +++++++--- quickdebayer.c | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 1830e34..63be2a6 100644 --- a/main.c +++ b/main.c @@ -363,6 +363,7 @@ process_image(const int *p, int size) double scale; cairo_t *cr; t = clock(); + int skip = 2; dc1394bayer_method_t method = DC1394_BAYER_METHOD_DOWNSAMPLE; dc1394color_filter_t filter = DC1394_COLOR_FILTER_BGGR; @@ -374,9 +375,12 @@ process_image(const int *p, int size) pixels = gdk_pixbuf_get_pixels(pixbuf); dc1394_bayer_decoding_8bit((const uint8_t *) p, pixels, current_width, current_height, filter, method); } else { - pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, current_width / 6, current_height / 6); + if(current_width > 1280) { + skip = 3; + } + pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, current_width / (skip*2), current_height / (skip*2)); pixels = gdk_pixbuf_get_pixels(pixbuf); - quick_debayer_bggr8((const uint8_t *)p, pixels, current_width, current_height, 3); + quick_debayer_bggr8((const uint8_t *)p, pixels, current_width, current_height, skip); } if (current_rotate == 0) { @@ -413,7 +417,7 @@ process_image(const int *p, int size) capture = 0; t = clock() - t; time_taken = ((double) t) / CLOCKS_PER_SEC; - printf("%f fps\n", 1.0 / time_taken); + //printf("%f fps\n", 1.0 / time_taken); } static gboolean diff --git a/quickdebayer.c b/quickdebayer.c index a97977f..d254643 100644 --- a/quickdebayer.c +++ b/quickdebayer.c @@ -8,6 +8,7 @@ quick_debayer_bggr8(const uint8_t *source, uint8_t *destination, int width, int { int byteskip = 2 * skip; int input_size = width * height; + int output_size = (width/byteskip) * (height/byteskip); int i; int j=0; int row_left = width; @@ -20,9 +21,10 @@ quick_debayer_bggr8(const uint8_t *source, uint8_t *destination, int width, int destination[j++] = source[i]; i = i + byteskip; row_left = row_left - byteskip; - if(row_left <= 0){ + if(row_left < byteskip){ + i = i + row_left; row_left = width; - i = i+width; + i = i + width; i = i + (width * 2 * (skip-1)); } }