Beatmup
Beatmup::BitmapBinaryOperation Class Reference

A binary pixelwise operation on images. More...

#include <operator.h>

Inheritance diagram for Beatmup::BitmapBinaryOperation:
Beatmup::AbstractTask Beatmup::BitmapContentLock Beatmup::Object

Public Types

enum class  Operation { NONE , ADD , MULTIPLY }
 Binary operation specification. More...
 
- 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...
 

Public Member Functions

 BitmapBinaryOperation ()
 
void setOperand1 (AbstractBitmap *op1)
 
void setOperand2 (AbstractBitmap *op2)
 
void setOutput (AbstractBitmap *output)
 
void setOperation (const Operation operation)
 
void setCropSize (int width, int height)
 
void setOp1Origin (const IntPoint origin)
 
void setOp2Origin (const IntPoint origin)
 
void setOutputOrigin (const IntPoint origin)
 
void resetCrop ()
 
int getCropWidth () const
 
int getCropHeight () const
 
const IntPoint getOp1Origin () const
 
const IntPoint getOp2Origin () const
 
const IntPoint getOutputOrigin () const
 
- Public Member Functions inherited from Beatmup::AbstractTask
virtual bool processOnGPU (GraphicPipeline &gpu, TaskThread &thread)
 Executes the task on GPU. More...
 
virtual TaskDeviceRequirement getUsedDevices () const
 Communicates devices (CPU and/or GPU) the task is run on. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Protected Member Functions

virtual bool process (TaskThread &thread)
 Executes the task on CPU within a given thread. More...
 
virtual void beforeProcessing (ThreadIndex, ProcessingTarget target, GraphicPipeline *)
 Instruction called before the task is executed. More...
 
virtual void afterProcessing (ThreadIndex, GraphicPipeline *, bool)
 Instruction called after the task is executed. More...
 
virtual ThreadIndex getMaxThreads () const
 Gives the upper limint on the number of threads the task may be performed by. More...
 

Private Attributes

const int MIN_PIXEL_COUNT_PER_THREAD = 1000
 minimum number of pixels per worker More...
 
AbstractBitmapop1
 
AbstractBitmapop2
 
AbstractBitmapoutput
 input and output bitmaps More...
 
Operation operation
 
IntPoint op1Origin
 
IntPoint op2Origin
 
IntPoint outputOrigin
 
int cropWidth
 
int cropHeight
 

Additional Inherited Members

- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 
- Private Member Functions inherited from Beatmup::BitmapContentLock
 BitmapContentLock ()
 
 ~BitmapContentLock ()
 
void readLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for reading using a specific processing target device. More...
 
void writeLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for writing using a specific processing target device. More...
 
void unlock (AbstractBitmap *bitmap)
 Drops a lock to the bitmap. More...
 
void unlockAll ()
 Unlocks all the locked bitmaps unconditionally. More...
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output)
 
void lock (GraphicPipeline *gpu, ProcessingTarget target, AbstractBitmap *input, AbstractBitmap *output)
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, std::initializer_list< AbstractBitmap * > read, std::initializer_list< AbstractBitmap * > write)
 
template<typename ... Args>
void unlock (AbstractBitmap *first, Args ... others)
 

Detailed Description

A binary pixelwise operation on images.

Evaluates expression O = op(L, R) for bitmaps L, R, O and a given pixelwise operation op. Allows to select the operating area in all the three bitmaps.

Definition at line 30 of file operator.h.

Member Enumeration Documentation

◆ Operation

Binary operation specification.

Enumerator
NONE 

bypass; the output bitmap remains unchanged

ADD 

the input images are added

MULTIPLY 

the input images are multiplied

Definition at line 35 of file operator.h.

35  {
36  NONE, //!< bypass; the output bitmap remains unchanged
37  ADD, //!< the input images are added
38  MULTIPLY //!< the input images are multiplied
39  };
@ NONE
no extension
Definition: program.h:64

Constructor & Destructor Documentation

◆ BitmapBinaryOperation()

BitmapBinaryOperation::BitmapBinaryOperation ( )

Definition at line 156 of file operator.cpp.

156  :
157  op1(nullptr), op2(nullptr), output(nullptr),
159 {}
AbstractBitmap * output
input and output bitmaps
Definition: operator.h:44
@ NONE
bypass; the output bitmap remains unchanged
AbstractBitmap * op2
Definition: operator.h:44
AbstractBitmap * op1
Definition: operator.h:44

Member Function Documentation

◆ process()

bool BitmapBinaryOperation::process ( TaskThread thread)
protectedvirtual

Executes the task on CPU within a given thread.

Generally called by multiple threads.

Parameters
threadassociated task execution context
Returns
true if the execution is finished correctly, false otherwise

Implements Beatmup::AbstractTask.

Definition at line 240 of file operator.cpp.

