Beatmup
bitmap.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 
21 #include <pybind11/numpy.h>
22 
23 #include "bitmap/abstract_bitmap.h"
24 #include "context.h"
25 
26 namespace Beatmup {
27  /**
28  %Python binding utilities
29  */
30  namespace Python {
31 
32  /**
33  Wrapper of Android.Graphics.Bitmap object
34  */
35  class Bitmap : public AbstractBitmap {
36  private:
37  pybind11::buffer_info data;
40 
41  void lockPixelData() {}
42  void unlockPixelData() {}
43 
44  public:
45  /**
46  Creates the bitmap from Android Bitmap java object
47  */
48  Bitmap(Beatmup::Context& context, pybind11::buffer& buffer);
49 
50  inline const PixelFormat getPixelFormat() const { return format; };
51 
52  inline const int getWidth() const { return (int)data.shape[data.ndim - 2]; }
53 
54  inline const int getHeight() const { return (int)data.shape[data.ndim - 3]; }
55 
56  const pixbyte* getData(int x, int y) const;
57  pixbyte* getData(int x, int y);
58 
59  const msize getMemorySize() const;
60 
61  /**
62  Returns a mutable python buffer containing bitmap data.
63  */
64  inline pybind11::buffer_info getPythonBuffer() {
65 #ifdef BEATMUP_DEBUG
66  DebugAssertion::check(isUpToDate(ProcessingTarget::CPU), "Returning a buffer for outdated Python bitmap");
67 #endif
68  return pybind11::buffer_info(data.ptr, data.itemsize, data.format, data.ndim, data.shape, data.strides, false);
69  }
70  };
71 
72  }
73 }
A very basic class for any image.
bool isUpToDate(ProcessingTarget) const
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Wrapper of Android.Graphics.Bitmap object.
Definition: bitmap.h:35
void unlockPixelData()
Unlocks access to the CPU memory buffer containing pixel data.
Definition: bitmap.h:42
const PixelFormat getPixelFormat() const
Pixel format of the bitmap.
Definition: bitmap.h:50
const int getHeight() const
Height of the texture in pixels.
Definition: bitmap.h:54
const msize getMemorySize() const
Bitmap size in bytes.
Definition: bitmap.cpp:87
void lockPixelData()
Locks access to the CPU memory buffer containing pixel data.
Definition: bitmap.h:41
pybind11::buffer_info getPythonBuffer()
Returns a mutable python buffer containing bitmap data.
Definition: bitmap.h:64
const int getWidth() const
Width of the texture in pixels.
Definition: bitmap.h:52
pybind11::buffer_info data
Definition: bitmap.h:37
Bitmap(Beatmup::Context &context, pybind11::buffer &buffer)
Creates the bitmap from Android Bitmap java object.
Definition: bitmap.cpp:25
PixelFormat format
Definition: bitmap.h:38
const pixbyte * getData(int x, int y) const
Returns a pointer to given pixel.
Definition: bitmap.cpp:77
uint32_t msize
memory size
Definition: basic_types.h:30
uint8_t pixbyte
Definition: basic_types.h:34
jobject jlong jint jint y
jobject jlong jint x