+vector<string> EffectChain::get_labels_for_edge(const Node *from, const Node *to)
+{
+ vector<string> labels;
+
+ if (to != NULL && to->effect->needs_texture_bounce()) {
+ labels.push_back("needs_bounce");
+ }
+ if (from->effect->changes_output_size()) {
+ labels.push_back("resize");
+ }
+
+ switch (from->output_color_space) {
+ case COLORSPACE_INVALID:
+ labels.push_back("spc[invalid]");
+ break;
+ case COLORSPACE_REC_601_525:
+ labels.push_back("spc[rec601-525]");
+ break;
+ case COLORSPACE_REC_601_625:
+ labels.push_back("spc[rec601-625]");
+ break;
+ default:
+ break;
+ }
+
+ switch (from->output_gamma_curve) {
+ case GAMMA_INVALID:
+ labels.push_back("gamma[invalid]");
+ break;
+ case GAMMA_sRGB:
+ labels.push_back("gamma[sRGB]");
+ break;
+ case GAMMA_REC_601: // and GAMMA_REC_709
+ labels.push_back("gamma[rec601/709]");
+ break;
+ default:
+ break;
+ }
+
+ switch (from->output_alpha_type) {
+ case ALPHA_INVALID:
+ labels.push_back("alpha[invalid]");
+ break;
+ case ALPHA_BLANK:
+ labels.push_back("alpha[blank]");
+ break;
+ case ALPHA_POSTMULTIPLIED:
+ labels.push_back("alpha[postmult]");
+ break;
+ default:
+ break;
+ }
+
+ return labels;
+}
+
+void EffectChain::output_dot_edge(FILE *fp,
+ const string &from_node_id,
+ const string &to_node_id,
+ const vector<string> &labels)
+{
+ if (labels.empty()) {
+ fprintf(fp, " %s -> %s;\n", from_node_id.c_str(), to_node_id.c_str());
+ } else {
+ string label = labels[0];
+ for (unsigned k = 1; k < labels.size(); ++k) {
+ label += ", " + labels[k];
+ }
+ fprintf(fp, " %s -> %s [label=\"%s\"];\n", from_node_id.c_str(), to_node_id.c_str(), label.c_str());
+ }
+}
+
+void EffectChain::size_rectangle_to_fit(unsigned width, unsigned height, unsigned *output_width, unsigned *output_height)
+{
+ unsigned scaled_width, scaled_height;
+
+ if (float(width) * aspect_denom >= float(height) * aspect_nom) {
+ // Same aspect, or W/H > aspect (image is wider than the frame).
+ // In either case, keep width, and adjust height.
+ scaled_width = width;
+ scaled_height = lrintf(width * aspect_denom / aspect_nom);
+ } else {
+ // W/H < aspect (image is taller than the frame), so keep height,
+ // and adjust width.
+ scaled_width = lrintf(height * aspect_nom / aspect_denom);
+ scaled_height = height;
+ }
+
+ // We should be consistently larger or smaller then the existing choice,
+ // since we have the same aspect.
+ assert(!(scaled_width < *output_width && scaled_height > *output_height));
+ assert(!(scaled_height < *output_height && scaled_width > *output_width));
+
+ if (scaled_width >= *output_width && scaled_height >= *output_height) {
+ *output_width = scaled_width;
+ *output_height = scaled_height;
+ }
+}
+
+// Propagate input texture sizes throughout, and inform effects downstream.
+// (Like a lot of other code, we depend on effects being in topological order.)
+void EffectChain::inform_input_sizes(Phase *phase)
+{
+ // All effects that have a defined size (inputs and RTT inputs)
+ // get that. Reset all others.
+ for (unsigned i = 0; i < phase->effects.size(); ++i) {
+ Node *node = phase->effects[i];
+ if (node->effect->num_inputs() == 0) {
+ Input *input = static_cast<Input *>(node->effect);
+ node->output_width = input->get_width();
+ node->output_height = input->get_height();
+ assert(node->output_width != 0);
+ assert(node->output_height != 0);
+ } else {
+ node->output_width = node->output_height = 0;
+ }
+ }
+ for (unsigned i = 0; i < phase->inputs.size(); ++i) {
+ Node *input = phase->inputs[i];
+ input->output_width = input->phase->virtual_output_width;
+ input->output_height = input->phase->virtual_output_height;
+ assert(input->output_width != 0);
+ assert(input->output_height != 0);
+ }
+
+ // Now propagate from the inputs towards the end, and inform as we go.
+ // The rules are simple:
+ //
+ // 1. Don't touch effects that already have given sizes (ie., inputs).
+ // 2. If all of your inputs have the same size, that will be your output size.
+ // 3. Otherwise, your output size is 0x0.
+ for (unsigned i = 0; i < phase->effects.size(); ++i) {
+ Node *node = phase->effects[i];
+ if (node->effect->num_inputs() == 0) {
+ continue;
+ }
+ unsigned this_output_width = 0;
+ unsigned this_output_height = 0;
+ for (unsigned j = 0; j < node->incoming_links.size(); ++j) {
+ Node *input = node->incoming_links[j];
+ node->effect->inform_input_size(j, input->output_width, input->output_height);
+ if (j == 0) {
+ this_output_width = input->output_width;
+ this_output_height = input->output_height;
+ } else if (input->output_width != this_output_width || input->output_height != this_output_height) {
+ // Inputs disagree.
+ this_output_width = 0;
+ this_output_height = 0;
+ }
+ }
+ node->output_width = this_output_width;
+ node->output_height = this_output_height;
+ }
+}
+
+// Note: You should call inform_input_sizes() before this, as the last effect's
+// desired output size might change based on the inputs.