18#include <gtkmm/adjustment.h>
19#include <gtkmm/spinbutton.h>
21#include <glib/gstdio.h>
40 std::unique_ptr<Magick::Image>
image;
47 friend class ImageMagick;
49 void readImage(
char const *xlink,
char const *
id, Magick::Image &
image);
51 std::vector<ImageInfo> images;
57 :
Inkscape::Extension::Implementation::ImplementationDocumentCache(
desktop)
60 images.reserve(boost::distance(selected_item_list));
63 for (
auto item : selected_item_list) {
65 if (strcmp(
node->
name(),
"image") != 0 && strcmp(
node->
name(),
"svg:image") != 0) {
71 .image = std::make_unique<Magick::Image>(),
75 readImage(xlink,
node->
attribute(
"id"), *images.back().image);
79void ImageMagickDocCache::readImage(
const char *xlink,
const char *
id, Magick::Image &
image)
82 gchar *search = g_strndup(xlink, 30);
83 if (strstr(search,
"base64") != (
char*)NULL) {
85 const char* pureBase64 = strstr(xlink,
"base64") + 7;
87 blob.base64(pureBase64);
90 }
catch (Magick::Exception &error_) {
91 g_warning(
"ImageMagick could not read '%s'\nDetails: %s",
id, error_.what());
95 if (strncmp (xlink,
"file:", 5) == 0) {
96 path = g_filename_from_uri(xlink, NULL, NULL);
98 path = g_strdup(xlink);
102 }
catch (Magick::Exception &error_) {
103 g_warning(
"ImageMagick could not read '%s' from '%s'\nDetails: %s",
id, path, error_.what());
118 return new ImageMagickDocCache(
desktop);
124 refreshParameters(module);
125 ImageMagickDocCache * dc =
dynamic_cast<ImageMagickDocCache *
>(docCache);
129 unsigned constexpr b64_line_length = 76;
132 for (
auto &
image : dc->images) {
133 Magick::Image effected_image = *
image.image;
134 applyEffect(&effected_image);
138 postEffect(&effected_image,
image.item);
140 auto blob = std::make_unique<Magick::Blob>();
141 effected_image.write(blob.get());
143 std::string base64_string = blob->base64();
144 for (
size_t newline_pos = b64_line_length;
145 newline_pos < base64_string.length();
146 newline_pos += b64_line_length + 1) {
147 base64_string.insert(newline_pos,
"\n");
149 image.cache =
"data:image/" + effected_image.magick() +
";base64, \n" + base64_string;
152 image.node->removeAttribute(
"sodipodi:absref");
154 }
catch (Magick::Exception &error) {
155 std::cerr <<
"ImageMagick effect exception:" << error.what() << std::endl;
173 if (!selected.empty()) {
174 first_select = (selected.front())->getRepr();
176 return module->autogui(current_document, first_select, changeSignal);
Effects are extensions that take a document and do something to it in place.
The object that is the basis for the Extension system.
A cache for the document and this implementation.
SPDesktop const * desktop()
SPItemRange items()
Returns a range of selected SPItems.
Interface for refcounted XML nodes.
virtual char const * name() const =0
Get the name of the element node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
To do: update description of desktop.
Inkscape::Selection * getSelection() const
Typed SVG document implementation.
Base class for visual SVG elements.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
Editable view implementation.
std::unique_ptr< Magick::Image > image
Inkscape::XML::Node * node
Helper class to stream background task notifications as a series of messages.
void setHrefAttribute(XML::Node &node, Util::const_char_ptr value)
If the 'href' attribute already exists for the given node, then set a new value for it.
std::pair< char const *, char const * > getHrefAttribute(XML::Node const &node)
Get the 'href' or 'xlink:href' (fallback) attribute from an XML node.