Explorar el Código

Add more pixfmt support

Martijn Braam hace 1 año
padre
commit
b13d15d5de
Se han modificado 4 ficheros con 59 adiciones y 8 borrados
  1. 4 4
      config/purism,librem5.conf
  2. 45 2
      src/mode.c
  3. 9 1
      src/parse.c
  4. 1 1
      util/getframe.c

+ 4 - 4
config/purism,librem5.conf

@@ -31,10 +31,10 @@ Front: {
 
     Modes: (
         {
-            Width: 1280;
-            Height: 960;
-            Rate: 60;
-            Format: "BGGR8";
+            Width: 1632;
+            Height: 1224;
+            Rate: 30;
+            Format: "GBRG10";
             Rotate: 90;
             Mirror: true;
 

+ 45 - 2
src/mode.c

@@ -10,6 +10,7 @@ struct libmegapixels_modename {
 		uint32_t media_bus_format;
 };
 
+// TODO: The 16 bit formats are imported from millipixels and seem broken
 static struct libmegapixels_modename mode_lut[] = {
 	{
 		.name = "unsupported",
@@ -56,6 +57,46 @@ static struct libmegapixels_modename mode_lut[] = {
 		.v4l_pixel_format = V4L2_PIX_FMT_SRGGB10P,
 		.media_bus_format = MEDIA_BUS_FMT_SRGGB10_1X10,
 	},
+	{
+		.name = "BGGR10",
+		.v4l_pixel_format = V4L2_PIX_FMT_SBGGR10,
+		.media_bus_format = MEDIA_BUS_FMT_SBGGR10_1X10,
+	},
+	{
+		.name = "GBRG10",
+		.v4l_pixel_format = V4L2_PIX_FMT_SGBRG10,
+		.media_bus_format = MEDIA_BUS_FMT_SGBRG10_1X10,
+	},
+	{
+		.name = "GRBG10",
+		.v4l_pixel_format = V4L2_PIX_FMT_SGRBG10,
+		.media_bus_format = MEDIA_BUS_FMT_SGRBG10_1X10,
+	},
+	{
+		.name = "RGGB10",
+		.v4l_pixel_format = V4L2_PIX_FMT_SRGGB10,
+		.media_bus_format = MEDIA_BUS_FMT_SRGGB10_1X10,
+	},
+	{
+		.name = "BGGR16",
+		.v4l_pixel_format = V4L2_PIX_FMT_SBGGR16,
+		.media_bus_format = MEDIA_BUS_FMT_SBGGR10_1X10,
+	},
+	{
+		.name = "GBRG16",
+		.v4l_pixel_format = V4L2_PIX_FMT_SGBRG16,
+		.media_bus_format = MEDIA_BUS_FMT_SGBRG10_1X10,
+	},
+	{
+		.name = "GRBG16",
+		.v4l_pixel_format = V4L2_PIX_FMT_SGRBG16,
+		.media_bus_format =MEDIA_BUS_FMT_SGRBG10_1X10 ,
+	},
+	{
+		.name = "RGGB16",
+		.v4l_pixel_format = V4L2_PIX_FMT_SRGGB16,
+		.media_bus_format = MEDIA_BUS_FMT_SRGGB10_1X10,
+	},
 	{
 		.name = "UYVY",
 		.v4l_pixel_format = V4L2_PIX_FMT_UYVY,
@@ -71,7 +112,8 @@ static struct libmegapixels_modename mode_lut[] = {
 uint32_t
 format_name_to_v4l_pixfmt(const char *name)
 {
-	for (int i = 0; i < sizeof(mode_lut); i++) {
+	int count = sizeof(mode_lut) / sizeof(mode_lut[0]);
+	for (int i = 0; i < count; i++) {
 		if (strcasecmp(mode_lut[i].name, name) == 0) {
 			return mode_lut[i].v4l_pixel_format;
 		}
@@ -82,7 +124,8 @@ format_name_to_v4l_pixfmt(const char *name)
 uint32_t
 format_name_to_media_busfmt(const char *name)
 {
-	for (int i = 0; i < sizeof(mode_lut); i++) {
+	int count = sizeof(mode_lut) / sizeof(mode_lut[0]);
+	for (int i = 0; i < count; i++) {
 		if (strcasecmp(mode_lut[i].name, name) == 0) {
 			return mode_lut[i].media_bus_format;
 		}

+ 9 - 1
src/parse.c

@@ -13,6 +13,7 @@
 #include "libmegapixels.h"
 #include "mode.h"
 #include "util.h"
+#include "log.h"
 
 char *
 find_path_for_devnode(struct media_v2_intf_devnode devnode)
@@ -221,18 +222,25 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name)
 		libmegapixels_mode *mm = malloc(sizeof(libmegapixels_mode));
 		camera->modes[n] = mm;
 		if (!config_setting_lookup_int(mode, "Width", &mm->width)) {
+			log_error("Missing Width\n");
 			return -1;
 		}
 		if (!config_setting_lookup_int(mode, "Height", &mm->height)) {
+			log_error("Missing Height\n");
 			return -1;
 		}
 		if (!config_setting_lookup_int(mode, "Rate", &mm->rate)) {
+			log_error("Missing Rate\n");
 			return -1;
 		}
 
 		const char *fmt;
 		config_setting_lookup_string(mode, "Format", &fmt);
 		mm->v4l_pixfmt = format_name_to_v4l_pixfmt(fmt);
+		if (mm->v4l_pixfmt == 0) {
+			log_error("Unknown format '%s'\n", fmt);
+			return -1;
+		}
 		mm->media_busfmt = format_name_to_media_busfmt(fmt);
 
 
@@ -251,7 +259,7 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name)
 		config_setting_t *cmd;
 
 		if (cmds == NULL) {
-			fprintf(stderr, "Missing pipeline\n");
+			log_error("Mode has no pipeline\n");
 			n++;
 			continue;
 		}

+ 1 - 1
util/getframe.c

@@ -187,7 +187,7 @@ main(int argc, char *argv[])
 				fwrite(buffers[buf.index].start, buf.bytesused, 1, fp);
 				fclose(fp);
 				printf("Stored frame to: %s\n", outfile);
-				printf("Format: %dx%x\n", mode->width, mode->height);
+				printf("Format: %dx%d\n", mode->width, mode->height);
 
 				char fourcc[5] = {0};
 				fourcc[0] = (char) (mode->v4l_pixfmt & 0xff);