Selaa lähdekoodia

Allow setting color/forward matrices

Kristian Vos 1 kuukausi sitten
vanhempi
commit
57024da3b7
3 muutettua tiedostoa jossa 72 lisäystä ja 0 poistoa
  1. 9 0
      include/libdng.h
  2. 60 0
      src/libdng.c
  3. 3 0
      tests/check_dng.c

+ 9 - 0
include/libdng.h

@@ -160,6 +160,15 @@ libdng_set_distortion(libdng_info *dng, float a, float b, float c);
 EXPORT int
 libdng_set_vignette(libdng_info *dng, float k1, float k2, float k3);
 
+EXPORT int
+libdng_set_color_matrix_1(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9);
+
+EXPORT int
+libdng_set_color_matrix_2(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9);
+
+EXPORT int
+libdng_set_forward_matrix_1(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9);
+
 EXPORT int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, const uint8_t *data,
 	size_t length);

+ 60 - 0
src/libdng.c

@@ -42,6 +42,7 @@ libdng_new(libdng_info *dng)
 	for (size_t i = 0; i < 9; i++) {
 		dng->color_matrix_1[i] = 0.0f;
 		dng->color_matrix_2[i] = 0.0f;
+		dng->forward_matrix_1[i] = 0.0f;
 	}
 	dng->color_matrix_1[0] = 1.0f;
 	dng->color_matrix_1[4] = 1.0f;
@@ -300,6 +301,63 @@ libdng_set_vignette(libdng_info *dng, float k1, float k2, float k3)
 	return 1;
 }
 
+int
+libdng_set_color_matrix_1(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9)
+{
+	if (dng == NULL)
+		return 0;
+	
+	dng->color_matrix_1[0] = v1;
+	dng->color_matrix_1[1] = v2;
+	dng->color_matrix_1[2] = v3;
+	dng->color_matrix_1[3] = v4;
+	dng->color_matrix_1[4] = v5;
+	dng->color_matrix_1[5] = v6;
+	dng->color_matrix_1[6] = v7;
+	dng->color_matrix_1[7] = v8;
+	dng->color_matrix_1[8] = v9;
+
+	return 1;
+}
+
+int
+libdng_set_color_matrix_2(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9)
+{
+	if (dng == NULL)
+		return 0;
+	
+	dng->color_matrix_2[0] = v1;
+	dng->color_matrix_2[1] = v2;
+	dng->color_matrix_2[2] = v3;
+	dng->color_matrix_2[3] = v4;
+	dng->color_matrix_2[4] = v5;
+	dng->color_matrix_2[5] = v6;
+	dng->color_matrix_2[6] = v7;
+	dng->color_matrix_2[7] = v8;
+	dng->color_matrix_2[8] = v9;
+
+	return 1;
+}
+
+int
+libdng_set_forward_matrix_1(libdng_info *dng, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9)
+{
+	if (dng == NULL)
+		return 0;
+	
+	dng->forward_matrix_1[0] = v1;
+	dng->forward_matrix_1[1] = v2;
+	dng->forward_matrix_1[2] = v3;
+	dng->forward_matrix_1[3] = v4;
+	dng->forward_matrix_1[4] = v5;
+	dng->forward_matrix_1[5] = v6;
+	dng->forward_matrix_1[6] = v7;
+	dng->forward_matrix_1[7] = v8;
+	dng->forward_matrix_1[8] = v9;
+
+	return 1;
+}
+
 int
 libdng_write(libdng_info *dng, const char *path, unsigned int width, unsigned int height, const uint8_t *data,
 	size_t length)
@@ -350,6 +408,8 @@ libdng_write_with_thumbnail(libdng_info *dng, const char *path, unsigned int wid
 	TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
 	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 	TIFFSetField(tif, DNGTAG_COLOR_MATRIX_1, 9, dng->color_matrix_1);
+	TIFFSetField(tif, DNGTAG_COLOR_MATRIX_2, 9, dng->color_matrix_2);
+	TIFFSetField(tif, DNGTAG_FORWARD_MATRIX_1, 9, dng->forward_matrix_1);
 	TIFFSetField(tif, DNGTAG_ASSHOTNEUTRAL, 3, dng->neutral);
 	TIFFSetField(tif, DNGTAG_ANALOGBALANCE, 3, dng->analogbalance);
 

+ 3 - 0
tests/check_dng.c

@@ -51,6 +51,9 @@ TEST generate_simple_dng(void)
 		ASSERT_EQm("Set framerate", 1, libdng_set_frame_rate(&info, 30.0f));
 		ASSERT_EQm("Set distortion", 1, libdng_set_distortion(&info, 1.0f, 2.0f, 3.0f));
 		ASSERT_EQm("Set vignette", 1, libdng_set_vignette(&info, 1.0f, -1.0f, 6.0f));
+		ASSERT_EQm("Set color matrix 1", 1, libdng_set_color_matrix_1(&info, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
+		ASSERT_EQm("Set color matrix 2", 1, libdng_set_color_matrix_2(&info, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
+		ASSERT_EQm("Set forward matrix 1", 1, libdng_set_forward_matrix_1(&info, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
 	uint8_t *data = malloc(1280 * 720);
 		ASSERT_EQm("Write DNG", 1, libdng_write(&info, "test.dng", 1280, 720, data, 1280 * 720));
 	free(data);