Mercurial > libavcodec.hg
annotate msrledec.c @ 8105:b122cb798801 libavcodec
Fix illegal identifier, __ are reserved for the system.
author | diego |
---|---|
date | Mon, 03 Nov 2008 21:59:35 +0000 |
parents | f874e1d5cf07 |
children | bb310197d59f |
rev | line source |
---|---|
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
1 /* |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
2 * Micrsoft RLE Decoder |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
3 * Copyright (C) 2008 Konstantin Shishkov |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
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:
3800
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
16 * |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
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:
3800
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:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
20 */ |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
21 |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
22 /** |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
23 * @file msrledec.c |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
24 * MS RLE Decoder based on decoder by Mike Melanson and my own for TSCC |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
25 * For more information about the MS RLE format, visit: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
26 * http://www.multimedia.cx/msrle.txt |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
27 */ |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
28 |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
29 #include "avcodec.h" |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
30 |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
31 #define FETCH_NEXT_STREAM_BYTE() \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
32 if (stream_ptr >= data_size) \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
33 { \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
34 av_log(avctx, AV_LOG_ERROR, " MS RLE: stream ptr just went out of bounds (1)\n"); \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
35 return -1; \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
36 } \ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
37 stream_byte = data[stream_ptr++]; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
38 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
39 static int msrle_decode_pal4(AVCodecContext *avctx, AVPicture *pic, |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
40 const uint8_t *data, int data_size) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
41 { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
42 int stream_ptr = 0; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
43 unsigned char rle_code; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
44 unsigned char extra_byte, odd_pixel; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
45 unsigned char stream_byte; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
46 int pixel_ptr = 0; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
47 int row_dec = pic->linesize[0]; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
48 int row_ptr = (avctx->height - 1) * row_dec; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
49 int frame_size = row_dec * avctx->height; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
50 int i; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
51 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
52 while (row_ptr >= 0) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
53 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
54 rle_code = stream_byte; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
55 if (rle_code == 0) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
56 /* fetch the next byte to see how to handle escape code */ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
57 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
58 if (stream_byte == 0) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
59 /* line is done, goto the next one */ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
60 row_ptr -= row_dec; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
61 pixel_ptr = 0; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
62 } else if (stream_byte == 1) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
63 /* decode is done */ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
64 return 0; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
65 } else if (stream_byte == 2) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
66 /* reposition frame decode coordinates */ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
67 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
68 pixel_ptr += stream_byte; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
69 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
70 row_ptr -= stream_byte * row_dec; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
71 } else { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
72 // copy pixels from encoded stream |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
73 odd_pixel = stream_byte & 1; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
74 rle_code = (stream_byte + 1) / 2; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
75 extra_byte = rle_code & 0x01; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
76 if ((row_ptr + pixel_ptr + stream_byte > frame_size) || |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
77 (row_ptr < 0)) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
78 av_log(avctx, AV_LOG_ERROR, " MS RLE: frame ptr just went out of bounds (1)\n"); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
79 return -1; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
80 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
81 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
82 for (i = 0; i < rle_code; i++) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
83 if (pixel_ptr >= avctx->width) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
84 break; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
85 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
86 pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
87 pixel_ptr++; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
88 if (i + 1 == rle_code && odd_pixel) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
89 break; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
90 if (pixel_ptr >= avctx->width) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
91 break; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
92 pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
93 pixel_ptr++; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
94 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
95 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
96 // if the RLE code is odd, skip a byte in the stream |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
97 if (extra_byte) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
98 stream_ptr++; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
99 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
100 } else { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
101 // decode a run of data |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
102 if ((row_ptr + pixel_ptr + stream_byte > frame_size) || |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
103 (row_ptr < 0)) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
104 av_log(avctx, AV_LOG_ERROR, " MS RLE: frame ptr just went out of bounds (1)\n"); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
105 return -1; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
106 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
107 FETCH_NEXT_STREAM_BYTE(); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
108 for (i = 0; i < rle_code; i++) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
109 if (pixel_ptr >= avctx->width) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
110 break; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
111 if ((i & 1) == 0) |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
112 pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
113 else |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
114 pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
115 pixel_ptr++; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
116 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
117 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
118 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
119 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
120 /* one last sanity check on the way out */ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
121 if (stream_ptr < data_size) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
122 av_log(avctx, AV_LOG_ERROR, " MS RLE: ended frame decode with bytes left over (%d < %d)\n", |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
123 stream_ptr, data_size); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
124 return -1; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
125 } |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
126 |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
127 return 0; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
128 } |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
129 |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
130 |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
131 static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth, |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
132 const uint8_t *data, int srcsize) |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
133 { |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
134 uint8_t *output, *output_end; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
135 const uint8_t* src = data; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
136 int p1, p2, line=avctx->height, pos=0, i; |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
137 uint16_t pix16; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
138 uint32_t pix32; |
2967 | 139 |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
140 output = pic->data[0] + (avctx->height - 1) * pic->linesize[0]; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
141 output_end = pic->data[0] + (avctx->height) * pic->linesize[0]; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
142 while(src < data + srcsize) { |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
143 p1 = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
144 if(p1 == 0) { //Escape code |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
145 p2 = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
146 if(p2 == 0) { //End-of-line |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
147 output = pic->data[0] + (--line) * pic->linesize[0]; |
2455 | 148 if (line < 0) |
149 return -1; | |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
150 pos = 0; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
151 continue; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
152 } else if(p2 == 1) { //End-of-picture |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
153 return 0; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
154 } else if(p2 == 2) { //Skip |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
155 p1 = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
156 p2 = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
157 line -= p2; |
2455 | 158 if (line < 0) |
159 return -1; | |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
160 pos += p1; |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
161 output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3); |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
162 continue; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
163 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
164 // Copy data |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
165 if (output + p2 * (depth >> 3) > output_end) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
166 src += p2 * (depth >> 3); |
2455 | 167 continue; |
168 } | |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
169 if ((depth == 8) || (depth == 24)) { |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
170 for(i = 0; i < p2 * (depth >> 3); i++) { |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
171 *output++ = *src++; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
172 } |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
173 // RLE8 copy is actually padded - and runs are not! |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
174 if(depth == 8 && (p2 & 1)) { |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
175 src++; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
176 } |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
177 } else if (depth == 16) { |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
178 for(i = 0; i < p2; i++) { |
4364 | 179 pix16 = AV_RL16(src); |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
180 src += 2; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
181 *(uint16_t*)output = pix16; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
182 output += 2; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
183 } |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
184 } else if (depth == 32) { |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
185 for(i = 0; i < p2; i++) { |
4364 | 186 pix32 = AV_RL32(src); |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
187 src += 4; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
188 *(uint32_t*)output = pix32; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
189 output += 4; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
190 } |
2979 | 191 } |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
192 pos += p2; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
193 } else { //Run of pixels |
2481 | 194 int pix[4]; //original pixel |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
195 switch(depth){ |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
196 case 8: pix[0] = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
197 break; |
4364 | 198 case 16: pix16 = AV_RL16(src); |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
199 src += 2; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
200 *(uint16_t*)pix = pix16; |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
201 break; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
202 case 24: pix[0] = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
203 pix[1] = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
204 pix[2] = *src++; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
205 break; |
4364 | 206 case 32: pix32 = AV_RL32(src); |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
207 src += 4; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
208 *(uint32_t*)pix = pix32; |
2481 | 209 break; |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
210 } |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
211 if (output + p1 * (depth >> 3) > output_end) |
2455 | 212 continue; |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
213 for(i = 0; i < p1; i++) { |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
214 switch(depth){ |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
215 case 8: *output++ = pix[0]; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
216 break; |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
217 case 16: *(uint16_t*)output = pix16; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
218 output += 2; |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
219 break; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
220 case 24: *output++ = pix[0]; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
221 *output++ = pix[1]; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
222 *output++ = pix[2]; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
223 break; |
3121
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
224 case 32: *(uint32_t*)output = pix32; |
99cbff5f8038
make TSCC endian-safe, PPC testing courtesy of Diego B.
melanson
parents:
3036
diff
changeset
|
225 output += 4; |
2481 | 226 break; |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
227 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
228 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
229 pos += p1; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
230 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
231 } |
2967 | 232 |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
233 av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no End-of-picture code\n"); |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
234 return 0; |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
235 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
236 |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
237 |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
238 int ff_msrle_decode(AVCodecContext *avctx, AVPicture *pic, int depth, |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
239 const uint8_t* data, int data_size) |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
240 { |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
241 switch(depth){ |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
242 case 4: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
243 return msrle_decode_pal4(avctx, pic, data, data_size); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
244 case 8: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
245 case 16: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
246 case 24: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
247 case 32: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
248 return msrle_decode_8_16_24_32(avctx, pic, depth, data, data_size); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
249 default: |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
250 av_log(avctx, AV_LOG_ERROR, "Unknown depth %d\n", depth); |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
251 return -1; |
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7823
diff
changeset
|
252 } |
2170
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
253 } |
51da590b31a3
TechSmith Camtasia (TSCC) video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
254 |