Activate right padding.

This commit is contained in:
Fabien Freling 2014-08-07 00:31:03 +02:00
parent 723cd88d56
commit bd84e85c1e

View file

@ -164,6 +164,20 @@ bool fequal(float a, float b, float sigma)
// Padding // Padding
// //
int get_iteration(int distance, int upper_bound, int step)
{
if (distance < 0)
{
return ceil((float) -distance / (float) step);
}
else if (distance >= upper_bound)
{
return ceil((float) (distance - upper_bound + 1) / (float) (-step));
}
return 0;
}
uint16_t* generate_padding_table(Image const& rotated, uint16_t* generate_padding_table(Image const& rotated,
Point src_rotated_origin, Point src_rotated_origin,
Point const& qdx, Point const& qdy, Point const& qdx, Point const& qdy,
@ -179,30 +193,14 @@ uint16_t* generate_padding_table(Image const& rotated,
for (unsigned int i = 0; i < rotated.height; ++i) for (unsigned int i = 0; i < rotated.height; ++i)
{ {
int y_range = 0; int y_range = get_iteration(src_rotated_origin.y, src_qheight, qdx.y);
if (src_rotated_origin.y < 0)
{
y_range = ceil((-src_rotated_origin.y) / (float) qdx.y);
}
else if (src_rotated_origin.y >= src_qheight)
{
y_range = ceil((float) (src_rotated_origin.y - src_qheight + 1) / (float) (-qdx.y));
}
if (y_range < 0) if (y_range < 0)
{ {
cout << "Negative Y range" << endl; cout << "Negative Y range" << endl;
abort(); abort();
} }
int x_range = 0; int x_range = get_iteration(src_rotated_origin.x, src_qwidth, qdx.x);
if (src_rotated_origin.x < 0)
{
x_range = ceil((-src_rotated_origin.x) / (float) qdx.x);
}
else if (src_rotated_origin.x >= src_qwidth)
{
x_range = ceil((float) (src_rotated_origin.x - src_qwidth + 1) / (float) (-qdx.x));
}
if (x_range < 0) if (x_range < 0)
{ {
cout << "Negative X range" << endl; cout << "Negative X range" << endl;
@ -235,9 +233,9 @@ uint16_t* generate_padding_table(Image const& rotated,
} }
else if (src_rotated_origin.y >= src_qheight) else if (src_rotated_origin.y >= src_qheight)
{ {
LOG << " y < height" << endl; LOG << " y >= height" << endl;
LOG << " y diff = " << src_rotated_origin.x - src_qwidth + 1 << endl; LOG << " y diff = " << src_rotated_origin.y - src_qheight + 1 << endl;
LOG << " y coef = " << (float) (src_rotated_origin.x - src_qwidth + 1) / (float) (-qdx.x) << endl; LOG << " y coef = " << (float) (src_rotated_origin.y - src_qheight + 1) / (float) (-qdx.y) << endl;
} }
else else
{ {
@ -255,7 +253,7 @@ uint16_t* generate_padding_table(Image const& rotated,
return padding_table; return padding_table;
} }
uint16_t* generate_padding_table_back_q(Image const& rotated, uint16_t* generate_padding_table_back(Image const& rotated,
Point src_rotated_origin, Point src_rotated_origin,
Point const& qdx, Point const& qdx,
Point const& qdy, Point const& qdy,
@ -271,64 +269,27 @@ uint16_t* generate_padding_table_back_q(Image const& rotated,
return padding_table; return padding_table;
} }
src_rotated_origin.x = (rotated.width - 1) * qdx.x; src_rotated_origin.x += (rotated.width - 1) * qdx.x;
src_rotated_origin.y = (rotated.width - 1) * qdx.y; src_rotated_origin.y += (rotated.width - 1) * qdx.y;
for (unsigned int i = 0; i < rotated.height; ++i) for (unsigned int i = 0; i < rotated.height; ++i)
{ {
int y_range = 0; int y_range = get_iteration(src_rotated_origin.y, src_qheight, -qdx.y);
if (src_rotated_origin.y < 0)
{
y_range = ceil((-src_rotated_origin.y) / (float) qdx.y);
}
else if (src_rotated_origin.y >= src_qheight)
{
y_range = ceil((float) (src_rotated_origin.y - src_qheight + 1) / (float) (qdx.y));
}
if (y_range < 0) if (y_range < 0)
{ {
cout << "Negative back Y range at line " << i << endl; cout << "Negative back Y range at line " << i << endl;
abort(); abort();
} }
int x_range = 0; int x_range = get_iteration(src_rotated_origin.x, src_qwidth, -qdx.x);
if (src_rotated_origin.x < 0)
{
x_range = ceil((-src_rotated_origin.x) / (float) qdx.x);
}
else if (src_rotated_origin.x >= src_qwidth)
{
x_range = ceil((float) (src_rotated_origin.x - src_qwidth + 1) / abs(qdx.x));
}
if (x_range < 0) if (x_range < 0)
{ {
cout << "Negative back X range at line " << i << endl; cout << "Negative back X range at line " << i << endl;
cout << " src origin: " << src_rotated_origin << endl;
cout << " q dim: " << src_qwidth << " x " << src_qheight << endl;
abort(); abort();
} }
padding_table[i] = max(x_range, y_range); padding_table[i] = max(x_range, y_range);
padding_table[i] = min((int) padding_table[i], (int) rotated.width - front_padding[i]);
{
Point test(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)
{
padding_table[i] = rotated.width - front_padding[i];
// cout << "Back padding issue at line " << i << endl;
// cout << " src origin: " << 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 range " << x_range << endl;
// cout << " Y range " << y_range << endl;
// cout << " height diff = " << src_rotated_origin.y - src_qheight + 1 << endl;
// cout << " coef = " << (float) (src_rotated_origin.y - src_qheight + 1) / (float) qdx.y << endl;
// abort();
}
}
src_rotated_origin += qdy; src_rotated_origin += qdy;
} }
@ -433,18 +394,19 @@ uint16_t* generate_border_table(uint16_t const* padding_table, Image const& imag
} }
border_table[image.height - 1] = image.width - padding_table[0] - padding_table[image.height - 1] - border_table[0]; border_table[image.height - 1] = image.width - padding_table[0] - padding_table[image.height - 1] - border_table[0];
if (border_table[image.height - 1] > image.width) if (border_table[image.height - 1] > image.width)
{ {
cout << "That shit cray" << endl; LOG << "That shit cray" << endl;
cout << " width = " << image.width << endl; LOG << " width = " << image.width << endl;
cout << " left padding = " << padding_table[0] << endl; LOG << " left padding = " << padding_table[0] << endl;
cout << " left border = " << border_table[0] << endl; LOG << " left border = " << border_table[0] << endl;
cout << " right border = " << border_table[image.height - 1] << endl; LOG << " right border = " << border_table[image.height - 1] << endl;
cout << " right padding = " << padding_table[image.height - 1] << endl; LOG << " right padding = " << padding_table[image.height - 1] << endl;
cout << " ~ " << image.width << endl; LOG << " ~ width ~ " << image.width << endl;
cout << " ~ " << image.width - padding_table[0] << endl; LOG << " ~ width - left padding ~ " << image.width - padding_table[0] << endl;
cout << " ~ " << image.width - padding_table[0] - padding_table[image.height - 1] << endl; LOG << " ~ width - padding ~ " << image.width - padding_table[0] - padding_table[image.height - 1] << endl;
cout << " ~ " << image.width - padding_table[0] - padding_table[image.height - 1] - border_table[0] << endl; LOG << " ~ width - padding - left border ~ " << image.width - padding_table[0] - padding_table[image.height - 1] - border_table[0] << endl;
} }
return border_table; return border_table;
@ -575,12 +537,12 @@ Image* rotate(Image const& src, double angle)
uint16_t* padding_table = generate_padding_table(*rotated, src_rotated_origin, uint16_t* padding_table = generate_padding_table(*rotated, src_rotated_origin,
qdx, qdy, qdx, qdy,
src_qwidth, src_qheight); src_qwidth, src_qheight);
// uint16_t* back_padding_table = generate_padding_table_back_q(*rotated, src_rotated_origin, uint16_t* back_padding_table = generate_padding_table_back(*rotated, src_rotated_origin,
// qdx, qdy, qdx, qdy,
// src_qwidth, src_qheight, src_qwidth, src_qheight,
// padding_table); padding_table);
//uint16_t* border_table = generate_border_table(padding_table, *rotated); //uint16_t* border_table = generate_border_table(padding_table, *rotated);
//print_padding_table(padding_table, border_table, *rotated);
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
@ -589,7 +551,7 @@ Image* rotate(Image const& src, double angle)
int const left_padding = padding_table[y]; int const left_padding = padding_table[y];
int const left_border = 0; int const left_border = 0;
int const right_border = 0; int const right_border = 0;
int const right_padding = min((int) padding_table[height - 1 - y], (int) width - left_padding); int const right_padding = back_padding_table[y];
int const core_pixels = width - left_padding - left_border - right_border - right_padding; int const core_pixels = width - left_padding - left_border - right_border - right_padding;
if (false) if (false)
@ -607,7 +569,7 @@ Image* rotate(Image const& src, double angle)
// Border // Border
for (int x = 0; x < left_border; ++x, ++buffer_index) for (int x = 0; x < left_border; ++x, ++buffer_index)
{ {
buffer[buffer_index] = 0; // TODO: handle border buffer[buffer_index] = 70; // TODO: handle border
} }
Point src_rotated_point(src_rotated_origin.x + (left_padding + left_border) * qdx.x, Point src_rotated_point(src_rotated_origin.x + (left_padding + left_border) * qdx.x,
@ -646,7 +608,7 @@ Image* rotate(Image const& src, double angle)
// Border // Border
for (int x = 0; x < right_border; ++x, ++buffer_index) for (int x = 0; x < right_border; ++x, ++buffer_index)
{ {
buffer[buffer_index] = 0; // TODO: handle border buffer[buffer_index] = 80; // TODO: handle border
src_rotated_point += qdx; src_rotated_point += qdx;
} }