Beatmup
operator.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, 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 #include "abstract_bitmap.h"
20 #include "../parallelism.h"
21 #include "../geometry.h"
22 
23 namespace Beatmup {
24 
25  /**
26  A binary pixelwise operation on images.
27  Evaluates expression O = op(L, R) for bitmaps L, R, O and a given pixelwise operation op.
28  Allows to select the operating area in all the three bitmaps.
29  */
31  public:
32  /**
33  Binary operation specification.
34  */
35  enum class Operation {
36  NONE, //!< bypass; the output bitmap remains unchanged
37  ADD, //!< the input images are added
38  MULTIPLY //!< the input images are multiplied
39  };
40 
41  private:
42  const int MIN_PIXEL_COUNT_PER_THREAD = 1000; //!< minimum number of pixels per worker
43 
44  AbstractBitmap *op1, *op2, *output; //!< input and output bitmaps
48 
49  protected:
50  virtual bool process(TaskThread& thread);
52  virtual void afterProcessing(ThreadIndex, GraphicPipeline*, bool);
53  virtual ThreadIndex getMaxThreads() const;
54 
55  public:
60  void setOperation(const Operation operation);
61  void setCropSize(int width, int height);
62  void setOp1Origin(const IntPoint origin);
63  void setOp2Origin(const IntPoint origin);
64  void setOutputOrigin(const IntPoint origin);
65 
66  void resetCrop();
67 
68  int getCropWidth() const { return cropWidth; }
69  int getCropHeight() const { return cropHeight; }
70  const IntPoint getOp1Origin() const { return op1Origin; }
71  const IntPoint getOp2Origin() const { return op2Origin; }
72  const IntPoint getOutputOrigin() const { return outputOrigin; }
73 
74  };
75 }
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
A binary pixelwise operation on images.
Definition: operator.h:30
virtual void beforeProcessing(ThreadIndex, ProcessingTarget target, GraphicPipeline *)
Instruction called before the task is executed.
Definition: operator.cpp:217
void setOp1Origin(const IntPoint origin)
Definition: operator.cpp:188
AbstractBitmap * output
input and output bitmaps
Definition: operator.h:44
void setCropSize(int width, int height)
Definition: operator.cpp:182
void setOperand1(AbstractBitmap *op1)
Definition: operator.cpp:162
Operation
Binary operation specification.
Definition: operator.h:35
@ MULTIPLY
the input images are multiplied
@ ADD
the input images are added
@ NONE
bypass; the output bitmap remains unchanged
virtual void afterProcessing(ThreadIndex, GraphicPipeline *, bool)
Instruction called after the task is executed.
Definition: operator.cpp:235
void setOperation(const Operation operation)
Definition: operator.cpp:177
void setOutputOrigin(const IntPoint origin)
Definition: operator.cpp:198
const IntPoint getOp1Origin() const
Definition: operator.h:70
AbstractBitmap * op2
Definition: operator.h:44
virtual ThreadIndex getMaxThreads() const
Gives the upper limint on the number of threads the task may be performed by.
Definition: operator.cpp:212
const IntPoint getOp2Origin() const
Definition: operator.h:71
const int MIN_PIXEL_COUNT_PER_THREAD
minimum number of pixels per worker
Definition: operator.h:42
void setOutput(AbstractBitmap *output)
Definition: operator.cpp:172
AbstractBitmap * op1
Definition: operator.h:44
void setOp2Origin(const IntPoint origin)
Definition: operator.cpp:193
const IntPoint getOutputOrigin() const
Definition: operator.h:72
void setOperand2(AbstractBitmap *op2)
Definition: operator.cpp:167
virtual bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
Definition: operator.cpp:240
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Internal low-level GPU control API.
Definition: pipeline.h:33
Thread executing tasks.
Definition: parallelism.h:154
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
ProcessingTarget
Definition: basic_types.h:55
jlong jint width
jlong jint jint height