Mercurial > libavcodec.hg
annotate qtrle.c @ 6773:ec58e76c25a3 libavcodec
fix reading of samples-per-frame
author | jbr |
---|---|
date | Sun, 11 May 2008 04:25:34 +0000 |
parents | 5b3acf9fd50a |
children | 0f63fc62ea8b |
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 * @file qtrle.c |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
24 * 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
|
25 * For more information about the QT RLE format, visit: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
26 * http://www.pcisys.net/~melanson/codecs/ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
27 * |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
28 * The QT RLE decoder has seven modes of operation: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
29 * 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
|
30 * 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
|
31 * 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
|
32 */ |
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 #include <stdio.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
35 #include <stdlib.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
36 #include <string.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
37 #include <unistd.h> |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
38 |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
41 typedef struct QtrleContext { |
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 AVCodecContext *avctx; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
44 AVFrame frame; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
45 |
6315 | 46 const unsigned char *buf; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
47 int size; |
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 } QtrleContext; |
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 #define CHECK_STREAM_PTR(n) \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
52 if ((stream_ptr + n) > s->size) { \ |
1807 | 53 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
|
54 stream_ptr + n, s->size); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
55 return; \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
56 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
57 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
58 #define CHECK_PIXEL_PTR(n) \ |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
59 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
|
60 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
|
61 pixel_ptr + n, pixel_limit); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
62 return; \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
63 } \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
64 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
65 static void qtrle_decode_1bpp(QtrleContext *s) |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
69 static void qtrle_decode_2bpp(QtrleContext *s) |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
73 static void qtrle_decode_4bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
74 { |
2049 | 75 int stream_ptr; |
76 int header; | |
77 int start_line; | |
78 int lines_to_change; | |
79 int rle_code; | |
80 int row_ptr, pixel_ptr; | |
81 int row_inc = s->frame.linesize[0]; | |
82 unsigned char pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8; /* 8 palette indices */ | |
83 unsigned char *rgb = s->frame.data[0]; | |
84 int pixel_limit = s->frame.linesize[0] * s->avctx->height; | |
85 | |
86 /* check if this frame is even supposed to change */ | |
87 if (s->size < 8) | |
88 return; | |
89 | |
90 /* start after the chunk size */ | |
91 stream_ptr = 4; | |
92 | |
93 /* fetch the header */ | |
94 CHECK_STREAM_PTR(2); | |
4364 | 95 header = AV_RB16(&s->buf[stream_ptr]); |
2049 | 96 stream_ptr += 2; |
97 | |
98 /* if a header is present, fetch additional decoding parameters */ | |
99 if (header & 0x0008) { | |
100 CHECK_STREAM_PTR(8); | |
4364 | 101 start_line = AV_RB16(&s->buf[stream_ptr]); |
2049 | 102 stream_ptr += 4; |
4364 | 103 lines_to_change = AV_RB16(&s->buf[stream_ptr]); |
2049 | 104 stream_ptr += 4; |
105 } else { | |
106 start_line = 0; | |
107 lines_to_change = s->avctx->height; | |
108 } | |
109 | |
110 row_ptr = row_inc * start_line; | |
111 while (lines_to_change--) { | |
112 CHECK_STREAM_PTR(2); | |
113 pixel_ptr = row_ptr + (8 * (s->buf[stream_ptr++] - 1)); | |
114 | |
115 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { | |
116 if (rle_code == 0) { | |
117 /* there's another skip code in the stream */ | |
118 CHECK_STREAM_PTR(1); | |
119 pixel_ptr += (8 * (s->buf[stream_ptr++] - 1)); | |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
120 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
2049 | 121 } else if (rle_code < 0) { |
122 /* decode the run length code */ | |
123 rle_code = -rle_code; | |
124 /* get the next 4 bytes from the stream, treat them as palette | |
125 * indices, and output them rle_code times */ | |
126 CHECK_STREAM_PTR(4); | |
127 pi1 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
128 pi2 = (s->buf[stream_ptr++]) & 0x0f; | |
129 pi3 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
130 pi4 = (s->buf[stream_ptr++]) & 0x0f; | |
131 pi5 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
132 pi6 = (s->buf[stream_ptr++]) & 0x0f; | |
133 pi7 = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
134 pi8 = (s->buf[stream_ptr++]) & 0x0f; | |
135 | |
136 CHECK_PIXEL_PTR(rle_code * 8); | |
137 | |
138 while (rle_code--) { | |
139 rgb[pixel_ptr++] = pi1; | |
140 rgb[pixel_ptr++] = pi2; | |
141 rgb[pixel_ptr++] = pi3; | |
142 rgb[pixel_ptr++] = pi4; | |
143 rgb[pixel_ptr++] = pi5; | |
144 rgb[pixel_ptr++] = pi6; | |
145 rgb[pixel_ptr++] = pi7; | |
146 rgb[pixel_ptr++] = pi8; | |
147 } | |
148 } else { | |
149 /* copy the same pixel directly to output 4 times */ | |
150 rle_code *= 4; | |
151 CHECK_STREAM_PTR(rle_code); | |
152 CHECK_PIXEL_PTR(rle_code*2); | |
153 | |
154 while (rle_code--) { | |
155 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f; | |
156 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f; | |
157 } | |
158 } | |
159 } | |
160 row_ptr += row_inc; | |
161 } | |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
162 } |
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 static void qtrle_decode_8bpp(QtrleContext *s) |
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 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
167 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
168 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
169 int lines_to_change; |
1808 | 170 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
171 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
172 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
173 unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
174 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
175 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
|
176 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
177 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
178 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
179 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
180 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
181 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
182 stream_ptr = 4; |
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 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
185 CHECK_STREAM_PTR(2); |
4364 | 186 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
187 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
188 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
189 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
190 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
191 CHECK_STREAM_PTR(8); |
4364 | 192 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
193 stream_ptr += 4; |
4364 | 194 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
|
195 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
196 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
197 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
198 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
199 } |
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 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
202 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
203 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
204 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
|
205 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
206 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
|
207 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
208 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
209 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
210 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1)); |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
211 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
|
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; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
252 int rle_code; |
1783
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); |
4364 | 268 header = AV_RB16(&s->buf[stream_ptr]); |
1783
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); |
4364 | 274 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
275 stream_ptr += 4; |
4364 | 276 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
|
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; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
293 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
|
294 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
295 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
296 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
297 CHECK_STREAM_PTR(2); |
4364 | 298 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
299 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
300 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
301 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
302 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
303 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
304 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
305 pixel_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
306 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
307 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
308 CHECK_STREAM_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
309 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
310 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
311 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
312 while (rle_code--) { |
4364 | 313 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
314 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
315 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
316 pixel_ptr += 2; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
320 row_ptr += row_inc; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
324 static void qtrle_decode_24bpp(QtrleContext *s) |
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 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
327 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
328 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
329 int lines_to_change; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
330 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
331 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
332 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
333 unsigned char r, g, b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
334 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
335 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
|
336 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
337 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
338 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
339 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
340 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
341 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
342 stream_ptr = 4; |
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 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
345 CHECK_STREAM_PTR(2); |
4364 | 346 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
347 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
348 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
349 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
350 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
351 CHECK_STREAM_PTR(8); |
4364 | 352 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
353 stream_ptr += 4; |
4364 | 354 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
|
355 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
356 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
357 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
358 lines_to_change = s->avctx->height; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
361 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
362 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
363 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
364 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
|
365 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
366 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
|
367 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
368 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
369 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
370 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
371 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
|
372 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
373 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
374 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
375 CHECK_STREAM_PTR(3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
376 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
377 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
378 b = s->buf[stream_ptr++]; |
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 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
381 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
382 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
383 rgb[pixel_ptr++] = r; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
384 rgb[pixel_ptr++] = g; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
385 rgb[pixel_ptr++] = b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
386 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
387 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
388 CHECK_STREAM_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
389 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
390 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
391 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
392 while (rle_code--) { |
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 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
395 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
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 } |
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 row_ptr += row_inc; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
403 static void qtrle_decode_32bpp(QtrleContext *s) |
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 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
406 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
407 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
408 int lines_to_change; |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
409 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
410 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
411 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
|
412 unsigned char a, r, g, b; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
413 unsigned int argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
414 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
415 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
|
416 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
417 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
418 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
419 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
420 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
421 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
422 stream_ptr = 4; |
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 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
425 CHECK_STREAM_PTR(2); |
4364 | 426 header = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
427 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
428 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
429 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
430 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
431 CHECK_STREAM_PTR(8); |
4364 | 432 start_line = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
433 stream_ptr += 4; |
4364 | 434 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
|
435 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
436 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
437 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
438 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
439 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
440 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
441 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
442 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
443 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
444 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
|
445 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
446 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
|
447 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
448 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
449 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
450 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
451 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
|
452 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
453 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
454 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
455 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
|
456 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
457 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
458 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
459 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
|
460 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
|
461 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
462 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
463 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
464 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
465 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
466 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
467 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
468 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
469 CHECK_STREAM_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
470 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
471 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
472 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
473 while (rle_code--) { |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
474 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
475 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
476 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
477 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
|
478 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
|
479 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
480 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
481 } |
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 row_ptr += row_inc; |
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 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6484
diff
changeset
|
488 static av_cold int qtrle_decode_init(AVCodecContext *avctx) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
489 { |
4827 | 490 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
491 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
492 s->avctx = avctx; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
493 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
494 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
495 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
496 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
497 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
498 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
499 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
500 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
501 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
502 avctx->pix_fmt = PIX_FMT_PAL8; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
503 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
504 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
505 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
506 avctx->pix_fmt = PIX_FMT_RGB555; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
507 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
508 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
509 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
510 avctx->pix_fmt = PIX_FMT_RGB24; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
511 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
512 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
513 case 32: |
4494
ce643a22f049
Replace deprecated PIX_FMT names by the newer variants.
diego
parents:
4364
diff
changeset
|
514 avctx->pix_fmt = PIX_FMT_RGB32; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
515 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
516 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
517 default: |
1807 | 518 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
|
519 avctx->bits_per_sample); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
520 break; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
523 s->frame.data[0] = NULL; |
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 return 0; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
528 static int qtrle_decode_frame(AVCodecContext *avctx, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
529 void *data, int *data_size, |
6315 | 530 const uint8_t *buf, int buf_size) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
531 { |
4827 | 532 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
533 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
534 s->buf = buf; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
535 s->size = buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
536 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
537 s->frame.reference = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
538 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
|
539 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
540 if (avctx->reget_buffer(avctx, &s->frame)) { |
1807 | 541 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
|
542 return -1; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
545 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
546 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
547 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
548 qtrle_decode_1bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
549 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
550 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
551 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
552 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
553 qtrle_decode_2bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
554 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
555 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
556 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
557 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
558 qtrle_decode_4bpp(s); |
2049 | 559 /* make the palette available on the way out */ |
560 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); | |
561 if (s->avctx->palctrl->palette_changed) { | |
562 s->frame.palette_has_changed = 1; | |
563 s->avctx->palctrl->palette_changed = 0; | |
564 } | |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
565 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
566 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
567 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
568 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
569 qtrle_decode_8bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
570 /* make the palette available on the way out */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
571 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
|
572 if (s->avctx->palctrl->palette_changed) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
573 s->frame.palette_has_changed = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
574 s->avctx->palctrl->palette_changed = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
575 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
576 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
577 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
578 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
579 qtrle_decode_16bpp(s); |
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 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
583 qtrle_decode_24bpp(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 32: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
587 qtrle_decode_32bpp(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 default: |
1807 | 591 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
|
592 avctx->bits_per_sample); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
593 break; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
596 *data_size = sizeof(AVFrame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
597 *(AVFrame*)data = s->frame; |
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 /* always report that the buffer was completely consumed */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
600 return buf_size; |
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 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6484
diff
changeset
|
603 static av_cold int qtrle_decode_end(AVCodecContext *avctx) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
604 { |
4827 | 605 QtrleContext *s = avctx->priv_data; |
1783
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 if (s->frame.data[0]) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
608 avctx->release_buffer(avctx, &s->frame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
609 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
610 return 0; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
613 AVCodec qtrle_decoder = { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
614 "qtrle", |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
615 CODEC_TYPE_VIDEO, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
616 CODEC_ID_QTRLE, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
617 sizeof(QtrleContext), |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
618 qtrle_decode_init, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
619 NULL, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
620 qtrle_decode_end, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
621 qtrle_decode_frame, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
622 CODEC_CAP_DR1, |
6712 | 623 .long_name = "QuickTime Animation (RLE) video", |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
624 }; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
625 |