5 * Copyright (C) 2004 Daniel Borca All Rights Reserved.
7 * this is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * this is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* Copyright (C) 2007 Hiroshi Morii <koolsmoky(at)users.sourceforge.net>
23 * Added support for ARGB inputs, DXT3,5 workaround for ATI Radeons, and
24 * YUV conversions to determine representative colors.
39 /***************************************************************************\
42 * The encoder was built by reversing the decoder,
43 * and is vaguely based on FXT1 codec. Note that this code
44 * is merely a proof of concept, since it is highly UNoptimized!
45 \***************************************************************************/
48 #define MAX_COMP 4 /* ever needed maximum number of components in texel */
49 #define MAX_VECT 4 /* ever needed maximum number of base vectors to find */
50 #define N_TEXELS 16 /* number of texels in a block (always 16) */
51 #define COLOR565(v) (word)((((v)[RCOMP] & 0xf8) << 8) | (((v)[GCOMP] & 0xfc) << 3) | ((v)[BCOMP] >> 3))
54 static const int dxtn_color_tlat[2][4] = {
59 static const int dxtn_alpha_tlat[2][8] = {
60 { 0, 2, 3, 4, 5, 6, 7, 1 },
61 { 0, 2, 3, 4, 5, 1, 6, 7 }
66 dxt1_rgb_quantize (dword *cc, const byte *lines[], int comps)
68 float b, iv[MAX_COMP]; /* interpolation vector */
70 dword hi; /* high doubleword */
77 int minSum = 2000; /* big enough */
81 int maxSum = -1; /* small enough */
82 int minCol = 0; /* phoudoin: silent compiler! */
83 int maxCol = 0; /* phoudoin: silent compiler! */
85 byte input[N_TEXELS][MAX_COMP];
88 /* make the whole block opaque */
89 /* we will NEVER reference ACOMP of any pixel */
91 /* 4 texels each line */
93 for (l = 0; l < 4; l++) {
94 for (k = 0; k < 4; k++) {
95 for (i = 0; i < comps; i++) {
96 input[k + l * 4][i] = *lines[l]++;
101 /* H.Morii - support for ARGB inputs */
102 for (l = 0; l < 4; l++) {
103 for (k = 0; k < 4; k++) {
104 input[k + l * 4][2] = *lines[l]++;
105 input[k + l * 4][1] = *lines[l]++;
106 input[k + l * 4][0] = *lines[l]++;
107 if (comps == 4) input[k + l * 4][3] = *lines[l]++;
112 /* Our solution here is to find the darkest and brightest colors in
113 * the 4x4 tile and use those as the two representative colors.
114 * There are probably better algorithms to use (histogram-based).
116 for (k = 0; k < N_TEXELS; k++) {
119 for (i = 0; i < n_comp; i++) {
123 /* RGB to YUV conversion according to CCIR 601 specs
124 * Y = 0.299R+0.587G+0.114B
125 * U = 0.713(R - Y) = 0.500R-0.419G-0.081B
126 * V = 0.564(B - Y) = -0.169R-0.331G+0.500B
128 sum = 299 * input[k][RCOMP] + 587 * input[k][GCOMP] + 114 * input[k][BCOMP];
143 color0 = COLOR565(input[minCol]);
144 color1 = COLOR565(input[maxCol]);
146 if (color0 == color1) {
147 /* we'll use 3-vector */
148 cc[0] = color0 | (color1 << 16);
151 if (black && ((color0 == 0) || (color1 == 0))) {
152 /* we still can use 4-vector */
156 if (black ^ (color0 <= color1)) {
165 n_vect = (color0 <= color1) ? 2 : 3;
167 MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]);
170 cc[0] = color0 | (color1 << 16);
172 for (k = N_TEXELS - 1; k >= 0; k--) {
176 for (i = 0; i < n_comp; i++) {
181 /* interpolate color */
182 CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]);
183 texel = dxtn_color_tlat[black][texel];
195 dxt1_rgba_quantize (dword *cc, const byte *lines[], int comps)
197 float b, iv[MAX_COMP]; /* interpolation vector */
199 dword hi; /* high doubleword */
202 const int n_comp = 3;
206 int minSum = 2000; /* big enough */
208 int minSum = 2000000;
210 int maxSum = -1; /* small enough */
211 int minCol = 0; /* phoudoin: silent compiler! */
212 int maxCol = 0; /* phoudoin: silent compiler! */
214 byte input[N_TEXELS][MAX_COMP];
218 /* make the whole block opaque */
219 memset(input, -1, sizeof(input));
222 /* 4 texels each line */
224 for (l = 0; l < 4; l++) {
225 for (k = 0; k < 4; k++) {
226 for (i = 0; i < comps; i++) {
227 input[k + l * 4][i] = *lines[l]++;
232 /* H.Morii - support for ARGB inputs */
233 for (l = 0; l < 4; l++) {
234 for (k = 0; k < 4; k++) {
235 input[k + l * 4][2] = *lines[l]++;
236 input[k + l * 4][1] = *lines[l]++;
237 input[k + l * 4][0] = *lines[l]++;
238 if (comps == 4) input[k + l * 4][3] = *lines[l]++;
243 /* Our solution here is to find the darkest and brightest colors in
244 * the 4x4 tile and use those as the two representative colors.
245 * There are probably better algorithms to use (histogram-based).
247 for (k = 0; k < N_TEXELS; k++) {
250 for (i = 0; i < n_comp; i++) {
254 sum = 299 * input[k][RCOMP] + 587 * input[k][GCOMP] + 114 * input[k][BCOMP];
264 if (input[k][ACOMP] < 128) {
269 color0 = COLOR565(input[minCol]);
270 color1 = COLOR565(input[maxCol]);
272 if (color0 == color1) {
273 /* we'll use 3-vector */
274 cc[0] = color0 | (color1 << 16);
275 hi = transparent ? -1 : 0;
277 if (transparent ^ (color0 <= color1)) {
286 n_vect = (color0 <= color1) ? 2 : 3;
288 MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]);
291 cc[0] = color0 | (color1 << 16);
293 for (k = N_TEXELS - 1; k >= 0; k--) {
295 if (input[k][ACOMP] >= 128) {
296 /* interpolate color */
297 CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]);
298 texel = dxtn_color_tlat[transparent][texel];
310 dxt3_rgba_quantize (dword *cc, const byte *lines[], int comps)
312 float b, iv[MAX_COMP]; /* interpolation vector */
314 dword lolo, lohi; /* low quadword: lo dword, hi dword */
315 dword hihi; /* high quadword: high dword */
317 const int n_vect = 3;
318 const int n_comp = 3;
321 int minSum = 2000; /* big enough */
323 int minSum = 2000000;
325 int maxSum = -1; /* small enough */
326 int minCol = 0; /* phoudoin: silent compiler! */
327 int maxCol = 0; /* phoudoin: silent compiler! */
329 byte input[N_TEXELS][MAX_COMP];
333 /* make the whole block opaque */
334 memset(input, -1, sizeof(input));
337 /* 4 texels each line */
339 for (l = 0; l < 4; l++) {
340 for (k = 0; k < 4; k++) {
341 for (i = 0; i < comps; i++) {
342 input[k + l * 4][i] = *lines[l]++;
347 /* H.Morii - support for ARGB inputs */
348 for (l = 0; l < 4; l++) {
349 for (k = 0; k < 4; k++) {
350 input[k + l * 4][2] = *lines[l]++;
351 input[k + l * 4][1] = *lines[l]++;
352 input[k + l * 4][0] = *lines[l]++;
353 if (comps == 4) input[k + l * 4][3] = *lines[l]++;
358 /* Our solution here is to find the darkest and brightest colors in
359 * the 4x4 tile and use those as the two representative colors.
360 * There are probably better algorithms to use (histogram-based).
362 for (k = 0; k < N_TEXELS; k++) {
365 for (i = 0; i < n_comp; i++) {
369 sum = 299 * input[k][RCOMP] + 587 * input[k][GCOMP] + 114 * input[k][BCOMP];
383 for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) {
386 lohi |= input[k][ACOMP] >> 4;
389 for (; k >= 0; k--) {
392 lolo |= input[k][ACOMP] >> 4;
396 color0 = COLOR565(input[minCol]);
397 color1 = COLOR565(input[maxCol]);
400 /* H.Morii - Workaround for ATI Radeon
401 * According to the OpenGL EXT_texture_compression_s3tc specs,
402 * the encoding of the RGB components for DXT3 and DXT5 formats
403 * use the non-transparent encodings of DXT1 but treated as
404 * though color0 > color1, regardless of the actual values of
405 * color0 and color1. ATI Radeons however require the values to
406 * be color0 > color1.
408 if (color0 < color1) {
419 cc[2] = color0 | (color1 << 16);
422 if (color0 != color1) {
423 MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]);
426 for (k = N_TEXELS - 1; k >= 0; k--) {
428 /* interpolate color */
429 CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]);
430 texel = dxtn_color_tlat[0][texel];
441 dxt5_rgba_quantize (dword *cc, const byte *lines[], int comps)
443 float b, iv[MAX_COMP]; /* interpolation vector */
445 qword lo; /* low quadword */
446 dword hihi; /* high quadword: high dword */
448 const int n_vect = 3;
449 const int n_comp = 3;
452 int minSum = 2000; /* big enough */
454 int minSum = 2000000;
456 int maxSum = -1; /* small enough */
457 int minCol = 0; /* phoudoin: silent compiler! */
458 int maxCol = 0; /* phoudoin: silent compiler! */
459 int alpha0 = 2000; /* big enough */
460 int alpha1 = -1; /* small enough */
461 int anyZero = 0, anyOne = 0;
464 byte input[N_TEXELS][MAX_COMP];
468 /* make the whole block opaque */
469 memset(input, -1, sizeof(input));
472 /* 4 texels each line */
474 for (l = 0; l < 4; l++) {
475 for (k = 0; k < 4; k++) {
476 for (i = 0; i < comps; i++) {
477 input[k + l * 4][i] = *lines[l]++;
482 /* H.Morii - support for ARGB inputs */
483 for (l = 0; l < 4; l++) {
484 for (k = 0; k < 4; k++) {
485 input[k + l * 4][2] = *lines[l]++;
486 input[k + l * 4][1] = *lines[l]++;
487 input[k + l * 4][0] = *lines[l]++;
488 if (comps == 4) input[k + l * 4][3] = *lines[l]++;
493 /* Our solution here is to find the darkest and brightest colors in
494 * the 4x4 tile and use those as the two representative colors.
495 * There are probably better algorithms to use (histogram-based).
497 for (k = 0; k < N_TEXELS; k++) {
500 for (i = 0; i < n_comp; i++) {
504 sum = 299 * input[k][RCOMP] + 587 * input[k][GCOMP] + 114 * input[k][BCOMP];
514 if (alpha0 > input[k][ACOMP]) {
515 alpha0 = input[k][ACOMP];
517 if (alpha1 < input[k][ACOMP]) {
518 alpha1 = input[k][ACOMP];
520 if (input[k][ACOMP] == 0) {
523 if (input[k][ACOMP] == 255) {
529 if (alpha0 == alpha1) {
530 /* we'll use 6-vector */
531 cc[0] = alpha0 | (alpha1 << 8);
534 if (anyZero && ((alpha0 == 0) || (alpha1 == 0))) {
535 /* we still might use 8-vector */
538 if (anyOne && ((alpha0 == 255) || (alpha1 == 255))) {
539 /* we still might use 8-vector */
542 if ((anyZero | anyOne) ^ (alpha0 <= alpha1)) {
548 a_vect = (alpha0 <= alpha1) ? 5 : 7;
550 /* compute interpolation vector */
551 iv[ACOMP] = (float)a_vect / (alpha1 - alpha0);
552 b = -iv[ACOMP] * alpha0 + 0.5F;
556 for (k = N_TEXELS - 1; k >= 0; k--) {
558 if (anyZero | anyOne) {
559 if (input[k][ACOMP] == 0) {
561 } else if (input[k][ACOMP] == 255) {
565 /* interpolate alpha */
567 float dot = input[k][ACOMP] * iv[ACOMP];
568 texel = (int)(dot + b);
572 } else if (texel > a_vect) {
576 texel = dxtn_alpha_tlat[anyZero | anyOne][texel];
583 Q_OR32(lo, alpha0 | (alpha1 << 8));
584 ((qword *)cc)[0] = lo;
587 color0 = COLOR565(input[minCol]);
588 color1 = COLOR565(input[maxCol]);
590 #ifdef RADEON /* H.Morii - Workaround for ATI Radeon */
591 if (color0 < color1) {
602 cc[2] = color0 | (color1 << 16);
605 if (color0 != color1) {
606 MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]);
609 for (k = N_TEXELS - 1; k >= 0; k--) {
611 /* interpolate color */
612 CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]);
613 texel = dxtn_color_tlat[0][texel];
623 #define ENCODER(dxtn, n) \
625 dxtn##_encode (int width, int height, int comps, \
626 const void *source, int srcRowStride, \
627 void *dest, int destRowStride) \
631 dword *encoded = (dword *)dest; \
632 void *newSource = NULL; \
634 /* Replicate image if width is not M4 or height is not M4 */ \
635 if ((width & 3) | (height & 3)) { \
636 int newWidth = (width + 3) & ~3; \
637 int newHeight = (height + 3) & ~3; \
638 newSource = malloc(comps * newWidth * newHeight * sizeof(byte *));\
639 _mesa_upscale_teximage2d(width, height, newWidth, newHeight, \
640 comps, (const byte *)source, \
641 srcRowStride, (byte *)newSource); \
642 source = newSource; \
644 height = newHeight; \
645 srcRowStride = comps * newWidth; \
648 data = (const byte *)source; \
649 destRowStride = (destRowStride - width * n) / 4; \
650 for (y = 0; y < height; y += 4) { \
651 unsigned int offs = 0 + (y + 0) * srcRowStride; \
652 for (x = 0; x < width; x += 4) { \
653 const byte *lines[4]; \
654 lines[0] = &data[offs]; \
655 lines[1] = lines[0] + srcRowStride; \
656 lines[2] = lines[1] + srcRowStride; \
657 lines[3] = lines[2] + srcRowStride; \
659 dxtn##_quantize(encoded, lines, comps); \
663 encoded += destRowStride; \
666 if (newSource != NULL) { \
674 ENCODER(dxt1_rgba, 2)
675 ENCODER(dxt3_rgba, 4)
676 ENCODER(dxt5_rgba, 4)
679 /***************************************************************************\
682 * The decoder is based on GL_EXT_texture_compression_s3tc
683 * specification and serves as a concept for the encoder.
684 \***************************************************************************/
687 /* lookup table for scaling 4 bit colors up to 8 bits */
688 static const byte _rgb_scale_4[] = {
689 0, 17, 34, 51, 68, 85, 102, 119,
690 136, 153, 170, 187, 204, 221, 238, 255
693 /* lookup table for scaling 5 bit colors up to 8 bits */
694 static const byte _rgb_scale_5[] = {
695 0, 8, 16, 25, 33, 41, 49, 58,
696 66, 74, 82, 90, 99, 107, 115, 123,
697 132, 140, 148, 156, 165, 173, 181, 189,
698 197, 206, 214, 222, 230, 239, 247, 255
701 /* lookup table for scaling 6 bit colors up to 8 bits */
702 static const byte _rgb_scale_6[] = {
703 0, 4, 8, 12, 16, 20, 24, 28,
704 32, 36, 40, 45, 49, 53, 57, 61,
705 65, 69, 73, 77, 81, 85, 89, 93,
706 97, 101, 105, 109, 113, 117, 121, 125,
707 130, 134, 138, 142, 146, 150, 154, 158,
708 162, 166, 170, 174, 178, 182, 186, 190,
709 194, 198, 202, 206, 210, 215, 219, 223,
710 227, 231, 235, 239, 243, 247, 251, 255
714 #define CC_SEL(cc, which) (((dword *)(cc))[(which) / 32] >> ((which) & 31))
715 #define UP4(c) _rgb_scale_4[(c) & 15]
716 #define UP5(c) _rgb_scale_5[(c) & 31]
717 #define UP6(c) _rgb_scale_6[(c) & 63]
718 #define ZERO_4UBV(v) *((dword *)(v)) = 0
722 dxt1_rgb_decode_1 (const void *texture, int stride,
723 int i, int j, byte *rgba)
725 const byte *src = (const byte *)texture
726 + ((j / 4) * ((stride + 3) / 4) + i / 4) * 8;
727 const int code = (src[4 + (j & 3)] >> ((i & 3) * 2)) & 0x3;
729 rgba[RCOMP] = UP5(CC_SEL(src, 11));
730 rgba[GCOMP] = UP6(CC_SEL(src, 5));
731 rgba[BCOMP] = UP5(CC_SEL(src, 0));
732 } else if (code == 1) {
733 rgba[RCOMP] = UP5(CC_SEL(src, 27));
734 rgba[GCOMP] = UP6(CC_SEL(src, 21));
735 rgba[BCOMP] = UP5(CC_SEL(src, 16));
737 const word col0 = src[0] | (src[1] << 8);
738 const word col1 = src[2] | (src[3] << 8);
741 rgba[RCOMP] = (UP5(col0 >> 11) * 2 + UP5(col1 >> 11)) / 3;
742 rgba[GCOMP] = (UP6(col0 >> 5) * 2 + UP6(col1 >> 5)) / 3;
743 rgba[BCOMP] = (UP5(col0 ) * 2 + UP5(col1 )) / 3;
745 rgba[RCOMP] = (UP5(col0 >> 11) + 2 * UP5(col1 >> 11)) / 3;
746 rgba[GCOMP] = (UP6(col0 >> 5) + 2 * UP6(col1 >> 5)) / 3;
747 rgba[BCOMP] = (UP5(col0 ) + 2 * UP5(col1 )) / 3;
751 rgba[RCOMP] = (UP5(col0 >> 11) + UP5(col1 >> 11)) / 2;
752 rgba[GCOMP] = (UP6(col0 >> 5) + UP6(col1 >> 5)) / 2;
753 rgba[BCOMP] = (UP5(col0 ) + UP5(col1 )) / 2;
764 dxt1_rgba_decode_1 (const void *texture, int stride,
765 int i, int j, byte *rgba)
767 /* Same as rgb_dxt1 above, except alpha=0 if col0<=col1 and code=3. */
768 const byte *src = (const byte *)texture
769 + ((j / 4) * ((stride + 3) / 4) + i / 4) * 8;
770 const int code = (src[4 + (j & 3)] >> ((i & 3) * 2)) & 0x3;
772 rgba[RCOMP] = UP5(CC_SEL(src, 11));
773 rgba[GCOMP] = UP6(CC_SEL(src, 5));
774 rgba[BCOMP] = UP5(CC_SEL(src, 0));
776 } else if (code == 1) {
777 rgba[RCOMP] = UP5(CC_SEL(src, 27));
778 rgba[GCOMP] = UP6(CC_SEL(src, 21));
779 rgba[BCOMP] = UP5(CC_SEL(src, 16));
782 const word col0 = src[0] | (src[1] << 8);
783 const word col1 = src[2] | (src[3] << 8);
786 rgba[RCOMP] = (UP5(col0 >> 11) * 2 + UP5(col1 >> 11)) / 3;
787 rgba[GCOMP] = (UP6(col0 >> 5) * 2 + UP6(col1 >> 5)) / 3;
788 rgba[BCOMP] = (UP5(col0 ) * 2 + UP5(col1 )) / 3;
790 rgba[RCOMP] = (UP5(col0 >> 11) + 2 * UP5(col1 >> 11)) / 3;
791 rgba[GCOMP] = (UP6(col0 >> 5) + 2 * UP6(col1 >> 5)) / 3;
792 rgba[BCOMP] = (UP5(col0 ) + 2 * UP5(col1 )) / 3;
797 rgba[RCOMP] = (UP5(col0 >> 11) + UP5(col1 >> 11)) / 2;
798 rgba[GCOMP] = (UP6(col0 >> 5) + UP6(col1 >> 5)) / 2;
799 rgba[BCOMP] = (UP5(col0 ) + UP5(col1 )) / 2;
810 dxt3_rgba_decode_1 (const void *texture, int stride,
811 int i, int j, byte *rgba)
813 const byte *src = (const byte *)texture
814 + ((j / 4) * ((stride + 3) / 4) + i / 4) * 16;
815 const int code = (src[12 + (j & 3)] >> ((i & 3) * 2)) & 0x3;
816 const dword *cc = (const dword *)(src + 8);
818 rgba[RCOMP] = UP5(CC_SEL(cc, 11));
819 rgba[GCOMP] = UP6(CC_SEL(cc, 5));
820 rgba[BCOMP] = UP5(CC_SEL(cc, 0));
821 } else if (code == 1) {
822 rgba[RCOMP] = UP5(CC_SEL(cc, 27));
823 rgba[GCOMP] = UP6(CC_SEL(cc, 21));
824 rgba[BCOMP] = UP5(CC_SEL(cc, 16));
825 } else if (code == 2) {
826 /* (col0 * (4 - code) + col1 * (code - 1)) / 3 */
827 rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) * 2 + UP5(CC_SEL(cc, 27))) / 3;
828 rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) * 2 + UP6(CC_SEL(cc, 21))) / 3;
829 rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) * 2 + UP5(CC_SEL(cc, 16))) / 3;
831 rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) + 2 * UP5(CC_SEL(cc, 27))) / 3;
832 rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) + 2 * UP6(CC_SEL(cc, 21))) / 3;
833 rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) + 2 * UP5(CC_SEL(cc, 16))) / 3;
835 rgba[ACOMP] = UP4(src[((j & 3) * 4 + (i & 3)) / 2] >> ((i & 1) * 4));
840 dxt5_rgba_decode_1 (const void *texture, int stride,
841 int i, int j, byte *rgba)
843 const byte *src = (const byte *)texture
844 + ((j / 4) * ((stride + 3) / 4) + i / 4) * 16;
845 const int code = (src[12 + (j & 3)] >> ((i & 3) * 2)) & 0x3;
846 const dword *cc = (const dword *)(src + 8);
847 const byte alpha0 = src[0];
848 const byte alpha1 = src[1];
849 const int alphaShift = (((j & 3) * 4) + (i & 3)) * 3 + 16;
850 const int acode = ((alphaShift == 31)
851 ? CC_SEL(src + 2, alphaShift - 16)
852 : CC_SEL(src, alphaShift)) & 0x7;
854 rgba[RCOMP] = UP5(CC_SEL(cc, 11));
855 rgba[GCOMP] = UP6(CC_SEL(cc, 5));
856 rgba[BCOMP] = UP5(CC_SEL(cc, 0));
857 } else if (code == 1) {
858 rgba[RCOMP] = UP5(CC_SEL(cc, 27));
859 rgba[GCOMP] = UP6(CC_SEL(cc, 21));
860 rgba[BCOMP] = UP5(CC_SEL(cc, 16));
861 } else if (code == 2) {
862 /* (col0 * (4 - code) + col1 * (code - 1)) / 3 */
863 rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) * 2 + UP5(CC_SEL(cc, 27))) / 3;
864 rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) * 2 + UP6(CC_SEL(cc, 21))) / 3;
865 rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) * 2 + UP5(CC_SEL(cc, 16))) / 3;
867 rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) + 2 * UP5(CC_SEL(cc, 27))) / 3;
868 rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) + 2 * UP6(CC_SEL(cc, 21))) / 3;
869 rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) + 2 * UP5(CC_SEL(cc, 16))) / 3;
872 rgba[ACOMP] = alpha0;
873 } else if (acode == 1) {
874 rgba[ACOMP] = alpha1;
875 } else if (alpha0 > alpha1) {
876 rgba[ACOMP] = ((8 - acode) * alpha0 + (acode - 1) * alpha1) / 7;
877 } else if (acode == 6) {
879 } else if (acode == 7) {
882 rgba[ACOMP] = ((6 - acode) * alpha0 + (acode - 1) * alpha1) / 5;