| 1 | // Aseprite |
| 2 | // Copyright (C) 2019 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2015 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef FILTERS_FILTER_H_INCLUDED |
| 9 | #define FILTERS_FILTER_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | namespace doc { |
| 13 | class PalettePicks; |
| 14 | } |
| 15 | |
| 16 | namespace filters { |
| 17 | |
| 18 | class FilterManager; |
| 19 | |
| 20 | // Interface which applies a filter to a sprite given a FilterManager |
| 21 | // which indicates where we have to apply the filter. |
| 22 | class Filter { |
| 23 | public: |
| 24 | virtual ~Filter() { } |
| 25 | |
| 26 | // Returns a proper name for the filter. It is used to show a label |
| 27 | // with the Undo action. |
| 28 | virtual const char* getName() = 0; |
| 29 | |
| 30 | // Applies the filter to one RGBA row. You must use |
| 31 | // FilterManager::getSourceAddress() and advance 32 bits to modify |
| 32 | // each pixel. |
| 33 | virtual void applyToRgba(FilterManager* filterMgr) = 0; |
| 34 | |
| 35 | // Applies the filter to one grayscale row. You must use |
| 36 | // FilterManager::getSourceAddress() and advance 16 bits to modify |
| 37 | // each pixel. |
| 38 | virtual void applyToGrayscale(FilterManager* filterMgr) = 0; |
| 39 | |
| 40 | // Applies the filter to one indexed row. You must use |
| 41 | // FilterManager::getSourceAddress() and advance 8 bits to modify |
| 42 | // each pixel. |
| 43 | virtual void applyToIndexed(FilterManager* filterMgr) = 0; |
| 44 | |
| 45 | // Applies the filter to the color palette. |
| 46 | virtual void applyToPalette(FilterManager* filterMgr) { } |
| 47 | }; |
| 48 | |
| 49 | // Filter that support applying it only to palette colors. |
| 50 | class FilterWithPalette : public Filter { |
| 51 | public: |
| 52 | FilterWithPalette(); |
| 53 | void applyToPalette(FilterManager* filterMgr) override; |
| 54 | |
| 55 | protected: |
| 56 | virtual void onApplyToPalette(FilterManager* filterMgr, |
| 57 | const doc::PalettePicks& picks) = 0; |
| 58 | |
| 59 | // Use the palette to replace colors in RGB images |
| 60 | bool m_usePaletteOnRGB; |
| 61 | }; |
| 62 | |
| 63 | } // namespace filters |
| 64 | |
| 65 | #endif |
| 66 | |