Code

Initial support of color-profile on <image>
authorjoncruz <joncruz@users.sourceforge.net>
Mon, 3 Apr 2006 00:00:31 +0000 (00:00 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Mon, 3 Apr 2006 00:00:31 +0000 (00:00 +0000)
ChangeLog
src/color-profile-fns.h
src/color-profile.cpp
src/color-profile.h
src/sp-image.cpp
src/sp-image.h

index 78687b96053e0f40579f6f419c68bf97e199235b..4b1e3232cfd76dd12c36b7d90606b24be0a58442 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,17 @@
 2005-04-02  Jon A. Cruz  <jon@joncruz.org>
 
        * src/color-profile.h, src/color-profile.cpp,
-        src/color-profile-fns.h, src/Makefile_insert, src/attributes.cpp,
-        src/attributes.h, src/sp-object-repr.cpp:
+         src/color-profile-fns.h, src/sp-image.h, src/sp-image.cpp:
 
-        Adding support for <color-profile> element.
+         Initial support of color-profile on <image> elements.
+
+2005-04-02  Jon A. Cruz  <jon@joncruz.org>
+
+       * src/color-profile.h, src/color-profile.cpp,
+         src/color-profile-fns.h, src/Makefile_insert, src/attributes.cpp,
+         src/attributes.h, src/sp-object-repr.cpp:
+
+         Adding support for <color-profile> element.
 
 2005-04-02  Jon A. Cruz  <jon@joncruz.org>
 
index 9c2388ab20fec9f04416f35d463d454280931f97..96a7410a9de0fe7c4f8d697467a45d98eece9b0e 100644 (file)
@@ -7,8 +7,14 @@
 
 #include <glib-object.h>
 #include <glib/gtypes.h>
+#if ENABLE_LCMS
+#include <lcms.h>
+#endif // ENABLE_LCMS
+
+class SPDocument;
 
 namespace Inkscape {
+
 namespace XML {
 class Node;
 } // namespace XML
@@ -17,6 +23,12 @@ class ColorProfile;
 
 GType colorprofile_get_type();
 
+#if ENABLE_LCMS
+
+cmsHPROFILE colorprofile_get_handle( SPDocument* document, gchar* const name );
+
+#endif
+
 } // namespace Inkscape
 
 #define COLORPROFILE_TYPE (Inkscape::colorprofile_get_type())
index 5f4e8324e16189cdb5906bbc9bb69a6cc23ac98a..049bd14ecf7791cfc8bbb7474cecc3d279f96fc5 100644 (file)
@@ -4,6 +4,7 @@
 #include "color-profile.h"
 #include "color-profile-fns.h"
 #include "attributes.h"
+#include "document.h"
 
 using Inkscape::ColorProfile;
 using Inkscape::ColorProfileClass;
@@ -207,6 +208,51 @@ static Inkscape::XML::Node* colorprofile_write( SPObject *object, Inkscape::XML:
 }
 
 
+#if ENABLE_LCMS
+
+
+static SPObject* bruteFind( SPObject* curr, gchar* const name )
+{
+    SPObject* result = 0;
+
+    if ( curr ) {
+        if ( IS_COLORPROFILE(curr) ) {
+            ColorProfile* prof = COLORPROFILE(curr);
+            if ( prof ) {
+                if ( prof->name && (strcmp(prof->name, name) == 0) ) {
+                    result = curr;
+                }
+            }
+        } else {
+            if ( curr->hasChildren() ) {
+                SPObject* child = curr->firstChild();
+                while ( child && !result ) {
+                    result = bruteFind( child, name );
+                    if ( !result ) {
+                        child = child->next;
+                    }
+                };
+            }
+        }
+    }
+
+    return result;
+}
+
+cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, gchar* const name )
+{
+    cmsHPROFILE prof = 0;
+
+    SPObject* root = SP_DOCUMENT_ROOT(document);
+    SPObject* thing = bruteFind( root, name );
+    if ( thing ) {
+        prof = COLORPROFILE(thing)->profHandle;
+    }
+
+    return prof;
+}
+#endif // ENABLE_LCMS
+
 /*
   Local Variables:
   mode:c++
index ea9755164de818c1b013647530878cfda710202e..a6a83ccb57d77664ef77764cac57766ef2e81299 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <glib/gtypes.h>
 #include <sp-object.h>
-#include "color-profile-fns.h"
 #if ENABLE_LCMS
 #include <lcms.h>
 #endif // ENABLE_LCMS
index 17f969b537c6f9d8229a76f719d7de910b6a5c1d..d06db6231bccfb50990272f127257e7835b5ffcd 100644 (file)
@@ -36,7 +36,9 @@
 
 #include "io/sys.h"
 #include <png.h>
-
+#if ENABLE_LCMS
+#include "color-profile-fns.h"
+#endif // ENABLE_LCMS
 /*
  * SPImage
  */
