TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua
标题:
请问在TCAS中怎么旋转PIX?
[打印本页]
作者:
乱步
时间:
2012-8-13 21:08:39
标题:
请问在TCAS中怎么旋转PIX?
沿z轴的旋转貌似可以先转成image再rotate, 如果是沿x轴和y轴呢
作者:
milkyjing
时间:
2012-8-13 21:21:06
貌似我没见到直接的方法, 但如果有一定编码能力的话, 可以按照如下思路去编写:
def ca_frz(x, y, a):
x2 = x * cos(a) + y * sin(a)
y2 = x * sin(a) + y * cos(a)
return x2, y2
def ca_fry(x, y, a):
x2 = x * cos(a)
y2 = y
return x2, y2
def ca_frx(x, y, a):
x2 = x
y2 = y * cos(a)
return x2, y2
复制代码
这个是我为cairo模块写的旋转代码, 利用这个原理, 以及双线性插值
int x = floor(u);
int y = floor(v);
double u_ratio = u - x;
double v_ratio = v - y;
double u_opposite = 1 - u_ratio;
double v_opposite = 1 - v_ratio;
double result = (tex[x][y] * u_opposite + tex[x+1][y] * u_ratio) * v_opposite +
(tex[x][y+1] * u_opposite + tex[x+1][y+1] * u_ratio) * v_ratio;
复制代码
(目标PIX中的一点由源PIX中最近的4点决定)
关于PIX的操作, 可以看最新版的TCAX中的tcaxPy.py, 里面有一些相关的函数可供参考.
p.s. 我没时间来编码这东西了, 所以靠自己努力吧, Fight~
作者:
milkyjing
时间:
2012-8-18 18:03:53
抽空写了个简单的, 基于最近点的绕X轴旋转代码. 未测试
# PIX rotate around x-axis, nearest point approach,
# the position of PIX is maintained by fixing the middle of the original PIX still
# point (x, y) maps to a new point (u, v) by the formula u = x, v = y * cos(ag)
# so destination resolution of PIX is dst_width = src_width, dst_height = src_height * cos(ag)
def PixRotateX_nearest(PIX, ag):
src_width = PIX[1][0]
src_height = PIX[1][1]
dst_width = src_width
dst_height = int(src_height * cos(ag) + 0.5)
PIX_pos = (PIX[0][0], PIX[0][1] + (src_height - dst_height) / 2)
PIX_res = (dst_width, dst_height)
size = dst_height * dst_width * 4
PIX_rgba = [0 for c in range(size)]
for h in range(dst_height):
for w in range(dst_width):
dst_idx = 4 * (h * dst_width + w)
src_idx = 4 * (int(h * cos(ag) + 0.5) * src_width + w)
PIX_rgba[dst_idx] = PIX[2][src_idx]
PIX_rgba[dst_idx + 1] = PIX[2][src_idx + 1]
PIX_rgba[dst_idx + 2] = PIX[2][src_idx + 2]
PIX_rgba[dst_idx + 3] = PIX[2][src_idx + 3]
return (PIX_pos, PIX_res, tuple(PIX_rgba))
复制代码
作者:
milkyjing
时间:
2012-8-19 18:08:11
经测试, 上帖第17行代码 h * cos(ag) 应改为 h / cos(ag), 顺带写了绕Y轴的最近点算法版本.
注: 不管是绕X轴旋转抑或是绕Y轴旋转, 都未考虑进"透视感"(即, 近端变大, 远端变小). 有待升级
from math import cos
# PIX rotate around x-axis, nearest point approach,
# the position of PIX is maintained by fixing the middle of the original PIX still
# point (x, y) maps to a new point (u, v) by the formula u = x, v = y * cos(ag)
# so destination resolution of PIX is dst_width = src_width, dst_height = src_height * cos(ag)
def PixRotateX_nearest(PIX, ag):
src_width = PIX[1][0]
src_height = PIX[1][1]
dst_width = src_width
dst_height = int(src_height * cos(ag) + 0.5)
PIX_pos = (PIX[0][0], PIX[0][1] + (src_height - dst_height) / 2)
PIX_res = (dst_width, dst_height)
size = dst_height * dst_width * 4
PIX_rgba = [0 for c in range(size)]
for h in range(dst_height):
for w in range(dst_width):
dst_idx = 4 * (h * dst_width + w)
src_idx = 4 * (int(h / cos(ag) + 0.5) * src_width + w)
PIX_rgba[dst_idx] = PIX[2][src_idx]
PIX_rgba[dst_idx + 1] = PIX[2][src_idx + 1]
PIX_rgba[dst_idx + 2] = PIX[2][src_idx + 2]
PIX_rgba[dst_idx + 3] = PIX[2][src_idx + 3]
return (PIX_pos, PIX_res, tuple(PIX_rgba))
# PIX rotate around y-axis, nearest point approach,
# the position of PIX is maintained by fixing the middle of the original PIX still
# point (x, y) maps to a new point (u, v) by the formula u = x * cos(ag), v = y
# so destination resolution of PIX is dst_width = src_width * cos(ag), dst_height = src_height
def PixRotateY_nearest(PIX, ag):
src_width = PIX[1][0]
src_height = PIX[1][1]
dst_width = int(src_width * cos(ag) + 0.5)
dst_height = src_height
PIX_pos = (PIX[0][0] + (src_width - dst_width) / 2, PIX[0][1])
PIX_res = (dst_width, dst_height)
size = dst_height * dst_width * 4
PIX_rgba = [0 for c in range(size)]
for h in range(dst_height):
for w in range(dst_width):
dst_idx = 4 * (h * dst_width + w)
src_idx = 4 * (h * src_width + int(w / cos(ag) + 0.5))
PIX_rgba[dst_idx] = PIX[2][src_idx]
PIX_rgba[dst_idx + 1] = PIX[2][src_idx + 1]
PIX_rgba[dst_idx + 2] = PIX[2][src_idx + 2]
PIX_rgba[dst_idx + 3] = PIX[2][src_idx + 3]
return (PIX_pos, PIX_res, tuple(PIX_rgba))
复制代码
作者:
milkyjing
时间:
2012-8-19 18:20:15
VSFilter中, 关于frx, fry, frz的代码是(同时输入3个角度以及一个坐标原点, 一同进行变换, 未指定的角度, 默认为0)
void CWord::Transform(CPoint org)
{
double scalex = m_style.fontScaleX/100;
double scaley = m_style.fontScaleY/100;
double caz = cos((3.1415/180)*m_style.fontAngleZ);
double saz = sin((3.1415/180)*m_style.fontAngleZ);
double cax = cos((3.1415/180)*m_style.fontAngleX);
double sax = sin((3.1415/180)*m_style.fontAngleX);
double cay = cos((3.1415/180)*m_style.fontAngleY);
double say = sin((3.1415/180)*m_style.fontAngleY);
for(int i = 0; i < mPathPoints; i++)
{
double x, y, z, xx, yy, zz;
x = scalex * (mpPathPoints[i].x + m_style.fontShiftX * mpPathPoints[i].y) - org.x;
y = scaley * (mpPathPoints[i].y + m_style.fontShiftY * mpPathPoints[i].x) - org.y;
z = 0;
xx = x*caz + y*saz;
yy = -(x*saz - y*caz);
zz = z;
x = xx;
y = yy*cax + zz*sax;
z = yy*sax - zz*cax;
xx = x*cay + z*say;
yy = y;
zz = x*say - z*cay;
zz = max(zz, -19000);
x = (xx * 20000) / (zz + 20000);
y = (yy * 20000) / (zz + 20000);
mpPathPoints[i].x = (LONG)(x + org.x + 0.5);
mpPathPoints[i].y = (LONG)(y + org.y + 0.5);
}
}
复制代码
作者:
six
时间:
2012-8-20 08:28:42
别折磨好少年了,牛奶大,直接搞内置函数得了@@
作者:
乱步
时间:
2012-8-29 20:52:54
受益良多!感谢牛奶大
欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/)
Powered by Discuz! X2