annotate s3tc.c @ 11762:91b9bd17e79c libavcodec

aacenc: Trellis over scalefactors using an estimated codebook rather than every codebook. The minimal codebook to encode the band without clipping is used (as is done in the TLS).
author alexc
date Tue, 25 May 2010 18:31:55 +0000
parents 2acf0ae7b041
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4933
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
1 /*
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
2 * S3 Texture Compression (S3TC) decoding functions
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
3 * Copyright (c) 2007 by Ivo van Poorten
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
4 *
5214
470601203f44 Group all copyright and author notices together.
diego
parents: 4933
diff changeset
5 * see also: http://wiki.multimedia.cx/index.php?title=S3TC
470601203f44 Group all copyright and author notices together.
diego
parents: 4933
diff changeset
6 *
4933
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
7 * This file is part of FFmpeg.
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
8 *
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
13 *
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
17 * Lesser General Public License for more details.
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
18 *
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
22 */
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
23
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 6306
diff changeset
24 #include "libavutil/intreadwrite.h"
4933
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
25 #include "avcodec.h"
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
26 #include "s3tc.h"
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
27
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
28 static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
29 unsigned int qstride, unsigned int flag,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
30 uint64_t alpha) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
31 unsigned int x, y, c0, c1, a = (!flag * 255) << 24;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
32 unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
33 uint32_t colors[4], pixels;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
34
6306
23c0704067f6 use AV_RL* instead of le2me_*
aurel
parents: 5214
diff changeset
35 c0 = AV_RL16(s);
23c0704067f6 use AV_RL* instead of le2me_*
aurel
parents: 5214
diff changeset
36 c1 = AV_RL16(s+2);
4933
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
37
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
38 rb0 = (c0<<3 | c0<<8) & 0xf800f8;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
39 rb1 = (c1<<3 | c1<<8) & 0xf800f8;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
40 rb0 += (rb0>>5) & 0x070007;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
41 rb1 += (rb1>>5) & 0x070007;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
42 g0 = (c0 <<5) & 0x00fc00;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
43 g1 = (c1 <<5) & 0x00fc00;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
44 g0 += (g0 >>6) & 0x000300;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
45 g1 += (g1 >>6) & 0x000300;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
46
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
47 colors[0] = rb0 + g0 + a;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
48 colors[1] = rb1 + g1 + a;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
49
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
50 if (c0 > c1 || flag) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
51 rb2 = (((2*rb0+rb1) * 21) >> 6) & 0xff00ff;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
52 rb3 = (((2*rb1+rb0) * 21) >> 6) & 0xff00ff;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
53 g2 = (((2*g0 +g1 ) * 21) >> 6) & 0x00ff00;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
54 g3 = (((2*g1 +g0 ) * 21) >> 6) & 0x00ff00;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
55 colors[3] = rb3 + g3 + a;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
56 } else {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
57 rb2 = ((rb0+rb1) >> 1) & 0xff00ff;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
58 g2 = ((g0 +g1 ) >> 1) & 0x00ff00;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
59 colors[3] = 0;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
60 }
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
61
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
62 colors[2] = rb2 + g2 + a;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
63
6306
23c0704067f6 use AV_RL* instead of le2me_*
aurel
parents: 5214
diff changeset
64 pixels = AV_RL32(s+4);
4933
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
65 for (y=0; y<4; y++) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
66 for (x=0; x<4; x++) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
67 a = (alpha & 0x0f) << 28;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
68 a += a >> 4;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
69 d[x] = a + colors[pixels&3];
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
70 pixels >>= 2;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
71 alpha >>= 4;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
72 }
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
73 d += qstride;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
74 }
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
75 }
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
76
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
77 void ff_decode_dxt1(const uint8_t *s, uint8_t *dst,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
78 const unsigned int w, const unsigned int h,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
79 const unsigned int stride) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
80 unsigned int bx, by, qstride = stride/4;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
81 uint32_t *d = (uint32_t *) dst;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
82
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
83 for (by=0; by < h/4; by++, d += stride-w)
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
84 for (bx=0; bx < w/4; bx++, s+=8, d+=4)
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
85 dxt1_decode_pixels(s, d, qstride, 0, 0LL);
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
86 }
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
87
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
88 void ff_decode_dxt3(const uint8_t *s, uint8_t *dst,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
89 const unsigned int w, const unsigned int h,
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
90 const unsigned int stride) {
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
91 unsigned int bx, by, qstride = stride/4;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
92 uint32_t *d = (uint32_t *) dst;
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
93
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
94 for (by=0; by < h/4; by++, d += stride-w)
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
95 for (bx=0; bx < w/4; bx++, s+=16, d+=4)
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
96 dxt1_decode_pixels(s+8, d, qstride, 1, AV_RL64(s));
ed67837533b0 generic S3TC DXT1 and DXT3 decoding functions
ivo
parents:
diff changeset
97 }