Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
bitmap.h
Go to the documentation of this file.
1
11#pragma once
12#include <banjo/api.h>
13#include <banjo/error.h>
14#include <banjo/pixel.h>
15#include <banjo/rect.h>
16#include <banjo/stream.h>
17
36
37
38
40typedef struct bj_bitmap_t bj_bitmap;
41
48 void
49);
50
67 size_t width,
68 size_t height,
69 bj_pixel_mode mode,
70 size_t stride
71);
72
78BANJO_EXPORT void bj_bitmap_del(
79 bj_bitmap* p_bitmap
80);
81
149 const char* p_path,
150 bj_error** p_error
151);
152
186BANJO_EXPORT bj_bitmap* bj_bitmap_new_from_pixels(
187 void* p_pixels,
188 size_t width,
189 size_t height,
190 bj_pixel_mode mode,
191 size_t stride
192);
193
213BANJO_EXPORT bj_bitmap* bj_bitmap_copy(
214 const bj_bitmap* p_bitmap
215);
216
245BANJO_EXPORT bj_bitmap* bj_bitmap_convert(
246 const bj_bitmap* p_bitmap,
247 bj_pixel_mode mode
248);
249
268BANJO_EXPORT bj_bitmap* bj_bitmap_init(
269 bj_bitmap* p_bitmap,
270 void* p_pixels,
271 size_t width,
272 size_t height,
273 bj_pixel_mode mode,
274 size_t stride
275);
276
282BANJO_EXPORT void bj_bitmap_reset(
283 bj_bitmap* p_bitmap
284);
285
292BANJO_EXPORT void* bj_bitmap_pixels(
293 bj_bitmap* p_bitmap
294);
295
302BANJO_EXPORT size_t bj_bitmap_width(
303 const bj_bitmap* p_bitmap
304);
305
312BANJO_EXPORT size_t bj_bitmap_height(
313 const bj_bitmap* p_bitmap
314);
315
322BANJO_EXPORT int bj_bitmap_mode(
323 bj_bitmap* p_bitmap
324);
325
332BANJO_EXPORT size_t bj_bitmap_stride(
333 bj_bitmap* p_bitmap
334);
335
347BANJO_EXPORT void bj_bitmap_rgb(
348 const bj_bitmap* p_bitmap,
349 size_t x,
350 size_t y,
351 uint8_t* p_red,
352 uint8_t* p_green,
353 uint8_t* p_blue
354);
355
366BANJO_EXPORT uint32_t bj_bitmap_pixel_value(
367 bj_bitmap* p_bitmap,
368 uint8_t red,
369 uint8_t green,
370 uint8_t blue
371);
372
381BANJO_EXPORT void bj_bitmap_put_pixel(
382 bj_bitmap* p_bitmap,
383 size_t x,
384 size_t y,
385 uint32_t value
386);
387
397BANJO_EXPORT void bj_bitmap_clear(
398 bj_bitmap* p_bitmap
399);
400
411BANJO_EXPORT void bj_bitmap_set_colorkey(
412 bj_bitmap* p_bitmap,
413 bj_bool enabled,
414 uint32_t key_value
415);
416
433BANJO_EXPORT uint32_t bj_bitmap_get(
434 const bj_bitmap* p_bitmap,
435 size_t x,
436 size_t y
437);
438
445BANJO_EXPORT void bj_bitmap_set_clear_color(
446 bj_bitmap* p_bitmap,
447 uint32_t clear_color
448);
449
483BANJO_EXPORT bj_bool bj_bitmap_blit(
484 const bj_bitmap* src, const bj_rect* src_area,
485 bj_bitmap* dst, const bj_rect* dst_area,
486 bj_blit_op op);
487
511BANJO_EXPORT bj_bool bj_bitmap_blit_stretched(
512 const bj_bitmap* src, const bj_rect* src_area,
513 bj_bitmap* dst, const bj_rect* dst_area,
514 bj_blit_op op);
515
534typedef enum {
535 BJ_MASK_BG_TRANSPARENT = 0,
536 BJ_MASK_BG_OPAQUE,
537 BJ_MASK_BG_REV_TRANSPARENT
538} bj_mask_bg_mode;
539
572BANJO_EXPORT bj_bool bj_bitmap_blit_mask(
573 const bj_bitmap* mask,
574 const bj_rect* mask_area, /* NULL = full mask */
576 const bj_rect* dst_area, /* NULL = place at {0,0} w/ mask_area size */
577 uint32_t fg_native, /* dst-native packed color */
578 uint32_t bg_native, /* dst-native packed color */
579 bj_mask_bg_mode mode
580);
581
608 const bj_bitmap* mask,
609 const bj_rect* mask_area, /* NULL = full mask */
610 bj_bitmap* dst,
611 const bj_rect* dst_area, /* NULL = fill entire dst */
612 uint32_t fg_native,
613 uint32_t bg_native,
614 bj_mask_bg_mode mode
615);
616
650BANJO_EXPORT void bj_bitmap_print(
651 bj_bitmap* dst,
652 int x,
653 int y,
654 unsigned height,
655 uint32_t fg_native,
656 const char* text
657);
658
680BANJO_EXPORT void bj_bitmap_printf(
681 bj_bitmap* p_bitmap,
682 int x,
683 int y,
684 unsigned height,
685 uint32_t fg_native,
686 const char* fmt,
687 ...
688);
689
743BANJO_EXPORT void bj_bitmap_blit_text(
744 bj_bitmap* dst,
745 int x,
746 int y,
747 unsigned height,
748 uint32_t fg_native,
749 uint32_t bg_native,
750 bj_mask_bg_mode mode, /* TRANSPARENT / OPAQUE / REV_TRANSPARENT */
751 const char* text
752);
753
General-purpose definitions for Banjo API.
Recoverable error handling.
void bj_bitmap_print(bj_bitmap *dst, int x, int y, unsigned height, uint32_t fg_native, const char *text)
Prints text using the default foreground color and transparent background.
bj_bitmap * bj_bitmap_alloc(void)
Allocate a new bitmap object.
bj_bitmap * dst
Definition bitmap.h:575
void bj_bitmap_del(bj_bitmap *p_bitmap)
Deletes a bj_bitmap object and releases associated memory.
void bj_bitmap_printf(bj_bitmap *p_bitmap, int x, int y, unsigned height, uint32_t fg_native, const char *fmt,...)
Prints formatted text into a bitmap, similar to printf.
bj_blit_op
Raster operation (ROP) to apply during blitting.
Definition bitmap.h:28
bj_bitmap * bj_bitmap_new(size_t width, size_t height, bj_pixel_mode mode, size_t stride)
Creates a new bj_bitmap with the specified width and height.
struct bj_bitmap_t bj_bitmap
Typedef for the bj_bitmap struct.
Definition bitmap.h:40
bj_bitmap * bj_bitmap_new_from_file(const char *p_path, bj_error **p_error)
Creates a new bitmap by loading from a file.
bj_bool bj_bitmap_blit_mask_stretched(const bj_bitmap *mask, const bj_rect *mask_area, bj_bitmap *dst, const bj_rect *dst_area, uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode)
Masked blit with stretching (nearest neighbor). The mask must be 8bpp.
@ BJ_BLIT_OP_OR
Bitwise OR.
Definition bitmap.h:31
@ BJ_BLIT_OP_COPY
Copy source to destination (fast path when formats match)
Definition bitmap.h:29
@ BJ_BLIT_OP_AND
Bitwise AND.
Definition bitmap.h:32
@ BJ_BLIT_OP_ADD_SAT
Per-channel saturated add (clamped to 255)
Definition bitmap.h:33
@ BJ_BLIT_OP_XOR
Bitwise XOR (channel-wise for >8bpp)
Definition bitmap.h:30
@ BJ_BLIT_OP_SUB_SAT
Per-channel saturated subtract (clamped to 0)
Definition bitmap.h:34
uint32_t bj_bool
Boolean type used throughout the BJ codebase.
Definition api.h:143
Error structure.
Definition error.h:131
bj_pixel_mode
Representation of a pixel encoding.
Definition pixel.h:15
struct bj_rect_t bj_rect
Typedef for bj_rect_t.
Definition rect.h:15
Header file for general pixel manipulation facilities.
Defines the bj_rect struct representing a rectangle with position and dimensions.
Header file for bj_stream_t struct and related functions.