70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
#ifndef UTILS_H
|
|
#define UTILS_H
|
|
|
|
#define BYTE_A 0xFF000000u
|
|
#define BYTE_R 0x00FF0000u
|
|
#define BYTE_G 0x0000FF00u
|
|
#define BYTE_B 0x000000FFu
|
|
#define BYTE_RGB 0x00FFFFFFu
|
|
#define BYTE 0xFFu
|
|
#define LONG_BYTE 0xFFFFu
|
|
|
|
#define SHIFT_8 8
|
|
#define SHIFT_16 16
|
|
#define SHIFT_24 24
|
|
|
|
#define MAX 255
|
|
#define HALF_MAX ((int)(MAX / 2) + 1)
|
|
|
|
#define DECODE_A(clr) (((clr) >> SHIFT_24) & BYTE)
|
|
#define DECODE_R(clr) (((clr) >> SHIFT_16) & BYTE)
|
|
#define DECODE_G(clr) (((clr) >> SHIFT_8) & BYTE)
|
|
#define DECODE_B(clr) ((clr) & BYTE)
|
|
|
|
#define ENCODE_RGB(r, g, b) \
|
|
(((unsigned int)(MAX) << SHIFT_24) | ((unsigned int)(r) << SHIFT_16) | \
|
|
((unsigned int)(g) << SHIFT_8) | (unsigned int)(b))
|
|
|
|
#define ENCODE_ARGB(a, r, g, b) \
|
|
(((unsigned int)(a) << SHIFT_24) | ((unsigned int)(r) << SHIFT_16) | \
|
|
((unsigned int)(g) << SHIFT_8) | (unsigned int)(b))
|
|
|
|
// #define ENCODE_BGRA(b, g, r, a) \
|
|
// (((unsigned int)(b) << SHIFT_24) | ((unsigned int)(g) << SHIFT_16) | \
|
|
// ((unsigned int)(r) << SHIFT_8) | (unsigned int)(a))
|
|
|
|
#define CLAMP_MAX(x) (((x) > MAX) ? MAX : (x))
|
|
#define CLAMP_MIN(x) (((x) < 0) ? 0 : (x))
|
|
|
|
typedef struct
|
|
{
|
|
int width, height;
|
|
int len;
|
|
char* name;
|
|
char fmt;
|
|
} PPM;
|
|
|
|
typedef struct
|
|
{
|
|
int width, height;
|
|
int len;
|
|
char* name;
|
|
} JPEG;
|
|
|
|
unsigned long
|
|
u32to_u64(const unsigned int clr);
|
|
|
|
unsigned int
|
|
u64to_u32(const unsigned long clr, const unsigned long u64_div);
|
|
|
|
/**
|
|
* Pretty Self Explanitory but prints the attributes of PPM images
|
|
* */
|
|
void __attribute__((overloadable)) print_attr(const PPM *src);
|
|
/**
|
|
* Pretty Self Explanitory but prints the attributes of JPEG images
|
|
* */
|
|
void __attribute__((overloadable)) print_attr(const JPEG *src);
|
|
|
|
#endif
|