20 using namespace DirectX::PackedVector;
29 static const float fEpsilon = (0.25f / 64.0f) * (0.25f / 64.0f);
30 static const float pC3[] = { 2.0f/2.0f, 1.0f/2.0f, 0.0f/2.0f };
31 static const float pD3[] = { 0.0f/2.0f, 1.0f/2.0f, 2.0f/2.0f };
32 static const float pC4[] = { 3.0f/3.0f, 2.0f/3.0f, 1.0f/3.0f, 0.0f/3.0f };
33 static const float pD4[] = { 0.0f/3.0f, 1.0f/3.0f, 2.0f/3.0f, 3.0f/3.0f };
37 const int g_aWeights4[] = {0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64};
43 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
44 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
45 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
46 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
47 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
48 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
50 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
51 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
52 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
53 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
54 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
55 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
56 { 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 2 },
239 { 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1 },
240 { 0, 2, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 1, 2, 2, 2 },
241 { 0, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
242 { 0, 1, 1, 1, 2, 0, 1, 1, 2, 2, 0, 1, 2, 2, 2, 0 }
250 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
251 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
252 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
253 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
254 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
255 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
256 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
257 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
258 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
259 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
260 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
261 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
262 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
263 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
264 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
265 { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}
269 { 0,15, 0}, { 0,15, 0}, { 0,15, 0}, { 0,15, 0},
270 { 0,15, 0}, { 0,15, 0}, { 0,15, 0}, { 0,15, 0},
271 { 0,15, 0}, { 0,15, 0}, { 0,15, 0}, { 0,15, 0},
272 { 0,15, 0}, { 0,15, 0}, { 0,15, 0}, { 0,15, 0},
273 { 0,15, 0}, { 0, 2, 0}, { 0, 8, 0}, { 0, 2, 0},
274 { 0, 2, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0,15, 0},
275 { 0, 2, 0}, { 0, 8, 0}, { 0, 2, 0}, { 0, 2, 0},
276 { 0, 8, 0}, { 0, 8, 0}, { 0, 2, 0}, { 0, 2, 0},
279 { 0,15, 0}, { 0,15, 0}, { 0, 6, 0}, { 0, 8, 0},
280 { 0, 2, 0}, { 0, 8, 0}, { 0,15, 0}, { 0,15, 0},
281 { 0, 2, 0}, { 0, 8, 0}, { 0, 2, 0}, { 0, 2, 0},
282 { 0, 2, 0}, { 0,15, 0}, { 0,15, 0}, { 0, 6, 0},
283 { 0, 6, 0}, { 0, 2, 0}, { 0, 6, 0}, { 0, 8, 0},
284 { 0,15, 0}, { 0,15, 0}, { 0, 2, 0}, { 0, 2, 0},
285 { 0,15, 0}, { 0,15, 0}, { 0,15, 0}, { 0,15, 0},
286 { 0,15, 0}, { 0, 2, 0}, { 0, 2, 0}, { 0,15, 0}
290 { 0, 3,15}, { 0, 3, 8}, { 0,15, 8}, { 0,15, 3},
291 { 0, 8,15}, { 0, 3,15}, { 0,15, 3}, { 0,15, 8},
292 { 0, 8,15}, { 0, 8,15}, { 0, 6,15}, { 0, 6,15},
293 { 0, 6,15}, { 0, 5,15}, { 0, 3,15}, { 0, 3, 8},
294 { 0, 3,15}, { 0, 3, 8}, { 0, 8,15}, { 0,15, 3},
295 { 0, 3,15}, { 0, 3, 8}, { 0, 6,15}, { 0,10, 8},
296 { 0, 5, 3}, { 0, 8,15}, { 0, 8, 6}, { 0, 6,10},
297 { 0, 8,15}, { 0, 5,15}, { 0,15,10}, { 0,15, 8},
298 { 0, 8,15}, { 0,15, 3}, { 0, 3,15}, { 0, 5,10},
299 { 0, 6,10}, { 0,10, 8}, { 0, 8, 9}, { 0,15,10},
300 { 0,15, 6}, { 0, 3,15}, { 0,15, 8}, { 0, 5,15},
301 { 0,15, 3}, { 0,15, 6}, { 0,15, 6}, { 0,15, 8},
302 { 0, 3,15}, { 0,15, 3}, { 0, 5,15}, { 0, 5,15},
303 { 0, 5,15}, { 0, 8,15}, { 0, 5,15}, { 0,10,15},
304 { 0, 5,15}, { 0,10,15}, { 0, 8,15}, { 0,13,15},
305 { 0,15, 3}, { 0,12,15}, { 0, 3,15}, { 0, 3, 8}
310 const D3DX_BC6H::ModeDescriptor D3DX_BC6H::ms_aDesc[14][82] =
313 { M, 0}, {
M, 1}, {GY, 4}, {BY, 4}, {BZ, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
314 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
315 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
316 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
317 {GZ, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
318 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
319 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
320 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
325 {
M, 0}, {
M, 1}, {GY, 5}, {GZ, 4}, {GZ, 5}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
326 {RW, 5}, {RW, 6}, {BZ, 0}, {BZ, 1}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
327 {GW, 5}, {GW, 6}, {BY, 5}, {BZ, 2}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
328 {BW, 5}, {BW, 6}, {BZ, 3}, {BZ, 5}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
329 {RX, 5}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
330 {GX, 5}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
331 {BX, 5}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
332 {RY, 5}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}, {
D, 0}, {
D, 1}, {
D, 2},
337 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
338 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
339 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
340 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
341 {RW,10}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GW,10},
342 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BW,10},
343 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
344 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
349 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
350 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
351 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
352 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RW,10},
353 {GZ, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
354 {GW,10}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BW,10},
355 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {BZ, 0},
356 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {GY, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
361 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
362 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
363 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
364 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RW,10},
365 {BY, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GW,10},
366 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
367 {BW,10}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {BZ, 1},
368 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
373 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
374 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
375 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
376 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
377 {GZ, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
378 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
379 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
380 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
385 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
386 {RW, 5}, {RW, 6}, {RW, 7}, {GZ, 4}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
387 {GW, 5}, {GW, 6}, {GW, 7}, {BZ, 2}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
388 {BW, 5}, {BW, 6}, {BW, 7}, {BZ, 3}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
389 {RX, 5}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
390 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
391 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
392 {RY, 5}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}, {
D, 0}, {
D, 1}, {
D, 2},
397 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
398 {RW, 5}, {RW, 6}, {RW, 7}, {BZ, 0}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
399 {GW, 5}, {GW, 6}, {GW, 7}, {GY, 5}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
400 {BW, 5}, {BW, 6}, {BW, 7}, {GZ, 5}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
401 {GZ, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
402 {GX, 5}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
403 {BZ, 1}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
404 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
409 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
410 {RW, 5}, {RW, 6}, {RW, 7}, {BZ, 1}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
411 {GW, 5}, {GW, 6}, {GW, 7}, {BY, 5}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
412 {BW, 5}, {BW, 6}, {BW, 7}, {BZ, 5}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
413 {GZ, 4}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
414 {BZ, 0}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
415 {BX, 5}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
416 {BZ, 2}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {BZ, 3}, {
D, 0}, {
D, 1}, {
D, 2},
421 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
422 {RW, 5}, {GZ, 4}, {BZ, 0}, {BZ, 1}, {BY, 4}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
423 {GW, 5}, {GY, 5}, {BY, 5}, {BZ, 2}, {GY, 4}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
424 {BW, 5}, {GZ, 5}, {BZ, 3}, {BZ, 5}, {BZ, 4}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
425 {RX, 5}, {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
426 {GX, 5}, {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
427 {BX, 5}, {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}, {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
428 {RY, 5}, {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}, {
D, 0}, {
D, 1}, {
D, 2},
433 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
434 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
435 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
436 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
437 {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}, {RX, 9}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
438 {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}, {GX, 9}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
439 {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8}, {BX, 9}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
440 {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
445 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
446 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
447 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
448 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
449 {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}, {RW,10}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
450 {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}, {GW,10}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
451 {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8}, {BW,10}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
452 {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
457 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
458 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
459 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
460 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4},
461 {RX, 5}, {RX, 6}, {RX, 7}, {RW,11}, {RW,10}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4},
462 {GX, 5}, {GX, 6}, {GX, 7}, {GW,11}, {GW,10}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4},
463 {BX, 5}, {BX, 6}, {BX, 7}, {BW,11}, {BW,10}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
464 {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
469 {
M, 0}, {
M, 1}, {
M, 2}, {
M, 3}, {
M, 4}, {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4},
470 {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}, {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4},
471 {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}, {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4},
472 {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}, {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RW,15},
473 {RW,14}, {RW,13}, {RW,12}, {RW,11}, {RW,10}, {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GW,15},
474 {GW,14}, {GW,13}, {GW,12}, {GW,11}, {GW,10}, {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BW,15},
475 {BW,14}, {BW,13}, {BW,12}, {BW,11}, {BW,10}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
476 {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0}, {NA, 0},
482 const D3DX_BC6H::ModeInfo D3DX_BC6H::ms_aInfo[] =
484 {0x00, 1,
true, 3, LDRColorA(10,10,10,0), LDRColorA( 5, 5, 5,0), LDRColorA(5,5,5,0), LDRColorA(5,5,5,0)},
485 {0x01, 1,
true, 3, LDRColorA( 7, 7, 7,0), LDRColorA( 6, 6, 6,0), LDRColorA(6,6,6,0), LDRColorA(6,6,6,0)},
486 {0x02, 1,
true, 3, LDRColorA(11,11,11,0), LDRColorA( 5, 4, 4,0), LDRColorA(5,4,4,0), LDRColorA(5,4,4,0)},
487 {0x06, 1,
true, 3, LDRColorA(11,11,11,0), LDRColorA( 4, 5, 4,0), LDRColorA(4,5,4,0), LDRColorA(4,5,4,0)},
488 {0x0a, 1,
true, 3, LDRColorA(11,11,11,0), LDRColorA( 4, 4, 5,0), LDRColorA(4,4,5,0), LDRColorA(4,4,5,0)},
489 {0x0e, 1,
true, 3, LDRColorA( 9, 9, 9,0), LDRColorA( 5, 5, 5,0), LDRColorA(5,5,5,0), LDRColorA(5,5,5,0)},
490 {0x12, 1,
true, 3, LDRColorA( 8, 8, 8,0), LDRColorA( 6, 5, 5,0), LDRColorA(6,5,5,0), LDRColorA(6,5,5,0)},
491 {0x16, 1,
true, 3, LDRColorA( 8, 8, 8,0), LDRColorA( 5, 6, 5,0), LDRColorA(5,6,5,0), LDRColorA(5,6,5,0)},
492 {0x1a, 1,
true, 3, LDRColorA( 8, 8, 8,0), LDRColorA( 5, 5, 6,0), LDRColorA(5,5,6,0), LDRColorA(5,5,6,0)},
493 {0x1e, 1,
false, 3, LDRColorA( 6, 6, 6,0), LDRColorA( 6, 6, 6,0), LDRColorA(6,6,6,0), LDRColorA(6,6,6,0)},
494 {0x03, 0,
false, 4, LDRColorA(10,10,10,0), LDRColorA(10,10,10,0), LDRColorA(0,0,0,0), LDRColorA(0,0,0,0)},
495 {0x07, 0,
true, 4, LDRColorA(11,11,11,0), LDRColorA( 9, 9, 9,0), LDRColorA(0,0,0,0), LDRColorA(0,0,0,0)},
496 {0x0b, 0,
true, 4, LDRColorA(12,12,12,0), LDRColorA( 8, 8, 8,0), LDRColorA(0,0,0,0), LDRColorA(0,0,0,0)},
497 {0x0f, 0,
true, 4, LDRColorA(16,16,16,0), LDRColorA( 4, 4, 4,0), LDRColorA(0,0,0,0), LDRColorA(0,0,0,0)},
500 const int D3DX_BC6H::ms_aModeToInfo[] =
537 const D3DX_BC7::ModeInfo D3DX_BC7::ms_aInfo[] =
539 {2, 4, 6, 0, 0, 3, 0, LDRColorA(4,4,4,0), LDRColorA(5,5,5,0)},
541 {1, 6, 2, 0, 0, 3, 0, LDRColorA(6,6,6,0), LDRColorA(7,7,7,0)},
543 {2, 6, 0, 0, 0, 2, 0, LDRColorA(5,5,5,0), LDRColorA(5,5,5,0)},
545 {1, 6, 4, 0, 0, 2, 0, LDRColorA(7,7,7,0), LDRColorA(8,8,8,0)},
547 {0, 0, 0, 2, 1, 2, 3, LDRColorA(5,5,5,6), LDRColorA(5,5,5,6)},
549 {0, 0, 0, 2, 0, 2, 2, LDRColorA(7,7,7,8), LDRColorA(7,7,7,8)},
551 {0, 0, 2, 0, 0, 4, 0, LDRColorA(7,7,7,7), LDRColorA(8,8,8,8)},
553 {1, 6, 4, 0, 0, 2, 0, LDRColorA(5,5,5,5), LDRColorA(6,6,6,6)}
561 inline static bool IsFixUpOffset(_In_range_(0,2)
size_t uPartitions, _In_range_(0,63)
size_t uShape, _In_range_(0,15)
size_t uOffset)
563 assert(uPartitions < 3 && uShape < 64 && uOffset < 16);
564 _Analysis_assume_(uPartitions < 3 && uShape < 64 && uOffset < 16);
565 for(
size_t p = 0; p <= uPartitions; p++)
567 if(uOffset ==
g_aFixUp[uPartitions][uShape][p])
577 aEndPts[0].B -= aEndPts[0].A;
578 aEndPts[1].A -= aEndPts[0].A;
579 aEndPts[1].B -= aEndPts[0].A;
584 INTColor WrapMask((1 << Prec.r) - 1, (1 << Prec.g) - 1, (1 << Prec.b) - 1);
585 aEndPts[0].B += aEndPts[0].A; aEndPts[0].B &= WrapMask;
586 aEndPts[1].A += aEndPts[0].A; aEndPts[1].A &= WrapMask;
587 aEndPts[1].B += aEndPts[0].A; aEndPts[1].B &= WrapMask;
598 float dr = float(a.r) - float(b.r);
599 float dg = float(a.g) - float(b.g);
600 float db = float(a.b) - float(b.b);
601 return dr * dr + dg * dg + db * db;
605 inline static int NBits(_In_
int n, _In_
bool bIsSigned)
614 for(nb = 0; n; ++nb, n >>= 1);
615 return nb + (bIsSigned ? 1 : 0);
620 for(nb = 0; n < -1; ++nb, n >>= 1) ;
629 _In_
size_t cSteps, _In_
size_t cPixels,
_In_reads_(cPixels)
const size_t* pIndex)
631 float fError = FLT_MAX;
632 const float *pC = (3 == cSteps) ?
pC3 :
pC4;
633 const float *pD = (3 == cSteps) ?
pD3 :
pD4;
639 for(
size_t iPoint = 0; iPoint < cPixels; iPoint++)
641 if(pPoints[pIndex[iPoint]].r < X.
r) X.
r = pPoints[pIndex[iPoint]].r;
642 if(pPoints[pIndex[iPoint]].g < X.
g) X.
g = pPoints[pIndex[iPoint]].g;
643 if(pPoints[pIndex[iPoint]].
b < X.
b) X.
b = pPoints[pIndex[iPoint]].b;
644 if(pPoints[pIndex[iPoint]].r > Y.
r) Y.
r = pPoints[pIndex[iPoint]].r;
645 if(pPoints[pIndex[iPoint]].g > Y.
g) Y.
g = pPoints[pIndex[iPoint]].g;
646 if(pPoints[pIndex[iPoint]].
b > Y.
b) Y.
b = pPoints[pIndex[iPoint]].b;
655 float fAB = AB.
r * AB.
r + AB.
g * AB.
g + AB.
b * AB.
b;
660 pX->r = X.
r; pX->g = X.
g; pX->b = X.
b;
661 pY->r = Y.
r; pY->g = Y.
g; pY->b = Y.
b;
666 float fABInv = 1.0f / fAB;
669 Dir.
r = AB.
r * fABInv;
670 Dir.
g = AB.
g * fABInv;
671 Dir.
b = AB.
b * fABInv;
674 Mid.
r = (X.
r + Y.
r) * 0.5f;
675 Mid.
g = (X.
g + Y.
g) * 0.5f;
676 Mid.
b = (X.
b + Y.
b) * 0.5f;
679 fDir[0] = fDir[1] = fDir[2] = fDir[3] = 0.0f;
681 for(
size_t iPoint = 0; iPoint < cPixels; iPoint++)
684 Pt.
r = (pPoints[pIndex[iPoint]].r - Mid.
r) * Dir.
r;
685 Pt.
g = (pPoints[pIndex[iPoint]].g - Mid.
g) * Dir.
g;
686 Pt.
b = (pPoints[pIndex[iPoint]].b - Mid.
b) * Dir.
b;
689 f = Pt.
r + Pt.
g + Pt.
b; fDir[0] += f * f;
690 f = Pt.
r + Pt.
g - Pt.
b; fDir[1] += f * f;
691 f = Pt.
r - Pt.
g + Pt.
b; fDir[2] += f * f;
692 f = Pt.
r - Pt.
g - Pt.
b; fDir[3] += f * f;
695 float fDirMax = fDir[0];
698 for(
size_t iDir = 1; iDir < 4; iDir++)
700 if(fDir[iDir] > fDirMax)
702 fDirMax = fDir[iDir];
707 if(iDirMax & 2) std::swap( X.
g, Y.
g );
708 if(iDirMax & 1) std::swap( X.
b, Y.
b );
711 if(fAB < 1.0f / 4096.0f)
713 pX->r = X.
r; pX->g = X.
g; pX->b = X.
b;
714 pY->r = Y.
r; pY->g = Y.
g; pY->b = Y.
b;
719 float fSteps = (float) (cSteps - 1);
721 for(
size_t iIteration = 0; iIteration < 8; iIteration++)
726 for(
size_t iStep = 0; iStep < cSteps; iStep++)
728 pSteps[iStep].
r = X.
r * pC[iStep] + Y.
r * pD[iStep];
729 pSteps[iStep].
g = X.
g * pC[iStep] + Y.
g * pD[iStep];
730 pSteps[iStep].
b = X.
b * pC[iStep] + Y.
b * pD[iStep];
738 float fLen = (Dir.
r * Dir.
r + Dir.
g * Dir.
g + Dir.
b * Dir.
b);
740 if(fLen < (1.0f / 4096.0f))
743 float fScale = fSteps / fLen;
750 float d2X = 0.0f, d2Y = 0.0f;
751 HDRColorA dX(0.0f, 0.0f, 0.0f, 0.0f), dY(0.0f, 0.0f, 0.0f, 0.0f);
753 for(
size_t iPoint = 0; iPoint < cPixels; iPoint++)
755 float fDot = (pPoints[pIndex[iPoint]].r - X.
r) * Dir.
r +
756 (pPoints[pIndex[iPoint]].g - X.
g) * Dir.
g +
757 (pPoints[pIndex[iPoint]].b - X.
b) * Dir.
b;
765 iStep = size_t(fDot + 0.5f);
768 Diff.
r = pSteps[iStep].
r - pPoints[pIndex[iPoint]].r;
769 Diff.
g = pSteps[iStep].
g - pPoints[pIndex[iPoint]].g;
770 Diff.
b = pSteps[iStep].
b - pPoints[pIndex[iPoint]].b;
772 float fC = pC[iStep] * (1.0f / 8.0f);
773 float fD = pD[iStep] * (1.0f / 8.0f);
775 d2X += fC * pC[iStep];
780 d2Y += fD * pD[iStep];
789 float f = -1.0f / d2X;
798 float f = -1.0f / d2Y;
812 pX->r = X.
r; pX->g = X.
g; pX->b = X.
b;
813 pY->r = Y.
r; pY->g = Y.
g; pY->b = Y.
b;
821 _In_
size_t cSteps, _In_
size_t cPixels,
_In_reads_(cPixels)
const size_t* pIndex)
823 float fError = FLT_MAX;
824 const float *pC = (3 == cSteps) ?
pC3 :
pC4;
825 const float *pD = (3 == cSteps) ?
pD3 :
pD4;
831 for(
size_t iPoint = 0; iPoint < cPixels; iPoint++)
833 if(pPoints[pIndex[iPoint]].r < X.
r) X.
r = pPoints[pIndex[iPoint]].r;
834 if(pPoints[pIndex[iPoint]].g < X.
g) X.
g = pPoints[pIndex[iPoint]].g;
835 if(pPoints[pIndex[iPoint]].
b < X.
b) X.
b = pPoints[pIndex[iPoint]].b;
836 if(pPoints[pIndex[iPoint]].
a < X.
a) X.
a = pPoints[pIndex[iPoint]].a;
837 if(pPoints[pIndex[iPoint]].r > Y.
r) Y.
r = pPoints[pIndex[iPoint]].r;
838 if(pPoints[pIndex[iPoint]].g > Y.
g) Y.
g = pPoints[pIndex[iPoint]].g;
839 if(pPoints[pIndex[iPoint]].
b > Y.
b) Y.
b = pPoints[pIndex[iPoint]].b;
840 if(pPoints[pIndex[iPoint]].
a > Y.
a) Y.
a = pPoints[pIndex[iPoint]].a;
856 float fABInv = 1.0f / fAB;
861 fDir[0] = fDir[1] = fDir[2] = fDir[3] = fDir[4] = fDir[5] = fDir[6] = fDir[7] = 0.0f;
863 for(
size_t iPoint = 0; iPoint < cPixels; iPoint++)
866 Pt.
r = (pPoints[pIndex[iPoint]].r - Mid.
r) * Dir.
r;
867 Pt.
g = (pPoints[pIndex[iPoint]].g - Mid.
g) * Dir.
g;
868 Pt.
b = (pPoints[pIndex[iPoint]].b - Mid.
b) * Dir.
b;
869 Pt.
a = (pPoints[pIndex[iPoint]].a - Mid.
a) * Dir.
a;
872 f = Pt.
r + Pt.
g + Pt.
b + Pt.
a; fDir[0] += f * f;
873 f = Pt.
r + Pt.
g + Pt.
b - Pt.
a; fDir[1] += f * f;
874 f = Pt.
r + Pt.
g - Pt.
b + Pt.
a; fDir[2] += f * f;
875 f = Pt.
r + Pt.
g - Pt.
b - Pt.
a; fDir[3] += f * f;
876 f = Pt.
r - Pt.
g + Pt.
b + Pt.
a; fDir[4] += f * f;
877 f = Pt.
r - Pt.
g + Pt.
b - Pt.
a; fDir[5] += f * f;
878 f = Pt.
r - Pt.
g - Pt.
b + Pt.
a; fDir[6] += f * f;
879 f = Pt.
r - Pt.
g - Pt.
b - Pt.
a; fDir[7] += f * f;
882 float fDirMax = fDir[0];
885 for(
size_t iDir = 1; iDir < 8; iDir++)
887 if(fDir[iDir] > fDirMax)
889 fDirMax = fDir[iDir];
894 if(iDirMax & 4) std::swap(X.g, Y.
g);
895 if(iDirMax & 2) std::swap(X.b, Y.
b);
896 if(iDirMax & 1) std::swap(X.a, Y.
a);
899 if(fAB < 1.0f / 4096.0f)
907 float fSteps = (float) (cSteps - 1);
909 for(
size_t iIteration = 0; iIteration < 8 && fError > 0.0f; iIteration++)
916 lX = (X * 255.0f).ToLDRColorA();
917 lY = (Y * 255.0f).ToLDRColorA();
919 for(
size_t iStep = 0; iStep < cSteps; iStep++)
921 pSteps[iStep] = X * pC[iStep] + Y * pD[iStep];
927 float fLen = Dir * Dir;
928 if(fLen < (1.0f / 4096.0f))
931 float fScale = fSteps / fLen;
935 float d2X = 0.0f, d2Y = 0.0f;
936 HDRColorA dX(0.0f, 0.0f, 0.0f, 0.0f), dY(0.0f, 0.0f, 0.0f, 0.0f);
938 for(
size_t iPoint = 0; iPoint < cPixels; ++iPoint)
940 float fDot = (pPoints[pIndex[iPoint]] - X) * Dir;
947 iStep = size_t(fDot + 0.5f);
949 HDRColorA Diff = pSteps[iStep] - pPoints[pIndex[iPoint]];
950 float fC = pC[iStep] * (1.0f / 8.0f);
951 float fD = pD[iStep] * (1.0f / 8.0f);
953 d2X += fC * pC[iStep];
956 d2Y += fD * pD[iStep];
963 float f = -1.0f / d2X;
969 float f = -1.0f / d2Y;
986 _In_
uint8_t uIndexPrec, _In_
uint8_t uIndexPrec2, _Out_opt_
size_t* pBestIndex =
nullptr, _Out_opt_
size_t* pBestIndex2 =
nullptr)
988 const size_t uNumIndices = size_t(1) << uIndexPrec;
989 const size_t uNumIndices2 = size_t(1) << uIndexPrec2;
991 float fBestErr = FLT_MAX;
998 XMVECTOR vpixel = XMLoadUByte4( reinterpret_cast<const XMUBYTE4*>( &pixel ) );
1000 if(uIndexPrec2 == 0)
1002 for(
register size_t i = 0; i < uNumIndices && fBestErr > 0; i++)
1004 XMVECTOR tpixel = XMLoadUByte4( reinterpret_cast<const XMUBYTE4*>( &aPalette[i] ) );
1006 tpixel = XMVectorSubtract( vpixel, tpixel );
1007 float fErr = XMVectorGetX( XMVector4Dot( tpixel, tpixel ) );
1017 fTotalErr += fBestErr;
1021 for(
register size_t i = 0; i < uNumIndices && fBestErr > 0; i++)
1023 XMVECTOR tpixel = XMLoadUByte4( reinterpret_cast<const XMUBYTE4*>( &aPalette[i] ) );
1025 tpixel = XMVectorSubtract( vpixel, tpixel );
1026 float fErr = XMVectorGetX( XMVector3Dot( tpixel, tpixel ) );
1036 fTotalErr += fBestErr;
1038 for(
register size_t i = 0; i < uNumIndices2 && fBestErr > 0; i++)
1041 float ea = float(pixel.a) - float(aPalette[i].
a);
1052 fTotalErr += fBestErr;
1065 pOut[i] =
HDRColorA(1.0f, 0.0f, 1.0f, 1.0f);
1068 pOut[i] =
HDRColorA(0.0f, 0.0f, 0.0f, 1.0f);
1077 _Use_decl_annotations_
1082 size_t uStartBit = 0;
1083 uint8_t uMode = GetBits(uStartBit, 2);
1084 if(uMode != 0x00 && uMode != 0x01)
1086 uMode = (GetBits(uStartBit, 3) << 2) | uMode;
1090 _Analysis_assume_( uMode < 32 );
1092 if ( ms_aModeToInfo[uMode] >= 0 )
1094 assert(ms_aModeToInfo[uMode] < ARRAYSIZE(ms_aInfo));
1095 _Analysis_assume_(ms_aModeToInfo[uMode] < ARRAYSIZE(ms_aInfo));
1096 const ModeDescriptor* desc = ms_aDesc[ms_aModeToInfo[uMode]];
1098 assert(ms_aModeToInfo[uMode] < ARRAYSIZE(ms_aDesc));
1099 _Analysis_assume_(ms_aModeToInfo[uMode] < ARRAYSIZE(ms_aDesc));
1100 const ModeInfo& info = ms_aInfo[ms_aModeToInfo[uMode]];
1104 uint32_t uShape = 0;
1107 const size_t uHeaderBits = info.uPartitions > 0 ? 82 : 65;
1108 while(uStartBit < uHeaderBits)
1110 size_t uCurBit = uStartBit;
1111 if(GetBit(uStartBit))
1113 switch(desc[uCurBit].m_eField)
1115 case D: uShape |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1116 case RW: aEndPts[0].
A.
r |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1117 case RX: aEndPts[0].
B.
r |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1118 case RY: aEndPts[1].
A.
r |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1119 case RZ: aEndPts[1].
B.
r |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1120 case GW: aEndPts[0].
A.
g |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1121 case GX: aEndPts[0].
B.
g |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1122 case GY: aEndPts[1].
A.
g |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1123 case GZ: aEndPts[1].
B.
g |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1124 case BW: aEndPts[0].
A.
b |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1125 case BX: aEndPts[0].
B.
b |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1126 case BY: aEndPts[1].
A.
b |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1127 case BZ: aEndPts[1].
B.
b |= 1 << uint32_t(desc[uCurBit].m_uBit);
break;
1131 OutputDebugStringA(
"BC6H: Invalid header bits encountered during decoding\n" );
1141 _Analysis_assume_( uShape < 64 );
1148 if(bSigned || info.bTransformed)
1152 for(
size_t p = 0; p <= info.uPartitions; ++p)
1163 if(info.bTransformed)
1171 size_t uNumBits =
IsFixUpOffset(info.uPartitions, uShape, i) ? info.uIndexPrec-1 : info.uIndexPrec;
1172 if ( uStartBit + uNumBits > 128 )
1175 OutputDebugStringA(
"BC6H: Invalid block encountered during decoding\n" );
1180 uint8_t uIndex = GetBits(uStartBit, uNumBits);
1182 if ( uIndex >= ((info.uPartitions > 0) ? 8 : 16) )
1185 OutputDebugStringA(
"BC6H: Invalid index encountered during decoding\n" );
1196 int r1 = Unquantize(aEndPts[uRegion].A.r, info.RGBAPrec[0][0].r, bSigned);
1197 int g1 = Unquantize(aEndPts[uRegion].A.g, info.RGBAPrec[0][0].g, bSigned);
1198 int b1 = Unquantize(aEndPts[uRegion].A.b, info.RGBAPrec[0][0].b, bSigned);
1199 int r2 = Unquantize(aEndPts[uRegion].B.r, info.RGBAPrec[0][0].r, bSigned);
1200 int g2 = Unquantize(aEndPts[uRegion].B.g, info.RGBAPrec[0][0].g, bSigned);
1201 int b2 = Unquantize(aEndPts[uRegion].B.b, info.RGBAPrec[0][0].b, bSigned);
1209 fc.
ToF16(rgb, bSigned);
1211 pOut[i].
r = XMConvertHalfToFloat( rgb[0] );
1212 pOut[i].
g = XMConvertHalfToFloat( rgb[1] );
1213 pOut[i].
b = XMConvertHalfToFloat( rgb[2] );
1220 const char* warnstr =
"BC6H: Invalid mode encountered during decoding\n";
1223 case 0x13: warnstr =
"BC6H: Reserved mode 10011 encountered during decoding\n";
break;
1224 case 0x17: warnstr =
"BC6H: Reserved mode 10111 encountered during decoding\n";
break;
1225 case 0x1B: warnstr =
"BC6H: Reserved mode 11011 encountered during decoding\n";
break;
1226 case 0x1F: warnstr =
"BC6H: Reserved mode 11111 encountered during decoding\n";
break;
1228 OutputDebugStringA( warnstr );
1233 pOut[i] =
HDRColorA(0.0f, 0.0f, 0.0f, 1.0f);
1238 _Use_decl_annotations_
1243 EncodeParams EP(pIn, bSigned);
1245 for(EP.uMode = 0; EP.uMode < ARRAYSIZE(ms_aInfo) && EP.fBestErr > 0; ++EP.uMode)
1247 const uint8_t uShapes = ms_aInfo[EP.uMode].uPartitions ? 32 : 1;
1250 const size_t uItems = std::max<size_t>(1, uShapes >> 2);
1255 for(EP.uShape = 0; EP.uShape < uShapes; ++EP.uShape)
1257 size_t uShape = EP.uShape;
1258 afRoughMSE[uShape] = RoughMSE(&EP);
1259 auShape[uShape] =
static_cast<uint8_t>(uShape);
1263 for(
register size_t i = 0; i < uItems; i++)
1265 for(
register size_t j = i + 1; j < uShapes; j++)
1267 if(afRoughMSE[i] > afRoughMSE[j])
1269 std::swap(afRoughMSE[i], afRoughMSE[j]);
1270 std::swap(auShape[i], auShape[j]);
1275 for(
size_t i = 0; i < uItems && EP.fBestErr > 0; i++)
1277 EP.uShape = auShape[i];
1285 _Use_decl_annotations_
1286 int D3DX_BC6H::Quantize(
int iValue,
int prec,
bool bSigned)
1298 q = (prec >= 16) ? iValue : (iValue << (prec-1)) / (
F16MAX+1);
1301 assert (q > -(1 << (prec-1)) && q < (1 << (prec-1)));
1306 q = (prec >= 15) ? iValue : (iValue << prec) / (
F16MAX+1);
1307 assert (q >= 0 && q < (1 << prec));
1313 _Use_decl_annotations_
1314 int D3DX_BC6H::Unquantize(
int comp,
uint8_t uBitsPerComp,
bool bSigned)
1319 if(uBitsPerComp >= 16)
1331 if(comp == 0) unq = 0;
1332 else if(comp >= ((1 << (uBitsPerComp - 1)) - 1)) unq = 0x7FFF;
1333 else unq = ((comp << 15) + 0x4000) >> (uBitsPerComp-1);
1340 if(uBitsPerComp >= 15) unq = comp;
1341 else if(comp == 0) unq = 0;
1342 else if(comp == ((1 << uBitsPerComp) - 1)) unq = 0xFFFF;
1343 else unq = ((comp << 16) + 0x8000) >> uBitsPerComp;
1349 _Use_decl_annotations_
1350 int D3DX_BC6H::FinishUnquantize(
int comp,
bool bSigned)
1354 return (comp < 0) ? -(((-comp) * 31) >> 5) : (comp * 31) >> 5;
1358 return (comp * 31) >> 6;
1364 _Use_decl_annotations_
1365 bool D3DX_BC6H::EndPointsFit(
const EncodeParams* pEP,
const INTEndPntPair aEndPts[])
1368 const bool bTransformed = ms_aInfo[pEP->uMode].bTransformed;
1369 const bool bIsSigned = pEP->bSigned;
1370 const LDRColorA& Prec0 = ms_aInfo[pEP->uMode].RGBAPrec[0][0];
1371 const LDRColorA& Prec1 = ms_aInfo[pEP->uMode].RGBAPrec[0][1];
1372 const LDRColorA& Prec2 = ms_aInfo[pEP->uMode].RGBAPrec[1][0];
1373 const LDRColorA& Prec3 = ms_aInfo[pEP->uMode].RGBAPrec[1][1];
1376 aBits[0].r =
NBits(aEndPts[0].
A.r, bIsSigned);
1377 aBits[0].g =
NBits(aEndPts[0].
A.g, bIsSigned);
1378 aBits[0].b =
NBits(aEndPts[0].
A.b, bIsSigned);
1379 aBits[1].r =
NBits(aEndPts[0].
B.r, bTransformed || bIsSigned);
1380 aBits[1].g =
NBits(aEndPts[0].
B.g, bTransformed || bIsSigned);
1381 aBits[1].b =
NBits(aEndPts[0].
B.b, bTransformed || bIsSigned);
1382 if(aBits[0].r > Prec0.r || aBits[1].r > Prec1.r ||
1383 aBits[0].g > Prec0.g || aBits[1].g > Prec1.g ||
1384 aBits[0].b > Prec0.b || aBits[1].b > Prec1.b)
1387 if(ms_aInfo[pEP->uMode].uPartitions)
1389 aBits[2].r =
NBits(aEndPts[1].
A.r, bTransformed || bIsSigned);
1390 aBits[2].g =
NBits(aEndPts[1].
A.g, bTransformed || bIsSigned);
1391 aBits[2].b =
NBits(aEndPts[1].
A.b, bTransformed || bIsSigned);
1392 aBits[3].r =
NBits(aEndPts[1].
B.r, bTransformed || bIsSigned);
1393 aBits[3].g =
NBits(aEndPts[1].
B.g, bTransformed || bIsSigned);
1394 aBits[3].b =
NBits(aEndPts[1].
B.b, bTransformed || bIsSigned);
1396 if(aBits[2].r > Prec2.r || aBits[3].r > Prec3.r ||
1397 aBits[2].g > Prec2.g || aBits[3].g > Prec3.g ||
1398 aBits[2].b > Prec2.b || aBits[3].b > Prec3.b)
1405 _Use_decl_annotations_
1406 void D3DX_BC6H::GeneratePaletteQuantized(
const EncodeParams* pEP,
const INTEndPntPair& endPts, INTColor aPalette[])
const
1409 const size_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
1410 const size_t uNumIndices = size_t(1) << uIndexPrec;
1411 assert( uNumIndices > 0 );
1412 _Analysis_assume_( uNumIndices > 0 );
1413 const LDRColorA& Prec = ms_aInfo[pEP->uMode].RGBAPrec[0][0];
1416 INTEndPntPair unqEndPts;
1417 unqEndPts.A.r = Unquantize(endPts.A.r, Prec.r, pEP->bSigned);
1418 unqEndPts.A.g = Unquantize(endPts.A.g, Prec.g, pEP->bSigned);
1419 unqEndPts.A.b = Unquantize(endPts.A.b, Prec.b, pEP->bSigned);
1420 unqEndPts.B.r = Unquantize(endPts.B.r, Prec.r, pEP->bSigned);
1421 unqEndPts.B.g = Unquantize(endPts.B.g, Prec.g, pEP->bSigned);
1422 unqEndPts.B.b = Unquantize(endPts.B.b, Prec.b, pEP->bSigned);
1425 const int* aWeights =
nullptr;
1428 case 3: aWeights =
g_aWeights3;
assert(uNumIndices <= 8); _Analysis_assume_(uNumIndices <= 8);
break;
1429 case 4: aWeights =
g_aWeights4;
assert(uNumIndices <= 16); _Analysis_assume_(uNumIndices <= 16);
break;
1432 for(
size_t i = 0; i < uNumIndices; ++i)
1434 #pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
1435 aPalette[i] = INTColor(0,0,0);
1440 for (
size_t i = 0; i < uNumIndices; ++i)
1442 aPalette[i].r = FinishUnquantize(
1445 aPalette[i].g = FinishUnquantize(
1448 aPalette[i].b = FinishUnquantize(
1455 _Use_decl_annotations_
1456 float D3DX_BC6H::MapColorsQuantized(
const EncodeParams* pEP,
const INTColor aColors[],
size_t np,
const INTEndPntPair &endPts)
const
1460 const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
1461 const uint8_t uNumIndices = 1 << uIndexPrec;
1463 GeneratePaletteQuantized(pEP, endPts, aPalette);
1466 for(
size_t i = 0; i < np; ++i)
1468 XMVECTOR vcolors = XMLoadSInt4( reinterpret_cast<const XMINT4*>( &aColors[i] ) );
1471 XMVECTOR tpal = XMLoadSInt4( reinterpret_cast<const XMINT4*>( &aPalette[0] ) );
1472 tpal = XMVectorSubtract( vcolors, tpal );
1473 float fBestErr = XMVectorGetX( XMVector3Dot( tpal, tpal ) );
1475 for(
int j = 1; j < uNumIndices && fBestErr > 0; ++j)
1478 tpal = XMLoadSInt4( reinterpret_cast<const XMINT4*>( &aPalette[j] ) );
1479 tpal = XMVectorSubtract( vcolors, tpal );
1480 float fErr = XMVectorGetX( XMVector3Dot( tpal, tpal ) );
1481 if(fErr > fBestErr)
break;
1482 if(fErr < fBestErr) fBestErr = fErr;
1484 fTotErr += fBestErr;
1489 _Use_decl_annotations_
1490 float D3DX_BC6H::PerturbOne(
const EncodeParams* pEP,
const INTColor aColors[],
size_t np,
uint8_t ch,
1491 const INTEndPntPair& oldEndPts, INTEndPntPair& newEndPts,
float fOldErr,
int do_b)
const
1497 case 0: uPrec = ms_aInfo[pEP->uMode].RGBAPrec[0][0].r;
break;
1498 case 1: uPrec = ms_aInfo[pEP->uMode].RGBAPrec[0][0].g;
break;
1499 case 2: uPrec = ms_aInfo[pEP->uMode].RGBAPrec[0][0].b;
break;
1500 default:
assert(
false); newEndPts = oldEndPts;
return FLT_MAX;
1502 INTEndPntPair tmpEndPts;
1503 float fMinErr = fOldErr;
1507 tmpEndPts = newEndPts = oldEndPts;
1510 for(
int step = 1 << (uPrec-1); step; step >>= 1)
1512 bool bImproved =
false;
1513 for(
int sign = -1; sign <= 1; sign += 2)
1517 tmpEndPts.A[ch] = newEndPts.A[ch] + sign * step;
1518 if(tmpEndPts.A[ch] < 0 || tmpEndPts.A[ch] >= (1 << uPrec))
1523 tmpEndPts.B[ch] = newEndPts.B[ch] + sign * step;
1524 if(tmpEndPts.B[ch] < 0 || tmpEndPts.B[ch] >= (1 << uPrec))
1528 float fErr = MapColorsQuantized(pEP, aColors, np, tmpEndPts);
1534 beststep = sign * step;
1541 newEndPts.A[ch] += beststep;
1543 newEndPts.B[ch] += beststep;
1549 _Use_decl_annotations_
1550 void D3DX_BC6H::OptimizeOne(
const EncodeParams* pEP,
const INTColor aColors[],
size_t np,
float aOrgErr,
1551 const INTEndPntPair &aOrgEndPts, INTEndPntPair &aOptEndPts)
const
1554 float aOptErr = aOrgErr;
1555 aOptEndPts.A = aOrgEndPts.A;
1556 aOptEndPts.B = aOrgEndPts.B;
1558 INTEndPntPair new_a, new_b;
1559 INTEndPntPair newEndPts;
1563 for(
uint8_t ch = 0; ch < 3; ++ch)
1567 float fErr0 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_a, aOptErr, 0);
1568 float fErr1 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_b, aOptErr, 1);
1572 if(fErr0 >= aOptErr)
continue;
1573 aOptEndPts.A[ch] = new_a.A[ch];
1579 if(fErr1 >= aOptErr)
continue;
1580 aOptEndPts.B[ch] = new_b.B[ch];
1588 float fErr = PerturbOne(pEP, aColors, np, ch, aOptEndPts, newEndPts, aOptErr, do_b);
1592 aOptEndPts.A[ch] = newEndPts.A[ch];
1594 aOptEndPts.B[ch] = newEndPts.B[ch];
1601 _Use_decl_annotations_
1602 void D3DX_BC6H::OptimizeEndPoints(
const EncodeParams* pEP,
const float aOrgErr[],
const INTEndPntPair aOrgEndPts[], INTEndPntPair aOptEndPts[])
const
1605 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1610 for(
size_t p = 0; p <= uPartitions; ++p)
1618 aPixels[np++] = pEP->aIPixels[i];
1622 OptimizeOne(pEP, aPixels, np, aOrgErr[p], aOrgEndPts[p], aOptEndPts[p]);
1627 _Use_decl_annotations_
1628 void D3DX_BC6H::SwapIndices(
const EncodeParams* pEP, INTEndPntPair aEndPts[],
size_t aIndices[])
1631 const size_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1632 const size_t uNumIndices = size_t(1) << ms_aInfo[pEP->uMode].uIndexPrec;
1633 const size_t uHighIndexBit = uNumIndices >> 1;
1636 _Analysis_assume_( uPartitions < BC6H_MAX_REGIONS && pEP->uShape <
BC6H_MAX_SHAPES );
1638 for(
size_t p = 0; p <= uPartitions; ++p)
1640 size_t i =
g_aFixUp[uPartitions][pEP->uShape][p];
1642 if(aIndices[i] & uHighIndexBit)
1645 std::swap(aEndPts[p].A, aEndPts[p].B);
1649 aIndices[j] = uNumIndices - 1 - aIndices[j];
1655 _Use_decl_annotations_
1656 void D3DX_BC6H::AssignIndices(
const EncodeParams* pEP,
const INTEndPntPair aEndPts[],
size_t aIndices[],
float aTotErr[])
const
1659 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1660 const uint8_t uNumIndices = 1 << ms_aInfo[pEP->uMode].uIndexPrec;
1663 _Analysis_assume_( uPartitions < BC6H_MAX_REGIONS && pEP->uShape <
BC6H_MAX_SHAPES );
1668 for(
size_t p = 0; p <= uPartitions; ++p)
1670 GeneratePaletteQuantized(pEP, aEndPts[p], aPalette[p]);
1679 float fBestErr =
Norm(pEP->aIPixels[i], aPalette[uRegion][0]);
1682 for(
uint8_t j = 1; j < uNumIndices && fBestErr > 0; ++j)
1684 float fErr =
Norm(pEP->aIPixels[i], aPalette[uRegion][j]);
1685 if(fErr > fBestErr)
break;
1692 aTotErr[uRegion] += fBestErr;
1696 _Use_decl_annotations_
1697 void D3DX_BC6H::QuantizeEndPts(
const EncodeParams* pEP, INTEndPntPair* aQntEndPts)
const
1699 assert( pEP && aQntEndPts );
1700 const INTEndPntPair* aUnqEndPts = pEP->aUnqEndPts[pEP->uShape];
1701 const LDRColorA& Prec = ms_aInfo[pEP->uMode].RGBAPrec[0][0];
1702 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1706 for(
size_t p = 0; p <= uPartitions; ++p)
1708 aQntEndPts[p].A.r = Quantize(aUnqEndPts[p].
A.r, Prec.r, pEP->bSigned);
1709 aQntEndPts[p].A.g = Quantize(aUnqEndPts[p].
A.g, Prec.g, pEP->bSigned);
1710 aQntEndPts[p].A.b = Quantize(aUnqEndPts[p].
A.b, Prec.b, pEP->bSigned);
1711 aQntEndPts[p].B.r = Quantize(aUnqEndPts[p].
B.r, Prec.r, pEP->bSigned);
1712 aQntEndPts[p].B.g = Quantize(aUnqEndPts[p].
B.g, Prec.g, pEP->bSigned);
1713 aQntEndPts[p].B.b = Quantize(aUnqEndPts[p].
B.b, Prec.b, pEP->bSigned);
1717 _Use_decl_annotations_
1718 void D3DX_BC6H::EmitBlock(
const EncodeParams* pEP,
const INTEndPntPair aEndPts[],
const size_t aIndices[])
1721 const uint8_t uRealMode = ms_aInfo[pEP->uMode].uMode;
1722 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1723 const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
1724 const size_t uHeaderBits = uPartitions > 0 ? 82 : 65;
1725 const ModeDescriptor* desc = ms_aDesc[pEP->uMode];
1726 size_t uStartBit = 0;
1728 while(uStartBit < uHeaderBits)
1730 switch(desc[uStartBit].m_eField)
1732 case M: SetBit(uStartBit,
uint8_t(uRealMode >> desc[uStartBit].m_uBit) & 0x01);
break;
1733 case D: SetBit(uStartBit,
uint8_t(pEP->uShape >> desc[uStartBit].m_uBit) & 0x01);
break;
1734 case RW: SetBit(uStartBit,
uint8_t(aEndPts[0].
A.r >> desc[uStartBit].m_uBit) & 0x01);
break;
1735 case RX: SetBit(uStartBit,
uint8_t(aEndPts[0].
B.r >> desc[uStartBit].m_uBit) & 0x01);
break;
1736 case RY: SetBit(uStartBit,
uint8_t(aEndPts[1].
A.r >> desc[uStartBit].m_uBit) & 0x01);
break;
1737 case RZ: SetBit(uStartBit,
uint8_t(aEndPts[1].
B.r >> desc[uStartBit].m_uBit) & 0x01);
break;
1738 case GW: SetBit(uStartBit,
uint8_t(aEndPts[0].
A.g >> desc[uStartBit].m_uBit) & 0x01);
break;
1739 case GX: SetBit(uStartBit,
uint8_t(aEndPts[0].
B.g >> desc[uStartBit].m_uBit) & 0x01);
break;
1740 case GY: SetBit(uStartBit,
uint8_t(aEndPts[1].
A.g >> desc[uStartBit].m_uBit) & 0x01);
break;
1741 case GZ: SetBit(uStartBit,
uint8_t(aEndPts[1].
B.g >> desc[uStartBit].m_uBit) & 0x01);
break;
1742 case BW: SetBit(uStartBit,
uint8_t(aEndPts[0].
A.b >> desc[uStartBit].m_uBit) & 0x01);
break;
1743 case BX: SetBit(uStartBit,
uint8_t(aEndPts[0].
B.b >> desc[uStartBit].m_uBit) & 0x01);
break;
1744 case BY: SetBit(uStartBit,
uint8_t(aEndPts[1].
A.b >> desc[uStartBit].m_uBit) & 0x01);
break;
1745 case BZ: SetBit(uStartBit,
uint8_t(aEndPts[1].
B.b >> desc[uStartBit].m_uBit) & 0x01);
break;
1752 if(
IsFixUpOffset(ms_aInfo[pEP->uMode].uPartitions, pEP->uShape, i))
1753 SetBits(uStartBit, uIndexPrec - 1, static_cast<uint8_t>( aIndices[i] ));
1755 SetBits(uStartBit, uIndexPrec, static_cast<uint8_t>( aIndices[i] ));
1757 assert(uStartBit == 128);
1760 _Use_decl_annotations_
1761 void D3DX_BC6H::Refine(EncodeParams* pEP)
1764 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1768 const bool bTransformed = ms_aInfo[pEP->uMode].bTransformed;
1773 QuantizeEndPts(pEP, aOrgEndPts);
1774 AssignIndices(pEP, aOrgEndPts, aOrgIdx, aOrgErr);
1775 SwapIndices(pEP, aOrgEndPts, aOrgIdx);
1778 if(EndPointsFit(pEP, aOrgEndPts))
1780 if(bTransformed)
TransformInverse(aOrgEndPts, ms_aInfo[pEP->uMode].RGBAPrec[0][0], pEP->bSigned);
1781 OptimizeEndPoints(pEP, aOrgErr, aOrgEndPts, aOptEndPts);
1782 AssignIndices(pEP, aOptEndPts, aOptIdx, aOptErr);
1783 SwapIndices(pEP, aOptEndPts, aOptIdx);
1785 float fOrgTotErr = 0.0f, fOptTotErr = 0.0f;
1786 for(
size_t p = 0; p <= uPartitions; ++p)
1788 fOrgTotErr += aOrgErr[p];
1789 fOptTotErr += aOptErr[p];
1793 if(EndPointsFit(pEP, aOptEndPts) && fOptTotErr < fOrgTotErr && fOptTotErr < pEP->fBestErr)
1795 pEP->fBestErr = fOptTotErr;
1796 EmitBlock(pEP, aOptEndPts, aOptIdx);
1798 else if(fOrgTotErr < pEP->fBestErr)
1803 pEP->fBestErr = fOrgTotErr;
1804 EmitBlock(pEP, aOrgEndPts, aOrgIdx);
1809 _Use_decl_annotations_
1810 void D3DX_BC6H::GeneratePaletteUnquantized(
const EncodeParams* pEP,
size_t uRegion, INTColor aPalette[])
1814 _Analysis_assume_( uRegion < BC6H_MAX_REGIONS && pEP->uShape <
BC6H_MAX_SHAPES );
1815 const INTEndPntPair& endPts = pEP->aUnqEndPts[pEP->uShape][uRegion];
1816 const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
1817 const uint8_t uNumIndices = 1 << uIndexPrec;
1819 _Analysis_assume_(uNumIndices > 0);
1821 const int* aWeights =
nullptr;
1824 case 3: aWeights =
g_aWeights3;
assert(uNumIndices <= 8); _Analysis_assume_(uNumIndices <= 8);
break;
1825 case 4: aWeights =
g_aWeights4;
assert(uNumIndices <= 16); _Analysis_assume_(uNumIndices <= 16);
break;
1828 for(
size_t i = 0; i < uNumIndices; ++i)
1830 #pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
1831 aPalette[i] = INTColor(0,0,0);
1836 for(
register size_t i = 0; i < uNumIndices; ++i)
1844 _Use_decl_annotations_
1845 float D3DX_BC6H::MapColors(
const EncodeParams* pEP,
size_t uRegion,
size_t np,
const size_t* auIndex)
const
1848 const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
1849 const uint8_t uNumIndices = 1 << uIndexPrec;
1851 GeneratePaletteUnquantized(pEP, uRegion, aPalette);
1853 float fTotalErr = 0.0f;
1854 for(
size_t i = 0; i < np; ++i)
1856 float fBestErr =
Norm(pEP->aIPixels[auIndex[i]], aPalette[0]);
1857 for(
uint8_t j = 1; j < uNumIndices && fBestErr > 0.0f; ++j)
1859 float fErr =
Norm(pEP->aIPixels[auIndex[i]], aPalette[j]);
1860 if(fErr > fBestErr)
break;
1861 if(fErr < fBestErr) fBestErr = fErr;
1863 fTotalErr += fBestErr;
1869 _Use_decl_annotations_
1870 float D3DX_BC6H::RoughMSE(EncodeParams* pEP)
const
1876 INTEndPntPair* aEndPts = pEP->aUnqEndPts[pEP->uShape];
1878 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
1884 float fError = 0.0f;
1885 for(
size_t p = 0; p <= uPartitions; ++p)
1900 aEndPts[p].A = pEP->aIPixels[auPixIdx[0]];
1901 aEndPts[p].B = pEP->aIPixels[auPixIdx[0]];
1906 aEndPts[p].A = pEP->aIPixels[auPixIdx[0]];
1907 aEndPts[p].B = pEP->aIPixels[auPixIdx[1]];
1912 OptimizeRGB(pEP->aHDRPixels, &epA, &epB, 4, np, auPixIdx);
1913 aEndPts[p].A.Set(epA, pEP->bSigned);
1914 aEndPts[p].B.Set(epB, pEP->bSigned);
1922 aEndPts[p].A.Clamp(0,
F16MAX);
1923 aEndPts[p].B.Clamp(0,
F16MAX);
1926 fError += MapColors(pEP, p, np, auPixIdx);
1937 _Use_decl_annotations_
1943 while(uFirst < 128 && !GetBit(uFirst)) {}
1948 const uint8_t uPartitions = ms_aInfo[uMode].uPartitions;
1952 const uint8_t uNumEndPts = (uPartitions + 1) << 1;
1953 const uint8_t uIndexPrec = ms_aInfo[uMode].uIndexPrec;
1954 const uint8_t uIndexPrec2 = ms_aInfo[uMode].uIndexPrec2;
1956 size_t uStartBit = uMode + 1;
1958 uint8_t uShape = GetBits(uStartBit, ms_aInfo[uMode].uPartitionBits);
1962 uint8_t uRotation = GetBits(uStartBit, ms_aInfo[uMode].uRotationBits);
1965 uint8_t uIndexMode = GetBits(uStartBit, ms_aInfo[uMode].uIndexModeBits);
1966 assert( uIndexMode < 2 );
1969 const LDRColorA RGBAPrec = ms_aInfo[uMode].RGBAPrec;
1970 const LDRColorA RGBAPrecWithP = ms_aInfo[uMode].RGBAPrecWithP;
1975 for(i = 0; i < uNumEndPts; i++)
1977 if ( uStartBit + RGBAPrec.
r > 128 )
1980 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
1986 c[i].
r = GetBits(uStartBit, RGBAPrec.
r);
1990 for(i = 0; i < uNumEndPts; i++)
1992 if ( uStartBit + RGBAPrec.
g > 128 )
1995 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2001 c[i].
g = GetBits(uStartBit, RGBAPrec.
g);
2005 for(i = 0; i < uNumEndPts; i++)
2007 if ( uStartBit + RGBAPrec.
b > 128 )
2010 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2016 c[i].
b = GetBits(uStartBit, RGBAPrec.
b);
2020 for(i = 0; i < uNumEndPts; i++)
2022 if ( uStartBit + RGBAPrec.
a > 128 )
2025 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2031 c[i].
a = RGBAPrec.
a ? GetBits(uStartBit, RGBAPrec.
a) : 255;
2035 assert( ms_aInfo[uMode].uPBits <= 6 );
2036 _Analysis_assume_( ms_aInfo[uMode].uPBits <= 6 );
2037 for(i = 0; i < ms_aInfo[uMode].uPBits; i++)
2039 if ( uStartBit > 127 )
2042 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2048 P[i] = GetBit(uStartBit);
2051 if(ms_aInfo[uMode].uPBits)
2053 for(i = 0; i < uNumEndPts; i++)
2055 size_t pi = i * ms_aInfo[uMode].uPBits / uNumEndPts;
2058 if(RGBAPrec[ch] != RGBAPrecWithP[ch])
2060 c[i][ch] = (c[i][ch] << 1) | P[pi];
2066 for(i = 0; i < uNumEndPts; i++)
2068 c[i] = Unquantize(c[i], RGBAPrecWithP);
2076 size_t uNumBits =
IsFixUpOffset(ms_aInfo[uMode].uPartitions, uShape, i) ? uIndexPrec - 1 : uIndexPrec;
2077 if ( uStartBit + uNumBits > 128 )
2080 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2085 w1[i] = GetBits(uStartBit, uNumBits);
2093 size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1;
2094 if ( uStartBit + uNumBits > 128 )
2097 OutputDebugStringA(
"BC7: Invalid block encountered during decoding\n" );
2102 w2[i] = GetBits(uStartBit, uNumBits );
2110 if(uIndexPrec2 == 0)
2112 LDRColorA::Interpolate(c[uRegion << 1], c[(uRegion << 1) + 1], w1[i], w1[i], uIndexPrec, uIndexPrec, outPixel);
2118 LDRColorA::Interpolate(c[uRegion << 1], c[(uRegion << 1) + 1], w1[i], w2[i], uIndexPrec, uIndexPrec2, outPixel);
2122 LDRColorA::Interpolate(c[uRegion << 1], c[(uRegion << 1) + 1], w2[i], w1[i], uIndexPrec2, uIndexPrec, outPixel);
2128 case 1: std::swap(outPixel.
r, outPixel.
a);
break;
2129 case 2: std::swap(outPixel.
g, outPixel.
a);
break;
2130 case 3: std::swap(outPixel.
b, outPixel.
a);
break;
2139 OutputDebugStringA(
"BC7: Reserved mode 8 encountered during decoding\n" );
2142 memset( pOut, 0,
sizeof(
HDRColorA) * NUM_PIXELS_PER_BLOCK );
2146 _Use_decl_annotations_
2152 EncodeParams EP(pIn);
2153 float fMSEBest = FLT_MAX;
2157 EP.aLDRPixels[i].r =
uint8_t( std::max<float>( 0.0f, std::min<float>( 255.0f, pIn[i].r * 255.0f + 0.01f ) ) );
2158 EP.aLDRPixels[i].g =
uint8_t( std::max<float>( 0.0f, std::min<float>( 255.0f, pIn[i].g * 255.0f + 0.01f ) ) );
2159 EP.aLDRPixels[i].b =
uint8_t( std::max<float>( 0.0f, std::min<float>( 255.0f, pIn[i].
b * 255.0f + 0.01f ) ) );
2160 EP.aLDRPixels[i].a =
uint8_t( std::max<float>( 0.0f, std::min<float>( 255.0f, pIn[i].
a * 255.0f + 0.01f ) ) );
2163 for(EP.uMode = 0; EP.uMode < 8 && fMSEBest > 0; ++EP.uMode)
2165 const size_t uShapes = size_t(1) << ms_aInfo[EP.uMode].uPartitionBits;
2169 const size_t uNumRots = size_t(1) << ms_aInfo[EP.uMode].uRotationBits;
2170 const size_t uNumIdxMode = size_t(1) << ms_aInfo[EP.uMode].uIndexModeBits;
2173 const size_t uItems = std::max<size_t>(1, uShapes >> 2);
2177 for(
size_t r = 0; r < uNumRots && fMSEBest > 0; ++r)
2181 case 1:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].r, EP.aLDRPixels[i].a);
break;
2182 case 2:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].g, EP.aLDRPixels[i].a);
break;
2183 case 3:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].b, EP.aLDRPixels[i].a);
break;
2186 for(
size_t im = 0; im < uNumIdxMode && fMSEBest > 0; ++im)
2189 for(
size_t s = 0; s < uShapes; s++)
2191 afRoughMSE[
s] = RoughMSE(&EP, s, im);
2196 for(
size_t i = 0; i < uItems; i++)
2198 for(
size_t j = i + 1; j < uShapes; j++)
2200 if(afRoughMSE[i] > afRoughMSE[j])
2202 std::swap(afRoughMSE[i], afRoughMSE[j]);
2203 std::swap(auShape[i], auShape[j]);
2208 for(
size_t i = 0; i < uItems && fMSEBest > 0; i++)
2210 float fMSE = Refine(&EP, auShape[i], r, im);
2221 case 1:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].r, EP.aLDRPixels[i].a);
break;
2222 case 2:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].g, EP.aLDRPixels[i].a);
break;
2223 case 3:
for(
register size_t i = 0; i <
NUM_PIXELS_PER_BLOCK; i++) std::swap(EP.aLDRPixels[i].b, EP.aLDRPixels[i].a);
break;
2233 _Use_decl_annotations_
2234 void D3DX_BC7::GeneratePaletteQuantized(
const EncodeParams* pEP,
size_t uIndexMode,
const LDREndPntPair& endPts,
LDRColorA aPalette[])
const
2237 const size_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
2238 const size_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
2239 const size_t uNumIndices = size_t(1) << uIndexPrec;
2240 const size_t uNumIndices2 = size_t(1) << uIndexPrec2;
2241 assert( uNumIndices > 0 && uNumIndices2 > 0 );
2242 _Analysis_assume_( uNumIndices > 0 && uNumIndices2 > 0 );
2246 LDRColorA a = Unquantize(endPts.
A, ms_aInfo[pEP->uMode].RGBAPrecWithP);
2247 LDRColorA b = Unquantize(endPts.
B, ms_aInfo[pEP->uMode].RGBAPrecWithP);
2248 if(uIndexPrec2 == 0)
2250 for(
register size_t i = 0; i < uNumIndices; i++)
2255 for(
register size_t i = 0; i < uNumIndices; i++)
2257 for(
register size_t i = 0; i < uNumIndices2; i++)
2262 _Use_decl_annotations_
2263 float D3DX_BC7::PerturbOne(
const EncodeParams* pEP,
const LDRColorA aColors[],
size_t np,
size_t uIndexMode,
size_t ch,
2264 const LDREndPntPair &oldEndPts, LDREndPntPair &newEndPts,
float fOldErr,
uint8_t do_b)
const
2267 const int prec = ms_aInfo[pEP->uMode].RGBAPrecWithP[ch];
2268 LDREndPntPair tmp_endPts = newEndPts = oldEndPts;
2269 float fMinErr = fOldErr;
2270 uint8_t* pnew_c = (do_b ? &newEndPts.B[ch] : &newEndPts.A[ch]);
2271 uint8_t* ptmp_c = (do_b ? &tmp_endPts.B[ch] : &tmp_endPts.A[ch]);
2274 for(
int step = 1 << (prec-1); step; step >>= 1)
2276 bool bImproved =
false;
2278 for(
int sign = -1; sign <= 1; sign += 2)
2280 int tmp = int(*pnew_c) + sign * step;
2281 if(tmp < 0 || tmp >= (1 << prec))
2286 float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr);
2287 if(fTotalErr < fMinErr)
2290 fMinErr = fTotalErr;
2291 beststep = sign * step;
2297 *pnew_c =
uint8_t(
int(*pnew_c) + beststep);
2304 _Use_decl_annotations_
2305 void D3DX_BC7::Exhaustive(
const EncodeParams* pEP,
const LDRColorA aColors[],
size_t np,
size_t uIndexMode,
size_t ch,
2306 float& fOrgErr, LDREndPntPair& optEndPt)
const
2309 const uint8_t uPrec = ms_aInfo[pEP->uMode].RGBAPrecWithP[ch];
2310 LDREndPntPair tmpEndPt;
2317 tmpEndPt = optEndPt;
2318 int alow = std::max<int>(0, int(optEndPt.A[ch]) - delta);
2319 int ahigh = std::min<int>((1 << uPrec) - 1,
int(optEndPt.A[ch]) + delta);
2320 int blow = std::max<int>(0, int(optEndPt.B[ch]) - delta);
2321 int bhigh = std::min<int>((1 << uPrec) - 1,
int(optEndPt.B[ch]) + delta);
2325 float fBestErr = fOrgErr;
2326 if(optEndPt.A[ch] <= optEndPt.B[ch])
2329 for(
int a = alow; a <= ahigh; ++
a)
2331 for(
int b = std::max<int>(a, blow); b < bhigh; ++
b)
2336 float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr);
2349 for(
int b = blow; b < bhigh; ++
b)
2351 for(
int a = std::max<int>(b, alow); a <= ahigh; ++
a)
2356 float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr);
2367 if(fBestErr < fOrgErr)
2369 optEndPt.A[ch] = (
uint8_t) amin;
2370 optEndPt.B[ch] = (
uint8_t) bmin;
2375 _Use_decl_annotations_
2376 void D3DX_BC7::OptimizeOne(
const EncodeParams* pEP,
const LDRColorA aColors[],
size_t np,
size_t uIndexMode,
2377 float fOrgErr,
const LDREndPntPair& org, LDREndPntPair& opt)
const
2381 float fOptErr = fOrgErr;
2384 LDREndPntPair new_a, new_b;
2385 LDREndPntPair newEndPts;
2391 if(ms_aInfo[pEP->uMode].RGBAPrecWithP[ch] == 0)
2396 float fErr0 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_a, fOptErr, 0);
2397 float fErr1 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_b, fOptErr, 1);
2401 uint8_t& cnew_a = new_a.A[ch];
2402 uint8_t& cnew_b = new_a.B[ch];
2406 if(fErr0 >= fOptErr)
2414 if(fErr1 >= fOptErr)
2424 float fErr = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, newEndPts, fOptErr, do_b);
2438 Exhaustive(pEP, aColors, np, uIndexMode, ch, fOptErr, opt);
2441 _Use_decl_annotations_
2442 void D3DX_BC7::OptimizeEndPoints(
const EncodeParams* pEP,
size_t uShape,
size_t uIndexMode,
const float afOrgErr[],
2443 const LDREndPntPair aOrgEndPts[], LDREndPntPair aOptEndPts[])
const
2446 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
2452 for(
size_t p = 0; p <= uPartitions; ++p)
2458 aPixels[np++] = pEP->aLDRPixels[i];
2460 OptimizeOne(pEP, aPixels, np, uIndexMode, afOrgErr[p], aOrgEndPts[p], aOptEndPts[p]);
2464 _Use_decl_annotations_
2465 void D3DX_BC7::AssignIndices(
const EncodeParams* pEP,
size_t uShape,
size_t uIndexMode, LDREndPntPair endPts[],
size_t aIndices[],
size_t aIndices2[],
2466 float afTotErr[])
const
2472 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
2476 const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
2477 const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
2478 const uint8_t uNumIndices = 1 << uIndexPrec;
2479 const uint8_t uNumIndices2 = 1 << uIndexPrec2;
2484 const uint8_t uHighestIndexBit = uNumIndices >> 1;
2485 const uint8_t uHighestIndexBit2 = uNumIndices2 >> 1;
2489 LDREndPntPair adjusted_endPts;
2490 for(
size_t p = 0; p <= uPartitions; p++)
2492 GeneratePaletteQuantized(pEP, uIndexMode, endPts[p], aPalette[p]);
2501 afTotErr[uRegion] +=
ComputeError(pEP->aLDRPixels[i], aPalette[uRegion], uIndexPrec, uIndexPrec2, &(aIndices[i]), &(aIndices2[i]));
2505 if(uIndexPrec2 == 0)
2507 for(
register size_t p = 0; p <= uPartitions; p++)
2509 if(aIndices[
g_aFixUp[uPartitions][uShape][p]] & uHighestIndexBit)
2511 std::swap(endPts[p].A, endPts[p].B);
2514 aIndices[i] = uNumIndices - 1 - aIndices[i];
2516 assert((aIndices[
g_aFixUp[uPartitions][uShape][p]] & uHighestIndexBit) == 0);
2521 for(
register size_t p = 0; p <= uPartitions; p++)
2523 if(aIndices[
g_aFixUp[uPartitions][uShape][p]] & uHighestIndexBit)
2525 std::swap(endPts[p].
A.r, endPts[p].B.r);
2526 std::swap(endPts[p].
A.g, endPts[p].B.g);
2527 std::swap(endPts[p].
A.b, endPts[p].B.b);
2530 aIndices[i] = uNumIndices - 1 - aIndices[i];
2532 assert((aIndices[
g_aFixUp[uPartitions][uShape][p]] & uHighestIndexBit) == 0);
2534 if(aIndices2[0] & uHighestIndexBit2)
2536 std::swap(endPts[p].
A.a, endPts[p].B.a);
2538 aIndices2[i] = uNumIndices2 - 1 - aIndices2[i];
2540 assert((aIndices2[0] & uHighestIndexBit2) == 0);
2545 _Use_decl_annotations_
2546 void D3DX_BC7::EmitBlock(
const EncodeParams* pEP,
size_t uShape,
size_t uRotation,
size_t uIndexMode,
const LDREndPntPair aEndPts[],
const size_t aIndex[],
const size_t aIndex2[])
2549 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
2553 const size_t uPBits = ms_aInfo[pEP->uMode].uPBits;
2554 const size_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
2555 const size_t uIndexPrec2 = ms_aInfo[pEP->uMode].uIndexPrec2;
2556 const LDRColorA RGBAPrec = ms_aInfo[pEP->uMode].RGBAPrec;
2557 const LDRColorA RGBAPrecWithP = ms_aInfo[pEP->uMode].RGBAPrecWithP;
2559 size_t uStartBit = 0;
2560 SetBits(uStartBit, pEP->uMode, 0);
2561 SetBits(uStartBit, 1, 1);
2562 SetBits(uStartBit, ms_aInfo[pEP->uMode].uRotationBits, static_cast<uint8_t>( uRotation ));
2563 SetBits(uStartBit, ms_aInfo[pEP->uMode].uIndexModeBits, static_cast<uint8_t>( uIndexMode ));
2564 SetBits(uStartBit, ms_aInfo[pEP->uMode].uPartitionBits, static_cast<uint8_t>( uShape ));
2568 const size_t uNumEP = size_t(1 + uPartitions) << 1;
2574 for(i = 0; i <= uPartitions; i++)
2576 if(RGBAPrec[ch] == RGBAPrecWithP[ch])
2578 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].A[ch]);
2579 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].B[ch]);
2583 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].A[ch] >> 1);
2584 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].B[ch] >> 1);
2585 size_t idx = ep++ * uPBits / uNumEP;
2588 aPVote[idx] += aEndPts[i].A[ch] & 0x01;
2590 idx = ep++ * uPBits / uNumEP;
2593 aPVote[idx] += aEndPts[i].B[ch] & 0x01;
2599 for(i = 0; i < uPBits; i++)
2601 SetBits(uStartBit, 1, aPVote[i] > (aCount[i] >> 1) ? 1 : 0);
2608 for(i = 0; i <= uPartitions; i++)
2610 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].A[ch] );
2611 SetBits(uStartBit, RGBAPrec[ch], aEndPts[i].B[ch] );
2616 const size_t* aI1 = uIndexMode ? aIndex2 : aIndex;
2617 const size_t* aI2 = uIndexMode ? aIndex : aIndex2;
2620 if(
IsFixUpOffset(ms_aInfo[pEP->uMode].uPartitions, uShape, i))
2621 SetBits(uStartBit, uIndexPrec - 1, static_cast<uint8_t>( aI1[i] ));
2623 SetBits(uStartBit, uIndexPrec, static_cast<uint8_t>( aI1[i] ));
2627 SetBits(uStartBit, i ? uIndexPrec2 : uIndexPrec2 - 1, static_cast<uint8_t>( aI2[i] ));
2629 assert(uStartBit == 128);
2632 _Use_decl_annotations_
2633 float D3DX_BC7::Refine(
const EncodeParams* pEP,
size_t uShape,
size_t uRotation,
size_t uIndexMode)
2638 const LDREndPntPair* aEndPts = pEP->aEndPts[uShape];
2640 const size_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
2653 for(
register size_t p = 0; p <= uPartitions; p++)
2655 aOrgEndPts[p].A = Quantize(aEndPts[p].A, ms_aInfo[pEP->uMode].RGBAPrecWithP);
2656 aOrgEndPts[p].B = Quantize(aEndPts[p].B, ms_aInfo[pEP->uMode].RGBAPrecWithP);
2659 AssignIndices(pEP, uShape, uIndexMode, aOrgEndPts, aOrgIdx, aOrgIdx2, aOrgErr);
2660 OptimizeEndPoints(pEP, uShape, uIndexMode, aOrgErr, aOrgEndPts, aOptEndPts);
2661 AssignIndices(pEP, uShape, uIndexMode, aOptEndPts, aOptIdx, aOptIdx2, aOptErr);
2663 float fOrgTotErr = 0, fOptTotErr = 0;
2664 for(
register size_t p = 0; p <= uPartitions; p++)
2666 fOrgTotErr += aOrgErr[p];
2667 fOptTotErr += aOptErr[p];
2669 if(fOptTotErr < fOrgTotErr)
2671 EmitBlock(pEP, uShape, uRotation, uIndexMode, aOptEndPts, aOptIdx, aOptIdx2);
2676 EmitBlock(pEP, uShape, uRotation, uIndexMode, aOrgEndPts, aOrgIdx, aOrgIdx2);
2681 _Use_decl_annotations_
2682 float D3DX_BC7::MapColors(
const EncodeParams* pEP,
const LDRColorA aColors[],
size_t np,
size_t uIndexMode,
const LDREndPntPair& endPts,
float fMinErr)
const
2685 const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
2686 const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
2688 float fTotalErr = 0;
2690 GeneratePaletteQuantized(pEP, uIndexMode, endPts, aPalette);
2691 for(
register size_t i = 0; i < np; ++i)
2693 fTotalErr +=
ComputeError(aColors[i], aPalette, uIndexPrec, uIndexPrec2);
2694 if(fTotalErr > fMinErr)
2696 fTotalErr = FLT_MAX;
2704 _Use_decl_annotations_
2705 float D3DX_BC7::RoughMSE(EncodeParams* pEP,
size_t uShape,
size_t uIndexMode)
2710 LDREndPntPair* aEndPts = pEP->aEndPts[uShape];
2712 const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
2716 const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
2717 const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
2718 const uint8_t uNumIndices = 1 << uIndexPrec;
2719 const uint8_t uNumIndices2 = 1 << uIndexPrec2;
2723 for(
size_t p = 0; p <= uPartitions; p++)
2738 aEndPts[p].A = pEP->aLDRPixels[auPixIdx[0]];
2739 aEndPts[p].B = pEP->aLDRPixels[auPixIdx[0]];
2744 aEndPts[p].A = pEP->aLDRPixels[auPixIdx[0]];
2745 aEndPts[p].B = pEP->aLDRPixels[auPixIdx[1]];
2749 if(uIndexPrec2 == 0)
2752 OptimizeRGBA(pEP->aHDRPixels, &epA, &epB, 4, np, auPixIdx);
2753 epA.Clamp(0.0f, 1.0f);
2754 epB.Clamp(0.0f, 1.0f);
2757 aEndPts[p].A = epA.ToLDRColorA();
2758 aEndPts[p].B = epB.ToLDRColorA();
2762 uint8_t uMinAlpha = 255, uMaxAlpha = 0;
2765 uMinAlpha = std::min<uint8_t>(uMinAlpha, pEP->aLDRPixels[auPixIdx[i]].a);
2766 uMaxAlpha = std::max<uint8_t>(uMaxAlpha, pEP->aLDRPixels[auPixIdx[i]].a);
2770 OptimizeRGB(pEP->aHDRPixels, &epA, &epB, 4, np, auPixIdx);
2771 epA.Clamp(0.0f, 1.0f);
2772 epB.Clamp(0.0f, 1.0f);
2775 aEndPts[p].A = epA.ToLDRColorA();
2776 aEndPts[p].B = epB.ToLDRColorA();
2777 aEndPts[p].A.a = uMinAlpha;
2778 aEndPts[p].B.a = uMaxAlpha;
2782 if(uIndexPrec2 == 0)
2784 for(
size_t p = 0; p <= uPartitions; p++)
2785 for(
register size_t i = 0; i < uNumIndices; i++)
2790 for(
size_t p = 0; p <= uPartitions; p++)
2792 for(
register size_t i = 0; i < uNumIndices; i++)
2794 for(
register size_t i = 0; i < uNumIndices2; i++)
2799 float fTotalErr = 0;
2803 fTotalErr +=
ComputeError(pEP->aLDRPixels[i], aPalette[uRegion], uIndexPrec, uIndexPrec2);
2816 _Use_decl_annotations_
2820 static_assert(
sizeof(
D3DX_BC6H) == 16,
"D3DX_BC6H should be 16 bytes" );
2821 reinterpret_cast< const D3DX_BC6H*
>( pBC )->Decode(
false, reinterpret_cast<HDRColorA*>(pColor));
2824 _Use_decl_annotations_
2828 static_assert(
sizeof(
D3DX_BC6H) == 16,
"D3DX_BC6H should be 16 bytes" );
2829 reinterpret_cast< const D3DX_BC6H*
>( pBC )->Decode(
true, reinterpret_cast<HDRColorA*>(pColor));
2832 _Use_decl_annotations_
2835 UNREFERENCED_PARAMETER(flags);
2837 static_assert(
sizeof(
D3DX_BC6H) == 16,
"D3DX_BC6H should be 16 bytes" );
2838 reinterpret_cast< D3DX_BC6H*
>( pBC )->Encode(
false, reinterpret_cast<const HDRColorA*>(pColor));
2841 _Use_decl_annotations_
2844 UNREFERENCED_PARAMETER(flags);
2846 static_assert(
sizeof(
D3DX_BC6H) == 16,
"D3DX_BC6H should be 16 bytes" );
2847 reinterpret_cast< D3DX_BC6H*
>( pBC )->Encode(
true, reinterpret_cast<const HDRColorA*>(pColor));
2854 _Use_decl_annotations_
2858 static_assert(
sizeof(
D3DX_BC7) == 16,
"D3DX_BC7 should be 16 bytes" );
2859 reinterpret_cast< const D3DX_BC7*
>( pBC )->Decode(reinterpret_cast<HDRColorA*>(pColor));
2862 _Use_decl_annotations_
2865 UNREFERENCED_PARAMETER(flags);
2867 static_assert(
sizeof(
D3DX_BC7) == 16,
"D3DX_BC7 should be 16 bytes" );
2868 reinterpret_cast< D3DX_BC7*
>( pBC )->Encode(reinterpret_cast<const HDRColorA*>(pColor));
const size_t BC7_NUM_CHANNELS
void D3DXDecodeBC6HS(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC)
#define NUM_PIXELS_PER_BLOCK
static bool IsFixUpOffset(_In_range_(0, 2) size_t uPartitions, _In_range_(0, 63) size_t uShape, _In_range_(0, 15) size_t uOffset)
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ DXGI_FORMAT _In_ DWORD flags
INTColor & SignExtend(_In_ const LDRColorA &Prec)
static float ComputeError(_Inout_ const LDRColorA &pixel, _In_reads_(1<< uIndexPrec) const LDRColorA aPalette[], _In_ uint8_t uIndexPrec, _In_ uint8_t uIndexPrec2, _Out_opt_ size_t *pBestIndex=nullptr, _Out_opt_ size_t *pBestIndex2=nullptr)
size_t _In_ DXGI_FORMAT size_t _In_ TEXP_LEGACY_FORMAT _In_ DWORD flags assert(pDestination &&outSize > 0)
const size_t BC6H_MAX_SHAPES
const int32_t BC67_WEIGHT_MAX
void ToF16(_Out_writes_(3) PackedVector::HALF aF16[3], _In_ bool bSigned) const
void D3DXEncodeBC6HU(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags)
void D3DXDecodeBC6HU(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC)
static void InterpolateRGB(_In_ const LDRColorA &c0, _In_ const LDRColorA &c1, _In_ size_t wc, _In_ _In_range_(2, 4) size_t wcprec, _Out_ LDRColorA &out)
static void Interpolate(_In_ const LDRColorA &c0, _In_ const LDRColorA &c1, _In_ size_t wc, _In_ size_t wa, _In_ _In_range_(2, 4) size_t wcprec, _In_ _In_range_(2, 4) size_t waprec, _Out_ LDRColorA &out)
static void OptimizeRGB(_Out_ HDRColorA *pX, _Out_ HDRColorA *pY, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *pPoints, _In_ size_t cSteps, _In_ DWORD flags)
void Decode(_In_ bool bSigned, _Out_writes_(NUM_PIXELS_PER_BLOCK) HDRColorA *pOut) const
const int32_t BC67_WEIGHT_ROUND
static void InterpolateA(_In_ const LDRColorA &c0, _In_ const LDRColorA &c1, _In_ size_t wa, _In_range_(2, 4) _In_ size_t waprec, _Out_ LDRColorA &out)
static const uint8_t g_aFixUp[3][64][3]
void D3DXDecodeBC7(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC)
void D3DXEncodeBC6HS(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags)
_In_ size_t _In_ DXGI_FORMAT _Inout_updates_all_(count) XMVECTOR *pSource
_In_ size_t _In_ const TexMetadata _In_ DWORD _Out_writes_(nImages) Image *images
void Encode(_In_ bool bSigned, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *const pIn)
const size_t BC7_MAX_SHAPES
static const uint8_t g_aPartitionTable[3][64][16]
_In_ size_t _In_ DXGI_FORMAT _In_reads_(count) const XMVECTOR *pSource
static void TransformInverse(_Inout_updates_all_(BC6H_MAX_REGIONS) INTEndPntPair aEndPts[], _In_ const LDRColorA &Prec, _In_ bool bSigned)
void Encode(_In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *const pIn)
static int NBits(_In_ int n, _In_ bool bIsSigned)
const uint32_t BC67_WEIGHT_SHIFT
static void FillWithErrorColors(_Out_writes_(NUM_PIXELS_PER_BLOCK) HDRColorA *pOut)
static const float fEpsilon
static float OptimizeRGBA(_In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *const pPoints, _Out_ HDRColorA *pX, _Out_ HDRColorA *pY, _In_ size_t cSteps, _In_ size_t cPixels, _In_reads_(cPixels) const size_t *pIndex)
const int g_aWeights4[16]
void Decode(_Out_writes_(NUM_PIXELS_PER_BLOCK) HDRColorA *pOut) const
void D3DXEncodeBC7(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags)
static void TransformForward(_Inout_updates_all_(BC6H_MAX_REGIONS) INTEndPntPair aEndPts[])
static float Norm(_In_ const INTColor &a, _In_ const INTColor &b)