} // namespace
ResampleEffect::ResampleEffect()
- : owns_effects(true),
- input_width(1280),
+ : input_width(1280),
input_height(720),
offset_x(0.0f), offset_y(0.0f),
zoom_x(1.0f), zoom_y(1.0f),
register_int("height", &output_height);
// The first blur pass will forward resolution information to us.
- hpass = new SingleResamplePassEffect(this);
+ hpass_owner.reset(new SingleResamplePassEffect(this));
+ hpass = hpass_owner.get();
CHECK(hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL));
- vpass = new SingleResamplePassEffect(nullptr);
+ vpass_owner.reset(new SingleResamplePassEffect(this));
+ vpass = vpass_owner.get();
CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL));
update_size();
ResampleEffect::~ResampleEffect()
{
- if (owns_effects) {
- delete hpass;
- delete vpass;
- }
}
void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
{
- Node *hpass_node = graph->add_node(hpass);
- Node *vpass_node = graph->add_node(vpass);
+ Node *hpass_node = graph->add_node(hpass_owner.release());
+ Node *vpass_node = graph->add_node(vpass_owner.release());
graph->connect_nodes(hpass_node, vpass_node);
graph->replace_receiver(self, hpass_node);
graph->replace_sender(self, vpass_node);
self->disabled = true;
- owns_effects = false;
}
// We get this information forwarded from the first blur pass,
SingleResamplePassEffect::SingleResamplePassEffect(ResampleEffect *parent)
: parent(parent),
direction(HORIZONTAL),
- input_width(1280),
- input_height(720),
+ input_width(1280),
+ input_height(720),
offset(0.0),
zoom(1.0),
last_input_width(-1),
// to compute the destination pixel, and how many depend on the scaling factor.
// Thus, the kernel width will vary with how much we scale.
float radius_scaling_factor = min(scaling_factor, 1.0f);
- int int_radius = lrintf(LANCZOS_RADIUS / radius_scaling_factor);
- int src_samples = int_radius * 2 + 1;
+ const int int_radius = lrintf(LANCZOS_RADIUS / radius_scaling_factor);
+ const int src_samples = int_radius * 2 + 1;
unique_ptr<Tap<float>[]> weights(new Tap<float>[dst_samples * src_samples]);
float subpixel_offset = offset - lrintf(offset); // The part not covered by whole_pixel_offset.
assert(subpixel_offset >= -0.5f && subpixel_offset <= 0.5f);
+ float inv_scaling_factor = 1.0f / scaling_factor;
for (unsigned y = 0; y < dst_samples; ++y) {
// Find the point around which we want to sample the source image,
// compensating for differing pixel centers as the scale changes.
- float center_src_y = (y + 0.5f) / scaling_factor - 0.5f;
+ float center_src_y = (y + 0.5f) * inv_scaling_factor - 0.5f;
int base_src_y = lrintf(center_src_y);
// Now sample <int_radius> pixels on each side around that point.