forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pan.dctl
27 lines (19 loc) · 965 Bytes
/
Pan.dctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Pan
// Snaps image to left or right side if gap present, or symmetrically aligns image if gap on both sides
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
int pan = 0;
int panL = 0;
int panR = 0;
for(int i = 0; i < p_Width / 2; ++i) {
if(_tex2D(p_TexR, i, p_Height / 2) == 0.0f && _tex2D(p_TexG, i, p_Height / 2) == 0.0f && _tex2D(p_TexB, i, p_Height / 2) == 0.0f){
panL += 1;}}
for(int i = p_Width / 2; i < p_Width; ++i) {
if(_tex2D(p_TexR, i, p_Height / 2) == 0.0f && _tex2D(p_TexG, i, p_Height / 2) == 0.0f && _tex2D(p_TexB, i, p_Height / 2) == 0.0f){
panR += 1;}}
pan = panL > 0 && panR > 0 ? (panL - panR) / 2 : panL - panR;
const float r = _tex2D(p_TexR, p_X + pan, p_Y);
const float g = _tex2D(p_TexG, p_X + pan, p_Y);
const float b = _tex2D(p_TexB, p_X + pan, p_Y);
return make_float3(r, g, b);
}