[gnome-color-manager] Use CdTransform to convert the sample image
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Use CdTransform to convert the sample image
- Date: Thu, 3 Apr 2014 17:00:04 +0000 (UTC)
commit 2b28b3c8631beb06822392a5954c9cda0924989c
Author: Richard Hughes <richard hughsie com>
Date: Thu Apr 3 17:25:32 2014 +0200
Use CdTransform to convert the sample image
src/Makefile.am | 2 -
src/gcm-image.c | 528 ---------------------------------------------------
src/gcm-image.h | 75 --------
src/gcm-self-test.c | 66 -------
src/gcm-utils.c | 104 ++++++++++
src/gcm-utils.h | 5 +
src/gcm-viewer.c | 41 ++--
7 files changed, 129 insertions(+), 692 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6cb7465..5d984c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,8 +28,6 @@ libgcmshared_a_SOURCES = \
gcm-debug.h \
gcm-exif.c \
gcm-exif.h \
- gcm-image.c \
- gcm-image.h \
gcm-print.c \
gcm-print.h \
gcm-trc-widget.c \
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 8c9a3a7..53fdf5f 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -32,7 +32,6 @@
#include "gcm-debug.h"
#include "gcm-exif.h"
#include "gcm-gamma-widget.h"
-#include "gcm-image.h"
#include "gcm-print.h"
#include "gcm-trc-widget.h"
#include "gcm-utils.h"
@@ -71,70 +70,6 @@ gcm_test_brightness_func (void)
}
static void
-gcm_test_image_func (void)
-{
- GcmImage *image;
- GtkWidget *image_test;
- GtkWidget *dialog;
- GtkWidget *vbox;
- gint response;
- gboolean ret;
- CdIcc *profile;
- GFile *file;
-
- image = gcm_image_new ();
- g_assert (image != NULL);
-
- gtk_image_set_from_file (GTK_IMAGE(image), TESTDATADIR "/image-widget.png");
-
- /* show in a dialog as an example */
- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO, "Does color-corrected image match\nthe picture below?");
- image_test = gtk_image_new_from_file (TESTDATADIR "/image-widget-good.png");
- vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_box_pack_end (GTK_BOX(vbox), GTK_WIDGET(image), TRUE, TRUE, 12);
- gtk_box_pack_end (GTK_BOX(vbox), image_test, TRUE, TRUE, 12);
- gtk_widget_set_size_request (GTK_WIDGET(image), 300, 300);
- gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
- gtk_widget_show (GTK_WIDGET(image));
- gtk_widget_show (image_test);
-
- g_object_set (image,
- "use-embedded-profile", TRUE,
- "output-profile", NULL,
- NULL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- g_assert ((response == GTK_RESPONSE_YES));
-
- gtk_image_set_from_file (GTK_IMAGE(image_test), TESTDATADIR "/image-widget-nonembed.png");
- g_object_set (image,
- "use-embedded-profile", FALSE,
- NULL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- g_assert ((response == GTK_RESPONSE_YES));
-
- gtk_image_set_from_file (GTK_IMAGE(image_test), TESTDATADIR "/image-widget-output.png");
- g_object_set (image,
- "use-embedded-profile", TRUE,
- NULL);
-
- /* get test file */
- profile = cd_icc_new ();
- file = g_file_new_for_path (TESTDATADIR "/ibm-t61.icc");
- ret = cd_icc_load_file (profile, file, CD_ICC_LOAD_FLAGS_NONE, NULL, NULL);
- g_object_unref (file);
- g_assert (ret);
- gcm_image_set_output_profile (image, profile);
- g_object_unref (profile);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- g_assert ((response == GTK_RESPONSE_YES));
-
- gtk_widget_destroy (dialog);
-}
-
-static void
gcm_test_calibrate_func (void)
{
GcmCalibrate *calibrate;
@@ -455,7 +390,6 @@ main (int argc, char **argv)
g_test_add_func ("/color/utils", gcm_test_utils_func);
if (g_test_thorough ()) {
g_test_add_func ("/color/brightness", gcm_test_brightness_func);
- g_test_add_func ("/color/image", gcm_test_image_func);
g_test_add_func ("/color/trc", gcm_test_trc_widget_func);
g_test_add_func ("/color/cie", gcm_test_cie_widget_func);
g_test_add_func ("/color/gamma_widget", gcm_test_gamma_widget_func);
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 2099f59..72ab0b8 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -338,3 +338,107 @@ cd_colorspace_to_localised_string (CdColorspace colorspace)
}
return NULL;
}
+
+/**
+ * gcm_utils_get_pixel_format:
+ **/
+static CdPixelFormat
+gcm_utils_get_pixel_format (GdkPixbuf *pixbuf)
+{
+ guint bits;
+ CdPixelFormat format = CD_PIXEL_FORMAT_UNKNOWN;
+
+ /* no alpha channel */
+ bits = gdk_pixbuf_get_bits_per_sample (pixbuf);
+ if (!gdk_pixbuf_get_has_alpha (pixbuf) && bits == 8) {
+ format = CD_PIXEL_FORMAT_RGB24;
+ goto out;
+ }
+
+ /* alpha channel */
+ if (bits == 8) {
+ format = CD_PIXEL_FORMAT_RGBA32;
+ goto out;
+ }
+out:
+ return format;
+}
+
+/**
+ * gcm_utils_image_convert:
+ **/
+gboolean
+gcm_utils_image_convert (GtkImage *image,
+ CdIcc *input,
+ CdIcc *abstract,
+ CdIcc *output,
+ GError **error)
+{
+ CdPixelFormat pixel_format;
+ CdTransform *transform;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *original_pixbuf;
+ gboolean ret = TRUE;
+ guchar *data;
+
+ /* get pixbuf */
+ pixbuf = gtk_image_get_pixbuf (image);
+ if (pixbuf == NULL)
+ goto out;
+
+ /* work out the pixel format */
+ pixel_format = gcm_utils_get_pixel_format (pixbuf);
+ if (pixel_format == CD_PIXEL_FORMAT_UNKNOWN) {
+ ret = FALSE;
+ g_set_error_literal (error, 1, 0, "format not supported");
+ goto out;
+ }
+
+ /* get a copy of the original image, *not* a ref */
+ original_pixbuf = g_object_get_data (G_OBJECT (pixbuf), "GcmImageOld");
+ if (original_pixbuf == NULL) {
+ data = g_memdup (gdk_pixbuf_get_pixels (pixbuf),
+ gdk_pixbuf_get_bits_per_sample (pixbuf) *
+ gdk_pixbuf_get_rowstride (pixbuf) *
+ gdk_pixbuf_get_height (pixbuf) / 8);
+ original_pixbuf = gdk_pixbuf_new_from_data (data,
+ gdk_pixbuf_get_colorspace (pixbuf),
+ gdk_pixbuf_get_has_alpha (pixbuf),
+ gdk_pixbuf_get_bits_per_sample (pixbuf),
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_rowstride (pixbuf),
+ (GdkPixbufDestroyNotify) g_free, NULL);
+ g_object_set_data_full (G_OBJECT (pixbuf), "GcmImageOld",
+ original_pixbuf,
+ (GDestroyNotify) g_object_unref);
+ }
+
+ /* convert in-place */
+ transform = cd_transform_new ();
+ cd_transform_set_input_icc (transform, input);
+ cd_transform_set_abstract_icc (transform, abstract);
+ cd_transform_set_output_icc (transform, output);
+ cd_transform_set_rendering_intent (transform, CD_RENDERING_INTENT_PERCEPTUAL);
+ cd_transform_set_input_pixel_format (transform, pixel_format);
+ cd_transform_set_output_pixel_format (transform, pixel_format);
+ ret = cd_transform_process (transform,
+ gdk_pixbuf_get_pixels (original_pixbuf),
+ gdk_pixbuf_get_pixels (pixbuf),
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_rowstride (pixbuf),
+ NULL,
+ error);
+ if (!ret)
+ goto out;
+
+ /* refresh */
+ g_object_ref (pixbuf);
+ gtk_image_set_from_pixbuf (image, pixbuf);
+ g_object_unref (pixbuf);
+out:
+ if (transform != NULL)
+ g_object_unref (transform);
+ return ret;
+}
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 0d62962..08cd760 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -47,6 +47,11 @@ gboolean gcm_utils_install_package (const gchar *package_name,
GtkWindow *window);
gchar *gcm_utils_linkify (const gchar *text);
const gchar *cd_colorspace_to_localised_string (CdColorspace colorspace);
+gboolean gcm_utils_image_convert (GtkImage *image,
+ CdIcc *input,
+ CdIcc *abstract,
+ CdIcc *output,
+ GError **error);
#endif /* __GCM_UTILS_H */
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index dd8e5f7..feb2ba8 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -33,7 +33,6 @@
#include "gcm-cell-renderer-profile-text.h"
#include "gcm-cell-renderer-color.h"
#include "gcm-cie-widget.h"
-#include "gcm-image.h"
#include "gcm-trc-widget.h"
#include "gcm-utils.h"
#include "gcm-debug.h"
@@ -995,7 +994,8 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
guint size;
guint temperature;
guint filesize;
- gboolean show_section = FALSE;
+ gboolean show_section_to = FALSE;
+ gboolean show_section_from = FALSE;
GError *error = NULL;
gchar **warnings;
guint i;
@@ -1019,25 +1019,24 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
g_error_free (error);
goto out;
}
+
+ /* convert the image if required */
if (cd_profile_get_colorspace (profile) == CD_COLORSPACE_RGB &&
cd_profile_get_kind (profile) != CD_PROFILE_KIND_NAMED_COLOR) {
- gcm_image_set_input_profile (GCM_IMAGE(viewer->preview_widget_input), icc);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_input), NULL);
- gcm_image_set_output_profile (GCM_IMAGE(viewer->preview_widget_output), icc);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_output), NULL);
- show_section = TRUE;
+ show_section_to = TRUE;
+ show_section_from = TRUE;
+ /* profile -> sRGB */
+ gcm_utils_image_convert (GTK_IMAGE (viewer->preview_widget_input),
+ icc, NULL, NULL, NULL);
+ /* sRGB -> profile */
+ gcm_utils_image_convert (GTK_IMAGE (viewer->preview_widget_output),
+ NULL, NULL, icc, NULL);
} else if (cd_profile_get_colorspace (profile) == CD_COLORSPACE_LAB &&
cd_profile_get_kind (profile) != CD_PROFILE_KIND_NAMED_COLOR) {
- gcm_image_set_input_profile (GCM_IMAGE(viewer->preview_widget_input), NULL);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_input), icc);
- gcm_image_set_output_profile (GCM_IMAGE(viewer->preview_widget_output), NULL);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_output), icc);
- show_section = TRUE;
- } else {
- gcm_image_set_input_profile (GCM_IMAGE(viewer->preview_widget_input), NULL);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_input), NULL);
- gcm_image_set_output_profile (GCM_IMAGE(viewer->preview_widget_output), NULL);
- gcm_image_set_abstract_profile (GCM_IMAGE(viewer->preview_widget_output), NULL);
+ /* sRGB -> profile -> sRGB */
+ gcm_utils_image_convert (GTK_IMAGE (viewer->preview_widget_input),
+ NULL, icc, NULL, NULL);
+ show_section_to = TRUE;
}
/* setup cie widget */
@@ -1255,9 +1254,9 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
/* should we show the image previews at all */
widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_to_srgb"));
- gtk_widget_set_visible (widget, show_section);
+ gtk_widget_set_visible (widget, show_section_to);
widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_from_srgb"));
- gtk_widget_set_visible (widget, show_section);
+ gtk_widget_set_visible (widget, show_section_from);
out:
if (icc != NULL)
@@ -1669,14 +1668,14 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
gtk_box_reorder_child (GTK_BOX(widget), viewer->vcgt_widget, 0);
/* use preview input */
- viewer->preview_widget_input = GTK_WIDGET (gcm_image_new ());
+ viewer->preview_widget_input = GTK_WIDGET (gtk_image_new ());
widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_preview_input"));
gtk_box_pack_end (GTK_BOX(widget), viewer->preview_widget_input, FALSE, FALSE, 0);
gcm_viewer_set_example_image (viewer, GTK_IMAGE (viewer->preview_widget_input));
gtk_widget_set_visible (viewer->preview_widget_input, TRUE);
/* use preview output */
- viewer->preview_widget_output = GTK_WIDGET (gcm_image_new ());
+ viewer->preview_widget_output = GTK_WIDGET (gtk_image_new ());
widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_preview_output"));
gtk_box_pack_end (GTK_BOX(widget), viewer->preview_widget_output, FALSE, FALSE, 0);
gcm_viewer_set_example_image (viewer, GTK_IMAGE (viewer->preview_widget_output));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]