28 #include "shared/shared.h"
29 #include "common/cvar.h"
30 #include "refresh/images.h"
33 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 7, 8, 3, 5, 13, 15,
34 1, 1, 2, 10, 1, 1, 2, 10, 3, 5, 8, 8, 3, 5, 6, 8,
35 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 12, 14, 3, 5, 9, 16,
36 1, 1, 2, 10, 1, 1, 2, 10, 3, 5, 9, 8, 3, 5, 6, 16,
37 1, 1, 2, 4, 1, 1, 2, 4, 3, 11, 8, 8, 3, 11, 9, 8,
38 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 8, 3, 5, 9, 8,
39 1, 1, 2, 4, 1, 1, 2, 4, 3, 11, 6, 8, 3, 11, 6, 16,
40 1, 1, 2, 4, 1, 1, 2, 10, 3, 5, 9, 8, 3, 11, 6, 16,
41 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 7, 8, 3, 5, 13, 15,
42 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 8, 3, 5, 9, 8,
43 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 12, 14, 3, 5, 9, 16,
44 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 14, 3, 5, 6, 16,
45 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 8, 3, 5, 9, 15,
46 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 8, 3, 5, 6, 8,
47 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 9, 8, 3, 5, 6, 16,
48 1, 1, 2, 4, 1, 1, 2, 4, 3, 5, 6, 8, 3, 5, 6, 16,
55 static q_noinline
int diff(uint32_t A_u32, uint32_t B_u32)
63 if (A.u8[3] == 0 &&
B.u8[3] == 0)
66 if (A.u8[3] == 0 ||
B.u8[3] == 0)
71 if (abs(a - b) >
maxY)
76 if (abs(a - b) >
maxCb)
81 if (abs(a - b) >
maxCr)
87 static inline int same(uint32_t A, uint32_t
B)
92 static inline uint64_t
grow(uint64_t n)
95 n &= UINT64_C(0xff00ff00ff00ff);
99 static inline uint32_t
pack(uint64_t n)
101 n &= UINT64_C(0xff00ff00ff00ff);
126 static q_noinline uint32_t
blend_2_1_1(uint32_t A, uint32_t
B, uint32_t C)
131 static q_noinline uint32_t
blend_5_2_1(uint32_t A, uint32_t
B, uint32_t C)
136 static q_noinline uint32_t
blend_6_1_1(uint32_t A, uint32_t
B, uint32_t C)
141 static q_noinline uint32_t
blend_2_3_3(uint32_t A, uint32_t
B, uint32_t C)
151 static q_noinline uint32_t
hq2x_blend(
int rule, uint32_t
E, uint32_t A, uint32_t
B, uint32_t D, uint32_t
F, uint32_t
H)
185 Com_Error(ERR_FATAL,
"%s: bad rule %d", __func__, rule);
190 static q_noinline
void hq4x_blend(
int rule, uint32_t *p00, uint32_t *p01, uint32_t *p10, uint32_t *p11,
191 uint32_t
E, uint32_t A, uint32_t
B, uint32_t D, uint32_t
F, uint32_t
H)
352 Com_Error(ERR_FATAL,
"%s: bad rule %d", __func__, rule);
361 for (y = 0; y <
height; y++) {
363 uint32_t *out0 = output + (y * 2 + 0) *
width * 2;
364 uint32_t *out1 = output + (y * 2 + 1) *
width * 2;
366 int prevline = (y == 0 ? 0 :
width);
369 for (x = 0; x <
width; x++) {
370 int prev = (x == 0 ? 0 : 1);
371 int next = (x ==
width - 1 ? 0 : 1);
373 uint32_t A = *(in - prevline - prev);
374 uint32_t
B = *(in - prevline);
375 uint32_t C = *(in - prevline + next);
376 uint32_t D = *(in - prev);
378 uint32_t
F = *(in + next);
379 uint32_t
G = *(in + nextline - prev);
380 uint32_t
H = *(in + nextline);
381 uint32_t
I = *(in + nextline + next);
384 pattern =
diff(
E, A) << 0;
385 pattern |=
diff(
E,
B) << 1;
386 pattern |=
diff(
E, C) << 2;
387 pattern |=
diff(
E, D) << 3;
388 pattern |=
diff(
E,
F) << 4;
389 pattern |=
diff(
E,
G) << 5;
390 pattern |=
diff(
E,
H) << 6;
391 pattern |=
diff(
E,
I) << 7;
409 for (y = 0; y <
height; y++) {
411 uint32_t *out0 = output + (y * 4 + 0) *
width * 4;
412 uint32_t *out1 = output + (y * 4 + 1) *
width * 4;
413 uint32_t *out2 = output + (y * 4 + 2) *
width * 4;
414 uint32_t *out3 = output + (y * 4 + 3) *
width * 4;
416 int prevline = (y == 0 ? 0 :
width);
419 for (x = 0; x <
width; x++) {
420 int prev = (x == 0 ? 0 : 1);
421 int next = (x ==
width - 1 ? 0 : 1);
423 uint32_t A = *(in - prevline - prev);
424 uint32_t
B = *(in - prevline);
425 uint32_t C = *(in - prevline + next);
426 uint32_t D = *(in - prev);
428 uint32_t
F = *(in + next);
429 uint32_t
G = *(in + nextline - prev);
430 uint32_t
H = *(in + nextline);
431 uint32_t
I = *(in + nextline + next);
434 pattern =
diff(
E, A) << 0;
435 pattern |=
diff(
E,
B) << 1;
436 pattern |=
diff(
E, C) << 2;
437 pattern |=
diff(
E, D) << 3;
438 pattern |=
diff(
E,
F) << 4;
439 pattern |=
diff(
E,
G) << 5;
440 pattern |=
diff(
E,
H) << 6;
441 pattern |=
diff(
E,
I) << 7;
443 hq4x_blend(
hqTable[pattern], out0 + 0, out0 + 1, out1 + 0, out1 + 1,
E, A,
B, D,
F,
H); pattern =
rotTable[pattern];
444 hq4x_blend(
hqTable[pattern], out0 + 3, out1 + 3, out0 + 2, out1 + 2,
E, C,
F,
B,
H, D); pattern =
rotTable[pattern];
445 hq4x_blend(
hqTable[pattern], out3 + 3, out3 + 2, out2 + 3, out2 + 2,
E,
I,
H,
F, D,
B); pattern =
rotTable[pattern];
446 hq4x_blend(
hqTable[pattern], out3 + 0, out2 + 0, out3 + 1, out2 + 1,
E,
G, D,
H,
B,
F);
457 #define FIX(x) (int)((x) * (1 << 16))
463 cvar_t *hqx_y =
Cvar_Get(
"hqx_y",
"48", CVAR_FILES);
464 cvar_t *hqx_cb =
Cvar_Get(
"hqx_cb",
"7", CVAR_FILES);
465 cvar_t *hqx_cr =
Cvar_Get(
"hqx_cr",
"6", CVAR_FILES);
471 for (n = 0; n < 256; n++) {
472 rotTable[n] = ((n >> 2) & 0x11) | ((n << 2) & 0x88)
473 | ((n & 0x01) << 5) | ((n & 0x08) << 3)
474 | ((n & 0x10) >> 3) | ((n & 0x80) >> 5);
478 for (n = 0; n < 256; n++) {