GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_convert.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz>
4 * Copyright (C) 2023-2024 Cyril Hrubis <metan@ucw.cz>
5 */
6
12#ifndef CORE_GP_CONVERT_H
13#define CORE_GP_CONVERT_H
14
15#include <core/gp_pixmap.h>
16#include <core/gp_pixel.h>
17#include <core/gp_convert.gen.h>
19
30static inline gp_pixel gp_rgb_to_pixel(uint8_t r, uint8_t g, uint8_t b,
31 gp_pixel_type type)
32{
33 gp_pixel p = GP_PIXEL_CREATE_RGB888(r, g, b);
34 return gp_RGB888_to_pixel(p, type);
35}
36
48static inline gp_pixel gp_rgba_to_pixel(uint8_t r, uint8_t g, uint8_t b,
49 uint8_t a, gp_pixel_type type)
50{
51 gp_pixel p = GP_PIXEL_CREATE_RGBA8888(r, g, b, a);
52 return gp_RGBA8888_to_pixel(p, type);
53}
54
55/*
56 * Converts a color specified by its R, G, B components to a pixel value
57 * compatible with the specified pixmap.
58 */
59static inline gp_pixel gp_rgb_to_pixmap_pixel(uint8_t r, uint8_t g, uint8_t b,
60 const gp_pixmap *pixmap)
61{
62 return gp_rgb_to_pixel(r, g, b, pixmap->pixel_type);
63}
64
65/*
66 * Converts a color specified by its R, G, B, A components to a pixel value
67 * compatible with the specified pixmap.
68 */
69static inline gp_pixel gp_rgba_to_pixmap_pixel(uint8_t r, uint8_t g,
70 uint8_t b, uint8_t a,
71 const gp_pixmap *pixmap)
72{
73 return gp_rgba_to_pixel(r, g, b, a, pixmap->pixel_type);
74}
75
76/*
77 * Convert between any pixel types (excl. palette types) via RGBA8888
78 */
79static inline gp_pixel gp_convert_pixel(gp_pixel pixel, gp_pixel_type from,
81{
82 return gp_RGBA8888_to_pixel(gp_pixel_to_RGBA8888(pixel, from), to);
83}
84
85/*
86 * Convert between pixel types of given pixmaps (excl. palette types) via
87 * RGBA8888.
88 */
89static inline gp_pixel gp_convert_pixmap_pixel(gp_pixel pixel,
90 const gp_pixmap *from,
91 const gp_pixmap *to)
92{
94 to->pixel_type);
95}
96
97#endif /* CORE_GP_CONVERT_H */
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
Macros and functions for conversions between pixel types.
gp_pixel gp_pixel_to_RGBA8888(gp_pixel pixel, gp_pixel_type type)
Converts to RGBA8888 from any other pixel type.
gp_pixel gp_RGB888_to_pixel(gp_pixel pixel, gp_pixel_type type)
Convert RGB888 to any other pixel type.
gp_pixel gp_RGBA8888_to_pixel(gp_pixel pixel, gp_pixel_type type)
Convert RGBA8888 to any other pixel type.
static gp_pixel gp_rgb_to_pixel(uint8_t r, uint8_t g, uint8_t b, gp_pixel_type type)
Converts a color specified by its R, G, B components to a specified type.
Definition gp_convert.h:30
static gp_pixel gp_rgba_to_pixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, gp_pixel_type type)
Converts a color specified by its R, G, B, A components to a specified type.
Definition gp_convert.h:48
Fast value scaling macros.
gp_pixel_type
List of all pixel types.
A pixel description.
A pixel buffer.
A pixmap buffer.
Definition gp_pixmap.h:33
enum gp_pixel_type pixel_type
A pixel format.
Definition gp_pixmap.h:63