Activate right padding.
This commit is contained in:
parent
723cd88d56
commit
bd84e85c1e
138
rotation.cpp
138
rotation.cpp
|
@ -164,6 +164,20 @@ bool fequal(float a, float b, float sigma)
|
|||
// 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,
|
||||
Point src_rotated_origin,
|
||||
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)
|
||||
{
|
||||
int y_range = 0;
|
||||
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));
|
||||
}
|
||||
int y_range = get_iteration(src_rotated_origin.y, src_qheight, qdx.y);
|
||||
if (y_range < 0)
|
||||
{
|
||||
cout << "Negative Y range" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
int x_range = 0;
|
||||
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));
|
||||
}
|
||||
int x_range = get_iteration(src_rotated_origin.x, src_qwidth, qdx.x);
|
||||
if (x_range < 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
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
|
||||
{
|
||||
|
@ -255,13 +253,13 @@ uint16_t* generate_padding_table(Image const& rotated,
|
|||
return padding_table;
|
||||
}
|
||||
|
||||
uint16_t* generate_padding_table_back_q(Image const& rotated,
|
||||
Point src_rotated_origin,
|
||||
Point const& qdx,
|
||||
Point const& qdy,
|
||||
int src_qwidth,
|
||||
int src_qheight,
|
||||
uint16_t const* front_padding)
|
||||
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,
|
||||
uint16_t const* front_padding)
|
||||
{
|
||||
uint16_t* padding_table = new uint16_t[rotated.height];
|
||||
// We suppose the image is square.
|
||||
|
@ -271,64 +269,27 @@ uint16_t* generate_padding_table_back_q(Image const& rotated,
|
|||
return padding_table;
|
||||
}
|
||||
|
||||
src_rotated_origin.x = (rotated.width - 1) * qdx.x;
|
||||
src_rotated_origin.y = (rotated.width - 1) * qdx.y;
|
||||
src_rotated_origin.x += (rotated.width - 1) * qdx.x;
|
||||
src_rotated_origin.y += (rotated.width - 1) * qdx.y;
|
||||
|
||||
for (unsigned int i = 0; i < rotated.height; ++i)
|
||||
{
|
||||
int y_range = 0;
|
||||
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));
|
||||
}
|
||||
int y_range = get_iteration(src_rotated_origin.y, src_qheight, -qdx.y);
|
||||
if (y_range < 0)
|
||||
{
|
||||
cout << "Negative back Y range at line " << i << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
int x_range = 0;
|
||||
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));
|
||||
}
|
||||
int x_range = get_iteration(src_rotated_origin.x, src_qwidth, -qdx.x);
|
||||
if (x_range < 0)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
padding_table[i] = max(x_range, y_range);
|
||||
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
padding_table[i] = min((int) padding_table[i], (int) rotated.width - front_padding[i]);
|
||||
|
||||
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];
|
||||
|
||||
if (border_table[image.height - 1] > image.width)
|
||||
{
|
||||
cout << "That shit cray" << endl;
|
||||
cout << " width = " << image.width << endl;
|
||||
cout << " left padding = " << padding_table[0] << endl;
|
||||
cout << " left border = " << border_table[0] << endl;
|
||||
cout << " right border = " << border_table[image.height - 1] << endl;
|
||||
cout << " right padding = " << padding_table[image.height - 1] << endl;
|
||||
cout << " ~ " << image.width << endl;
|
||||
cout << " ~ " << image.width - padding_table[0] << endl;
|
||||
cout << " ~ " << 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 << "That shit cray" << endl;
|
||||
LOG << " width = " << image.width << endl;
|
||||
LOG << " left padding = " << padding_table[0] << endl;
|
||||
LOG << " left border = " << border_table[0] << endl;
|
||||
LOG << " right border = " << border_table[image.height - 1] << endl;
|
||||
LOG << " right padding = " << padding_table[image.height - 1] << endl;
|
||||
LOG << " ~ width ~ " << image.width << endl;
|
||||
LOG << " ~ width - left padding ~ " << image.width - padding_table[0] << endl;
|
||||
LOG << " ~ width - padding ~ " << image.width - padding_table[0] - padding_table[image.height - 1] << endl;
|
||||
LOG << " ~ width - padding - left border ~ " << image.width - padding_table[0] - padding_table[image.height - 1] - border_table[0] << endl;
|
||||
}
|
||||
|
||||
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,
|
||||
qdx, qdy,
|
||||
src_qwidth, src_qheight);
|
||||
// uint16_t* back_padding_table = generate_padding_table_back_q(*rotated, src_rotated_origin,
|
||||
// qdx, qdy,
|
||||
// src_qwidth, src_qheight,
|
||||
// padding_table);
|
||||
uint16_t* back_padding_table = generate_padding_table_back(*rotated, src_rotated_origin,
|
||||
qdx, qdy,
|
||||
src_qwidth, src_qheight,
|
||||
padding_table);
|
||||
//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)
|
||||
{
|
||||
|
@ -589,7 +551,7 @@ Image* rotate(Image const& src, double angle)
|
|||
int const left_padding = padding_table[y];
|
||||
int const left_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;
|
||||
|
||||
if (false)
|
||||
|
@ -607,7 +569,7 @@ Image* rotate(Image const& src, double angle)
|
|||
// Border
|
||||
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,
|
||||
|
@ -646,7 +608,7 @@ Image* rotate(Image const& src, double angle)
|
|||
// Border
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue