Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
j2k.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2012 Moritz Lipp.
4 Copyright (C) 2012-2014, 2020-2021 Pascal Obry.
5 Copyright (C) 2012-2017, 2019-2020 Tobias Ellinghaus.
6 Copyright (C) 2013-2014 Jérémy Rosen.
7 Copyright (C) 2013 Pascal de Bruijn.
8 Copyright (C) 2013-2014, 2016 Roman Lebedev.
9 Copyright (C) 2013 Simon Spannagel.
10 Copyright (C) 2013 Thomas Pryds.
11 Copyright (C) 2013 Ulrich Pegelow.
12 Copyright (C) 2018 Heiko Bauke.
13 Copyright (C) 2019, 2025 Aurélien PIERRE.
14 Copyright (C) 2020 Diederik Ter Rahe.
15 Copyright (C) 2020-2021 Hubert Kowalski.
16 Copyright (C) 2020, 2022 Miloš Komarčević.
17 Copyright (C) 2022 Martin Bařinka.
18
19 darktable is free software: you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation, either version 3 of the License, or
22 (at your option) any later version.
23
24 darktable is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with darktable. If not, see <http://www.gnu.org/licenses/>.
31*/
32
33// Original copyright notice from image_to_j2k.c from openjpeg:
34/*
35 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain
36 *(UCL), Belgium
37 * Copyright (c) 2002-2007, Professor Benoit Macq
38 * Copyright (c) 2001-2003, David Janssens
39 * Copyright (c) 2002-2003, Yannick Verschueren
40 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
41 * Copyright (c) 2005, Herve Drolon, FreeImage Team
42 * Copyright (c) 2006-2007, Parvatha Elangovan
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
55 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
58 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
65 */
66
67#include "bauhaus/bauhaus.h"
68#include "common/darktable.h"
69#include "common/exif.h"
70#include "common/imageio.h"
72#include "control/conf.h"
74#include "gui/gtk.h"
75
76#include <stdio.h>
77#include <stdlib.h>
78
79#if defined(__has_include)
80#if __has_include(<openjpeg.h>)
81#include <openjpeg.h>
82#elif __has_include(<openjpeg-2.5/openjpeg.h>)
83#include <openjpeg-2.5/openjpeg.h>
84#elif __has_include(<openjpeg-2.1/openjpeg.h>)
85#include <openjpeg-2.1/openjpeg.h>
86#else
87#error "openjpeg.h not found"
88#endif
89#else
90#include <openjpeg.h>
91#endif
92
93typedef enum
94{
96 JP2_CFMT = 1
98
99// borrowed from blender
100#define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 255 : (int)roundf(255.0f * (_val)))
101#define DOWNSAMPLE_FLOAT_TO_12BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 4095 : (int)roundf(4095.0f * (_val)))
102#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) \
103 (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 65535 : (int)roundf(65535.0f * (_val)))
104
105DT_MODULE(2)
106
114
123
130
132{
133}
134
138
142static void error_callback(const char *msg, void *client_data)
143{
144 FILE *stream = (FILE *)client_data;
145 fprintf(stream, "[ERROR] %s", msg);
146}
150static void warning_callback(const char *msg, void *client_data)
151{
152 FILE *stream = (FILE *)client_data;
153 fprintf(stream, "[WARNING] %s", msg);
154}
158static void info_callback(const char *msg, void *client_data)
159{
160 FILE *stream = (FILE *)client_data;
161 fprintf(stream, "[INFO] %s", msg);
162}
163
164static int initialise_4K_poc(opj_poc_t *POC, int numres)
165{
166 POC[0].tile = 1;
167 POC[0].resno0 = 0;
168 POC[0].compno0 = 0;
169 POC[0].layno1 = 1;
170 POC[0].resno1 = numres - 1;
171 POC[0].compno1 = 3;
172 POC[0].prg1 = OPJ_CPRL;
173 POC[1].tile = 1;
174 POC[1].resno0 = numres - 1;
175 POC[1].compno0 = 0;
176 POC[1].layno1 = 1;
177 POC[1].resno1 = numres;
178 POC[1].compno1 = 3;
179 POC[1].prg1 = OPJ_CPRL;
180 return 2;
181}
182
183static void cinema_parameters(opj_cparameters_t *parameters)
184{
185 parameters->tile_size_on = 0;
186 parameters->cp_tdx = 1;
187 parameters->cp_tdy = 1;
188
189 /*Tile part*/
190 parameters->tp_flag = 'C';
191 parameters->tp_on = 1;
192
193 /*Tile and Image shall be at (0,0)*/
194 parameters->cp_tx0 = 0;
195 parameters->cp_ty0 = 0;
196 parameters->image_offset_x0 = 0;
197 parameters->image_offset_y0 = 0;
198
199 /*Codeblock size= 32*32*/
200 parameters->cblockw_init = 32;
201 parameters->cblockh_init = 32;
202 parameters->csty |= 0x01;
203
204 /*The progression order shall be CPRL*/
205 parameters->prog_order = OPJ_CPRL;
206
207 /* No ROI */
208 parameters->roi_compno = -1;
209
210 parameters->subsampling_dx = 1;
211 parameters->subsampling_dy = 1;
212
213 /* 9-7 transform */
214 parameters->irreversible = 1;
215}
216
217static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *image, float *rates)
218{
219 int i;
220 float temp_rate;
221
222 switch(parameters->cp_cinema)
223 {
224 case OPJ_CINEMA2K_24:
225 case OPJ_CINEMA2K_48:
226 parameters->cp_rsiz = OPJ_CINEMA2K;
227 if(parameters->numresolution > 6)
228 {
229 parameters->numresolution = 6;
230 }
231 if(!((image->comps[0].w == 2048) | (image->comps[0].h == 1080)))
232 {
233 fprintf(stdout,
234 "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
235 "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
236 image->comps[0].w, image->comps[0].h);
237 parameters->cp_rsiz = OPJ_STD_RSIZ;
238 }
239 break;
240
241 case OPJ_CINEMA4K_24:
242 parameters->cp_rsiz = OPJ_CINEMA4K;
243 if(parameters->numresolution < 1)
244 {
245 parameters->numresolution = 1;
246 }
247 else if(parameters->numresolution > 7)
248 {
249 parameters->numresolution = 7;
250 }
251 if(!((image->comps[0].w == 4096) | (image->comps[0].h == 2160)))
252 {
253 fprintf(stdout,
254 "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
255 "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
256 image->comps[0].w, image->comps[0].h);
257 parameters->cp_rsiz = OPJ_STD_RSIZ;
258 }
259 parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution);
260 break;
261 default:
262 break;
263 }
264
265 switch(parameters->cp_cinema)
266 {
267 case OPJ_CINEMA2K_24:
268 case OPJ_CINEMA4K_24:
269 for(i = 0; i < parameters->tcp_numlayers; i++)
270 {
271 if(rates[i] == 0)
272 {
273 parameters->tcp_rates[0]
274 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
275 / (OPJ_CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
276 }
277 else
278 {
279 temp_rate
280 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
281 / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
282 if(temp_rate > OPJ_CINEMA_24_CS)
283 {
284 parameters->tcp_rates[i]
285 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
286 / (OPJ_CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
287 }
288 else
289 {
290 parameters->tcp_rates[i] = rates[i];
291 }
292 }
293 }
294 parameters->max_comp_size = OPJ_CINEMA_24_COMP;
295 break;
296
297 case OPJ_CINEMA2K_48:
298 for(i = 0; i < parameters->tcp_numlayers; i++)
299 {
300 if(rates[i] == 0)
301 {
302 parameters->tcp_rates[0]
303 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
304 / (OPJ_CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
305 }
306 else
307 {
308 temp_rate
309 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
310 / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
311 if(temp_rate > OPJ_CINEMA_48_CS)
312 {
313 parameters->tcp_rates[0]
314 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
315 / (OPJ_CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
316 }
317 else
318 {
319 parameters->tcp_rates[i] = rates[i];
320 }
321 }
322 }
323 parameters->max_comp_size = OPJ_CINEMA_48_COMP;
324 break;
325 default:
326 break;
327 }
328 parameters->cp_disto_alloc = 1;
329}
330
331int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const void *in_tmp,
332 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
333 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
334 const gboolean export_masks)
335{
336 int rc = 1;
337 const float *in = (const float *)in_tmp;
338 dt_imageio_j2k_t *j2k = (dt_imageio_j2k_t *)j2k_tmp;
339 opj_cparameters_t parameters; /* compression parameters */
340 float *rates = NULL;
341 opj_image_t *image = NULL;
342 const int quality = CLAMP(j2k->quality, 1, 100);
343
344 /* set encoding parameters to default values */
345 opj_set_default_encoder_parameters(&parameters);
346
347 /* compression ratio */
348 /* invert range, from 10-100, 100-1
349 * where jpeg see's 1 and highest quality (lossless) and 100 is very low quality*/
350 parameters.tcp_rates[0] = 100 - quality + 1;
351
352 parameters.tcp_numlayers = 1; /* only one resolution */
353 parameters.cp_disto_alloc = 1;
354 parameters.cp_rsiz = OPJ_STD_RSIZ;
355
356 parameters.cod_format = j2k->format;
357 parameters.cp_cinema = (OPJ_CINEMA_MODE)j2k->preset;
358
359 if(parameters.cp_cinema)
360 {
361 rates = (float *)calloc(parameters.tcp_numlayers, sizeof(float));
362 for(int i = 0; i < parameters.tcp_numlayers; i++)
363 {
364 rates[i] = parameters.tcp_rates[i];
365 }
366 cinema_parameters(&parameters);
367 }
368
369 /* Create comment for codestream */
370 parameters.cp_comment = g_strdup_printf("Created by %s", darktable_package_string);
371
372 /*Converting the image to a format suitable for encoding*/
373 {
374 const int subsampling_dx = parameters.subsampling_dx;
375 const int subsampling_dy = parameters.subsampling_dy;
376 const int numcomps = 3;
377 const int prec = 12; // TODO: allow other bitdepths!
378 const int w = j2k->global.width, h = j2k->global.height;
379
380 opj_image_cmptparm_t cmptparm[4]; /* RGBA: max. 4 components */
381 memset(&cmptparm[0], 0, sizeof(opj_image_cmptparm_t) * numcomps);
382
383 for(int i = 0; i < numcomps; i++)
384 {
385 cmptparm[i].prec = prec;
386 cmptparm[i].sgnd = 0;
387 cmptparm[i].dx = subsampling_dx;
388 cmptparm[i].dy = subsampling_dy;
389 cmptparm[i].w = w;
390 cmptparm[i].h = h;
391 }
392 image = opj_image_create(numcomps, &cmptparm[0], OPJ_CLRSPC_SRGB);
393 if(IS_NULL_PTR(image))
394 {
395 fprintf(stderr, "Error: opj_image_create() failed\n");
396 dt_free(rates);
397 rc = 0;
398 goto exit;
399 }
400
401 /* set image offset and reference grid */
402 image->x0 = parameters.image_offset_x0;
403 image->y0 = parameters.image_offset_y0;
404 image->x1 = parameters.image_offset_x0 + (w - 1) * subsampling_dx + 1;
405 image->y1 = parameters.image_offset_y0 + (h - 1) * subsampling_dy + 1;
406
407 switch(prec)
408 {
409// case 8:
410// for(int i = 0; i < w * h; i++)
411// {
412// for(int k = 0; k < numcomps; k++) image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(in[i * 4 + k]);
413// }
414// break;
415 case 12:
416 for(int i = 0; i < w * h; i++)
417 {
418 for(int k = 0; k < numcomps; k++)
419 image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(in[i * 4 + k]);
420 }
421 break;
422// case 16:
423// for(int i = 0; i < w * h; i++)
424// {
425// for(int k = 0; k < numcomps; k++)
426// image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(in[i * 4 + k]);
427// }
428// break;
429// default:
430// fprintf(stderr, "Error: this shouldn't happen, there is no bit depth of %d for jpeg 2000 images.\n",
431// prec);
432// g_free(rates);
433// opj_image_destroy(image);
434// return 1;
435 }
436 }
437
438 /*Encoding image*/
439
440 /* Decide if MCT should be used */
441 parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;
442
443 if(parameters.cp_cinema)
444 {
445 cinema_setup_encoder(&parameters, image, rates);
446 dt_free(rates);
447 }
448
449 /* encode the destination image */
450 /* ---------------------------- */
451 OPJ_CODEC_FORMAT codec;
452 if(parameters.cod_format == J2K_CFMT) /* J2K format output */
453 codec = OPJ_CODEC_J2K;
454 else
455 codec = OPJ_CODEC_JP2;
456
457 opj_stream_t *cstream = NULL;
458
459 /* get a J2K/JP2 compressor handle */
460 opj_codec_t *ccodec = opj_create_compress(codec);
461
462 opj_set_error_handler(ccodec, error_callback, stderr);
463 opj_set_warning_handler(ccodec, warning_callback, stderr);
464 opj_set_info_handler(ccodec, info_callback, stderr);
465
466 g_strlcpy(parameters.outfile, filename, sizeof(parameters.outfile));
467
468 /* setup the encoder parameters using the current image and user parameters */
469 opj_setup_encoder(ccodec, &parameters, image);
470
471 /* open a byte stream for writing */
472 /* allocate memory for all tiles */
473 cstream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE);
474 if(IS_NULL_PTR(cstream))
475 {
476 opj_destroy_codec(ccodec);
477 opj_image_destroy(image);
478 fprintf(stderr, "failed to create output stream\n");
479 rc = 0;
480 goto exit;
481 }
482
483 if(!opj_start_compress(ccodec, image, cstream))
484 {
485 opj_stream_destroy(cstream);
486 opj_destroy_codec(ccodec);
487 opj_image_destroy(image);
488 fprintf(stderr, "failed to encode image: opj_start_compress\n");
489 rc = 0;
490 goto exit;
491 }
492
493 /* encode the image */
494 if(!opj_encode(ccodec, cstream))
495 {
496 opj_stream_destroy(cstream);
497 opj_destroy_codec(ccodec);
498 opj_image_destroy(image);
499 fprintf(stderr, "failed to encode image: opj_encode\n");
500 rc = 0;
501 goto exit;
502 }
503
504 /* encode the image */
505 if(!opj_end_compress(ccodec, cstream))
506 {
507 opj_stream_destroy(cstream);
508 opj_destroy_codec(ccodec);
509 opj_image_destroy(image);
510 fprintf(stderr, "failed to encode image: opj_end_compress\n");
511 rc = 0;
512 goto exit;
513 }
514
515 opj_stream_destroy(cstream);
516 opj_destroy_codec(ccodec);
517
518 /* add exif data blob. seems to not work for j2k files :( */
519 if(exif && j2k->format == JP2_CFMT) rc = dt_exif_write_blob(exif, exif_len, filename, 1);
520
521 /* free image data */
522 opj_image_destroy(image);
523
524exit:
525 /* free user parameters structure */
526 dt_free(parameters.cp_comment);
527 dt_free(parameters.cp_matrice);
528 dt_free(parameters.mct_data);
529
530 return ((rc == 1) ? 0 : 1);
531}
532
534{
535 return sizeof(dt_imageio_j2k_t);
536}
537
538void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params,
539 const size_t old_params_size, const int old_version, const int new_version,
540 size_t *new_size)
541{
542 if(old_version == 1 && new_version == 2)
543 {
544 typedef struct dt_imageio_j2k_v1_t
545 {
546 int max_width, max_height;
547 int width, height;
548 char style[128];
549 int bpp;
552 int quality;
553 } dt_imageio_j2k_v1_t;
554
555 dt_imageio_j2k_v1_t *o = (dt_imageio_j2k_v1_t *)old_params;
557
558 n->global.max_width = o->max_width;
559 n->global.max_height = o->max_height;
560 n->global.width = o->width;
561 n->global.height = o->height;
562 g_strlcpy(n->global.style, o->style, sizeof(o->style));
563 n->bpp = o->bpp;
564 n->format = o->format;
565 n->preset = o->preset;
566 n->quality = o->quality;
567 *new_size = self->params_size(self);
568 return n;
569 }
570 return NULL;
571}
572
574{
575 dt_imageio_j2k_t *d = (dt_imageio_j2k_t *)calloc(1, sizeof(dt_imageio_j2k_t));
576 d->bpp = 16; // can be 8, 12 or 16
577 d->format = dt_conf_get_int("plugins/imageio/format/j2k/format");
578 d->preset = dt_conf_get_int("plugins/imageio/format/j2k/preset");
579 d->quality = dt_conf_get_int("plugins/imageio/format/j2k/quality");
580 if(d->quality <= 0 || d->quality > 100) d->quality = 100;
581 return d;
582}
583
585{
586 dt_free(params);
587}
588
589int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
590{
591 if(size != self->params_size(self)) return 1;
594 dt_bauhaus_combobox_set(g->format, d->format);
595 dt_bauhaus_combobox_set(g->preset, d->preset);
596 dt_bauhaus_slider_set(g->quality, d->quality);
597 return 0;
598}
599
601{
602 return 32;
603}
604
606{
607 // TODO: adapt as soon as this module supports various bitdepths
608 return IMAGEIO_RGB | IMAGEIO_INT12;
609}
610
612{
613 return "image/jp2";
614}
615
617{
618 const dt_imageio_j2k_t *data = (dt_imageio_j2k_t *)data_tmp;
619 if(data->format == J2K_CFMT)
620 return "j2k";
621 else
622 return "jp2";
623}
624
625const char *name()
626{
627 return _("JPEG 2000 (12-bit)");
628}
629
630static void preset_changed(GtkWidget *widget, gpointer user_data)
631{
632 const int preset = dt_bauhaus_combobox_get(widget);
633 dt_conf_set_int("plugins/imageio/format/j2k/preset", preset);
634}
635
636static void format_changed(GtkWidget *widget, gpointer user_data)
637{
638 const int format = dt_bauhaus_combobox_get(widget);
639 dt_conf_set_int("plugins/imageio/format/j2k/format", format);
640}
641
642static void quality_changed(GtkWidget *slider, gpointer user_data)
643{
644 int quality = (int)dt_bauhaus_slider_get(slider);
645 dt_conf_set_int("plugins/imageio/format/j2k/quality", quality);
646}
647
648// TODO: some quality/compression stuff in case "off" is selected
650{
652 self->gui_data = (void *)gui;
653 self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_GUI_BOX_SPACING);
654
655 const int format_last = dt_conf_get_int("plugins/imageio/format/j2k/format");
656 const int preset_last = dt_conf_get_int("plugins/imageio/format/j2k/preset");
657 const int quality_last = dt_conf_get_int("plugins/imageio/format/j2k/quality");
658
660 dt_bauhaus_widget_set_label(gui->format, N_("format"));
661 dt_bauhaus_combobox_add(gui->format, _("J2K"));
662 dt_bauhaus_combobox_add(gui->format, _("jp2"));
663 dt_bauhaus_combobox_set(gui->format, format_last);
664 gtk_box_pack_start(GTK_BOX(self->widget), gui->format, TRUE, TRUE, 0);
665 g_signal_connect(G_OBJECT(gui->format), "value-changed", G_CALLBACK(format_changed), NULL);
666
668 dt_confgen_get_int("plugins/imageio/format/j2k/quality", DT_MIN),
669 dt_confgen_get_int("plugins/imageio/format/j2k/quality", DT_MAX),
670 1,
671 dt_confgen_get_int("plugins/imageio/format/j2k/quality", DT_DEFAULT),
672 0);
673 dt_bauhaus_widget_set_label(gui->quality, N_("quality"));
674 dt_bauhaus_slider_set_default(gui->quality, dt_confgen_get_int("plugins/imageio/format/j2k/quality", DT_DEFAULT));
675 if(quality_last > 0 && quality_last <= 100) dt_bauhaus_slider_set(gui->quality, quality_last);
676 gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(gui->quality), TRUE, TRUE, 0);
677 g_signal_connect(G_OBJECT(gui->quality), "value-changed", G_CALLBACK(quality_changed), NULL);
678
680 dt_bauhaus_widget_set_label(gui->preset, N_("DCP mode"));
681 dt_bauhaus_combobox_add(gui->preset, _("off"));
682 dt_bauhaus_combobox_add(gui->preset, _("Cinema2K, 24FPS"));
683 dt_bauhaus_combobox_add(gui->preset, _("Cinema2K, 48FPS"));
684 dt_bauhaus_combobox_add(gui->preset, _("Cinema4K, 24FPS"));
685 dt_bauhaus_combobox_set(gui->preset, preset_last);
686 gtk_box_pack_start(GTK_BOX(self->widget), gui->preset, TRUE, TRUE, 0);
687 g_signal_connect(G_OBJECT(gui->preset), "value-changed", G_CALLBACK(preset_changed), NULL);
688
689 // TODO: options for "off"
690}
691
693{
694 dt_free(self->gui_data);
695}
696
698{
699 const int format_def = dt_confgen_get_int("plugins/imageio/format/j2k/format", DT_DEFAULT);
700 const int preset_def = dt_confgen_get_int("plugins/imageio/format/j2k/preset", DT_DEFAULT);
701 const int quality_def = dt_confgen_get_int("plugins/imageio/format/j2k/quality", DT_DEFAULT);
703 dt_bauhaus_combobox_set(gui->format, format_def);
704 dt_bauhaus_combobox_set(gui->preset, preset_def);
705 dt_bauhaus_combobox_set(gui->quality, quality_def);
706}
707
709{
711 return ((j && j->format == JP2_CFMT) ? FORMAT_FLAGS_SUPPORT_XMP : 0);
712}
713
714// clang-format off
715// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
716// vim: shiftwidth=2 expandtab tabstop=2 cindent
717// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
718// clang-format on
#define TRUE
Definition ashift_lsd.c:162
void dt_bauhaus_slider_set_default(GtkWidget *widget, float def)
Definition bauhaus.c:1640
float dt_bauhaus_slider_get(GtkWidget *widget)
Definition bauhaus.c:3483
int dt_bauhaus_combobox_get(GtkWidget *widget)
Definition bauhaus.c:2347
void dt_bauhaus_slider_set(GtkWidget *widget, float pos)
Definition bauhaus.c:3506
void dt_bauhaus_combobox_set(GtkWidget *widget, const int pos)
Definition bauhaus.c:2301
void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *label)
Definition bauhaus.c:1653
GtkWidget * dt_bauhaus_slider_new_with_range(dt_bauhaus_t *bh, dt_gui_module_t *self, float min, float max, float step, float defval, int digits)
Definition bauhaus.c:1780
GtkWidget * dt_bauhaus_combobox_new(dt_bauhaus_t *bh, dt_gui_module_t *self)
Definition bauhaus.c:1842
void dt_bauhaus_combobox_add(GtkWidget *widget, const char *text)
Definition bauhaus.c:2016
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:81
@ DT_DEFAULT
Definition conf.h:96
@ DT_MAX
Definition conf.h:98
@ DT_MIN
Definition conf.h:97
const char darktable_package_string[]
void dt_conf_set_int(const char *name, int val)
int dt_conf_get_int(const char *name)
int dt_confgen_get_int(const char *name, dt_confgen_value_kind_t kind)
darktable_t darktable
Definition darktable.c:181
#define DT_MODULE(MODVER)
Definition darktable.h:140
#define dt_free(ptr)
Definition darktable.h:456
#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 darktable.h:281
int dt_exif_write_blob(uint8_t *blob, uint32_t size, const char *path, const int compressed)
Definition exif.cc:1816
#define DT_GUI_BOX_SPACING
Definition gtk.h:109
#define DT_GUI_MODULE(x)
int bpp
@ IMAGEIO_RGB
Definition imageio.h:70
@ IMAGEIO_INT12
Definition imageio.h:63
@ FORMAT_FLAGS_SUPPORT_XMP
struct dt_iop_tonecurve_params_t preset
const char * mime(dt_imageio_module_data_t *data)
Definition j2k.c:611
static void format_changed(GtkWidget *widget, gpointer user_data)
Definition j2k.c:636
size_t params_size(dt_imageio_module_format_t *self)
Definition j2k.c:533
const char * extension(dt_imageio_module_data_t *data_tmp)
Definition j2k.c:616
static void cinema_parameters(opj_cparameters_t *parameters)
Definition j2k.c:183
void gui_reset(dt_imageio_module_format_t *self)
Definition j2k.c:697
void gui_init(dt_imageio_module_format_t *self)
Definition j2k.c:649
dt_imageio_j2k_format_t
Definition j2k.c:94
@ J2K_CFMT
Definition j2k.c:95
@ JP2_CFMT
Definition j2k.c:96
dt_imageio_j2k_preset_t
Definition j2k.c:108
@ DT_J2K_PRESET_OFF
Definition j2k.c:109
@ DT_J2K_PRESET_CINEMA2K_24
Definition j2k.c:110
@ DT_J2K_PRESET_CINEMA4K_24
Definition j2k.c:112
@ DT_J2K_PRESET_CINEMA2K_48
Definition j2k.c:111
int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
Definition j2k.c:589
const char * name()
Definition j2k.c:625
static void warning_callback(const char *msg, void *client_data)
Definition j2k.c:150
void cleanup(dt_imageio_module_format_t *self)
Definition j2k.c:135
int levels(dt_imageio_module_data_t *p)
Definition j2k.c:605
void * legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, const int old_version, const int new_version, size_t *new_size)
Definition j2k.c:538
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
Definition j2k.c:584
static void preset_changed(GtkWidget *widget, gpointer user_data)
Definition j2k.c:630
static int initialise_4K_poc(opj_poc_t *POC, int numres)
Definition j2k.c:164
int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const void *in_tmp, dt_colorspaces_color_profile_type_t over_type, const char *over_filename, void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe, const gboolean export_masks)
Definition j2k.c:331
void init(dt_imageio_module_format_t *self)
Definition j2k.c:131
static void error_callback(const char *msg, void *client_data)
Definition j2k.c:142
void * get_params(dt_imageio_module_format_t *self)
Definition j2k.c:573
#define DOWNSAMPLE_FLOAT_TO_12BIT(_val)
Definition j2k.c:101
void gui_cleanup(dt_imageio_module_format_t *self)
Definition j2k.c:692
static void quality_changed(GtkWidget *slider, gpointer user_data)
Definition j2k.c:642
static void info_callback(const char *msg, void *client_data)
Definition j2k.c:158
static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *image, float *rates)
Definition j2k.c:217
float *const restrict const size_t k
size_t size
Definition mipmap_cache.c:3
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
struct _GtkWidget GtkWidget
Definition splash.h:29
struct dt_bauhaus_t * bauhaus
Definition darktable.h:778
GtkWidget * quality
Definition j2k.c:128
GtkWidget * preset
Definition j2k.c:127
GtkWidget * format
Definition j2k.c:126
dt_imageio_j2k_preset_t preset
Definition j2k.c:120
dt_imageio_j2k_format_t format
Definition j2k.c:119
dt_imageio_module_data_t global
Definition j2k.c:117
GModule *GtkWidget * widget