Beatmup
Kernels::Cropping< in_t, out_t > Class Template Reference

Static Public Member Functions

static void process (AbstractBitmap &input, AbstractBitmap &output, const IntRectangle &rect, const IntPoint &outOrigin)
 

Detailed Description

template<class in_t, class out_t>
class Kernels::Cropping< in_t, out_t >

Definition at line 31 of file crop.cpp.

Member Function Documentation

◆ process()

template<class in_t , class out_t >
static void Kernels::Cropping< in_t, out_t >::process ( AbstractBitmap input,
AbstractBitmap output,
const IntRectangle rect,
const IntPoint outOrigin 
)
inlinestatic

Definition at line 33 of file crop.cpp.

33  {
34  const unsigned char
35  bpp = AbstractBitmap::BITS_PER_PIXEL[input.getPixelFormat()],
36  ppb = 8 / bpp; // pixels per byte
37 
38  // test if output origin and clip rect horizontal borders are byte-aligned and the pixel formats are identical
39  const bool mayCopy = (input.getPixelFormat() == output.getPixelFormat()) &&
40  (bpp >= 8 || (outOrigin.x % ppb == 0 && rect.a.x % ppb == 0 && rect.b.x % ppb == 0));
41 
42  in_t in(input);
43  out_t out(output);
44 
45  if (mayCopy) {
46  // direct copying
47  const msize lineSizeBytes = bpp >= 8 ? rect.width() * bpp / 8 : rect.width() / ppb;
48  for (int y = rect.a.y; y < rect.b.y; ++y) {
49  out.goTo(outOrigin.x, outOrigin.y + y - rect.a.y);
50  in.goTo(rect.a.x, y);
51  memcpy(*out, *in, lineSizeBytes);
52  }
53  }
54  else
55  // projecting
56  for (int y = rect.a.y; y < rect.b.y; ++y) {
57  out.goTo(outOrigin.x, outOrigin.y + y - rect.a.y);
58  in.goTo(rect.a.x, y);
59  for (int x = rect.a.x; x < rect.b.x; ++x, in++, out++)
60  out = in();
61  }
62  }
virtual const PixelFormat getPixelFormat() const =0
Pixel format of the bitmap.
CustomPoint< numeric > b
Definition: geometry.h:131
numeric width() const
Definition: geometry.h:174
CustomPoint< numeric > a
Definition: geometry.h:131
uint32_t msize
memory size
Definition: basic_types.h:30
jobject jlong jint jint y
jobject jlong jint x
JNIEnv jlong jint out
Beatmup::IntPoint outOrigin(left, top)
Beatmup::IntRectangle rect(x1, y1, x2, y2)

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