Beatmup
Beatmup::Android::Bitmap Class Reference

Wrapper of Android.Graphics.Bitmap object. More...

#include <bitmap.h>

Inheritance diagram for Beatmup::Android::Bitmap:
Beatmup::AbstractBitmap Beatmup::GL::TextureHandler Beatmup::Object

Public Member Functions

 Bitmap (Beatmup::Context &, JNIEnv *, jobject)
 Creates the bitmap from Android Bitmap java object. More...
 
 ~Bitmap ()
 
const PixelFormat getPixelFormat () const
 Pixel format of the bitmap. More...
 
const int getWidth () const
 Width of the texture in pixels. More...
 
const int getHeight () const
 Height of the texture in pixels. More...
 
const pixbytegetData (int x, int y) const
 Returns a pointer to given pixel. More...
 
pixbytegetData (int x, int y)
 
const msize getMemorySize () const
 Bitmap size in bytes. More...
 
- Public Member Functions inherited from Beatmup::AbstractBitmap
virtual const int getDepth () const
 Depth of the texture in pixels. More...
 
virtual const TextureFormat getTextureFormat () const
 Returns the texture format specifying how the shader must interpret the data. More...
 
bool isUpToDate (ProcessingTarget) const
 
bool isDirty () const
 Returns true if the bitmap does not contain any valid content. More...
 
int getPixelInt (int x, int y, int cha=0) const
 Retrieves integer value of given channel at given pixel. More...
 
const unsigned char getBitsPerPixel () const
 Returns number of bits per pixel stored in each bitmap. More...
 
const unsigned char getNumberOfChannels () const
 Returns number of bytes per pixel stored in each bitmap. More...
 
const ImageResolution getSize () const
 Returns the bitmap resolution within ImageResolution object. More...
 
ContextgetContext () const
 
void zero ()
 Sets all the pixels to zero. More...
 
bool isInteger () const
 Returns true if the bitmap contains integer values, false otherwise. More...
 
bool isFloat () const
 Returns true if the bitmap contains floating point values, false otherwise. More...
 
bool isMask () const
 Returns true if the bitmap is a mask, false otherwise. More...
 
std::string toString () const
 Retruns a string describing the bitmap. More...
 
void saveBmp (const char *filename)
 Saves the bitmap to a BMP file. More...
 
 ~AbstractBitmap ()
 
- Public Member Functions inherited from Beatmup::GL::TextureHandler
 ~TextureHandler ()
 
float getAspectRatio () const
 Aspect ratio of the texture. More...
 
float getInvAspectRatio () const
 Inverse of the aspect ratio of the texture. More...
 
const bool isFloatingPoint () const
 
const int getNumberOfChannels () const
 Returns number of channels containing in the texture. More...
 
bool hasValidHandle () const
 Returns true if the texture handle points to a valid texture. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Private Member Functions

AndroidBitmapInfo getInfo () const
 
JNIEnv * getEnv () const
 
void lockPixelData ()
 Locks access to the CPU memory buffer containing pixel data. More...
 
void unlockPixelData ()
 Unlocks access to the CPU memory buffer containing pixel data. More...
 

Private Attributes

jobject bitmap
 java object representing the bitmap More...
 
JavaVM * jvm
 java environment More...
 
void * lockedPixels
 pixel buffer; available only after calling lockPixelData() More...
 
int lockedWidth
 
int lockedHeight
 
PixelFormat lockedPixelFormat
 

Additional Inherited Members

- Public Types inherited from Beatmup::GL::TextureHandler
enum  TextureFormat {
  Rx8 , RGBx8 , RGBAx8 , Rx32f ,
  RGBx32f , RGBAx32f , OES_Ext
}
 Texture format, specifies how the texture should be interpreted on the shader side. More...
 
- Static Public Member Functions inherited from Beatmup::AbstractBitmap
static bool isInteger (PixelFormat pixelFormat)
 Returns true if a given pixel format corresponds to integer values, false otherwise. More...
 
static bool isFloat (PixelFormat pixelFormat)
 Returns true if a given pixel format corresponds to floating point values, false otherwise. More...
 
static bool isMask (PixelFormat pixelFormat)
 Returns true if a given pixel format corresponds to a mask, false otherwise. More...
 
- Static Public Member Functions inherited from Beatmup::GL::TextureHandler
static const char * textureFormatToString (const TextureFormat &)
 
- Static Public Attributes inherited from Beatmup::AbstractBitmap
static const int NUM_PIXEL_FORMATS = 9
 
