GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_dpi.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2023 Cyril Hrubis <metan@ucw.cz>
4 */
5
11#ifndef BACKENDS_GP_DPI_H
12#define BACKENDS_GP_DPI_H
13
14#include <core/gp_debug.h>
15
25static inline unsigned int gp_dpi_from_size(unsigned int w, unsigned int w_mm,
26 unsigned int h, unsigned int h_mm)
27{
28 unsigned int dpi = ((w * 25.4) / w_mm + (h * 25.4) / h_mm + 1)/2;
29
30 GP_DEBUG(1, "Resolution %ux%u - %ummx%umm - dpi %u", w, h, w_mm, h_mm, dpi);
31
32 return dpi;
33}
34
41static inline float gp_dpi_to_ppmm(unsigned int dpi)
42{
43 return dpi / 25.4;
44}
45
53static inline gp_size gp_dpi_mm_to_px(unsigned int dpi, float mm)
54{
55 return gp_dpi_to_ppmm(dpi) * mm + 0.5;
56}
57
58#endif /* BACKENDS_GP_DPI_H */
unsigned int gp_size
Integer type for sizes i.e. w, h, ...
Definition gp_types.h:24
A debug message layer.
#define GP_DEBUG(level,...)
A debug printf-like macro.
Definition gp_debug.h:88
static gp_size gp_dpi_mm_to_px(unsigned int dpi, float mm)
Converts milimeters to pixels.
Definition gp_dpi.h:53
static unsigned int gp_dpi_from_size(unsigned int w, unsigned int w_mm, unsigned int h, unsigned int h_mm)
Calculates DPI from display physical size and resolution.
Definition gp_dpi.h:25
static float gp_dpi_to_ppmm(unsigned int dpi)
Converts DPI to dots/pixels per mm.
Definition gp_dpi.h:41