Browse Source

Support setting camera Make and Model

Martijn Braam 1 year ago
parent
commit
2ea1025a09
3 changed files with 25 additions and 5 deletions
  1. 3 0
      include/libdng.h
  2. 4 4
      tests/test_dng_validate.sh
  3. 18 1
      util/makedng.c

+ 3 - 0
include/libdng.h

@@ -35,6 +35,9 @@ libdng_free(libdng_info *dng);
 EXPORT int
 libdng_set_mode_from_name(libdng_info *dng, const char *name);
 
+EXPORT int
+libdng_set_make_model(libdng_info *dng, char *make, char *model);
+
 EXPORT int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, uint8_t *data,
 	size_t length);

+ 4 - 4
tests/test_dng_validate.sh

@@ -18,10 +18,10 @@ magick -size 1280x720 gradient: -colorspace RGB scratch/data.rgb
 
 # Generate DNG
 
-$makedng -w 1280 -h 720 -p RGGB scratch/data.rgb scratch/RGGB.dng
-$makedng -w 1280 -h 720 -p GRBG scratch/data.rgb scratch/GRBG.dng
-$makedng -w 1280 -h 720 -p GBRG scratch/data.rgb scratch/GBRG.dng
-$makedng -w 1280 -h 720 -p BGGR scratch/data.rgb scratch/BGGR.dng
+$makedng -w 1280 -h 720 -p RGGB -m Test,RGGB scratch/data.rgb scratch/RGGB.dng
+$makedng -w 1280 -h 720 -p GRBG -m Test,GRBG scratch/data.rgb scratch/GRBG.dng
+$makedng -w 1280 -h 720 -p GBRG -m Test,GBRG scratch/data.rgb scratch/GBRG.dng
+$makedng -w 1280 -h 720 -p BGGR -m Test,BGGR scratch/data.rgb scratch/BGGR.dng
 
 $makedng -w 1280 -h 720 -p RG10 scratch/data.rgb scratch/RG10.dng
 

+ 18 - 1
util/makedng.c

@@ -31,8 +31,9 @@ main(int argc, char *argv[])
 	unsigned int width = 0;
 	unsigned int height = 0;
 	char *pixelfmt = NULL;
+	char *model = NULL;
 
-	while ((c = getopt(argc, argv, "w:h:p:")) != -1) {
+	while ((c = getopt(argc, argv, "w:h:p:m:")) != -1) {
 		switch (c) {
 			case 'w':
 				val = strtol(optarg, &end, 10);
@@ -45,6 +46,9 @@ main(int argc, char *argv[])
 			case 'p':
 				pixelfmt = optarg;
 				break;
+			case 'm':
+				model = optarg;
+				break;
 			case '?':
 				if (optopt == 'd' || optopt == 'l') {
 					fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@@ -82,6 +86,19 @@ main(int argc, char *argv[])
 		return 1;
 	}
 
+	if (model != NULL) {
+		char *make = model;
+		for (size_t i = 0; i < strlen(model); i++) {
+			if (model[i] == ',') {
+				model[i] = '\0';
+				model = &model[i + 1];
+			}
+		}
+		printf("Make: '%s'\n", make);
+		printf("Model: '%s'\n", model);
+		libdng_set_make_model(&info, make, model);
+	}
+
 	printf("Reading %s...\n", argv[optind]);
 	FILE *src = fopen(argv[optind], "r");
 	if (src == NULL) {