static const char * PIXEL_FORMAT_NAMES [NUM_PIXEL_FORMATS]
 pixel format names More...
 
static const unsigned char CHANNELS_PER_PIXEL [NUM_PIXEL_FORMATS]
 number of channels for each pixel format More...
 
static const unsigned char BITS_PER_PIXEL [NUM_PIXEL_FORMATS]
 number of bits per pixel for each pixel format More...
 
- Static Public Attributes inherited from Beatmup::GL::TextureHandler
static const int TEXTURE_FORMAT_BYTES_PER_PIXEL []
 size of a texel in bytes for different texture formats More...
 
- Protected Member Functions inherited from Beatmup::AbstractBitmap
 AbstractBitmap (Context &ctx)
 
virtual void prepare (GraphicPipeline &gpu)
 Prepares (eventually uploads) texture data on GPU. More...
 
- Protected Member Functions inherited from Beatmup::GL::TextureHandler
 TextureHandler ()
 
void invalidate (RecycleBin &)
 Forces disposing the texture data, e.g. More...
 
- Protected Attributes inherited from Beatmup::AbstractBitmap
Contextctx
 context managing this bitmap More...
 
bool upToDate [2]
 bitmap up-to-date state on CPU and GPU More...
 
- Protected Attributes inherited from Beatmup::GL::TextureHandler
handle_t textureHandle
 

Detailed Description

Wrapper of Android.Graphics.Bitmap object.

Definition at line 34 of file bitmap.h.

Constructor & Destructor Documentation

◆ Bitmap()

Beatmup::Android::Bitmap::Bitmap ( Beatmup::Context ,
JNIEnv *  ,
jobject   
)

Creates the bitmap from Android Bitmap java object.

◆ ~Bitmap()

Bitmap::~Bitmap ( )

Definition at line 51 of file bitmap.cpp.

51  {
52  getEnv()->DeleteGlobalRef(bitmap);
53 }
JNIEnv * getEnv() const
Definition: bitmap.cpp:28
jobject bitmap
java object representing the bitmap
Definition: bitmap.h:36

Member Function Documentation

◆ getInfo()

AndroidBitmapInfo Bitmap::getInfo ( ) const
private

Definition at line 56 of file bitmap.cpp.

56  {
57  AndroidBitmapInfo info;
58  int result = AndroidBitmap_getInfo(getEnv(), bitmap, &info);
59  if (result < 0)
60  throw RuntimeError("AndroidBitmap_getInfo() failed");
61  return info;
62 }
Beatmup::IntPoint result

◆ getEnv()

JNIEnv * Bitmap::getEnv ( ) const
private

Definition at line 28 of file bitmap.cpp.

28  {
29  JNIEnv *env;
30  jvm->AttachCurrentThread(&env, NULL);
31  return env;
32 }
JavaVM * jvm
java environment
Definition: bitmap.h:37

◆ lockPixelData()

void Bitmap::lockPixelData ( )
privatevirtual

Locks access to the CPU memory buffer containing pixel data.

Implements Beatmup::AbstractBitmap.

Definition at line 96 of file bitmap.cpp.

96  {
101  int result = AndroidBitmap_lockPixels(getEnv(), bitmap, &lockedPixels);
102  if (result < 0)
103  throw RuntimeError("AndroidBitmap_lockPixels() failed with error");
104 }
const int getWidth() const
Width of the texture in pixels.
Definition: bitmap.cpp:82
const PixelFormat getPixelFormat() const
Pixel format of the bitmap.
Definition: bitmap.cpp:65
void * lockedPixels
pixel buffer; available only after calling lockPixelData()
Definition: bitmap.h:39
PixelFormat lockedPixelFormat
Definition: bitmap.h:41
const int getHeight() const
Height of the texture in pixels.
Definition: bitmap.cpp:89
#define BEATMUP_ASSERT_DEBUG(C)
Definition: exception.h:163

◆ unlockPixelData()

void Bitmap::unlockPixelData ( )
privatevirtual

Unlocks access to the CPU memory buffer containing pixel data.

Implements Beatmup::AbstractBitmap.

Definition at line 107 of file bitmap.cpp.

107  {
109  AndroidBitmap_unlockPixels(getEnv(), bitmap);
110  lockedPixels = nullptr;
111 }

◆ getPixelFormat()

const PixelFormat Bitmap::getPixelFormat ( ) const
virtual

Pixel format of the bitmap.

Implements Beatmup::AbstractBitmap.

