[RFC PATCH 6/6] image demo client: Add support for color management

Niels Ole Salscheider niels_ole at salscheider-online.de
Sun Mar 30 04:36:37 PDT 2014


You can now use the "C" key to toggle between the following modes:
- Assume sRGB input color space
- Assume that the input color space is the blending color space
- Do not use color correction
- Attach a false-color ICC profile to the surface

Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>
---
 clients/image.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 249 insertions(+)

diff --git a/clients/image.c b/clients/image.c
index 3a52c22..1d9645b 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -40,6 +40,212 @@
 #include "window.h"
 #include "../shared/cairo-util.h"
 
+#include "colorcorrection-client-protocol.h"
+
+const unsigned char icc_profile[798] =
+{
+    0x00, 0x00, 0x03, 0x1e,
+    0x6c, 0x63, 0x6d, 0x73,
+    0x02, 0x30, 0x00, 0x00,
+    0x6d, 0x6e, 0x74, 0x72,
+    0x52, 0x47, 0x42, 0x20,
+    0x58, 0x59, 0x5a, 0x20,
+    0x07, 0xd8, 0x00, 0x05,
+    0x00, 0x19, 0x00, 0x05,
+    0x00, 0x34, 0x00, 0x33,
+    0x61, 0x63, 0x73, 0x70,
+    0x41, 0x50, 0x50, 0x4c,
+    0x00, 0x00, 0x00, 0x00,
+    0x6c, 0x63, 0x6d, 0x73,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0xf6, 0xd6,
+    0x00, 0x01, 0x00, 0x00,
+    0x00, 0x00, 0xd3, 0x2d,
+    0x6c, 0x63, 0x6d, 0x73,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x0c,
+    0x64, 0x6d, 0x6e, 0x64,
+    0x00, 0x00, 0x01, 0x14,
+    0x00, 0x00, 0x00, 0x6a,
+    0x64, 0x65, 0x73, 0x63,
+    0x00, 0x00, 0x01, 0x80,
+    0x00, 0x00, 0x00, 0x66,
+    0x64, 0x6d, 0x64, 0x64,
+    0x00, 0x00, 0x01, 0xe8,
+    0x00, 0x00, 0x00, 0x67,
+    0x77, 0x74, 0x70, 0x74,
+    0x00, 0x00, 0x02, 0x50,
+    0x00, 0x00, 0x00, 0x14,
+    0x72, 0x58, 0x59, 0x5a,
+    0x00, 0x00, 0x02, 0x64,
+    0x00, 0x00, 0x00, 0x14,
+    0x62, 0x58, 0x59, 0x5a,
+    0x00, 0x00, 0x02, 0x78,
+    0x00, 0x00, 0x00, 0x14,
+    0x67, 0x58, 0x59, 0x5a,
+    0x00, 0x00, 0x02, 0x8c,
+    0x00, 0x00, 0x00, 0x14,
+    0x72, 0x54, 0x52, 0x43,
+    0x00, 0x00, 0x02, 0xa0,
+    0x00, 0x00, 0x00, 0x0e,
+    0x67, 0x54, 0x52, 0x43,
+    0x00, 0x00, 0x02, 0xb0,
+    0x00, 0x00, 0x00, 0x0e,
+    0x62, 0x54, 0x52, 0x43,
+    0x00, 0x00, 0x02, 0xc0,
+    0x00, 0x00, 0x00, 0x0e,
+    0x63, 0x68, 0x72, 0x6d,
+    0x00, 0x00, 0x02, 0xd0,
+    0x00, 0x00, 0x00, 0x24,
+    0x63, 0x70, 0x72, 0x74,
+    0x00, 0x00, 0x02, 0xf4,
+    0x00, 0x00, 0x00, 0x2a,
+    0x64, 0x65, 0x73, 0x63,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x10,
+    0x28, 0x6c, 0x63, 0x6d,
+    0x73, 0x20, 0x69, 0x6e,
+    0x74, 0x65, 0x72, 0x6e,
+    0x61, 0x6c, 0x29, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x64, 0x65, 0x73, 0x63,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x0c,
+    0x66, 0x61, 0x6b, 0x65,
+    0x42, 0x52, 0x47, 0x2e,
+    0x69, 0x63, 0x63, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x64, 0x65, 0x73, 0x63,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x0d,
+    0x72, 0x67, 0x62, 0x20,
+    0x62, 0x75, 0x69, 0x6c,
+    0x74, 0x2d, 0x69, 0x6e,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x58, 0x59, 0x5a, 0x20,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0xf3, 0x4f,
+    0x00, 0x01, 0x00, 0x00,
+    0x00, 0x01, 0x16, 0xc2,
+    0x58, 0x59, 0x5a, 0x20,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x24, 0x9e,
+    0x00, 0x00, 0x0f, 0x84,
+    0x00, 0x00, 0xb6, 0xc2,
+    0x58, 0x59, 0x5a, 0x20,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x62, 0x97,
+    0x00, 0x00, 0xb7, 0x88,
+    0x00, 0x00, 0x18, 0xda,
+    0x58, 0x59, 0x5a, 0x20,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x6f, 0xa0,
+    0x00, 0x00, 0x38, 0xf5,
+    0x00, 0x00, 0x03, 0x90,
+    0x63, 0x75, 0x72, 0x76,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x01,
+    0x02, 0x33, 0x00, 0x00,
+    0x63, 0x75, 0x72, 0x76,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x01,
+    0x02, 0x33, 0x00, 0x00,
+    0x63, 0x75, 0x72, 0x76,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x01,
+    0x02, 0x33, 0x00, 0x00,
+    0x63, 0x68, 0x72, 0x6d,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x03, 0x00, 0x00,
+    0x00, 0x00, 0x26, 0x66,
+    0x00, 0x00, 0x0f, 0x5c,
+    0x00, 0x00, 0xa3, 0xd7,
+    0x00, 0x00, 0x54, 0x7b,
+    0x00, 0x00, 0x4c, 0xcd,
+    0x00, 0x00, 0x99, 0x9a,
+    0x74, 0x65, 0x78, 0x74,
+    0x00, 0x00, 0x00, 0x00,
+    0x32, 0x30, 0x30, 0x38,
+    0x20, 0x4b, 0x61, 0x69,
+    0x2d, 0x55, 0x77, 0x65,
+    0x20, 0x42, 0x65, 0x68,
+    0x72, 0x6d, 0x61, 0x6e,
+    0x6e, 0x2c, 0x20, 0x75,
+    0x73, 0x65, 0x20, 0x66,
+    0x72, 0x65, 0x65, 0x6c,
+    0x79, 0x00
+};
+
 struct image {
 	struct window *window;
 	struct widget *widget;
@@ -58,6 +264,9 @@ struct image {
 
 	bool initialized;
 	cairo_matrix_t matrix;
+
+	struct wl_colorcorrection *colorcorrection;
+	int32_t color_mode;
 };
 
 static double
@@ -303,6 +512,30 @@ key_handler(struct window *window, struct input *input, uint32_t time,
 		clamp_view(image);
 		window_schedule_redraw(image->window);
 		break;
+	case XKB_KEY_C:
+		{
+			struct wl_surface *surface;
+			struct wl_array data;
+			char *ptr;
+
+			wl_array_init(&data);
+
+			image->color_mode = (image->color_mode + 1) % 4;
+			if (image->color_mode == 3) {
+				ptr = wl_array_add(&data, sizeof(icc_profile));
+				memcpy(ptr, icc_profile, sizeof(icc_profile));
+			}
+
+			surface = window_get_wl_surface(image->window);
+			wl_colorcorrection_set_profile(image->colorcorrection,
+						       surface,
+						       image->color_mode,
+						       &data);
+
+			wl_array_release(&data);
+
+			window_schedule_redraw(image->window);
+		}
 	}
 }
 
@@ -351,6 +584,19 @@ close_handler(void *data)
 	free(image);
 }
 
+static void
+global_handler(struct display *display, uint32_t name,
+	       const char *interface, uint32_t version, void *data)
+{
+	struct image *image = data;
+
+	if (strcmp(interface, "wl_colorcorrection") == 0) {
+		image->colorcorrection =
+			display_bind(display, name,
+				     &wl_colorcorrection_interface, 1);
+	}
+}
+
 static struct image *
 image_create(struct display *display, const char *filename,
 	     int *image_counter)
@@ -400,6 +646,9 @@ image_create(struct display *display, const char *filename,
 	window_set_key_handler(image->window, key_handler);
 	widget_schedule_resize(image->widget, 500, 400);
 
+	display_set_user_data(display, image);
+	display_set_global_handler(display, global_handler);
+
 	return image;
 }
 
-- 
1.9.1



More information about the wayland-devel mailing list