Back to Darktable

Darktable IOP Developer's Guide - Overview

dev-doc/README.md

0.48.4 KB
Original Source

Darktable IOP Developer's Guide - Overview

This guide covers building Image Operation (IOP) modules for darktable's darkroom.

Documentation Files

Module API

FileDescription
IOP_Module_API.mdModule API reference: params_t vs data_t, processing, commit_params, lifecycle
pixelpipe_architecture.mdPixelpipe data flow, caching, ROI, ordering asymmetry
introspection.mdIntrospection system for parameters and GUI
Shortcuts.mdThe Action/Shortcut system and dt_action_def_t
Module_Groups.mdModule grouping explanation and default_group()
maths.mdCore Math, transposed matrices, and color science helpers

GUI Development

FileDescription
GUI.mdGUI architecture: UI construction, events/callbacks, thread safety, reparenting
imageop_gui.mdWidget creation functions (dt_bauhaus_*_from_params, buttons, sections)
sliders.mdSlider configuration (ranges, formatting, color stops, recipes)
Notebook_UI.mdCreating tabbed interfaces with GtkNotebook
Quick_Access_Panel.mdQuick Access Panel integration for widgets
GUI_Recipes.mdCopy-paste patterns for notebooks, sections, buttons, visibility

AI Subsystem

FileDescription
AI.mdAI subsystem architecture, backend API, and how to add new AI features
AI_Tasks.mdReference for each AI task: mask, denoise, upscale

Guides

FileDescription
New_Module_Guide.mdStep-by-step guide to creating a new IOP module

Quick Reference

Essential Headers

c
// GUI / widget creation
#include "develop/imageop.h"          // IOP infrastructure, copy_pixel_nontemporal
#include "develop/imageop_gui.h"      // Widget creation helpers (_from_params)
#include "bauhaus/bauhaus.h"          // Slider/combobox configuration
#include "gui/gtk.h"                  // Notebooks, sections, collapsibles
#include "dtgtk/paint.h"             // Icon paint functions for buttons
#include "gui/color_picker_proxy.h"   // Color picker attachment

// Processing
#include "common/darktable.h"         // DT_OMP_FOR, copy_pixel, dt_alloc_align
#include "common/imagebuf.h"          // dt_iop_alloc_image_buffers, dt_iop_copy_image_roi
#include "develop/tiling.h"           // dt_develop_tiling_t (for tiling_callback)

Processing Cheat Sheet

c
// Validate input channels (copies input→output and sets trouble message on mismatch)
if(!dt_iop_have_required_input_format(4, self, piece->colors, ivoid, ovoid, roi_in, roi_out))
  return;

// Parallel pixel loop with safe defaults
DT_OMP_FOR()
for(int j = 0; j < roi_out->height; j++)
{
  const float *in = ((float *)ivoid) + (size_t)4 * roi_in->width * j;
  float *out = ((float *)ovoid) + (size_t)4 * roi_out->width * j;
  for(int i = 0; i < roi_out->width; i++)
  {
    for_each_channel(c, aligned(in, out : 16))
      out[c] = in[c] * factor;
    in += 4; out += 4;
  }
}

// Allocate a temporary buffer (auto trouble message on failure)
float *tmp = NULL;
if(!dt_iop_alloc_image_buffers(self, roi_in, roi_out,
                                4 | DT_IMGSZ_OUTPUT, &tmp, NULL))
  return;
// ... use tmp ...
dt_free_align(tmp);

// Scale spatial parameters for current zoom level
const float sigma = user_radius * roi_out->scale / piece->iscale;

// Report trouble to the user (icon on module header)
dt_iop_set_module_trouble_message(self, _("warning text"), _("tooltip"), NULL);

// Check pipe type
if(piece->pipe->type & DT_DEV_PIXELPIPE_FULL) { /* full view only */ }

For widget creation, slider configuration, and notebook patterns, see GUI.md, sliders.md, and GUI_Recipes.md.


Module Lifecycle

Key Functions to Implement

FunctionPurpose
gui_init()Create and configure all widgets (do NOT set values here)
gui_update()Sync widget values from self->params (called when params change)
gui_changed()Adjust UI based on current state (show/hide widgets, update labels)
gui_cleanup()Free any manually allocated resources
init_pipe()Allocate piece->data — required if using a custom data_t larger than params_t
commit_params()Transform self->params (from database/UI) into processing-ready piece->data for process()
cleanup_pipe()Free piece->data and any sub-allocations
color_picker_apply()Handle color picker results (if using pickers)
reload_defaults()Update defaults for different image types
init_global()One-time setup per module type (OpenCL kernels, shared LUTs)
cleanup_global()Free resources from init_global()
process_cl()GPU (OpenCL) processing — optional, falls back to process()
tiling_callback()Report memory requirements for tiled processing

Key Data Structures

StructStored inPurpose
params_tself->params, databaseUser-facing parameters — controlled by UI widgets, serialized to database
data_t (optional)piece->dataProcessing-optimized version of params — precomputed LUTs, transformed values, runtime state. Built by commit_params(), consumed by process(). If not defined, piece->data is a plain copy of params_t.
gui_data_tself->gui_dataWidget references and GUI-only state — only exists in darkroom mode

Data Flow

gui_init()    →  Create widgets, configure ranges/formats
                 (do NOT call gui_update here - params may not be ready)
                      ↓
gui_update()  ←  Called when params change (image switch, history)
                      ↓
gui_changed() ←  Always call gui_changed(self, NULL, NULL) at end of gui_update
                 to apply any UI adjustments (show/hide, sensitivity, etc.)
                      ↓
User interacts with widget
                      ↓
Auto-callback (from_params) or manual callback
                      ↓
self->params updated → gui_changed() called automatically
                      ↓
dt_dev_add_history_item() → commit_params() → process()
         │                        │                │
    records params         transforms params    reads piece->data
    to history stack       into piece->data     (data_t or params_t)

See GUI.md for the full event flow, callback patterns, and thread safety.


File Locations

WhatWhere
IOP modulessrc/iop/*.c
GUI helperssrc/develop/imageop_gui.c, imageop_gui.h
Bauhaus widgetssrc/bauhaus/bauhaus.c, bauhaus.h
GTK helperssrc/gui/gtk.c, gtk.h
Paint iconssrc/dtgtk/paint.c, paint.h
Color pickersrc/gui/color_picker_proxy.c, .h
Image buffer helperssrc/common/imagebuf.c, imagebuf.h
Pixel types/macrossrc/common/dttypes.h (for_each_channel), darktable.h (DT_OMP_FOR)
Tiling supportsrc/develop/tiling.c, tiling.h
Sample modulesrc/iop/useless.c (extensively commented)

Example Modules to Study

ModuleFeatures Demonstrated
useless.cStart here - Fully documented template; uses params_t directly as piece->data
exposure.cCustom data_t (embeds params_t + precomputed fields), color picker, deflicker mode
bloom.cSimple module: percentage sliders, basic processing
sharpen.cSimple module: few parameters, straightforward processing
vignette.cToggle buttons, various slider types, coordinate parameters
filmicrgb.cComplex data_t with spline LUT, tabbed UI, graphs, color science
colorbalancergb.cComplex data_t with gamut LUT, color space transforms, many precomputations
colorequal.cGtkStack with notebook, collapsible sections, advanced patterns
toneequal.cdata_t with interpolation matrix solving and precomputed correction LUT
sigmoid.cdata_t derived entirely from mathematical transformations of user params
retouch.cMany icon toggle buttons, drawing tools, mask shapes
ashift.cGeometry module with modify_roi_*, distort_* functions