annotate ptx.c @ 12468:443f38ceeaad libavcodec

Reimplement av_picture_data_copy() avoiding the use of PixFmtInfo information. Required for moving the function to libavcore.
author stefano
date Tue, 07 Sep 2010 21:23:52 +0000
parents ffb3668ff7af
children
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
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7040
diff changeset
22 #include "libavutil/intreadwrite.h"
12372
914f484bb476 Remove use of the deprecated function avcodec_check_dimensions(), use
stefano
parents: 11560
diff changeset
23 #include "libavcore/imgutils.h"
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
24 #include "avcodec.h"
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
25
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
26 typedef struct PTXContext {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
27 AVFrame picture;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
28 } PTXContext;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
29
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6246
diff changeset
30 static av_cold int ptx_init(AVCodecContext *avctx) {
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
31 PTXContext *s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
32
6070
4acd7b248bb8 remove useless casts
ivo
parents: 5520
diff changeset
33 avcodec_get_frame_defaults(&s->picture);
4acd7b248bb8 remove useless casts
ivo
parents: 5520
diff changeset
34 avctx->coded_frame= &s->picture;
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
35
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
36 return 0;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
37 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
38
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
39 static int ptx_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
40 AVPacket *avpkt) {
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
41 const uint8_t *buf = avpkt->data;
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
42 PTXContext * const s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
43 AVFrame *picture = data;
6075
4d43f2e3aaa5 remove useless cast
ivo
parents: 6071
diff changeset
44 AVFrame * const p = &s->picture;
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
45 unsigned int offset, w, h, y, stride, bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
46 uint8_t *ptr;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
47
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
48 offset = AV_RL16(buf);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
49 w = AV_RL16(buf+8);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
50 h = AV_RL16(buf+10);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
51 bytes_per_pixel = AV_RL16(buf+12) >> 3;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
52
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
53 if (bytes_per_pixel != 2) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
54 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
55 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
56 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
57
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
58 avctx->pix_fmt = PIX_FMT_RGB555;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
59
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
60 if (offset != 0x2c)
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
61 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
62
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
63 buf += offset;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
64
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
65 if (p->data[0])
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
66 avctx->release_buffer(avctx, p);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
67
12462
ffb3668ff7af Use new imgutils.h API names, fix deprecation warnings.
stefano
parents: 12372
diff changeset
68 if (av_image_check_size(w, h, 0, avctx))
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
69 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
70 if (w != avctx->width || h != avctx->height)
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
71 avcodec_set_dimensions(avctx, w, h);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
72 if (avctx->get_buffer(avctx, p) < 0) {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
73 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
74 return -1;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
75 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
76
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
77 p->pict_type = FF_I_TYPE;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
78
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
79 ptr = p->data[0];
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
80 stride = p->linesize[0];
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
81
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
82 for (y=0; y<h; y++) {
9985
266bf83f634d Replace WORDS_BIGENDIAN with HAVE_BIGENDIAN
mru
parents: 9805
diff changeset
83 #if HAVE_BIGENDIAN
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
84 unsigned int x;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
85 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
86 AV_WN16(ptr+x, AV_RL16(buf+x));
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
87 #else
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
88 memcpy(ptr, buf, w*bytes_per_pixel);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
89 #endif
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
90 ptr += stride;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
91 buf += w*bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
92 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
93
6070
4acd7b248bb8 remove useless casts
ivo
parents: 5520
diff changeset
94 *picture = s->picture;
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
95 *data_size = sizeof(AVPicture);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
96
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
97 return offset + w*h*bytes_per_pixel;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
98 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
99
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6246
diff changeset
100 static av_cold int ptx_end(AVCodecContext *avctx) {
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
101 PTXContext *s = avctx->priv_data;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
102
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
103 if(s->picture.data[0])
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
104 avctx->release_buffer(avctx, &s->picture);
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
105
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
106 return 0;
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
107 }
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
108
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
109 AVCodec ptx_decoder = {
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
110 "ptx",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9985
diff changeset
111 AVMEDIA_TYPE_VIDEO,
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
112 CODEC_ID_PTX,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
113 sizeof(PTXContext),
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
114 ptx_init,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
115 NULL,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
116 ptx_end,
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
117 ptx_decode_frame,
9805
7d851240d479 ptx image decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9385
diff changeset
118 CODEC_CAP_DR1,
6722
6eeb19edcee3 Add long names to some AVCodec declarations.
diego
parents: 6517
diff changeset
119 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6722
diff changeset
120 .long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"),
4884
b23051d2a676 add V.Flash PTX decoder
ivo
parents:
diff changeset
121 };