tahoma2d/toonz/sources/stdfx/igs_warp_vert.cpp

90 lines
3.2 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include <cmath>
#include <vector>
#include <limits> /* std::numeric_limits */
#include "igs_ifx_common.h"
#include "igs_warp.h"
2016-06-15 18:43:10 +12:00
namespace {
void vert_change_(float* image, const int height, const int width,
const int channels,
const float* refer, // same as height,width,channels
const int refchannels, const int refcc, const double maxlen,
const bool alpha_rendering_sw, const bool anti_aliasing_sw) {
std::vector<std::vector<float>> buf_s1(channels);
2016-06-15 18:43:10 +12:00
for (int zz = 0; zz < channels; ++zz) {
buf_s1.at(zz).resize(height);
}
std::vector<float> buf_r(height);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
refer += refcc; /* 参照画像の参照色チャンネル */
for (int xx = 0; xx < width; ++xx, image += channels, refer += refchannels) {
for (int yy = 0; yy < height; ++yy) {
for (int zz = 0; zz < channels; ++zz) {
buf_s1.at(zz).at(yy) = image[yy * width * channels + zz];
2016-06-15 18:43:10 +12:00
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (int yy = 0; yy < height; ++yy) { // reference red of refer[]
float pos = refer[yy * width * refchannels];
buf_r.at(yy) = (pos - 0.5f) * maxlen;
2016-06-15 18:43:10 +12:00
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (anti_aliasing_sw) {
for (int yy = 0; yy < height; ++yy) {
double pos = buf_r.at(yy);
int fl_pos = yy + static_cast<int>(std::floor(pos));
int ce_pos = yy + static_cast<int>(std::ceil(pos));
float div = pos - floor(pos);
// clamp
if (fl_pos < 0)
2016-06-15 18:43:10 +12:00
fl_pos = 0;
else if (height <= fl_pos)
2016-06-15 18:43:10 +12:00
fl_pos = height - 1;
if (ce_pos < 0)
2016-06-15 18:43:10 +12:00
ce_pos = 0;
else if (height <= ce_pos)
2016-06-15 18:43:10 +12:00
ce_pos = height - 1;
2016-06-15 18:43:10 +12:00
for (int zz = 0; zz < channels; ++zz) {
if (!alpha_rendering_sw && (igs::image::rgba::alp == zz)) {
image[yy * width * channels + zz] = buf_s1.at(zz).at(yy);
2016-06-15 18:43:10 +12:00
} else {
image[yy * width * channels + zz] =
buf_s1.at(zz).at(fl_pos) * (1.0 - div) +
buf_s1.at(zz).at(ce_pos) * div;
2016-06-15 18:43:10 +12:00
}
}
}
} else {
for (int yy = 0; yy < height; ++yy) {
int pos = yy + static_cast<int>(floor(buf_r.at(yy) + 0.5));
// clamp
if (pos < 0)
2016-06-15 18:43:10 +12:00
pos = 0;
else if (height <= pos)
2016-06-15 18:43:10 +12:00
pos = height - 1;
2016-06-15 18:43:10 +12:00
for (int zz = 0; zz < channels; ++zz) {
if (!alpha_rendering_sw && (igs::image::rgba::alp == zz)) {
image[yy * width * channels + zz] = buf_s1.at(zz).at(yy);
2016-06-15 18:43:10 +12:00
} else {
image[yy * width * channels + zz] = buf_s1.at(zz).at(pos);
2016-06-15 18:43:10 +12:00
}
}
}
}
}
2016-03-19 06:57:51 +13:00
}
} // namespace
2016-03-19 06:57:51 +13:00
//--------------------------------------------------------------------
void igs::warp::vert_change(float* image, const int height, const int width,
const int channels,
const float* refer, // by height,width,channels
const int refchannels, const int refcc,
const double maxlen, const bool alpha_rendering_sw,
const bool anti_aliasing_sw) {
vert_change_(image, height, width, channels, refer, refchannels, refcc,
maxlen, alpha_rendering_sw, anti_aliasing_sw);
2016-03-19 06:57:51 +13:00
}