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