Mercurial > libavcodec.hg
annotate qtrle.c @ 2788:1bf080e490db libavcodec
fix segfault (bug #1165640)
| author | michael |
|---|---|
| date | Mon, 11 Jul 2005 22:56:23 +0000 |
| parents | f67b63ed036d |
| children | deaf39d8381b |
| 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 * |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
6 * 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
|
7 * License as published by the Free Software Foundation; either |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
9 * |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * Lesser General Public License for more details. |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
14 * |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
18 * |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
19 */ |
|
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 * @file qtrle.c |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
23 * 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
|
24 * For more information about the QT RLE format, visit: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
25 * http://www.pcisys.net/~melanson/codecs/ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
26 * |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
27 * The QT RLE decoder has seven modes of operation: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
28 * 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
|
29 * the decoder outputs PAL8 colorspace data. 16-bit data yields RGB555 |
|
39ad6cd5d4a6
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
1808
diff
changeset
|
30 * data. 24-bit data is RGB24 and 32-bit data is RGBA32. |
|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
31 */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
32 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
33 #include <stdio.h> |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
34 #include <stdlib.h> |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
35 #include <string.h> |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
36 #include <unistd.h> |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
37 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
38 #include "common.h" |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
39 #include "avcodec.h" |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
40 #include "dsputil.h" |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
41 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
42 typedef struct QtrleContext { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
43 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
44 AVCodecContext *avctx; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
45 DSPContext dsp; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
46 AVFrame frame; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
47 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
48 unsigned char *buf; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
49 int size; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
50 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
51 } QtrleContext; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
52 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
53 #define CHECK_STREAM_PTR(n) \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
54 if ((stream_ptr + n) > s->size) { \ |
| 1807 | 55 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
|
56 stream_ptr + n, s->size); \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
57 return; \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
58 } |
|
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 #define CHECK_PIXEL_PTR(n) \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
61 if (pixel_ptr + n > pixel_limit) { \ |
| 1807 | 62 av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \ |
|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
63 pixel_ptr + n, pixel_limit); \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
64 return; \ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
65 } \ |
|
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 static void qtrle_decode_1bpp(QtrleContext *s) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
68 { |
|
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 static void qtrle_decode_2bpp(QtrleContext *s) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
72 { |
|
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 static void qtrle_decode_4bpp(QtrleContext *s) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
76 { |
| 2049 | 77 int stream_ptr; |
| 78 int header; | |
| 79 int start_line; | |
| 80 int lines_to_change; | |
| 81 int rle_code; | |
| 82 int row_ptr, pixel_ptr; | |
| 83 int row_inc = s->frame.linesize[0]; | |
| 84 unsigned char pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8; /* 8 palette indices */ | |
| 85 unsigned char *rgb = s->frame.data[0]; | |
| 86 int pixel_limit = s->frame.linesize[0] * s->avctx->height; | |
| 87 | |
| 88 /* check if this frame is even supposed to change */ | |
| 89 if (s->size < 8) | |
| 90 return; | |
| 91 | |
| 92 /* start after the chunk size */ | |
| 93 stream_ptr = 4; | |
| 94 | |
| 95 /* fetch the header */ | |
| 96 CHECK_STREAM_PTR(2); | |
| 97 header = BE_16(&s->buf[stream_ptr]); | |
| 98 stream_ptr += 2; | |
| 99 | |
| 100 /* if a header is present, fetch additional decoding parameters */ | |
| 101 if (header & 0x0008) { | |
| 102 CHECK_STREAM_PTR(8); | |
| 103 start_line = BE_16(&s->buf[stream_ptr]); | |
| 104 stream_ptr += 4; | |
| 105 lines_to_change = BE_16(&s->buf[stream_ptr]); | |
| 106 stream_ptr += 4; | |
| 107 } else { | |
| 108 start_line = 0; | |
| 109 lines_to_change = s->avctx->height; | |
| 110 } | |
| 111 | |
| 112 row_ptr = row_inc * start_line; | |
| 113 while (lines_to_change--) { | |
| 114 CHECK_STREAM_PTR(2); | |
| 115 pixel_ptr = row_ptr + (8 * (s->buf[stream_ptr++] - 1)); | |
| 116 | |
| 117 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { | |
| 118 if (rle_code == 0) { | |
| 119 /* there's another skip code in the stream */ | |
| 120 CHECK_STREAM_PTR(1); | |
| 121 pixel_ptr += (8 * (s->buf[stream_ptr++] - 1)); | |
| 122 } else if (rle_code < 0) { | |
| 123 /* decode the run length code */ | |
| 124 rle_code = -rle_code; | |
| 125 /* get the next 4 bytes from the stream, treat them as palette | |
| 126 * indices, and output them rle_code times */ | |
| 127 CHECK_STREAM_PTR(4); | |
| 128 pi1 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
| 129 pi2 = (s->buf[stream_ptr++]) & 0x0f; | |
| 130 pi3 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
| 131 pi4 = (s->buf[stream_ptr++]) & 0x0f; | |
| 132 pi5 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
| 133 pi6 = (s->buf[stream_ptr++]) & 0x0f; | |
| 134 pi7 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
| 135 pi8 = (s->buf[stream_ptr++]) & 0x0f; | |
| 136 | |
| 137 CHECK_PIXEL_PTR(rle_code * 8); | |
| 138 | |
| 139 while (rle_code--) { | |
| 140 rgb[pixel_ptr++] = pi1; | |
| 141 rgb[pixel_ptr++] = pi2; | |
| 142 rgb[pixel_ptr++] = pi3; | |
| 143 rgb[pixel_ptr++] = pi4; | |
| 144 rgb[pixel_ptr++] = pi5; | |
| 145 rgb[pixel_ptr++] = pi6; | |
| 146 rgb[pixel_ptr++] = pi7; | |
| 147 rgb[pixel_ptr++] = pi8; | |
| 148 } | |
| 149 } else { | |
| 150 /* copy the same pixel directly to output 4 times */ | |
| 151 rle_code *= 4; | |
| 152 CHECK_STREAM_PTR(rle_code); | |
| 153 CHECK_PIXEL_PTR(rle_code*2); | |
| 154 | |
| 155 while (rle_code--) { | |
| 156 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
| 157 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f; | |
| 158 } | |
| 159 } | |
| 160 } | |
| 161 row_ptr += row_inc; | |
| 162 } | |
|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
163 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
164 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
165 static void qtrle_decode_8bpp(QtrleContext *s) |
|
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 int stream_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
168 int header; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
169 int start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
170 int lines_to_change; |
| 1808 | 171 int rle_code; |
|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
172 int row_ptr, pixel_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
173 int row_inc = s->frame.linesize[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
174 unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
175 unsigned char *rgb = s->frame.data[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
176 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
|
177 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
178 /* check if this frame is even supposed to change */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
179 if (s->size < 8) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
180 return; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
181 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
182 /* start after the chunk size */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
183 stream_ptr = 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
184 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
185 /* fetch the header */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
186 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
187 header = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
188 stream_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
189 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
190 /* if a header is present, fetch additional decoding parameters */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
191 if (header & 0x0008) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
192 CHECK_STREAM_PTR(8); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
193 start_line = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
194 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
195 lines_to_change = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
196 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
197 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
198 start_line = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
199 lines_to_change = s->avctx->height; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
200 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
201 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
202 row_ptr = row_inc * start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
203 while (lines_to_change--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
204 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
205 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
|
206 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
207 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
|
208 if (rle_code == 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
209 /* there's another skip code in the stream */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
210 CHECK_STREAM_PTR(1); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
211 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1)); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
212 } else if (rle_code < 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
213 /* decode the run length code */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
214 rle_code = -rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
215 /* 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
|
216 * indices, and output them rle_code times */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
217 CHECK_STREAM_PTR(4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
218 pi1 = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
219 pi2 = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
220 pi3 = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
221 pi4 = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
222 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
223 CHECK_PIXEL_PTR(rle_code * 4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
224 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
225 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
226 rgb[pixel_ptr++] = pi1; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
227 rgb[pixel_ptr++] = pi2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
228 rgb[pixel_ptr++] = pi3; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
229 rgb[pixel_ptr++] = pi4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
230 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
231 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
232 /* copy the same pixel directly to output 4 times */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
233 rle_code *= 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
234 CHECK_STREAM_PTR(rle_code); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
235 CHECK_PIXEL_PTR(rle_code); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
236 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
237 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
238 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
|
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 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
241 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
242 row_ptr += row_inc; |
|
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 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
246 static void qtrle_decode_16bpp(QtrleContext *s) |
|
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 int stream_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
249 int header; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
250 int start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
251 int lines_to_change; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
252 signed char rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
253 int row_ptr, pixel_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
254 int row_inc = s->frame.linesize[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
255 unsigned short rgb16; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
256 unsigned char *rgb = s->frame.data[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
257 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
|
258 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
259 /* check if this frame is even supposed to change */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
260 if (s->size < 8) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
261 return; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
262 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
263 /* start after the chunk size */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
264 stream_ptr = 4; |
|
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 /* fetch the header */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
267 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
268 header = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
269 stream_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
270 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
271 /* if a header is present, fetch additional decoding parameters */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
272 if (header & 0x0008) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
273 CHECK_STREAM_PTR(8); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
274 start_line = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
275 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
276 lines_to_change = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
277 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
278 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
279 start_line = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
280 lines_to_change = s->avctx->height; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
281 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
282 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
283 row_ptr = row_inc * start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
284 while (lines_to_change--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
285 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
286 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
|
287 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
288 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
|
289 if (rle_code == 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
290 /* there's another skip code in the stream */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
291 CHECK_STREAM_PTR(1); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
292 pixel_ptr += (s->buf[stream_ptr++] - 1) * 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
293 } else if (rle_code < 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
294 /* decode the run length code */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
295 rle_code = -rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
296 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
297 rgb16 = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
298 stream_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
299 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
300 CHECK_PIXEL_PTR(rle_code * 2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
301 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
302 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
303 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
304 pixel_ptr += 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 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
307 CHECK_STREAM_PTR(rle_code * 2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
308 CHECK_PIXEL_PTR(rle_code * 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 /* copy pixels directly to output */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
311 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
312 rgb16 = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
313 stream_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
314 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
315 pixel_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
316 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
317 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
318 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
319 row_ptr += row_inc; |
|
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 static void qtrle_decode_24bpp(QtrleContext *s) |
|
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 int stream_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
326 int header; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
327 int start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
328 int lines_to_change; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
329 signed char rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
330 int row_ptr, pixel_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
331 int row_inc = s->frame.linesize[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
332 unsigned char r, g, b; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
333 unsigned char *rgb = s->frame.data[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
334 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
|
335 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
336 /* check if this frame is even supposed to change */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
337 if (s->size < 8) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
338 return; |
|
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 /* start after the chunk size */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
341 stream_ptr = 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
342 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
343 /* fetch the header */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
344 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
345 header = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
346 stream_ptr += 2; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
347 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
348 /* if a header is present, fetch additional decoding parameters */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
349 if (header & 0x0008) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
350 CHECK_STREAM_PTR(8); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
351 start_line = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
352 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
353 lines_to_change = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
354 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
355 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
356 start_line = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
357 lines_to_change = s->avctx->height; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
358 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
359 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
360 row_ptr = row_inc * start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
361 while (lines_to_change--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
362 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
363 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
|
364 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
365 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
|
366 if (rle_code == 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
367 /* there's another skip code in the stream */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
368 CHECK_STREAM_PTR(1); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
369 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
370 } else if (rle_code < 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
371 /* decode the run length code */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
372 rle_code = -rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
373 CHECK_STREAM_PTR(3); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
374 r = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
375 g = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
376 b = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
377 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
378 CHECK_PIXEL_PTR(rle_code * 3); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
379 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
380 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
381 rgb[pixel_ptr++] = r; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
382 rgb[pixel_ptr++] = g; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
383 rgb[pixel_ptr++] = b; |
|
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 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
386 CHECK_STREAM_PTR(rle_code * 3); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
387 CHECK_PIXEL_PTR(rle_code * 3); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
388 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
389 /* copy pixels directly to output */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
390 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
391 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
392 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
393 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
394 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
395 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
396 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
397 row_ptr += row_inc; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
398 } |
|
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 static void qtrle_decode_32bpp(QtrleContext *s) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
402 { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
403 int stream_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
404 int header; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
405 int start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
406 int lines_to_change; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
407 signed char rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
408 int row_ptr, pixel_ptr; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
409 int row_inc = s->frame.linesize[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
410 unsigned char r, g, b; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
411 unsigned int argb; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
412 unsigned char *rgb = s->frame.data[0]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
413 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
|
414 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
415 /* check if this frame is even supposed to change */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
416 if (s->size < 8) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
417 return; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
418 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
419 /* start after the chunk size */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
420 stream_ptr = 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
421 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
422 /* fetch the header */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
423 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
424 header = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
425 stream_ptr += 2; |
|
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 /* if a header is present, fetch additional decoding parameters */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
428 if (header & 0x0008) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
429 CHECK_STREAM_PTR(8); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
430 start_line = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
431 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
432 lines_to_change = BE_16(&s->buf[stream_ptr]); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
433 stream_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
434 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
435 start_line = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
436 lines_to_change = s->avctx->height; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
437 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
438 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
439 row_ptr = row_inc * start_line; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
440 while (lines_to_change--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
441 CHECK_STREAM_PTR(2); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
442 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
|
443 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
444 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
|
445 if (rle_code == 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
446 /* there's another skip code in the stream */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
447 CHECK_STREAM_PTR(1); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
448 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
449 } else if (rle_code < 0) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
450 /* decode the run length code */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
451 rle_code = -rle_code; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
452 CHECK_STREAM_PTR(4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
453 stream_ptr++; /* skip the alpha (?) byte */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
454 r = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
455 g = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
456 b = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
457 argb = (r << 16) | (g << 8) | (b << 0); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
458 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
459 CHECK_PIXEL_PTR(rle_code * 4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
460 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
461 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
462 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
463 pixel_ptr += 4; |
|
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 } else { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
466 CHECK_STREAM_PTR(rle_code * 4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
467 CHECK_PIXEL_PTR(rle_code * 4); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
468 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
469 /* copy pixels directly to output */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
470 while (rle_code--) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
471 stream_ptr++; /* skip the alpha (?) byte */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
472 r = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
473 g = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
474 b = s->buf[stream_ptr++]; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
475 argb = (r << 16) | (g << 8) | (b << 0); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
476 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
477 pixel_ptr += 4; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
478 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
479 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
480 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
481 row_ptr += row_inc; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
482 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
483 } |
|
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 static int qtrle_decode_init(AVCodecContext *avctx) |
|
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 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
|
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 s->avctx = avctx; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
490 switch (avctx->bits_per_sample) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
491 case 1: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
492 case 2: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
493 case 4: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
494 case 8: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
495 case 33: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
496 case 34: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
497 case 36: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
498 case 40: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
499 avctx->pix_fmt = PIX_FMT_PAL8; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
500 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
501 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
502 case 16: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
503 avctx->pix_fmt = PIX_FMT_RGB555; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
504 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
505 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
506 case 24: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
507 avctx->pix_fmt = PIX_FMT_RGB24; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
508 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
509 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
510 case 32: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
511 avctx->pix_fmt = PIX_FMT_RGBA32; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
512 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
513 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
514 default: |
| 1807 | 515 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
|
516 avctx->bits_per_sample); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
517 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
518 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
519 avctx->has_b_frames = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
520 dsputil_init(&s->dsp, avctx); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
521 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
522 s->frame.data[0] = NULL; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
523 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
524 return 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
525 } |
|
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 static int qtrle_decode_frame(AVCodecContext *avctx, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
528 void *data, int *data_size, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
529 uint8_t *buf, int buf_size) |
|
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 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
532 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
533 s->buf = buf; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
534 s->size = buf_size; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
535 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
536 s->frame.reference = 1; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
537 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
|
538 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
539 if (avctx->reget_buffer(avctx, &s->frame)) { |
| 1807 | 540 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
|
541 return -1; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
542 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
543 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
544 switch (avctx->bits_per_sample) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
545 case 1: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
546 case 33: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
547 qtrle_decode_1bpp(s); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
548 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
549 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
550 case 2: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
551 case 34: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
552 qtrle_decode_2bpp(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 4: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
556 case 36: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
557 qtrle_decode_4bpp(s); |
| 2049 | 558 /* make the palette available on the way out */ |
| 559 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); | |
| 560 if (s->avctx->palctrl->palette_changed) { | |
| 561 s->frame.palette_has_changed = 1; | |
| 562 s->avctx->palctrl->palette_changed = 0; | |
| 563 } | |
|
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
564 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
565 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
566 case 8: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
567 case 40: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
568 qtrle_decode_8bpp(s); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
569 /* make the palette available on the way out */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
570 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
|
571 if (s->avctx->palctrl->palette_changed) { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
572 s->frame.palette_has_changed = 1; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
573 s->avctx->palctrl->palette_changed = 0; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
574 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
575 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
576 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
577 case 16: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
578 qtrle_decode_16bpp(s); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
579 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
580 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
581 case 24: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
582 qtrle_decode_24bpp(s); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
583 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
584 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
585 case 32: |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
586 qtrle_decode_32bpp(s); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
587 break; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
588 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
589 default: |
| 1807 | 590 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
|
591 avctx->bits_per_sample); |
|
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 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
595 *data_size = sizeof(AVFrame); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
596 *(AVFrame*)data = s->frame; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
597 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
598 /* always report that the buffer was completely consumed */ |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
599 return buf_size; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
600 } |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
601 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
602 static int qtrle_decode_end(AVCodecContext *avctx) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
603 { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
604 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
|
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 if (s->frame.data[0]) |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
607 avctx->release_buffer(avctx, &s->frame); |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
608 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
609 return 0; |
|
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 |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
612 AVCodec qtrle_decoder = { |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
613 "qtrle", |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
614 CODEC_TYPE_VIDEO, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
615 CODEC_ID_QTRLE, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
616 sizeof(QtrleContext), |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
617 qtrle_decode_init, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
618 NULL, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
619 qtrle_decode_end, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
620 qtrle_decode_frame, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
621 CODEC_CAP_DR1, |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
622 }; |
|
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
623 |
