Parcourir la source

Set DNGTAG_ASSHOTNEUTRAL and DNGTAG_ANALOGBALANCE

Martijn Braam il y a 1 an
Parent
commit
1370816a40
4 fichiers modifiés avec 65 ajouts et 2 suppressions
  1. 7 0
      include/libdng.h
  2. 34 1
      src/libdng.c
  3. 2 0
      tests/test_dng_validate.sh
  4. 22 1
      util/makedng.c

+ 7 - 0
include/libdng.h

@@ -19,6 +19,7 @@ typedef struct {
 		// Raw image data
 		uint16_t bayer_pattern_dimensions[2];
 		float neutral[3];
+		float analogbalance[3];
 		uint8_t cfapattern[4];
 
 		// Calibration data
@@ -77,6 +78,12 @@ libdng_set_datetime_now(libdng_info *dng);
 EXPORT int
 libdng_set_orientation(libdng_info *dng, uint16_t orientation);
 
+EXPORT int
+libdng_set_neutral(libdng_info *dng, float red, float green, float blue);
+
+EXPORT int
+libdng_set_analog_balance(libdng_info *dng, float red, float green, float blue);
+
 EXPORT int
 libdng_load_calibration_file(libdng_info *dng, const char *path);
 

+ 34 - 1
src/libdng.c

@@ -49,6 +49,14 @@ libdng_new(libdng_info *dng)
 	dng->cfapattern[1] = 1;
 	dng->cfapattern[2] = 1;
 	dng->cfapattern[3] = 2;
+
+	dng->neutral[0] = 1.0f;
+	dng->neutral[1] = 1.0f;
+	dng->neutral[2] = 1.0f;
+
+	dng->analogbalance[0] = 1.0f;
+	dng->analogbalance[1] = 1.0f;
+	dng->analogbalance[2] = 1.0f;
 }
 
 int
@@ -150,6 +158,30 @@ libdng_set_orientation(libdng_info *dng, uint16_t orientation)
 	return 1;
 }
 
+int
+libdng_set_neutral(libdng_info *dng, float red, float green, float blue)
+{
+	if (dng == NULL)
+		return 0;
+
+	dng->neutral[0] = red;
+	dng->neutral[1] = green;
+	dng->neutral[2] = blue;
+	return 1;
+}
+
+int
+libdng_set_analog_balance(libdng_info *dng, float red, float green, float blue)
+{
+	if (dng == NULL)
+		return 0;
+
+	dng->analogbalance[0] = red;
+	dng->analogbalance[1] = green;
+	dng->analogbalance[2] = blue;
+	return 1;
+}
+
 int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, const uint8_t *data,
 	size_t length)
@@ -188,6 +220,7 @@ libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned in
 	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 	TIFFSetField(tif, DNGTAG_COLOR_MATRIX_1, 9, dng->color_matrix_1);
 	TIFFSetField(tif, DNGTAG_ASSHOTNEUTRAL, 3, dng->neutral);
+	TIFFSetField(tif, DNGTAG_ANALOGBALANCE, 3, dng->analogbalance);
 
 	if (dng->camera_make != NULL)
 		TIFFSetField(tif, TIFFTAG_MAKE, dng->camera_make);
@@ -276,6 +309,6 @@ libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned in
 	if (dng->needs_repack) {
 		free(raw_frame);
 	}
-	
+
 	return 1;
 }

+ 2 - 0
tests/test_dng_validate.sh

@@ -29,6 +29,8 @@ $makedng -w 1280 -h 720 -p SRGGB10P scratch/data.rgb scratch/SRGGB10P.dng
 $makedng -w 1280 -h 720 -p RGGB \
   -s "Testsuite" \
   -o 2 \
+  -n 0.1,0.2,0.3 \
+  -b 0.4,0.5,0.6 \
   scratch/data.rgb scratch/fields.dng
 
 # Validate DNG

+ 22 - 1
util/makedng.c

@@ -19,6 +19,8 @@ usage(char *name)
 	fprintf(stderr, "  -s software    Software name\n");
 	fprintf(stderr, "  -o orientation Orientation number [0-9]\n");
 	fprintf(stderr, "  -c dcp         Append calibration data from .dcp file\n");
+	fprintf(stderr, "  -n r,g,b       Set the whitepoint as 3 comma seperated floats\n");
+	fprintf(stderr, "  -b r,g,b       Set sensor analog gain as 3 comma seperated floats\n");
 }
 
 int
@@ -39,8 +41,10 @@ main(int argc, char *argv[])
 	char *software = NULL;
 	char *calibration = NULL;
 	uint16_t orientation = 0;
+	float neutral[] = {1.0f, 1.0f, 1.0f};
+	float balance[] = {1.0f, 1.0f, 1.0f};
 
-	while ((c = getopt(argc, argv, "w:h:p:o:m:s:c:")) != -1) {
+	while ((c = getopt(argc, argv, "w:h:p:o:m:s:c:n:b:")) != -1) {
 		switch (c) {
 			case 'w':
 				val = strtol(optarg, &end, 10);
@@ -70,6 +74,20 @@ main(int argc, char *argv[])
 			case 'c':
 				calibration = optarg;
 				break;
+			case 'n':
+				val = sscanf(optarg, "%f,%f,%f", &neutral[0], &neutral[1], &neutral[2]);
+				if (val != 3) {
+					fprintf(stderr, "Invalid format for -n\n");
+					return 1;
+				}
+				break;
+			case 'b':
+				val = sscanf(optarg, "%f,%f,%f", &balance[0], &balance[1], &balance[2]);
+				if (val != 3) {
+					fprintf(stderr, "Invalid format for -b\n");
+					return 1;
+				}
+				break;
 			case '?':
 				if (optopt == 'd' || optopt == 'l') {
 					fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@@ -132,6 +150,9 @@ main(int argc, char *argv[])
 		libdng_load_calibration_file(&info, calibration);
 	}
 
+	libdng_set_neutral(&info, neutral[0], neutral[1], neutral[2]);
+	libdng_set_analog_balance(&info, balance[0], balance[1], balance[2]);
+
 	printf("Reading %s...\n", argv[optind]);
 	FILE *src = fopen(argv[optind], "r");
 	if (src == NULL) {