Patch border to have at least one pixel.
We check that we have a border of at least 1 pixel in 8-neighborhood.
This commit is contained in:
parent
7f1bd27ac0
commit
df00295cd1
44
rotation.cpp
44
rotation.cpp
|
@ -279,6 +279,7 @@ void print_padding_table(uint16_t const* padding_table,
|
||||||
//
|
//
|
||||||
// Border
|
// Border
|
||||||
//
|
//
|
||||||
|
|
||||||
uint16_t* generate_border_table(uint16_t const* padding_table, int size)
|
uint16_t* generate_border_table(uint16_t const* padding_table, int size)
|
||||||
{
|
{
|
||||||
uint16_t* border_table = new uint16_t[size];
|
uint16_t* border_table = new uint16_t[size];
|
||||||
|
@ -286,26 +287,31 @@ uint16_t* generate_border_table(uint16_t const* padding_table, int size)
|
||||||
|
|
||||||
for (int i = 1; i < size - 1; ++i)
|
for (int i = 1; i < size - 1; ++i)
|
||||||
{
|
{
|
||||||
border_table[i] = max(1, abs(padding_table[i - 1] - padding_table[i]));
|
if (padding_table[i - 1] > padding_table[i])
|
||||||
|
{
|
||||||
|
border_table[i] = padding_table[i - 1] - padding_table[i];
|
||||||
|
if (padding_table[i - 1] != padding_table[i])
|
||||||
|
border_table[i] += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
border_table[i] = 1;
|
||||||
|
if (padding_table[i - 1] != padding_table[i])
|
||||||
|
border_table[i - 1] += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = size / 2; i < size - 1; ++i)
|
// Check that we don't add too much border
|
||||||
|
for (int i = 1; i < size - 1; ++i)
|
||||||
{
|
{
|
||||||
if (padding_table[i] + border_table[i]
|
if (padding_table[i] + border_table[i]
|
||||||
+ border_table[size - 1 - i] + padding_table[size - 1 - i] > size)
|
+ padding_table[size - 1 - i] + border_table[size - 1 - i]
|
||||||
|
> size)
|
||||||
{
|
{
|
||||||
border_table[i] -= 1;
|
border_table[i] -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (padding_table[0] + padding_table[size - 1] > size)
|
|
||||||
{
|
|
||||||
cout << "Too many padding pixels." << endl;
|
|
||||||
cout << " padding_table[0] = " << padding_table[0] << endl;;
|
|
||||||
cout << " padding_table[size - 1] = " << padding_table[size - 1] << endl;;
|
|
||||||
cout << " size = " << size << endl;;
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
border_table[size - 1] = size - padding_table[0] - padding_table[size - 1];
|
border_table[size - 1] = size - padding_table[0] - padding_table[size - 1];
|
||||||
|
|
||||||
return border_table;
|
return border_table;
|
||||||
|
@ -419,9 +425,6 @@ Image* rotate(Image const& src, double angle)
|
||||||
unsigned int buffer_index = 0;
|
unsigned int buffer_index = 0;
|
||||||
pvalue_t* buffer = rotated->buffer;
|
pvalue_t* buffer = rotated->buffer;
|
||||||
|
|
||||||
int64_t const src_qwidth = (int64_t) src.width * q_pos;
|
|
||||||
int64_t const src_qheight = (int64_t) src.height * q_pos;
|
|
||||||
|
|
||||||
unsigned int const src_limit = src.width * src.height * src.pixel_size;
|
unsigned int const src_limit = src.width * src.height * src.pixel_size;
|
||||||
int const width = rotated->width;
|
int const width = rotated->width;
|
||||||
int const height = rotated->height;
|
int const height = rotated->height;
|
||||||
|
@ -437,11 +440,12 @@ Image* rotate(Image const& src, double angle)
|
||||||
{
|
{
|
||||||
Point src_rotated_point = src_rotated_origin;
|
Point src_rotated_point = src_rotated_origin;
|
||||||
|
|
||||||
|
// TODO: compact these structure to increase locality
|
||||||
int const left_padding = padding_table[y];
|
int const left_padding = padding_table[y];
|
||||||
int const left_border = border_table[y];
|
int const left_border = border_table[y];
|
||||||
int const right_padding = padding_table[height - 1 - y];
|
int const right_padding = padding_table[height - 1 - y];
|
||||||
int const right_border = border_table[height - 1 - y];
|
int const right_border = border_table[height - 1 - y];
|
||||||
int const core_pixels = height - left_padding - left_border - right_border - right_padding;
|
int const core_pixels = width - left_padding - left_border - right_border - right_padding;
|
||||||
|
|
||||||
// Left padding
|
// Left padding
|
||||||
for (int x = 0; x < left_padding; ++x, ++buffer_index)
|
for (int x = 0; x < left_padding; ++x, ++buffer_index)
|
||||||
|
@ -461,15 +465,7 @@ Image* rotate(Image const& src, double angle)
|
||||||
// Body
|
// Body
|
||||||
for (int x = 0; x < core_pixels; ++x, ++buffer_index)
|
for (int x = 0; x < core_pixels; ++x, ++buffer_index)
|
||||||
{
|
{
|
||||||
if (src_rotated_point.x >= 0 && src_rotated_point.x < src_qwidth
|
rotate_pixel(src, src_rotated_point, src_limit, buffer, buffer_index, q_pos_pow);
|
||||||
&& src_rotated_point.y >= 0 && src_rotated_point.y < src_qheight)
|
|
||||||
{
|
|
||||||
rotate_pixel(src, src_rotated_point,
|
|
||||||
src_limit,
|
|
||||||
buffer, buffer_index,
|
|
||||||
q_pos_pow);
|
|
||||||
}
|
|
||||||
|
|
||||||
src_rotated_point += qdx;
|
src_rotated_point += qdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue