Merge left and right padding into one table.
This commit is contained in:
parent
242813ed41
commit
fd36a3bea6
133
rotation.cpp
133
rotation.cpp
|
@ -185,131 +185,45 @@ uint16_t* generate_padding_table(Image const& rotated,
|
|||
int src_qwidth, int src_qheight,
|
||||
int q_pos)
|
||||
{
|
||||
uint16_t* padding_table = new uint16_t[rotated.height];
|
||||
uint16_t* padding_table = new uint16_t[2 * rotated.height];
|
||||
|
||||
Point right_edge = src_rotated_origin;
|
||||
right_edge.x += (rotated.width - 1) * qdx.x;
|
||||
right_edge.y += (rotated.width - 1) * qdx.y;
|
||||
|
||||
for (unsigned int i = 0; i < rotated.height; ++i)
|
||||
{
|
||||
int x_range = get_iteration(src_rotated_origin.x, src_qwidth - q_pos, qdx.x);
|
||||
int y_range = get_iteration(src_rotated_origin.y, src_qheight - q_pos, qdx.y);
|
||||
|
||||
padding_table[i] = max(max(x_range, y_range), 0);
|
||||
padding_table[2 * i] = max(max(x_range, y_range), 0);
|
||||
|
||||
Point border(src_rotated_origin.x + padding_table[i] * qdx.x,
|
||||
src_rotated_origin.y + padding_table[i] * qdx.y);
|
||||
Point border(src_rotated_origin.x + padding_table[2 * i] * qdx.x,
|
||||
src_rotated_origin.y + padding_table[2 * i] * qdx.y);
|
||||
if (border.x < 0 || border.y < 0
|
||||
|| border.x >= src_qwidth || border.y >= src_qheight)
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
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.y - src_qheight + 1 << endl;
|
||||
LOG << " y coef = " << (float) (src_rotated_origin.y - src_qheight + 1) / (float) (-qdx.y) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG << " in bounds" << endl;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
padding_table[i] = rotated.width;
|
||||
padding_table[2 * i] = rotated.width;
|
||||
}
|
||||
|
||||
src_rotated_origin += qdy;
|
||||
}
|
||||
// Right padding
|
||||
x_range = get_iteration(right_edge.x, src_qwidth - q_pos, -qdx.x);
|
||||
y_range = get_iteration(right_edge.y, src_qheight - q_pos, -qdx.y);
|
||||
|
||||
return padding_table;
|
||||
}
|
||||
|
||||
uint16_t* generate_padding_table_back(Image const& rotated,
|
||||
Point src_rotated_origin,
|
||||
Point const& qdx, Point const& qdy,
|
||||
int src_qwidth, int src_qheight,
|
||||
int q_pos,
|
||||
uint16_t const* front_padding)
|
||||
{
|
||||
uint16_t* padding_table = new uint16_t[rotated.height];
|
||||
|
||||
src_rotated_origin.x += (rotated.width - 1) * qdx.x;
|
||||
src_rotated_origin.y += (rotated.width - 1) * qdx.y;
|
||||
|
||||
// This is actually a border
|
||||
padding_table[0] = rotated.width - front_padding[0];
|
||||
src_rotated_origin += qdy;
|
||||
padding_table[rotated.height - 1] = rotated.width - front_padding[rotated.height - 1];
|
||||
|
||||
for (unsigned int i = 1; i < rotated.height - 1; ++i)
|
||||
{
|
||||
int x_range = get_iteration(src_rotated_origin.x, src_qwidth - q_pos, -qdx.x);
|
||||
int y_range = get_iteration(src_rotated_origin.y, src_qheight - q_pos, -qdx.y);
|
||||
|
||||
padding_table[i] = max(max(x_range, y_range), 0);
|
||||
padding_table[i] = min((int) padding_table[i], (int) rotated.width - front_padding[i]);
|
||||
padding_table[2 * i + 1] = max(max(x_range, y_range), 0);
|
||||
padding_table[2 * i + 1] = min((int) padding_table[2 * i + 1], (int) rotated.width - padding_table[2 * i]);
|
||||
|
||||
src_rotated_origin += qdy;
|
||||
right_edge += qdy;
|
||||
}
|
||||
|
||||
// Right padding
|
||||
padding_table[1] = rotated.width - padding_table[0];
|
||||
padding_table[2 * (rotated.height - 1) + 1] = rotated.width - padding_table[2 * (rotated.height - 1)];
|
||||
|
||||
return padding_table;
|
||||
}
|
||||
|
||||
void print_padding_table(uint16_t const* padding_table,
|
||||
uint16_t const* border_table,
|
||||
Image const& image)
|
||||
{
|
||||
cout << "Padding table:" << endl;
|
||||
|
||||
for (unsigned int i = 0; i < image.height; ++i)
|
||||
{
|
||||
int left_padding = padding_table[i];
|
||||
int left_border = border_table[i];
|
||||
int right_padding = padding_table[image.height - 1 - i];
|
||||
int right_border = border_table[image.height - 1 - i];
|
||||
int core_pixels = image.width - left_padding - right_padding - left_border - right_border;
|
||||
|
||||
if (core_pixels < 0)
|
||||
{
|
||||
cout << "Too much padding + border at line " << i << endl;
|
||||
cout << " left padding = " << left_padding << endl;
|
||||
cout << " left border = " << left_border << endl;
|
||||
cout << " right border = " << right_border << endl;
|
||||
cout << " right padding = " << right_padding << endl;
|
||||
cout << " total = " << left_padding + left_border + right_border + right_padding << endl;
|
||||
cout << " width = " << image.width << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
cout << " " << i << " [";
|
||||
for (int j = 0; j < left_padding; ++j)
|
||||
cout << " ";
|
||||
for (int j = 0; j < left_border; ++j)
|
||||
cout << ".";
|
||||
for (int j = 0; j < core_pixels; ++j)
|
||||
cout << "x";
|
||||
for (int j = 0; j < right_border; ++j)
|
||||
cout << ".";
|
||||
for (int j = 0; j < right_padding; ++j)
|
||||
cout << " ";
|
||||
cout << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
@ -530,11 +444,6 @@ Image* rotate(Image const& src, double angle)
|
|||
qdx, qdy,
|
||||
src_qwidth, src_qheight,
|
||||
q_pos));
|
||||
unique_ptr<uint16_t[]> back_padding_table(generate_padding_table_back(*rotated, src_rotated_origin,
|
||||
qdx, qdy,
|
||||
src_qwidth, src_qheight,
|
||||
q_pos,
|
||||
padding_table.get()));
|
||||
// uint16_t* front_border = generate_border_table(padding_table, back_padding_table, *rotated);
|
||||
// uint16_t* back_border = generate_border_table_back(padding_table, front_border, back_padding_table, *rotated);
|
||||
|
||||
|
@ -542,10 +451,10 @@ Image* rotate(Image const& src, double angle)
|
|||
{
|
||||
|
||||
// TODO: compact these structure to increase locality
|
||||
int const left_padding = padding_table[y];
|
||||
int const left_padding = padding_table[2 * y];
|
||||
int const left_border = 0;
|
||||
int const right_border = 0;
|
||||
int const right_padding = back_padding_table[y];
|
||||
int const right_padding = padding_table[2 * y + 1];
|
||||
int const core_pixels = width - left_padding - left_border - right_border - right_padding;
|
||||
|
||||
if (core_pixels < 0)
|
||||
|
|
Loading…
Reference in a new issue