Beatmup
Beatmup::Crop Class Reference

A task to clip images on CPU. More...

#include <crop.h>

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

Public Member Functions

 Crop ()
 
ThreadIndex getMaxThreads () const
 Gives the upper limint on the number of threads the task may be performed by. More...
 
void setInput (AbstractBitmap *input)
 
void setOutput (AbstractBitmap *output)
 
void setCropRect (IntRectangle)
 Sets crop rectangle in input bitmap. More...
 
void setOutputOrigin (IntPoint)
 Sets top-left position of the clip rectangle in output bitmap. More...
 
bool isFit () const
 Checks if everything is fitted to make cropping. More...
 
- 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 ()
 

Static Public Member Functions

static AbstractBitmaprun (AbstractBitmap &bitmap, IntRectangle clipRect)
 Copies out a specified rect of a bitmap into another bitmap. More...
 
- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 

Protected Member Functions

virtual bool process (TaskThread &)
 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...
 

Private Attributes

AbstractBitmapinput
 
AbstractBitmapoutput
 input and output bitmaps More...
 
IntPoint outOrigin
 origin on output bitmap More...
 
IntRectangle cropRect
 clip rect on input bitmap 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...
 
- 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 task to clip images on CPU.

Definition at line 29 of file crop.h.

Constructor & Destructor Documentation

◆ Crop()

Crop::Crop ( )

Definition at line 67 of file crop.cpp.

67  : outOrigin(0, 0), cropRect(0, 0, 0, 0)
68 {}
IntRectangle cropRect
clip rect on input bitmap
Definition: crop.h:33
IntPoint outOrigin
origin on output bitmap
Definition: crop.h:32

Member Function Documentation

◆ process()

bool Crop::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 71 of file crop.cpp.

71  {
72  BitmapProcessing::pipeline<Kernels::Cropping>(*input, *output, cropRect, outOrigin);
73  return true;
74 }
AbstractBitmap * input
Definition: crop.h:31
AbstractBitmap * output
input and output bitmaps
Definition: crop.h:31

◆ beforeProcessing()

void Crop::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 77 of file crop.cpp.

77  {
78  NullTaskInput::check(input, "input bitmap");
79  NullTaskInput::check(output, "output bitmap");
81  if (!isFit()) {
82  BEATMUP_DEBUG_E("Crop rectangle does not fit to bitmaps: ((%d,%d),(%d,%d)) from %d x %d to put at (%d,%d) in %d x %d.",
87  throw RuntimeError("Crop rectangle does not fit to bitmaps");
88  }
89  lock<ProcessingTarget::CPU>(gpu, input, output);
90 }
bool isFit() const
Checks if everything is fitted to make cropping.
Definition: crop.cpp:118
CustomPoint< numeric > b
Definition: geometry.h:131
CustomPoint< numeric > a
Definition: geometry.h:131
void normalize()
Flips corners coordinates guaranteeing that it has a non negative area, i.e.
Definition: geometry.h:192
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.
static void check(const void *pointer, const char *which)
Definition: exception.h:115
#define BEATMUP_DEBUG_E(...)
Definition: debug.h:34

◆ afterProcessing()

void Crop::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 93 of file crop.cpp.

93  {
95 }
void unlock(AbstractBitmap *bitmap)
Drops a lock to the bitmap.

◆ getMaxThreads()

ThreadIndex Beatmup::Crop::getMaxThreads ( ) const
inlinevirtual

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 41 of file crop.h.

41 { return 1; }

◆ setInput()

void Crop::setInput ( AbstractBitmap input)

Definition at line 98 of file crop.cpp.

98  {
99  this->input = input;
100 }

◆ setOutput()

void Crop::setOutput ( AbstractBitmap output)

Definition at line 103 of file crop.cpp.

103  {
104  this->output = output;
105 }

◆ setCropRect()

void Crop::setCropRect ( IntRectangle  rect)

Sets crop rectangle in input bitmap.

Definition at line 108 of file crop.cpp.

108  {
109  cropRect = rect;
110 }
Beatmup::IntRectangle rect(x1, y1, x2, y2)

◆ setOutputOrigin()

void Crop::setOutputOrigin ( IntPoint  pos)

Sets top-left position of the clip rectangle in output bitmap.

Definition at line 113 of file crop.cpp.

113  {
114  outOrigin = pos;
115 }

◆ isFit()

bool Crop::isFit ( ) const

Checks if everything is fitted to make cropping.

Definition at line 118 of file crop.cpp.

118  {
119  if (!input || !output)
120  return false;
122  return false;
123  IntPoint corner = cropRect.b - cropRect.a - 1 + outOrigin;
124  if (!output->getSize().closedRectangle().isInside(corner))
125  return false;
126  return true;
127 }
const ImageResolution getSize() const
Returns the bitmap resolution within ImageResolution object.
bool isInside(const CustomPoint< numeric > &point) const
Test if a point is inside the rectangle (or on its the border)
Definition: geometry.h:252
IntRectangle closedRectangle() const

◆ run()

AbstractBitmap * Crop::run ( AbstractBitmap bitmap,
IntRectangle  clipRect 
)
static

Copies out a specified rect of a bitmap into another bitmap.

Definition at line 130 of file crop.cpp.

130  {
131  AbstractBitmap* out = new InternalBitmap(bitmap.getContext(), bitmap.getPixelFormat(), clipRect.width(), clipRect.height());
132  // after byte-aligning out must be zeroed (not very optimal...)
133  if (out->getSize().numPixels() != clipRect.getArea())
134  out->zero();
135  Crop clip;
136  clip.setInput(&bitmap);
137  clip.setOutput(out);
138  clip.setCropRect(clipRect);
139  bitmap.getContext().performTask(clip);
140  return out;
141 }
A very basic class for any image.
Context & getContext() const
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition: context.cpp:240
A task to clip images on CPU.
Definition: crop.h:29
void setOutput(AbstractBitmap *output)
Definition: crop.cpp:103
void setCropRect(IntRectangle)
Sets crop rectangle in input bitmap.
Definition: crop.cpp:108
void setInput(AbstractBitmap *input)
Definition: crop.cpp:98
numeric height() const
Definition: geometry.h:178
numeric getArea() const
Computes the rectangle area.
Definition: geometry.h:185
numeric width() const
Definition: geometry.h:174
Bitmap whose memory is managed by the Beatmup engine.
const PixelFormat getPixelFormat() const
Pixel format of the bitmap.
JNIEnv jlong jint out
Beatmup::InternalBitmap * bitmap

Member Data Documentation

◆ input

AbstractBitmap* Beatmup::Crop::input
private

Definition at line 31 of file crop.h.

◆ output

AbstractBitmap * Beatmup::Crop::output
private

input and output bitmaps

Definition at line 31 of file crop.h.

◆ outOrigin

IntPoint Beatmup::Crop::outOrigin
private

origin on output bitmap

Definition at line 32 of file crop.h.

◆ cropRect

IntRectangle Beatmup::Crop::cropRect
private

clip rect on input bitmap

Definition at line 33 of file crop.h.


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