From: joncruz Date: Mon, 3 Apr 2006 00:00:31 +0000 (+0000) Subject: Initial support of color-profile on X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4eefb060ba4e9d34d04abdb76989376292a6fe9b;p=inkscape.git Initial support of color-profile on --- diff --git a/ChangeLog b/ChangeLog index 78687b960..4b1e3232c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,17 @@ 2005-04-02 Jon A. Cruz * 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 element. + Initial support of color-profile on elements. + +2005-04-02 Jon A. Cruz + + * 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 element. 2005-04-02 Jon A. Cruz diff --git a/src/color-profile-fns.h b/src/color-profile-fns.h index 9c2388ab2..96a7410a9 100644 --- a/src/color-profile-fns.h +++ b/src/color-profile-fns.h @@ -7,8 +7,14 @@ #include #include +#if ENABLE_LCMS +#include +#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()) diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 5f4e8324e..049bd14ec 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -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++ diff --git a/src/color-profile.h b/src/color-profile.h index ea9755164..a6a83ccb5 100644 --- a/src/color-profile.h +++ b/src/color-profile.h @@ -7,7 +7,6 @@ #include #include -#include "color-profile-fns.h" #if ENABLE_LCMS #include #endif // ENABLE_LCMS diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 17f969b53..d06db6231 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -36,7 +36,9 @@ #include "io/sys.h" #include - +#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); diff --git a/src/sp-image.h b/src/sp-image.h index 500d9699e..e0546d63d 100644 --- a/src/sp-image.h +++ b/src/sp-image.h @@ -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; };