GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_pattern_fill.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2025 Cyril Hrubis <metan@ucw.cz>
4 */
5
13#ifndef CORE_GP_PATTERN_FILL_H
14#define CORE_GP_PATTERN_FILL_H
15
16#include <core/gp_types.h>
17#include <stdbool.h>
18
196
200#define GP_PIXEL_PATTERN_CNT 10
201
208#define GP_PIXEL_PATTERN_MASK 0x0f00
209
215#define GP_PIXEL_PATTERN_SHIFT 8
216
220#define GP_PIXEL_PATTERN_FG_MASK 0x000f
221
225#define GP_PIXEL_PATTERN_FG_SHIFT 0
226
230#define GP_PIXEL_PATTERN_BG_MASK 0x00f0
231
235#define GP_PIXEL_PATTERN_BG_SHIFT 4
236
244{
246}
247
258
269
279static inline gp_pixel gp_pixel_pattern(uint8_t fg_color, uint8_t bg_color, enum gp_pixel_pattern pattern)
280{
281 if (fg_color == bg_color)
282 return fg_color;
283
284 return (GP_PIXEL_PATTERN_FG_MASK & (fg_color << GP_PIXEL_PATTERN_FG_SHIFT)) |
287}
288
294#define GP_PIXEL_PATTERN_W 4
295
301#define GP_PIXEL_PATTERN_H 4
302
307
317static inline uint8_t *gp_pixel_pattern_lookup_table_get(enum gp_pixel_pattern pattern)
318{
319 return gp_pixel_pattern_lookup_table[pattern];
320}
321
333static inline gp_pixel gp_pixel_pattern_pixel_get(uint8_t *lookup, gp_pixel fg, gp_pixel bg,
334 uint8_t x_mod, uint8_t y_mod)
335{
336 return lookup[y_mod] & (8>>x_mod) ? fg : bg;
337}
338
339#endif /* CORE_GP_PATTERN_FILL_H */
A common types.
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
static gp_pixel gp_pixel_pattern_bg_get(gp_pixel pixel)
Returns a pattern background for a grayscale pixel.
gp_pixel_pattern
Pattern fill constants.
@ GP_PIXEL_PATTERN_ASC_25
This pattern draws ascending 45 degrees lines that are spaced so that the color fills 25% of the area...
@ GP_PIXEL_PATTERN_50
This patterns pattern draws every other pixel and swaps offset on each line.
@ GP_PIXEL_PATTERN_DOTS_12_5
This pattern draws dots that fill 12.5% of the space.
@ GP_PIXEL_PATTERN_DOTS_87_5
This pattern draws inverse dots that fill 87.5% of the space.
@ GP_PIXEL_PATTERN_DSC_75
This pattern draws ascending 45 degrees lines that are spaced so that the color fills 75% of the area...
@ GP_PIXEL_PATTERN_DSC_25
This pattern draws descending 45 degrees lines that are spaced so that the color fills 25% of the are...
@ GP_PIXEL_PATTERN_ASC_75
This pattern draws ascending 45 degrees lines that are spaced so that the color fills 75% of the area...
@ GP_PIXEL_PATTERN_NONE
No pattern.
@ GP_PIXEL_PATTERN_DOTS_75
This pattern draws inverse dots that fill 75% of the space.
@ GP_PIXEL_PATTERN_DOTS_25
This pattern draws dots that fill 25% of the space.
#define GP_PIXEL_PATTERN_SHIFT
Pattern shift.
#define GP_PIXEL_PATTERN_CNT
Number of patterns.
static gp_pixel gp_pixel_pattern_fg_get(gp_pixel pixel)
Returns a pattern foreground for a grayscale pixel.
static gp_pixel gp_pixel_pattern_pixel_get(uint8_t *lookup, gp_pixel fg, gp_pixel bg, uint8_t x_mod, uint8_t y_mod)
Looks up a pixel color in a pattern based on x and y offsets.
#define GP_PIXEL_PATTERN_BG_SHIFT
Pattern background color shift.
uint8_t * gp_pixel_pattern_lookup_table[10]
A pattern lookup tables.
#define GP_PIXEL_PATTERN_BG_MASK
Pattern background color mask.
#define GP_PIXEL_PATTERN_MASK
Pattern mask.
#define GP_PIXEL_PATTERN_FG_MASK
Pattern foreground color mask.
static uint8_t * gp_pixel_pattern_lookup_table_get(enum gp_pixel_pattern pattern)
Returns a pattern lookup table.
#define GP_PIXEL_PATTERN_FG_SHIFT
Pattern foreground color shift.
static enum gp_pixel_pattern gp_pixel_pattern_get(gp_pixel pixel)
Returns a pattern for a grayscale pixel.