|
Shinya Kitaoka |
120a6e |
#include <iostream> // std::cout</iostream>
|
|
Shinya Kitaoka |
120a6e |
#include <vector> // std::vector</vector>
|
|
Shinya Kitaoka |
120a6e |
#include <cmath> // cos(),sin(),sqrt()</cmath>
|
|
Shinya Kitaoka |
120a6e |
#include <limits> // std::numeric_limits<t></t></limits>
|
|
Shinya Kitaoka |
120a6e |
#include <stdexcept> // std::domain_error()</stdexcept>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_ifx_common.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_rotate_blur.h"
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
#include <qvector2d></qvector2d>
|
|
shun-iwasawa |
0e1837 |
#include <qtransform></qtransform>
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
enum Type { Accelerator = 0, Uniform_Angle, Uniform_Length };
|
|
shun-iwasawa |
0e1837 |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
shun-iwasawa |
0e1837 |
class Rotator {
|
|
shun-iwasawa |
0e1837 |
const float* in_top_;
|
|
shun-iwasawa |
0e1837 |
const int hh_;
|
|
shun-iwasawa |
0e1837 |
const int ww_;
|
|
shun-iwasawa |
0e1837 |
const int cc_;
|
|
shun-iwasawa |
0e1837 |
const TPointD center_;
|
|
shun-iwasawa |
0e1837 |
const bool antialias_sw_;
|
|
shun-iwasawa |
0e1837 |
const bool alpha_rendering_sw_;
|
|
shun-iwasawa |
0e1837 |
const double radian_;
|
|
shun-iwasawa |
0e1837 |
const double blur_radius_;
|
|
shun-iwasawa |
0e1837 |
const double spin_radius_;
|
|
shun-iwasawa |
0e1837 |
const int type_;
|
|
shun-iwasawa |
0e1837 |
const double ellipse_aspect_ratio_;
|
|
shun-iwasawa |
0e1837 |
const double ellipse_angle_;
|
|
shun-iwasawa |
0e1837 |
QTransform tr_, tr_inv_;
|
|
shun-iwasawa |
0e1837 |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
shun-iwasawa |
0e1837 |
Rotator(const float* in_top, const int height, const int width,
|
|
shun-iwasawa |
0e1837 |
const int channels, const TPointD center, const bool antialias_sw,
|
|
shun-iwasawa |
0e1837 |
const bool alpha_rendering_sw, const double radian,
|
|
shun-iwasawa |
0e1837 |
const double blur_radius, const double spin_radius, const int type,
|
|
shun-iwasawa |
0e1837 |
const double ellipse_aspect_ratio, const double ellipse_angle)
|
|
Shinya Kitaoka |
120a6e |
: in_top_(in_top)
|
|
Shinya Kitaoka |
120a6e |
, hh_(height)
|
|
Shinya Kitaoka |
120a6e |
, ww_(width)
|
|
Shinya Kitaoka |
120a6e |
, cc_(channels)
|
|
shun-iwasawa |
0e1837 |
, center_(center)
|
|
shun-iwasawa |
0e1837 |
, antialias_sw_(antialias_sw)
|
|
shun-iwasawa |
0e1837 |
, alpha_rendering_sw_(alpha_rendering_sw)
|
|
Shinya Kitaoka |
120a6e |
, radian_(radian)
|
|
Shinya Kitaoka |
120a6e |
, blur_radius_(blur_radius)
|
|
shun-iwasawa |
0e1837 |
, spin_radius_(spin_radius)
|
|
shun-iwasawa |
0e1837 |
, type_(type)
|
|
shun-iwasawa |
0e1837 |
, ellipse_aspect_ratio_(ellipse_aspect_ratio)
|
|
shun-iwasawa |
0e1837 |
, ellipse_angle_(ellipse_angle) {
|
|
shun-iwasawa |
0e1837 |
if (ellipse_aspect_ratio_ != 1.0) {
|
|
shun-iwasawa |
0e1837 |
double axis_x =
|
|
shun-iwasawa |
0e1837 |
2.0 * ellipse_aspect_ratio_ / (ellipse_aspect_ratio_ + 1.0);
|
|
shun-iwasawa |
0e1837 |
double axis_y = axis_x / ellipse_aspect_ratio_;
|
|
shun-iwasawa |
0e1837 |
tr_ = QTransform()
|
|
shun-iwasawa |
0e1837 |
.rotateRadians(this->ellipse_angle_)
|
|
shun-iwasawa |
0e1837 |
.scale(axis_x, axis_y);
|
|
shun-iwasawa |
0e1837 |
tr_inv_ = QTransform(tr_).inverted();
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
void pixel_value(const float* in_current_pixel, const int xx, const int yy,
|
|
shun-iwasawa |
0e1837 |
const bool isRGB, const double refVal, float* result_pixel) {
|
|
shun-iwasawa |
0e1837 |
auto in_pixel = [&](int x, int y) {
|
|
shun-iwasawa |
0e1837 |
/* clamp */
|
|
shun-iwasawa |
0e1837 |
x = (x < 0) ? 0 : ((this->ww_ <= x) ? this->ww_ - 1 : x);
|
|
shun-iwasawa |
0e1837 |
y = (y < 0) ? 0 : ((this->hh_ <= y) ? this->hh_ - 1 : y);
|
|
shun-iwasawa |
0e1837 |
return this->in_top_ + this->cc_ * y * this->ww_ + this->cc_ * x;
|
|
shun-iwasawa |
0e1837 |
};
|
|
shun-iwasawa |
0e1837 |
auto interp = [&](float v1, float v2, float r) {
|
|
shun-iwasawa |
0e1837 |
return v1 * (1.f - r) + v2 * r;
|
|
shun-iwasawa |
0e1837 |
};
|
|
shun-iwasawa |
0e1837 |
auto accum_interp_in_values = [&](QPointF pos, std::vector<float>& accumP,</float>
|
|
shun-iwasawa |
0e1837 |
int z1, int z2, float weight) {
|
|
shun-iwasawa |
0e1837 |
int xId = (int)std::floor(pos.x());
|
|
shun-iwasawa |
0e1837 |
float rx = pos.x() - (float)xId;
|
|
shun-iwasawa |
0e1837 |
int yId = (int)std::floor(pos.y());
|
|
shun-iwasawa |
0e1837 |
float ry = pos.y() - (float)yId;
|
|
shun-iwasawa |
0e1837 |
const float* p00 = in_pixel(xId, yId);
|
|
shun-iwasawa |
0e1837 |
const float* p01 = in_pixel(xId + 1, yId);
|
|
shun-iwasawa |
0e1837 |
const float* p10 = in_pixel(xId, yId + 1);
|
|
shun-iwasawa |
0e1837 |
const float* p11 = in_pixel(xId + 1, yId + 1);
|
|
shun-iwasawa |
0e1837 |
for (int zz = z1; zz <= z2; zz++) {
|
|
shun-iwasawa |
0e1837 |
accumP[zz] += weight * interp(interp(p00[zz], p01[zz], rx),
|
|
shun-iwasawa |
0e1837 |
interp(p10[zz], p11[zz], rx), ry);
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
};
|
|
shun-iwasawa |
0e1837 |
auto accum_in_values = [&](QPointF pos, std::vector<float>& accumP, int z1,</float>
|
|
shun-iwasawa |
0e1837 |
int z2, float weight) {
|
|
shun-iwasawa |
0e1837 |
int xId = (int)std::round(pos.x());
|
|
shun-iwasawa |
0e1837 |
int yId = (int)std::round(pos.y());
|
|
shun-iwasawa |
0e1837 |
const float* p = in_pixel(xId, yId);
|
|
shun-iwasawa |
0e1837 |
for (int zz = z1; zz <= z2; zz++) {
|
|
shun-iwasawa |
0e1837 |
accumP[zz] += weight * p[zz];
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
};
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
int c1, c2;
|
|
shun-iwasawa |
0e1837 |
if (isRGB) {
|
|
shun-iwasawa |
0e1837 |
#if defined RGBA_ORDER_OF_TOONZ6
|
|
shun-iwasawa |
0e1837 |
c1 = igs::image::rgba::blu;
|
|
shun-iwasawa |
0e1837 |
c2 = igs::image::rgba::red;
|
|
shun-iwasawa |
0e1837 |
#elif defined RGBA_ORDER_OF_OPENGL
|
|
shun-iwasawa |
0e1837 |
c1 = igs::image::rgba::red;
|
|
shun-iwasawa |
0e1837 |
c2 = igs::image::rgba::blu;
|
|
shun-iwasawa |
0e1837 |
#else
|
|
shun-iwasawa |
0e1837 |
Must be define / DRGBA_ORDER_OF_TOONZ6 or / DRGBA_ORDER_OF_OPENGL
|
|
shun-iwasawa |
0e1837 |
#endif
|
|
shun-iwasawa |
0e1837 |
} else {
|
|
shun-iwasawa |
0e1837 |
c1 = igs::image::rgba::alp;
|
|
shun-iwasawa |
0e1837 |
c2 = igs::image::rgba::alp;
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
const QPointF center(this->center_.x, this->center_.y);
|
|
shun-iwasawa |
185136 |
/* Pixel位置 */
|
|
shun-iwasawa |
185136 |
const QPointF p(static_cast<float>(xx), static_cast<float>(yy));</float></float>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* 中心からPixel位置へのベクトルと長さ */
|
|
shun-iwasawa |
0e1837 |
const QVector2D v(p - center);
|
|
shun-iwasawa |
0e1837 |
const float dist = v.length();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* 指定半径の範囲内なら何もしない */
|
|
shun-iwasawa |
0e1837 |
bool is_in_blur_radius = false;
|
|
shun-iwasawa |
0e1837 |
if (this->ellipse_aspect_ratio_ == 1.f) {
|
|
shun-iwasawa |
0e1837 |
is_in_blur_radius = (dist <= this->blur_radius_);
|
|
shun-iwasawa |
0e1837 |
} else {
|
|
shun-iwasawa |
0e1837 |
is_in_blur_radius =
|
|
shun-iwasawa |
0e1837 |
QVector2D(this->tr_inv_.map(v.toPointF())).lengthSquared() <=
|
|
shun-iwasawa |
0e1837 |
(this->blur_radius_ * this->blur_radius_);
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
if (is_in_blur_radius) {
|
|
shun-iwasawa |
0e1837 |
for (int c = c1; c <= c2; ++c) {
|
|
shun-iwasawa |
0e1837 |
result_pixel[c] = in_current_pixel[c];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* 積算値と積算回数 */
|
|
shun-iwasawa |
0e1837 |
std::vector<float> accum_val(this->cc_);</float>
|
|
shun-iwasawa |
0e1837 |
float accum_counter = 0.f; // TODO 重みづけを均一以外も選べるようにしたい
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* 参照画像による強弱付加 */
|
|
shun-iwasawa |
0e1837 |
float radian = this->radian_ * refVal; // TODO: it can be bidirectional..
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
if (type_ == Accelerator) { /* 外への強調 */
|
|
shun-iwasawa |
0e1837 |
radian *= (dist - this->blur_radius_) / this->spin_radius_;
|
|
shun-iwasawa |
0e1837 |
} else if (type_ == Uniform_Length &&
|
|
shun-iwasawa |
0e1837 |
dist > 0.) { // decrease radian so that the blur length becomes
|
|
shun-iwasawa |
0e1837 |
// the same along radius
|
|
shun-iwasawa |
0e1837 |
radian *= (this->spin_radius_ + this->blur_radius_) / dist;
|
|
shun-iwasawa |
0e1837 |
radian = std::min(radian, 2.f * (float)M_PI);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
// blur pixel length at the current pos
|
|
shun-iwasawa |
0e1837 |
float spin_length_half = dist * radian * 0.5f;
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
// sampling in both directions
|
|
shun-iwasawa |
0e1837 |
float sample_length = 0.f;
|
|
shun-iwasawa |
0e1837 |
while (sample_length < spin_length_half) {
|
|
shun-iwasawa |
0e1837 |
// compute weight
|
|
shun-iwasawa |
0e1837 |
float weight = 1.f;
|
|
shun-iwasawa |
0e1837 |
if (sample_length >= spin_length_half - 1.f) {
|
|
shun-iwasawa |
0e1837 |
if (antialias_sw_)
|
|
shun-iwasawa |
0e1837 |
weight = spin_length_half - sample_length;
|
|
shun-iwasawa |
0e1837 |
else
|
|
shun-iwasawa |
0e1837 |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
// advance to the next sample
|
|
shun-iwasawa |
0e1837 |
sample_length += weight;
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
// compute for both side
|
|
shun-iwasawa |
0e1837 |
float sample_radian = sample_length / dist;
|
|
shun-iwasawa |
0e1837 |
QPointF vrot1, vrot2;
|
|
shun-iwasawa |
0e1837 |
if (this->ellipse_aspect_ratio_ == 1.f) {
|
|
shun-iwasawa |
0e1837 |
float cos = std::cos(sample_radian);
|
|
shun-iwasawa |
0e1837 |
float sin = std::sin(sample_radian);
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
vrot1 = QPointF(cos * v.x() - sin * v.y(), sin * v.x() + cos * v.y());
|
|
shun-iwasawa |
0e1837 |
vrot2 = QPointF(cos * v.x() + sin * v.y(), -sin * v.x() + cos * v.y());
|
|
shun-iwasawa |
0e1837 |
} else {
|
|
shun-iwasawa |
0e1837 |
vrot1 =
|
|
shun-iwasawa |
0e1837 |
(this->tr_inv_ * QTransform(this->tr_).rotateRadians(sample_radian))
|
|
shun-iwasawa |
0e1837 |
.map(v.toPointF());
|
|
shun-iwasawa |
0e1837 |
vrot2 = (this->tr_inv_ *
|
|
shun-iwasawa |
0e1837 |
QTransform(this->tr_).rotateRadians(-sample_radian))
|
|
shun-iwasawa |
0e1837 |
.map(v.toPointF());
|
|
shun-iwasawa |
0e1837 |
}
|
|
shun-iwasawa |
0e1837 |
if (antialias_sw_) {
|
|
shun-iwasawa |
0e1837 |
accum_interp_in_values(vrot1 + center, accum_val, c1, c2, weight);
|
|
shun-iwasawa |
0e1837 |
accum_interp_in_values(vrot2 + center, accum_val, c1, c2, weight);
|
|
shun-iwasawa |
0e1837 |
} else {
|
|
shun-iwasawa |
0e1837 |
accum_in_values(vrot1 + center, accum_val, c1, c2, weight);
|
|
shun-iwasawa |
0e1837 |
accum_in_values(vrot2 + center, accum_val, c1, c2, weight);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
accum_counter += weight * 2.f;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
// sample the original pos
|
|
shun-iwasawa |
0e1837 |
if (antialias_sw_)
|
|
shun-iwasawa |
0e1837 |
accum_interp_in_values(p, accum_val, c1, c2, 1.f);
|
|
shun-iwasawa |
0e1837 |
else
|
|
shun-iwasawa |
0e1837 |
accum_in_values(p, accum_val, c1, c2, 1.f);
|
|
shun-iwasawa |
0e1837 |
accum_counter += 1.f;
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
//}
|
|
Shinya Kitaoka |
120a6e |
/* 積算しなかったとき(念のためのCheck) */
|
|
shun-iwasawa |
0e1837 |
if (accum_counter <= 0.f) {
|
|
shun-iwasawa |
0e1837 |
for (int c = c1; c <= c2; ++c) {
|
|
shun-iwasawa |
0e1837 |
result_pixel[c] = in_current_pixel[c];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* ここで画像Pixelに保存 */
|
|
shun-iwasawa |
0e1837 |
for (int c = c1; c <= c2; ++c) {
|
|
shun-iwasawa |
0e1837 |
accum_val[c] /= accum_counter;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
if (isRGB && !this->alpha_rendering_sw_ &&
|
|
shun-iwasawa |
0e1837 |
(in_current_pixel[c] < accum_val[c]) &&
|
|
shun-iwasawa |
0e1837 |
result_pixel[igs::image::rgba::alp] < 1.f) {
|
|
Shinya Kitaoka |
120a6e |
/* 増分のみMask! */
|
|
shun-iwasawa |
0e1837 |
result_pixel[c] =
|
|
shun-iwasawa |
0e1837 |
in_current_pixel[c] + (accum_val[c] - in_current_pixel[c]) *
|
|
shun-iwasawa |
0e1837 |
result_pixel[igs::image::rgba::alp];
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
shun-iwasawa |
0e1837 |
result_pixel[c] = accum_val[c];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
shun-iwasawa |
0e1837 |
// disable
|
|
shun-iwasawa |
0e1837 |
Rotator();
|
|
shun-iwasawa |
0e1837 |
Rotator(const Rotator&);
|
|
shun-iwasawa |
0e1837 |
Rotator& operator=(const Rotator&) {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
void rotate_convert(
|
|
shun-iwasawa |
0e1837 |
const float* in, float* out, const int margin, /* 参照画像(in)がもつ余白 */
|
|
shun-iwasawa |
0e1837 |
const TDimension out_dim, /* 求める画像(out)のサイズ */
|
|
shun-iwasawa |
0e1837 |
const int channels, const float* ref, /* 求める画像(out)と同じ高さ、幅 */
|
|
shun-iwasawa |
0e1837 |
const TPointD center, const double degree,
|
|
shun-iwasawa |
0e1837 |
const double blur_radius, /* ぼかしの始まる半径 */
|
|
shun-iwasawa |
0e1837 |
const double spin_radius, /* ゼロ以上でspin指定となり、
|
|
shun-iwasawa |
0e1837 |
かつぼかし強弱の一定になる半径となる */
|
|
shun-iwasawa |
0e1837 |
const int type, // 0: Accelerator, 1: Uniform Angle, 2: Uniform Length
|
|
shun-iwasawa |
0e1837 |
const bool antialias_sw, /* when true, sampled pixel will be
|
|
shun-iwasawa |
0e1837 |
bilinear-interpolated */
|
|
shun-iwasawa |
0e1837 |
const bool alpha_rendering_sw, const double ellipse_aspect_ratio,
|
|
shun-iwasawa |
0e1837 |
const double ellipse_angle) {
|
|
shun-iwasawa |
0e1837 |
assert(degree > 0.0);
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
Rotator rotator(in, out_dim.ly + margin * 2, out_dim.lx + margin * 2,
|
|
shun-iwasawa |
0e1837 |
channels, center, antialias_sw, alpha_rendering_sw,
|
|
shun-iwasawa |
0e1837 |
degree * M_PI_180, blur_radius, spin_radius, type,
|
|
shun-iwasawa |
0e1837 |
ellipse_aspect_ratio, ellipse_angle * M_PI_180);
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
const float* p_in =
|
|
shun-iwasawa |
0e1837 |
in + margin * (out_dim.lx + margin * 2) * channels + margin * channels;
|
|
shun-iwasawa |
0e1837 |
float* p_out = out;
|
|
shun-iwasawa |
0e1837 |
const float* p_ref = ref; // may be nullptr
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
for (int yy = margin; yy < out_dim.ly + margin;
|
|
shun-iwasawa |
0e1837 |
++yy, p_in += 2 * margin * channels) {
|
|
shun-iwasawa |
0e1837 |
for (int xx = margin; xx < out_dim.lx + margin;
|
|
shun-iwasawa |
0e1837 |
++xx, p_in += channels, p_out += channels) {
|
|
Shinya Kitaoka |
120a6e |
using namespace igs::image::rgba;
|
|
shun-iwasawa |
0e1837 |
float refVal = (ref) ? *p_ref : 1.f;
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
// if the reference value is zero
|
|
shun-iwasawa |
0e1837 |
if (refVal == 0.f) {
|
|
shun-iwasawa |
0e1837 |
for (int c = 0; c < channels; ++c) p_out[c] = p_in[c];
|
|
shun-iwasawa |
0e1837 |
p_ref++;
|
|
shun-iwasawa |
0e1837 |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
if (alpha_rendering_sw) { // blur alpha
|
|
shun-iwasawa |
0e1837 |
rotator.pixel_value(p_in, xx, yy, false, refVal, p_out);
|
|
shun-iwasawa |
0e1837 |
} else { // use the src alpha as-is
|
|
shun-iwasawa |
0e1837 |
p_out[alp] = p_in[alp];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
if (p_out[alp] == 0.f) {
|
|
shun-iwasawa |
0e1837 |
p_out[red] = p_in[red];
|
|
shun-iwasawa |
0e1837 |
p_out[gre] = p_in[gre];
|
|
shun-iwasawa |
0e1837 |
p_out[blu] = p_in[blu];
|
|
shun-iwasawa |
0e1837 |
if (ref) p_ref++;
|
|
shun-iwasawa |
0e1837 |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
// blur RGB channels
|
|
shun-iwasawa |
0e1837 |
rotator.pixel_value(p_in, xx, yy, true, refVal, p_out);
|
|
shun-iwasawa |
0e1837 |
|
|
shun-iwasawa |
0e1837 |
if (ref) p_ref++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun-iwasawa |
0e1837 |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
shun-iwasawa |
0e1837 |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void igs::rotate_blur::convert(
|
|
shun-iwasawa |
0e1837 |
const float* in, float* out, const int margin,
|
|
shun-iwasawa |
0e1837 |
const TDimension out_dim, /* 求める画像(out)の大きさ */
|
|
shun-iwasawa |
0e1837 |
const int channels, const float* ref, /* outと同じ高さ、幅 */
|
|
shun-iwasawa |
0e1837 |
const TPointD center, const double degree, /* ぼかしの回転角度 */
|
|
shun-iwasawa |
0e1837 |
const double blur_radius, /* ぼかしの始まる半径 */
|
|
shun-iwasawa |
0e1837 |
const double spin_radius, /* ゼロ以上でspin指定となり、
|
|
Shinya Kitaoka |
120a6e |
かつぼかし強弱の一定になる半径となる */
|
|
shun-iwasawa |
0e1837 |
const int type, // 0: Accelerator, 1: Uniform Angle, 2: Uniform Length
|
|
shun-iwasawa |
0e1837 |
const bool antialias_sw, /* when true, sampled pixel will be
|
|
shun-iwasawa |
0e1837 |
bilinear-interpolated */
|
|
shun-iwasawa |
0e1837 |
const bool alpha_rendering_sw, const double ellipse_aspect_ratio,
|
|
shun-iwasawa |
0e1837 |
const double ellipse_angle) {
|
|
shun-iwasawa |
0e1837 |
/* 強度のないとき */
|
|
shun-iwasawa |
0e1837 |
if (degree <= 0.0) {
|
|
shun-iwasawa |
0e1837 |
igs::image::copy_except_margin(in, margin, out, out_dim.ly, out_dim.lx,
|
|
shun-iwasawa |
0e1837 |
channels);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
rotate_convert(in, out, margin, out_dim, channels, ref, center, degree,
|
|
shun-iwasawa |
0e1837 |
blur_radius, spin_radius, type, antialias_sw,
|
|
shun-iwasawa |
0e1837 |
alpha_rendering_sw, ellipse_aspect_ratio, ellipse_angle);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
shun-iwasawa |
0e1837 |
double reference_margin_length_(const TPointD center, const double xp,
|
|
shun-iwasawa |
0e1837 |
const double yp, double radian,
|
|
Shinya Kitaoka |
120a6e |
const double blur_radius,
|
|
shun-iwasawa |
0e1837 |
const double spin_radius, const int type) {
|
|
shun-iwasawa |
0e1837 |
const QPointF c(center.x, center.y);
|
|
shun-iwasawa |
0e1837 |
const QPointF p(xp, yp);
|
|
shun-iwasawa |
0e1837 |
const QVector2D v(p - c);
|
|
shun-iwasawa |
0e1837 |
const float dist = v.length();
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
if (type == Accelerator) { /* 外への強調 */
|
|
Shinya Kitaoka |
120a6e |
radian *= (dist - blur_radius) / spin_radius;
|
|
shun-iwasawa |
0e1837 |
} else if (type == Uniform_Length &&
|
|
shun-iwasawa |
0e1837 |
dist > 0.) { // decrease radian so that the blur length becomes
|
|
shun-iwasawa |
0e1837 |
// the same along radius
|
|
shun-iwasawa |
0e1837 |
radian *= (spin_radius + blur_radius) / dist;
|
|
shun-iwasawa |
0e1837 |
radian = std::min(radian, 2. * M_PI);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
double cosval = cos(radian / 2.0);
|
|
shun-iwasawa |
0e1837 |
double sinval = sin(radian / 2.0);
|
|
shun-iwasawa |
0e1837 |
QPointF vrot1(v.x() * cosval - v.y() * sinval,
|
|
shun-iwasawa |
0e1837 |
v.x() * sinval + v.y() * cosval);
|
|
shun-iwasawa |
0e1837 |
QPointF vrot2(v.x() * cosval + v.y() * sinval,
|
|
shun-iwasawa |
0e1837 |
-v.x() * sinval + v.y() * cosval);
|
|
shun-iwasawa |
0e1837 |
float dist1 = QVector2D(vrot1 + c - p).length();
|
|
shun-iwasawa |
0e1837 |
float dist2 = QVector2D(vrot2 + c - p).length();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return (dist1 < dist2) ? dist2 : dist1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun-iwasawa |
0e1837 |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
int igs::rotate_blur::reference_margin(
|
|
shun-iwasawa |
0e1837 |
const int height, /* 求める画像(out)の高さ */
|
|
shun-iwasawa |
0e1837 |
const int width, /* 求める画像(out)の幅 */
|
|
shun-iwasawa |
0e1837 |
const TPointD center, const double degree, /* ぼかしの回転角度 */
|
|
shun-iwasawa |
0e1837 |
const double blur_radius, /* ぼかしの始まる半径 */
|
|
shun-iwasawa |
0e1837 |
const double spin_radius, /* ゼロ以上でspin指定となり、
|
|
Shinya Kitaoka |
120a6e |
かつぼかし強弱の一定になる半径となる */
|
|
shun-iwasawa |
3b3431 |
const int type, // 0: Accelerator, 1: Uniform Angle, 2: Uniform Length
|
|
shun-iwasawa |
3b3431 |
const double ellipse_aspect_ratio) {
|
|
shun-iwasawa |
0e1837 |
/* 強度のないとき、なにもしない */
|
|
shun-iwasawa |
0e1837 |
if (degree <= 0.0) {
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double margin1 = 0;
|
|
Shinya Kitaoka |
120a6e |
double margin2 = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double deg = degree;
|
|
Shinya Kitaoka |
120a6e |
if (180.0 < deg) {
|
|
Shinya Kitaoka |
120a6e |
deg = 180.0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
margin1 =
|
|
shun-iwasawa |
0e1837 |
reference_margin_length_(center, -width / 2.0, -height / 2.0,
|
|
shun-iwasawa |
0e1837 |
deg * M_PI_180, blur_radius, spin_radius, type);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
margin2 =
|
|
shun-iwasawa |
0e1837 |
reference_margin_length_(center, -width / 2.0, height / 2.0,
|
|
shun-iwasawa |
0e1837 |
deg * M_PI_180, blur_radius, spin_radius, type);
|
|
Shinya Kitaoka |
120a6e |
if (margin1 < margin2) {
|
|
Shinya Kitaoka |
120a6e |
margin1 = margin2;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
margin2 =
|
|
shun-iwasawa |
0e1837 |
reference_margin_length_(center, width / 2.0, -height / 2.0,
|
|
shun-iwasawa |
0e1837 |
deg * M_PI_180, blur_radius, spin_radius, type);
|
|
Shinya Kitaoka |
120a6e |
if (margin1 < margin2) {
|
|
Shinya Kitaoka |
120a6e |
margin1 = margin2;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
0e1837 |
margin2 =
|
|
shun-iwasawa |
0e1837 |
reference_margin_length_(center, width / 2.0, height / 2.0,
|
|
shun-iwasawa |
0e1837 |
deg * M_PI_180, blur_radius, spin_radius, type);
|
|
Shinya Kitaoka |
120a6e |
if (margin1 < margin2) {
|
|
Shinya Kitaoka |
120a6e |
margin1 = margin2;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
3b3431 |
// Consider ellipse deformation.
|
|
shun-iwasawa |
3b3431 |
// Instead of precise computing, return the maximum possible value.
|
|
shun-iwasawa |
3b3431 |
if (ellipse_aspect_ratio != 1.0) {
|
|
shun-iwasawa |
3b3431 |
double axis_x = 2.0 * ellipse_aspect_ratio / (ellipse_aspect_ratio + 1.0);
|
|
shun-iwasawa |
3b3431 |
double axis_y = axis_x / ellipse_aspect_ratio;
|
|
shun-iwasawa |
3b3431 |
margin1 *= std::max(axis_x, axis_y);
|
|
shun-iwasawa |
3b3431 |
}
|
|
shun-iwasawa |
3b3431 |
|
|
Shinya Kitaoka |
120a6e |
return static_cast<int>(ceil(margin1));</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|