21
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
#include "libavutil/intreadwrite.h"
24
#include "libavcodec/bytestream.h"
25
25
#include "avcodec.h"
28
static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d,
28
static inline void dxt1_decode_pixels(GetByteContext *gb, uint32_t *d,
29
29
unsigned int qstride, unsigned int flag,
31
31
unsigned int x, y, c0, c1, a = (!flag * 255u) << 24;
32
32
unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3;
33
33
uint32_t colors[4], pixels;
35
c0 = bytestream2_get_le16(gb);
36
c1 = bytestream2_get_le16(gb);
38
38
rb0 = (c0<<3 | c0<<8) & 0xf800f8;
39
39
rb1 = (c1<<3 | c1<<8) & 0xf800f8;
77
void ff_decode_dxt1(const uint8_t *s, uint8_t *dst,
77
void ff_decode_dxt1(GetByteContext *gb, uint8_t *dst,
78
78
const unsigned int w, const unsigned int h,
79
79
const unsigned int stride) {
80
80
unsigned int bx, by, qstride = stride/4;
81
81
uint32_t *d = (uint32_t *) dst;
83
83
for (by=0; by < h/4; by++, d += stride-w)
84
for (bx=0; bx < w/4; bx++, s+=8, d+=4)
85
dxt1_decode_pixels(s, d, qstride, 0, 0LL);
84
for (bx = 0; bx < w / 4; bx++, d += 4)
85
dxt1_decode_pixels(gb, d, qstride, 0, 0LL);
88
void ff_decode_dxt3(const uint8_t *s, uint8_t *dst,
88
void ff_decode_dxt3(GetByteContext *gb, uint8_t *dst,
89
89
const unsigned int w, const unsigned int h,
90
90
const unsigned int stride) {
91
91
unsigned int bx, by, qstride = stride/4;
92
92
uint32_t *d = (uint32_t *) dst;
94
94
for (by=0; by < h/4; by++, d += stride-w)
95
for (bx=0; bx < w/4; bx++, s+=16, d+=4)
96
dxt1_decode_pixels(s+8, d, qstride, 1, AV_RL64(s));
95
for (bx = 0; bx < w / 4; bx++, d += 4)
96
dxt1_decode_pixels(gb, d, qstride, 1, bytestream2_get_le64(gb));