Project

General

Profile

darktable-tiff-add-compression-level.patch

Simon Raffeiner, 02/15/2018 11:59 AM

View differences:

data/darktableconfig.xml.in
1315 1315
    <shortdescription/>
1316 1316
    <longdescription/>
1317 1317
  </dtconfig>
1318
  <dtconfig>
1319
    <name>plugins/imageio/format/tiff/compresslevel</name>
1320
    <type>int</type>
1321
    <default>5</default>
1322
    <shortdescription/>
1323
    <longdescription/>
1324
  </dtconfig>
1318 1325
  <dtconfig>
1319 1326
    <name>plugins/imageio/format/png/bpp</name>
1320 1327
    <type>int</type>
src/imageio/format/tiff.c
31 31
#include <stdlib.h>
32 32
#include <tiffio.h>
33 33

  
34
DT_MODULE(2)
34
DT_MODULE(3)
35 35

  
36 36
typedef struct dt_imageio_tiff_t
37 37
{
......
41 41
  gboolean style_append;
42 42
  int bpp;
43 43
  int compress;
44
  int compresslevel;
44 45
  TIFF *handle;
45 46
} dt_imageio_tiff_t;
46 47

  
......
48 49
{
49 50
  GtkWidget *bpp;
50 51
  GtkWidget *compress;
52
  GtkWidget *compresslevel;
51 53
} dt_imageio_tiff_gui_t;
52 54

  
53 55

  
......
106 108
  if(d->compress == 1)
107 109
  {
108 110
    TIFFSetField(tif, TIFFTAG_COMPRESSION, (uint16_t)COMPRESSION_ADOBE_DEFLATE);
109
    TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)1);
110
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)9);
111
    TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)PREDICTOR_NONE);
112
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)d->compresslevel);
111 113
  }
112 114
  else if(d->compress == 2)
113 115
  {
114 116
    TIFFSetField(tif, TIFFTAG_COMPRESSION, (uint16_t)COMPRESSION_ADOBE_DEFLATE);
115
    TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)2);
116
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)9);
117
    TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)PREDICTOR_HORIZONTAL);
118
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)d->compresslevel);
117 119
  }
118 120
  else if(d->compress == 3)
119 121
  {
120 122
    TIFFSetField(tif, TIFFTAG_COMPRESSION, (uint16_t)COMPRESSION_ADOBE_DEFLATE);
121 123
    if(d->bpp == 32)
122
      TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)3);
124
      TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)PREDICTOR_FLOATINGPOINT);
123 125
    else
124
      TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)2);
125
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)9);
126
      TIFFSetField(tif, TIFFTAG_PREDICTOR, (uint16_t)PREDICTOR_HORIZONTAL);
127
    TIFFSetField(tif, TIFFTAG_ZIPQUALITY, (uint16_t)d->compresslevel);
126 128
  }
127 129
  else // (d->compress == 0)
128 130
  {
......
269 271
                    const size_t old_params_size, const int old_version, const int new_version,
270 272
                    size_t *new_size)
