Beatmup
Beatmup::Filters::ColorMatrix Class Reference

Color matrix filter: applies mapping Ax + B at each pixel of a given image in RGBA space. More...

#include <color_matrix.h>

Inheritance diagram for Beatmup::Filters::ColorMatrix:
Beatmup::Filters::PixelwiseFilter Beatmup::AbstractTask Beatmup::BitmapContentLock Beatmup::Object

Public Member Functions

 ColorMatrix ()
 
bool isIntegerApproximationsAllowed () const
 
void allowIntegerApproximations (bool allow)
 
Color::MatrixgetMatrix ()
 
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. More...
 
void setHSVCorrection (float hueShiftDegrees, float saturationFactor=1.0f, float valueFactor=1.0f)
 Resets the current transformation to a matrix performing standard HSV correction. More...
 
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. More...
 
void applyContrast (float factor)
 Applies a contrast adjustment by a given factor on top of the current transformation. More...
 
void setBrightness (float brightness)
 Sets a brightness adjustment by a given factor (non-cumulative with respect to the current transformation) More...
 
- Public Member Functions inherited from Beatmup::Filters::PixelwiseFilter
virtual ~PixelwiseFilter ()
 
virtual void setInput (AbstractBitmap *input)
 
virtual void setOutput (AbstractBitmap *output)
 
AbstractBitmapgetInput ()
 
AbstractBitmapgetOutput ()
 
ThreadIndex getMaxThreads () const
 Gives the upper limint on the number of threads the task may be performed by. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Protected Member Functions

void apply (int x, int y, msize nPix, TaskThread &thread)
 Applies filtering to given pixel data. More...
 
std::string getGlslDeclarations () const
 Provides GLSL declarations used in the GLSL code. More...
 
std::string getGlslSourceCode () const
 Provides GLSL source code of the filter. More...
 
void setup (bool useGpu)
 A callback run every time before the filter is applied to the image. More...
 
- Protected Member Functions inherited from Beatmup::Filters::PixelwiseFilter
virtual bool process (TaskThread &thread) final
 Executes the task on CPU within a given thread. More...
 
virtual bool processOnGPU (GraphicPipeline &gpu, TaskThread &thread) final
 Executes the task on GPU. More...
 
