static
| 191 | |
| 192 | // static |
| 193 | FileOp* 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 |
nothing calls this directly
no test coverage detected