summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7ad9592)
raw | patch | inline | side by side (parent: 7ad9592)
author | joncruz <joncruz@users.sourceforge.net> | |
Mon, 3 Apr 2006 00:00:31 +0000 (00:00 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Mon, 3 Apr 2006 00:00:31 +0000 (00:00 +0000) |
diff --git a/ChangeLog b/ChangeLog
index 78687b96053e0f40579f6f419c68bf97e199235b..4b1e3232cfd76dd12c36b7d90606b24be0a58442 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
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)
--- a/src/color-profile-fns.h
+++ b/src/color-profile-fns.h
#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
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 5f4e8324e16189cdb5906bbc9bb69a6cc23ac98a..049bd14ecf7791cfc8bbb7474cecc3d279f96fc5 100644 (file)
--- a/src/color-profile.cpp
+++ b/src/color-profile.cpp
#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 ea9755164de818c1b013647530878cfda710202e..a6a83ccb57d77664ef77764cac57766ef2e81299 100644 (file)
--- a/src/color-profile.h
+++ b/src/color-profile.h
#include <glib/gtypes.h>
#include <sp-object.h>
-#include "color-profile-fns.h"
#if ENABLE_LCMS
#include <lcms.h>
#endif // ENABLE_LCMS
diff --git a/src/sp-image.cpp b/src/sp-image.cpp
index 17f969b537c6f9d8229a76f719d7de910b6a5c1d..d06db6231bccfb50990272f127257e7835b5ffcd 100644 (file)
--- a/src/sp-image.cpp
+++ b/src/sp-image.cpp
#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);
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);
}
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);
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;
}
}
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 500d9699eb1e52caa477bf90f28fce11e08391a1..e0546d63d5057365374d855e0a43794204143e53 100644 (file)
--- a/src/sp-image.h
+++ b/src/sp-image.h
double viewx, viewy, viewwidth, viewheight;
gchar *href;
+#if ENABLE_LCMS
+ gchar *color_profile;
+#endif // ENABLE_LCMS
GdkPixbuf *pixbuf;
};