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

Submitted by Niels Ole Salscheider on Oct. 13, 2014, 5:40 p.m.

Details

Message ID 1413222051-4637-7-git-send-email-niels_ole@salscheider-online.de
State Changes Requested
Headers show

Not browsing as part of any series.

Commit Message

Niels Ole Salscheider Oct. 13, 2014, 5:40 p.m.
You can now use "C" to switch between the following modes:
- Assume sRGB input color space
- Assume that the input color space is the blending color space
- Attach a false-color ICC profile to the surface

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

Patch hide | download patch | download mbox

diff --git a/clients/image.c b/clients/image.c
index aee8112..0941125 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -36,12 +36,219 @@ 
 #include <cairo.h>
 #include <assert.h>
 #include <linux/input.h>
+#include <sys/stat.h>
 
 #include <wayland-client.h>
 
 #include "window.h"
 #include "../shared/cairo-util.h"
 
+#include "cms-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;
@@ -60,6 +267,12 @@  struct image {
 
 	bool initialized;
 	cairo_matrix_t matrix;
+
+	int color_mode;
+	struct wl_cms *cms;
+	struct wl_cms_colorspace *profile_colorspace;
+	struct wl_cms_colorspace *srgb_colorspace;
+	struct wl_cms_colorspace *blending_colorspace;
 };
 
 static double
@@ -305,6 +518,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:
+		if (image->cms) {
+			struct wl_surface *surface;
+			surface = window_get_wl_surface(image->window);
+
+			image->color_mode = (image->color_mode + 1) % 3;
+			switch (image->color_mode) {
+			case 0:
+				wl_cms_set_colorspace(image->cms, surface,
+						      image->srgb_colorspace);
+				break;
+			case 1:
+				wl_cms_set_colorspace(image->cms, surface,
+						      image->blending_colorspace);
+				break;
+			case 2:
+				wl_cms_set_colorspace(image->cms, surface,
+						      image->profile_colorspace);
+				break;
+			}
+
+			window_schedule_redraw(image->window);
+		}
+		break;
 	}
 }
 
@@ -353,12 +590,28 @@  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_cms") == 0) {
+		image->cms =
+			display_bind(display, name,
+				     &wl_cms_interface, 1);
+	}
+}
+
 static struct image *
 image_create(struct display *display, const char *filename,
 	     int *image_counter)
 {
 	struct image *image;
 	char *b, *copy, title[512];;
+	int fd;
+	FILE *profilefile;
+	char template[24];
 
 	image = zalloc(sizeof *image);
 	if (image == NULL)
@@ -401,6 +654,26 @@  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);
+
+	if (image->cms) {
+		image->color_mode = 0;
+		image->srgb_colorspace = wl_cms_srgb_colorspace(image->cms);
+		image->blending_colorspace =
+			wl_cms_blending_colorspace(image->cms);
+
+		strncpy(template, "/tmp/weston-cms-XXXXXX", 24);
+		fd = mkstemp(template);
+		unlink(template);
+		profilefile = fdopen(fd, "w");
+		fwrite(icc_profile, sizeof(icc_profile), 1, profilefile);
+		rewind(profilefile);
+		image->profile_colorspace =
+			wl_cms_colorspace_from_fd(image->cms, fd);
+		close(fd);
+	}
+
 	return image;
 }
 

Comments

On 13 October 2014 18:40, Niels Ole Salscheider
<niels_ole@salscheider-online.de> wrote:
> - Attach a false-color ICC profile to the surface
> +const unsigned char icc_profile[798] =

Hey, looks really good. Are you using a channel-swapped test profile?
If so, there are example profiles in
/usr/share/color/icc/colord/SwappedRedAndGreen.icc that might be
easier than embedding it. Up to you.

