docs
Loading...
Searching...
No Matches
Bitmap.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
7#include <Ultralight/RefPtr.h>
9#include <Ultralight/Buffer.h>
10
11namespace ultralight {
12
13///
14/// The various Bitmap formats.
15///
16enum class BitmapFormat : uint8_t {
17 ///
18 /// Alpha channel only, 8-bits per pixel.
19 ///
20 /// Encoding: 8-bits per channel, unsigned normalized.
21 ///
22 /// Color-space: Linear (no gamma), alpha-coverage only.
23 ///
25
26 ///
27 /// Blue Green Red Alpha channels, 32-bits per pixel.
28 ///
29 /// Encoding: 8-bits per channel, unsigned normalized.
30 ///
31 /// Color-space: sRGB gamma with premultiplied linear alpha channel.
32 ///
34
35 ///
36 /// Red Green channels, 16-bits per pixel.
37 ///
38 /// Encoding: 8-bits per channel, unsigned normalized.
39 ///
40 /// Color-space: Linear (no gamma).
41 ///
42 /// Not PNG-encodable.
43 ///
45
46 ///
47 /// BC1 block-compressed color (4x4 blocks, 8 bytes/block). Optional 1-bit alpha.
48 ///
49 /// Color-space: sRGB gamma with optional alpha.
50 ///
52
53 ///
54 /// BC2 block-compressed color (4x4 blocks, 16 bytes/block). Explicit 4-bit alpha.
55 ///
56 /// Color-space: sRGB gamma with premultiplied alpha.
57 ///
59
60 ///
61 /// BC3 block-compressed color (4x4 blocks, 16 bytes/block). Interpolated alpha.
62 ///
63 /// Color-space: sRGB gamma with premultiplied alpha.
64 ///
66
67 ///
68 /// BC7 block-compressed color (4x4 blocks, 16 bytes/block). High-quality RGB(A).
69 ///
70 /// Color-space: sRGB gamma with premultiplied alpha.
71 ///
73
74 ///
75 /// Four half-precision float channels (16 bits per channel, 64 bits per pixel).
76 ///
77 /// This is a raw data format: GPUDriver should create these as sampleable
78 /// textures without filtering or mipmaps and upload rows exactly as stored.
79 ///
81
82 ///
83 /// Four unsigned integer channels (16 bits per channel, 64 bits per pixel).
84 ///
85 /// This is a raw data format: GPUDriver should create these as sampleable
86 /// textures without filtering or mipmaps and upload rows exactly as stored.
87 ///
89
90 ///
91 /// Four float channels (32 bits per channel, 128 bits per pixel).
92 ///
93 /// This is a raw data format: GPUDriver should create these as sampleable
94 /// textures without filtering or mipmaps and upload rows exactly as stored.
95 ///
97};
98
99///
100/// Macro to get the bytes per pixel from a BitmapFormat.
101///
102/// @note This is only meaningful for non-block-compressed formats. Block-compressed (BCn) formats
103/// have no per-pixel size-- use GetBitmapFormatInfo() and row_bytes() / size() for storage
104/// math instead.
105///
106#define GetBytesPerPixel(x) ((x) == BitmapFormat::A8_UNORM ? 1 \
107 : (x) == BitmapFormat::RG8_UNORM ? 2 \
108 : (x) == BitmapFormat::RGBA16F ? 8 \
109 : (x) == BitmapFormat::RGBA16UI ? 8 \
110 : (x) == BitmapFormat::RGBA32F ? 16 \
111 : 4)
112
113///
114/// Block geometry for a BitmapFormat.
115///
116/// Uncompressed formats have a 1x1 block whose block_bytes equals the bytes-per-pixel.
117/// Block-compressed (BCn) formats have a 4x4 block. A bitmap's row pitch and surface size are
118/// derived from the block geometry:
119///
120/// ```
121/// row_pitch = ceil(width / block_width) * block_bytes
122/// surface_size = row_pitch * ceil(height / block_height)
123/// ```
124///
125/// For a 1x1 block this reduces to `width * block_bytes` and `row_pitch * height`.
126///
128 ///
129 /// Width of one block, in pixels (1 for uncompressed, 4 for BCn).
130 ///
131 uint32_t block_width;
132
133 ///
134 /// Height of one block, in pixels (1 for uncompressed, 4 for BCn).
135 ///
136 uint32_t block_height;
137
138 ///
139 /// Size of one block, in bytes (equals bytes-per-pixel when the block is 1x1).
140 ///
141 uint32_t block_bytes;
142};
143
144///
145/// Get the block geometry for a given BitmapFormat.
146///
147/// @param format The pixel format to query.
148///
149/// @return Returns the block width, block height, and block size in bytes for the format.
150///
152
153///
154/// Whether or not a given BitmapFormat is block-compressed (a BCn format).
155///
156/// @param format The pixel format to query.
157///
159
160///
161/// Forward declaration for the LockedPixels class.
162///
163template<typename T>
164class LockedPixels;
165
166///
167/// Function signature for a user-defined destruction callback to be optionally called when the
168/// Bitmap is destroyed.
169///
170/// @param user_data Pointer to user-defined user-data (this will be the same value as what was
171/// passed to Bitmap::Create, if any)
172///
173/// @param data Pointer to raw Bitmap pixel data.
174///
175typedef void (*DestroyBitmapCallback)(void* user_data, void* data);
176
177///
178/// A container for pixel data.
179///
180/// The bitmap class is used to store pixel data in a variety of formats. It intelligently manages
181/// the lifetime of the pixel buffer and serializes access to it while the Bitmap owns the pixels.
182///
183/// ## Thread Safety
184///
185/// LockPixels() and UnlockPixels() take the Bitmap's internal lock only when the Bitmap owns its
186/// pixel buffer, ie. one created by a Create() overload that allocates, or one that copied the
187/// pixels you passed in. A Bitmap that wraps memory you still own-- created with
188/// `should_copy = false`, or with a destruction callback-- does no locking at all, so you must
189/// serialize access to that buffer yourself.
190///
191/// An immutable Bitmap (see is_immutable()) does no locking either, since its pixels never change.
192///
193/// ## Accessing Pixel Data
194///
195/// You can access the underlying pixel data by using the LockPixelsSafe() method. An example
196/// follows:
197///
198/// ```
199/// auto bitmap = Bitmap::Create(100, 100, BitmapFormat::BGRA8_UNORM_SRGB);
200/// auto pixels = bitmap->LockPixelsSafe();
201/// if (pixels && pixels.data()) {
202/// // Zero out the pixel buffer by setting every byte to 0.
203/// memset(pixels.data(), 0, pixels.size());
204/// }
205///
206/// // 'pixels' is automatically unlocked when it goes out of scope.
207/// ```
209 public:
210 ///
211 /// Maximum supported width or height, in pixels.
212 ///
213 /// Create() returns a null ref-pointer if either dimension exceeds this limit.
214 ///
215 /// The largest possible allocation, MaxDimension by MaxDimension at 4 bytes per pixel, is
216 /// about 1 GB.
217 ///
218 static constexpr uint32_t MaxDimension = 16384;
219
220 ///
221 /// Create an empty Bitmap. No pixels will be allocated.
222 ///
223 /// @return Returns a ref-pointer to a new Bitmap instance.
224 ///
226
227 ///
228 /// Create a Bitmap with a certain configuration. Pixels will be allocated and zero-initialized.
229 ///
230 /// @param width The width in pixels.
231 ///
232 /// @param height The height in pixels.
233 ///
234 /// @param format The pixel format to use.
235 ///
236 /// @return Returns a ref-pointer to a new Bitmap instance.
237 ///
239
240 ///
241 /// Create an aligned Bitmap with a certain configuration. Pixels will be allocated and
242 /// zero-initialized. Row bytes will be padded to reach the specified alignment.
243 ///
244 /// @param width The width in pixels.
245 ///
246 /// @param height The height in pixels.
247 ///
248 /// @param format The pixel format to use.
249 ///
250 /// @param alignment The alignment (in bytes) to use. Row bytes will be padded to reach a
251 /// multiple of this value and the underlying storage will be allocated with
252 /// this alignment.
253 ///
254 /// @return Returns a ref-pointer to a new Bitmap instance.
255 ///
257 uint32_t alignment);
258
259 ///
260 /// Create a Bitmap with existing pixel data, a copy will be made unless should_copy is false.
261 ///
262 /// @param width The width in pixels.
263 ///
264 /// @param height The height in pixels.
265 ///
266 /// @param format The pixel format to use.
267 ///
268 /// @param row_bytes The number of bytes between each row of pixels. This should be at least
269 /// `width * bytes_per_pixel`, or for a block-compressed format, the width
270 /// in 4x4 blocks times the block size (see GetBitmapFormatInfo()).
271 ///
272 /// @param pixels Pointer to raw pixel buffer.
273 ///
274 /// @param size Size of the raw pixel buffer.
275 ///
276 /// @param should_copy Whether or not a copy should be made of the pixels. If this is false
277 /// the returned Bitmap will use the raw pixels passed in as its own, but
278 /// you are still responsible for destroying your buffer afterwards.
279 ///
280 /// @return Returns a ref-pointer to a new Bitmap instance.
281 ///
283 uint32_t row_bytes, const void* pixels, size_t size,
284 bool should_copy = true);
285
286 ///
287 /// Create a Bitmap that wraps existing pixel data, a user-defined destruction callback will be
288 /// called when the Bitmap wants to destroy the data.
289 ///
290 /// @param width The width in pixels.
291 ///
292 /// @param height The height in pixels.
293 ///
294 /// @param format The pixel format to use.
295 ///
296 /// @param row_bytes The number of bytes between each row of pixels. This should be at least
297 /// `width * bytes_per_pixel`, or for a block-compressed format, the width
298 /// in 4x4 blocks times the block size (see GetBitmapFormatInfo()).
299 ///
300 /// @param pixels Pointer to raw pixel buffer.
301 ///
302 /// @param size Size of the raw pixel buffer.
303 ///
304 /// @param user_data Optional user data that will be passed to destruction_callback when the
305 /// Bitmap wants to destroy the pixel data. (Pass nullptr to ignore)
306 ///
307 /// @param destruction_callback Callback that will be called upon destruction.
308 ///
309 /// @return Returns a ref-pointer to a new Bitmap instance.
310 ///
312 uint32_t row_bytes, const void* pixels, size_t size,
313 void* user_data, DestroyBitmapCallback destruction_callback);
314
315 ///
316 /// Create a bitmap from a deep copy of another Bitmap.
317 ///
318 /// @param bitmap The bitmap to copy from.
319 ///
320 /// @return Returns a ref-pointer to a new Bitmap instance.
321 ///
322 static RefPtr<Bitmap> Create(const Bitmap& bitmap);
323
324 ///
325 /// Get the width in pixels.
326 ///
327 virtual uint32_t width() const = 0;
328
329 ///
330 /// Get the height in pixels.
331 ///
332 virtual uint32_t height() const = 0;
333
334 ///
335 /// Get the bounds as an IntRect.
336 ///
337 virtual IntRect bounds() const = 0;
338
339 ///
340 /// Get the pixel format.
341 ///
342 virtual BitmapFormat format() const = 0;
343
344 ///
345 /// Get the number of bytes per pixel.
346 ///
347 virtual uint32_t bpp() const = 0;
348
349 ///
350 /// Get the number of bytes between each row of pixels.
351 ///
352 /// @note This value is usually calculated as width * bytes_per_pixel (bpp) but it may be larger
353 /// due to alignment rules in the allocator.
354 ///
355 virtual uint32_t row_bytes() const = 0;
356
357 ///
358 /// Get the size in bytes of the pixel buffer.
359 ///
360 /// @note Size is calculated as row_bytes() * height().
361 ///
362 virtual size_t size() const = 0;
363
364 ///
365 /// Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its
366 /// lifetime.
367 ///
368 virtual bool owns_pixels() const = 0;
369
370 ///
371 /// Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
372 ///
373 /// @return Returns a managed container that can be used to access the pixels
374 /// (LockedPixels::data()). This container will automatically unlock the pixels when it
375 /// goes out of scope.
376 ///
378
379 ///
380 /// Lock the pixel buffer for reading/writing.
381 ///
382 /// @return Returns a pointer to the pixel buffer.
383 ///
384 virtual void* LockPixels() = 0;
385
386 ///
387 /// Unlock the pixel buffer.
388 ///
389 virtual void UnlockPixels() = 0;
390
391 ///
392 /// Lock the pixel buffer for reading/writing. (const)
393 ///
394 /// @return Returns a const pointer to the pixel buffer.
395 ///
396 virtual const void* LockPixels() const = 0;
397
398 ///
399 /// Unlock the pixel buffer. (const)
400 ///
401 virtual void UnlockPixels() const = 0;
402
403 ///
404 /// Get the raw pixel buffer.
405 ///
406 /// @note You should only call this if pixels are already locked.
407 ///
408 virtual void* raw_pixels() = 0;
409
410 ///
411 /// Whether or not this Bitmap is empty (no pixels allocated).
412 ///
413 virtual bool IsEmpty() const = 0;
414
415 ///
416 /// Erase the Bitmap (set all pixels to 0).
417 ///
418 virtual void Erase() = 0;
419
420 ///
421 /// Assign another bitmap to this one.
422 ///
423 /// @param bitmap The bitmap to copy from.
424 ///
425 /// @note The source pixels are deep-copied in every case but one: a source that wraps memory
426 /// you still own (created with `should_copy = false` and no destruction callback) is
427 /// aliased instead, so that buffer must outlive this Bitmap.
428 ///
429 virtual void Set(RefPtr<Bitmap> bitmap) = 0;
430
431 ///
432 /// Draw another bitmap to this bitmap.
433 ///
434 /// @note Formats do not need to match. Bitmap formats will be converted to one another
435 /// automatically.
436 ///
437 /// @param src_rect The source rectangle, relative to src bitmap.
438 ///
439 /// @param dest_rect The destination rectangle, relative to this bitmap.
440 ///
441 /// @param src The source bitmap.
442 ///
443 /// @param pad_repeat Whether or not we should pad the drawn bitmap by one pixel of repeated
444 /// edge pixels from the source bitmap.
445 ///
446 /// @return Returns whether or not the operation succeeded (this can fail if the src_rect and/or
447 /// dest_rect are invalid).
448 ///
449 virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr<Bitmap> src, bool pad_repeat)
450 = 0;
451
452 ///
453 /// Encode this Bitmap as a PNG image and store the encoded bytes in a Buffer.
454 ///
455 /// @param convert_to_rgba The PNG format expects RGBA format but our bitmap is stored as BGRA,
456 /// set this to true to perform the conversion automatically.
457 ///
458 /// @param convert_to_straight_alpha The PNG format expects semi-transparent values to be
459 /// stored as straight alpha instead of premultiplied alpha,
460 /// set this to true to perform the conversion automatically.
461 ///
462 /// @return Returns a buffer containing the encoded bytes, or a null ref-pointer on failure.
463 ///
464 virtual RefPtr<Buffer> EncodePNG(bool convert_to_rgba = true,
465 bool convert_to_straight_alpha = true) const = 0;
466
467 ///
468 /// Write this Bitmap out to a PNG image.
469 ///
470 /// @param path The filepath to write to (opened with fopen())
471 ///
472 /// @param convert_to_rgba The PNG format expects RGBA format but our bitmap is stored as BGRA,
473 /// set this to true to perform the conversion automatically.
474 ///
475 /// @param convert_to_straight_alpha The PNG format expects semi-transparent values to be
476 /// stored as straight alpha instead of premultiplied alpha,
477 /// set this to true to perform the conversion automatically.
478 ///
479 /// @return Returns whether or not the operation succeeded.
480 ///
481 virtual bool WritePNG(const char* path, bool convert_to_rgba = true,
482 bool convert_to_straight_alpha = true) const = 0;
483
484 ///
485 /// Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.
486 ///
487 /// @param destination The bitmap to store the result in, the width and height of the
488 /// destination will be used.
489 ///
490 /// @param high_quality Whether or not a high quality resampling will be used during the
491 /// resize. (Otherwise, just uses fast nearest-neighbor sampling)
492 ///
493 /// @return Returns whether or not the operation succeeded. This operation is only valid if both
494 /// formats are BitmapFormat::BGRA8_UNORM_SRGB and the source and destination are
495 /// non-empty.
496 ///
497 virtual bool Resample(RefPtr<Bitmap> destination, bool high_quality) = 0;
498
499 ///
500 /// Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
501 ///
502 /// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB.
503 ///
504 virtual void SwapRedBlueChannels() = 0;
505
506 ///
507 /// Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
508 ///
509 /// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB.
510 ///
511 virtual void ConvertToStraightAlpha() = 0;
512
513 ///
514 /// Convert a BGRA bitmap from straight alpha to premultiplied alpha.
515 ///
516 /// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB.
517 ///
518 virtual void ConvertToPremultipliedAlpha() = 0;
519
520 ///
521 /// Whether or not this Bitmap uses a block-compressed (BCn) format.
522 ///
523 /// @note Compressed bitmaps store 4x4 pixel blocks and don't support per-pixel operations.
524 /// Erase(), DrawBitmap(), Resample(), and the channel/alpha conversions are no-ops or
525 /// fail on a compressed Bitmap.
526 ///
527 virtual bool is_compressed() const = 0;
528
529 protected:
531 virtual ~Bitmap();
532 Bitmap(const Bitmap&);
533 void operator=(const Bitmap&);
534
535 public:
536 ///
537 /// Whether or not this Bitmap is immutable.
538 ///
539 /// The library makes a Bitmap immutable once its pixels are final (eg, a fully decoded image).
540 /// Once this returns true it stays true: the pixels never change again and the pixel buffer
541 /// lives as long as the Bitmap, so you can keep a reference to it instead of copying the pixels.
542 ///
543 /// Erase(), Set(), DrawBitmap(), SwapRedBlueChannels(), ConvertToStraightAlpha(),
544 /// ConvertToPremultipliedAlpha(), and using this Bitmap as the destination of Resample() all
545 /// fail or do nothing on an immutable Bitmap.
546 ///
547 /// You can still read it: LockPixels(), LockPixelsSafe(), EncodePNG(), WritePNG(), and using it
548 /// as the source of Resample() or DrawBitmap() work as usual.
549 ///
550 /// @note This is safe to call from any thread. An immutable Bitmap's pixels can be read from
551 /// any thread at the same time.
552 ///
553 virtual bool is_immutable() const = 0;
554};
555
556///
557/// Managed container that keeps a pixel buffer locked for the duration of its lifetime.
558///
559/// You obtain an instance via Bitmap::LockPixelsSafe() or Surface::LockPixelsSafe(). The pixel
560/// buffer is automatically unlocked when this object goes out of scope. This class can be moved
561/// but not copied.
562///
563/// The template parameter `T` is the lockable type, `RefPtr<Bitmap>` or `Surface*`.
564///
565template <typename T>
567 public:
568 LockedPixels(const LockedPixels&) = delete;
570 LockedPixels(int) = delete;
571 explicit LockedPixels(T& lockable) : lockable_(lockable), data_(nullptr), size_(0) { lock(); }
572
574 if (lockable_)
575 lockable_->UnlockPixels();
576 }
577
578 ///
579 /// Access the locked pixel data.
580 ///
581 void* data() { return data_; }
582
583 ///
584 /// Access the size of the locked pixel data.
585 ///
586 size_t size() { return size_; }
587
588 explicit operator bool() const { return !!lockable_; }
589
590 LockedPixels(LockedPixels&& other) : lockable_(other.lockable_), data_(other.data_),
591 size_(other.size_) {
592 other.lockable_ = nullptr;
593 other.data_ = nullptr;
594 other.size_ = 0;
595 }
596
598 if (lockable_)
599 lockable_->UnlockPixels();
600 lockable_ = other.lockable_;
601 data_ = other.data_;
602 size_ = other.size_;
603 other.lockable_ = nullptr;
604 other.data_ = nullptr;
605 other.size_ = 0;
606 return *this;
607 }
608
609 private:
610 void lock() {
611 if (lockable_) {
612 data_ = lockable_->LockPixels();
613 size_ = lockable_->size();
614 }
615 }
616
617 T lockable_;
618 void* data_;
619 size_t size_;
620};
621
622
623} // namespace ultralight
#define UExport
Definition Exports.h:22
virtual RefPtr< Buffer > EncodePNG(bool convert_to_rgba=true, bool convert_to_straight_alpha=true) const =0
Encode this Bitmap as a PNG image and store the encoded bytes in a Buffer.
virtual bool owns_pixels() const =0
Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its lifetime.
static RefPtr< Bitmap > Create()
Create an empty Bitmap.
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr< Bitmap > src, bool pad_repeat)=0
Draw another bitmap to this bitmap.
void operator=(const Bitmap &)
virtual uint32_t height() const =0
Get the height in pixels.
virtual bool IsEmpty() const =0
Whether or not this Bitmap is empty (no pixels allocated).
static RefPtr< Bitmap > Create(const Bitmap &bitmap)
Create a bitmap from a deep copy of another Bitmap.
virtual uint32_t row_bytes() const =0
Get the number of bytes between each row of pixels.
virtual bool is_immutable() const =0
Whether or not this Bitmap is immutable.
Bitmap(const Bitmap &)
virtual void Set(RefPtr< Bitmap > bitmap)=0
Assign another bitmap to this one.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format)
Create a Bitmap with a certain configuration.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format, uint32_t row_bytes, const void *pixels, size_t size, void *user_data, DestroyBitmapCallback destruction_callback)
Create a Bitmap that wraps existing pixel data, a user-defined destruction callback will be called wh...
virtual uint32_t width() const =0
Get the width in pixels.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format, uint32_t alignment)
Create an aligned Bitmap with a certain configuration.
virtual void SwapRedBlueChannels()=0
Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
virtual void Erase()=0
Erase the Bitmap (set all pixels to 0).
virtual void * LockPixels()=0
Lock the pixel buffer for reading/writing.
virtual bool WritePNG(const char *path, bool convert_to_rgba=true, bool convert_to_straight_alpha=true) const =0
Write this Bitmap out to a PNG image.
virtual IntRect bounds() const =0
Get the bounds as an IntRect.
virtual void ConvertToPremultipliedAlpha()=0
Convert a BGRA bitmap from straight alpha to premultiplied alpha.
virtual void UnlockPixels()=0
Unlock the pixel buffer.
static RefPtr< Bitmap > Create(uint32_t width, uint32_t height, BitmapFormat format, uint32_t row_bytes, const void *pixels, size_t size, bool should_copy=true)
Create a Bitmap with existing pixel data, a copy will be made unless should_copy is false.
virtual uint32_t bpp() const =0
Get the number of bytes per pixel.
virtual bool is_compressed() const =0
Whether or not this Bitmap uses a block-compressed (BCn) format.
virtual LockedPixels< RefPtr< Bitmap > > LockPixelsSafe() const =0
Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
virtual const void * LockPixels() const =0
Lock the pixel buffer for reading/writing.
virtual void UnlockPixels() const =0
Unlock the pixel buffer.
virtual size_t size() const =0
Get the size in bytes of the pixel buffer.
virtual bool Resample(RefPtr< Bitmap > destination, bool high_quality)=0
Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.
virtual void ConvertToStraightAlpha()=0
Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
virtual BitmapFormat format() const =0
Get the pixel format.
static constexpr uint32_t MaxDimension
Maximum supported width or height, in pixels.
Definition Bitmap.h:218
virtual void * raw_pixels()=0
Get the raw pixel buffer.
Forward declaration for the LockedPixels class.
Definition Bitmap.h:566
void * data()
Access the locked pixel data.
Definition Bitmap.h:581
size_t size()
Access the size of the locked pixel data.
Definition Bitmap.h:586
~LockedPixels()
Definition Bitmap.h:573
LockedPixels(const LockedPixels &)=delete
LockedPixels & operator=(LockedPixels &&other)
Definition Bitmap.h:597
LockedPixels & operator=(const LockedPixels &)=delete
LockedPixels(T &lockable)
Definition Bitmap.h:571
LockedPixels(LockedPixels &&other)
Definition Bitmap.h:590
A nullable smart pointer.
Definition RefPtr.h:126
Interface for ref-counted objects that can additionally be observed via the WeakPtr<> smart pointer.
Definition RefPtr.h:83
Root namespace for every public Ultralight type, function, and enumeration.
bool IsCompressedFormat(BitmapFormat format)
Whether or not a given BitmapFormat is block-compressed (a BCn format).
BitmapFormatInfo GetBitmapFormatInfo(BitmapFormat format)
Get the block geometry for a given BitmapFormat.
void(*) DestroyBitmapCallback(void *user_data, void *data)
Function signature for a user-defined destruction callback to be optionally called when the Bitmap is...
Definition Bitmap.h:175
BitmapFormat
The various Bitmap formats.
Definition Bitmap.h:16
@ BC1_UNORM
BC1 block-compressed color (4x4 blocks, 8 bytes/block).
Definition Bitmap.h:51
@ RGBA32F
Four float channels (32 bits per channel, 128 bits per pixel).
Definition Bitmap.h:96
@ BC2_UNORM
BC2 block-compressed color (4x4 blocks, 16 bytes/block).
Definition Bitmap.h:58
@ RGBA16F
Four half-precision float channels (16 bits per channel, 64 bits per pixel).
Definition Bitmap.h:80
@ A8_UNORM
Alpha channel only, 8-bits per pixel.
Definition Bitmap.h:24
@ BGRA8_UNORM_SRGB
Blue Green Red Alpha channels, 32-bits per pixel.
Definition Bitmap.h:33
@ RG8_UNORM
Red Green channels, 16-bits per pixel.
Definition Bitmap.h:44
@ BC7_UNORM
BC7 block-compressed color (4x4 blocks, 16 bytes/block).
Definition Bitmap.h:72
@ RGBA16UI
Four unsigned integer channels (16 bits per channel, 64 bits per pixel).
Definition Bitmap.h:88
@ BC3_UNORM
BC3 block-compressed color (4x4 blocks, 16 bytes/block).
Definition Bitmap.h:65
Block geometry for a BitmapFormat.
Definition Bitmap.h:127
uint32_t block_width
Width of one block, in pixels (1 for uncompressed, 4 for BCn).
Definition Bitmap.h:131
uint32_t block_height
Height of one block, in pixels (1 for uncompressed, 4 for BCn).
Definition Bitmap.h:136
uint32_t block_bytes
Size of one block, in bytes (equals bytes-per-pixel when the block is 1x1).
Definition Bitmap.h:141
Integer Rectangle Helper.
Definition Geometry.h:533