Add check_90().

- Fix border.
master
Fabien Freling 2014-06-26 21:28:34 +02:00
parent b666b1b4a6
commit c0ed5f1be0
2 changed files with 40 additions and 6 deletions

View File

@ -1,2 +1,6 @@
[ ] Quaternions
[ ] Draw rotated pixels in src order
[-] Quaternions
[X] Draw rotated pixels in src order
[X] Use atan2 at beginning and end of line.
Interpolation in-between values
[X] Test pixel perfect 90
[ ] Optimization for square images?

View File

@ -517,13 +517,13 @@ Image rotate(Image const& src, double angle)
DPoint bresenham((tr.x - tl.x) / (float) line_nb_steps, (tr.y - tl.y) / (float) line_nb_steps);
cout << "bresenham: " << bresenham << endl;
for (int y_i = 0; y_i < (int) origin_nb_steps; ++y_i)
for (int y_i = 0; y_i <= (int) origin_nb_steps; ++y_i)
{
// first column origin
DPoint const src_origin(src_tl.x + y_i * origin_x_inc, src_tl.y + y_i * origin_y_inc);
APoint const rot_origin(tl.x + y_i * rotated_x_inc, tl.y + y_i * rotated_y_inc);
for (int x_i = 0; x_i < (int) line_nb_steps; ++x_i)
for (int x_i = 0; x_i <= (int) line_nb_steps; ++x_i)
{
DPoint const src_rotated_point(src_origin.x + x_i * line_x_inc, src_origin.y + x_i * line_y_inc);
APoint const rot_point(rot_origin.x + x_i * bresenham.x, rot_origin.y + x_i * bresenham.y);
@ -677,6 +677,30 @@ void check_lines()
draw_outline(rect1, 90, "rect1");
}
bool check_90()
{
Image const src("img/lena.ppm");
Image const rotated = rotate(src, 90);
for (unsigned int y = 0; y < rotated.height; ++y)
{
for (unsigned int x = 0; x < rotated.width; ++x)
{
unsigned rot_index = y * rotated.width + x;
unsigned src_index = x * src.width + (rotated.width - 1 - y);
if (rotated.r_chan[rot_index] != src.r_chan[src_index])
return false;
if (rotated.g_chan[rot_index] != src.g_chan[src_index])
return false;
if (rotated.b_chan[rot_index] != src.b_chan[src_index])
return false;
}
}
return true;
}
//
@ -697,11 +721,17 @@ int main()
return 1;
//check_lines();
if (!check_90())
{
cerr << __LINE__ << " | 90 degrees check failed" << endl;
return 1;
}
}
Image img("img/luigi.ppm");
//Image img("img/luigi.ppm");
//Image img("img/wallpaper.ppm");
// Image img("img/mini_luigi.ppm");
Image img("img/mini_lena.ppm");
//for (double rotation : {0, 1, 5, 15, 30, 45, 60, 75, 90, 110, 140, 160, 180, 200, 210, 235, 260, 270, 300, 315, 355, 359})
for (double rotation : {0, 45, 90})