Beatmup
Beatmup::InternalBitmap Class Reference

Bitmap whose memory is managed by the Beatmup engine. More...

#include <internal_bitmap.h>

Inheritance diagram for Beatmup::InternalBitmap:
Beatmup::AbstractBitmap Beatmup::GL::TextureHandler Beatmup::Object

Public Member Functions

 InternalBitmap (Context &ctx, PixelFormat pixelFormat, int width, int height, bool allocate=true)
 Creates a bitmap. More...
 
 InternalBitmap (Context &ctx, const char *bmpFilename)
 Loads image from a BMP file. More...
 
void reshape (int width, int height)
 Changes bitmap size. More...
 
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 msize getMemorySize () const
 Bitmap size in bytes. More...
 
const pixbytegetData (int x, int y) const
 Returns a pointer to given pixel. More...
 
pixbytegetData (int x, int y)
 
- 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

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

PixelFormat pixelFormat
 
int width
 
int height
 
AlignedMemory memory
 

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

Bitmap whose memory is managed by the Beatmup engine.

Main pixel data container used internally by Beatmup. Applications would typically use a different incarnation of AbstractBitmap implementing I/O operations, and InternalBitmap instances are used to exchange data between different processing entities (AbstractTask instances) within the application.

Definition at line 35 of file internal_bitmap.h.

Constructor & Destructor Documentation

◆ InternalBitmap() [1/2]

InternalBitmap::InternalBitmap ( Context ctx,
PixelFormat  pixelFormat,
int  width,
int  height,
bool  allocate = true 
)

Creates a bitmap.

The new bitmap created this way is "dirty" (contains random content). It is up to the application to fill it with a content (e.g., set to zero).

Parameters
ctxA Beatmup context instance
pixelFormatPixel format
widthBitmap width in pixels
heightBitmap height in pixels
allocateIf true, a storage is allocated in RAM. Otherwise the allocation is deferred till the first use of the bitmap data by CPU. It is convenient to not allocate if the bitmap is only used as a texture handler to store intremediate data when processing on GPU.

Definition at line 27 of file internal_bitmap.cpp.

27  :
30 {
31  if (getBitsPerPixel() < 8) {
32  int n = 8 / getBitsPerPixel();
33  this->width = ceili(width, n) * n;
34  }
35  if (allocate)
37  upToDate[ProcessingTarget::CPU] = allocate;
38 }
Context & ctx
context managing this bitmap
const unsigned char getBitsPerPixel() const
Returns number of bits per pixel stored in each bitmap.
AbstractBitmap(const AbstractBitmap &that)=delete
disabling copying constructor
bool upToDate[2]
bitmap up-to-date state on CPU and GPU
Aligned memory buffer.
Definition: memory.h:27
const msize getMemorySize() const
Bitmap size in bytes.
#define ceili(x, y)
integer division x/y with ceiling
Definition: utils.hpp:21
int n

◆ InternalBitmap() [2/2]

InternalBitmap::InternalBitmap ( Context ctx,
const char *  bmpFilename 
)

Loads image from a BMP file.

Parameters
ctxA Beatmup context instance
bmpFilenameName of the .bmp file to be loaded Raises exceptions if the input file is not readable or not a valid BMP image.

Definition at line 41 of file internal_bitmap.cpp.

41  :
43 {
44  // read header
45  BmpFile bmp(bmpFilename);
46  switch (bmp.getBitsPerPixel()) {
47  case 1:
49  break;
50  case 4:
52  break;
53  case 8:
55  break;
56  case 24:
58  break;
59  case 32:
61  break;
62  default:
63  throw IOError(bmpFilename, "Unsupported pixel format");
64  }
65  this->width = bmp.getWidth();
66  this->height = bmp.getHeight();
67 
68  // allocate & read
70  bmp.load(memory(), getMemorySize());
71 }
Toolset to load and store images in BMP format.
Definition: bmp_file.h:28
@ 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
@ TripleByte
3 channels of 8 bits per pixel (like RGB), unsigned integer values
@ BinaryMask
1 bit per pixel
@ HexMask
4 bits per pixel

Member Function Documentation

◆ lockPixelData()

void InternalBitmap::lockPixelData ( )
privatevirtual

Locks access to the CPU memory buffer containing pixel data.

Implements Beatmup::AbstractBitmap.

Definition at line 123 of file internal_bitmap.cpp.

123  {
124  if (!memory)
126 }

◆ unlockPixelData()

void Beatmup::InternalBitmap::unlockPixelData ( )
inlineprivatevirtual

Unlocks access to the CPU memory buffer containing pixel data.

Implements Beatmup::AbstractBitmap.

Definition at line 42 of file internal_bitmap.h.

42 {}

◆ reshape()

void Beatmup::InternalBitmap::reshape ( int  width,
int  height 
)

Changes bitmap size.

Reallocates the memory if necessary. Bitmap becomes "dirty" (contains no valid content).

Parameters
[in]widthNew width in pixels
[in]heightNew height in pixels

Definition at line 74 of file internal_bitmap.cpp.

74  {
75  if (this->width * this->height != width * height && memory) {
76  this->width = width;
77  this->height = height;
79  }
80  else {
81  this->width = width;
82  this->height = height;
83  }
84 
86  TextureHandler::invalidate(*ctx.getGpuRecycleBin());
87 
90 }
GL::RecycleBin * getGpuRecycleBin() const
Definition: context.cpp:340

◆ getPixelFormat()

const PixelFormat InternalBitmap::getPixelFormat ( ) const
virtual

Pixel format of the bitmap.

Implements Beatmup::AbstractBitmap.

Definition at line 93 of file internal_bitmap.cpp.

93  {
94  return pixelFormat;
95 }

◆ getWidth()

const int InternalBitmap::getWidth ( ) const
virtual

Width of the texture in pixels.

Implements Beatmup::GL::TextureHandler.

Definition at line 98 of file internal_bitmap.cpp.

98  {
99  return width;
100 }

◆ getHeight()

const int InternalBitmap::getHeight ( ) const
virtual

Height of the texture in pixels.

Implements Beatmup::GL::TextureHandler.

Definition at line 103 of file internal_bitmap.cpp.

103  {
104  return height;
105 }

◆ getMemorySize()

const msize InternalBitmap::getMemorySize ( ) const
virtual

Bitmap size in bytes.

Implements Beatmup::AbstractBitmap.

Definition at line 108 of file internal_bitmap.cpp.

108  {
109  // a proper way to compute required memory size (works for bpp < 8)
111 }
static const unsigned char BITS_PER_PIXEL[NUM_PIXEL_FORMATS]
number of bits per pixel for each pixel format

◆ getData() [1/2]

const pixbyte * InternalBitmap::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 internal_bitmap.cpp.

114  {
116 }
datatype * ptr(int offset=0)
Definition: memory.h:46
uint8_t pixbyte
Definition: basic_types.h:34
jobject jlong jint jint y
jobject jlong jint x

◆ getData() [2/2]

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

Implements Beatmup::AbstractBitmap.

Definition at line 118 of file internal_bitmap.cpp.

118  {
120 }

Member Data Documentation

◆ pixelFormat

PixelFormat Beatmup::InternalBitmap::pixelFormat
private

Definition at line 37 of file internal_bitmap.h.

◆ width

int Beatmup::InternalBitmap::width
private

Definition at line 38 of file internal_bitmap.h.

◆ height

int Beatmup::InternalBitmap::height
private

Definition at line 38 of file internal_bitmap.h.

◆ memory

AlignedMemory Beatmup::InternalBitmap::memory
private

Definition at line 39 of file internal_bitmap.h.


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