libtcod
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_IMAGE_H_
36#define TCOD_IMAGE_H_
37
38#include "color.h"
39#include "console_types.h"
40#include "error.h"
41#include "portability.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47struct TCOD_mipmap_ {
48 int width, height;
49 float fwidth, fheight;
50 TCOD_ColorRGB* __restrict buf;
51 bool dirty;
52};
53
54typedef struct TCOD_Image {
55 int nb_mipmaps;
56 struct TCOD_mipmap_* __restrict mipmaps;
57 TCOD_ColorRGB key_color;
58 bool has_key_color;
60
61typedef TCOD_Image* TCOD_image_t;
62
63TCODLIB_API TCOD_Image* TCOD_image_new(int width, int height);
69TCODLIB_API TCOD_Image* TCOD_image_from_console(const TCOD_Console* console);
73TCODLIB_API void TCOD_image_refresh_console(TCOD_Image* image, const TCOD_Console* console);
74TCODLIB_API void TCOD_image_clear(TCOD_Image* image, TCOD_color_t color);
75TCODLIB_API void TCOD_image_invert(TCOD_Image* image);
76TCODLIB_API void TCOD_image_hflip(TCOD_Image* image);
77TCODLIB_API void TCOD_image_rotate90(TCOD_Image* image, int numRotations);
78TCODLIB_API void TCOD_image_vflip(TCOD_Image* image);
79TCODLIB_API void TCOD_image_scale(TCOD_Image* image, int new_w, int new_h);
80#ifndef NO_SDL
81TCODLIB_API TCOD_Image* TCOD_image_load(const char* filename);
91TCODLIB_API TCOD_Error TCOD_image_save(const TCOD_Image* image, const char* filename);
92#endif // NO_SDL
93TCODLIB_API void TCOD_image_get_size(const TCOD_Image* image, int* w, int* h);
94TCODLIB_API TCOD_color_t TCOD_image_get_pixel(const TCOD_Image* image, int x, int y);
95TCODLIB_API int TCOD_image_get_alpha(const TCOD_Image* image, int x, int y);
102TCODLIB_API TCOD_color_t TCOD_image_get_mipmap_pixel(TCOD_Image* image, float x0, float y0, float x1, float y1);
103TCODLIB_API void TCOD_image_put_pixel(TCOD_Image* image, int x, int y, TCOD_color_t col);
104TCODLIB_API void TCOD_image_blit(
105 TCOD_Image* image,
106 TCOD_console_t console,
107 float x,
108 float y,
109 TCOD_bkgnd_flag_t bkgnd_flag,
110 float scale_x,
111 float scale_y,
112 float angle);
113TCODLIB_API void TCOD_image_blit_rect(
114 TCOD_Image* image, TCOD_console_t console, int x, int y, int w, int h, TCOD_bkgnd_flag_t bkgnd_flag);
115TCODLIB_API void TCOD_image_blit_2x(
116 const TCOD_Image* __restrict image, TCOD_Console* __restrict dest, int dx, int dy, int sx, int sy, int w, int h);
117TCODLIB_API void TCOD_image_delete(TCOD_Image* image);
118TCODLIB_API void TCOD_image_set_key_color(TCOD_Image* image, TCOD_color_t key_color);
119TCODLIB_API bool TCOD_image_is_pixel_transparent(const TCOD_Image* image, int x, int y);
120
121#ifdef __cplusplus
122}
123namespace tcod {} // namespace tcod
124#endif // __cplusplus
125#endif // TCOD_IMAGE_H_
Color handling module.
C types for console functions.
Error handling module.
TCOD_Error
An enum of libtcod error codes.
Definition error.h:48
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
TCOD_Error TCOD_image_save(const TCOD_Image *image, const char *filename)
Save an image to a PNG or BMP file.
TCOD_color_t TCOD_image_get_mipmap_pixel(TCOD_Image *image, float x0, float y0, float x1, float y1)
Return a mipmapped pixel of image.
TCOD_Image * TCOD_image_from_console(const TCOD_Console *console)
Return a new image rendered from a console.
void TCOD_image_refresh_console(TCOD_Image *image, const TCOD_Console *console)
Same as TCOD_image_from_console, but with an existing image.
The libtcod namespace.
Definition bresenham.hpp:157
Miscellaneous tools needed across platforms.
A 3-channel RGB color struct.
Definition color.h:50
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125
Definition image.h:54