Remove tiled image rotation.
This commit is contained in:
parent
8adf17510f
commit
210dff5c62
158
rotation.cpp
158
rotation.cpp
|
@ -634,135 +634,6 @@ Image* rotate(Image const& src, double angle)
|
|||
return rotated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Tile rotation
|
||||
//
|
||||
|
||||
template<unsigned int W, unsigned int H>
|
||||
void rotate_pixel(TiledImage<W, H> const& src,
|
||||
Point const& src_rotated_point,
|
||||
pvalue_t* rot_tile)
|
||||
{
|
||||
unsigned int const quantize = 8;
|
||||
|
||||
int const src_x = src_rotated_point.x >> 3;
|
||||
int const src_y = src_rotated_point.y >> 3;
|
||||
|
||||
pvalue_t const* src_index_1 = src.access_pixel(src_x, src_y);
|
||||
pvalue_t const* src_index_3 = src_index_1 + (W + 1) * src.pixel_size;
|
||||
|
||||
unsigned int x_delta = src_rotated_point.x & 0x07;;
|
||||
unsigned int y_delta = src_rotated_point.y & 0x07;
|
||||
unsigned int const inv_x = quantize - x_delta;
|
||||
unsigned int const inv_y = quantize - y_delta;
|
||||
|
||||
#ifndef SIMD
|
||||
|
||||
pvalue_t const* src_index_2 = src_index_1 + src.pixel_size;
|
||||
pvalue_t const* src_index_4 = src_index_3 + src.pixel_size;
|
||||
|
||||
rot_tile[0] = ((src_index_1[0] * inv_x + src_index_2[0] * x_delta) * inv_y
|
||||
+ (src_index_3[0] * inv_x + src_index_4[0] * x_delta) * y_delta) >> 6;
|
||||
rot_tile[1] = ((src_index_1[1] * inv_x + src_index_2[1] * x_delta) * inv_y
|
||||
+ (src_index_3[1] * inv_x + src_index_4[1] * x_delta) * y_delta) >> 6;
|
||||
rot_tile[2] = ((src_index_1[2] * inv_x + src_index_2[2] * x_delta) * inv_y
|
||||
+ (src_index_3[2] * inv_x + src_index_4[2] * x_delta) * y_delta) >> 6;
|
||||
|
||||
#else
|
||||
|
||||
// X-axis
|
||||
__m128i top = _mm_loadu_si128((__m128i*) src_index_1);
|
||||
__m128i bottom = _mm_loadu_si128((__m128i*) src_index_3);
|
||||
__m128i coef = _mm_set_epi16(x_delta, x_delta, x_delta, x_delta, inv_x, inv_x, inv_x, inv_x);
|
||||
top = _mm_mullo_epi16(top, coef);
|
||||
bottom = _mm_mullo_epi16(bottom, coef);
|
||||
|
||||
// Y-axis
|
||||
coef = _mm_set1_epi16(inv_y);
|
||||
top = _mm_mullo_epi16(top, coef);
|
||||
coef = _mm_set1_epi16(y_delta);
|
||||
bottom = _mm_mullo_epi16(bottom, coef);
|
||||
top = _mm_add_epi16(top, bottom);
|
||||
|
||||
top = _mm_srli_epi16(top, 6);
|
||||
|
||||
rot_tile[0] = _mm_extract_epi16(top, 0) + _mm_extract_epi16(top, 4);
|
||||
rot_tile[1] = _mm_extract_epi16(top, 1) + _mm_extract_epi16(top, 5);
|
||||
rot_tile[2] = _mm_extract_epi16(top, 2) + _mm_extract_epi16(top, 6);
|
||||
|
||||
#endif // ! SIMD
|
||||
}
|
||||
|
||||
template<unsigned int W, unsigned int H>
|
||||
TiledImage<W, H>*
|
||||
rotate(TiledImage<W, H> const& src, double angle)
|
||||
{
|
||||
double const rotation = (angle / 180.0f) * M_PI;
|
||||
unsigned int w = 0;
|
||||
unsigned int h = 0;
|
||||
compute_output_size(src, rotation, w, h);
|
||||
auto rotated = new TiledImage<W, H>(w, h);
|
||||
|
||||
DPoint src_origin = get_mapped_point(*rotated, Point(0, 0), -rotation);
|
||||
DPoint src_delta_x = get_mapped_point(*rotated, Point(1, 0), -rotation);
|
||||
DPoint src_delta_y = get_mapped_point(*rotated, Point(0, 1), -rotation);
|
||||
|
||||
src_delta_x.x = src_delta_x.x - src_origin.x;
|
||||
src_delta_x.y = src_delta_x.y - src_origin.y;
|
||||
round_if_very_small(src_delta_x.x);
|
||||
round_if_very_small(src_delta_x.y);
|
||||
src_delta_y.x = src_delta_y.x - src_origin.x;
|
||||
src_delta_y.y = src_delta_y.y - src_origin.y;
|
||||
round_if_very_small(src_delta_y.x);
|
||||
round_if_very_small(src_delta_y.y);
|
||||
|
||||
DPoint const rot_origin_in_src_grid = get_mapped_point(*rotated, Point(0, 0), -rotation);
|
||||
DPoint const rot_origin_in_src = convert_img_coord_precision(src, rot_origin_in_src_grid);
|
||||
|
||||
unsigned int const quantize = 8;
|
||||
int const& src_qwidth = src.width * quantize;
|
||||
int const& src_qheight = src.height * quantize;
|
||||
|
||||
for (unsigned int y = 0; y < rotated->nb_row_tile; ++y)
|
||||
{
|
||||
for (unsigned int x = 0; x < rotated->nb_col_tile; ++x)
|
||||
{
|
||||
unsigned int const rot_tile_index = y * rotated->nb_col_tile + x;
|
||||
pvalue_t* runner = rotated->get_tile(rot_tile_index);
|
||||
|
||||
for (unsigned int j = 0; j < H; ++j)
|
||||
{
|
||||
int const y_index = y * H + j;
|
||||
int x_index = x * W;
|
||||
DPoint const src_rotated_point((rot_origin_in_src.x + x_index * src_delta_x.x + y_index * src_delta_y.x) * quantize,
|
||||
(rot_origin_in_src.y + x_index * src_delta_x.y + y_index * src_delta_y.y) * quantize);
|
||||
|
||||
for (unsigned int i = 0; i < W; ++i)
|
||||
{
|
||||
Point const src_runner(src_rotated_point.x + i * src_delta_x.x * quantize,
|
||||
src_rotated_point.y + i * src_delta_x.y * quantize);
|
||||
|
||||
if (src_runner.x >= 0 && src_runner.x < src_qwidth
|
||||
&& src_runner.y >= 0 && src_runner.y < src_qheight)
|
||||
{
|
||||
rotate_pixel(src, src_runner, runner);
|
||||
}
|
||||
|
||||
runner += rotated->pixel_size;
|
||||
}
|
||||
|
||||
// Jump overlapping pixel
|
||||
runner += rotated->pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rotated->fill_overlap();
|
||||
|
||||
return rotated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
@ -982,7 +853,6 @@ int main(int argc, char* argv[])
|
|||
double const step = 5;
|
||||
bool save_output_img = true;
|
||||
bool print_each_run = true;
|
||||
bool test_tile = false;
|
||||
|
||||
// No tile
|
||||
Image img(argv[1]);
|
||||
|
@ -1008,33 +878,5 @@ int main(int argc, char* argv[])
|
|||
cout << "---------" << endl;
|
||||
cout << " average: " << average / i << "ms" << endl << endl;
|
||||
|
||||
// Tile
|
||||
if (test_tile)
|
||||
{
|
||||
TiledImage<32, 32> tiled_img(argv[1]);
|
||||
average = 0.0;
|
||||
i = 0;
|
||||
cout << "Tiled image" << endl;
|
||||
for (double rotation = 0; rotation < 360; rotation += step)
|
||||
{
|
||||
auto const before = chrono::high_resolution_clock::now();
|
||||
auto const rotated = rotate(tiled_img, rotation);
|
||||
auto const after = chrono::high_resolution_clock::now();
|
||||
auto const duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(after - before);
|
||||
average += duration_ms.count();
|
||||
|
||||
if (print_each_run)
|
||||
cout << "rotate tiled(" << rotation << "): " << duration_ms.count() << " ms" << endl;
|
||||
|
||||
if (save_output_img)
|
||||
rotated->save(get_save_path("rotated_tiled", rotation));
|
||||
|
||||
delete rotated;
|
||||
++i;
|
||||
}
|
||||
cout << "---------" << endl;
|
||||
cout << " average: " << average / i << "ms" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue