Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
masks_touched.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_DEVELOP_MASKS_MASKS_TOUCHED_H
20#define DT_DEVELOP_MASKS_MASKS_TOUCHED_H
21
22#include <string.h>
23
24#include "pixel/format.h"
25
39static inline void dt_masks_touched_none(dt_iop_roi_t *touched)
40{
41 if(touched == NULL) return;
42 touched->x = 0;
43 touched->y = 0;
44 touched->width = 0;
45 touched->height = 0;
46 touched->scale = 1.0f;
47}
48
49static inline void dt_masks_touched_full(dt_iop_roi_t *touched, const int width, const int height)
50{
51 if(touched == NULL) return;
52 touched->x = 0;
53 touched->y = 0;
54 touched->width = width;
55 touched->height = height;
56 touched->scale = 1.0f;
57}
58
61static inline void dt_masks_touched_set(dt_iop_roi_t *touched, int x0, int y0, int x1, int y1,
62 const int width, const int height)
63{
64 if(touched == NULL) return;
65 if(x0 < 0) x0 = 0;
66 if(y0 < 0) y0 = 0;
67 if(x1 > width - 1) x1 = width - 1;
68 if(y1 > height - 1) y1 = height - 1;
69 if(x1 < x0 || y1 < y0)
70 {
71 dt_masks_touched_none(touched);
72 return;
73 }
74 touched->x = x0;
75 touched->y = y0;
76 touched->width = x1 - x0 + 1;
77 touched->height = y1 - y0 + 1;
78 touched->scale = 1.0f;
79}
80
81static inline int dt_masks_touched_is_empty(const dt_iop_roi_t *touched)
82{
83 return touched == NULL || touched->width <= 0 || touched->height <= 0;
84}
85
87static inline void dt_masks_touched_union(dt_iop_roi_t *into, const dt_iop_roi_t *other)
88{
89 if(into == NULL || dt_masks_touched_is_empty(other)) return;
91 {
92 *into = *other;
93 return;
94 }
95 const int x0 = into->x < other->x ? into->x : other->x;
96 const int y0 = into->y < other->y ? into->y : other->y;
97 const int ix1 = into->x + into->width - 1;
98 const int ox1 = other->x + other->width - 1;
99 const int iy1 = into->y + into->height - 1;
100 const int oy1 = other->y + other->height - 1;
101 const int x1 = ix1 > ox1 ? ix1 : ox1;
102 const int y1 = iy1 > oy1 ? iy1 : oy1;
103 into->x = x0;
104 into->y = y0;
105 into->width = x1 - x0 + 1;
106 into->height = y1 - y0 + 1;
107}
108
110static inline void dt_masks_touched_clear(float *const buffer, const int width, const dt_iop_roi_t *touched)
111{
112 if(buffer == NULL || dt_masks_touched_is_empty(touched)) return;
113 for(int y = touched->y; y < touched->y + touched->height; y++)
114 memset(buffer + (size_t)y * width + touched->x, 0, sizeof(float) * (size_t)touched->width);
115}
116
117#endif // DT_DEVELOP_MASKS_MASKS_TOUCHED_H
static int dt_masks_touched_is_empty(const dt_iop_roi_t *touched)
static void dt_masks_touched_set(dt_iop_roi_t *touched, int x0, int y0, int x1, int y1, const int width, const int height)
static void dt_masks_touched_full(dt_iop_roi_t *touched, const int width, const int height)
static void dt_masks_touched_clear(float *const buffer, const int width, const dt_iop_roi_t *touched)
static void dt_masks_touched_none(dt_iop_roi_t *touched)
static void dt_masks_touched_union(dt_iop_roi_t *into, const dt_iop_roi_t *other)
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
Region of interest passed through the pixelpipe.
Definition format.h:49
double scale
Definition format.h:51
int width
Definition format.h:50
int height
Definition format.h:50