Definition at line 65 of file bitmap.cpp.

65  {
66  if (lockedPixels)
67  return lockedPixelFormat;
68 
69  AndroidBitmapFormat format = (AndroidBitmapFormat) getInfo().format;
70  switch (format) {
71  case ANDROID_BITMAP_FORMAT_RGBA_8888:
72  return QuadByte;
73  case ANDROID_BITMAP_FORMAT_A_8:
74  return SingleByte;
75  default:
76  Insanity::insanity("AndroidBitmap_getInfo() returned unexpected format");
77  return SingleByte;
78  }
79 }
AndroidBitmapInfo getInfo() const
Definition: bitmap.cpp:56
static void insanity(const char *message)
Definition: exception.h:136
@ SingleByte
single channel of 8 bits per pixel (like grayscale), unsigned integer values
@ QuadByte
4 channels of 8 bits per pixel (like RGBA), unsigned integer values
JNIEnv jobject jint format

◆ getWidth()

const int Bitmap::getWidth ( ) const
virtual

Width of the texture in pixels.

Implements Beatmup::GL::TextureHandler.

Definition at line 82 of file bitmap.cpp.

82  {
83  if (lockedPixels)
84  return lockedWidth;
85  return getInfo().width;
86 }

◆ getHeight()

const int Bitmap::getHeight ( ) const
virtual

Height of the texture in pixels.

Implements Beatmup::GL::TextureHandler.

Definition at line 89 of file bitmap.cpp.

89  {
90  if (lockedPixels)
91  return lockedHeight;
92  return getInfo().height;
93 }

◆ getData() [1/2]

const pixbyte * Bitmap::getData ( int  x,
int  y 
) const
virtual

Returns a pointer to given pixel.

Parameters
xtarget pixel horizontal coordinate
ytarget pixel vertical coordinate
Returns
a pointer, may be NULL.

Implements Beatmup::AbstractBitmap.

Definition at line 114 of file bitmap.cpp.

114  {
115  RuntimeError::check(lockedPixels, "No pixel data available. Forget to lock the bitmap?");
116  if (x < 0 || y < 0 || x >= lockedWidth || y >= lockedHeight)
117  return nullptr;
118  msize n = y * lockedWidth + x;
119  return (pixbyte*)( (unsigned char*)lockedPixels + n * BITS_PER_PIXEL[lockedPixelFormat] / 8 );
120 }
static const unsigned char BITS_PER_PIXEL[NUM_PIXEL_FORMATS]
number of bits per pixel for each pixel format
static void check(const bool condition, const std::string &message)
Definition: exception.h:64
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
int n

◆ getData() [2/2]

pixbyte * Bitmap::getData ( int  x,
int  y 
)
virtual

Implements Beatmup::AbstractBitmap.

Definition at line 123 of file bitmap.cpp.

123  {
124  RuntimeError::check(lockedPixels, "No pixel data available. Forget to lock the bitmap?");
125  if (x < 0 || y < 0 || x >= lockedWidth || y >= lockedHeight)
126  return nullptr;
127  msize n = y * lockedWidth + x;
128  return (pixbyte*)( (unsigned char*)lockedPixels + n * BITS_PER_PIXEL[lockedPixelFormat] / 8 );
129 }

◆ getMemorySize()

const msize Bitmap::getMemorySize ( ) const
virtual

Bitmap size in bytes.

Implements Beatmup::AbstractBitmap.

Definition at line 132 of file bitmap.cpp.

132  {
133  return getWidth() * getHeight() * BITS_PER_PIXEL[ getPixelFormat() ] / 8;
134 }

Member Data Documentation

◆ bitmap

jobject Beatmup::Android::Bitmap::bitmap
private

java object representing the bitmap

Definition at line 36 of file bitmap.h.

◆ jvm

JavaVM* Beatmup::Android::Bitmap::jvm
private

java environment

Definition at line 37 of file bitmap.h.

◆ lockedPixels

void* Beatmup::Android::Bitmap::lockedPixels
private

pixel buffer; available only after calling lockPixelData()

Definition at line 39 of file bitmap.h.

◆ lockedWidth

int Beatmup::Android::Bitmap::lockedWidth
private

Definition at line 40 of file bitmap.h.

◆ lockedHeight

int Beatmup::Android::Bitmap::lockedHeight
private

Definition at line 40 of file bitmap.h.

◆ lockedPixelFormat

PixelFormat Beatmup::Android::Bitmap::lockedPixelFormat
private

Definition at line 41 of file bitmap.h.


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