// [[Rcpp::export]] Rcpp::RawVector magick_image_write( XPtrImage input, Rcpp::CharacterVector format, Rcpp::IntegerVector quality, Rcpp::IntegerVector depth, Rcpp::CharacterVector density, Rcpp::CharacterVector comment){ if(!input->size()) return Rcpp::RawVector(0); XPtrImage image = copy(input); #if MagickLibVersion >= 0x691 //suppress write warnings see #74 and #116 image->front().quiet(true); #endif if(format.size()) for_each ( image->begin(), image->end(), Magick::magickImage(std::string(format[0]))); if(quality.size()) for_each ( image->begin(), image->end(), Magick::qualityImage(quality[0])); if(depth.size()) for_each ( image->begin(), image->end(), Magick::depthImage(depth[0])); if(density.size()){ for_each ( image->begin(), image->end(), Magick::resolutionUnitsImage(Magick::PixelsPerInchResolution)); for_each ( image->begin(), image->end(), Magick::densityImage(Point(density[0]))); } if(comment.size()) for_each ( image->begin(), image->end(), Magick::commentImage(std::string(comment.at(0)))); Magick::Blob output; writeImages( image->begin(), image->end(), &output ); Rcpp::RawVector res(output.length()); std::memcpy(res.begin(), output.data(), output.length()); return res; }
// [[Rcpp::export]] XPtrImage magick_image_readbin(Rcpp::RawVector x, Rcpp::CharacterVector density, Rcpp::IntegerVector depth, bool strip = false){ XPtrImage image = create(); #if MagickLibVersion >= 0x689 Magick::ReadOptions opts = Magick::ReadOptions(); #if MagickLibVersion >= 0x690 opts.quiet(1); #endif if(density.size()) opts.density(std::string(density.at(0)).c_str()); if(depth.size()) opts.depth(depth.at(0)); Magick::readImages(image.get(), Magick::Blob(x.begin(), x.length()), opts); #else Magick::readImages(image.get(), Magick::Blob(x.begin(), x.length())); #endif if(strip) for_each (image->begin(), image->end(), Magick::stripImage()); return image; }
// [[Rcpp::export]] XPtrImage magick_image_readpath(Rcpp::CharacterVector paths, Rcpp::CharacterVector density, Rcpp::IntegerVector depth, bool strip = false){ XPtrImage image = create(); #if MagickLibVersion >= 0x689 Magick::ReadOptions opts = Magick::ReadOptions(); #if MagickLibVersion >= 0x690 opts.quiet(1); #endif if(density.size()) opts.density(std::string(density.at(0)).c_str()); if(depth.size()) opts.depth(depth.at(0)); for(int i = 0; i < paths.size(); i++) Magick::readImages(image.get(), std::string(paths[i]), opts); #else for(int i = 0; i < paths.size(); i++) Magick::readImages(image.get(), std::string(paths[i])); #endif if(strip) for_each (image->begin(), image->end(), Magick::stripImage()); return image; }