From: gouldtj Date: Tue, 30 Oct 2007 19:30:04 +0000 (+0000) Subject: r16894@shi: ted | 2007-10-30 09:26:42 -0700 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0ff4eef7ffaeb576f4810bd8677b9383bf660a3b;p=inkscape.git r16894@shi: ted | 2007-10-30 09:26:42 -0700 OH MY GOD IT WORKS!!! --- diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 0dbb32b11..8e33fe64a 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -102,8 +102,8 @@ ExecutionEnv::~ExecutionEnv (void) { void ExecutionEnv::genDocCache (void) { if (_docCache == NULL) { - printf("Gen Doc Cache\n"); - Implementation::ImplementationDocumentCache * _docCache = _effect->get_imp()->newDocCache(_effect, _doc); + // printf("Gen Doc Cache\n"); + _docCache = _effect->get_imp()->newDocCache(_effect, _doc); } return; } @@ -111,7 +111,7 @@ ExecutionEnv::genDocCache (void) { void ExecutionEnv::killDocCache (void) { if (_docCache != NULL) { - printf("Killed Doc Cache\n"); + // printf("Killed Doc Cache\n"); delete _docCache; _docCache = NULL; } @@ -287,6 +287,13 @@ ExecutionEnv::run (void) { return; } +/** \brief Set the state of live preview + \param state The current state + + This will cancel the document preview and and configure + whether we should be waiting on the human. It will also + clear the document cache. +*/ void ExecutionEnv::livePreview (bool state) { _mainloop->quit(); diff --git a/src/extension/implementation/implementation.h b/src/extension/implementation/implementation.h index ad1bbf1d2..f2855a168 100644 --- a/src/extension/implementation/implementation.h +++ b/src/extension/implementation/implementation.h @@ -56,7 +56,7 @@ public: virtual bool load(Inkscape::Extension::Extension *module); virtual void unload(Inkscape::Extension::Extension *module); - ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * doc); + virtual ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * doc); /** Verify any dependencies. */ virtual bool check(Inkscape::Extension::Extension *module); diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index ddb7a0145..9b6ed5390 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -33,34 +33,82 @@ namespace Extension { namespace Internal { namespace Bitmap { -bool -ImageMagick::load(Inkscape::Extension::Extension *module) -{ - _loaded = FALSE; +class ImageMagickDocCache: public Inkscape::Extension::Implementation::ImplementationDocumentCache { + friend class ImageMagick; +private: + void readImage(char const *xlink, Magick::Image *image); +protected: + Inkscape::XML::Node** _nodes; - return TRUE; -} + Magick::Image** _images; + int _imageCount; + char** _caches; + unsigned* _cacheLengths; + + const char** _originals; +public: + ImageMagickDocCache(Inkscape::UI::View::View * view); + ~ImageMagickDocCache ( ); +}; + +ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : + Inkscape::Extension::Implementation::ImplementationDocumentCache(view), + _nodes(NULL), + _images(NULL), + _imageCount(0), + _caches(NULL), + _cacheLengths(NULL), + _originals(NULL) +{ + SPDesktop *desktop = (SPDesktop*)view; + const GSList *selectedReprList = desktop->selection->reprList(); + int selectCount = g_slist_length((GSList *)selectedReprList); + + // Init the data-holders + _nodes = new Inkscape::XML::Node*[selectCount]; + _originals = new const char*[selectCount]; + _caches = new char*[selectCount]; + _cacheLengths = new unsigned int[selectCount]; + _images = new Magick::Image*[selectCount]; + _imageCount = 0; + + // Loop through selected nodes + for (; selectedReprList != NULL; selectedReprList = g_slist_next(selectedReprList)) + { + Inkscape::XML::Node *node = reinterpret_cast(selectedReprList->data); + if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) + { + _nodes[_imageCount] = node; + char const *xlink = node->attribute("xlink:href"); -/* -void -ImageMagick::commitDocument(void) { - _loaded = FALSE; -} + _originals[_imageCount] = xlink; + _caches[_imageCount] = ""; + _cacheLengths[_imageCount] = 0; + _images[_imageCount] = new Magick::Image(); + readImage(xlink, _images[_imageCount]); -void -ImageMagick::cancelDocument(void) { - for (int i = 0; i < _imageCount; i++) { - _nodes[i]->setAttribute("xlink:href", _originals[i], true); - - if (strlen(_originals[i]) < 256) - _nodes[i]->setAttribute("sodipodi:absref", _originals[i], true); + _imageCount++; + } } - - _loaded = FALSE; -}*/ +} + +ImageMagickDocCache::~ImageMagickDocCache ( ) { + if (_nodes) + delete _nodes; + if (_originals) + delete _originals; + if (_caches) + delete _caches; + if (_cacheLengths) + delete _cacheLengths; + if (_images) + delete _images; + + return; +} void -ImageMagick::readImage(const char *xlink, Magick::Image *image) +ImageMagickDocCache::readImage(const char *xlink, Magick::Image *image) { // Find if the xlink:href is base64 data, i.e. if the image is embedded char *search = (char *) g_strndup(xlink, 30); @@ -76,53 +124,36 @@ ImageMagick::readImage(const char *xlink, Magick::Image *image) } } +bool +ImageMagick::load(Inkscape::Extension::Extension *module) +{ + return true; +} + +Inkscape::Extension::Implementation::ImplementationDocumentCache * +ImageMagick::newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view) { + return new ImageMagickDocCache(view); +} + void ImageMagick::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * docCache) { refreshParameters(module); - _loaded = FALSE; - - if (!_loaded) - { - SPDesktop *desktop = (SPDesktop*)document; - const GSList *selectedReprList = desktop->selection->reprList(); - int selectCount = g_slist_length((GSList *)selectedReprList); - - // Init the data-holders - _nodes = new Inkscape::XML::Node*[selectCount]; - _originals = new const char*[selectCount]; - _caches = new char*[selectCount]; - _cacheLengths = new unsigned[selectCount]; - _images = new Magick::Image*[selectCount]; - _imageCount = 0; - - // Loop through selected nodes - for (; selectedReprList != NULL; selectedReprList = g_slist_next(selectedReprList)) - { - Inkscape::XML::Node *node = reinterpret_cast(selectedReprList->data); - if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) - { - _nodes[_imageCount] = node; - char const *xlink = node->attribute("xlink:href"); - - _originals[_imageCount] = xlink; - _caches[_imageCount] = ""; - _cacheLengths[_imageCount] = 0; - _images[_imageCount] = new Magick::Image(); - readImage(xlink, _images[_imageCount]); - - _imageCount++; - } - } - _loaded = 1; + if (docCache == NULL) { // should never happen + docCache = newDocCache(module, document); } - - for (int i = 0; i < _imageCount; i++) + ImageMagickDocCache * dc = dynamic_cast(docCache); + if (dc == NULL) { // should really never happen + printf("AHHHHHHHHH!!!!!"); + exit(1); + } + + for (int i = 0; i < dc->_imageCount; i++) { try { - Magick::Image effectedImage = *_images[i]; // make a copy + Magick::Image effectedImage = *dc->_images[i]; // make a copy applyEffect(&effectedImage); Magick::Blob *blob = new Magick::Blob(); @@ -133,11 +164,11 @@ ImageMagick::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::Vi const char *raw_i = raw_string.c_str(); unsigned new_len = (int)(raw_len * (77.0 / 76.0) + 100); - if (new_len > _cacheLengths[i]) { - _cacheLengths[i] = (int)(new_len * 1.2); - _caches[i] = new char[_cacheLengths[i]]; + if (new_len > dc->_cacheLengths[i]) { + dc->_cacheLengths[i] = (int)(new_len * 1.2); + dc->_caches[i] = new char[dc->_cacheLengths[i]]; } - char *formatted_i = _caches[i]; + char *formatted_i = dc->_caches[i]; const char *src; for (src = "data:image/"; *src; ) @@ -160,15 +191,16 @@ ImageMagick::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::Vi } *formatted_i = '\0'; - _nodes[i]->setAttribute("xlink:href", _caches[i], true); - _nodes[i]->setAttribute("sodipodi:absref", NULL, true); + dc->_nodes[i]->setAttribute("xlink:href", dc->_caches[i], true); + dc->_nodes[i]->setAttribute("sodipodi:absref", NULL, true); } catch (Magick::Exception &error_) { printf("Caught exception: %s \n", error_.what()); } - while(Gtk::Main::events_pending()) + while(Gtk::Main::events_pending()) { Gtk::Main::iteration(); + } } } diff --git a/src/extension/internal/bitmap/imagemagick.h b/src/extension/internal/bitmap/imagemagick.h index 1fb79f826..4a8a318fc 100644 --- a/src/extension/internal/bitmap/imagemagick.h +++ b/src/extension/internal/bitmap/imagemagick.h @@ -18,36 +18,16 @@ namespace Extension { namespace Internal { namespace Bitmap { -class ImageMagickDocCache: public Inkscape::Extension::Implementation::ImplementationDocumentCache { -public: - ImageMagickDocCache(Inkscape::UI::View::View * view) : Inkscape::Extension::Implementation::ImplementationDocumentCache(view) { }; - ~ImageMagickDocCache ( ) { }; -}; - class ImageMagick : public Inkscape::Extension::Implementation::Implementation { - -private: - bool _loaded; - - Inkscape::XML::Node** _nodes; - - Magick::Image** _images; - int _imageCount; - char** _caches; - unsigned* _cacheLengths; - - const char** _originals; public: + /* Functions to be implemented by subclasses */ virtual void applyEffect(Magick::Image *image) { }; virtual void refreshParameters(Inkscape::Extension::Effect *module) { }; - bool load(Inkscape::Extension::Extension *module); - - /*void commitDocument(void);*/ - /*void cancelDocument(void);*/ - void readImage(char const *xlink, Magick::Image *image); + /* Functions implemented from ::Implementation */ + bool load(Inkscape::Extension::Extension *module); + Inkscape::Extension::Implementation::ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * doc); void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * docCache); - Gtk::Widget* prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, sigc::signal * changeSignal, Inkscape::Extension::Implementation::ImplementationDocumentCache * docCache); };