|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tropcm.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline double gauss(double x, double y, double x0, double y0, double s) {
|
|
Shinya Kitaoka |
120a6e |
return exp(-((x - x0) * (x - x0) + (y - y0) * (y - y0)) / s) / (s * M_PI);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double integ_gauss(double xmin, double ymin, double xmax, double ymax,
|
|
Shinya Kitaoka |
120a6e |
double x0, double y0, double s) {
|
|
Shinya Kitaoka |
120a6e |
int i, j, n;
|
|
Shinya Kitaoka |
120a6e |
double x1, y1, x2, y2, xstep, ystep, area;
|
|
Shinya Kitaoka |
120a6e |
double sum;
|
|
Shinya Kitaoka |
120a6e |
n = 50;
|
|
Shinya Kitaoka |
120a6e |
sum = 0;
|
|
Shinya Kitaoka |
120a6e |
xstep = (xmax - xmin) / n;
|
|
Shinya Kitaoka |
120a6e |
ystep = (ymax - ymin) / n;
|
|
Shinya Kitaoka |
120a6e |
area = xstep * ystep;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < n; i++)
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < n; j++) {
|
|
Shinya Kitaoka |
120a6e |
x1 = xmin + xstep * i;
|
|
Shinya Kitaoka |
120a6e |
y1 = ymin + ystep * i;
|
|
Shinya Kitaoka |
120a6e |
x2 = x1 + xstep;
|
|
Shinya Kitaoka |
120a6e |
y2 = y1 + ystep;
|
|
Shinya Kitaoka |
120a6e |
sum += area * (gauss(x1, y1, x0, y0, s) + gauss(x1, y2, x0, y0, s) +
|
|
Shinya Kitaoka |
120a6e |
gauss(x2, y2, x0, y0, s) + gauss(x2, y1, x0, y0, s)) /
|
|
Shinya Kitaoka |
120a6e |
4;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return sum;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void build_filter(double h[], double x0, double y0, double s) {
|
|
Shinya Kitaoka |
120a6e |
double sum, vv;
|
|
Shinya Kitaoka |
120a6e |
int i, j, k;
|
|
Shinya Kitaoka |
120a6e |
double x1, y1, x2, y2;
|
|
Shinya Kitaoka |
120a6e |
k = 0;
|
|
Shinya Kitaoka |
120a6e |
sum = 0.0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 3; i++)
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < 3; j++) {
|
|
Shinya Kitaoka |
120a6e |
x1 = -1.5 + j;
|
|
Shinya Kitaoka |
120a6e |
y1 = -1.5 + i;
|
|
Shinya Kitaoka |
120a6e |
x2 = x1 + 1.0;
|
|
Shinya Kitaoka |
120a6e |
y2 = y1 + 1.0;
|
|
Shinya Kitaoka |
120a6e |
h[k++] = vv = integ_gauss(x1, y1, x2, y2, x0, y0, s);
|
|
Shinya Kitaoka |
120a6e |
sum += vv;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (sum > 0.0) {
|
|
Shinya Kitaoka |
120a6e |
sum = 1.0 / sum;
|
|
Shinya Kitaoka |
120a6e |
for (k = 0; k < 9; k++) h[k] *= sum;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // anonymous namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::fracmove(TRasterP rout, TRasterP rin, double dx, double dy) {
|
|
Shinya Kitaoka |
120a6e |
// Using a bilinear filter is best - consider that only 4 pixels should
|
|
Shinya Kitaoka |
120a6e |
// contribute
|
|
Shinya Kitaoka |
120a6e |
// to a fractionarily shifted one, with weights proportional to the
|
|
Shinya Kitaoka |
120a6e |
// intersection areas.
|
|
Shinya Kitaoka |
120a6e |
double w[4] = {1, 0, 0, 0};
|
|
Shinya Kitaoka |
120a6e |
double sum = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int idx = tfloor(dx);
|
|
Shinya Kitaoka |
120a6e |
int idy = tfloor(dy);
|
|
Shinya Kitaoka |
120a6e |
double fracX = dx - idx;
|
|
Shinya Kitaoka |
120a6e |
double fracY = dy - idy;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int i, j;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 2; ++i)
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < 2; ++j)
|
|
Shinya Kitaoka |
120a6e |
sum += w[j + 2 * i] = fabs(fracX - j) * fabs(fracY - i);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 4; ++i) w[i] /= sum;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRop::convolve_i(rout, rin, idx, idy, w, 2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::fracmove(TRasterP rout, TRasterCM32P rin, const TPaletteP &palette,
|
|
Shinya Kitaoka |
120a6e |
double dx, double dy) {
|
|
Shinya Kitaoka |
120a6e |
double w[4] = {1, 0, 0, 0};
|
|
Shinya Kitaoka |
120a6e |
double sum = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int idx = tfloor(dx);
|
|
Shinya Kitaoka |
120a6e |
int idy = tfloor(dy);
|
|
Shinya Kitaoka |
120a6e |
double fracX = dx - idx;
|
|
Shinya Kitaoka |
120a6e |
double fracY = dy - idy;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int i, j;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 2; ++i)
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < 2; ++j)
|
|
Shinya Kitaoka |
120a6e |
sum += w[j + 2 * i] = fabs(fracX - j) * fabs(fracY - i);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 4; ++i) w[i] /= sum;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRop::convolve_i(rout, rin, idx, idy, w, 2);
|
|
Toshihiro Shimizu |
890ddd |
}
|