Banjo API 1.1.0-alpha
Low-level C99 game development API
Loading...
Searching...
No Matches
bitmap.h
Go to the documentation of this file.
1
80#ifndef BJ_BITMAP_H
81#define BJ_BITMAP_H
82#include <banjo/api.h>
83#include <banjo/error.h>
84#include <banjo/pixel.h>
85#include <banjo/rect.h>
86#include <banjo/stream.h>
87
106#ifndef BJ_NO_TYPEDEF
108#endif
109
119
121struct bj_bitmap;
122
126
152 size_t width,
153 size_t height,
154 enum bj_pixel_mode mode,
155 size_t stride
156);
157
165 struct bj_bitmap* bitmap
166);
167
253 const char* path,
254 struct bj_error** error
255);
256
276 struct bj_stream* stream,
277 struct bj_error** error
278);
279
280
320 void* pixels,
321 size_t width,
322 size_t height,
323 enum bj_pixel_mode mode,
324 size_t stride
325);
326
349 const struct bj_bitmap* bitmap
350);
351
385 const struct bj_bitmap* bitmap,
386 enum bj_pixel_mode mode
387);
388
394 struct bj_bitmap* bitmap, void* pixels,
395 size_t width, size_t height, enum bj_pixel_mode mode, size_t stride);
396
400 struct bj_bitmap* bitmap, void* pixels,
401 size_t width, size_t height, enum bj_pixel_mode mode, size_t stride);
402
406
415 struct bj_bitmap* bitmap
416);
417
420
428 const struct bj_bitmap* bitmap
429);
430
438 const struct bj_bitmap* bitmap
439);
440
449 const struct bj_bitmap* bitmap
450);
451
459 const struct bj_bitmap* bitmap
460);
461
473 const struct bj_bitmap* bitmap,
474 size_t x,
475 size_t y,
476 uint8_t* red,
477 uint8_t* green,
478 uint8_t* blue
479);
480
482BANJO_EXPORT void bj_make_bitmap_rgb(const struct bj_bitmap* bitmap, size_t x, size_t y,
483 uint8_t* red, uint8_t* green, uint8_t* blue);
484
498 struct bj_bitmap* bitmap,
499 uint8_t red,
500 uint8_t green,
501 uint8_t blue
502);
503
506 uint8_t red, uint8_t green, uint8_t blue);
507
519 struct bj_bitmap* bitmap,
520 size_t x,
521 size_t y,
522 uint32_t value
523);
524
534 struct bj_bitmap* bitmap
535);
536
545 struct bj_bitmap* bitmap,
546 uint32_t color
547);
548
565 struct bj_bitmap* bitmap,
566 uint32_t color
567);
568
571BANJO_EXPORT void bj_set_bitmap_color(struct bj_bitmap* bitmap, uint32_t color, uint8_t roles);
572
583
590
593BANJO_EXPORT void bj_enable_colorkey(struct bj_bitmap* bitmap, bj_bool enabled);
594
605 const struct bj_bitmap* bitmap,
606 size_t x,
607 size_t y
608);
609
610
647 const struct bj_bitmap* src, const struct bj_rect* src_area,
648 struct bj_bitmap* dst, const struct bj_rect* dst_area,
649 enum bj_blit_op op);
650
652BANJO_EXPORT bj_bool bj_blit(const struct bj_bitmap* src, const struct bj_rect* src_area,
653 struct bj_bitmap* dst, const struct bj_rect* dst_area,
654 enum bj_blit_op op);
655
681 const struct bj_bitmap* src, const struct bj_rect* src_area,
682 struct bj_bitmap* dst, const struct bj_rect* dst_area,
683 enum bj_blit_op op);
684
686BANJO_EXPORT bj_bool bj_blit_stretched(const struct bj_bitmap* src, const struct bj_rect* src_area,
687 struct bj_bitmap* dst, const struct bj_rect* dst_area,
688 enum bj_blit_op op);
689
713
722
731
769 const struct bj_bitmap* mask,
770 const struct bj_rect* mask_area, /* 0 = full mask */
771 struct bj_bitmap* dst,
772 const struct bj_rect* dst_area, /* 0 = place at {0,0} w/ mask_area size */
773 uint32_t fg_native, /* dst-native packed colour */
774 uint32_t bg_native, /* dst-native packed colour */
775 bj_mask_bg_mode mode
776);
777
779BANJO_EXPORT bj_bool bj_blit_mask(const struct bj_bitmap* mask, const struct bj_rect* mask_area,
780 struct bj_bitmap* dst, const struct bj_rect* dst_area,
781 uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode);
782
812 const struct bj_bitmap* mask,
813 const struct bj_rect* mask_area, /* 0 = full mask */
814 struct bj_bitmap* dst,
815 const struct bj_rect* dst_area, /* 0 = fill entire dst */
816 uint32_t fg_native,
817 uint32_t bg_native,
818 bj_mask_bg_mode mode
819);
820
822BANJO_EXPORT bj_bool bj_blit_mask_stretched(const struct bj_bitmap* mask, const struct bj_rect* mask_area,
823 struct bj_bitmap* dst, const struct bj_rect* dst_area,
824 uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode);
825
843 const char* text,
844 unsigned height
845);
846
899 struct bj_bitmap* dst,
900 unsigned height,
901 struct bj_rect area,
902 bj_text_halign halign,
903 bj_text_valign valign,
904 uint32_t fg_native,
905 const char* text
906);
907
935 struct bj_bitmap* dst,
936 unsigned height,
937 struct bj_rect area,
938 bj_text_halign halign,
939 bj_text_valign valign,
940 uint32_t fg_native,
941 const char* fmt,
942 ...
943);
944
1005 struct bj_bitmap* dst,
1006 unsigned height,
1007 struct bj_rect area,
1008 bj_text_halign halign,
1009 bj_text_valign valign,
1010 uint32_t fg_native,
1011 uint32_t bg_native,
1012 bj_mask_bg_mode mode,
1013 const char* text
1014);
1015
1016#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.
void bj_set_bitmap_colorkey(struct bj_bitmap *bitmap, uint32_t color)
Set the transparent colour used when this bitmap is a blit source, and enable colour keying.
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)
size_t bj_bitmap_stride(const struct bj_bitmap *bitmap)
Get the number of bytes in a row of pixel data, including the padding.
unsigned bj_measure_text(const char *text, unsigned height)
Measures the pixel width of a text string at a given height.
struct bj_bitmap * bj_create_bitmap_from_stream(struct bj_stream *stream, struct bj_error **error)
Loads a BMP image from a stream into a new bitmap.
void bj_assign_bitmap(struct bj_bitmap *bitmap, void *pixels, size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
int bj_bitmap_mode(const struct bj_bitmap *bitmap)
Get the pixel mode of the given bitmap.
bj_bool bj_blit_bitmap(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.
struct bj_bitmap * bj_allocate_bitmap(void)
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)
bj_bool bj_blit_bitmap_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:708
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)
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)
size_t bj_bitmap_height(const struct bj_bitmap *bitmap)
Get the height of the given bitmap.
void bj_set_bitmap_clear_color(struct bj_bitmap *bitmap, uint32_t color)
Set the colour bj_clear_bitmap fills with.
void bj_reset_bitmap(struct bj_bitmap *bitmap)
void bj_disable_bitmap_colorkey(struct bj_bitmap *bitmap)
Turn colour keying off for this bitmap, keeping the key colour.
void bj_enable_bitmap_colorkey(struct bj_bitmap *bitmap)
Turn colour keying on for this bitmap (as a blit source).
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)
void * bj_bitmap_pixel_data(struct bj_bitmap *bitmap)
Reach the bitmap's raw pixel buffer for direct access.
uint32_t bj_make_bitmap_pixel(struct bj_bitmap *bitmap, uint8_t red, uint8_t green, uint8_t blue)
bj_blit_op
Raster operation (ROP) to apply during blitting.
Definition bitmap.h:98
uint32_t bj_pack_bitmap_rgb(struct bj_bitmap *bitmap, uint8_t red, uint8_t green, uint8_t blue)
Pack an (R, G, B) triple into the bitmap's native pixel format.
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)
bj_bitmap_color_role
Definition bitmap.h:115
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)
void bj_bitmap_pixel_rgb(const struct bj_bitmap *bitmap, size_t x, size_t y, uint8_t *red, uint8_t *green, uint8_t *blue)
Read the pixel at (x, y) as separate R, G, B components.
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:717
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 in a foreground colour over a transparent background.
void bj_set_bitmap_color(struct bj_bitmap *bitmap, uint32_t color, uint8_t roles)
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.
bj_bool bj_blit_bitmap_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).
void bj_enable_colorkey(struct bj_bitmap *bitmap, bj_bool enabled)
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:726
bj_bool bj_blit_bitmap_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).
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:709
@ BJ_MASK_BG_OPAQUE
Opaque band: mix(background, foreground, mask)
Definition bitmap.h:710
@ BJ_MASK_BG_REV_TRANSPARENT
Carved: mix(destination, background, 1-mask)
Definition bitmap.h:711
@ BJ_BLIT_OP_OR
Bitwise OR.
Definition bitmap.h:101
@ BJ_BLIT_OP_COPY
Copy source to destination (fast path when formats match)
Definition bitmap.h:99
@ BJ_BLIT_OP_AND
Bitwise AND.
Definition bitmap.h:102
@ BJ_BLIT_OP_ADD_SAT
Per-channel saturated add (clamped to 255)
Definition bitmap.h:103
@ BJ_BLIT_OP_XOR
Bitwise XOR (channel-wise for >8bpp)
Definition bitmap.h:100
@ BJ_BLIT_OP_SUB_SAT
Per-channel saturated subtract (clamped to 0)
Definition bitmap.h:104
@ BJ_BITMAP_CLEAR_COLOR
Clear/fill colour for bj_clear_bitmap()
Definition bitmap.h:116
@ BJ_BITMAP_COLORKEY
Transparency key for blitting (auto-enables)
Definition bitmap.h:117
@ BJ_TEXT_HALIGN_RIGHT
Align text to the right edge of the area.
Definition bitmap.h:720
@ BJ_TEXT_HALIGN_LEFT
Align text to the left edge of the area.
Definition bitmap.h:718
@ BJ_TEXT_HALIGN_CENTER
Center text horizontally within the area.
Definition bitmap.h:719
@ BJ_TEXT_VALIGN_BOTTOM
Align text to the bottom edge of the area.
Definition bitmap.h:729
@ BJ_TEXT_VALIGN_CENTER
Center text vertically within the area.
Definition bitmap.h:728
@ BJ_TEXT_VALIGN_TOP
Align text to the top edge of the area.
Definition bitmap.h:727
struct bj_stream bj_stream
Definition api.h:374
struct bj_error bj_error
Definition api.h:348
#define BANJO_EXPORT
Definition api.h:179
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:264
struct bj_bitmap bj_bitmap
Definition api.h:340
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.