Add border pixels.

A border pixels is a pixel missing a neighbor.
This commit is contained in:
Fabien Freling 2014-08-05 22:36:48 +02:00
parent 085dc2861c
commit 57c5052908

View file

@ -265,6 +265,44 @@ void print_padding_table(uint16_t const* padding_table,
//
//
// Border
//
uint16_t* generate_border_table(uint16_t const* padding_table, int size)
{
uint16_t* border_table = new uint16_t[size];
border_table[0] = 0;
for (int i = 1; i < size - 1; ++i)
{
border_table[i] = max(1, abs(padding_table[i - 1] - padding_table[i]));
}
for (int i = size / 2; i < size - 1; ++i)
{
if (padding_table[i] + border_table[i]
+ border_table[size - 1 - i] + padding_table[size - 1 - i] > size)
{
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];
return border_table;
}
//
//
// Image rotation
@ -382,6 +420,7 @@ Image* rotate(Image const& src, double angle)
rot_origin_in_src.y * q_pos);
// Padding
uint16_t* padding_table = generate_padding_table(src, *rotated, rotation, q_pos);
uint16_t* border_table = generate_border_table(padding_table, rotated->height);
//print_padding_table(padding_table, border_table, height, true);
for (int y = 0; y < height; ++y)
@ -389,8 +428,10 @@ Image* rotate(Image const& src, double angle)
Point src_rotated_point = src_rotated_origin;
int const left_padding = padding_table[y];
int const left_border = border_table[y];
int const right_padding = padding_table[height - 1 - y];
int const core_pixels = width - left_padding - right_padding;
int const right_border = border_table[height - 1 - y];
int const core_pixels = height - left_padding - left_border - right_border - right_padding;
// Left padding
for (int x = 0; x < left_padding; ++x, ++buffer_index)
@ -400,6 +441,13 @@ Image* rotate(Image const& src, double angle)
src_rotated_point += qdx;
}
// Border
for (int x = 0; x < left_border; ++x, ++buffer_index)
{
buffer[buffer_index] = 0; // TODO: handle border
src_rotated_point += qdx;
}
// Body
for (int x = 0; x < core_pixels; ++x, ++buffer_index)
{
@ -415,6 +463,13 @@ Image* rotate(Image const& src, double angle)
src_rotated_point += qdx;
}
// Border
for (int x = 0; x < right_border; ++x, ++buffer_index)
{
buffer[buffer_index] = 0; // TODO: handle border
src_rotated_point += qdx;
}
// Right padding
for (int x = 0; x < right_padding; ++x, ++buffer_index)
{