diff --git a/src/common/utilities/load_save.cpp b/src/common/utilities/load_save.cpp index 90faed778..b20d2b887 100644 --- a/src/common/utilities/load_save.cpp +++ b/src/common/utilities/load_save.cpp @@ -185,7 +185,10 @@ void reloadMesh( loadMesh(filename, ioPlugin, prePar, meshList, masks, cb); } -void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg::CallBackPos* cb) +QImage loadImage( + const QString& filename, + GLLogStream* log, + vcg::CallBackPos* cb) { QFileInfo fi(filename); QString extension = fi.suffix(); @@ -194,15 +197,40 @@ void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg: if (ioPlugin == nullptr) throw MLException( - "Raster " + filename + " cannot be opened. Your MeshLab version " + "Image " + filename + " cannot be opened. Your MeshLab version " "has not plugin to read " + extension + " file format."); ioPlugin->setLog(log); - QImage loadedImage = ioPlugin->openImage(extension, filename, cb); + return ioPlugin->openImage(extension, filename, cb); +} + +void saveImage( + const QString& filename, + const QImage& image, + GLLogStream* log, + vcg::CallBackPos* cb) +{ + QFileInfo fi(filename); + QString extension = fi.suffix(); + PluginManager& pm = meshlab::pluginManagerInstance(); + IOPlugin *ioPlugin = pm.outputImagePlugin(extension); + + if (ioPlugin == nullptr) + throw MLException( + "Image " + filename + " cannot be saved. Your MeshLab version " + "has not plugin to save " + extension + " file format."); + + ioPlugin->setLog(log); + ioPlugin->saveImage(extension, filename, image, cb); +} + +void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg::CallBackPos* cb) +{ + QImage loadedImage = loadImage(filename, log, cb); rm.setLabel(filename); rm.addPlane(new RasterPlane(loadedImage, filename, RasterPlane::RGBA)); - // Read the JPEG file into a buffer + // Read the file into a buffer FILE *fp = fopen(qUtf8Printable(filename), "rb"); if (!fp) { QString errorMsgFormat = "Exif Parsing: Unable to open file:\n\"%1\"\n\nError details: file %1 is not readable."; @@ -225,7 +253,7 @@ void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg: int code = ImageInfo.parseFrom(buf, fsize); delete[] buf; if (!code) { - ioPlugin->log(GLLogStream::FILTER, "Warning: unable to parse exif for file %s", qPrintable(filename)); + log->log(GLLogStream::FILTER, "Warning: unable to parse exif for file " + filename); } if (code && ImageInfo.FocalLengthIn35mm==0.0f) diff --git a/src/common/utilities/load_save.h b/src/common/utilities/load_save.h index 6c52cca4b..3eab98aa5 100644 --- a/src/common/utilities/load_save.h +++ b/src/common/utilities/load_save.h @@ -53,6 +53,17 @@ void reloadMesh( GLLogStream* log = nullptr, vcg::CallBackPos* cb = nullptr); +QImage loadImage( + const QString& filename, + GLLogStream* log = nullptr, + vcg::CallBackPos *cb = nullptr); + +void saveImage( + const QString& filename, + const QImage& image, + GLLogStream* log = nullptr, + vcg::CallBackPos* cb = nullptr); + void loadRaster( const QString& filename, RasterModel& rm,