Beatmup
pixelwise_filter.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 "../parallelism.h"
21 #include "../bitmap/abstract_bitmap.h"
22 #include "../shading/image_shader.h"
23 
24 namespace Beatmup {
25  /**
26  Image filtering operations
27  */
28  namespace Filters {
29 
30  /**
31  Base class for image filters processing a given bitmap in a pixelwise fashion.
32  */
34  protected:
35  static const std::string GLSL_RGBA_INPUT;
36 
39 
40  /**
41  Applies filtering to given pixel data.
42  \param x Horizontal position of the first pixel in image
43  \param y Vertical position of the first pixel in image
44  \param nPix Number of pixels to process
45  \param thread Calling thread descriptor
46  */
47  virtual void apply(int x, int y, msize nPix, TaskThread& thread) = 0;
48 
49  /**
50  Provides GLSL declarations used in the GLSL code.
51  */
52  virtual std::string getGlslDeclarations() const;
53 
54  /**
55  Provides GLSL source code of the filter.
56  */
57  virtual std::string getGlslSourceCode() const = 0;
58 
59  /**
60  A callback run every time before the filter is applied to the image.
61  \param useGpu If `true`, the filter will be run on GPU.
62  */
63  virtual void setup(bool useGpu);
64 
65  virtual bool process(TaskThread& thread) final;
66  virtual bool processOnGPU(GraphicPipeline& gpu, TaskThread& thread) final;
67  virtual void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline* gpu);
68  virtual void afterProcessing(ThreadIndex threadCount, GraphicPipeline* gpu, bool aborted);
69  virtual TaskDeviceRequirement getUsedDevices() const final;
70 
72  public:
73  virtual ~PixelwiseFilter();
74 
75  inline virtual void setInput(AbstractBitmap *input) { this->inputBitmap = input; }
76  inline virtual void setOutput(AbstractBitmap *output) { this->outputBitmap = output; }
77 
78  inline AbstractBitmap *getInput() { return inputBitmap; }
79  inline AbstractBitmap *getOutput() { return outputBitmap; }
80 
81  ThreadIndex getMaxThreads() const;
82  };
83 
84  }
85 
86 }
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
TaskDeviceRequirement
Specifies which device (CPU and/or GPU) is used to run the task.
Definition: parallelism.h:95
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Base class for image filters processing a given bitmap in a pixelwise fashion.
virtual std::string getGlslDeclarations() const
Provides GLSL declarations used in the GLSL code.
virtual void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
Instruction called before the task is executed.
virtual void setInput(AbstractBitmap *input)
virtual TaskDeviceRequirement getUsedDevices() const final
Communicates devices (CPU and/or GPU) the task is run on.
virtual void afterProcessing(ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
Instruction called after the task is executed.
virtual void apply(int x, int y, msize nPix, TaskThread &thread)=0
Applies filtering to given pixel data.
virtual std::string getGlslSourceCode() const =0
Provides GLSL source code of the filter.
virtual bool processOnGPU(GraphicPipeline &gpu, TaskThread &thread) final
Executes the task on GPU.
virtual void setup(bool useGpu)
A callback run every time before the filter is applied to the image.
virtual void setOutput(AbstractBitmap *output)
virtual bool process(TaskThread &thread) final
Executes the task on CPU within a given thread.
ThreadIndex getMaxThreads() const
Gives the upper limint on the number of threads the task may be performed by.
static const std::string GLSL_RGBA_INPUT
Internal low-level GPU control API.
Definition: pipeline.h:33
A GLSL program to process images.
Definition: image_shader.h:34
Thread executing tasks.
Definition: parallelism.h:154
uint32_t msize
memory size
Definition: basic_types.h:30
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
ProcessingTarget
Definition: basic_types.h:55
jobject jlong jint jint y
jobject jlong jint x