| 1 | // Aseprite |
| 2 | // Copyright (C) 2001-2015 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifndef FILTERS_CONVOLUTION_MATRIX_H_INCLUDED |
| 8 | #define FILTERS_CONVOLUTION_MATRIX_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "filters/target.h" |
| 12 | |
| 13 | #include <vector> |
| 14 | #include <string> |
| 15 | |
| 16 | namespace filters { |
| 17 | |
| 18 | // A convolution matrix which is used by ConvolutionMatrixFilter. |
| 19 | class ConvolutionMatrix { |
| 20 | public: |
| 21 | // TODO warning: this number could be dangerous for big filters |
| 22 | static const int Precision = 256; |
| 23 | |
| 24 | ConvolutionMatrix(int width, int height); |
| 25 | |
| 26 | const char* getName() const { return m_name.c_str(); } |
| 27 | int getWidth() const { return m_width; } |
| 28 | int getHeight() const { return m_height; } |
| 29 | int getCenterX() const { return m_cx; } |
| 30 | int getCenterY() const { return m_cy; } |
| 31 | int getDiv() const { return m_div; } |
| 32 | int getBias() const { return m_bias; } |
| 33 | Target getDefaultTarget() const { return m_defaultTarget; } |
| 34 | |
| 35 | void setName(const char* name) { m_name = name; } |
| 36 | void setWidth(int width) { m_width = width; } |
| 37 | void setHeight(int height) { m_height = height; } |
| 38 | void setCenterX(int cx) { m_cx = cx; } |
| 39 | void setCenterY(int cy) { m_cy = cy; } |
| 40 | void setDiv(int div) { m_div = div; } |
| 41 | void setBias(int bias) { m_bias = bias; } |
| 42 | void setDefaultTarget(Target target) { m_defaultTarget = target; } |
| 43 | |
| 44 | // Returns a reference to a value in the matrix. It is very |
| 45 | // important that values of this matrix are sortered in the |
| 46 | // following way (e.g. m_width=4, m_height=3): |
| 47 | // |
| 48 | // x0 x1 x2 x3 |
| 49 | // x4 x5 x6 x7 |
| 50 | // x8 x9 x10 x11 |
| 51 | // |
| 52 | // The ConvolutionMatrixFilter expects that memory layout. |
| 53 | // |
| 54 | int& value(int x, int y) { return m_data[y*m_width+x]; } |
| 55 | const int& value(int x, int y) const { return m_data[y*m_width+x]; } |
| 56 | |
| 57 | private: |
| 58 | std::string m_name; // Name |
| 59 | int m_width, m_height; // Size of the matrix |
| 60 | int m_cx, m_cy; // Center of the filter |
| 61 | int m_div; // Division factor |
| 62 | int m_bias; // Addition factor (for offset) |
| 63 | Target m_defaultTarget; // Targets by default (look at TARGET_RED_CHANNEL, etc. constants) |
| 64 | std::vector<int> m_data; // The matrix with the multiplication factors |
| 65 | }; |
| 66 | |
| 67 | } // namespace filters |
| 68 | |
| 69 | #endif |
| 70 | |