| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_FILE_FILE_FORMAT_H_INCLUDED |
| 9 | #define APP_FILE_FILE_FORMAT_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/file/format_options.h" |
| 13 | #include "base/paths.h" |
| 14 | #include "dio/file_format.h" |
| 15 | |
| 16 | #include <vector> |
| 17 | |
| 18 | #define FILE_SUPPORT_LOAD 0x00000001 |
| 19 | #define FILE_SUPPORT_SAVE 0x00000002 |
| 20 | #define FILE_SUPPORT_RGB 0x00000004 |
| 21 | #define FILE_SUPPORT_RGBA 0x00000008 |
| 22 | #define FILE_SUPPORT_GRAY 0x00000010 |
| 23 | #define FILE_SUPPORT_GRAYA 0x00000020 |
| 24 | #define FILE_SUPPORT_INDEXED 0x00000040 |
| 25 | #define FILE_SUPPORT_LAYERS 0x00000080 |
| 26 | #define FILE_SUPPORT_FRAMES 0x00000100 |
| 27 | #define FILE_SUPPORT_PALETTES 0x00000200 |
| 28 | #define FILE_SUPPORT_SEQUENCES 0x00000400 |
| 29 | #define FILE_SUPPORT_GET_FORMAT_OPTIONS 0x00000800 |
| 30 | #define FILE_SUPPORT_TAGS 0x00001000 |
| 31 | #define FILE_SUPPORT_BIG_PALETTES 0x00002000 // Palettes w/more than 256 colors |
| 32 | #define FILE_SUPPORT_PALETTE_WITH_ALPHA 0x00004000 |
| 33 | #define FILE_ENCODE_ABSTRACT_IMAGE 0x00008000 // Use the new FileAbstractImage |
| 34 | |
| 35 | namespace app { |
| 36 | |
| 37 | class FormatOptions; |
| 38 | class FileFormat; |
| 39 | class FileOp; |
| 40 | |
| 41 | // A file format supported by ASE. It is the base class to extend if |
| 42 | // you want to add support to load and/or save a new kind of |
| 43 | // image/animation format. |
| 44 | class FileFormat { |
| 45 | public: |
| 46 | FileFormat(); |
| 47 | virtual ~FileFormat(); |
| 48 | |
| 49 | const char* name() const; // File format name |
| 50 | |
| 51 | // Fill "exts" variable with the supported extensions (e.g. "jpeg" and "jpg") |
| 52 | void getExtensions(base::paths& exts) const; |
| 53 | |
| 54 | dio::FileFormat dioFormat() const; |
| 55 | |
| 56 | bool load(FileOp* fop); |
| 57 | #ifdef ENABLE_SAVE |
| 58 | bool save(FileOp* fop); |
| 59 | #endif |
| 60 | |
| 61 | // Does post-load operation which require user intervention. |
| 62 | // Returns false cancelled the operation. |
| 63 | bool postLoad(FileOp* fop); |
| 64 | |
| 65 | // Returns extra options for this format. It can return != NULL |
| 66 | // only if flags() returns FILE_SUPPORT_GET_FORMAT_OPTIONS. |
| 67 | FormatOptionsPtr askUserForFormatOptions(FileOp* fop) { |
| 68 | return onAskUserForFormatOptions(fop); |
| 69 | } |
| 70 | |
| 71 | // Returns true if this file format supports the given flag. |
| 72 | bool support(int f) const { |
| 73 | return ((onGetFlags() & f) == f); |
| 74 | } |
| 75 | |
| 76 | protected: |
| 77 | virtual const char* onGetName() const = 0; |
| 78 | virtual void onGetExtensions(base::paths& exts) const = 0; |
| 79 | virtual dio::FileFormat onGetDioFormat() const = 0; |
| 80 | virtual int onGetFlags() const = 0; |
| 81 | |
| 82 | virtual bool onLoad(FileOp* fop) = 0; |
| 83 | virtual bool onPostLoad(FileOp* fop) { return true; } |
| 84 | #ifdef ENABLE_SAVE |
| 85 | virtual bool onSave(FileOp* fop) = 0; |
| 86 | #endif |
| 87 | |
| 88 | virtual FormatOptionsPtr onAskUserForFormatOptions(FileOp* fop) { |
| 89 | return FormatOptionsPtr(nullptr); |
| 90 | } |
| 91 | |
| 92 | }; |
| 93 | |
| 94 | } // namespace app |
| 95 | |
| 96 | #endif |
| 97 | |