GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_pattern_fill.h File Reference

A pattern fill constants. More...

#include <core/gp_types.h>
#include <stdbool.h>

Go to the source code of this file.

Macros

#define GP_PIXEL_PATTERN_CNT   10
 Number of patterns.
 
#define GP_PIXEL_PATTERN_MASK   0x0f00
 Pattern mask.
 
#define GP_PIXEL_PATTERN_SHIFT   8
 Pattern shift.
 
#define GP_PIXEL_PATTERN_FG_MASK   0x000f
 Pattern foreground color mask.
 
#define GP_PIXEL_PATTERN_FG_SHIFT   0
 Pattern foreground color shift.
 
#define GP_PIXEL_PATTERN_BG_MASK   0x00f0
 Pattern background color mask.
 
#define GP_PIXEL_PATTERN_BG_SHIFT   4
 Pattern background color shift.
 
#define GP_PIXEL_PATTERN_W   4
 Pattern width.
 
#define GP_PIXEL_PATTERN_H   4
 Pattern height.
 

Enumerations

enum  gp_pixel_pattern {
  GP_PIXEL_PATTERN_NONE = 0x00 , GP_PIXEL_PATTERN_50 = 0x01 , GP_PIXEL_PATTERN_ASC_25 = 0x02 , GP_PIXEL_PATTERN_DSC_25 = 0x03 ,
  GP_PIXEL_PATTERN_ASC_75 = 0x04 , GP_PIXEL_PATTERN_DSC_75 = 0x05 , GP_PIXEL_PATTERN_DOTS_12_5 = 0x06 , GP_PIXEL_PATTERN_DOTS_25 = 0x07 ,
  GP_PIXEL_PATTERN_DOTS_75 = 0x08 , GP_PIXEL_PATTERN_DOTS_87_5 = 0x09
}
 Pattern fill constants. More...
 

Functions

static enum gp_pixel_pattern gp_pixel_pattern_get (gp_pixel pixel)
 Returns a pattern for a grayscale pixel.
 
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_bg_get (gp_pixel pixel)
 Returns a pattern background for a grayscale pixel.
 
static gp_pixel gp_pixel_pattern (uint8_t fg_color, uint8_t bg_color, enum gp_pixel_pattern pattern)
 Creates a pattern from a colors and pattern type.
 
static uint8_t * gp_pixel_pattern_lookup_table_get (enum gp_pixel_pattern pattern)
 Returns a pattern lookup table.
 
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.
 

Variables

uint8_t * gp_pixel_pattern_lookup_table [10]
 A pattern lookup tables.
 

Detailed Description

A pattern fill constants.

Constants for different fill patterns for 1bpp fill runtines.

Definition in file gp_pattern_fill.h.

Macro Definition Documentation

◆ GP_PIXEL_PATTERN_H

#define GP_PIXEL_PATTERN_H   4

Pattern height.

All patterns are limited to this height.

Definition at line 301 of file gp_pattern_fill.h.

◆ GP_PIXEL_PATTERN_MASK

#define GP_PIXEL_PATTERN_MASK   0x0f00

Pattern mask.

After applying a pattern mask on a pixel the value can be compared to the pattern constants.

Definition at line 208 of file gp_pattern_fill.h.

Referenced by gp_pixel_pattern(), and gp_pixel_pattern_get().

◆ GP_PIXEL_PATTERN_SHIFT

#define GP_PIXEL_PATTERN_SHIFT   8

Pattern shift.

The pattern value is shifted to the left by this number of bits.

Definition at line 215 of file gp_pattern_fill.h.

Referenced by gp_pixel_pattern(), and gp_pixel_pattern_get().

◆ GP_PIXEL_PATTERN_W

#define GP_PIXEL_PATTERN_W   4

Pattern width.

All patterns are limited to this width.

Definition at line 294 of file gp_pattern_fill.h.

Enumeration Type Documentation

◆ gp_pixel_pattern

Pattern fill constants.

The upper bits enable a pattern and the bottom bit changes the starting offset, i.e. wheter pixel at even address starts as a black or white.

Attention
Pattern fill works only with 1bpp aka monochrome colors.
Enumerator
GP_PIXEL_PATTERN_NONE 

No pattern.

If upper byte of the pixel is zeroed it's a solid color.

GP_PIXEL_PATTERN_50 

This patterns pattern draws every other pixel and swaps offset on each line.

# # # # # # # #
# # # # # # #
# # # # # # # #
# # # # # # #
# # # # # # # #
# # # # # # #
# # # # # # # #
Attention
This pattern value can be also passed to all hline and vline functions where it will draw a dotted line that matches the placement of white and black pixels in the pattern.
GP_PIXEL_PATTERN_ASC_25 

This pattern draws ascending 45 degrees lines that are spaced so that the color fills 25% of the area.

# # # # #
# # # #
# # # #
# # # #
# # # # #
Attention
This pattern value can be also passed to all hline and vline functions where it will draw a dotted line that matches the placement of white and black pixels in the pattern.
GP_PIXEL_PATTERN_DSC_25 