virtual void beforeProcessing (ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
 Instruction called before the task is executed. More...
 
virtual void afterProcessing (ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
 Instruction called after the task is executed. More...
 
virtual TaskDeviceRequirement getUsedDevices () const final
 Communicates devices (CPU and/or GPU) the task is run on. More...
 
 PixelwiseFilter ()
 

Private Attributes

Color::Matrix matrix
 the matrix More...
 
color4f bias
 added constant More...
 
bool allowIntApprox
 allow integer approximation of the coefficients More...
 

Additional Inherited Members

- Public Types inherited from Beatmup::AbstractTask
enum class  TaskDeviceRequirement { CPU_ONLY , GPU_OR_CPU , GPU_ONLY }
 Specifies which device (CPU and/or GPU) is used to run the task. More...
 
- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 
- Protected Attributes inherited from Beatmup::Filters::PixelwiseFilter
AbstractBitmapinputBitmap
 
AbstractBitmapoutputBitmap
 
ImageShadershader
 
- Static Protected Attributes inherited from Beatmup::Filters::PixelwiseFilter
static const std::string GLSL_RGBA_INPUT
 

Detailed Description

Color matrix filter: applies mapping Ax + B at each pixel of a given image in RGBA space.

Definition at line 30 of file color_matrix.h.

Constructor & Destructor Documentation

◆ ColorMatrix()

Filters::ColorMatrix::ColorMatrix ( )

Definition at line 27 of file color_matrix.cpp.

27  :
29 {}
bool allowIntApprox
allow integer approximation of the coefficients
Definition: color_matrix.h:34
color4f bias
added constant
Definition: color_matrix.h:33
static const color4f ZERO_F
Definition: constants.h:37

Member Function Documentation

◆ apply()

void Filters::ColorMatrix::apply ( int  x,
int  y,
msize  nPix,
TaskThread thread 
)
protectedvirtual

Applies filtering to given pixel data.

Parameters
xHorizontal position of the first pixel in image
yVertical position of the first pixel in image
nPixNumber of pixels to process
threadCalling thread descriptor

Implements Beatmup::Filters::PixelwiseFilter.

Definition at line 74 of file color_matrix.cpp.

74  {
75  BitmapProcessing::pipeline<Kernels::ApplyColorMatrix>(
78  nPix
79  );
80 }
bool isInteger() const
Returns true if the bitmap contains integer values, false otherwise.
Color::Matrix matrix
the matrix
Definition: color_matrix.h:32
jobject jlong jint jint y
jobject jlong jint x

◆ getGlslDeclarations()

std::string Filters::ColorMatrix::getGlslDeclarations ( ) const
protectedvirtual

Provides GLSL declarations used in the GLSL code.

Reimplemented from Beatmup::Filters::PixelwiseFilter.

Definition at line 83 of file color_matrix.cpp.

83  {
84  if (allowIntApprox)
85  return
86  "uniform lowp mat4 transform;" \
87  "uniform lowp vec4 bias;";
88  else
89  return
90  "uniform highp mat4 transform;" \
91  "uniform highp vec4 bias;";
92 }

◆ getGlslSourceCode()

std::string Filters::ColorMatrix::getGlslSourceCode ( ) const
protectedvirtual

Provides GLSL source code of the filter.

Implements Beatmup::Filters::PixelwiseFilter.

Definition at line 95 of file color_matrix.cpp.

95  {
96  return "gl_FragColor = " + PixelwiseFilter::GLSL_RGBA_INPUT + " * transform + bias;";
97 }
static const std::string GLSL_RGBA_INPUT

◆ setup()

void Filters::ColorMatrix::setup ( bool  useGpu)
protectedvirtual

A callback run every time before the filter is applied to the image.

Parameters
useGpuIf true, the filter will be run on GPU.

Reimplemented from Beatmup::Filters::PixelwiseFilter.

Definition at line 100 of file color_matrix.cpp.

100  {
101  if (useGpu) {
102  shader->setFloatMatrix4("transform", matrix);
103  shader->setFloat("bias", bias.r, bias.g, bias.b, bias.a);
104  }
105 }
void setFloatMatrix4(std::string name, const float matrix[16])
Sets a float 4*4 matrix variable value.
void setFloat(std::string name, float value)
Sets a scalar float uniform value.

◆ isIntegerApproximationsAllowed()

bool Beatmup::Filters::ColorMatrix::isIntegerApproximationsAllowed ( ) const
inline

Definition at line 46 of file color_matrix.h.

46 { return allowIntApprox; }

◆ allowIntegerApproximations()

void Filters::ColorMatrix::allowIntegerApproximations ( bool  allow)

Definition at line 108 of file color_matrix.cpp.

108  {
110 }
jlong jboolean allow

◆ getMatrix()

Color::Matrix& Beatmup::Filters::ColorMatrix::getMatrix ( )
inline

Definition at line 50 of file color_matrix.h.

50 { return matrix; }

◆ setCoefficients()

void Filters::ColorMatrix::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.

Parameters
outChannelmatrix line number (output channel)
biasconstant to add to the output channel
rred channel coefficient
ggreen channel coefficient
bblue channel coefficient
aalpha channel coefficient

Definition at line 113 of file color_matrix.cpp.

113  {
114  OutOfRange::check(outChannel, 0, 3, "Invalid output channel index: %d");
115  pixfloat4 _(this->bias);
116  _[outChannel] = bias;
117  this->bias = _;
118  matrix[outChannel].r = r;
119  matrix[outChannel].g = g;
120  matrix[outChannel].b = b;
121  matrix[outChannel].a = a;
122 }
color4f r() const
Definition: matrix.h:60
color4f g() const
Definition: matrix.h:61
color4f b() const
Definition: matrix.h:62
color4f a() const
Definition: matrix.h:63
static void check(const datatype value, const datatype min, const datatype max, const char *message)
Definition: exception.h:86
4-channel floating point arithmetic
jobject jlong jint jint jint jint g
jobject jlong jint jint jint jint jint b
jobject jlong jint jint jint r
jobject jlong jint jint jint jint jint jint a

◆ setHSVCorrection()

void Filters::ColorMatrix::setHSVCorrection ( float  hueShiftDegrees,
float  saturationFactor = 1.0f,
float  valueFactor = 1.0f 
)

Resets the current transformation to a matrix performing standard HSV correction.

Parameters
hueShiftDegreesHue shift in degrees
saturationFactorSaturation scaling factor
valueFactorValue scaling factor

Definition at line 125 of file color_matrix.cpp.

125  {
126  matrix = Color::Matrix(hueDegrees, saturationFactor, valueFactor);
128 }
RGBA color mapping.
Definition: matrix.h:29

◆ setColorInversion()

void Filters::ColorMatrix::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.

Parameters
preservedHueHue value to keep constant. The other colors are inverted
saturationFactorSaturation scaling factor (in HSV sense)
valueFactorValue scaling factor (in HSV sense)

Definition at line 131 of file color_matrix.cpp.

131  {
132  matrix = Color::Matrix(preservedHue, saturationFactor, valueFactor);
134 }

◆ applyContrast()

void Filters::ColorMatrix::applyContrast ( float  factor)

Applies a contrast adjustment by a given factor on top of the current transformation.

Definition at line 137 of file color_matrix.cpp.

137  {
138  matrix.r().r *= factor;
139  matrix.r().g *= factor;
140  matrix.r().b *= factor;
141  matrix.g().r *= factor;
142  matrix.g().g *= factor;
143  matrix.g().b *= factor;
144  matrix.b().r *= factor;
145  matrix.b().g *= factor;
146  matrix.b().b *= factor;
147 }
layer getMapping().setCenterPosition(Beatmup jlong jfloat factor

◆ setBrightness()

void Filters::ColorMatrix::setBrightness ( float  brightness)

Sets a brightness adjustment by a given factor (non-cumulative with respect to the current transformation)

Definition at line 150 of file color_matrix.cpp.

150  {
151  bias.r = brightness;
152  bias.g = brightness;
153  bias.b = brightness;
154 }

Member Data Documentation

◆ matrix

Color::Matrix Beatmup::Filters::ColorMatrix::matrix
private

the matrix

Definition at line 32 of file color_matrix.h.

◆ bias

color4f Beatmup::Filters::ColorMatrix::bias
private

added constant

Definition at line 33 of file color_matrix.h.

◆ allowIntApprox

bool Beatmup::Filters::ColorMatrix::allowIntApprox
private

allow integer approximation of the coefficients

Definition at line 34 of file color_matrix.h.


The documentation for this class was generated from the following files: