tahoma2d/toonz/sources/stdfx/warp.h

82 lines
2.2 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef WARP_H
#define WARP_H
#include "tfxparam.h"
#include "trop.h"
#include "trasterfx.h"
//-----------------------------------------------------------------------
struct WarpParams {
2016-06-15 18:43:10 +12:00
int m_shrink;
double m_warperScale;
double m_intensity;
bool m_sharpen;
2016-03-19 06:57:51 +13:00
};
struct LPoint {
2016-06-15 18:43:10 +12:00
TPointD s; // Warped lattice point
TPointD d; // Original lattice point
2016-03-19 06:57:51 +13:00
};
struct Lattice {
2016-06-15 18:43:10 +12:00
int m_width; // Number of lattice columns
int m_height; // Number of lattice rows
LPoint *coords; // Grid vertex coordinates
Lattice() : coords(0) {}
~Lattice() {
if (coords) delete[] coords;
}
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
namespace // Ugly...
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
inline int myCeil(double x) {
return ((x - (int)(x)) > TConsts::epsilon ? (int)(x) + 1 : (int)(x));
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
inline TRect convert(const TRectD &r, TPointD &dp) {
TRect ri(tfloor(r.x0), tfloor(r.y0), myCeil(r.x1), myCeil(r.y1));
dp.x = r.x0 - ri.x0;
dp.y = r.y0 - ri.y0;
assert(dp.x >= 0 && dp.y >= 0);
return ri;
2016-03-19 06:57:51 +13:00
}
}
//---------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
inline double getWarpRadius(const WarpParams &params) {
return 2.55 * 1.5 * 1.5 * fabs(params.m_intensity);
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
inline double getWarperEnlargement(const WarpParams &params) {
// It accounts for:
// * Resample factor (1 - due to triangle filtering)
// * Eventual grid smoothening (6 - as the blur radius applied after
// resampling)
// * grid interpolation (2 - for the shepard interpolant radius)
int enlargement = 3;
if (!params.m_sharpen) enlargement += 6;
return enlargement;
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void getWarpComputeRects(TRectD &outputComputeRect, TRectD &warpedComputeRect,
const TRectD &warpedBox, const TRectD &requestedRect,
const WarpParams &params);
2016-03-19 06:57:51 +13:00
//---------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
//! Deals with raster tiles and invokes warper functions
2016-03-19 06:57:51 +13:00
void warp(TRasterP &tileRas, const TRasterP &rasIn, TRasterP &warper,
2016-06-15 18:43:10 +12:00
TPointD rasInPos, TPointD warperPos, const WarpParams &params);
2016-03-19 06:57:51 +13:00
#endif