00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "avcodec.h"
00025 #include "s3tc.h"
00026
00027 static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d,
00028 unsigned int qstride, unsigned int flag,
00029 uint64_t alpha) {
00030 unsigned int x, y, c0, c1, a = (!flag * 255) << 24;
00031 unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3;
00032 uint32_t colors[4], pixels;
00033
00034 c0 = AV_RL16(s);
00035 c1 = AV_RL16(s+2);
00036
00037 rb0 = (c0<<3 | c0<<8) & 0xf800f8;
00038 rb1 = (c1<<3 | c1<<8) & 0xf800f8;
00039 rb0 += (rb0>>5) & 0x070007;
00040 rb1 += (rb1>>5) & 0x070007;
00041 g0 = (c0 <<5) & 0x00fc00;
00042 g1 = (c1 <<5) & 0x00fc00;
00043 g0 += (g0 >>6) & 0x000300;
00044 g1 += (g1 >>6) & 0x000300;
00045
00046 colors[0] = rb0 + g0 + a;
00047 colors[1] = rb1 + g1 + a;
00048
00049 if (c0 > c1 || flag) {
00050 rb2 = (((2*rb0+rb1) * 21) >> 6) & 0xff00ff;
00051 rb3 = (((2*rb1+rb0) * 21) >> 6) & 0xff00ff;
00052 g2 = (((2*g0 +g1 ) * 21) >> 6) & 0x00ff00;
00053 g3 = (((2*g1 +g0 ) * 21) >> 6) & 0x00ff00;
00054 colors[3] = rb3 + g3 + a;
00055 } else {
00056 rb2 = ((rb0+rb1) >> 1) & 0xff00ff;
00057 g2 = ((g0 +g1 ) >> 1) & 0x00ff00;
00058 colors[3] = 0;
00059 }
00060
00061 colors[2] = rb2 + g2 + a;
00062
00063 pixels = AV_RL32(s+4);
00064 for (y=0; y<4; y++) {
00065 for (x=0; x<4; x++) {
00066 a = (alpha & 0x0f) << 28;
00067 a += a >> 4;
00068 d[x] = a + colors[pixels&3];
00069 pixels >>= 2;
00070 alpha >>= 4;
00071 }
00072 d += qstride;
00073 }
00074 }
00075
00076 void ff_decode_dxt1(const uint8_t *s, uint8_t *dst,
00077 const unsigned int w, const unsigned int h,
00078 const unsigned int stride) {
00079 unsigned int bx, by, qstride = stride/4;
00080 uint32_t *d = (uint32_t *) dst;
00081
00082 for (by=0; by < h/4; by++, d += stride-w)
00083 for (bx=0; bx < w/4; bx++, s+=8, d+=4)
00084 dxt1_decode_pixels(s, d, qstride, 0, 0LL);
00085 }
00086
00087 void ff_decode_dxt3(const uint8_t *s, uint8_t *dst,
00088 const unsigned int w, const unsigned int h,
00089 const unsigned int stride) {
00090 unsigned int bx, by, qstride = stride/4;
00091 uint32_t *d = (uint32_t *) dst;
00092
00093 for (by=0; by < h/4; by++, d += stride-w)
00094 for (bx=0; bx < w/4; bx++, s+=16, d+=4)
00095 dxt1_decode_pixels(s+8, d, qstride, 1, AV_RL64(s));
00096 }