271 273
{
272
  if(old_version == 1 && new_version == 2)
274
  if(old_version == 1 && new_version == 3)
273 275
  {
274 276
    typedef struct dt_imageio_tiff_v1_t
275 277
    {
......
292 294
    n->style_append = 0;
293 295
    n->bpp = o->bpp;
294 296
    n->compress = o->compress;
297
    n->compresslevel = 9;
298
    n->handle = o->handle;
299
    *new_size = self->params_size(self);
300
    return n;
301
  }
302
  else if(old_version == 2 && new_version == 3)
303
  {
304
    typedef struct dt_imageio_tiff_v2_t
305
    {
306
      int max_width, max_height;
307
      int width, height;
308
      char style[128];
309
      gboolean style_append;
310
      int bpp;
311
      int compress;
312
      TIFF *handle;
313
    } dt_imageio_tiff_v2_t;
314

  
315
    const dt_imageio_tiff_v2_t *o = (dt_imageio_tiff_v2_t *)old_params;
316
    dt_imageio_tiff_t *n = (dt_imageio_tiff_t *)malloc(sizeof(dt_imageio_tiff_t));
317

  
318
    n->max_width = o->max_width;
319
    n->max_height = o->max_height;
320
    n->width = o->width;
321
    n->height = o->height;
322
    g_strlcpy(n->style, o->style, sizeof(o->style));
323
    n->style_append = o->style_append;
324
    n->bpp = o->bpp;
325
    n->compress = o->compress;
326
    n->compresslevel = 9;
295 327
    n->handle = o->handle;
296 328
    *new_size = self->params_size(self);
297 329
    return n;
......
310 342
  else
311 343
    d->bpp = 8;
312 344
  d->compress = dt_conf_get_int("plugins/imageio/format/tiff/compress");
345

  
346
  // TIFF compression level might actually be zero, handle this
347
  if(!dt_conf_key_exists("plugins/imageio/format/tiff/compresslevel"))
348
    d->compresslevel = 5;
349
  else
350
  {
351
    d->compresslevel = dt_conf_get_int("plugins/imageio/format/tiff/compresslevel");
352
    if(d->compresslevel < 0 || d->compresslevel > 9) d->compresslevel = 5;
353
  }
354

  
313 355
  return d;
314 356
}
315 357

  
......
333 375

  
334 376
  dt_bauhaus_combobox_set(g->compress, d->compress);
335 377

  
378
  dt_bauhaus_slider_set(g->compresslevel, d->compresslevel);
379
  dt_conf_set_int("plugins/imageio/format/tiff/compresslevel", d->compresslevel);
380

  
336 381
  return 0;
337 382
}
338 383

  
......
388 433
  dt_conf_set_int("plugins/imageio/format/tiff/compress", compress);
389 434
}
390 435

  
436
static void compress_level_changed(GtkWidget *slider, gpointer user_data)
437
{
438
    const int compresslevel = (int)dt_bauhaus_slider_get(slider);
439
    dt_conf_set_int("plugins/imageio/format/tiff/compresslevel", compresslevel);
440
}
441

  
391 442
void init(dt_imageio_module_format_t *self)
392 443
{
393 444
#ifdef USE_LUA
......
398 449
{
399 450
}
400 451

  
401
// TODO: some quality/compression stuff?
402 452
void gui_init(dt_imageio_module_format_t *self)
403 453
{
404 454
  dt_imageio_tiff_gui_t *gui = (dt_imageio_tiff_gui_t *)malloc(sizeof(dt_imageio_tiff_gui_t));
......
408 458

  
409 459
  const int compress = dt_conf_get_int("plugins/imageio/format/tiff/compress");
410 460

  
461
  // TIFF compression level might actually be zero!
462
  int compresslevel = 5;
463
  if(dt_conf_key_exists("plugins/imageio/format/tiff/compresslevel"))
464
    compresslevel = dt_conf_get_int("plugins/imageio/format/tiff/compresslevel");
465

  
411 466
  self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_PIXEL_APPLY_DPI(5));
412 467

  
468
  // Bit depth combo box
413 469
  gui->bpp = dt_bauhaus_combobox_new(NULL);
414 470
  dt_bauhaus_widget_set_label(gui->bpp, NULL, _("bit depth"));
415 471
  dt_bauhaus_combobox_add(gui->bpp, _("8 bit"));
......
424 480
  gtk_box_pack_start(GTK_BOX(self->widget), gui->bpp, TRUE, TRUE, 0);
425 481
  g_signal_connect(G_OBJECT(gui->bpp), "value-changed", G_CALLBACK(bpp_combobox_changed), NULL);
426 482

  
483
  // Compression method combo box
427 484
  gui->compress = dt_bauhaus_combobox_new(NULL);
428 485
  dt_bauhaus_widget_set_label(gui->compress, NULL, _("compression"));
429 486
  dt_bauhaus_combobox_add(gui->compress, _("uncompressed"));
......
433 490
  dt_bauhaus_combobox_set(gui->compress, compress);
434 491
  gtk_box_pack_start(GTK_BOX(self->widget), gui->compress, TRUE, TRUE, 0);
435 492
  g_signal_connect(G_OBJECT(gui->compress), "value-changed", G_CALLBACK(compress_combobox_changed), NULL);
493

  
494
  // Compression level slider
495
  gui->compresslevel = dt_bauhaus_slider_new_with_range(NULL, 0, 9, 1, 5, 0);
496
  dt_bauhaus_widget_set_label(gui->compresslevel, NULL, _("compression level"));
497
  dt_bauhaus_slider_set(gui->compresslevel, compresslevel);
498
  gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(gui->compresslevel), TRUE, TRUE, 0);
499
  g_signal_connect(G_OBJECT(gui->compresslevel), "value-changed", G_CALLBACK(compress_level_changed), NULL);
436 500
}
437 501

  
438 502
void gui_cleanup(dt_imageio_module_format_t *self)
Go to top