Beatmup
internal_bitmap.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, 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 "../basic_types.h"
22 #include "../context.h"
23 #include "../memory.h"
24 #include "abstract_bitmap.h"
25 #include <vector>
26 
27 namespace Beatmup {
28 
29  /**
30  Bitmap whose memory is managed by the Beatmup engine.
31  Main pixel data container used internally by Beatmup. Applications would typically use a different incarnation
32  of AbstractBitmap implementing I/O operations, and InternalBitmap instances are used to exchange data between
33  different processing entities (AbstractTask instances) within the application.
34  */
35  class InternalBitmap : public AbstractBitmap {
36  private:
38  int width, height;
40 
41  void lockPixelData();
42  inline void unlockPixelData() {}
43 
44  public:
45  /**
46  Creates a bitmap.
47  The new bitmap created this way is "dirty" (contains random content). It is up to the application to fill
48  it with a content (e.g., set to zero).
49  \param ctx A Beatmup context instance
50  \param pixelFormat Pixel format
51  \param width Bitmap width in pixels
52  \param height Bitmap height in pixels
53  \param allocate If `true`, a storage is allocated in RAM. Otherwise the allocation is deferred
54  till the first use of the bitmap data by CPU. It is convenient to not allocate
55  if the bitmap is only used as a texture handler to store intremediate data when
56  processing on GPU.
57  */
58  InternalBitmap(Context& ctx, PixelFormat pixelFormat, int width, int height, bool allocate = true);
59 
60  /**
61  Loads image from a BMP file.
62  \param ctx A Beatmup context instance
63  \param bmpFilename Name of the .bmp file to be loaded
64  Raises exceptions if the input file is not readable or not a valid BMP image.
65  */
66  InternalBitmap(Context& ctx, const char* bmpFilename);
67 
68  /**
69  Changes bitmap size. Reallocates the memory if necessary.
70  Bitmap becomes "dirty" (contains no valid content).
71  \param[in] width New width in pixels
72  \param[in] height New height in pixels
73  */
74  void reshape(int width, int height);
75 
76  const PixelFormat getPixelFormat() const;
77  const int getWidth() const;
78  const int getHeight() const;
79  const msize getMemorySize() const;
80  const pixbyte* getData(int x, int y) const;
81  pixbyte* getData(int x, int y);
82  };
83 
84 }
A very basic class for any image.
Context & ctx
context managing this bitmap
Aligned memory buffer.
Definition: memory.h:27
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Bitmap whose memory is managed by the Beatmup engine.
void unlockPixelData()
Unlocks access to the CPU memory buffer containing pixel data.
const pixbyte * getData(int x, int y) const
Returns a pointer to given pixel.
const int getHeight() const
Height of the texture in pixels.
const msize getMemorySize() const
Bitmap size in bytes.
const int getWidth() const
Width of the texture in pixels.
const PixelFormat getPixelFormat() const
Pixel format of the bitmap.
InternalBitmap(Context &ctx, PixelFormat pixelFormat, int width, int height, bool allocate=true)
Creates a bitmap.
void lockPixelData()
Locks access to the CPU memory buffer containing pixel data.
void reshape(int width, int height)
Changes bitmap size.
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