Bladeren bron

Added quick'n'bad debayer implementation for previews

Martijn Braam 4 jaren geleden
bovenliggende
commit
243ef89cb5
4 gewijzigde bestanden met toevoegingen van 40 en 4 verwijderingen
  1. 6 3
      main.c
  2. 1 1
      meson.build
  3. 29 0
      quickdebayer.c
  4. 4 0
      quickdebayer.h

+ 6 - 3
main.c

@@ -15,6 +15,7 @@
 #include <gtk/gtk.h>
 #include "ini.h"
 #include "bayer.h"
+#include "quickdebayer.h"
 
 enum io_method {
 	IO_METHOD_READ,
@@ -370,12 +371,14 @@ process_image(const int *p, int size)
 		method = DC1394_BAYER_METHOD_SIMPLE;
 		// method = DC1394_BAYER_METHOD_VNG is slightly sharper but takes 10 seconds;
 		pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, current_width, current_height);
+		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 / 2, current_height / 2);
+		pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, current_width / 6, current_height / 6);
+		pixels = gdk_pixbuf_get_pixels(pixbuf);
+		quick_debayer_bggr8((const uint8_t *)p, pixels, current_width, current_height, 3);
 	}
 
-	pixels = gdk_pixbuf_get_pixels(pixbuf);
-	dc1394_bayer_decoding_8bit((const uint8_t *) p, pixels, current_width, current_height, filter, method);
 	if (current_rotate == 0) {
 		pixbufrot = pixbuf;
 	} else if (current_rotate == 90) {

+ 1 - 1
meson.build

@@ -4,7 +4,7 @@ gtkdep = dependency('gtk+-3.0')
 cc = meson.get_compiler('c')
 libm = cc.find_library('m', required: false)
 
-executable('megapixels', 'main.c', 'ini.c', 'bayer.c', dependencies : [gtkdep, libm], install : true)
+executable('megapixels', 'main.c', 'ini.c', 'bayer.c', 'quickdebayer.c', dependencies : [gtkdep, libm], install : true)
 
 install_data(['camera.glade', 'camera.css'],
              install_dir : get_option('datadir') / 'megapixels/ui')

+ 29 - 0
quickdebayer.c

@@ -0,0 +1,29 @@
+#include "quickdebayer.h"
+
+// Fast but bad debayer method that scales and rotates by skipping source pixels and
+// doesn't interpolate any values at all
+
+void
+quick_debayer_bggr8(const uint8_t *source, uint8_t *destination, int width, int height, int skip)
+{
+	int byteskip = 2 * skip;
+	int input_size = width * height;
+	int i;
+	int j=0;
+	int row_left = width;
+
+	// B G
+	// G R
+	for(i=0;i<input_size;) {
+		destination[j++] = source[i+width+1];
+		destination[j++] = source[i+1];
+		destination[j++] = source[i];
+		i = i + byteskip;
+		row_left = row_left - byteskip;
+		if(row_left <= 0){
+			row_left = width;
+			i = i+width;
+			i = i + (width * 2 * (skip-1));
+		}
+	}
+}

+ 4 - 0
quickdebayer.h

@@ -0,0 +1,4 @@
+#include <stdint.h>
+
+void quick_debayer_bggr8(const uint8_t *source, uint8_t *destination, int width, int height, int skip);
+