Factorize the computation of the source point.
This commit is contained in:
parent
7e33e85909
commit
e86dbe0f36
25
rotation.cpp
25
rotation.cpp
|
@ -761,16 +761,10 @@ void rotate_pixel(TiledImage<W, H> const& src, TiledImage<W, H>& rotated,
|
|||
// special case if we can directly map the src to the dest
|
||||
if (x_delta == 0 && y_delta == 0)
|
||||
{
|
||||
// cout << "we can directly map, w00t" << endl;
|
||||
uint8_t* rot_tile = rotated.tiles[rot_tile_index];
|
||||
memcpy(&rot_tile[rot_index], src_index_1, 3 * sizeof (uint8_t));
|
||||
return;
|
||||
}
|
||||
// cout << "src rotated point: " << src_rotated_point << endl;
|
||||
// cout << "src rotated point y: " << src_rotated_point.y << endl;
|
||||
// cout << "src rotated point y int: " << (int) src_rotated_point.y << endl;
|
||||
// cout << "x delta = " << x_delta << endl;
|
||||
// cout << "y delta = " << y_delta << endl;
|
||||
|
||||
uint8_t const* src_index_2 = src.access_pixel((int) src_rotated_point.x + 1, (int) src_rotated_point.y);
|
||||
uint8_t const* src_index_3 = src.access_pixel((int) src_rotated_point.x, (int) src_rotated_point.y + 1);
|
||||
|
@ -842,18 +836,14 @@ TiledImage<W, H> rotate(TiledImage<W, H> const& src, double angle)
|
|||
for (unsigned int j = 0; j < H; ++j)
|
||||
{
|
||||
int const y_index = y * H + j;
|
||||
int x_index = x * W;
|
||||
DPoint src_rotated_point(rot_origin_in_src.x + x_index * src_delta_x.x + y_index * src_delta_y.x,
|
||||
rot_origin_in_src.y + x_index * src_delta_x.y + y_index * src_delta_y.y);
|
||||
|
||||
for (unsigned int i = 0; i < W; ++i)
|
||||
for (unsigned int i = 0; i < W; ++i, ++x_index)
|
||||
{
|
||||
// cout << "rotated: tile[" << x << ", " << y << "] point(" << i << ", " << j << ")" << endl;
|
||||
unsigned int const rot_index = (j * W + i) * 3;
|
||||
int const x_index = x * W + i;
|
||||
Point const rot_point(x_index, y_index);
|
||||
DPoint src_rotated_point(rot_origin_in_src.x + x_index * src_delta_x.x + y_index * src_delta_y.x,
|
||||
rot_origin_in_src.y + x_index * src_delta_x.y + y_index * src_delta_y.y);
|
||||
|
||||
// cout << "rotated tile index: " << rot_tile_index << endl;
|
||||
// cout << "src point: " << src_rotated_point << endl;
|
||||
|
||||
if (src_rotated_point.x < 0 || src_rotated_point.x > src.width
|
||||
|| src_rotated_point.y < 0 || src_rotated_point.y > src.height)
|
||||
|
@ -863,6 +853,9 @@ TiledImage<W, H> rotate(TiledImage<W, H> const& src, double angle)
|
|||
src_rotated_point,
|
||||
rot_tile_index, rot_index);
|
||||
|
||||
src_rotated_point.x += src_delta_x.x;
|
||||
src_rotated_point.y += src_delta_x.y;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1036,9 +1029,9 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
Image img(argv[1]);
|
||||
TiledImage<16, 16> tiled_img(argv[1]);
|
||||
TiledImage<32, 32> tiled_img(argv[1]);
|
||||
|
||||
for (double rotation = 0; rotation < 360; rotation += 450)
|
||||
for (double rotation = 0; rotation < 360; rotation += 45)
|
||||
{
|
||||
// No tile
|
||||
auto const before = chrono::high_resolution_clock::now();
|
||||
|
|
Loading…
Reference in a new issue