dymokomi/luced-photo
Source of release 0.1.1
0.1.1 / src / develop_controls.luc
## The develop's controls in the Properties pane. Each section of luce-develop's
## parameter table (White Balance, Exposure, Lens, Filter, Film, Develop, Scan,
## Tone, Levels, Curves, Color, Color Mixer, Color Grading, Black & White, View,
## Vignette, Geometry, Crop) is a
## luce-ui ParameterPanel with one folder heading, the same rows luced-2d and
## luced-3d use: right-aligned labels in one fixed column, a typeable field and
## an equal-length slider per number, gradient tracks where color or light helps
## to read the value, toggles, menus and buttons. Curves and Color Grading add a
## widget under their panel (the curve editor, the tone wheels), shown while the
## folder is open. The Color Mixer edits one hue band at a time: a row of chips
## picks the band, its hue, saturation and luminance show on three sliders.
##
## Each section belongs to a stage of the photo's recipe (luce-develop's
## recipe.lucb), each stage to one of the app's modes (modes.luc), and a mode
## shows its stages' sections: Capture the camera's and the film's, Develop the
## chemistry, Print the Output it goes to (a telecine, a release print, a
## slide, paper) and that output's stages, View the display rendering and the
## frame. White Balance, Lens and Filter have an On switch: off, the light
## passes them by.
##
## The controls edit a Look (luce-develop's settings) and call `on_change` after
## every edit; `show` loads a photo's settings without calling it.
from luce_ui.ui import VStack, HStack, Text, Font, Widget, ParameterPanel, ParameterSpec, ParameterKind, CurveEditor, ColorWheel, Button, Size
from luce_ui import ui
from interop import Connection
from luce_develop.settings import Look, look
from luce_develop import settings
from luce_develop import film
from luce_develop import recipe
from luce_std import math
import modes
## The label column every section shares, so all the sliders line up.
let label_width: float = 104.0
## The sections in the order they show, and those that start open.
func section_order() -> list[str]:
return ["White Balance", "Exposure", "Lens", "Filter", "Film", "Develop", "Output", "Scan", "Tone", "Levels", "Curves", "Color", "Color Mixer", "Color Grading", "Black & White", "Print", "Paper", "View", "Vignette", "Geometry", "Crop"]
## A stage with one section shows it open; the Grade's start with Tone and Color.
func opened() -> list[str]:
return ["White Balance", "Exposure", "Lens", "Filter", "Film", "Develop", "Output", "Scan", "Tone", "Color", "Print", "Paper", "View", "Vignette", "Geometry", "Crop"]
## The Color Mixer's bands, as the parameter names spell them, and their chips' colors.
func bands() -> list[str]:
return ["red", "orange", "yellow", "green", "aqua", "blue", "purple", "magenta"]
func band_colors() -> list[str]:
return ["#D23C3C", "#E0802A", "#E3C93A", "#4CAF50", "#3FBFBF", "#3B6FD8", "#8A4FD0", "#D04FA8"]
## The track a parameter's slider shows, or "" for the plain one.
func gradient_for(name: str) -> str:
if name in ["temperature", "film_warmth"]:
return "#4A7FD6|#F0F0F0|#E8A93C"
if name in ["tint", "film_tint"]:
return "#3FA34A|#F0F0F0|#C24FBF"
if name in ["exposure", "highlights", "shadows", "whites", "blacks", "levels_black", "levels_white", "levels_out_black", "levels_out_white", "grade_global_luminance", "grade_shadows_luminance", "grade_midtones_luminance", "grade_highlights_luminance"]:
return "#161616|#E8E8E8"
# Printer lights: more of a color's light prints its complement.
if name == "print_red":
return "#D23C3C|#F0F0F0|#3FBFBF"
if name == "print_green":
return "#3FA34A|#F0F0F0|#C24FBF"
if name == "print_blue":
return "#3B6FD8|#F0F0F0|#E3C93A"
# The color head's filtration: each holds back its complement's layer.
if name == "paper_yellow":
return "#F0F0F0|#E3C93A"
if name == "paper_magenta":
return "#F0F0F0|#C24FBF"
if name == "paper_cyan":
return "#F0F0F0|#3FBFBF"
if name in ["saturation", "vibrance"]:
return "#808080|#D9534F|#E3C93A|#4CAF50|#3B6FD8"
if name.starts_with("bw_") and name != "bw_tint_hue" and name != "bw_tint_amount":
let at = bands().index_of(name[3..]) else return ""
return f"#202020|{band_colors()[at]}|#EFEFEF"
if name == "bw_tint_hue":
return "#D23C3C|#E3C93A|#4CAF50|#3FBFBF|#3B6FD8|#D04FA8|#D23C3C"
return ""
## Parameters a section's sliders do not show: the wheels hold the grading hues
## and saturations, the mixer rows the bands', and switches and menus the rest.
func by_hand(name: str) -> bool:
if name in ["view", "bw", "geometry_autocrop", "film_stock", "film_format", "film_filter", "film_color_filter", "develop_process", "scan_calibration", "scan_resolution", "lens_coating", "lens_diffusion", "paper_stock", "paper_enlarger", "paper_surface", "print_material", "print_optical", "film_backing", "develop_agitation", "geometry_turn"] or name.starts_with("crop_"):
return true
if name.starts_with("grade_") and (name.ends_with("_hue") or name.ends_with("_saturation")):
return true
for band in bands():
if name.starts_with(band + "_"):
return true
return false
## One section: its panel, what each row edits, and a widget under it.
class Section:
pub let title: str
pub let panel: ParameterPanel
pub let names: list[str]
pub let extra: VStack?
## The recipe stage the section belongs to, and whether it shows.
pub let stage: int
pub var shown: bool = true
pub func init(self, title: str, specs: list[ParameterSpec], extra: VStack?, font: Font) -> unit!:
self.title = title
# No margin of its own, so its headings line up with the histogram above, and
# dense headings, so the long column of sections stays compact.
self.panel = ParameterPanel(specs, font = font, label_width = label_width, margin = 0.0, dense = true)
var names: list[str] = []
for spec in specs:
names.append(spec.name)
self.names = names
self.extra = extra
# The Output menu belongs to the Print mode, not to a stage.
self.stage = output_section if title == "Output" else recipe.owner_of(title)
## Row `name`'s index, or -1.
pub func row(self, name: str) -> int:
return self.names.index_of(name) else -1
pub func is_open(self) -> bool:
return self.panel.folder_open(self.title)
## The Output section's stage number: none of the recipe's.
let output_section: int = -2
## Parameter `name`'s menu items ("name=value|…") from its choices in
## luce-develop (the names the settings store), from choice `first` to before
## `end` (-1: all).
func choice_items(name: str, first: int = 0, end: int = -1) -> str:
var items: list[str] = []
let last = settings.choice_total(name) if end < 0 else end
for at in first..<last:
items.append(f"{settings.choice_name(name, at)}={at}")
return items.join("|")
## The stages a switch takes in and out of the recipe.
func optional(stage: int) -> bool:
return stage >= 0 and recipe.stage_optional(stage)
pub class DevelopControls:
pub let body: VStack
## The settings the controls edit.
pub let look: Look
let sections: list[Section]
let curves: CurveEditor
var channel: int = 0
let channel_name: Text
## The tone wheels: shadows, midtones, highlights, global.
let wheels: list[ColorWheel]
## The Color Mixer's band.
var band: int = 0
var connections: list[Connection] = []
## The photo's as-shot white balance, which temperature 0 means.
var shot_temperature: float = 5500.0
var shot_seconds: float = 0.0
var shot_tint: float = 0.0
var showing: bool = false
## Whether the guide tool and the crop tool are on.
pub var guiding: bool = false
pub var cropping: bool = false
pub var on_change: func() -> unit!? = none
pub var on_guide_tool: func(bool) -> unit!? = none
pub var on_guides_cleared: func() -> unit!? = none
## Called when the crop tool turns on or off, and with the aspect to keep
## (width over height; 0 free, -1 the photo's own).
pub var on_crop_tool: func(bool, float) -> unit!? = none
pub var on_crop_aspect: func(float) -> unit!? = none
## Called when the photo turns a quarter (its sides swap).
pub var on_turn: func() -> unit!? = none
## The mode whose sections show (modes.luc).
var mode: int = 1
## What the Library mode shows: the photo's preset's exposed parameters.
pub var exposed: list[str] = []
pub func init(self, font: Font) -> unit!:
self.look = look("")
self.sections = []
self.channel_name = Text("RGB", font = font, muted = true)
self.curves = CurveEditor()
self.curves.layout().set_limits(Size(200.0, 200.0), Size(320.0, 320.0))
self.wheels = []
var widgets: list[Widget] = []
for title in section_order():
let section = Section(title, self.specs_for(title), self.extra_for(title, font), font)
self.watch(section)
self.sections.append(section)
widgets.append(section.panel)
if let extra = section.extra:
widgets.append(extra)
self.body = VStack(widgets, spacing = 0.0)
self.show_values()
# mark: building ============================================================================
## The parameters of section `title` that are plain sliders, in table order.
func table_rows(self, title: str) -> list[int]:
var rows: list[int] = []
for at in 0..<settings.parameter_total():
if settings.section_of(at) == title and not by_hand(settings.name_of(at)):
rows.append(at)
return rows
func specs_for(self, title: str) -> list[ParameterSpec]:
var specs = [ParameterSpec(name = title, label = title, kind = ParameterKind.folder, open = title in opened())]
if title == "Color Mixer":
var items: list[str] = []
for (at, band) in bands().indexed():
items.append(f"{band.upper()[0..<1]}{band[1..]}={band_colors()[at]}")
specs.append(ParameterSpec(name = "band", label = "Band", kind = ParameterKind.swatches, items = items.join("|"), resettable = false))
for part in ["Hue", "Saturation", "Luminance"]:
specs.append(ParameterSpec(name = f"mixer_{part.lower()}", label = part, minimum = -100.0, maximum = 100.0, decimals = 0, slider = true))
for at in self.table_rows(title):
let name = settings.name_of(at)
specs.append(ParameterSpec(name = name, label = settings.label_of(at), value = settings.default_of(at),
minimum = settings.low_of(at), maximum = settings.high_of(at),
soft_minimum = 2000.0 if name == "temperature" else 0.0, soft_maximum = 12000.0 if name == "temperature" else 0.0,
decimals = settings.decimals_of(at), slider = true, gradient = gradient_for(name)))
if title == "White Balance":
specs.append(ParameterSpec(name = "as_shot", label = "As Shot", kind = ParameterKind.button))
if title == "Output":
var outputs: list[str] = []
for at in 0..<recipe.output_total():
outputs.append(f"{recipe.output_name(at)}={at}")
specs.append(ParameterSpec(name = "output", label = "Output", kind = ParameterKind.menu, items = outputs.join("|"), resettable = false,
doc = "What the developed film goes to: a telecine, a release print projected, a slide on a lightbox, paper, or a digital intermediate"))
return specs
if title == "Black & White":
specs.insert(1, ParameterSpec(name = "bw", label = "Black & White", kind = ParameterKind.toggle))
if title == "Geometry":
specs.insert(1, ParameterSpec(name = "draw_guides", label = "Draw Guides", kind = ParameterKind.button, join = true))
specs.insert(2, ParameterSpec(name = "clear_guides", label = "Clear Guides", kind = ParameterKind.button))
specs.append(ParameterSpec(name = "geometry_autocrop", label = "Crop to Fit", kind = ParameterKind.toggle, value = 1.0))
if title == "Crop":
specs.append(ParameterSpec(name = "turn_left", label = "Rotate Left", kind = ParameterKind.button, join = true,
doc = "A quarter turn counterclockwise; the crop turns with the photo"))
specs.append(ParameterSpec(name = "turn_right", label = "Rotate Right", kind = ParameterKind.button,
doc = "A quarter turn clockwise; the crop turns with the photo"))
specs.append(ParameterSpec(name = "crop_tool", label = "Crop", kind = ParameterKind.button, join = true))
specs.append(ParameterSpec(name = "aspect", label = "Aspect", kind = ParameterKind.menu, resettable = false,
items = "Free=0|Original=-1|1:1=1|4:5=0.8|5:4=1.25|3:2=1.5|2:3=0.6667|16:9=1.7778"))
if title == "Film":
# Every stock; no film is not a choice here.
specs.insert(1, ParameterSpec(name = "film_stock", label = "Stock", kind = ParameterKind.menu, items = choice_items("film_stock", 1), value = 3.0))
specs.insert(2, ParameterSpec(name = "film_format", label = "Format", kind = ParameterKind.menu,
items = choice_items("film_format")))
specs.append(ParameterSpec(name = "film_backing", label = "Backing", kind = ParameterKind.menu,
items = choice_items("film_backing"),
doc = "The antihalation backing: removed, light reflected off the base comes back as red halos"))
if title == "Print":
specs.insert(1, ParameterSpec(name = "print_material", label = "Print Film", kind = ParameterKind.menu,
items = choice_items("print_material")))
specs.append(ParameterSpec(name = "print_optical", label = "Optical Step", kind = ParameterKind.toggle,
doc = "An optical printer between negative and print: Super 35's squeeze, a 70 mm blow-up"))
if title == "Paper":
specs.insert(1, ParameterSpec(name = "paper_stock", label = "Paper", kind = ParameterKind.menu, items = choice_items("paper_stock")))
specs.insert(2, ParameterSpec(name = "paper_enlarger", label = "Enlarger", kind = ParameterKind.menu,
items = choice_items("paper_enlarger"),
doc = "A condenser prints a silver negative harder (the Callier effect); a contact print has no enlarger flare"))
specs.insert(3, ParameterSpec(name = "paper_surface", label = "Surface", kind = ParameterKind.menu,
items = choice_items("paper_surface"),
doc = "A matte surface reflects some light before the image: its blacks are lighter (Kodak: D-max 1.7 against glossy's 2.1)"))
if title == "Lens":
specs.insert(1, ParameterSpec(name = "lens_coating", label = "Coating", kind = ParameterKind.menu,
items = choice_items("lens_coating"),
doc = "Veiling glare beyond a modern lens's: older coatings scatter more light over the frame"))
specs.insert(2, ParameterSpec(name = "lens_diffusion", label = "Diffusion", kind = ParameterKind.menu,
items = choice_items("lens_diffusion"),
doc = "A Tiffen Low Contrast filter: light from the frame laid over the shadows"))
if title == "Scan":
specs.insert(1, ParameterSpec(name = "scan_calibration", label = "Calibration", kind = ParameterKind.menu,
items = choice_items("scan_calibration"),
doc = "Reference: the scanner set up once, each stock showing its own color. Matched: fitted to this stock, colors returned to themselves"))
specs.insert(2, ParameterSpec(name = "scan_resolution", label = "Resolution", kind = ParameterKind.menu,
items = choice_items("scan_resolution"),
doc = "How finely the scanner samples the film: grain and detail are what it resolves, however far the viewer zooms"))
if title == "Develop":
# Its items follow the stock (show_values): its standard process,
# then the others of its family.
specs.insert(1, ParameterSpec(name = "develop_process", label = "Process", kind = ParameterKind.menu, items = "Standard=0"))
specs.append(ParameterSpec(name = "develop_agitation", label = "Agitation", kind = ParameterKind.menu,
items = choice_items("develop_agitation"),
doc = "How often fresh developer reaches the film: less agitation, stronger edge effects"))
if title == "Filter":
# Matched balances the light to the stock as a white balance does;
# with None or 85, White Balance is the light on set and the film sees it.
specs.insert(1, ParameterSpec(name = "film_filter", label = "Balance", kind = ParameterKind.menu,
items = choice_items("film_filter"),
doc = "Matched: balanced to the stock. None or 85: White Balance is the light on set, as the film saw it"))
specs.insert(2, ParameterSpec(name = "film_color_filter", label = "Color Filter", kind = ParameterKind.menu,
items = choice_items("film_color_filter"),
doc = "A color filter on the lens, as for black-and-white film; exposure opens up by its factor"))
if title == "View":
specs.append(ParameterSpec(name = "view", label = "Transform", kind = ParameterKind.menu, items = choice_items("view", 0, 3)))
specs.append(ParameterSpec(name = "reset", label = "Reset", kind = ParameterKind.button, doc = f"Put {title} back as it was"))
# The switch first, under the heading.
if optional(recipe.owner_of(title)):
specs.insert(1, ParameterSpec(name = "stage_on", label = "On", kind = ParameterKind.toggle, resettable = false,
doc = f"Off, the light passes the {title.lower()} by"))
return specs
## The widget under a section: the curve editor, or the tone wheels.
func extra_for(self, title: str, font: Font) -> VStack?!:
if title == "Curves":
var channels: list[Widget] = []
for (at, caption) in ["RGB", "R", "G", "B", "Luma"].indexed():
let button = Button(caption, font = font)
self.connections.append(button.on_click(func () -> unit!:
self.channel = at
self.channel_name.set_text(caption)
self.show_curve()))
channels.append(button)
channels.append(self.channel_name)
self.connections.append(self.curves.on_change(func () -> unit!:
if self.showing:
return
var xs: list[float] = []
var ys: list[float] = []
for point in 0..<self.curves.point_count():
xs.append(self.curves.point_x(point))
ys.append(self.curves.point_y(point))
self.look.set_curve(self.channel, xs, ys)
self.changed()))
return VStack([HStack(channels, spacing = 4.0), self.curves], spacing = 6.0, padding = 8.0)
if title == "Color Grading":
var cells: list[Widget] = []
for range in ["shadows", "midtones", "highlights", "global"]:
let wheel = ColorWheel(ui.wheel_disc)
wheel.layout().set_limits(Size(56.0, 56.0), Size(72.0, 72.0))
self.connections.append(wheel.on_change(func () -> unit!:
if self.showing:
return
self.look.set(f"grade_{range}_hue", wheel.hue_value())
self.look.set(f"grade_{range}_saturation", wheel.saturation_value() * 100.0)
self.changed()))
self.wheels.append(wheel)
cells.append(VStack([wheel, Text(range.upper()[0..<1] + range[1..], font = font, muted = true)], spacing = 2.0))
return VStack([HStack(cells, spacing = 6.0)], padding = 8.0)
return none
## Take a section's panel edits and buttons into the look.
func watch(self, section: Section) -> unit!:
self.connections.append(section.panel.on_change(func (index: int) -> unit!:
if not self.showing:
self.take(section, index)))
# A folder opened or closed: the widget under it with it.
self.connections.append(section.panel.on_folder(func (index: int) -> unit!:
self.show_extras()))
self.connections.append(section.panel.on_action(func (index: int) -> unit!:
self.act(section, section.names[index])))
# mark: editing =============================================================================
func take(self, section: Section, index: int) -> unit!:
let name = section.names[index]
let value = section.panel.value(index)
if name == "band":
self.band = int(value)
self.show_mixer(section)
return
if name == "aspect":
if let tell = self.on_crop_aspect:
tell(value)
return
if name == "stage_on":
self.look.set_stage_used(section.stage, value > 0.5)
self.show_values()
self.changed()
return
if name == "output":
self.look.set_output(int(value))
self.show_values()
self.changed()
return
if name.starts_with("mixer_"):
self.look.set(f"{bands()[self.band]}_{name[6..]}", value)
else:
self.look.set(name, value)
# Leaving as-shot white balance keeps the as-shot value of the other.
if name == "temperature" and self.look.get("tint") == 0.0:
self.look.set("tint", self.shot_tint)
if name == "tint" and self.look.get("temperature") == 0.0:
self.look.set("temperature", self.shot_temperature)
# Another stock or process: Develop shows its processes and normals.
if name == "film_stock" or name == "develop_process" or name == "paper_stock":
self.show_values()
self.changed()
func act(self, section: Section, name: str) -> unit!:
match name:
"as_shot":
self.look.set("temperature", 0.0)
self.look.set("tint", 0.0)
"draw_guides":
self.set_guiding(not self.guiding)
return
"crop_tool":
self.set_cropping(not self.cropping)
return
"turn_left":
self.turn(-1)
"turn_right":
self.turn(1)
"clear_guides":
self.look.set_guides([], [], [], [])
if let tell = self.on_guides_cleared:
tell()
"reset":
if section.title == "Curves":
for channel in 0..<5:
self.look.set_curve(channel, [], [])
else:
self.look.reset_section(section.title)
_:
return
self.show_values()
self.changed()
## Turn the photo a quarter `direction` (1 clockwise, -1 counterclockwise),
## the crop with it: a point (x, y) of the frame goes to (1 − y, x)
## clockwise, (y, 1 − x) counterclockwise.
pub func turn(self, direction: int) -> unit!:
let left = self.look.get("crop_left")
let top = self.look.get("crop_top")
let right = self.look.get("crop_right")
let bottom = self.look.get("crop_bottom")
if direction > 0:
self.set_crop([1.0 - bottom, left, 1.0 - top, right])
else:
self.set_crop([top, 1.0 - right, bottom, 1.0 - left])
self.look.set("geometry_turn", float((int(self.look.get("geometry_turn")) + direction + 4) % 4))
if let tell = self.on_turn:
tell()
func changed(self) -> unit!:
if let tell = self.on_change:
tell()
## Turn the crop tool on or off (the guide tool off when it turns on).
pub func set_cropping(self, on: bool) -> unit!:
if on == self.cropping:
return
if on:
self.set_guiding(false)
self.cropping = on
var aspect = 0.0
for section in self.sections:
let at = section.row("crop_tool")
if at >= 0:
section.panel.set_label(at, "Done" if on else "Crop")
aspect = section.panel.value(section.row("aspect"))
if let tell = self.on_crop_tool:
tell(on, aspect)
## The crop: left, top, right, bottom.
pub func crop_values(self) -> list[float]!:
return [self.look.get("crop_left"), self.look.get("crop_top"), self.look.get("crop_right"), self.look.get("crop_bottom")]
## Take `edges` (left, top, right, bottom) as the crop.
pub func set_crop(self, edges: list[float]) -> unit!:
for (at, name) in ["crop_left", "crop_top", "crop_right", "crop_bottom"].indexed():
self.look.set(name, edges[at])
## Turn the guide tool on or off (the crop tool off when it turns on).
pub func set_guiding(self, on: bool) -> unit!:
if on == self.guiding:
return
if on:
self.set_cropping(false)
self.guiding = on
for section in self.sections:
let at = section.row("draw_guides")
if at >= 0:
section.panel.set_label(at, "Done" if on else "Draw Guides")
if let tell = self.on_guide_tool:
tell(on)
## The look's guides, x1, y1, x2, y2 each.
pub func guide_points(self) -> list[float]:
var points: list[float] = []
for at in 0..<self.look.guide_count():
for end in 0..<4:
points.append(self.look.guide(at, end))
return points
## Take `points` (x1, y1, x2, y2 each) as the look's guides.
pub func set_guide_points(self, points: list[float]) -> unit!:
var x1s: list[float] = []
var y1s: list[float] = []
var x2s: list[float] = []
var y2s: list[float] = []
var at = 0
while at + 3 < points.length:
x1s.append(points[at])
y1s.append(points[at + 1])
x2s.append(points[at + 2])
y2s.append(points[at + 3])
at += 4
self.look.set_guides(x1s, y1s, x2s, y2s)
# mark: showing =============================================================================
## Load `text` (a photo's settings in their text form); the photo's as-shot
## balance is `shot_temperature` and `shot_tint`.
pub func show(self, text: str, shot_temperature: float, shot_tint: float) -> unit!:
self.look.load(text)
self.set_shot(shot_temperature, shot_tint)
## Load `text` keeping the photo's as-shot balance (undo, paste).
pub func reload(self, text: str) -> unit!:
self.look.load(text)
self.show_values()
## The photo's as-shot white balance and shutter time (seconds, zero when
## unknown), known once its develop has loaded.
pub func set_shot(self, shot_temperature: float, shot_tint: float, shot_seconds: float = 0.0) -> unit!:
self.shot_temperature = shot_temperature
self.shot_tint = shot_tint
self.shot_seconds = shot_seconds
self.show_values()
## Put the look's values on every control.
pub func show_values(self) -> unit!:
self.showing = true
for section in self.sections:
for (index, name) in section.names.indexed():
if name == section.title or name == "band" or name.starts_with("mixer_") or name in ["as_shot", "draw_guides", "clear_guides", "reset", "crop_tool", "aspect", "turn_left", "turn_right"]:
continue
if name == "stage_on":
section.panel.set_value(index, 1.0 if self.look.has_stage(section.stage) else 0.0)
continue
if name == "output":
section.panel.set_value(index, float(self.look.output()))
continue
var value = self.look.get(name)
# The white balance's default is the camera's: it shows as shot,
# unmarked, until moved.
# The shutter, likewise: the camera's until moved.
if name == "exposure_time" and self.shot_seconds > 0.0:
section.panel.set_default(index, 0, self.shot_seconds)
if value == 0.0:
value = self.shot_seconds
if name == "temperature":
section.panel.set_default(index, 0, self.shot_temperature)
if value == 0.0:
value = self.shot_temperature
if name == "tint":
section.panel.set_default(index, 0, self.shot_tint)
if self.look.get("temperature") == 0.0:
value = self.shot_tint
# Development defaults to the stock's process: its normal time
# and temperature, unmarked until moved.
if name == "develop_process":
section.panel.set_items(index, film.stock_processes(self.stock()))
# Grade for variable-contrast paper, filtration for color paper.
if name == "paper_grade":
section.panel.set_enabled(index, not film.paper_is_color(int(self.look.get("paper_stock"))))
if name in ["paper_yellow", "paper_magenta", "paper_cyan"]:
section.panel.set_enabled(index, film.paper_is_color(int(self.look.get("paper_stock"))))
# Only a color negative's silver is extra to its image.
if name == "develop_silver":
section.panel.set_enabled(index, film.stock_kind(self.stock()) == 0)
if name in ["develop_time", "develop_temperature"]:
let process = self.process()
let normal = film.stock_process_time(self.stock(), process) if name == "develop_time" else film.process_temperature(process)
section.panel.set_default(index, 0, normal)
if value == 0.0:
value = normal
section.panel.set_value(index, value)
if section.title == "Color Mixer":
self.show_mixer(section)
for (at, range) in ["shadows", "midtones", "highlights", "global"].indexed():
self.wheels[at].set_hsb(self.look.get(f"grade_{range}_hue"), self.look.get(f"grade_{range}_saturation") / 100.0, 1.0)
self.showing = false
self.show_curve()
self.show_mode(self.mode)
## Show mode `mode`'s sections (modes.luc): its stages' that the recipe
## has, and its optional ones (switched off, their rows greyed); Print's
## Output first. The Library mode shows none.
pub func show_mode(self, mode: int) -> unit!:
self.mode = mode
for section in self.sections:
var shown = false
# The Library mode: only the exposed rows, in their sections.
let library = mode == modes.library
for (index, name) in section.names.indexed():
if name != section.title:
let hidden = library and not (name in self.exposed)
section.panel.set_hidden(index, hidden)
shown = shown or (library and not hidden)
if library:
shown = shown and (section.stage < 0 or self.look.has_stage(section.stage))
elif section.stage == output_section:
shown = mode == modes.printing
elif section.stage >= 0 and modes.of_stage(section.stage) == mode:
shown = self.look.has_stage(section.stage) or optional(section.stage)
section.shown = shown
section.panel.layout().set_visible(shown)
if shown and optional(section.stage):
let on = self.look.has_stage(section.stage)
for (index, name) in section.names.indexed():
if name != section.title and name != "stage_on":
section.panel.set_enabled(index, on)
self.show_extras()
## The stock chosen (0-based).
func stock(self) -> int!:
return int(math.clamp(self.look.get("film_stock"), 1.0, float(film.stock_count()))) - 1
## The process the stock develops in (an index into film's processes).
func process(self) -> int!:
return film.stock_process(self.stock(), self.look.get("develop_process"))
## Whether section `title` shows (its stage is picked, or in the recipe).
pub func section_shown(self, title: str) -> bool:
for section in self.sections:
if section.title == title:
return section.shown
return false
## The Color Mixer's three rows for the chosen band: its values and tracks.
func show_mixer(self, section: Section) -> unit!:
let was = self.showing
self.showing = true
let band = bands()[self.band]
let colors = band_colors()
let color = colors[self.band]
let before = colors[(self.band + 7) % 8]
let after = colors[(self.band + 1) % 8]
section.panel.set_value(section.row("band"), float(self.band))
for (part, gradient) in [("hue", f"{before}|{color}|{after}"), ("saturation", f"#808080|{color}"), ("luminance", f"#161616|{color}|#EFEFEF")]:
let at = section.row(f"mixer_{part}")
section.panel.set_value(at, self.look.get(f"{band}_{part}"))
section.panel.set_gradient(at, gradient)
self.showing = was
func show_curve(self) -> unit!:
let was = self.showing
self.showing = true
var xs: list[float] = []
var ys: list[float] = []
for point in 0..<self.look.curve_size(self.channel):
xs.append(self.look.curve_x(self.channel, point))
ys.append(self.look.curve_y(self.channel, point))
self.curves.set_points(xs, ys)
self.showing = was
## The widgets under sections (the curve editor, the tone wheels): shown
## while their section shows and its folder is open.
func show_extras(self):
for section in self.sections:
if let extra = section.extra:
extra.layout().set_visible(section.shown and section.is_open())
pub func close(self):
for connection in self.connections:
connection.disconnect()
self.connections.clear()