annotate txd.c @ 12197:fbf4d5b1b664 libavcodec

Remove FF_MM_SSE2/3 flags for CPUs where this is generally not faster than regular MMX code. Examples of this are the Core1 CPU. Instead, set a new flag, FF_MM_SSE2/3SLOW, which can be checked for particular SSE2/3 functions that have been checked specifically on such CPUs and are actually faster than their MMX counterparts. In addition, use this flag to enable particular VP8 and LPC SSE2 functions that are faster than their MMX counterparts. Based on a patch by Loren Merritt <lorenm AT u washington edu>.
author rbultje
date Mon, 19 Jul 2010 22:38:23 +0000
parents 8a4984c5cacc
children 914f484bb476
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
1 /*
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
2 * Renderware TeXture Dictionary (.txd) image decoder
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
3 * Copyright (c) 2007 Ivo van Poorten
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
4 *
5214
470601203f44 Group all copyright and author notices together.
diego
parents: 4934
diff changeset
5 * See also: http://wiki.multimedia.cx/index.php?title=TXD
470601203f44 Group all copyright and author notices together.
diego
parents: 4934
diff changeset
6 *
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
7 * This file is part of FFmpeg.
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
8 *
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
13 *
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
17 * Lesser General Public License for more details.
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
18 *
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
22 */
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
23
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7040
diff changeset
24 #include "libavutil/intreadwrite.h"
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
25 #include "avcodec.h"
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
26 #include "s3tc.h"
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
27
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
28 typedef struct TXDContext {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
29 AVFrame picture;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
30 } TXDContext;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
31
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6288
diff changeset
32 static av_cold int txd_init(AVCodecContext *avctx) {
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
33 TXDContext *s = avctx->priv_data;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
34
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
35 avcodec_get_frame_defaults(&s->picture);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
36 avctx->coded_frame = &s->picture;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
37
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
38 return 0;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
39 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
40
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
41 static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
42 AVPacket *avpkt) {
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
43 const uint8_t *buf = avpkt->data;
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
44 TXDContext * const s = avctx->priv_data;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
45 AVFrame *picture = data;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
46 AVFrame * const p = &s->picture;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
47 unsigned int version, w, h, d3d_format, depth, stride, mipmap_count, flags;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
48 unsigned int y, v;
6288
michael
parents: 6072
diff changeset
49 uint8_t *ptr;
michael
parents: 6072
diff changeset
50 const uint8_t *cur = buf;
michael
parents: 6072
diff changeset
51 const uint32_t *palette = (const uint32_t *)(cur + 88);
michael
parents: 6072
diff changeset
52 uint32_t *pal;
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
53
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
54 version = AV_RL32(cur);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
55 d3d_format = AV_RL32(cur+76);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
56 w = AV_RL16(cur+80);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
57 h = AV_RL16(cur+82);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
58 depth = AV_RL8 (cur+84);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
59 mipmap_count = AV_RL8 (cur+85);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
60 flags = AV_RL8 (cur+87);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
61 cur += 92;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
62
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
63 if (version < 8 || version > 9) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
64 av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n",
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
65 version);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
66 return -1;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
67 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
68
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
69 if (depth == 8) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
70 avctx->pix_fmt = PIX_FMT_PAL8;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
71 cur += 1024;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
72 } else if (depth == 16 || depth == 32)
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
73 avctx->pix_fmt = PIX_FMT_RGB32;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
74 else {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
75 av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
76 return -1;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
77 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
78
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
79 if (p->data[0])
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
80 avctx->release_buffer(avctx, p);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
81
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
82 if (avcodec_check_dimensions(avctx, w, h))
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
83 return -1;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
84 if (w != avctx->width || h != avctx->height)
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
85 avcodec_set_dimensions(avctx, w, h);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
86 if (avctx->get_buffer(avctx, p) < 0) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
87 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
88 return -1;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
89 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
90
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
91 p->pict_type = FF_I_TYPE;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
92
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
93 ptr = p->data[0];
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
94 stride = p->linesize[0];
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
95
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
96 if (depth == 8) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
97 pal = (uint32_t *) p->data[1];
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
98 for (y=0; y<256; y++) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
99 v = AV_RB32(palette+y);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
100 pal[y] = (v>>8) + (v<<24);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
101 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
102 for (y=0; y<h; y++) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
103 memcpy(ptr, cur, w);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
104 ptr += stride;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
105 cur += w;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
106 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
107 } else if (depth == 16) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
108 switch (d3d_format) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
109 case 0:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
110 if (!flags&1) goto unsupported;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
111 case FF_S3TC_DXT1:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
112 ff_decode_dxt1(cur, ptr, w, h, stride);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
113 break;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
114 case FF_S3TC_DXT3:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
115 ff_decode_dxt3(cur, ptr, w, h, stride);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
116 break;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
117 default:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
118 goto unsupported;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
119 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
120 } else if (depth == 32) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
121 switch (d3d_format) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
122 case 0x15:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
123 case 0x16:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
124 for (y=0; y<h; y++) {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
125 memcpy(ptr, cur, w*4);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
126 ptr += stride;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
127 cur += w*4;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
128 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
129 break;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
130 default:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
131 goto unsupported;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
132 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
133 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
134
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
135 for (; mipmap_count > 1; mipmap_count--)
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
136 cur += AV_RL32(cur) + 4;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
137
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
138 *picture = s->picture;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
139 *data_size = sizeof(AVPicture);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
140
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
141 return cur - buf;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
142
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
143 unsupported:
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
144 av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
145 return -1;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
146 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
147
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6288
diff changeset
148 static av_cold int txd_end(AVCodecContext *avctx) {
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
149 TXDContext *s = avctx->priv_data;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
150
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
151 if (s->picture.data[0])
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
152 avctx->release_buffer(avctx, &s->picture);
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
153
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
154 return 0;
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
155 }
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
156
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
157 AVCodec txd_decoder = {
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
158 "txd",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9814
diff changeset
159 AVMEDIA_TYPE_VIDEO,
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
160 CODEC_ID_TXD,
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
161 sizeof(TXDContext),
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
162 txd_init,
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
163 NULL,
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
164 txd_end,
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
165 txd_decode_frame,
9814
f2fb80b9952a renderware txd image decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9385
diff changeset
166 CODEC_CAP_DR1,
6722
6eeb19edcee3 Add long names to some AVCodec declarations.
diego
parents: 6517
diff changeset
167 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6722
diff changeset
168 .long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),
4934
feba7e1adac5 Renderware TXD decoder
ivo
parents:
diff changeset
169 };