11__kernel void processNineCellWindow ( __global float * scanLine1 ,
2- __global float * scanLine2 ,
3- __global float * scanLine3 ,
4- __global uchar4 * resultLine , // This is an image!
5- __global float * rasterParams // [ mInputNodataValue, mOutputNodataValue, mZFactor, mCellSizeX, mCellSizeY,
6- // cos_az_mul_cos_alt_mul_z_mul_254, sin_az_mul_cos_alt_mul_z_mul_254, square_z, sin_altRadians_mul_254]
2+ __global float * scanLine2 ,
3+ __global float * scanLine3 ,
4+ __global uchar4 * resultLine , // This is an image!
5+ __global float * rasterParams
76
8- ) {
7+ )
8+ {
99
10- // Get the index of the current element
11- const int i = get_global_id (0 );
10+ // Get the index of the current element
11+ const int i = get_global_id (0 );
1212
13- float x11 = scanLine1 [i ];
14- float x12 = scanLine1 [i + 1 ];
15- float x13 = scanLine1 [i + 2 ];
16- float x21 = scanLine2 [i ];
17- float x22 = scanLine2 [i + 1 ];
18- float x23 = scanLine2 [i + 2 ];
19- float x31 = scanLine3 [i ];
20- float x32 = scanLine3 [i + 1 ];
21- float x33 = scanLine3 [i + 2 ];
13+ float x11 = scanLine1 [i ];
14+ float x12 = scanLine1 [i + 1 ];
15+ float x13 = scanLine1 [i + 2 ];
16+ float x21 = scanLine2 [i ];
17+ float x22 = scanLine2 [i + 1 ];
18+ float x23 = scanLine2 [i + 2 ];
19+ float x31 = scanLine3 [i ];
20+ float x32 = scanLine3 [i + 1 ];
21+ float x33 = scanLine3 [i + 2 ];
2222
23- float res ;
24- if ( x22 == rasterParams [1 ] )
25- {
26- res = rasterParams [2 ];
27- }
28- else
29- {
23+ if ( x22 == rasterParams [0 ] )
24+ {
25+ float alpha = rasterParams [5 ] * rasterParams [16 ];
26+ resultLine [i ] = (uchar4 )(rasterParams [13 ] * alpha ,
27+ rasterParams [14 ] * alpha ,
28+ rasterParams [15 ] * alpha , 255 * alpha );
29+ }
30+ else
31+ {
3032 if ( x11 == rasterParams [0 ] ) x11 = x22 ;
3133 if ( x12 == rasterParams [0 ] ) x12 = x22 ;
3234 if ( x13 == rasterParams [0 ] ) x13 = x22 ;
@@ -40,36 +42,41 @@ __kernel void processNineCellWindow( __global float *scanLine1,
4042 float derX = ( ( x13 + x23 + x23 + x33 ) - ( x11 + x21 + x21 + x31 ) ) / ( 8 * rasterParams [3 ] );
4143 float derY = ( ( x31 + x32 + x32 + x33 ) - ( x11 + x12 + x12 + x13 ) ) / ( 8 * - rasterParams [4 ]);
4244
43- if ( derX == rasterParams [1 ] || derY == rasterParams [1 ] )
45+ if ( derX == rasterParams [0 ] ||
46+ derX == rasterParams [0 ] )
4447 {
45- res = rasterParams [2 ];
48+ float alpha = rasterParams [5 ] * rasterParams [16 ];
49+ resultLine [i ] = (uchar4 )(rasterParams [13 ] * alpha ,
50+ rasterParams [14 ] * alpha ,
51+ rasterParams [15 ] * alpha , 255 * alpha );
4652 }
4753 else
4854 {
55+ float res ;
4956 // Weighted multi direction as in http://pubs.usgs.gov/of/1992/of92-422/of92-422.pdf
5057 // Fast formula from GDAL DEM
5158 const float xx = derX * derX ;
5259 const float yy = derY * derY ;
5360 const float xx_plus_yy = xx + yy ;
54- // Flat? -> white
61+ // Flat?
5562 if ( xx_plus_yy == 0.0f )
5663 {
57- res = clamp ( 1.0f + rasterParams [12 ], 0.0f , 255.0f );
64+ res = clamp ( 1.0f + rasterParams [9 ], 0.0f , 255.0f );
5865 }
5966 else
6067 {
6168 // ... then the shade value from different azimuth
62- float val225_mul_127 = rasterParams [13 ] +
63- ( derX - derY ) * rasterParams [14 ];
69+ float val225_mul_127 = rasterParams [10 ] +
70+ ( derX - derY ) * rasterParams [11 ];
6471 val225_mul_127 = ( val225_mul_127 <= 0.0 ) ? 0.0 : val225_mul_127 ;
65- float val270_mul_127 = rasterParams [13 ] -
66- derX * rasterParams [15 ];
72+ float val270_mul_127 = rasterParams [10 ] -
73+ derX * rasterParams [12 ];
6774 val270_mul_127 = ( val270_mul_127 <= 0.0 ) ? 0.0 : val270_mul_127 ;
68- float val315_mul_127 = rasterParams [13 ] +
69- ( derX + derY ) * rasterParams [14 ];
75+ float val315_mul_127 = rasterParams [10 ] +
76+ ( derX + derY ) * rasterParams [11 ];
7077 val315_mul_127 = ( val315_mul_127 <= 0.0 ) ? 0.0 : val315_mul_127 ;
71- float val360_mul_127 = rasterParams [13 ] -
72- derY * rasterParams [15 ];
78+ float val360_mul_127 = rasterParams [10 ] -
79+ derY * rasterParams [12 ];
7380 val360_mul_127 = ( val360_mul_127 <= 0.0 ) ? 0.0 : val360_mul_127 ;
7481 // ... then the weighted shading
7582 const float weight_225 = 0.5 * xx_plus_yy - derX * derY ;
@@ -81,16 +88,11 @@ __kernel void processNineCellWindow( __global float *scanLine1,
8188 weight_270 * val270_mul_127 +
8289 weight_315 * val315_mul_127 +
8390 weight_360 * val360_mul_127 ) / xx_plus_yy ) /
84- ( 1 + rasterParams [11 ] * xx_plus_yy );
85-
91+ ( 1 + rasterParams [8 ] * xx_plus_yy );
8692 res = clamp ( 1.0f + cang_mul_127 , 0.0f , 255.0f );
93+ res = res * rasterParams [5 ];
94+ resultLine [i ] = (uchar4 )(res , res , res , 255 * rasterParams [5 ]);
8795 }
8896 }
8997 }
90-
91- // Opacity
92- res = res * rasterParams [7 ];
93-
94- resultLine [i ] = (uchar4 )(res , res , res , 255 * rasterParams [7 ]);
95-
9698}
0 commit comments