Loading...
Searching...
No Matches
CAPI_Bitmap.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * This file is a part of Ultralight. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2024 Ultralight, Inc. *
7 **************************************************************************************************/
8
9///
10/// @file CAPI_Bitmap.h
11///
12/// A thread-safe container for pixel data.
13///
14/// `#include <Ultralight/CAPI/CAPI_Bitmap.h>`
15///
16/// The bitmap class is used to store pixel data in a variety of formats. It intelligently manages
17/// the lifetime of the pixel buffer and provides thread-safe access to the pixel data.
18///
19/// ## Accessing Pixel Data
20///
21/// To access the pixel data, you must first lock the pixels using ulBitmapLockPixels(). This will
22/// return a pointer to the pixel buffer. An example follows:
23///
24/// ```
25/// void* pixels = ulBitmapLockPixels(bitmap);
26/// if (pixels) {
27/// // Zero out the pixel buffer
28/// memset(pixels, 0, ulBitmapGetSize(bitmap));
29/// }
30///
31/// // Unlock the pixels when you're done.
32/// ulBitmapUnlockPixels(bitmap);
33/// ```
34///
35#ifndef ULTRALIGHT_CAPI_BITMAP_H
36#define ULTRALIGHT_CAPI_BITMAP_H
37
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/******************************************************************************
45 * Bitmap
46 *****************************************************************************/
47
48///
49/// Create empty bitmap.
50///
52
53///
54/// Create bitmap with certain dimensions and pixel format.
55///
56ULExport ULBitmap ulCreateBitmap(unsigned int width, unsigned int height, ULBitmapFormat format);
57
58///
59/// Create bitmap from existing pixel buffer. @see Bitmap for help using this function.
60///
61ULExport ULBitmap ulCreateBitmapFromPixels(unsigned int width, unsigned int height,
62 ULBitmapFormat format, unsigned int row_bytes,
63 const void* pixels, size_t size, bool should_copy);
64
65///
66/// Create bitmap from copy.
67///
69
70///
71/// Destroy a bitmap (you should only destroy Bitmaps you have explicitly created via one of the
72/// creation functions above.
73///
75
76///
77/// Get the width in pixels.
78///
79ULExport unsigned int ulBitmapGetWidth(ULBitmap bitmap);
80
81///
82/// Get the height in pixels.
83///
84ULExport unsigned int ulBitmapGetHeight(ULBitmap bitmap);
85
86///
87/// Get the pixel format.
88///
90
91///
92/// Get the bytes per pixel.
93///
94ULExport unsigned int ulBitmapGetBpp(ULBitmap bitmap);
95
96///
97/// Get the number of bytes per row.
98///
100
101///
102/// Get the size in bytes of the underlying pixel buffer.
103///
105
106///
107/// Whether or not this bitmap owns its own pixel buffer.
108///
110
111///
112/// Lock pixels for reading/writing, returns pointer to pixel buffer.
113///
115
116///
117/// Unlock pixels after locking.
118///
120
121///
122/// Get raw pixel buffer-- you should only call this if Bitmap is already locked.
123///
125
126///
127/// Whether or not this bitmap is empty.
128///
130
131///
132/// Reset bitmap pixels to 0.
133///
135
136///
137/// Write bitmap to a PNG on disk.
138///
139ULExport bool ulBitmapWritePNG(ULBitmap bitmap, const char* path);
140
141///
142/// This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
143///
145
146#ifdef __cplusplus
147} // extern "C"
148#endif
149
150#endif // ULTRALIGHT_CAPI_BITMAP_H
ULExport bool ulBitmapIsEmpty(ULBitmap bitmap)
Whether or not this bitmap is empty.
ULExport bool ulBitmapWritePNG(ULBitmap bitmap, const char *path)
Write bitmap to a PNG on disk.
ULExport bool ulBitmapOwnsPixels(ULBitmap bitmap)
Whether or not this bitmap owns its own pixel buffer.
ULExport ULBitmapFormat ulBitmapGetFormat(ULBitmap bitmap)
Get the pixel format.
ULExport unsigned int ulBitmapGetWidth(ULBitmap bitmap)
Get the width in pixels.
ULExport void ulBitmapErase(ULBitmap bitmap)
Reset bitmap pixels to 0.
ULExport ULBitmap ulCreateBitmapFromPixels(unsigned int width, unsigned int height, ULBitmapFormat format, unsigned int row_bytes, const void *pixels, size_t size, bool should_copy)
Create bitmap from existing pixel buffer.
ULExport size_t ulBitmapGetSize(ULBitmap bitmap)
Get the size in bytes of the underlying pixel buffer.
ULExport void ulBitmapUnlockPixels(ULBitmap bitmap)
Unlock pixels after locking.
ULExport unsigned int ulBitmapGetBpp(ULBitmap bitmap)
Get the bytes per pixel.
ULExport void ulDestroyBitmap(ULBitmap bitmap)
Destroy a bitmap (you should only destroy Bitmaps you have explicitly created via one of the creation...
ULExport unsigned int ulBitmapGetHeight(ULBitmap bitmap)
Get the height in pixels.
ULExport ULBitmap ulCreateBitmapFromCopy(ULBitmap existing_bitmap)
Create bitmap from copy.
ULExport void * ulBitmapLockPixels(ULBitmap bitmap)
Lock pixels for reading/writing, returns pointer to pixel buffer.
ULExport ULBitmap ulCreateEmptyBitmap()
Create empty bitmap.
ULExport void ulBitmapSwapRedBlueChannels(ULBitmap bitmap)
This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
ULExport unsigned int ulBitmapGetRowBytes(ULBitmap bitmap)
Get the number of bytes per row.
ULExport ULBitmap ulCreateBitmap(unsigned int width, unsigned int height, ULBitmapFormat format)
Create bitmap with certain dimensions and pixel format.
ULExport void * ulBitmapRawPixels(ULBitmap bitmap)
Get raw pixel buffer– you should only call this if Bitmap is already locked.
Various defines and utility functions for the C API.
#define ULExport
Definition CAPI_Defines.h:38
struct C_Bitmap * ULBitmap
Definition CAPI_Defines.h:64
ULBitmapFormat
Definition CAPI_Defines.h:153