| 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | #define SWAP16(value) \ |
| 7 | ( \ |
| 8 | (((uint16_t)((value) & 0x00FF)) << 8) | \ |
| 9 | (((uint16_t)((value) & 0xFF00)) >> 8) \ |
| 10 | ) |
| 11 | |
| 12 | #define SWAP32(value) \ |
| 13 | ( \ |
| 14 | (((uint32_t)((value) & 0x000000FF)) << 24) | \ |
| 15 | (((uint32_t)((value) & 0x0000FF00)) << 8) | \ |
| 16 | (((uint32_t)((value) & 0x00FF0000)) >> 8) | \ |
| 17 | (((uint32_t)((value) & 0xFF000000)) >> 24) \ |
| 18 | ) |
| 19 | |
| 20 | #define SWAP64(x) \ |
| 21 | ( \ |
| 22 | (((x) << 56) & 0xFF00000000000000ULL) | \ |
| 23 | (((x) << 40) & 0x00FF000000000000ULL) | \ |
| 24 | (((x) << 24) & 0x0000FF0000000000ULL) | \ |
| 25 | (((x) << 8) & 0x000000FF00000000ULL) | \ |
| 26 | (((x) >> 8) & 0x00000000FF000000ULL) | \ |
| 27 | (((x) >> 24) & 0x0000000000FF0000ULL) | \ |
| 28 | (((x) >> 40) & 0x000000000000FF00ULL) | \ |
| 29 | (((x) >> 56) & 0x00000000000000FFULL) \ |
| 30 | ) |
| 31 | |
| 32 | #define SGN(x) (((x) >= 0) ? 1 : -1) |
| 33 | #define ABS(a) (((a) < 0) ? -(a) : (a)) |
| 34 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 35 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
| 36 | #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) |
| 37 | |
| 38 | #define R12(x) (((x) >> 8) & 0xF) |
| 39 | #define G12(x) (((x) >> 4) & 0xF) |
| 40 | #define B12(x) ((x) & 0xF) |
| 41 | |
| 42 | // 0..15 -> 0..255 |
| 43 | #define R12_to_R24(x) (R12(x) * 17) |
| 44 | #define G12_to_G24(x) (G12(x) * 17) |
| 45 | #define B12_to_B24(x) (B12(x) * 17) |
| 46 | |
| 47 | #define RGB12_to_RGB24(x) ((R12_to_R24(x) << 16) | (G12_to_G24(x) << 8) | (B12_to_B24(x))) |
| 48 | |
| 49 | #define R24(x) (((x) >> 16) & 0xFF) |
| 50 | #define G24(x) (((x) >> 8) & 0xFF) |
| 51 | #define B24(x) ((x) & 0xFF) |
| 52 | |
| 53 | #define RGB24(r, g, b) (((r) << 16) | ((g) << 8) | (b)) |
| 54 | |
| 55 | void showErrorMsgBox(const char *fmt, ...); |
| 56 | |
| 57 | void sanitizeFilenameChar(char *chr); |
| 58 | bool sampleNameIsEmpty(char *name); |
| 59 | bool moduleNameIsEmpty(char *name); |
| 60 | void updateWindowTitle(bool modified); |