This pattern draws descending 45 degrees lines that are spaced so that the color fills 25% of the area.

# # # # #
# # # #
# # # #
# # # #
# # # # #
Attention
This pattern value can be also passed to all hline and vline functions where it will draw a dotted line that matches the placement of white and black pixels in the pattern.
GP_PIXEL_PATTERN_ASC_75 

This pattern draws ascending 45 degrees lines that are spaced so that the color fills 75% of the area.

### ### ### ### #
## ### ### ### ##
# ### ### ### ###
### ### ### ###
### ### ### ### #
Attention
This pattern value can be also passed to all hline and vline functions where it will draw a dotted line that matches the placement of white and black pixels in the pattern.
GP_PIXEL_PATTERN_DSC_75 

This pattern draws ascending 45 degrees lines that are spaced so that the color fills 75% of the area.

### ### ### ### #
### ### ### ###
# ### ### ### ###
## ### ### ### ##
### ### ### ### #
Attention
This pattern value can be also passed to all hline and vline functions where it will draw a dotted line that matches the placement of white and black pixels in the pattern.
GP_PIXEL_PATTERN_DOTS_12_5 

This pattern draws dots that fill 12.5% of the space.

# # # #
# # # #
GP_PIXEL_PATTERN_DOTS_25 

This pattern draws dots that fill 25% of the space.

# # # # # # # #
# # # # # # # #
# # # # # # # #
# # # # # # # #
GP_PIXEL_PATTERN_DOTS_75 

This pattern draws inverse dots that fill 75% of the space.

# # # # # # # #
################
# # # # # # # #
################
# # # # # # # #
################
# # # # # # # #
################
GP_PIXEL_PATTERN_DOTS_87_5 

This pattern draws inverse dots that fill 87.5% of the space.

### ### ### ###
################
################
################
### ### ### ###
################
################
################

Definition at line 27 of file gp_pattern_fill.h.

Function Documentation

◆ gp_pixel_pattern()

static gp_pixel gp_pixel_pattern ( uint8_t fg_color,
uint8_t bg_color,
enum gp_pixel_pattern pattern )
inlinestatic

Creates a pattern from a colors and pattern type.

Parameters
fg_colorA pattern foreground color.
bg_colorA pattern background color.
patternA pattern.
Returns
A pattern pixel color.

Definition at line 279 of file gp_pattern_fill.h.

References GP_PIXEL_PATTERN_BG_MASK, GP_PIXEL_PATTERN_BG_SHIFT, GP_PIXEL_PATTERN_FG_MASK, GP_PIXEL_PATTERN_FG_SHIFT, GP_PIXEL_PATTERN_MASK, and GP_PIXEL_PATTERN_SHIFT.

◆ gp_pixel_pattern_bg_get()

static gp_pixel gp_pixel_pattern_bg_get ( gp_pixel pixel)
inlinestatic

Returns a pattern background for a grayscale pixel.

@pixel A 1bpp pixel.

Returns
A pixel background color.

Definition at line 265 of file gp_pattern_fill.h.

References GP_PIXEL_PATTERN_BG_MASK, and GP_PIXEL_PATTERN_BG_SHIFT.

◆ gp_pixel_pattern_fg_get()

static gp_pixel gp_pixel_pattern_fg_get ( gp_pixel pixel)
inlinestatic

Returns a pattern foreground for a grayscale pixel.

@pixel A 1bpp pixel.

Returns
A pixel foreground color.

Definition at line 254 of file gp_pattern_fill.h.

References GP_PIXEL_PATTERN_FG_MASK, and GP_PIXEL_PATTERN_FG_SHIFT.

◆ gp_pixel_pattern_get()

static enum gp_pixel_pattern gp_pixel_pattern_get ( gp_pixel pixel)
inlinestatic

Returns a pattern for a grayscale pixel.

@pixel A 1bpp pixel.

Returns
A pattern constant.

Definition at line 243 of file gp_pattern_fill.h.

References GP_PIXEL_PATTERN_MASK, and GP_PIXEL_PATTERN_SHIFT.

◆ gp_pixel_pattern_lookup_table_get()

static uint8_t * gp_pixel_pattern_lookup_table_get ( enum gp_pixel_pattern pattern)
inlinestatic

Returns a pattern lookup table.

The table is then passed down to the gp_pixel_pattern_pixel() function to determine a pixel value at a given coordinates.

Parameters
patternA pixel pattern.
Returns
A byte array lookup table suitable.

Definition at line 317 of file gp_pattern_fill.h.

References gp_pixel_pattern_lookup_table.

◆ gp_pixel_pattern_pixel_get()

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 )
inlinestatic

Looks up a pixel color in a pattern based on x and y offsets.

Parameters
lookupA pattern lookup table.
fgA foreground pixel color.
bgA background pixel color.
x_modAn X offset of the pixel, i.e. x coordinate modulo GP_PIXEL_PATTERN_W.
y_modAn Y offset of the pixel, i.e. y coordinate modulo GP_PIXEL_PATTERN_H.
Returns
A pixel value for a given coordinates and pattern.

Definition at line 333 of file gp_pattern_fill.h.