28 auto info = buffer.request();
32 throw std::invalid_argument(
"A bitmap cannot be empty");
36 throw std::invalid_argument(
"A bitmap is expected to have at least 3 dimensions");
38 for (
int i = 0; i + 3 < info.ndim; ++i)
39 if (info.shape[i] != 1)
40 throw std::invalid_argument(
"A bitmap is expected to have at most 3 inner non-singleton dimensions.");
43 static const char* FORMAT_UINT8 =
"B";
44 static const char* FORMAT_FLOAT =
"f";
45 const auto numChannels = info.shape[info.ndim - 1];
47 if (info.format == FORMAT_UINT8)
48 switch (numChannels) {
53 throw std::invalid_argument(
"A bitmap may have 1, 3 of 4 channels, but got " +
std::to_string(numChannels));
55 else if (info.format == FORMAT_FLOAT)
56 switch (numChannels) {
61 throw std::invalid_argument(
"A bitmap may have 1, 3 of 4 channels, but got " +
std::to_string(numChannels));
64 throw std::invalid_argument(
"Unsupported data format. Expected bitmap values of type float32 or uint8.");
69 if (info.strides[info.ndim - 1] * numChannels != bps || info.strides[info.ndim - 2] != bps || info.strides[info.ndim - 3] !=
strideBytes)
70 throw std::invalid_argument(
"Strided bitmaps are not supported.");
73 data = std::move(info);
78 return static_cast<const pixbyte*
>(data.ptr) +
y * strideBytes +
x;
83 return static_cast<pixbyte*
>(data.ptr) +
y * strideBytes +
x;
88 return data.itemsize * data.size;
A very basic class for any image.
const unsigned char getBitsPerPixel() const
Returns number of bits per pixel stored in each bitmap.
Basic class: task and memory management, any kind of static data.
const msize getMemorySize() const
Bitmap size in bytes.
pybind11::buffer_info data
Bitmap(Beatmup::Context &context, pybind11::buffer &buffer)
Creates the bitmap from Android Bitmap java object.
const pixbyte * getData(int x, int y) const
Returns a pointer to given pixel.
uint32_t msize
memory size
@ 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
@ 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
std::string to_string(Beatmup::NNets::ActivationFunction function)
jobject jlong jint jint y