Beatmup
color_matrix.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "pixelwise_filter.h"
21 #include "../basic_types.h"
22 #include "../color/matrix.h"
23 
24 namespace Beatmup {
25  namespace Filters {
26 
27  /**
28  Color matrix filter: applies mapping Ax + B at each pixel of a given image in RGBA space.
29  */
30  class ColorMatrix : public PixelwiseFilter {
31  private:
32  Color::Matrix matrix; //!< the matrix
33  color4f bias; //!< added constant
34  bool allowIntApprox; //!< allow integer approximation of the coefficients
35 
36  protected:
37  void apply(int x, int y, msize nPix, TaskThread& thread);
38 
39  std::string getGlslDeclarations() const;
40  std::string getGlslSourceCode() const;
41  void setup(bool useGpu);
42 
43  public:
44  ColorMatrix();
45 
46  inline bool isIntegerApproximationsAllowed() const { return allowIntApprox; }
47 
49 
50  inline Color::Matrix& getMatrix() { return matrix; }
51 
52  /**
53  Sets color matrix coefficients for a specific output color channel.
54  \param outChannel matrix line number (output channel)
55  \param bias constant to add to the output channel
56  \param r red channel coefficient
57  \param g green channel coefficient
58  \param b blue channel coefficient
59  \param a alpha channel coefficient
60  */
61  void setCoefficients(int outChannel, float bias, float r = .0f, float g = .0f, float b = .0f, float a = .0f);
62 
63  /**
64  Resets the current transformation to a matrix performing standard HSV correction.
65  \param hueShiftDegrees Hue shift in degrees
66  \param saturationFactor Saturation scaling factor
67  \param valueFactor Value scaling factor
68  */
69  void setHSVCorrection(float hueShiftDegrees, float saturationFactor = 1.0f, float valueFactor = 1.0f);
70 
71  /**
72  Resets the current transformation to a fancy color inversion mode with a fixed hue point.
73  \param preservedHue Hue value to keep constant. The other colors are inverted
74  \param saturationFactor Saturation scaling factor (in HSV sense)
75  \param valueFactor Value scaling factor (in HSV sense)
76  */
77  void setColorInversion(color3f preservedHue, float saturationFactor = 1.0f, float valueFactor = 1.0f);
78 
79  /**
80  Applies a contrast adjustment by a given factor on top of the current transformation
81  */
82  void applyContrast(float factor);
83 
84  /**
85  Sets a brightness adjustment by a given factor (non-cumulative with respect to the current transformation)
86  */
87  void setBrightness(float brightness);
88  };
89  }
90 }
RGBA color mapping.
Definition: matrix.h:29
Color matrix filter: applies mapping Ax + B at each pixel of a given image in RGBA space.
Definition: color_matrix.h:30
void setBrightness(float brightness)
Sets a brightness adjustment by a given factor (non-cumulative with respect to the current transforma...
void setColorInversion(color3f preservedHue, float saturationFactor=1.0f, float valueFactor=1.0f)
Resets the current transformation to a fancy color inversion mode with a fixed hue point.
bool allowIntApprox
allow integer approximation of the coefficients
Definition: color_matrix.h:34
void allowIntegerApproximations(bool allow)
bool isIntegerApproximationsAllowed() const
Definition: color_matrix.h:46
void setHSVCorrection(float hueShiftDegrees, float saturationFactor=1.0f, float valueFactor=1.0f)
Resets the current transformation to a matrix performing standard HSV correction.
void setup(bool useGpu)
A callback run every time before the filter is applied to the image.
std::string getGlslSourceCode() const
Provides GLSL source code of the filter.
void setCoefficients(int outChannel, float bias, float r=.0f, float g=.0f, float b=.0f, float a=.0f)
Sets color matrix coefficients for a specific output color channel.
std::string getGlslDeclarations() const
Provides GLSL declarations used in the GLSL code.
void apply(int x, int y, msize nPix, TaskThread &thread)
Applies filtering to given pixel data.
color4f bias
added constant
Definition: color_matrix.h:33
Color::Matrix matrix
the matrix
Definition: color_matrix.h:32
void applyContrast(float factor)
Applies a contrast adjustment by a given factor on top of the current transformation.
Color::Matrix & getMatrix()
Definition: color_matrix.h:50
Base class for image filters processing a given bitmap in a pixelwise fashion.
Thread executing tasks.
Definition: parallelism.h:154
uint32_t msize
memory size
Definition: basic_types.h:30
jobject jlong jint jint jint jint g
jobject jlong jint jint jint jint jint b
jobject jlong jint jint y
jobject jlong jint jint jint r
jobject jlong jint jint jint jint jint jint a
jobject jlong jint x
jlong jboolean allow
layer getMapping().setCenterPosition(Beatmup jlong jfloat factor