Richard.
On Mon, Oct 13, 2014 at 07:40:51PM +0200, Niels Ole Salscheider wrote:
> You can now use "C" to switch between the following modes:
> - Assume sRGB input color space
> - Assume that the input color space is the blending color space
> - Attach a false-color ICC profile to the surface
> 
> Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>
> ---
>  clients/image.c | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 273 insertions(+)
> 
> diff --git a/clients/image.c b/clients/image.c
> index aee8112..0941125 100644
> --- a/clients/image.c
> +++ b/clients/image.c
> @@ -36,12 +36,219 @@
>  #include <cairo.h>
>  #include <assert.h>
>  #include <linux/input.h>
> +#include <sys/stat.h>
>  
>  #include <wayland-client.h>
>  
>  #include "window.h"
>  #include "../shared/cairo-util.h"
>  
> +#include "cms-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;
> @@ -60,6 +267,12 @@ struct image {
>  
>  	bool initialized;
>  	cairo_matrix_t matrix;
> +
> +	int color_mode;
> +	struct wl_cms *cms;
> +	struct wl_cms_colorspace *profile_colorspace;
> +	struct wl_cms_colorspace *srgb_colorspace;
> +	struct wl_cms_colorspace *blending_colorspace;
>  };
>  
>  static double
> @@ -305,6 +518,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:
> +		if (image->cms) {
> +			struct wl_surface *surface;
> +			surface = window_get_wl_surface(image->window);
> +
> +			image->color_mode = (image->color_mode + 1) % 3;
> +			switch (image->color_mode) {
> +			case 0:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->srgb_colorspace);
> +				break;
> +			case 1:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->blending_colorspace);
> +				break;
> +			case 2:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->profile_colorspace);
> +				break;
> +			}
> +
> +			window_schedule_redraw(image->window);
> +		}
> +		break;
>  	}
>  }
>  
> @@ -353,12 +590,28 @@ 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_cms") == 0) {
> +		image->cms =
> +			display_bind(display, name,
> +				     &wl_cms_interface, 1);
> +	}
> +}
> +
>  static struct image *
>  image_create(struct display *display, const char *filename,
>  	     int *image_counter)
>  {
>  	struct image *image;
>  	char *b, *copy, title[512];;
> +	int fd;
> +	FILE *profilefile;
> +	char template[24];
>  
>  	image = zalloc(sizeof *image);
>  	if (image == NULL)
> @@ -401,6 +654,26 @@ 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);
> +
> +	if (image->cms) {
> +		image->color_mode = 0;
> +		image->srgb_colorspace = wl_cms_srgb_colorspace(image->cms);
> +		image->blending_colorspace =
> +			wl_cms_blending_colorspace(image->cms);
> +
> +		strncpy(template, "/tmp/weston-cms-XXXXXX", 24);

sizeof(template) instead of the 24?  Or at least use a constant instead
of the 24.

> +		fd = mkstemp(template);
> +		unlink(template);
> +		profilefile = fdopen(fd, "w");
> +		fwrite(icc_profile, sizeof(icc_profile), 1, profilefile);
> +		rewind(profilefile);
> +		image->profile_colorspace =
> +			wl_cms_colorspace_from_fd(image->cms, fd);
> +		close(fd);

error checking needed in above routines.

> +	}
> +
>  	return image;
>  }
>  
> -- 
> 2.1.2
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
On Mon, Oct 13, 2014 at 07:40:51PM +0200, Niels Ole Salscheider wrote:
> You can now use "C" to switch between the following modes:
> - Assume sRGB input color space
> - Assume that the input color space is the blending color space
> - Attach a false-color ICC profile to the surface
> 
> Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>

In talking with daniels, it's unclear if color management belongs in
weston, since it adds quite a bit of complex code.  If weston is merely
going to be a demonstration compositor then it may be overkill.
However, if we go ahead with libweston (or something similar), where
Weston bits are the basis for other compositors, then we probably would
want color management.

So for now, moving this patchset to Deferred.
 
