1
1
package com .bobrust .generator ;
2
2
3
3
class BorstCore {
4
- static BorstColor computeColor (BorstImage target , BorstImage current , Scanline [] lines , int alpha ) {
4
+ static BorstColor computeColor (BorstImage target , BorstImage current , int alpha , int size , int x_offset , int y_offset ) {
5
5
long rsum_1 = 0 ;
6
6
long gsum_1 = 0 ;
7
7
long bsum_1 = 0 ;
8
-
8
+
9
9
long rsum_2 = 0 ;
10
10
long gsum_2 = 0 ;
11
11
long bsum_2 = 0 ;
12
-
12
+
13
13
int count = 0 ;
14
14
int w = target .width ;
15
+ int h = target .height ;
15
16
17
+ final Scanline [] lines = CircleCache .CIRCLE_CACHE [size ];
16
18
final int len = lines .length ;
17
- for (int i = 0 ; i < len ; i ++) {
19
+ for (int i = 0 ; i < len ; i ++) {
18
20
Scanline line = lines [i ];
19
- int idx = line .y * w ;
20
-
21
- for (int x = line .x1 ; x <= line .x2 ; x ++) {
21
+ int y = line .y + y_offset ;
22
+ if (y < 0 || y >= h ) {
23
+ continue ;
24
+ }
25
+
26
+ int xs = Math .max (line .x1 + x_offset , 0 );
27
+ int xe = Math .min (line .x2 + x_offset , w - 1 );
28
+ int idx = y * w ;
29
+
30
+ for (int x = xs ; x <= xe ; x ++) {
22
31
int tt = target .pixels [idx + x ];
23
32
int cc = current .pixels [idx + x ];
24
33
@@ -30,7 +39,7 @@ static BorstColor computeColor(BorstImage target, BorstImage current, Scanline[]
30
39
gsum_2 += (cc >>> 8 ) & 0xff ;
31
40
bsum_2 += (cc ) & 0xff ;
32
41
}
33
-
42
+
34
43
count += (line .x2 - line .x1 + 1 );
35
44
}
36
45
@@ -48,30 +57,30 @@ static BorstColor computeColor(BorstImage target, BorstImage current, Scanline[]
48
57
49
58
return BorstUtils .getClosestColor ((alpha << 24 ) | (r << 16 ) | (g << 8 ) | (b ));
50
59
}
51
-
52
- static void copyLinesReplaceRegion (BorstImage dst , BorstImage src , Scanline [] lines ) {
53
- int w = dst .width ;
54
- int len = lines .length ;
55
- for (int i = 0 ; i < len ; i ++) {
56
- Scanline line = lines [i ];
57
- int idx = line .x1 + line .y * w ;
58
-
59
- System .arraycopy (src .pixels , idx , dst .pixels , idx , line .x2 - line .x1 + 1 );
60
- }
61
- }
62
-
63
- static void drawLines (BorstImage im , BorstColor c , Scanline [] lines , int alpha ) {
60
+
61
+ static void drawLines (BorstImage im , BorstColor c , int alpha , int size , int x_offset , int y_offset ) {
64
62
int cr = c .r * alpha ;
65
63
int cg = c .g * alpha ;
66
64
int cb = c .b * alpha ;
67
65
int pa = 255 - alpha ;
68
66
int w = im .width ;
67
+ int h = im .height ;
68
+
69
+ final Scanline [] lines = CircleCache .CIRCLE_CACHE [size ];
69
70
final int len = lines .length ;
70
- for (int i = 0 ; i < len ; i ++) {
71
+ for (int i = 0 ; i < len ; i ++) {
71
72
Scanline line = lines [i ];
73
+ int y = line .y + y_offset ;
74
+ if (y < 0 || y >= h ) {
75
+ continue ;
76
+ }
77
+
78
+ int xs = Math .max (line .x1 + x_offset , 0 );
79
+ int xe = Math .min (line .x2 + x_offset , w - 1 );
80
+ int idx = y * w ;
72
81
73
- for (int x = line . x1 ; x <= line . x2 ; x ++) {
74
- int a = im .pixels [line . y * w + x ];
82
+ for (int x = xs ; x <= xe ; x ++) {
83
+ int a = im .pixels [idx + x ];
75
84
int a_a = (a >>> 24 ) & 0xff ;
76
85
int a_r = (a >>> 16 ) & 0xff ;
77
86
int a_g = (a >>> 8 ) & 0xff ;
@@ -82,7 +91,7 @@ static void drawLines(BorstImage im, BorstColor c, Scanline[] lines, int alpha)
82
91
int ab = (cb + (a_b * pa )) >>> 8 ;
83
92
int aa = 255 - (((255 - a_a ) * pa ) >>> 8 );
84
93
85
- im .pixels [line . y * w + x ] = (aa << 24 ) | (ar << 16 ) | (ag << 8 ) | (ab );
94
+ im .pixels [idx + x ] = (aa << 24 ) | (ar << 16 ) | (ag << 8 ) | (ab );
86
95
}
87
96
}
88
97
}
@@ -119,18 +128,26 @@ static float differenceFull(BorstImage a, BorstImage b) {
119
128
return (float )(Math .sqrt (total / (w * h * 4.0 )) / 255.0 );
120
129
}
121
130
122
- static float differencePartial (BorstImage target , BorstImage before , BorstImage after , float score , Scanline [] lines ) {
131
+ static float differencePartial (BorstImage target , BorstImage before , BorstImage after , float score , int size , int x_offset , int y_offset ) {
123
132
int w = target .width ;
124
133
int h = target .height ;
125
134
double denom = (w * h * 4.0 );
126
135
long total = (long )(Math .pow (score * 255 , 2 ) * denom );
127
136
137
+ final Scanline [] lines = CircleCache .CIRCLE_CACHE [size ];
128
138
final int len = lines .length ;
129
- for (int i = 0 ; i < len ; i ++) {
139
+ for (int i = 0 ; i < len ; i ++) {
130
140
Scanline line = lines [i ];
131
- int idx = line .y * w ;
141
+ int y = line .y + y_offset ;
142
+ if (y < 0 || y >= h ) {
143
+ continue ;
144
+ }
145
+
146
+ int xs = Math .max (line .x1 + x_offset , 0 );
147
+ int xe = Math .min (line .x2 + x_offset , w - 1 );
148
+ int idx = y * w ;
132
149
133
- for (int x = line . x1 ; x <= line . x2 ; x ++) {
150
+ for (int x = xs ; x <= xe ; x ++) {
134
151
int tt = target .pixels [idx + x ];
135
152
int bb = before .pixels [idx + x ];
136
153
int aa = after .pixels [idx + x ];
@@ -168,10 +185,9 @@ static float differencePartial(BorstImage target, BorstImage before, BorstImage
168
185
return (float )(Math .sqrt (total / denom ) / 255.0 );
169
186
}
170
187
171
- static float differencePartialThread (BorstImage target , BorstImage before , float score , int alpha , Scanline [] lines ) {
172
- BorstColor color = BorstCore .computeColor (target , before , lines , alpha );
188
+ static float differencePartialThread (BorstImage target , BorstImage before , float score , int alpha , int size , int x_offset , int y_offset ) {
189
+ BorstColor color = BorstCore .computeColor (target , before , alpha , size , x_offset , y_offset );
173
190
174
- final int len = lines .length ;
175
191
final int h = target .height ;
176
192
final int w = target .width ;
177
193
@@ -183,11 +199,21 @@ static float differencePartialThread(BorstImage target, BorstImage before, float
183
199
final int cb = color .b * alpha ;
184
200
final int pa = 255 - alpha ;
185
201
186
- for (int i = 0 ; i < len ; i ++) {
202
+ final Scanline [] lines = CircleCache .CIRCLE_CACHE [size ];
203
+ final int len = lines .length ;
204
+
205
+ for (int i = 0 ; i < len ; i ++) {
187
206
Scanline line = lines [i ];
188
- int idx = line .y * w ;
207
+ int y = line .y + y_offset ;
208
+ if (y < 0 || y >= h ) {
209
+ continue ;
210
+ }
211
+
212
+ int xs = Math .max (line .x1 + x_offset , 0 );
213
+ int xe = Math .min (line .x2 + x_offset , w - 1 );
214
+ int idx = y * w ;
189
215
190
- for (int x = line . x1 ; x <= line . x2 ; x ++) {
216
+ for (int x = xs ; x <= xe ; x ++) {
191
217
int tt = target .pixels [idx + x ];
192
218
int bb = before .pixels [idx + x ];
193
219
0 commit comments