240  {
241 #define PROCESS(IN_T, OUT_T) \
242  Kernels::BinaryOpBody<IN_T, OUT_T>::process( \
243  IN_T(*op1), IN_T(*op2), OUT_T(*output), \
244  operation, cropWidth, cropHeight, op1Origin, op2Origin, outputOrigin, thread);
245 
246  switch (output->getPixelFormat()) {
247  case SingleByte:
249  break;
250  case TripleByte:
252  break;
253  case QuadByte:
255  break;
256  case SingleFloat:
258  break;
259  case TripleFloat:
261  break;
262  case QuadFloat:
264  break;
265  case BinaryMask:
266  if (op1Origin.x % 8 == 0 && op2Origin.x % 8 == 0 && outputOrigin.x % 8 == 0)
270  thread);
271  else
273  break;
274  case QuaternaryMask:
276  break;
277  case HexMask:
279  break;
280  }
281  return true;
282 }
virtual const PixelFormat getPixelFormat() const =0
Pixel format of the bitmap.
A generic to access sub-byte mask bitmap data.
A generic to write mask bitmap data lookup tables for masks values.
Quad byte bitmap reader.
Quad byte bitmap writer.
Quad float bitmap reader.
Quad float bitmap writer.
Single byte bitmap reader.
Single byte bitmap writer.
Single float bitmap reader.
Single float bitmap writer.
Triple byte bitmap reader.
Triple byte bitmap writer.
Triple float bitmap reader.
Triple float bitmap writer.
static void processAlignedBinaryMask(in_t op1, in_t op2, out_t out, BitmapBinaryOperation::Operation operation, int width, int height, const IntPoint &op1Origin, const IntPoint &op2Origin, const IntPoint &outOrigin, const TaskThread &tt)
Performs a binary operation on two binary masks.
Definition: operator.cpp:77
LookupMaskWriter< 1, MASK_LUT_1_BIT > BinaryMaskWriter
LookupMaskScanner< 1, MASK_LUT_1_BIT > BinaryMaskReader
@ SingleByte
single channel of 8 bits per pixel (like grayscale), unsigned integer values
@ SingleFloat
single channel of 32 bits per pixel (like grayscale), single precision floating point values
@ QuaternaryMask
2 bits per pixel
@ QuadFloat
4 channels of 32 bits per pixel, single precision floating point values,
@ TripleFloat
3 channels of 32 bits per pixel, single precision floating point values
@ QuadByte
4 channels of 8 bits per pixel (like RGBA), unsigned integer values
@ TripleByte
3 channels of 8 bits per pixel (like RGB), unsigned integer values
@ BinaryMask
1 bit per pixel
@ HexMask
4 bits per pixel
#define PROCESS(IN_T, OUT_T)

◆ beforeProcessing()

void BitmapBinaryOperation::beforeProcessing ( ThreadIndex  threadCount,
ProcessingTarget  target,
GraphicPipeline gpu 
)
protectedvirtual

Instruction called before the task is executed.

Parameters
threadCountNumber of threads used to perform the task
targetDevice used to perform the task
gpuA graphic pipeline instance; may be null.

Reimplemented from Beatmup::AbstractTask.

Definition at line 217 of file operator.cpp.

217  {
218  NullTaskInput::check(op1, "operand 1 bitmap");
219  NullTaskInput::check(op2, "operand 2 bitmap");
220  NullTaskInput::check(output, "output bitmap");
221  RuntimeError::check(op1->getPixelFormat() == op2->getPixelFormat(), "operands pixel formats do not match");
222  RuntimeError::check(op1->getPixelFormat() == output->getPixelFormat(), "output pixel format does not match operands pixel format");
223  RuntimeError::check(op1Origin.x + cropWidth <= op1->getWidth(), "operand 1 width exceeded");
224  RuntimeError::check(op1Origin.y + cropHeight <= op1->getHeight(), "operand 1 height exceeded");
225  RuntimeError::check(op2Origin.x + cropWidth <= op2->getWidth(), "operand 2 width exceeded");
226  RuntimeError::check(op2Origin.y + cropHeight <= op2->getHeight(), "operand 2 height exceeded");
227  RuntimeError::check(outputOrigin.x + cropWidth <= output->getWidth(), "operand 1 width exceeded");
228  RuntimeError::check(outputOrigin.y + cropHeight <= output->getHeight(), "operand 1 height exceeded");
229 
230 
231  lock<ProcessingTarget::CPU>(gpu, { op1, op2 }, { output });
232 }
static void check(const void *pointer, const char *which)
Definition: exception.h:115
static void check(const bool condition, const std::string &message)
Definition: exception.h:64
return bitmap getWidth()
return bitmap getHeight()

◆ afterProcessing()

void BitmapBinaryOperation::afterProcessing ( ThreadIndex  threadCount,
GraphicPipeline gpu,
bool  aborted 
)
protectedvirtual

Instruction called after the task is executed.

Parameters
threadCountNumber of threads used to perform the task
gpuGPU to be used to execute the task; may be null.
abortedtrue if the task was aborted

Reimplemented from Beatmup::AbstractTask.

Definition at line 235 of file operator.cpp.

235  {
236  unlock(output, op1, op2);
237 }
void unlock(AbstractBitmap *bitmap)
Drops a lock to the bitmap.

◆ getMaxThreads()

ThreadIndex BitmapBinaryOperation::getMaxThreads ( ) const
protectedvirtual

