Mercurial > libavcodec.hg
annotate qtrle.c @ 1982:800db77ec7c8 libavcodec
avoid macro conflicts
author | alex |
---|---|
date | Mon, 26 Apr 2004 09:43:55 +0000 |
parents | 39ad6cd5d4a6 |
children | 19c713e14316 |
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 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
77 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
78 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
79 static void qtrle_decode_8bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
80 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
81 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
82 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
83 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
84 int lines_to_change; |
1808 | 85 int rle_code; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
86 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
87 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
88 unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
89 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
90 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
|
91 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
92 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
93 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
94 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
95 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
96 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
97 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
98 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
99 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
100 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
101 header = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
102 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
103 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
104 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
105 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
106 CHECK_STREAM_PTR(8); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
107 start_line = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
108 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
109 lines_to_change = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
110 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
111 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
112 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
113 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
114 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
115 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
116 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
117 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
118 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
119 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
|
120 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
121 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
|
122 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
123 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
124 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
125 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1)); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
126 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
127 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
128 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
129 /* 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
|
130 * indices, and output them rle_code times */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
131 CHECK_STREAM_PTR(4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
132 pi1 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
133 pi2 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
134 pi3 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
135 pi4 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
136 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
137 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
138 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
139 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
140 rgb[pixel_ptr++] = pi1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
141 rgb[pixel_ptr++] = pi2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
142 rgb[pixel_ptr++] = pi3; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
143 rgb[pixel_ptr++] = pi4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
144 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
145 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
146 /* copy the same pixel directly to output 4 times */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
147 rle_code *= 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
148 CHECK_STREAM_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
149 CHECK_PIXEL_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
150 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
151 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
152 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
153 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
154 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
155 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
156 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
157 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
158 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
159 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
160 static void qtrle_decode_16bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
161 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
162 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
163 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
164 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
165 int lines_to_change; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
166 signed char rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
167 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
168 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
169 unsigned short rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
170 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
171 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
|
172 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
173 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
174 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
175 return; |
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 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
178 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
179 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
180 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
181 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
182 header = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
183 stream_ptr += 2; |
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 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
186 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
187 CHECK_STREAM_PTR(8); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
188 start_line = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
189 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
190 lines_to_change = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
191 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
192 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
193 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
194 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
195 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
196 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
197 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
198 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
199 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
200 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
|
201 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
202 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
|
203 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
204 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
205 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
206 pixel_ptr += (s->buf[stream_ptr++] - 1) * 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
207 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
208 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
209 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
210 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
211 rgb16 = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
212 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
213 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
214 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
215 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
216 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
217 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
218 pixel_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
219 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
220 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
221 CHECK_STREAM_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
222 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
223 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
224 /* copy pixels directly to output */ |
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 rgb16 = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
227 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
228 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
229 pixel_ptr += 2; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
232 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
233 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
234 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
235 } |
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 static void qtrle_decode_24bpp(QtrleContext *s) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
238 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
239 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
240 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
241 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
242 int lines_to_change; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
243 signed char rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
244 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
245 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
246 unsigned char r, g, b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
247 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
248 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
|
249 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
250 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
251 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
252 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
253 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
254 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
255 stream_ptr = 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
256 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
257 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
258 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
259 header = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
260 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
261 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
262 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
263 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
264 CHECK_STREAM_PTR(8); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
265 start_line = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
266 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
267 lines_to_change = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
268 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
269 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
270 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
271 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
272 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
273 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
274 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
275 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
276 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
277 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
|
278 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
279 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
|
280 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
281 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
282 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
283 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
284 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
285 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
286 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
287 CHECK_STREAM_PTR(3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
288 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
289 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
290 b = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
291 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
292 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
293 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
294 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
295 rgb[pixel_ptr++] = r; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
296 rgb[pixel_ptr++] = g; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
297 rgb[pixel_ptr++] = b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
298 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
299 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
300 CHECK_STREAM_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
301 CHECK_PIXEL_PTR(rle_code * 3); |
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 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
304 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
305 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
306 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
307 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
308 } |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
311 row_ptr += row_inc; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
312 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
313 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
314 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
315 static void qtrle_decode_32bpp(QtrleContext *s) |
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 int stream_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
318 int header; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
319 int start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
320 int lines_to_change; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
321 signed char rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
322 int row_ptr, pixel_ptr; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
323 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
324 unsigned char r, g, b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
325 unsigned int argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
326 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
327 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
|
328 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
329 /* check if this frame is even supposed to change */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
330 if (s->size < 8) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
331 return; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
332 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
333 /* start after the chunk size */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
334 stream_ptr = 4; |
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 /* fetch the header */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
337 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
338 header = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
339 stream_ptr += 2; |
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 /* if a header is present, fetch additional decoding parameters */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
342 if (header & 0x0008) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
343 CHECK_STREAM_PTR(8); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
344 start_line = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
345 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
346 lines_to_change = BE_16(&s->buf[stream_ptr]); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
347 stream_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
348 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
349 start_line = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
350 lines_to_change = s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
351 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
352 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
353 row_ptr = row_inc * start_line; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
354 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
355 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
356 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
|
357 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
358 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
|
359 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
360 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
361 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
362 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
363 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
364 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
365 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
366 CHECK_STREAM_PTR(4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
367 stream_ptr++; /* skip the alpha (?) byte */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
368 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
369 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
370 b = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
371 argb = (r << 16) | (g << 8) | (b << 0); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
372 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
373 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
374 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
375 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
376 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
377 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
378 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
379 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
380 CHECK_STREAM_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
381 CHECK_PIXEL_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
382 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
383 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
384 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
385 stream_ptr++; /* skip the alpha (?) byte */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
386 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
387 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
388 b = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
389 argb = (r << 16) | (g << 8) | (b << 0); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
390 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
391 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
392 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
393 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
394 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
395 row_ptr += row_inc; |
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 static int qtrle_decode_init(AVCodecContext *avctx) |
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 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
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 s->avctx = avctx; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
404 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
405 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
406 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
407 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
408 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
409 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
410 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
411 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
412 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
413 avctx->pix_fmt = PIX_FMT_PAL8; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
414 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
415 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
416 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
417 avctx->pix_fmt = PIX_FMT_RGB555; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
418 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
419 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
420 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
421 avctx->pix_fmt = PIX_FMT_RGB24; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
422 break; |
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 case 32: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
425 avctx->pix_fmt = PIX_FMT_RGBA32; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
426 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
427 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
428 default: |
1807 | 429 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
|
430 avctx->bits_per_sample); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
431 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
432 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
433 avctx->has_b_frames = 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
434 dsputil_init(&s->dsp, avctx); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
435 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
436 s->frame.data[0] = NULL; |
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 return 0; |
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 static int qtrle_decode_frame(AVCodecContext *avctx, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
442 void *data, int *data_size, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
443 uint8_t *buf, int buf_size) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
444 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
445 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
446 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
447 /* no supplementary picture */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
448 if (buf_size == 0) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
449 return 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
450 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
451 s->buf = buf; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
452 s->size = buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
453 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
454 s->frame.reference = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
455 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
|
456 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
457 if (avctx->reget_buffer(avctx, &s->frame)) { |
1807 | 458 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
|
459 return -1; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
462 switch (avctx->bits_per_sample) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
463 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
464 case 33: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
465 qtrle_decode_1bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
466 break; |
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 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
469 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
470 qtrle_decode_2bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
471 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
472 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
473 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
474 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
475 qtrle_decode_4bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
476 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
477 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
478 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
479 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
480 qtrle_decode_8bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
481 /* make the palette available on the way out */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
482 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
|
483 if (s->avctx->palctrl->palette_changed) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
484 s->frame.palette_has_changed = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
485 s->avctx->palctrl->palette_changed = 0; |
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 break; |
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 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
490 qtrle_decode_16bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
491 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
492 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
493 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
494 qtrle_decode_24bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
495 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
496 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
497 case 32: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
498 qtrle_decode_32bpp(s); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
499 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
500 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
501 default: |
1807 | 502 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
|
503 avctx->bits_per_sample); |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
507 *data_size = sizeof(AVFrame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
508 *(AVFrame*)data = s->frame; |
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 /* always report that the buffer was completely consumed */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
511 return buf_size; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
514 static int qtrle_decode_end(AVCodecContext *avctx) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
515 { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
516 QtrleContext *s = (QtrleContext *)avctx->priv_data; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
517 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
518 if (s->frame.data[0]) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
519 avctx->release_buffer(avctx, &s->frame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
520 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
521 return 0; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
524 AVCodec qtrle_decoder = { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
525 "qtrle", |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
526 CODEC_TYPE_VIDEO, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
527 CODEC_ID_QTRLE, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
528 sizeof(QtrleContext), |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
529 qtrle_decode_init, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
530 NULL, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
531 qtrle_decode_end, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
532 qtrle_decode_frame, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
533 CODEC_CAP_DR1, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
534 }; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
535 |