Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
bitmap_blit.c

Demonstration on bitmap blit function.

Demonstration on bitmap blit function.Blitting a bj_bitmap into another is done by calling bj_bitmap_blit. This example blits 3 bitmaps onto another and displays the result on screen.

#define BJ_AUTOMAIN_CALLBACKS
#include <banjo/bitmap.h>
#include <banjo/log.h>
#include <banjo/main.h>
#include <banjo/memory.h>
#include <banjo/system.h>
#include <banjo/time.h>
#include <banjo/window.h>
#define WINDOW_W 800
#define WINDOW_H 600
bj_window* window = 0;
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
bj_error* p_error = 0;
bj_bitmap* bmp_rendering = bj_bitmap_new(WINDOW_W, WINDOW_H, BJ_PIXEL_MODE_BGR24, 0);
bj_bitmap_set_clear_color(bmp_rendering, bj_bitmap_pixel_value(bmp_rendering, 0xFF, 0x00, 0x00));
bj_bitmap_clear(bmp_rendering);
bj_bitmap* bmp_blackbuck_512_512 = bj_bitmap_new_from_file(BANJO_ASSETS_DIR"/bmp/blackbuck.bmp", 0);
bj_bitmap* bmp_greenland_grid_velo_762_1309 = bj_bitmap_new_from_file(BANJO_ASSETS_DIR"/bmp/greenland_grid_velo.bmp", 0);
bj_bitmap* bmp_lena_512_512 = bj_bitmap_new_from_file(BANJO_ASSETS_DIR"/bmp/lena.bmp", 0);
bj_bitmap* bmp_snail_256_256 = bj_bitmap_new_from_file(BANJO_ASSETS_DIR"/bmp/snail.bmp", 0);
bj_bitmap_blit(bmp_greenland_grid_velo_762_1309, &(bj_rect){.x = 0, .y = 0, .w = 762, .h = 1309}, bmp_rendering, & (bj_rect){.x = 20, .y = 0});
bj_bitmap_blit(bmp_blackbuck_512_512, &(bj_rect){.x = 100, .y = 100, .w = 512, .h = 512}, bmp_rendering, & (bj_rect){.x = 100, .y = 200});
bj_bitmap_blit(bmp_snail_256_256, &(bj_rect){.x = 0, .y = 0, .w = 256, .h = 256}, bmp_rendering, & (bj_rect){.x = 500, .y = 130});
bj_bitmap_del(bmp_snail_256_256);
bj_bitmap_del(bmp_lena_512_512);
bj_bitmap_del(bmp_greenland_grid_velo_762_1309);
bj_bitmap_del(bmp_blackbuck_512_512);
if(!bj_begin(&p_error)) {
bj_err("Error 0x%08X: %s", p_error->code, p_error->message);
return bj_callback_exit_error;
}
window = bj_window_new("Blitmap Blit", 0, 0, WINDOW_W, WINDOW_H, 0);
bj_bitmap_blit(bmp_rendering, 0, bj_window_get_framebuffer(window, 0), 0);
bj_bitmap_del(bmp_rendering);
return bj_callback_continue;
}
int bj_app_iterate(void* user_data) {
(void)user_data;
bj_sleep(30);
return bj_window_should_close(window)
? bj_callback_exit_success
: bj_callback_continue;
}
int bj_app_end(void* user_data, int status) {
(void)user_data;
bj_window_del(window);
bj_end(0);
return status;
}
Header file for Bitmap type.
void bj_bitmap_del(bj_bitmap *p_bitmap)
Deletes a bj_bitmap object and releases associated memory.
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:22
bj_bitmap * bj_bitmap_new_from_file(const char *p_path, bj_error **p_error)
Creates a new bitmap by loading from a file.
uint32_t code
Error code.
Definition error.h:132
char message[BJ_ERROR_MESSAGE_MAX_LEN+1]
Optional error description.
Definition error.h:133
Error structure.
Definition error.h:131
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:131
@ BJ_PIXEL_MODE_BGR24
24bpp BGR
Definition pixel.h:25
struct bj_rect_t bj_rect
Typedef for bj_rect_t.
Definition rect.h:15
void bj_end(bj_error **p_error)
De-initializes the system.
bj_bool bj_begin(bj_error **p_error)
Initializes the system.
void bj_sleep(int milliseconds)
Suspends the current thread for a specified duration.
bj_window * bj_window_new(const char *p_title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
Create a new bj_window with the specified attributes.
bj_bool bj_window_should_close(bj_window *p_window)
Get the close flag state of a window.
struct bj_window_t bj_window
Opaque typedef for the window type.
Definition window.h:18
bj_bitmap * bj_window_get_framebuffer(bj_window *p_window, bj_error **p_error)
Return the framebuffer attached to the window.
void bj_close_on_escape(bj_window *, bj_event_action, bj_key, int)
An event call back for closing the window when escape key is pressed.
void bj_poll_events(void)
Polls all pending events and dispatch them to callbacks.
void bj_window_del(bj_window *p_window)
Deletes a bj_window object and releases associated memory.
void bj_window_update_framebuffer(bj_window *p_window)
Copy window's framebuffer onto screen.
bj_window_key_event_t bj_window_set_key_event(bj_window *p_window, bj_window_key_event_t p_callback)
Set the callback for key events.
Logging utility functions.
All memory-related functions, including custom allocators.
Header file for system interactions.
Header file for time manipulation.
Header file for bj_window type.