Gives the upper limint on the number of threads the task may be performed by.

The actual number of threads running a specific task may be less or equal to the returned value, depending on the number of workers in ThreadPool running the task.

Reimplemented from Beatmup::AbstractTask.

Definition at line 212 of file operator.cpp.

212  {
214 }
static ThreadIndex validThreadCount(int number)
Valid thread count from a given integer value.
Definition: parallelism.cpp:45
const int MIN_PIXEL_COUNT_PER_THREAD
minimum number of pixels per worker
Definition: operator.h:42

◆ setOperand1()

void BitmapBinaryOperation::setOperand1 ( AbstractBitmap op1)

Definition at line 162 of file operator.cpp.

162  {
163  this->op1 = bitmap;
164 }
Beatmup::InternalBitmap * bitmap

◆ setOperand2()

void BitmapBinaryOperation::setOperand2 ( AbstractBitmap op2)

Definition at line 167 of file operator.cpp.

167  {
168  this->op2 = bitmap;
169 }

◆ setOutput()

void BitmapBinaryOperation::setOutput ( AbstractBitmap output)

Definition at line 172 of file operator.cpp.

172  {
173  this->output = bitmap;
174 }

◆ setOperation()

void BitmapBinaryOperation::setOperation ( const Operation  operation)

Definition at line 177 of file operator.cpp.

177  {
178  this->operation = operation;
179 }

◆ setCropSize()

void BitmapBinaryOperation::setCropSize ( int  width,
int  height 
)

Definition at line 182 of file operator.cpp.

182  {
183  this->cropWidth = width;
184  this->cropHeight = height;
185 }
jlong jint width
jlong jint jint height

◆ setOp1Origin()

void BitmapBinaryOperation::setOp1Origin ( const IntPoint  origin)

Definition at line 188 of file operator.cpp.

188  {
189  this->op1Origin = origin;
190 }

◆ setOp2Origin()

void BitmapBinaryOperation::setOp2Origin ( const IntPoint  origin)

Definition at line 193 of file operator.cpp.

193  {
194  this->op2Origin = origin;
195 }

◆ setOutputOrigin()

void BitmapBinaryOperation::setOutputOrigin ( const IntPoint  origin)

Definition at line 198 of file operator.cpp.

198  {
199  this->outputOrigin = origin;
200 }

◆ resetCrop()

void BitmapBinaryOperation::resetCrop ( )

Definition at line 203 of file operator.cpp.

203  {
204  if (op1 && op2 && output) {
208  }
209 }
static const CustomPoint ZERO
Definition: geometry.h:122
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724

◆ getCropWidth()

int Beatmup::BitmapBinaryOperation::getCropWidth ( ) const
inline

Definition at line 68 of file operator.h.

68 { return cropWidth; }

◆ getCropHeight()

int Beatmup::BitmapBinaryOperation::getCropHeight ( ) const
inline

Definition at line 69 of file operator.h.

69 { return cropHeight; }

◆ getOp1Origin()

const IntPoint Beatmup::BitmapBinaryOperation::getOp1Origin ( ) const
inline

Definition at line 70 of file operator.h.

70 { return op1Origin; }

◆ getOp2Origin()

const IntPoint Beatmup::BitmapBinaryOperation::getOp2Origin ( ) const
inline

Definition at line 71 of file operator.h.

71 { return op2Origin; }

◆ getOutputOrigin()

const IntPoint Beatmup::BitmapBinaryOperation::getOutputOrigin ( ) const
inline

Definition at line 72 of file operator.h.

72 { return outputOrigin; }

Member Data Documentation

◆ MIN_PIXEL_COUNT_PER_THREAD

const int Beatmup::BitmapBinaryOperation::MIN_PIXEL_COUNT_PER_THREAD = 1000
private

minimum number of pixels per worker

Definition at line 42 of file operator.h.

◆ op1

AbstractBitmap* Beatmup::BitmapBinaryOperation::op1
private

Definition at line 44 of file operator.h.

◆ op2

AbstractBitmap * Beatmup::BitmapBinaryOperation::op2
private

Definition at line 44 of file operator.h.

◆ output

AbstractBitmap * Beatmup::BitmapBinaryOperation::output
private

input and output bitmaps

Definition at line 44 of file operator.h.

◆ operation

Operation Beatmup::BitmapBinaryOperation::operation
private

Definition at line 45 of file operator.h.

◆ op1Origin

IntPoint Beatmup::BitmapBinaryOperation::op1Origin
private

Definition at line 46 of file operator.h.

◆ op2Origin

IntPoint Beatmup::BitmapBinaryOperation::op2Origin
private

Definition at line 46 of file operator.h.

◆ outputOrigin

IntPoint Beatmup::BitmapBinaryOperation::outputOrigin
private

Definition at line 46 of file operator.h.

◆ cropWidth

int Beatmup::BitmapBinaryOperation::cropWidth
private

Definition at line 47 of file operator.h.

◆ cropHeight

int Beatmup::BitmapBinaryOperation::cropHeight
private

Definition at line 47 of file operator.h.


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