2
* V.Flash PTX (.ptx) image decoder
3
* Copyright (c) 2007 Ivo van Poorten
5
* This file is part of FFmpeg.
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.
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.
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
24
typedef struct PTXContext {
28
static av_cold int ptx_init(AVCodecContext *avctx) {
29
PTXContext *s = avctx->priv_data;
31
avcodec_get_frame_defaults(&s->picture);
32
avctx->coded_frame= &s->picture;
37
static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
38
const uint8_t *buf, int buf_size) {
39
PTXContext * const s = avctx->priv_data;
40
AVFrame *picture = data;
41
AVFrame * const p = &s->picture;
42
unsigned int offset, w, h, y, stride, bytes_per_pixel;
45
offset = AV_RL16(buf);
48
bytes_per_pixel = AV_RL16(buf+12) >> 3;
50
if (bytes_per_pixel != 2) {
51
av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n");
55
avctx->pix_fmt = PIX_FMT_RGB555;
58
av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n");
63
avctx->release_buffer(avctx, p);
65
if (avcodec_check_dimensions(avctx, w, h))
67
if (w != avctx->width || h != avctx->height)
68
avcodec_set_dimensions(avctx, w, h);
69
if (avctx->get_buffer(avctx, p) < 0) {
70
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
74
p->pict_type = FF_I_TYPE;
77
stride = p->linesize[0];
80
#ifdef WORDS_BIGENDIAN
82
for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
83
AV_WN16(ptr+x, AV_RL16(buf+x));
85
memcpy(ptr, buf, w*bytes_per_pixel);
88
buf += w*bytes_per_pixel;
91
*picture = s->picture;
92
*data_size = sizeof(AVPicture);
94
return offset + w*h*bytes_per_pixel;
97
static av_cold int ptx_end(AVCodecContext *avctx) {
98
PTXContext *s = avctx->priv_data;
100
if(s->picture.data[0])
101
avctx->release_buffer(avctx, &s->picture);
106
AVCodec ptx_decoder = {
117
.long_name = "V.Flash PTX image",