From 7ac7522908f5d8de6054edb5ccb2e876a6dbafb3 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 6 Aug 2014 23:11:42 +0200 Subject: [PATCH] Add check when building padding table. --- rotation.cpp | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/rotation.cpp b/rotation.cpp index a1a6a16..1d88ea1 100644 --- a/rotation.cpp +++ b/rotation.cpp @@ -211,21 +211,42 @@ uint16_t* generate_padding_table(Image const& rotated, padding_table[i] = max(x_range, y_range); - { - Point test(src_rotated_origin.x + padding_table[i] * qdx.x, + Point border(src_rotated_origin.x + padding_table[i] * qdx.x, src_rotated_origin.y + padding_table[i] * qdx.y); - if (test.x < 0 || test.y < 0 - || test.x >= src_qwidth || test.y >= src_qheight) + if (border.x < 0 || border.y < 0 + || border.x >= src_qwidth || border.y >= src_qheight) + { + if (false) { - cout << "Padding issue at line " << i << endl; - cout << " src: " << src_rotated_origin << endl; - cout << " test: " << test << endl; - cout << " q dim: " << src_qwidth << " x " << src_qheight << endl; - cout << " " << padding_table[i] << " x " << qdx << endl; - cout << " x diff = " << src_rotated_origin.x - src_qwidth + 1 << endl; - cout << " x coef = " << (float) (src_rotated_origin.x - src_qwidth + 1) / (float) (-qdx.x) << endl; + LOG << "Padding issue at line " << i << endl; + LOG << " origin: " << src_rotated_origin << endl; + LOG << " border: " << border << endl; + LOG << " q dim: " << src_qwidth << " x " << src_qheight << endl; + LOG << " " << padding_table[i] << " x " << qdx << endl; + LOG << " X range" << endl; + LOG << " x diff = " << src_rotated_origin.x - src_qwidth + 1 << endl; + LOG << " x coef = " << (float) (src_rotated_origin.x - src_qwidth + 1) / (float) (-qdx.x) << endl; + LOG << " Y range" << endl; + if (src_rotated_origin.y < 0) + { + LOG << " y < 0" << endl; + LOG << " y diff = " << (-src_rotated_origin.y) << endl; + LOG << " y coef = " << (-src_rotated_origin.y) / (float) qdx.y << endl; + } + else if (src_rotated_origin.y >= src_qheight) + { + LOG << " y < height" << endl; + LOG << " y diff = " << src_rotated_origin.x - src_qwidth + 1 << endl; + LOG << " y coef = " << (float) (src_rotated_origin.x - src_qwidth + 1) / (float) (-qdx.x) << endl; + } + else + { + LOG << " in bounds" << endl; + } abort(); } + + padding_table[i] = rotated.width; } src_rotated_origin += qdy;