Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
surface_scaling.h
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Aurélien PIERRE.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef DT_SYSTEM_SURFACE_SCALING_H
20#define DT_SYSTEM_SURFACE_SCALING_H
21
22/* Device-scale-aware cairo surfaces: allocate at `scale` resolution and tell cairo about it,
23 * so callers keep drawing in logical coordinates and get a sharp result on a HiDPI screen.
24 *
25 * The scale is an argument, not a global. That is what keeps this file -- and therefore
26 * src/system -- stateless: the arithmetic is the same whoever asks and whatever the display
27 * is doing. Where the current screen's scale comes from is gui/screen_metrics.h, which
28 * owns that value and offers the same three constructors already bound to it.
29 */
30
31#include <cairo.h>
32#include <glib.h>
33
35
37 double scale)
38{
39 cairo_surface_t *cst = cairo_image_surface_create(format, width * scale, height * scale);
40 cairo_surface_set_device_scale(cst, scale, scale);
41 return cst;
42}
43
45 cairo_format_t format, int width,
46 int height, int stride, double scale)
47{
49 cairo_surface_set_device_scale(cst, scale, scale);
50 return cst;
51}
52
53static inline cairo_surface_t *dt_cairo_surface_create_from_png_at_scale(const char *filename, double scale)
54{
56 cairo_surface_set_device_scale(cst, scale, scale);
57 return cst;
58}
59
60/* The size a device-scaled surface occupies in logical coordinates -- what the caller asked
61 * for, not the scale-multiplied pixel count cairo actually allocated. */
62
63static inline int dt_cairo_surface_logical_width(cairo_surface_t *surface, double scale)
64{
65 return cairo_image_surface_get_width(surface) / scale;
66}
67
68static inline int dt_cairo_surface_logical_height(cairo_surface_t *surface, double scale)
69{
70 return cairo_image_surface_get_height(surface) / scale;
71}
72
74
75#endif // DT_SYSTEM_SURFACE_SCALING_H
76
77// clang-format off
78// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
79// vim: shiftwidth=2 expandtab tabstop=2 cindent
80// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
81// clang-format on
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
static cairo_surface_t * dt_cairo_surface_create_from_png_at_scale(const char *filename, double scale)
static int dt_cairo_surface_logical_width(cairo_surface_t *surface, double scale)
static int dt_cairo_surface_logical_height(cairo_surface_t *surface, double scale)
static cairo_surface_t * dt_cairo_surface_create_for_data_at_scale(unsigned char *data, cairo_format_t format, int width, int height, int stride, double scale)
static G_BEGIN_DECLS cairo_surface_t * dt_cairo_surface_create_at_scale(cairo_format_t format, int width, int height, double scale)