Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
finalscale.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2015 johannes hanika.
4 Copyright (C) 2015-2016 Roman Lebedev.
5 Copyright (C) 2015 Ulrich Pegelow.
6 Copyright (C) 2016, 2019 Tobias Ellinghaus.
7 Copyright (C) 2017 Heiko Bauke.
8 Copyright (C) 2018, 2020-2021, 2023-2026 Aurélien PIERRE.
9 Copyright (C) 2018 Edgardo Hoszowski.
10 Copyright (C) 2020 Aldric Renaudin.
11 Copyright (C) 2020-2021 Pascal Obry.
12 Copyright (C) 2021 Hanno Schwalm.
13 Copyright (C) 2022 Martin Bařinka.
14 Copyright (C) 2022 Philipp Lutz.
15
16 darktable is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 darktable is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with darktable. If not, see <http://www.gnu.org/licenses/>.
28*/
29#ifdef HAVE_CONFIG_H
30#include "common/darktable.h"
31#include "config.h"
32#endif
33#include "bauhaus/bauhaus.h"
35#include "common/opencl.h"
36#include "develop/imageop.h"
38#include "develop/tiling.h"
39#include "iop/iop_api.h"
40#include "gui/gtk.h"
41
43
48
50
51const char *name()
52{
53 return C_("modulename", "Final resampling");
54}
55
60
62{
64}
65
70
71
72// see ../../doc/resizing-scaling.md for details
74 const dt_iop_roi_t *const roi_out,
75 dt_iop_roi_t *roi_in)
76{
77 *roi_in = *roi_out;
78 int scaling_pref = dt_conf_get_int("darkroom/render_size");
79
80 // Use cases :
81 // 1. we run an export pipeline. We mandatorily get a 1:1 image, process it whole, downscale at the end.
82 // 2. we run a GUI (darkroom) pipeline. If we upsample it, we want it done at the end of the pipe,
83 // so sharpening and blurring is at most 1:1.
84 if(roi_in->scale > 1.f)
85 {
86 roi_in->x = (int)roundf((float)roi_in->x / roi_out->scale);
87 roi_in->y = (int)roundf((float)roi_in->y / roi_out->scale);
88 roi_in->width = (int)roundf(roi_out->width / roi_out->scale);
89 roi_in->height = (int)roundf(roi_out->height / roi_out->scale);
90 roi_in->scale = 1.0f;
91 }
92 // 3. we run the pipeline in full-res mode : force scale = 1 no matter what.
93 else if(scaling_pref == 0)
94 {
95 // x, y are in original-image coordinates — leave them unchanged.
96 roi_in->width = (int)roundf(roi_out->width / roi_out->scale);
97 roi_in->height = (int)roundf(roi_out->height / roi_out->scale);
98 roi_in->scale = 1.0f;
99 const float resample_scale = roi_out->scale / roi_in->scale;
100 roi_in->x = (int)roundf(roi_in->x / resample_scale);
101 roi_in->y = (int)roundf(roi_in->y / resample_scale);
102 }
103 // else if(scaling_pref == 1) : we run the pipeline scaled at display resolution
104 // nothing to resample and anyway commit_params() will self-disable
105}
106
107void distort_mask(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece,
108 const float *const in, float *const out, const dt_iop_roi_t *const roi_in,
109 const dt_iop_roi_t *const roi_out)
110{
112 dt_interpolation_resample_roi_1c(itor, out, roi_out, in, roi_in);
113}
114
116 const void *const ivoid, void *const ovoid)
117{
118 dt_iop_roi_t roi_in = piece->roi_in;
119 dt_iop_roi_t roi_out = piece->roi_out;
120 // ROI (x,y) are not used here since we don't crop but only scale.
121 // Leaving them will offset the result, which is not what we want.
122 roi_in.x = 0;
123 roi_in.y = 0;
124 roi_out.x = 0;
125 roi_out.y = 0;
126 dt_iop_clip_and_zoom_roi(ovoid, ivoid, &roi_out, &roi_in, roi_out.width, roi_in.width);
127 return 0;
128}
129
130#ifdef HAVE_OPENCL
131int process_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
132{
133 dt_iop_roi_t roi_in = piece->roi_in;
134 dt_iop_roi_t roi_out = piece->roi_out;
135 // ROI (x,y) are not used here since we don't crop but only scale.
136 // Leaving them will offset the result, which is not what we want.
137 roi_in.x = 0;
138 roi_in.y = 0;
139 roi_out.x = 0;
140 roi_out.y = 0;
141 const int devid = pipe->devid;
142 cl_int err = -999;
143
144 err = dt_iop_clip_and_zoom_roi_cl(devid, dev_out, dev_in, &roi_out, &roi_in);
145 if(err != CL_SUCCESS) goto error;
146
147 return TRUE;
148
149error:
150 dt_print(DT_DEBUG_OPENCL, "[opencl_finalscale] couldn't enqueue kernel! %d\n", err);
151 return FALSE;
152}
153#endif
154
155
158{
159 // Depending on ROI zoom level, we may need to enable finalscale so the pipeline runs
160 // at most at 100%, for pixel-level accuracy, and we upscale at the end.
161 // This is important for consistency with exports.
162 const float darkroom_zoom = pipe->dev->roi.scaling * pipe->dev->roi.natural_scale;
163 piece->enabled = (darkroom_zoom > 1.f && pipe->type != DT_DEV_PIXELPIPE_THUMBNAIL)
164 || (pipe->type == DT_DEV_PIXELPIPE_EXPORT)
165 || (dt_conf_get_int("darkroom/render_size") != 1 && darkroom_zoom != 1.f && pipe->type != DT_DEV_PIXELPIPE_THUMBNAIL);
166}
167
169{
171 piece->data_size = sizeof(dt_iop_finalscale_data_t);
172 piece->enabled = (pipe->type == DT_DEV_PIXELPIPE_EXPORT);
173}
174
176{
177 dt_free_align(piece->data);
178 piece->data = NULL;
179}
180
182{
183 self->params = calloc(1, sizeof(dt_iop_finalscale_params_t));
184 self->default_params = calloc(1, sizeof(dt_iop_finalscale_params_t));
185 self->default_enabled = 1;
186 self->hide_enable_button = 1;
188 self->gui_data = NULL;
189}
190
192{
193 dt_free(self->params);
194 dt_free(self->default_params);
195}
196
199
201
203{
204 IOP_GUI_ALLOC(finalscale);
205 self->widget = gtk_label_new(NULL);
206 gtk_label_set_markup(GTK_LABEL(self->widget),_("This module is used to downscale images at export time. "
207 "Moving it along the pipeline will have diffent effects on exported images. "
208 "<a href='https://ansel.photos/en/doc/modules/processing-modules/finalscale/'>Learn more</a>"));
209 gtk_widget_set_halign(self->widget, GTK_ALIGN_START);
210 gtk_label_set_xalign (GTK_LABEL(self->widget), 0.0f);
211 gtk_label_set_line_wrap(GTK_LABEL(self->widget), TRUE);
212}
213
214// clang-format off
215// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
216// vim: shiftwidth=2 expandtab tabstop=2 cindent
217// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
218// clang-format on
static void error(char *msg)
Definition ashift_lsd.c:202
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
@ IOP_CS_RGB
const dt_colormatrix_t dt_aligned_pixel_t out
int dt_conf_get_int(const char *name)
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1542
#define dt_free_align(ptr)
Definition darktable.h:481
static void * dt_calloc_align(size_t size)
Definition darktable.h:488
@ DT_DEBUG_OPENCL
Definition darktable.h:722
#define dt_free(ptr)
Definition darktable.h:456
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
Definition darktable.h:151
void dt_iop_params_t
Definition dev_history.h:41
void distort_mask(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece, const float *const in, float *const out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
Definition finalscale.c:107
int process(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid)
Definition finalscale.c:115
int default_group()
Definition finalscale.c:61
dt_iop_finalscale_gui_data_t dummy
Definition finalscale.c:200
void modify_roi_in(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *const roi_out, dt_iop_roi_t *roi_in)
Definition finalscale.c:73
dt_iop_finalscale_params_t dt_iop_finalscale_data_t
Definition finalscale.c:49
const char * name()
Definition finalscale.c:51
void gui_init(dt_iop_module_t *self)
Definition finalscale.c:202
void cleanup_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition finalscale.c:175
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition finalscale.c:66
int flags()
Definition finalscale.c:56
void init(dt_iop_module_t *self)
Definition finalscale.c:181
void commit_params(dt_iop_module_t *self, dt_iop_params_t *params, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition finalscale.c:156
void init_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition finalscale.c:168
int process_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
Definition finalscale.c:131
void cleanup(dt_iop_module_t *self)
Definition finalscale.c:191
@ IOP_FLAGS_ALLOW_TILING
Definition imageop.h:169
@ IOP_FLAGS_ONE_INSTANCE
Definition imageop.h:172
@ IOP_FLAGS_TILING_FULL_ROI
Definition imageop.h:171
@ IOP_FLAGS_NO_HISTORY_STACK
Definition imageop.h:174
@ IOP_GROUP_TECHNICAL
Definition imageop.h:143
#define IOP_GUI_ALLOC(module)
Definition imageop.h:599
void dt_iop_clip_and_zoom_roi(float *out, const float *const in, const dt_iop_roi_t *const roi_out, const dt_iop_roi_t *const roi_in, const int32_t out_stride, const int32_t in_stride)
int dt_iop_clip_and_zoom_roi_cl(int devid, cl_mem dev_out, cl_mem dev_in, const dt_iop_roi_t *const roi_out, const dt_iop_roi_t *const roi_in)
void *const ovoid
const struct dt_interpolation * dt_interpolation_new(enum dt_interpolation_type type)
void dt_interpolation_resample_roi_1c(const struct dt_interpolation *itor, float *out, const dt_iop_roi_t *const roi_out, const float *const in, const dt_iop_roi_t *const roi_in)
@ DT_INTERPOLATION_USERPREF_WARP
@ DT_DEV_PIXELPIPE_THUMBNAIL
Definition pixelpipe.h:41
@ DT_DEV_PIXELPIPE_EXPORT
Definition pixelpipe.h:38
struct dt_iop_module_t *void * data
dt_dev_pixelpipe_type_t type
struct dt_develop_t * dev
float scaling
Definition develop.h:193
struct dt_develop_t::@17 roi
float natural_scale
Definition develop.h:224
int32_t hide_enable_button
Definition imageop.h:262
dt_iop_params_t * default_params
Definition imageop.h:307
GtkWidget * widget
Definition imageop.h:337
dt_iop_gui_data_t * gui_data
Definition imageop.h:311
gboolean default_enabled
Definition imageop.h:303
int32_t params_size
Definition imageop.h:309
dt_iop_params_t * params
Definition imageop.h:307
Region of interest passed through the pixelpipe.
Definition imageop.h:72
double scale
Definition imageop.h:74