annotate ptx.c @ 5867:67e62f3367e0 libavcodec

move adx.c to adxdec.c
author aurel
date Thu, 01 Nov 2007 18:40:42 +0000
parents c16a59ef6a86
children 4acd7b248bb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
1 /*
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
2 * V.Flash PTX (.ptx) image decoder
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
3 * Copyright (c) 2007 Ivo van Poorten
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
4 *
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
5 * This file is part of FFmpeg.
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
6 *
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
11 *
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
15 * Lesser General Public License for more details.
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
16 *
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
20 */
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
21
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
22 #include "avcodec.h"
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
23
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
24 typedef struct PTXContext {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
25 AVFrame picture;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
26 } PTXContext;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
27
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
28 static int ptx_init(AVCodecContext *avctx) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
29 PTXContext *s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
30
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
31 avcodec_get_frame_defaults((AVFrame*)&s->picture);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
32 avctx->coded_frame= (AVFrame*)&s->picture;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
33 s->picture.data[0] = NULL;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
34
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
35 return 0;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
36 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
37
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
38 static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
39 uint8_t *buf, int buf_size) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
40 PTXContext * const s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
41 AVFrame *picture = data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
42 AVFrame * const p = (AVFrame *)&s->picture;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
43 unsigned int offset, w, h, y, stride, bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
44 uint8_t *ptr;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
45
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
46 offset = AV_RL16(buf);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
47 w = AV_RL16(buf+8);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
48 h = AV_RL16(buf+10);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
49 bytes_per_pixel = AV_RL16(buf+12) >> 3;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
50
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
51 if (bytes_per_pixel != 2) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
52 av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n");
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
53 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
54 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
55
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
56 avctx->pix_fmt = PIX_FMT_RGB555;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
57
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
58 if (offset != 0x2c)
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
59 av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n");
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
60
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
61 buf += offset;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
62
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
63 if (p->data[0])
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
64 avctx->release_buffer(avctx, p);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
65
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
66 if (avcodec_check_dimensions(avctx, w, h))
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
67 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
68 if (w != avctx->width || h != avctx->height)
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
69 avcodec_set_dimensions(avctx, w, h);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
70 if (avctx->get_buffer(avctx, p) < 0) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
71 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
72 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
73 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
74
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
75 p->pict_type = FF_I_TYPE;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
76
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
77 ptr = p->data[0];
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
78 stride = p->linesize[0];
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
79
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
80 for (y=0; y<h; y++) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
81 #ifdef WORDS_BIGENDIAN
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
82 unsigned int x;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
83 for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
5520
c16a59ef6a86 * renaming (ST|LD)(16|32|64) -> AV_(R|W)N(16|32|64)
romansh
parents: 5215
diff changeset
84 AV_WN16(ptr+x, AV_RL16(buf+x));
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
85 #else
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
86 memcpy(ptr, buf, w*bytes_per_pixel);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
87 #endif
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
88 ptr += stride;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
89 buf += w*bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
90 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
91
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
92 *picture = *(AVFrame *)&s->picture;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
93 *data_size = sizeof(AVPicture);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
94
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
95 return offset + w*h*bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
96 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
97
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
98 static int ptx_end(AVCodecContext *avctx) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
99 PTXContext *s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
100
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
101 if(s->picture.data[0])
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
102 avctx->release_buffer(avctx, &s->picture);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
103
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
104 return 0;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
105 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
106
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
107 AVCodec ptx_decoder = {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
108 "ptx",
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
109 CODEC_TYPE_VIDEO,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
110 CODEC_ID_PTX,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
111 sizeof(PTXContext),
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
112 ptx_init,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
113 NULL,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
114 ptx_end,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
115 ptx_decode_frame,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
116 0,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
117 NULL
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
118 };