Mercurial > libavcodec.hg
annotate qtrle.c @ 5131:757efe20a3c8 libavcodec
Blackfin dct_quantize_bfin routine
2x performance boost in performing quantization for mpeg encoding
author | mhoffman |
---|---|
date | Tue, 12 Jun 2007 19:13:50 +0000 |
parents | f99e40a7155b |
children | 2b72f9bc4f06 |
rev | line source |
---|---|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
1 /* |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
2 * Quicktime Animation (RLE) Video Decoder |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
3 * Copyright (C) 2004 the ffmpeg project |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
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 |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
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:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
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, |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
16 * |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
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:
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:
2964
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
20 * |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
21 */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
22 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
23 /** |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
24 * @file qtrle.c |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
25 * QT RLE Video Decoder by Mike Melanson (melanson@pcisys.net) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
26 * For more information about the QT RLE format, visit: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
27 * http://www.pcisys.net/~melanson/codecs/ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
28 * |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
29 * The QT RLE decoder has seven modes of operation: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
30 * 1, 2, 4, 8, 16, 24, and 32 bits per pixel. For modes 1, 2, 4, and 8 |
1881
39ad6cd5d4a6
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
1808
diff
changeset
|
31 * the decoder outputs PAL8 colorspace data. 16-bit data yields RGB555 |
4494
ce643a22f049
Replace deprecated PIX_FMT names by the newer variants.
diego
parents:
4364
diff
changeset
|
32 * data. 24-bit data is RGB24 and 32-bit data is RGB32. |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
33 */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
34 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
35 #include <stdio.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
36 #include <stdlib.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
37 #include <string.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
38 #include <unistd.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
39 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
40 #include "avcodec.h" |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
41 #include "dsputil.h" |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
42 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
43 typedef struct QtrleContext { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
44 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
45 AVCodecContext *avctx; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
46 DSPContext dsp; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
47 AVFrame frame; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
48 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
49 unsigned char *buf; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
50 int size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
51 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
52 } QtrleContext; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
53 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
54 #define CHECK_STREAM_PTR(n) \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
55 if ((stream_ptr + n) > s->size) { \ |
1807 | 56 av_log (s->avctx, AV_LOG_INFO, "Problem: stream_ptr out of bounds (%d >= %d)\n", \ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
57 stream_ptr + n, s->size); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
58 return; \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
59 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
60 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
61 #define CHECK_PIXEL_PTR(n) \ |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
62 if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \ |
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
63 av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
64 pixel_ptr + n, pixel_limit); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
65 return; \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
66 } \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
67 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
68 static void qtrle_decode_1bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
69 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
70 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
71 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
72 static void qtrle_decode_2bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
73 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
74 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
75 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
76 static void qtrle_decode_4bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
77 { |
2049 | 78 int stream_ptr; |
79 int header; | |
80 int start_line; | |
81 int lines_to_change; | |
82 int rle_code; | |
83 int row_ptr, pixel_ptr; | |
84 int row_inc = s->frame.linesize[0]; | |
85 unsigned char pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8; /* 8 palette indices */ | |
86 unsigned char *rgb = s->frame.data[0]; | |
87 int pixel_limit = s->frame.linesize[0] * s->avctx->height; | |
88 | |
89 /* check if this frame is even supposed to change */ | |
90 if (s->size < 8) | |
91 return; | |
92 | |
93 /* start after the chunk size */ | |
94 stream_ptr = 4; | |
95 | |
96 /* fetch the header */ | |
97 CHECK_STREAM_PTR(2); | |
4364 | 98 header = AV_RB16(&s->buf[stream_ptr]); |
2049 | 99 stream_ptr += 2; |
100 | |
101 /* if a header is present, fetch additional decoding parameters */ | |
102 if (header & 0x0008) { | |
103 CHECK_STREAM_PTR(8); | |
4364 | 104 start_line = AV_RB16(&s->buf[stream_ptr]); |
2049 | 105 stream_ptr += 4; |
4364 | 106 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
2049 | 107 stream_ptr += 4; |
108 } else { | |
109 start_line = 0; | |
110 lines_to_change = s->avctx->height; | |
111 } | |
112 | |
113 row_ptr = row_inc * start_line; | |
114 while (lines_to_change--) { | |
115 CHECK_STREAM_PTR(2); | |
116 pixel_ptr = row_ptr + (8 * (s->buf[stream_ptr++] - 1)); | |
117 | |
118 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { | |
119 if (rle_code == 0) { | |
120 /* there's another skip code in the stream */ | |
121 CHECK_STREAM_PTR(1); | |
122 pixel_ptr += (8 * (s->buf[stream_ptr++] - 1)); | |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
123 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
2049 | 124 } else if (rle_code < 0) { |
125 /* decode the run length code */ | |
126 rle_code = -rle_code; | |
127 /* get the next 4 bytes from the stream, treat them as palette | |
128 * indices, and output them rle_code times */ | |
129 CHECK_STREAM_PTR(4); | |
130 pi1 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
131 pi2 = (s->buf[stream_ptr++]) & 0x0f; | |
132 pi3 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
133 pi4 = (s->buf[stream_ptr++]) & 0x0f; | |
134 pi5 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
135 pi6 = (s->buf[stream_ptr++]) & 0x0f; | |
136 pi7 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
137 pi8 = (s->buf[stream_ptr++]) & 0x0f; | |
138 | |
139 CHECK_PIXEL_PTR(rle_code * 8); | |
140 | |
141 while (rle_code--) { | |
142 rgb[pixel_ptr++] = pi1; | |
143 rgb[pixel_ptr++] = pi2; | |
144 rgb[pixel_ptr++] = pi3; | |
145 rgb[pixel_ptr++] = pi4; | |
146 rgb[pixel_ptr++] = pi5; | |
147 rgb[pixel_ptr++] = pi6; | |
148 rgb[pixel_ptr++] = pi7; | |
149 rgb[pixel_ptr++] = pi8; | |
150 } | |
151 } else { | |
152 /* copy the same pixel directly to output 4 times */ | |
153 rle_code *= 4; | |
154 CHECK_STREAM_PTR(rle_code); | |
155 CHECK_PIXEL_PTR(rle_code*2); | |
156 | |
157 while (rle_code--) { | |
158 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
159 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f; | |
160 } | |
161 } | |
162 } | |
163 row_ptr += row_inc; | |
164 } | |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
165 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
166 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
167 static void qtrle_decode_8bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
168 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
169 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
170 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
171 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
172 int lines_to_change; |
1808 | 173 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
174 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
175 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
176 unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
177 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
178 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
179 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
180 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
181 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
182 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
183 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
184 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
185 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
186 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
187 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
188 CHECK_STREAM_PTR(2); |
4364 | 189 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
190 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
191 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
192 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
193 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
194 CHECK_STREAM_PTR(8); |
4364 | 195 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
196 stream_ptr += 4; |
4364 | 197 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
198 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
199 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
200 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
201 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
202 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
203 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
204 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
205 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
206 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
207 pixel_ptr = row_ptr + (4 * (s->buf[stream_ptr++] - 1)); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
208 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
209 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
210 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
211 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
212 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
213 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1)); |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
214 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
215 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
216 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
217 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
218 /* get the next 4 bytes from the stream, treat them as palette |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
219 * indices, and output them rle_code times */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
220 CHECK_STREAM_PTR(4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
221 pi1 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
222 pi2 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
223 pi3 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
224 pi4 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
225 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
226 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
227 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
228 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
229 rgb[pixel_ptr++] = pi1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
230 rgb[pixel_ptr++] = pi2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
231 rgb[pixel_ptr++] = pi3; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
232 rgb[pixel_ptr++] = pi4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
233 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
234 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
235 /* copy the same pixel directly to output 4 times */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
236 rle_code *= 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
237 CHECK_STREAM_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
238 CHECK_PIXEL_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
239 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
240 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
241 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
242 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
243 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
244 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
245 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
246 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
247 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
248 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
249 static void qtrle_decode_16bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
250 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
251 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
252 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
253 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
254 int lines_to_change; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
255 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
256 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
257 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
258 unsigned short rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
259 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
260 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
261 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
262 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
263 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
264 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
265 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
266 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
267 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
268 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
269 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
270 CHECK_STREAM_PTR(2); |
4364 | 271 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
272 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
273 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
274 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
275 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
276 CHECK_STREAM_PTR(8); |
4364 | 277 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
278 stream_ptr += 4; |
4364 | 279 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
280 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
281 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
282 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
283 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
284 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
285 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
286 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
287 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
288 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
289 pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
290 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
291 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
292 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
293 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
294 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
295 pixel_ptr += (s->buf[stream_ptr++] - 1) * 2; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
296 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
297 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
298 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
299 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
300 CHECK_STREAM_PTR(2); |
4364 | 301 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
302 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
303 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
304 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
305 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
306 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
307 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
308 pixel_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
309 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
310 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
311 CHECK_STREAM_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
312 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
313 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
314 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
315 while (rle_code--) { |
4364 | 316 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
317 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
318 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
319 pixel_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
320 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
321 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
322 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
323 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
324 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
325 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
326 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
327 static void qtrle_decode_24bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
328 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
329 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
330 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
331 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
332 int lines_to_change; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
333 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
334 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
335 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
336 unsigned char r, g, b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
337 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
338 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
339 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
340 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
341 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
342 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
343 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
344 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
345 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
346 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
347 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
348 CHECK_STREAM_PTR(2); |
4364 | 349 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
350 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
351 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
352 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
353 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
354 CHECK_STREAM_PTR(8); |
4364 | 355 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
356 stream_ptr += 4; |
4364 | 357 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
358 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
359 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
360 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
361 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
362 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
363 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
364 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
365 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
366 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
367 pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
368 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
369 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
370 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
371 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
372 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
373 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
374 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
375 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
376 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
377 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
378 CHECK_STREAM_PTR(3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
379 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
380 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
381 b = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
382 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
383 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
384 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
385 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
386 rgb[pixel_ptr++] = r; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
387 rgb[pixel_ptr++] = g; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
388 rgb[pixel_ptr++] = b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
389 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
390 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
391 CHECK_STREAM_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
392 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
393 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
394 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
395 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
396 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
397 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
398 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
399 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
400 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
401 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
402 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
403 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
404 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
405 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
406 static void qtrle_decode_32bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
407 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
408 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
409 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
410 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
411 int lines_to_change; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
412 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
413 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
414 int row_inc = s->frame.linesize[0]; |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
415 unsigned char a, r, g, b; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
416 unsigned int argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
417 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
418 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
419 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
420 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
421 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
422 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
423 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
424 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
425 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
426 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
427 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
428 CHECK_STREAM_PTR(2); |
4364 | 429 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
430 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
431 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
432 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
433 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
434 CHECK_STREAM_PTR(8); |
4364 | 435 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
436 stream_ptr += 4; |
4364 | 437 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
438 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
439 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
440 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
441 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
442 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
443 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
444 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
445 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
446 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
447 pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
448 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
449 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
450 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
451 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
452 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
453 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
454 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
455 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
456 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
457 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
458 CHECK_STREAM_PTR(4); |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
459 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
460 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
461 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
462 b = s->buf[stream_ptr++]; |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
463 argb = (a << 24) | (r << 16) | (g << 8) | (b << 0); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
464 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
465 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
466 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
467 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
468 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
469 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
470 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
471 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
472 CHECK_STREAM_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
473 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
474 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
475 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
476 while (rle_code--) { |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
477 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
478 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
479 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
480 b = s->buf[stream_ptr++]; |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
481 argb = (a << 24) | (r << 16) | (g << 8) | (b << 0); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
482 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
483 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
484 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
485 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
486 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
487 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
488 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
489 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
490 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
491 static int qtrle_decode_init(AVCodecContext *avctx) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
492 { |
4827 | 493 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
494 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
495 s->avctx = avctx; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
496 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
497 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
498 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
499 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
500 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
501 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
502 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
503 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
504 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
505 avctx->pix_fmt = PIX_FMT_PAL8; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
506 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
507 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
508 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
509 avctx->pix_fmt = PIX_FMT_RGB555; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
510 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
511 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
512 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
513 avctx->pix_fmt = PIX_FMT_RGB24; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
514 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
515 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
516 case 32: |
4494
ce643a22f049
Replace deprecated PIX_FMT names by the newer variants.
diego
parents:
4364
diff
changeset
|
517 avctx->pix_fmt = PIX_FMT_RGB32; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
518 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
519 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
520 default: |
1807 | 521 av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
522 avctx->bits_per_sample); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
523 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
524 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
525 dsputil_init(&s->dsp, avctx); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
526 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
527 s->frame.data[0] = NULL; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
528 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
529 return 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
530 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
531 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
532 static int qtrle_decode_frame(AVCodecContext *avctx, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
533 void *data, int *data_size, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
534 uint8_t *buf, int buf_size) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
535 { |
4827 | 536 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
537 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
538 s->buf = buf; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
539 s->size = buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
540 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
541 s->frame.reference = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
542 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
543 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
544 if (avctx->reget_buffer(avctx, &s->frame)) { |
1807 | 545 av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
546 return -1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
547 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
548 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
549 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
550 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
551 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
552 qtrle_decode_1bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
553 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
554 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
555 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
556 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
557 qtrle_decode_2bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
558 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
559 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
560 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
561 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
562 qtrle_decode_4bpp(s); |
2049 | 563 /* make the palette available on the way out */ |
564 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); | |
565 if (s->avctx->palctrl->palette_changed) { | |
566 s->frame.palette_has_changed = 1; | |
567 s->avctx->palctrl->palette_changed = 0; | |
568 } | |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
569 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
570 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
571 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
572 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
573 qtrle_decode_8bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
574 /* make the palette available on the way out */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
575 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
576 if (s->avctx->palctrl->palette_changed) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
577 s->frame.palette_has_changed = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
578 s->avctx->palctrl->palette_changed = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
579 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
580 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
581 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
582 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
583 qtrle_decode_16bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
584 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
585 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
586 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
587 qtrle_decode_24bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
588 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
589 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
590 case 32: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
591 qtrle_decode_32bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
592 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
593 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
594 default: |
1807 | 595 av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
596 avctx->bits_per_sample); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
597 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
598 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
599 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
600 *data_size = sizeof(AVFrame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
601 *(AVFrame*)data = s->frame; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
602 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
603 /* always report that the buffer was completely consumed */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
604 return buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
605 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
606 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
607 static int qtrle_decode_end(AVCodecContext *avctx) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
608 { |
4827 | 609 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
610 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
611 if (s->frame.data[0]) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
612 avctx->release_buffer(avctx, &s->frame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
613 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
614 return 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
615 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
616 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
617 AVCodec qtrle_decoder = { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
618 "qtrle", |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
619 CODEC_TYPE_VIDEO, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
620 CODEC_ID_QTRLE, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
621 sizeof(QtrleContext), |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
622 qtrle_decode_init, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
623 NULL, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
624 qtrle_decode_end, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
625 qtrle_decode_frame, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
626 CODEC_CAP_DR1, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
627 }; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
628 |