@@ -478,6 +480,7 @@ sp_image_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *rep
        sp_object_read_attr (object, "width");
        sp_object_read_attr (object, "height");
        sp_object_read_attr (object, "preserveAspectRatio");
+       sp_object_read_attr (object, "color-profile");
 
        /* Register */
        sp_document_add_resource (document, "image", object);
@@ -505,6 +508,13 @@ sp_image_release (SPObject *object)
                image->pixbuf = NULL;
        }
 
+#if ENABLE_LCMS
+       if (image->color_profile) {
+               g_free (image->color_profile);
+               image->color_profile = NULL;
+       }
+#endif ENABLE_LCMS
+
        if (((SPObjectClass *) parent_class)->release)
                ((SPObjectClass *) parent_class)->release (object);
 }
@@ -608,6 +618,16 @@ sp_image_set (SPObject *object, unsigned int key, const gchar *value)
                        image->aspect_clip = clip;
                }
                break;
+#if ENABLE_LCMS
+        case SP_PROP_COLOR_PROFILE:
+                if ( image->color_profile ) {
+                    g_free (image->color_profile);
+                }
+                image->color_profile = (value) ? g_strdup (value) : NULL;
+                // TODO check on this HREF_MODIFIED flag
+                object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_IMAGE_HREF_MODIFIED_FLAG);
+                break;
+#endif // ENABLE_LCMS
        default:
                if (((SPObjectClass *) (parent_class))->set)
                        ((SPObjectClass *) (parent_class))->set (object, key, value);
@@ -635,6 +655,38 @@ sp_image_update (SPObject *object, SPCtx *ctx, unsigned int flags)
                        pixbuf = sp_image_repr_read_image (object->repr);
                        if (pixbuf) {
                                pixbuf = sp_image_pixbuf_force_rgba (pixbuf);
+// BLIP
+#if ENABLE_LCMS
+                if ( image->color_profile )
+                {
+                    int imagewidth = gdk_pixbuf_get_width( pixbuf );
+                    int imageheight = gdk_pixbuf_get_height( pixbuf );
+                    int rowstride = gdk_pixbuf_get_rowstride( pixbuf );
+                    guchar* px = gdk_pixbuf_get_pixels( pixbuf );
+
+                    if ( px ) {
+                        cmsHPROFILE prof = Inkscape::colorprofile_get_handle( SP_OBJECT_DOCUMENT( object ), image->color_profile );
+                        if ( prof ) {
+                            cmsHPROFILE destProf = cmsCreate_sRGBProfile();
+                            cmsHTRANSFORM transf = cmsCreateTransform( prof, 
+                                                                       TYPE_RGBA_8,
+                                                                       destProf,
+                                                                       TYPE_RGBA_8,
+                                                                       INTENT_PERCEPTUAL, 0 );
+                            guchar* currLine = px;
+                            for ( int y = 0; y < imageheight; y++ ) {
+                                // Since the types are the same size, we can do the transformation in-place
+                                cmsDoTransform( transf, currLine, currLine, imagewidth );
+                                currLine += rowstride;
+                            }
+
+                            if ( transf ) {
+                                cmsDeleteTransform( transf );
+                            }
+                        }
+                    }
+                }
+#endif // ENABLE_LCMS
                                image->pixbuf = pixbuf;
                        }
                }
@@ -751,6 +803,9 @@ sp_image_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
        if (image->width._set) sp_repr_set_svg_double(repr, "width", image->width.computed);
        if (image->height._set) sp_repr_set_svg_double(repr, "height", image->height.computed);
        repr->setAttribute("preserveAspectRatio", object->repr->attribute("preserveAspectRatio"));
+#if ENABLE_LCMS
+        if (image->color_profile) repr->setAttribute("color-profile", image->color_profile);
+#endif // ENABLE_LCMS
 
        if (((SPObjectClass *) (parent_class))->write)
                ((SPObjectClass *) (parent_class))->write (object, repr, flags);
index 500d9699eb1e52caa477bf90f28fce11e08391a1..e0546d63d5057365374d855e0a43794204143e53 100644 (file)
@@ -45,6 +45,9 @@ struct SPImage : public SPItem {
        double viewx, viewy, viewwidth, viewheight;
 
        gchar *href;
+#if ENABLE_LCMS
+        gchar *color_profile;
+#endif // ENABLE_LCMS
 
        GdkPixbuf *pixbuf;
 };