Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
ds_surface.h
1/* Copyright (C) 2017 - 2024, Thornwave Labs Inc - All Rights Reserved.
2 * Unauthorized copying of this file, via any medium is strictly prohibited.
3 * Proprietary and confidential.
4 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
5*/
6
7#ifndef _DS_SURFACE_H
8#define _DS_SURFACE_H
9
10#include <stdint.h>
11#include <stddef.h>
12
13#include <ds_color.h>
14#include <ds_types.h>
15#include <ds_geometry.h>
16#include <ds_allocator.h>
17
18
19
30{
31public:
46 DsSurface(int32_t width, int32_t height, const DsRotation &rotation, DsColorMode cmode, bool palette_has_alpha, size_t palette_size, ds_malloc_t fb_malloc, ds_free_t fb_free, uint32_t alignment = 32, size_t extra_data = 0);
47
48
59 DsSurface(uint32_t* stream, size_t size);
60
61
69 DsSurface(const DsSurface &src);
70
71
76
77
78
83 DsSize getSize(void) const;
84
85
90 DsRect getRegion(void) const;
91
92
97 void setUser(void* user);
98
99
104 void* getUser(void);
105
106
112
113
121 int32_t getPhysicalWidth(void) const;
122
130 int32_t getPhysicalHeight(void) const;
131
132
137 uint32_t getBpp(void) const;
138
139
147 uint32_t getPitch(void) const;
148
156 uint32_t getPitchPx(void) const;
157
158
164
169 uint8_t* getPixels(void);
170
175 size_t getFrameBufferSize(void) const;
176
181 uint16_t getPaletteSize(void) const;
182
187 bool doesPaletteHaveAlpha(void) const;
188
193 uint8_t* getPalette(void);
194
195
203 DsSurface getSubSurface(const DsRect &rect) const;
204
205
211 void clear(DsColor color);
212
213
221 void putPixel(int32_t x, int32_t y, DsColor color);
222
223
235 void copy(int32_t x, int32_t y, const DsSurface &src, DsAlphaMode alpha_mode, DsColor color);
236
237
250 void copy(int32_t x, int32_t y, const DsSurface &src, const DsRect &src_area, DsAlphaMode alpha_mode, DsColor color)
251 {
252 const DsSurface sub_surface = src.getSubSurface(src_area);
253 copy(x, y, sub_surface, alpha_mode, color);
254 }
255
256
268 void blend(int32_t x, int32_t y, const DsSurface &src, DsAlphaMode alpha_mode, DsColor color);
269
270
283 void blend(int32_t x, int32_t y, const DsSurface &src, const DsRect &src_area, DsAlphaMode alpha_mode, DsColor color)
284 {
285 const DsSurface sub_surface = src.getSubSurface(src_area);
286 blend(x, y, sub_surface, alpha_mode, color);
287 }
288
289
306 void blendAligned(const DsSurface &src, DsAlphaMode alpha_mode, DsColor color, const DsRect &boundary, const DsAlignment &alignment, const DsPoint &offset = DsPoint(0, 0));
307
311 void invert(void);
312
328 void replaceColor(DsColor match_color, bool match_mask_a, bool match_mask_r, bool match_mask_g, bool match_mask_b,
329 DsColor new_color, bool new_mask_a, bool new_mask_r, bool new_mask_g, bool new_mask_b);
330
331
341 void replaceColor(const DsSurface &src, bool replace_a, bool replace_r, bool replace_g, bool replace_b);
342
343
349 void replaceAlpha(const DsSurface &alpha_only_src);
350
351
358
365 size_t saveStream(uint32_t* stream);
366
367
371 void rotateXY(int32_t &x, int32_t &y) const;
372
376 void rotateXY(float &x, float &y) const;
377
381 void rotateWH(int32_t &w, int32_t &h) const;
382
386 void rotateWH(float &w, float &h) const;
387
391 void rotateRect(DsRect &rect) const;
392
396 void rotateRect(DsFRect &rect) const;
397
401 void unrotateRect(DsRect &rect) const;
402
406 void unrotateRect(DsFRect &rect) const;
407
408private:
409 friend class DsRenderer;
410 friend class DsScreen;
411 friend class DsView;
412
413 void* mUser;
414
415 ds_malloc_t mFbMalloc;
416 ds_free_t mFbFree;
417
418 DsRotation mRotation;
419
420 int32_t mWidth;
421 int32_t mHeight;
422
423 DsColorMode mColorMode;
424 size_t mExtraData;
425 size_t mAlignment;
426
427 size_t mBytesPerPixel;
428 size_t mPitch;
429
430 size_t mPitchPx;
431
432 bool mPaletteHasAlpha;
433 size_t mPaletteSize;
434
435 DsRect mClipRegion;
436
437 uint8_t* mPixels;
438 uint8_t* mPalette;
439
440 size_t computePitch(size_t with);
441
447 void setClipRegion(const DsRect &region);
448
449
455 DsRect getClipRegion(void) const;
456
457
461 void resetClipRegion(void);
462};
463
464
465#endif
DsAlignment is a class representing both horizontal and vertical alignment type.
Definition ds_types.h:130
DsColor is a class that represents a 4 channel color (Alpha, Red, Green, Blue).
Definition ds_color.h:53
DsFRect is a class that represents a 2D rectangle (X, Y, W, H) using floating point coordiantes and s...
Definition ds_geometry.h:2059
DsPoint is a class that represents the X and Y 2D coordinates of a point as integer numbers.
Definition ds_geometry.h:24
DsRect is a class that represents a 2D rectangle (X, Y, W, H)
Definition ds_geometry.h:1507
DsRenderer is a class that implements all the drawing operations.
Definition ds_renderer.h:42
DsScreen is class of type DsView (inherits from DsView) that implements a physical screen.
Definition ds_screen.h:29
DsSize is class that represents the 2D size of a graphic object (width, height) as integer values.
Definition ds_geometry.h:780
DsSurface is a class that represents a drawing surface.
Definition ds_surface.h:30
DsColorMode getColorMode(void) const
Gets the color mode of the surface.
uint8_t * getPixels(void)
Gets the address of the framebuffer.
uint32_t getPitch(void) const
Gets the pitch of the surface (number of bytes to add to a pixel to advance exactly one line).
void replaceColor(DsColor match_color, bool match_mask_a, bool match_mask_r, bool match_mask_g, bool match_mask_b, DsColor new_color, bool new_mask_a, bool new_mask_r, bool new_mask_g, bool new_mask_b)
Replaces a the color component of each pixel in the surface with a new value.
size_t saveStream(uint32_t *stream)
Saves the DsSurface object in the specified stream.
DsSurface(int32_t width, int32_t height, const DsRotation &rotation, DsColorMode cmode, bool palette_has_alpha, size_t palette_size, ds_malloc_t fb_malloc, ds_free_t fb_free, uint32_t alignment=32, size_t extra_data=0)
Creates a surface, allocates the framebuffer and the pallete table (if required)
void * getUser(void)
Gets the user pointer attached to the surface.
int32_t getPhysicalHeight(void) const
Gets the physical height of the framebuffer.
uint32_t getBpp(void) const
Gets the number of bytes per pixel of the surface. This value depends on the color mode of the frameb...
void putPixel(int32_t x, int32_t y, DsColor color)
Sets the color of a pixel within the surface.
size_t getFrameBufferSize(void) const
Gets the total size in bytes of the framebuffer (allocated size)
DsRect getRegion(void) const
Return the rectangular region of the surface (logical).
DsRotation getRotation(void) const
Gets the surface rotation.
bool doesPaletteHaveAlpha(void) const
Does the palette have the alpha channel?
int32_t getPhysicalWidth(void) const
Gets the physical width of the framebuffer.
void rotateFrameBuffer(DsRotation rotation)
Rotates the entire framebuffer counter-clockwise.
void copy(int32_t x, int32_t y, const DsSurface &src, DsAlphaMode alpha_mode, DsColor color)
Copies an entire surface to the current surface object respecting the clipping region.
void unrotateRect(DsFRect &rect) const
Rotates a rectangle to match the screen framebuffer rotation.
void copy(int32_t x, int32_t y, const DsSurface &src, const DsRect &src_area, DsAlphaMode alpha_mode, DsColor color)
Copies a region of a surface to the current surface object respecting the clipping region.
Definition ds_surface.h:250
void rotateRect(DsFRect &rect) const
Rotates a rectangle to match the screen framebuffer rotation.
uint8_t * getPalette(void)
Gets the address of the palette.
void rotateXY(float &x, float &y) const
Rotates the coordinate system to match the screen framebuffer rotation.
DsSurface getSubSurface(const DsRect &rect) const
Returns a subsurface of the existing surface. The same framebuffer is used.
void invert(void)
Inverts all the pixel values in a surface at a byte level.
void setUser(void *user)
Sets the user pointer attached to the surface.
~DsSurface()
Destructor - frees the frame buffer and the palette table.
void rotateXY(int32_t &x, int32_t &y) const
Rotates the coordinate system to match the screen framebuffer rotation.
DsSurface(uint32_t *stream, size_t size)
Creates a surface, allocates the framebuffer and the pallete table (if required) using a stream of by...
void replaceColor(const DsSurface &src, bool replace_a, bool replace_r, bool replace_g, bool replace_b)
Replaces the color components of each pixel in the surface with the components of the corresponding p...
void rotateWH(float &w, float &h) const
Rotates the size (W, H) to match the screen framebuffer rotation.
void unrotateRect(DsRect &rect) const
Rotates a rectangle to match the screen framebuffer rotation.
void replaceAlpha(const DsSurface &alpha_only_src)
Replaces the alpha channel of each pixel in the surface with the alpha of the corresponding pixel in ...
void rotateRect(DsRect &rect) const
Rotates a rectangle to match the screen framebuffer rotation.
void blend(int32_t x, int32_t y, const DsSurface &src, DsAlphaMode alpha_mode, DsColor color)
Blends an entire surface to the current surface object respecting the clipping region.
void blend(int32_t x, int32_t y, const DsSurface &src, const DsRect &src_area, DsAlphaMode alpha_mode, DsColor color)
Blends a region of a surface to the current surface object respecting the clipping region.
Definition ds_surface.h:283
DsSize getSize(void) const
Return the logical size of the surface in pixels.
uint16_t getPaletteSize(void) const
Gets the total size in bytes of the pallete (allocated size)
void blendAligned(const DsSurface &src, DsAlphaMode alpha_mode, DsColor color, const DsRect &boundary, const DsAlignment &alignment, const DsPoint &offset=DsPoint(0, 0))
Blends an entire surface to the current surface object respecting the clipping region.
void rotateWH(int32_t &w, int32_t &h) const
Rotates the size (W, H) to match the screen framebuffer rotation.
void clear(DsColor color)
Fills the surface with a specified color respecting the clip region.
DsSurface(const DsSurface &src)
Copy constructor - creates a copy of a surface. This will share the same framebuffer as the original ...
uint32_t getPitchPx(void) const
Gets the pitch of the surface (number of pixels to add to a pixel to advance exactly one line).
DsView is a base class that represents any view on the screen.
Definition ds_view.h:40
DsAlphaMode
AlphaMode is an enumeration of all possible alpha channel modes. These modes determine how the alpha ...
Definition ds_color.h:41
DsColorMode
DsColorMode is an enumeration of all possible color modes. These modes determine the color format use...
Definition ds_color.h:25
DsRotation
DsRotation is an enumeration of all possible values of the rotation used in drawing operations.
Definition ds_types.h:34