Mercurial > libavcodec.hg
annotate ptx.c @ 8799:cb4441bed13a libavcodec
Rename vdpauvideo.c --> vdpau.c and xvmcvideo.c --> xvmc.c to better fit
the general libavcodec naming structure.
author | diego |
---|---|
date | Wed, 11 Feb 2009 12:01:59 +0000 |
parents | 2acf0ae7b041 |
children | 54bc8a2727b0 |
rev | line source |
---|---|
4884 | 1 /* |
2 * V.Flash PTX (.ptx) image decoder | |
3 * Copyright (c) 2007 Ivo van Poorten | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
8573
2acf0ae7b041
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
7040
diff
changeset
|
22 #include "libavutil/intreadwrite.h" |
4884 | 23 #include "avcodec.h" |
24 | |
25 typedef struct PTXContext { | |
26 AVFrame picture; | |
27 } PTXContext; | |
28 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6246
diff
changeset
|
29 static av_cold int ptx_init(AVCodecContext *avctx) { |
4884 | 30 PTXContext *s = avctx->priv_data; |
31 | |
6070 | 32 avcodec_get_frame_defaults(&s->picture); |
33 avctx->coded_frame= &s->picture; | |
4884 | 34 |
35 return 0; | |
36 } | |
37 | |
38 static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |
6246 | 39 const uint8_t *buf, int buf_size) { |
4884 | 40 PTXContext * const s = avctx->priv_data; |
41 AVFrame *picture = data; | |
6075 | 42 AVFrame * const p = &s->picture; |
4884 | 43 unsigned int offset, w, h, y, stride, bytes_per_pixel; |
44 uint8_t *ptr; | |
45 | |
46 offset = AV_RL16(buf); | |
47 w = AV_RL16(buf+8); | |
48 h = AV_RL16(buf+10); | |
49 bytes_per_pixel = AV_RL16(buf+12) >> 3; | |
50 | |
51 if (bytes_per_pixel != 2) { | |
52 av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n"); | |
53 return -1; | |
54 } | |
55 | |
56 avctx->pix_fmt = PIX_FMT_RGB555; | |
57 | |
58 if (offset != 0x2c) | |
59 av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n"); | |
60 | |
61 buf += offset; | |
62 | |
63 if (p->data[0]) | |
64 avctx->release_buffer(avctx, p); | |
65 | |
66 if (avcodec_check_dimensions(avctx, w, h)) | |
67 return -1; | |
68 if (w != avctx->width || h != avctx->height) | |
69 avcodec_set_dimensions(avctx, w, h); | |
70 if (avctx->get_buffer(avctx, p) < 0) { | |
71 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
72 return -1; | |
73 } | |
74 | |
75 p->pict_type = FF_I_TYPE; | |
76 | |
77 ptr = p->data[0]; | |
78 stride = p->linesize[0]; | |
79 | |
80 for (y=0; y<h; y++) { | |
81 #ifdef WORDS_BIGENDIAN | |
82 unsigned int x; | |
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 | 85 #else |
86 memcpy(ptr, buf, w*bytes_per_pixel); | |
87 #endif | |
88 ptr += stride; | |
89 buf += w*bytes_per_pixel; | |
90 } | |
91 | |
6070 | 92 *picture = s->picture; |
4884 | 93 *data_size = sizeof(AVPicture); |
94 | |
95 return offset + w*h*bytes_per_pixel; | |
96 } | |
97 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6246
diff
changeset
|
98 static av_cold int ptx_end(AVCodecContext *avctx) { |
4884 | 99 PTXContext *s = avctx->priv_data; |
100 | |
101 if(s->picture.data[0]) | |
102 avctx->release_buffer(avctx, &s->picture); | |
103 | |
104 return 0; | |
105 } | |
106 | |
107 AVCodec ptx_decoder = { | |
108 "ptx", | |
109 CODEC_TYPE_VIDEO, | |
110 CODEC_ID_PTX, | |
111 sizeof(PTXContext), | |
112 ptx_init, | |
113 NULL, | |
114 ptx_end, | |
115 ptx_decode_frame, | |
116 0, | |
6722 | 117 NULL, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6722
diff
changeset
|
118 .long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"), |
4884 | 119 }; |