Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dev_geometry.c
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
20#include "develop/develop.h"
21
22#include <string.h>
23
24/* The seqlock, both halves in one place.
25 *
26 * Writers are serialised by convention, not by a lock: the raw pair is published by the one
27 * function that loads the image, the processed pair by the one function that runs the virtual
28 * pipe, and both run on whichever thread owns that dev. Two concurrent writers would break
29 * this, so if a second publisher ever appears it needs a real lock, not a second odd counter.
30 */
31
33{
34 dt_atomic_set_uint64(&store->generation, dt_atomic_get_uint64(&store->generation) + 1);
35}
36
38{
39 dt_atomic_set_uint64(&store->generation, dt_atomic_get_uint64(&store->generation) + 1);
40}
41
43{
44 if(IS_NULL_PTR(dev)) return;
45
46 memset(&dev->geometry.value, 0, sizeof(dev->geometry.value));
48}
49
50void dt_dev_geometry_set_raw_size(dt_develop_t *dev, const int32_t width, const int32_t height,
51 const gboolean valid)
52{
53 if(IS_NULL_PTR(dev)) return;
54
58 dev->geometry.value.raw_inited = valid;
60}
61
62void dt_dev_geometry_set_processed_size(dt_develop_t *dev, const int32_t width, const int32_t height)
63{
64 if(IS_NULL_PTR(dev)) return;
65
71}
72
74{
75 if(IS_NULL_PTR(out)) return FALSE;
76
77 memset(out, 0, sizeof(*out));
78 if(IS_NULL_PTR(dev)) return FALSE;
79
81
82 // Retry until we read a settled generation twice with no write in between. A publication is
83 // three stores between two counter bumps, so this converges immediately unless a writer is
84 // running right now; there is no waiting and no lock to order against anything.
85 for(;;)
86 {
87 const uint64_t before = dt_atomic_get_uint64(&store->generation);
88 if(before & 1) continue; // publication in flight
89
90 *out = store->value;
91
92 const uint64_t after = dt_atomic_get_uint64(&store->generation);
93 if(before == after) break;
94 }
95
96 return out->raw_inited || out->processed_inited;
97}
98
100{
102 dt_dev_geometry_get(dev, &geometry);
103 return geometry;
104}
105
106gboolean dt_dev_geometry_get_raw_size(const dt_develop_t *dev, int32_t *width, int32_t *height)
107{
109
110 if(!IS_NULL_PTR(width)) *width = geometry.raw_width;
111 if(!IS_NULL_PTR(height)) *height = geometry.raw_height;
112
113 return geometry.raw_inited;
114}
115
116gboolean dt_dev_geometry_get_processed_size(const dt_develop_t *dev, int32_t *width, int32_t *height)
117{
119
120 if(!IS_NULL_PTR(width)) *width = geometry.processed_width;
121 if(!IS_NULL_PTR(height)) *height = geometry.processed_height;
122
123 return geometry.processed_inited;
124}
125
127{
129}
130
132{
134}
135
140
145
147{
149}
150
151// clang-format off
152// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
153// vim: shiftwidth=2 expandtab tabstop=2 cindent
154// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
155// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
uint64_t dt_atomic_get_uint64(const dt_atomic_uint64 *var)
void dt_atomic_set_uint64(dt_atomic_uint64 *var, uint64_t value)
const dt_colormatrix_t dt_aligned_pixel_t out
gboolean dt_dev_geometry_get_processed_size(const dt_develop_t *dev, int32_t *width, int32_t *height)
int32_t dt_dev_geometry_processed_height(const dt_develop_t *dev)
int32_t dt_dev_geometry_raw_width(const dt_develop_t *dev)
int32_t dt_dev_geometry_raw_height(const dt_develop_t *dev)
gboolean dt_dev_geometry_raw_inited(const dt_develop_t *dev)
static void _publish_end(dt_dev_geometry_store_t *store)
gboolean dt_dev_geometry_get_raw_size(const dt_develop_t *dev, int32_t *width, int32_t *height)
static void _publish_begin(dt_dev_geometry_store_t *store)
void dt_dev_geometry_set_processed_size(dt_develop_t *dev, const int32_t width, const int32_t height)
gboolean dt_dev_geometry_get(const dt_develop_t *dev, dt_dev_image_geometry_t *out)
void dt_dev_geometry_init(dt_develop_t *dev)
dt_dev_image_geometry_t dt_dev_geometry_snapshot(const dt_develop_t *dev)
int32_t dt_dev_geometry_processed_width(const dt_develop_t *dev)
void dt_dev_geometry_set_raw_size(dt_develop_t *dev, const int32_t width, const int32_t height, const gboolean valid)
int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, const int32_t imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata, const int num, const int total, const gboolean high_quality, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent, dt_export_metadata_t *metadata)
Definition disk.c:250
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:65
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
unsigned __int64 uint64_t
Definition strptime.c:75
Single-writer seqlock around the record.
dt_dev_image_geometry_t value
dt_atomic_uint64 generation
Objective facts about the image a dev is working on.
dt_dev_geometry_store_t geometry
Objective geometry of the image being worked on: the raw dimensions and the full-resolution processed...
Definition develop.h:191