| 1 | // Aseprite |
| 2 | // Copyright (C) 2019 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2017 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_MANAGER_H_INCLUDED |
| 9 | #define FILTERS_FILTER_MANAGER_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "doc/pixel_format.h" |
| 13 | #include "filters/target.h" |
| 14 | |
| 15 | namespace doc { |
| 16 | class Image; |
| 17 | } |
| 18 | |
| 19 | namespace filters { |
| 20 | |
| 21 | class FilterIndexedData; |
| 22 | |
| 23 | // Information given to a filter (Filter interface) to apply it to a |
| 24 | // single row. Basically an Filter implementation has to obtain |
| 25 | // colors from getSourceAddress(), applies some kind of transformation |
| 26 | // to that color, and save the result in getDestinationAddress(). |
| 27 | // This process must be repeated getWidth() times. |
| 28 | class FilterManager { |
| 29 | public: |
| 30 | virtual ~FilterManager() { } |
| 31 | |
| 32 | virtual doc::PixelFormat pixelFormat() const = 0; |
| 33 | |
| 34 | // Gets the address of the first pixel which has the original color |
| 35 | // to apply the filter. |
| 36 | virtual const void* getSourceAddress() = 0; |
| 37 | |
| 38 | // Gets the address of the first pixel which is destination of the |
| 39 | // filter. |
| 40 | virtual void* getDestinationAddress() = 0; |
| 41 | |
| 42 | // Returns the width of the row to apply the filter. You must apply |
| 43 | // the Filter "getWidth()" times, in each pixel from getSourceAddress(). |
| 44 | virtual int getWidth() = 0; |
| 45 | |
| 46 | // Returns the target of the Filter, i.e. what channels/components |
| 47 | // (e.g. Red, Green, or Blue) will be modified by the filter. |
| 48 | virtual Target getTarget() = 0; |
| 49 | |
| 50 | // Returns a interface needed by filters which operate over indexed |
| 51 | // images. FilterIndexedData interface provides a Palette and a |
| 52 | // RgbMap to help the filter to make its job. |
| 53 | virtual FilterIndexedData* getIndexedData() = 0; |
| 54 | |
| 55 | // Returns true if you should skip the current pixel (do not apply |
| 56 | // the filter). You must increment all your internal source and |
| 57 | // destination address pointers one pixel without applying the |
| 58 | // filter. |
| 59 | // |
| 60 | // This method is used to skip non-selected pixels (when the |
| 61 | // selection is actived). |
| 62 | virtual bool skipPixel() = 0; |
| 63 | |
| 64 | ////////////////////////////////////////////////////////////////////// |
| 65 | // Special members for 2D filters like convolution matrices. |
| 66 | |
| 67 | // Returns the source image. |
| 68 | virtual const doc::Image* getSourceImage() = 0; |
| 69 | |
| 70 | // Returns the first X coordinate of the row to apply the filter. |
| 71 | virtual int x() const = 0; |
| 72 | |
| 73 | // Returns the Y coordinate of the row. |
| 74 | virtual int y() const = 0; |
| 75 | |
| 76 | // Returns true if this is the first row. Useful to apply a filter |
| 77 | // to the palette in the first row. |
| 78 | virtual bool isFirstRow() const = 0; |
| 79 | |
| 80 | // Returns true if the mask is actived (so we are applying the |
| 81 | // filter just to a part of the sprite). |
| 82 | virtual bool isMaskActive() const = 0; |
| 83 | |
| 84 | }; |
| 85 | |
| 86 | } // namespace filters |
| 87 | |
| 88 | #endif |
| 89 | |