+
+// If the user has requested dither, add a DitherEffect right at the end
+// (after GammaCompressionEffect etc.). This needs to be done after everything else,
+// since dither is about the only effect that can _not_ be done in linear space.
+void EffectChain::add_dither_if_needed()
+{
+ if (num_dither_bits == 0) {
+ return;
+ }
+ Node *output = find_output_node();
+ Node *dither = add_node(new DitherEffect());
+ CHECK(dither->effect->set_int("num_bits", num_dither_bits));
+ connect_nodes(output, dither);
+
+ dither_effect = dither->effect;
+}