MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / createSaveDocumentOperation

Method createSaveDocumentOperation

src/app/file/file.cpp:193–443  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

191
192// static
193FileOp* FileOp::createSaveDocumentOperation(const Context* context,
194 const Document* document,
195 const char* filename,
196 const char* fn_format_arg)
197{
198 std::unique_ptr<FileOp> fop(new FileOp(FileOpSave, const_cast<Context*>(context)));
199
200 // Document to save
201 fop->m_document = const_cast<Document*>(document);
202
203 // Get the extension of the filename (in lower case)
204 std::string extension = base::string_to_lower(base::get_file_extension(filename));
205
206 LOG("Saving document \"%s\" (%s)\n", filename, extension.c_str());
207
208 // Get the format through the extension of the filename
209 fop->m_format = FileFormatsManager::instance()
210 ->getFileFormatByExtension(extension.c_str());
211
212 if (!fop->m_format ||
213 !fop->m_format->support(FILE_SUPPORT_SAVE)) {
214 fop->setError("%s can't save \"%s\" files\n", PACKAGE, extension.c_str());
215 return fop.release();
216 }
217
218 // Warnings
219 std::string warnings;
220 bool fatal = false;
221
222 // Check image type support
223 // TODO add support to automatically convert the image to a supported format
224 switch (fop->m_document->sprite()->pixelFormat()) {
225
226 case IMAGE_RGB:
227 if (!(fop->m_format->support(FILE_SUPPORT_RGB))) {
228 warnings += "<<- RGB format";
229 fatal = true;
230 }
231
232 if (!(fop->m_format->support(FILE_SUPPORT_RGBA)) &&
233 fop->m_document->sprite()->needAlpha()) {
234
235 warnings += "<<- Alpha channel";
236 }
237 break;
238
239 case IMAGE_GRAYSCALE:
240 if (!(fop->m_format->support(FILE_SUPPORT_GRAY))) {
241 warnings += "<<- Grayscale format";
242 fatal = true;
243 }
244 if (!(fop->m_format->support(FILE_SUPPORT_GRAYA)) &&
245 fop->m_document->sprite()->needAlpha()) {
246
247 warnings += "<<- Alpha channel";
248 }
249 break;
250

Callers

nothing calls this directly

Calls 15

string_to_lowerFunction · 0.85
get_file_extensionFunction · 0.85
LOGFunction · 0.85
instanceFunction · 0.85
rgba_getaFunction · 0.85
filename_formatterFunction · 0.85
split_filenameFunction · 0.85
set_frame_formatFunction · 0.85
add_frame_formatFunction · 0.85
get_file_nameFunction · 0.85
setErrorMethod · 0.80

Tested by

no test coverage detected