> ---
> clients/image.c | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 273 insertions(+)
> 
> diff --git a/clients/image.c b/clients/image.c
> index aee8112..0941125 100644
> --- a/clients/image.c
> +++ b/clients/image.c
> @@ -36,12 +36,219 @@
>  #include <cairo.h>
>  #include <assert.h>
>  #include <linux/input.h>
> +#include <sys/stat.h>
>  
>  #include <wayland-client.h>
>  
>  #include "window.h"
>  #include "../shared/cairo-util.h"
>  
> +#include "cms-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;
> @@ -60,6 +267,12 @@ struct image {
>  
>  	bool initialized;
>  	cairo_matrix_t matrix;
> +
> +	int color_mode;
> +	struct wl_cms *cms;
> +	struct wl_cms_colorspace *profile_colorspace;
> +	struct wl_cms_colorspace *srgb_colorspace;
> +	struct wl_cms_colorspace *blending_colorspace;
>  };
>  
>  static double
> @@ -305,6 +518,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:
> +		if (image->cms) {
> +			struct wl_surface *surface;
> +			surface = window_get_wl_surface(image->window);
> +
> +			image->color_mode = (image->color_mode + 1) % 3;
> +			switch (image->color_mode) {
> +			case 0:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->srgb_colorspace);
> +				break;
> +			case 1:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->blending_colorspace);
> +				break;
> +			case 2:
> +				wl_cms_set_colorspace(image->cms, surface,
> +						      image->profile_colorspace);
> +				break;
> +			}
> +
> +			window_schedule_redraw(image->window);
> +		}
> +		break;
>  	}
>  }
>  
> @@ -353,12 +590,28 @@ 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_cms") == 0) {
> +		image->cms =
> +			display_bind(display, name,
> +				     &wl_cms_interface, 1);
> +	}
> +}
> +
>  static struct image *
>  image_create(struct display *display, const char *filename,
>  	     int *image_counter)
>  {
>  	struct image *image;
>  	char *b, *copy, title[512];;
> +	int fd;
> +	FILE *profilefile;
> +	char template[24];
>  
>  	image = zalloc(sizeof *image);
>  	if (image == NULL)
> @@ -401,6 +654,26 @@ 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);
> +
> +	if (image->cms) {
> +		image->color_mode = 0;
> +		image->srgb_colorspace = wl_cms_srgb_colorspace(image->cms);
> +		image->blending_colorspace =
> +			wl_cms_blending_colorspace(image->cms);
> +
> +		strncpy(template, "/tmp/weston-cms-XXXXXX", 24);
> +		fd = mkstemp(template);
> +		unlink(template);
> +		profilefile = fdopen(fd, "w");
> +		fwrite(icc_profile, sizeof(icc_profile), 1, profilefile);
> +		rewind(profilefile);
> +		image->profile_colorspace =
> +			wl_cms_colorspace_from_fd(image->cms, fd);
> +		close(fd);
> +	}
> +
>  	return image;
>  }
>
On Tue, 27 Jan 2015 12:13:32 -0800
Bryce Harrington <bryce@osg.samsung.com> wrote:

> On Mon, Oct 13, 2014 at 07:40:51PM +0200, Niels Ole Salscheider wrote:
> > You can now use "C" to switch between the following modes:
> > - Assume sRGB input color space
> > - Assume that the input color space is the blending color space
> > - Attach a false-color ICC profile to the surface
> > 
> > Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>
> 
> In talking with daniels, it's unclear if color management belongs in
> weston, since it adds quite a bit of complex code.  If weston is merely
> going to be a demonstration compositor then it may be overkill.
> However, if we go ahead with libweston (or something similar), where
> Weston bits are the basis for other compositors, then we probably would
> want color management.
> 
> So for now, moving this patchset to Deferred.

Hi,

I see this patch series is marked as Under review currently. Would it
be safe to say "Changes requested" is a more correct status?

Or do we think this is not in scope for Weston at this time, and mark
the series as Rejected?

Are there other compositors implementing this?
Is it worth to push the Weston implementation, considering we decided
that a Weston DE is a non-goal?

And most importantly, what are the authors' plans at the moment?


Thanks,
pq