GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_bit_swap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2012 Cyril Hrubis <metan@ucw.cz>
4 */
5
11#ifndef CORE_GP_BIT_SWAP_H
12#define CORE_GP_BIT_SWAP_H
13
25static inline uint8_t GP_BIT_SWAP_B1(uint8_t byte)
26{
27 return ((byte * 0x0802LU & 0x22110LU) |
28 (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
29}
30
37static inline void gp_bit_swap_row_b1(uint8_t *row, unsigned int len)
38{
39 unsigned int i;
40
41 for (i = 0; i < len; i++)
42 row[i] = GP_BIT_SWAP_B1(row[i]);
43}
44
56static inline uint8_t GP_BIT_SWAP_B2(uint8_t byte)
57{
58 return ((byte & 0xC0) >> 6) | ((byte & 0x30) >> 2) |
59 ((byte & 0x0C) << 2) | ((byte & 0x03) << 6);
60}
61
68static inline void gp_bit_swap_row_b2(uint8_t *row, unsigned int len)
69{
70 unsigned int i;
71
72 for (i = 0; i < len; i++)
73 row[i] = GP_BIT_SWAP_B2(row[i]);
74}
75
87static inline uint8_t GP_BIT_SWAP_B4(uint8_t byte)
88{
89 return ((byte & 0xf0) >> 4) | ((byte & 0x0f) << 4);
90}
91
98static inline void gp_bit_swap_row_b4(uint8_t *row, unsigned int len)
99{
100 unsigned int i;
101
102 for (i = 0; i < len; i++)
103 row[i] = GP_BIT_SWAP_B4(row[i]);
104}
105
106#endif /* CORE_GP_BIT_SWAP_H */
static uint8_t GP_BIT_SWAP_B1(uint8_t byte)
Reverses 1 bit blocks in the byte.
Definition gp_bit_swap.h:25
static uint8_t GP_BIT_SWAP_B4(uint8_t byte)
Reverses 4 bit blocks in the byte.
Definition gp_bit_swap.h:87
static void gp_bit_swap_row_b4(uint8_t *row, unsigned int len)
Reverses 4 bit blocks in a row.
Definition gp_bit_swap.h:98
static uint8_t GP_BIT_SWAP_B2(uint8_t byte)
Reverses 2 bit blocks in the byte.
Definition gp_bit_swap.h:56
static void gp_bit_swap_row_b2(uint8_t *row, unsigned int len)
Reverses 2 bit blocks in a row.
Definition gp_bit_swap.h:68
static void gp_bit_swap_row_b1(uint8_t *row, unsigned int len)
Reverses 1 bit blocks in a row.
Definition gp_bit_swap.h:37