@@ -108,8 +108,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
108
108
109
109
// determine covariance matrix
110
110
float cov[6 ];
111
- for (int i = 0 ; i < 6 ; ++ i)
111
+ for (int i = 0 ; i < 6 ; ++ i) {
112
112
cov[i] = 0 ;
113
+ }
113
114
114
115
for (int i = 0 ; i < 16 ; ++ i) {
115
116
const float3 currColor = unpackUnorm4x8(srcPixelsBlock[i]).xyz * 255 .0f;
@@ -124,8 +125,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
124
125
}
125
126
126
127
// convert covariance matrix to float, find principal axis via power iter
127
- for (int i = 0 ; i < 6 ; ++ i)
128
+ for (int i = 0 ; i < 6 ; ++ i) {
128
129
cov[i] /= 255 .0f;
130
+ }
129
131
130
132
float3 vF = maxColor - minColor;
131
133
@@ -180,8 +182,9 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
180
182
float3 dir = color[0 ] - color[1 ];
181
183
float stops[4 ];
182
184
183
- for (int i = 0 ; i < 4 ; ++ i)
185
+ for (int i = 0 ; i < 4 ; ++ i) {
184
186
stops[i] = dot (color[i], dir);
187
+ }
185
188
186
189
// think of the colors as arranged on a line; project point onto that line, then choose
187
190
// next color out of available ones. we compute the crossover points for "best color in top
@@ -203,10 +206,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
203
206
const float dotValue = dot (currColor, dir);
204
207
mask <<= 2u;
205
208
206
- if (dotValue < halfPoint)
209
+ if (dotValue < halfPoint) {
207
210
mask |= ((dotValue < c0Point) ? 1u : 3u);
208
- else
211
+ } else {
209
212
mask |= ((dotValue < c3Point) ? 2u : 0u);
213
+ }
210
214
}
211
215
#else
212
216
// with floyd-steinberg dithering
@@ -228,43 +232,47 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
228
232
dotValue = dot (currColor, dir);
229
233
230
234
ditherDot = (dotValue * 16 .0f) + (3 * ep2[1 ] + 5 * ep2[0 ]);
231
- if (ditherDot < halfPoint)
235
+ if (ditherDot < halfPoint) {
232
236
step = (ditherDot < c0Point) ? 1u : 3u;
233
- else
237
+ } else {
234
238
step = (ditherDot < c3Point) ? 2u : 0u;
239
+ }
235
240
ep1[0 ] = dotValue - stops[step ];
236
241
lmask = step ;
237
242
238
243
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 1 ]).xyz * 255 .0f;
239
244
dotValue = dot (currColor, dir);
240
245
241
246
ditherDot = (dotValue * 16 .0f) + (7 * ep1[0 ] + 3 * ep2[2 ] + 5 * ep2[1 ] + ep2[0 ]);
242
- if (ditherDot < halfPoint)
247
+ if (ditherDot < halfPoint) {
243
248
step = (ditherDot < c0Point) ? 1u : 3u;
244
- else
249
+ } else {
245
250
step = (ditherDot < c3Point) ? 2u : 0u;
251
+ }
246
252
ep1[1 ] = dotValue - stops[step ];
247
253
lmask |= step << 2u;
248
254
249
255
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2 ]).xyz * 255 .0f;
250
256
dotValue = dot (currColor, dir);
251
257
252
258
ditherDot = (dotValue * 16 .0f) + (7 * ep1[1 ] + 3 * ep2[3 ] + 5 * ep2[2 ] + ep2[1 ]);
253
- if (ditherDot < halfPoint)
259
+ if (ditherDot < halfPoint) {
254
260
step = (ditherDot < c0Point) ? 1u : 3u;
255
- else
261
+ } else {
256
262
step = (ditherDot < c3Point) ? 2u : 0u;
263
+ }
257
264
ep1[2 ] = dotValue - stops[step ];
258
265
lmask |= step << 4u;
259
266
260
267
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2 ]).xyz * 255 .0f;
261
268
dotValue = dot (currColor, dir);
262
269
263
270
ditherDot = (dotValue * 16 .0f) + (7 * ep1[2 ] + 5 * ep2[3 ] + ep2[2 ]);
264
- if (ditherDot < halfPoint)
271
+ if (ditherDot < halfPoint) {
265
272
step = (ditherDot < c0Point) ? 1u : 3u;
266
- else
273
+ } else {
267
274
step = (ditherDot < c3Point) ? 2u : 0u;
275
+ }
268
276
ep1[3 ] = dotValue - stops[step ];
269
277
lmask |= step << 6u;
270
278
@@ -294,8 +302,9 @@ bool RefineBlock(const uint srcPixelsBlock[16], uint mask, inout float inOutMinE
294
302
// yes, linear system would be singular; solve using optimal
295
303
// single-color match on average color
296
304
float3 rgbVal = float3(8 .0f / 255 .0f, 8 .0f / 255 .0f, 8 .0f / 255 .0f);
297
- for (int i = 0 ; i < 16 ; ++ i)
305
+ for (int i = 0 ; i < 16 ; ++ i) {
298
306
rgbVal += unpackUnorm4x8(srcPixelsBlock[i]).xyz;
307
+ }
299
308
300
309
rgbVal = floor (rgbVal * (255 .0f / 16 .0f));
301
310
0 commit comments