From 8adf17510f2d3b3f11b3ca1b34697cf5d508c02d Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 6 Aug 2014 22:24:20 +0200 Subject: [PATCH] Fix qdx and qdy computation. Off-by-1 error. --- rotation.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rotation.cpp b/rotation.cpp index f00c02e..cfce3e3 100644 --- a/rotation.cpp +++ b/rotation.cpp @@ -517,8 +517,8 @@ Image* rotate(Image const& src, double angle) Image* rotated = new Image(w, h, src.type); DPoint const src_origin = get_mapped_point(*rotated, Point(0, 0), -rotation); - DPoint src_delta_x = get_mapped_point(*rotated, Point(src.width - 1, 0), -rotation); - DPoint src_delta_y = get_mapped_point(*rotated, Point(0, src.height - 1), -rotation); + DPoint src_delta_x = get_mapped_point(*rotated, Point(src.width, 0), -rotation); + DPoint src_delta_y = get_mapped_point(*rotated, Point(0, src.height), -rotation); src_delta_x -= src_origin; src_delta_y -= src_origin; @@ -527,8 +527,8 @@ Image* rotate(Image const& src, double angle) int const q_pos = 1 << q_pos_pow; // TODO: we could have only one delta and deduce the other one - Point const qdx((src_delta_x.x * q_pos) / src.width, (src_delta_x.y * q_pos) / src.width); - Point const qdy((src_delta_y.x * q_pos) / src.height, (src_delta_y.y * q_pos) / src.height); + Point const qdx(ceil(src_delta_x.x * q_pos / src.width), ceil(src_delta_x.y * q_pos / src.width)); + Point const qdy(ceil(src_delta_y.x * q_pos / src.height), ceil(src_delta_y.y * q_pos / src.height)); DPoint const rot_origin_in_src_grid = get_mapped_point(*rotated, Point(0, 0), -rotation); DPoint const rot_origin_in_src = convert_img_coord_precision(src, rot_origin_in_src_grid); @@ -542,8 +542,8 @@ Image* rotate(Image const& src, double angle) int const& src_qwidth = src.width * q_pos; int const& src_qheight = src.height * q_pos; - Point src_rotated_origin(rot_origin_in_src.x * q_pos + q_pos / 2, - rot_origin_in_src.y * q_pos + q_pos / 2); + Point src_rotated_origin(rot_origin_in_src.x * q_pos, + rot_origin_in_src.y * q_pos); // Padding uint16_t* padding_table = generate_padding_table(*rotated, src_rotated_origin, qdx, qdy,