Banjo API 1.0.0-stable
Low-level C99 game development API
Loading...
Searching...
No Matches
bitmap.h
Go to the documentation of this file.
1
74#ifndef BJ_BITMAP_H
75#define BJ_BITMAP_H
76#include <banjo/api.h>
77#include <banjo/error.h>
78#include <banjo/pixel.h>
79#include <banjo/rect.h>
80#include <banjo/stream.h>
81
100#ifndef BJ_NO_TYPEDEF
102#endif
103
121
122
123
125struct bj_bitmap;
126
133 void
134);
135
153 size_t width,
154 size_t height,
155 enum bj_pixel_mode mode,
156 size_t stride
157);
158
165 struct bj_bitmap* bitmap
166);
167
235 const char* path,
236 struct bj_error** error
237);
238
239
274 void* pixels,
275 size_t width,
276 size_t height,
277 enum bj_pixel_mode mode,
278 size_t stride
279);
280
301 const struct bj_bitmap* bitmap
302);
303
333 const struct bj_bitmap* bitmap,
334 enum bj_pixel_mode mode
335);
336
356 struct bj_bitmap* bitmap,
357 void* pixels,
358 size_t width,
359 size_t height,
360 enum bj_pixel_mode mode,
361 size_t stride
362);
363
365 struct bj_bitmap* bitmap,
366 void* pixels,
367 size_t width,
368 size_t height,
369 enum bj_pixel_mode mode,
370 size_t stride
371);
372
373
380 struct bj_bitmap* bitmap
381);
382
390 struct bj_bitmap* bitmap
391);
392
400 const struct bj_bitmap* bitmap
401);
402
410 const struct bj_bitmap* bitmap
411);
412
420 struct bj_bitmap* bitmap
421);
422
430 struct bj_bitmap* bitmap
431);
432
445 const struct bj_bitmap* bitmap,
446 size_t x,
447 size_t y,
448 uint8_t* red,
449 uint8_t* green,
450 uint8_t* blue
451);
452
464 struct bj_bitmap* bitmap,
465 uint8_t red,
466 uint8_t green,
467 uint8_t blue
468);
469
479 struct bj_bitmap* bitmap,
480 size_t x,
481 size_t y,
482 uint32_t value
483);
484
496 struct bj_bitmap* bitmap
497);
498
536 struct bj_bitmap* bitmap,
537 uint32_t color,
538 uint8_t roles
539);
540
559 struct bj_bitmap* bitmap,
560 bj_bool enabled
561);
562
580 const struct bj_bitmap* bitmap,
581 size_t x,
582 size_t y
583);
584
585
620 const struct bj_bitmap* src, const struct bj_rect* src_area,
621 struct bj_bitmap* dst, const struct bj_rect* dst_area,
622 enum bj_blit_op op);
623
648 const struct bj_bitmap* src, const struct bj_rect* src_area,
649 struct bj_bitmap* dst, const struct bj_rect* dst_area,
650 enum bj_blit_op op);
651
675
684
693
727 const struct bj_bitmap* mask,
728 const struct bj_rect* mask_area, /* NULL = full mask */
729 struct bj_bitmap* dst,
730 const struct bj_rect* dst_area, /* NULL = place at {0,0} w/ mask_area size */
731 uint32_t fg_native, /* dst-native packed colour */
732 uint32_t bg_native, /* dst-native packed colour */
733 bj_mask_bg_mode mode
734);
735
762 const struct bj_bitmap* mask,
763 const struct bj_rect* mask_area, /* NULL = full mask */
764 struct bj_bitmap* dst,
765 const struct bj_rect* dst_area, /* NULL = fill entire dst */
766 uint32_t fg_native,
767 uint32_t bg_native,
768 bj_mask_bg_mode mode
769);
770
783 const char* text,
784 unsigned height
785);
786
828 struct bj_bitmap* dst,
829 unsigned height,
830 struct bj_rect area,
831 bj_text_halign halign,
832 bj_text_valign valign,
833 uint32_t fg_native,
834 const char* text
835);
836
860 struct bj_bitmap* dst,
861 unsigned height,
862 struct bj_rect area,
863 bj_text_halign halign,
864 bj_text_valign valign,
865 uint32_t fg_native,
866 const char* fmt,
867 ...
868);
869
925 struct bj_bitmap* dst,
926 unsigned height,
927 struct bj_rect area,
928 bj_text_halign halign,
929 bj_text_valign valign,
930 uint32_t fg_native,
931 uint32_t bg_native,
932 bj_mask_bg_mode mode,
933 const char* text
934);
935
936#endif
General-purpose definitions for Banjo API.
Recoverable error handling.
void bj_clear_bitmap(struct bj_bitmap *bitmap)
Fills the entire bitmap with the clear colour.
bj_bool bj_blit_mask_stretched(const struct bj_bitmap *mask, const struct bj_rect *mask_area, struct bj_bitmap *dst, const struct bj_rect *dst_area, uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode)
Masked blit with stretching (nearest neighbor).
unsigned bj_measure_text(const char *text, unsigned height)
Measures the pixel width of a text string at a given height.
void bj_assign_bitmap(struct bj_bitmap *bitmap, void *pixels, size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
struct bj_bitmap * bj_allocate_bitmap(void)
Allocate a new bitmap object.
bj_bool bj_blit_stretched(const struct bj_bitmap *src, const struct bj_rect *src_area, struct bj_bitmap *dst, const struct bj_rect *dst_area, enum bj_blit_op op)
Stretched bitmap blitting (nearest neighbor).
bj_mask_bg_mode
Mask background mode for masked blits (glyph/text rendering).
Definition bitmap.h:670
struct bj_bitmap * bj_create_bitmap_from_file(const char *path, struct bj_error **error)
Creates a new bitmap by loading from a file.
void * bj_bitmap_pixels(struct bj_bitmap *bitmap)
Get the underlying pixels data for direct access.
void bj_draw_textf(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, const char *fmt,...)
Prints formatted text into a bitmap, similar to printf.
bj_bool bj_blit(const struct bj_bitmap *src, const struct bj_rect *src_area, struct bj_bitmap *dst, const struct bj_rect *dst_area, enum bj_blit_op op)
Bitmap blitting operation from a source to a destination bitmap.
size_t bj_bitmap_height(const struct bj_bitmap *bitmap)
Get the height of the given bitmap.
size_t bj_bitmap_stride(struct bj_bitmap *bitmap)
Get the number of bytes in a row of pixel data, including the padding.
void bj_reset_bitmap(struct bj_bitmap *bitmap)
Resets a struct bj_bitmap object making it ready for a new init or free.
void bj_make_bitmap_rgb(const struct bj_bitmap *bitmap, size_t x, size_t y, uint8_t *red, uint8_t *green, uint8_t *blue)
Gets the RGB value of a pixel given its 32-bits representation.
uint32_t bj_make_bitmap_pixel(struct bj_bitmap *bitmap, uint8_t red, uint8_t green, uint8_t blue)
Returns an opaque value representing a pixel colour, given its RGB composition.
bj_blit_op
Raster operation (ROP) to apply during blitting.
Definition bitmap.h:92
struct bj_bitmap * bj_convert_bitmap(const struct bj_bitmap *bitmap, enum bj_pixel_mode mode)
Creates a new struct bj_bitmap by converting bitmap.
bj_bool bj_blit_mask(const struct bj_bitmap *mask, const struct bj_rect *mask_area, struct bj_bitmap *dst, const struct bj_rect *dst_area, uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode)
Masked blit (non-stretched).
bj_bitmap_color_role
Colour roles for bitmaps.
Definition bitmap.h:117
size_t bj_bitmap_width(const struct bj_bitmap *bitmap)
Get the width of the given bitmap.
struct bj_bitmap * bj_init_bitmap(struct bj_bitmap *bitmap, void *pixels, size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
Initialises a new struct bj_bitmap with the specified width and height.
int bj_bitmap_mode(struct bj_bitmap *bitmap)
Get the pixel mode of the given bitmap.
struct bj_bitmap * bj_create_bitmap(size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
Creates a new struct bj_bitmap with the specified width and height.
bj_text_halign
Horizontal alignment for text rendering.
Definition bitmap.h:679
struct bj_bitmap * bj_create_bitmap_from_pixels(void *pixels, size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
Creates a new struct bj_bitmap with the specified width and height.
void bj_put_pixel(struct bj_bitmap *bitmap, size_t x, size_t y, uint32_t value)
Change the pixel colour at given coordinate.
void bj_draw_text(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, const char *text)
Prints text using the default foreground colour and transparent background.
void bj_set_bitmap_color(struct bj_bitmap *bitmap, uint32_t color, uint8_t roles)
Sets one or more colour properties of a bitmap.
uint32_t bj_bitmap_pixel(const struct bj_bitmap *bitmap, size_t x, size_t y)
Gets the colour of a bitmap pixel, given its coordinates.
void bj_enable_colorkey(struct bj_bitmap *bitmap, bj_bool enabled)
Enables or disables colour key transparency for blitting.
void bj_destroy_bitmap(struct bj_bitmap *bitmap)
Deletes a struct bj_bitmap object and releases associated memory.
void bj_blit_text(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode, const char *text)
Prints text with explicit foreground/background and background mode.
bj_text_valign
Vertical alignment for text rendering.
Definition bitmap.h:688
struct bj_bitmap * bj_copy_bitmap(const struct bj_bitmap *bitmap)
Creates a new struct bj_bitmap by copying bitmap.
@ BJ_MASK_BG_TRANSPARENT
Foreground over destination where mask>0.
Definition bitmap.h:671
@ BJ_MASK_BG_OPAQUE
Opaque band: mix(background, foreground, mask)
Definition bitmap.h:672
@ BJ_MASK_BG_REV_TRANSPARENT
Carved: mix(destination, background, 1-mask)
Definition bitmap.h:673
@ BJ_BLIT_OP_OR
Bitwise OR.
Definition bitmap.h:95
@ BJ_BLIT_OP_COPY
Copy source to destination (fast path when formats match)
Definition bitmap.h:93
@ BJ_BLIT_OP_AND
Bitwise AND.
Definition bitmap.h:96
@ BJ_BLIT_OP_ADD_SAT
Per-channel saturated add (clamped to 255)
Definition bitmap.h:97
@ BJ_BLIT_OP_XOR
Bitwise XOR (channel-wise for >8bpp)
Definition bitmap.h:94
@ BJ_BLIT_OP_SUB_SAT
Per-channel saturated subtract (clamped to 0)
Definition bitmap.h:98
@ BJ_BITMAP_CLEAR_COLOR
Clear/fill colour for bj_clear_bitmap()
Definition bitmap.h:118
@ BJ_BITMAP_COLORKEY
Transparency key for blitting (auto-enables)
Definition bitmap.h:119
@ BJ_TEXT_HALIGN_RIGHT
Align text to the right edge of the area.
Definition bitmap.h:682
@ BJ_TEXT_HALIGN_LEFT
Align text to the left edge of the area.
Definition bitmap.h:680
@ BJ_TEXT_HALIGN_CENTER
Center text horizontally within the area.
Definition bitmap.h:681
@ BJ_TEXT_VALIGN_BOTTOM
Align text to the bottom edge of the area.
Definition bitmap.h:691
@ BJ_TEXT_VALIGN_CENTER
Center text vertically within the area.
Definition bitmap.h:690
@ BJ_TEXT_VALIGN_TOP
Align text to the top edge of the area.
Definition bitmap.h:689
struct bj_error bj_error
Definition api.h:336
#define BANJO_EXPORT
Definition api.h:174
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:260
struct bj_bitmap bj_bitmap
Definition api.h:331
Axis-aligned rectangle: a top-left corner plus a width and height.
Definition rect.h:33
bj_pixel_mode
Representation of a pixel encoding.
Definition pixel.h:86
Header file for general pixel manipulation facilities.
Axis-aligned rectangle in pixel coordinates.
Header file for struct bj_stream struct and related functions.