summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2013-09-14 01:59:43 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2013-09-14 01:59:43 +0000
commit35dc2e5a640375d51119f2051a240454b5f5b8c8 (patch)
tree2b35e5a1068a675c9c27cb13eaec598410a9b787 /src/extension
parentFix serious bug in recent GdkPixbuf / Cairo interop rework (diff)
downloadinkscape-35dc2e5a640375d51119f2051a240454b5f5b8c8.tar.gz
inkscape-35dc2e5a640375d51119f2051a240454b5f5b8c8.zip
Do not recompress images when embedding and generating PDFs.
Fixes blocker bug #871563. Fixed bugs: - https://launchpad.net/bugs/871563 (bzr r12516)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/internal/gdkpixbuf-input.cpp81
-rw-r--r--src/extension/internal/image-resolution.cpp18
2 files changed, 32 insertions, 67 deletions
diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index 994258ccc..117c2fe39 100644
--- a/src/extension/internal/gdkpixbuf-input.cpp
+++ b/src/extension/internal/gdkpixbuf-input.cpp
@@ -19,23 +19,18 @@
namespace Inkscape {
namespace IO {
-GdkPixbuf* pixbuf_new_from_file( char const *utf8name, GError **error );
+// this is defined in sp-image.cpp
+GdkPixbuf* pixbuf_new_from_file(char const *filename, time_t &modTime, gchar*& pixPath);
}
namespace Extension {
namespace Internal {
-static std::set<Glib::ustring> create_lossy_set()
-{
- std::set<Glib::ustring> lossy;
- lossy.insert(".jpg");
- lossy.insert(".jpeg");
- return lossy;
-}
-
SPDocument *
GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
{
+ // determine whether the image should be embedded
+ // TODO: this logic seems very wrong
bool embed = false;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Glib::ustring attr = prefs->getString("/dialogs/import/link");
@@ -52,27 +47,14 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
}
SPDocument *doc = NULL;
- GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
- static std::set<Glib::ustring> lossy = create_lossy_set();
-
- if (pb) { /* We are readable */
- // TODO revisit: bool is_lossy;
- Glib::ustring mime_type, ext;
- Glib::ustring u = uri;
- std::size_t dotpos = u.rfind('.');
- if (dotpos != Glib::ustring::npos) {
- ext = u.substr(dotpos, Glib::ustring::npos);
- }
+ gchar *pixpath = NULL;
+ time_t dummy;
+ GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file(uri, dummy, pixpath);
- // HACK: replace with something better based on GIO
- if (!ext.empty() && lossy.find(ext) != lossy.end()) {
- // TODO revisit: is_lossy = true;
- mime_type = "image/jpeg";
- } else {
- // TODO revisit: is_lossy = false;
- mime_type = "image/png";
- }
+ // TODO: the pixbuf is created again from the base64-encoded attribute in SPImage.
+ // Find a way to create the pixbuf only once.
+ if (pb) {
doc = SPDocument::createNewDoc(NULL, TRUE, TRUE);
bool saved = DocumentUndo::getUndoSensitive(doc);
DocumentUndo::setUndoSensitive(doc, false); // no need to undo in this temporary document
@@ -85,40 +67,22 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
double xscale = 1;
double yscale = 1;
- gchar const *str = gdk_pixbuf_get_option( pb, "Inkscape::DpiX" );
- if ( str ) {
- gint dpi = atoi(str);
- if ( dpi > 0 && dpi != 72 ) {
- xscale = 72.0 / (double)dpi;
- }
- } else {
- if (!ir && !forcexdpi)
- ir = new ImageResolution(uri);
- if (ir && ir->ok())
- xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi
- else
- xscale = 90.0 / defaultxdpi;
- }
- width *= xscale;
- str = gdk_pixbuf_get_option( pb, "Inkscape::DpiY" );
- if ( str ) {
- gint dpi = atoi(str);
- if ( dpi > 0 && dpi != 72 ) {
- yscale = 72.0 / (double)dpi;
- }
+ if (!ir && !forcexdpi) {
+ ir = new ImageResolution(uri);
+ }
+ if (ir && ir->ok()) {
+ xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi
+ yscale = 900.0 / floor(10.*ir->y() + .5);
} else {
- if (!ir && !forcexdpi)
- ir = new ImageResolution(uri);
- if (ir && ir->ok())
- yscale = 900.0 / floor(10.*ir->y() + .5); // round-off to 0.1 dpi
- else
- yscale = 90.0 / defaultxdpi;
+ xscale = 90.0 / defaultxdpi;
+ yscale = 90.0 / defaultxdpi;
}
+
+ width *= xscale;
height *= yscale;
- if (ir)
- delete ir;
+ delete ir; // deleting NULL is safe
// Create image node
Inkscape::XML::Document *xml_doc = doc->getReprDoc();
@@ -127,7 +91,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
sp_repr_set_svg_double(image_node, "height", height);
if (embed) {
- sp_embed_image(image_node, pb, mime_type);
+ sp_embed_image(image_node, pb);
} else {
// convert filename to uri
gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
@@ -139,6 +103,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
}
}
+ g_object_set_data(G_OBJECT(pb), "cairo_surface", NULL);
g_object_unref(pb);
// Add it to the current layer
diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp
index 3c254a59c..a9d33e831 100644
--- a/src/extension/internal/image-resolution.cpp
+++ b/src/extension/internal/image-resolution.cpp
@@ -14,13 +14,21 @@
#include "image-resolution.h"
#define IR_TRY_PNG 1
+#include <png.h>
+
#ifdef HAVE_EXIF
-#define IR_TRY_EXIF 1
+#include <math.h>
+#include <libexif/exif-data.h>
#endif
+
#define IR_TRY_EXIV 0
+
#ifdef HAVE_JPEG
#define IR_TRY_JFIF 1
+#include <jpeglib.h>
+#include <setjmp.h>
#endif
+
#ifdef WITH_IMAGE_MAGICK
#include <Magick++.h>
#endif
@@ -62,8 +70,6 @@ double ImageResolution::y() const {
#if IR_TRY_PNG
-
-#include <png.h>
static bool haspngheader(FILE *fp) {
unsigned char header[8];
@@ -133,9 +139,6 @@ void ImageResolution::readpng(char const *) {
#if IR_TRY_EXIF
-#include <math.h>
-#include <libexif/exif-data.h>
-
static double exifDouble(ExifEntry *entry, ExifByteOrder byte_order) {
switch (entry->format) {
case EXIF_FORMAT_BYTE: {
@@ -264,9 +267,6 @@ void ImageResolution::readexiv(char const *) {
#if IR_TRY_JFIF
-#include <jpeglib.h>
-#include <setjmp.h>
-
static void irjfif_error_exit(j_common_ptr cinfo) {
longjmp(*(jmp_buf*)cinfo->client_data, 1);
}