Browse Source

Add the ISO metadata

Martijn Braam 1 year ago
parent
commit
90e01b907e
5 changed files with 31 additions and 1 deletions
  1. 4 0
      include/libdng.h
  2. 3 0
      man/makedng.1.scd
  3. 13 0
      src/libdng.c
  4. 1 0
      tests/test_dng_validate.sh
  5. 10 1
      util/makedng.c

+ 4 - 0
include/libdng.h

@@ -17,6 +17,7 @@ typedef struct {
 		struct tm datetime;
 		uint16_t exposure_program;
 		float exposure_time;
+		uint32_t iso;
 
 		// Raw image data
 		uint16_t bayer_pattern_dimensions[2];
@@ -128,6 +129,9 @@ libdng_set_exposure_program(libdng_info *dng, uint16_t mode);
 EXPORT int
 libdng_set_exposure_time(libdng_info *dng, float seconds);
 
+EXPORT int
+libdng_set_iso(libdng_info *dng, uint32_t isospeed);
+
 EXPORT int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, const uint8_t *data,
 	size_t length);

+ 3 - 0
man/makedng.1.scd

@@ -49,6 +49,9 @@ metadata to correctly render the file.
 *-t seconds*
 	Set the exposure time for the picture in seconds (eg. 0.01 for 1/100)
 
+*-i iso-speed*
+	Set the ISO speed rating for the picture
+
 # PIXEL FORMATS
 
 The pixel format argument accepts the following values:

+ 13 - 0
src/libdng.c

@@ -59,6 +59,7 @@ libdng_new(libdng_info *dng)
 	dng->analogbalance[2] = 1.0f;
 
 	dng->exposure_time = 0.0f;
+	dng->iso = 0;
 }
 
 int
@@ -212,6 +213,15 @@ libdng_set_exposure_time(libdng_info *dng, float seconds)
 	return 1;
 }
 
+int
+libdng_set_iso(libdng_info *dng, uint32_t isospeed)
+{
+	if (dng == NULL)
+		return 0;
+
+	dng->iso = isospeed;
+	return 1;
+}
 
 int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, const uint8_t *data,
@@ -352,6 +362,9 @@ libdng_write_with_thumbnail(libdng_info *dng, const char *path, unsigned int wid
 	if (dng->exposure_time > 0) {
 		TIFFSetField(tif, EXIFTAG_EXPOSURETIME, dng->exposure_time);
 	}
+	if(dng->iso > 0) {
+		TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &dng->iso);
+	}
 
 	uint64_t exif_offset = 0;
 	if (!TIFFWriteCustomDirectory(tif, &exif_offset)) {

+ 1 - 0
tests/test_dng_validate.sh

@@ -33,6 +33,7 @@ $makedng -w 1280 -h 720 -p RGGB \
   -b 0.4,0.5,0.6 \
   -e 2 \
   -t 0.01 \
+  -i 1600 \
   scratch/data.rgb scratch/fields.dng
 
 # Validate DNG

+ 10 - 1
util/makedng.c

@@ -23,6 +23,7 @@ usage(char *name)
 	fprintf(stderr, "  -b r,g,b       Set sensor analog gain as 3 comma seperated floats\n");
 	fprintf(stderr, "  -e program     Set the exposure program in EXIF, 0-8\n");
 	fprintf(stderr, "  -t seconds     Set the exposure time in seconds\n");
+	fprintf(stderr, "  -i speed       Set the ISO speed rating\n");
 }
 
 int
@@ -47,8 +48,9 @@ main(int argc, char *argv[])
 	float balance[] = {1.0f, 1.0f, 1.0f};
 	uint16_t exposure_program = 0;
 	float exposure_time = 0;
+	uint32_t iso = 0;
 
-	while ((c = getopt(argc, argv, "w:h:p:o:m:s:c:n:b:e:t:")) != -1) {
+	while ((c = getopt(argc, argv, "w:h:p:o:m:s:c:n:b:e:t:i:")) != -1) {
 		switch (c) {
 			case 'w':
 				val = strtol(optarg, &end, 10);
@@ -99,6 +101,10 @@ main(int argc, char *argv[])
 			case 't':
 				exposure_time = strtof(optarg, &end);
 				break;
+			case 'i':
+				val = strtol(optarg, &end, 10);
+				iso = (uint32_t) val;
+				break;
 			case '?':
 				if (optopt == 'd' || optopt == 'l') {
 					fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@@ -167,6 +173,9 @@ main(int argc, char *argv[])
 	if (exposure_time > 0) {
 		libdng_set_exposure_time(&info, exposure_time);
 	}
+	if (iso > 0) {
+		libdng_set_iso(&info, iso);
+	}
 
 	printf("Reading %s...\n", argv[optind]);
 	FILE *src = fopen(argv[optind], "r");