annotate msrle.c @ 8238:93ee77578391 libavcodec

More OKed parts of the QCELP decoder patch by Kenan Gillet, kenan.gillet gmail com
author vitor
date Mon, 01 Dec 2008 22:07:00 +0000
parents f874e1d5cf07
children e9d9d946f213
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
1 /*
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
2 * Micrsoft RLE Video Decoder
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
3 * Copyright (C) 2003 the ffmpeg project
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
15 * Lesser General Public License for more details.
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
16 *
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2453
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
20 */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
21
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
22 /**
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
23 * @file msrle.c
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
24 * MS RLE Video Decoder by Mike Melanson (melanson@pcisys.net)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
25 * For more information about the MS RLE format, visit:
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
26 * http://www.pcisys.net/~melanson/codecs/
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
27 *
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
28 * The MS RLE decoder outputs PAL8 colorspace data.
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
29 *
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
30 * Note that this decoder expects the palette colors from the end of the
1595
b2fecae88e84 Moved to new palette API
rtognimp
parents: 1592
diff changeset
31 * BITMAPINFO header passed through palctrl.
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
32 */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
33
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
34 #include <stdio.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
35 #include <stdlib.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
36 #include <string.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
37 #include <unistd.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
38
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
39 #include "avcodec.h"
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
40 #include "dsputil.h"
7885
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
41 #include "msrledec.h"
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
42
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
43 typedef struct MsrleContext {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
44 AVCodecContext *avctx;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
45 AVFrame frame;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
46
6218
michael
parents: 4962
diff changeset
47 const unsigned char *buf;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
48 int size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
49
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
50 } MsrleContext;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
51
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
52 static av_cold int msrle_decode_init(AVCodecContext *avctx)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
53 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
54 MsrleContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
55
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
56 s->avctx = avctx;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
57
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
58 avctx->pix_fmt = PIX_FMT_PAL8;
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
59 s->frame.data[0] = NULL;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
60
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
61 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
62 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
63
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
64 static int msrle_decode_frame(AVCodecContext *avctx,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
65 void *data, int *data_size,
6218
michael
parents: 4962
diff changeset
66 const uint8_t *buf, int buf_size)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
67 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
68 MsrleContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
69
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
70 s->buf = buf;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
71 s->size = buf_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
72
1592
63009885ca88 100l: free previous frame, not current one!
rtognimp
parents: 1591
diff changeset
73 s->frame.reference = 1;
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
74 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
75 if (avctx->reget_buffer(avctx, &s->frame)) {
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
76 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
77 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
78 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
79
7885
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
80 /* make the palette available */
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
81 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
82 if (s->avctx->palctrl->palette_changed) {
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
83 s->frame.palette_has_changed = 1;
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
84 s->avctx->palctrl->palette_changed = 0;
1609
7f4d1ab4ac17 4bpp support
rtognimp
parents: 1607
diff changeset
85 }
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
86
7885
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
87 ff_msrle_decode(avctx, &s->frame, avctx->bits_per_coded_sample, buf, buf_size);
f874e1d5cf07 Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents: 7823
diff changeset
88
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
89 *data_size = sizeof(AVFrame);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
90 *(AVFrame*)data = s->frame;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
91
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
92 /* report that the buffer was completely consumed */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
93 return buf_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
94 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
95
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
96 static av_cold int msrle_decode_end(AVCodecContext *avctx)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
97 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
98 MsrleContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
99
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
100 /* release the last frame */
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
101 if (s->frame.data[0])
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
102 avctx->release_buffer(avctx, &s->frame);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
103
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
104 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
105 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
106
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
107 AVCodec msrle_decoder = {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
108 "msrle",
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
109 CODEC_TYPE_VIDEO,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
110 CODEC_ID_MSRLE,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
111 sizeof(MsrleContext),
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
112 msrle_decode_init,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
113 NULL,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
114 msrle_decode_end,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
115 msrle_decode_frame,
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1609
diff changeset
116 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6717
diff changeset
117 .long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"),
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
118 };