From 952bd17480865d5fd23789d972fe33615095839c Mon Sep 17 00:00:00 2001 From: Artem Senichev Date: Sun, 28 Jan 2024 18:14:29 +0300 Subject: [PATCH] Remove types.h file Content now in pixmap. Signed-off-by: Artem Senichev --- src/config.h | 2 +- src/font.h | 2 +- src/pixmap.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++- src/sway.h | 2 +- src/types.h | 62 ---------------------------------------------------- src/ui.h | 2 +- src/viewer.h | 2 +- 7 files changed, 61 insertions(+), 68 deletions(-) delete mode 100644 src/types.h diff --git a/src/config.h b/src/config.h index 487afde..11302b4 100644 --- a/src/config.h +++ b/src/config.h @@ -4,7 +4,7 @@ #pragma once -#include "types.h" +#include "pixmap.h" // Name of the general configuration section #define GENERAL_CONFIG_SECTION "general" diff --git a/src/font.h b/src/font.h index 2418fd9..65e9578 100644 --- a/src/font.h +++ b/src/font.h @@ -4,7 +4,7 @@ #pragma once -#include "types.h" +#include "pixmap.h" /** * Initialize font. diff --git a/src/pixmap.h b/src/pixmap.h index 8c01f7a..c7129ea 100644 --- a/src/pixmap.h +++ b/src/pixmap.h @@ -4,7 +4,62 @@ #pragma once -#include "types.h" +#include +#include +#include +#include + +/** ARGB color. */ +typedef uint32_t argb_t; + +// shifts for each channel in argb_t +#define ARGB_A_SHIFT 24 +#define ARGB_R_SHIFT 16 +#define ARGB_G_SHIFT 8 +#define ARGB_B_SHIFT 0 + +// get channel value from argb_t +#define ARGB_GET_A(c) (((c) >> ARGB_A_SHIFT) & 0xff) +#define ARGB_GET_R(c) (((c) >> ARGB_R_SHIFT) & 0xff) +#define ARGB_GET_G(c) (((c) >> ARGB_G_SHIFT) & 0xff) +#define ARGB_GET_B(c) (((c) >> ARGB_B_SHIFT) & 0xff) + +// create argb_t from channel value +#define ARGB_SET_A(a) (((a)&0xff) << ARGB_A_SHIFT) +#define ARGB_SET_R(r) (((r)&0xff) << ARGB_R_SHIFT) +#define ARGB_SET_G(g) (((g)&0xff) << ARGB_G_SHIFT) +#define ARGB_SET_B(b) (((b)&0xff) << ARGB_B_SHIFT) + +// convert RGBA to ARGB +#define ARGB_SET_ABGR(c) \ + ((c & 0xff00ff00) | ARGB_SET_R(ARGB_GET_B(c)) | ARGB_SET_B(ARGB_GET_R(c))) + +// alpha blending (a=alpha, s=target alpha, b=background, f=foreground) +#define ARGB_ALPHA_BLEND(a, s, b, f) \ + ARGB_SET_A(s) | \ + ARGB_SET_R((a * ARGB_GET_R(f) + (256 - a) * ARGB_GET_R(b)) >> 8) | \ + ARGB_SET_G((a * ARGB_GET_G(f) + (256 - a) * ARGB_GET_G(b)) >> 8) | \ + ARGB_SET_B((a * ARGB_GET_B(f) + (256 - a) * ARGB_GET_B(b)) >> 8) + +/** 2D coordinates. */ +struct point { + ssize_t x; + ssize_t y; +}; + +/** Size description. */ +struct size { + size_t width; + size_t height; +}; + +/** Rectangle description. */ +struct rect { + ssize_t x; + ssize_t y; + size_t width; + size_t height; +}; /** Pixel map. */ struct pixmap { diff --git a/src/sway.h b/src/sway.h index e0571af..cf3562d 100644 --- a/src/sway.h +++ b/src/sway.h @@ -4,7 +4,7 @@ #pragma once -#include "types.h" +#include "pixmap.h" #include diff --git a/src/types.h b/src/types.h deleted file mode 100644 index 09f4c68..0000000 --- a/src/types.h +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: MIT -// Common types and constants. -// Copyright (C) 2022 Artem Senichev - -#pragma once - -#include -#include -#include -#include - -/** ARGB color. */ -typedef uint32_t argb_t; - -// shifts for each channel in argb_t -#define ARGB_A_SHIFT 24 -#define ARGB_R_SHIFT 16 -#define ARGB_G_SHIFT 8 -#define ARGB_B_SHIFT 0 - -// get channel value from argb_t -#define ARGB_GET_A(c) (((c) >> ARGB_A_SHIFT) & 0xff) -#define ARGB_GET_R(c) (((c) >> ARGB_R_SHIFT) & 0xff) -#define ARGB_GET_G(c) (((c) >> ARGB_G_SHIFT) & 0xff) -#define ARGB_GET_B(c) (((c) >> ARGB_B_SHIFT) & 0xff) - -// create argb_t from channel value -#define ARGB_SET_A(a) (((a)&0xff) << ARGB_A_SHIFT) -#define ARGB_SET_R(r) (((r)&0xff) << ARGB_R_SHIFT) -#define ARGB_SET_G(g) (((g)&0xff) << ARGB_G_SHIFT) -#define ARGB_SET_B(b) (((b)&0xff) << ARGB_B_SHIFT) - -// convert RGBA to ARGB -#define ARGB_SET_ABGR(c) \ - ((c & 0xff00ff00) | ARGB_SET_R(ARGB_GET_B(c)) | ARGB_SET_B(ARGB_GET_R(c))) - -// alpha blending (a=alpha, s=target alpha, b=background, f=foreground) -#define ARGB_ALPHA_BLEND(a, s, b, f) \ - ARGB_SET_A(s) | \ - ARGB_SET_R((a * ARGB_GET_R(f) + (256 - a) * ARGB_GET_R(b)) >> 8) | \ - ARGB_SET_G((a * ARGB_GET_G(f) + (256 - a) * ARGB_GET_G(b)) >> 8) | \ - ARGB_SET_B((a * ARGB_GET_B(f) + (256 - a) * ARGB_GET_B(b)) >> 8) - -/** 2D coordinates. */ -struct point { - ssize_t x; - ssize_t y; -}; - -/** Size description. */ -struct size { - size_t width; - size_t height; -}; - -/** Rectangle description. */ -struct rect { - ssize_t x; - ssize_t y; - size_t width; - size_t height; -}; diff --git a/src/ui.h b/src/ui.h index 15d11b4..59a51ab 100644 --- a/src/ui.h +++ b/src/ui.h @@ -4,7 +4,7 @@ #pragma once -#include "types.h" +#include "pixmap.h" // Configuration parameters #define UI_CFG_APP_ID "app_id" diff --git a/src/viewer.h b/src/viewer.h index 623b935..b96aa6f 100644 --- a/src/viewer.h +++ b/src/viewer.h @@ -5,7 +5,7 @@ #pragma once #include "keybind.h" -#include "types.h" +#include "pixmap.h" // Configuration parameters #define VIEWER_CFG_SLIDESHOW "slideshow"