Mercurial > libavcodec.hg
annotate qtrle.c @ 9969:5cca2790d582 libavcodec
ARM: handle VFP register arguments in ff_vector_fmul_window_neon()
author | mru |
---|---|
date | Mon, 20 Jul 2009 22:30:27 +0000 |
parents | 54bc8a2727b0 |
children | 5da84f0d0a55 |
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 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8573
diff
changeset
|
23 * @file libavcodec/qtrle.c |
1783
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 |
8573
2acf0ae7b041
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
7823
diff
changeset
|
39 #include "libavutil/intreadwrite.h" |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
40 #include "avcodec.h" |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
41 |
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 AVFrame frame; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
46 |
6315 | 47 const unsigned char *buf; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
48 int size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
49 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
50 } QtrleContext; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
51 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
52 #define CHECK_STREAM_PTR(n) \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
53 if ((stream_ptr + n) > s->size) { \ |
1807 | 54 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
|
55 stream_ptr + n, s->size); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
56 return; \ |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
59 #define CHECK_PIXEL_PTR(n) \ |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
60 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
|
61 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
|
62 pixel_ptr + n, pixel_limit); \ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
63 return; \ |
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 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
66 static void qtrle_decode_1bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
67 { |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
68 int rle_code; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
69 int pixel_ptr = 0; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
70 int row_inc = s->frame.linesize[0]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
71 unsigned char pi0, pi1; /* 2 8-pixel values */ |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
72 unsigned char *rgb = s->frame.data[0]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
73 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
74 int skip; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
75 |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
76 while (lines_to_change) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
77 CHECK_STREAM_PTR(2); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
78 skip = s->buf[stream_ptr++]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
79 rle_code = (signed char)s->buf[stream_ptr++]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
80 if (rle_code == 0) |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
81 break; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
82 if(skip & 0x80) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
83 lines_to_change--; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
84 row_ptr += row_inc; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
85 pixel_ptr = row_ptr + 2 * (skip & 0x7f); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
86 } else |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
87 pixel_ptr += 2 * skip; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
88 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
|
89 |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
90 if (rle_code < 0) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
91 /* decode the run length code */ |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
92 rle_code = -rle_code; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
93 /* get the next 2 bytes from the stream, treat them as groups |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
94 * of 8 pixels, and output them rle_code times */ |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
95 CHECK_STREAM_PTR(2); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
96 pi0 = s->buf[stream_ptr++]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
97 pi1 = s->buf[stream_ptr++]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
98 CHECK_PIXEL_PTR(rle_code * 2); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
99 |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
100 while (rle_code--) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
101 rgb[pixel_ptr++] = pi0; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
102 rgb[pixel_ptr++] = pi1; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
103 } |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
104 } else { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
105 /* copy the same pixel directly to output 2 times */ |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
106 rle_code *= 2; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
107 CHECK_STREAM_PTR(rle_code); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
108 CHECK_PIXEL_PTR(rle_code); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
109 |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
110 while (rle_code--) |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
111 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
112 } |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
113 } |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
114 } |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
115 |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
116 static inline void qtrle_decode_2n4bpp(QtrleContext *s, int stream_ptr, |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
117 int row_ptr, int lines_to_change, int bpp) |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
118 { |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
119 int rle_code, i; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
120 int pixel_ptr; |
2049 | 121 int row_inc = s->frame.linesize[0]; |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
122 unsigned char pi[16]; /* 16 palette indices */ |
2049 | 123 unsigned char *rgb = s->frame.data[0]; |
124 int pixel_limit = s->frame.linesize[0] * s->avctx->height; | |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
125 int num_pixels = (bpp == 4) ? 8 : 16; |
2049 | 126 |
127 while (lines_to_change--) { | |
128 CHECK_STREAM_PTR(2); | |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
129 pixel_ptr = row_ptr + (num_pixels * (s->buf[stream_ptr++] - 1)); |
2049 | 130 |
131 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { | |
132 if (rle_code == 0) { | |
133 /* there's another skip code in the stream */ | |
134 CHECK_STREAM_PTR(1); | |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
135 pixel_ptr += (num_pixels * (s->buf[stream_ptr++] - 1)); |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
136 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ |
2049 | 137 } else if (rle_code < 0) { |
138 /* decode the run length code */ | |
139 rle_code = -rle_code; | |
140 /* get the next 4 bytes from the stream, treat them as palette | |
6903 | 141 * indexes, and output them rle_code times */ |
2049 | 142 CHECK_STREAM_PTR(4); |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
143 for (i = num_pixels-1; i >= 0; i--) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
144 pi[num_pixels-1-i] = (s->buf[stream_ptr] >> ((i*bpp) & 0x07)) & ((1<<bpp)-1); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
145 stream_ptr+= ((i & ((num_pixels>>2)-1)) == 0); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
146 } |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
147 CHECK_PIXEL_PTR(rle_code * num_pixels); |
2049 | 148 while (rle_code--) { |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
149 for (i = 0; i < num_pixels; i++) |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
150 rgb[pixel_ptr++] = pi[i]; |
2049 | 151 } |
152 } else { | |
153 /* copy the same pixel directly to output 4 times */ | |
154 rle_code *= 4; | |
155 CHECK_STREAM_PTR(rle_code); | |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
156 CHECK_PIXEL_PTR(rle_code*(num_pixels>>2)); |
2049 | 157 while (rle_code--) { |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
158 if(bpp == 4) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
159 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
160 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
161 } else { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
162 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 6) & 0x03; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
163 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x03; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
164 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 2) & 0x03; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
165 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x03; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
166 } |
2049 | 167 } |
168 } | |
169 } | |
170 row_ptr += row_inc; | |
171 } | |
1783
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 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
174 static void qtrle_decode_8bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
175 { |
1808 | 176 int rle_code; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
177 int pixel_ptr; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
178 int row_inc = s->frame.linesize[0]; |
6903 | 179 unsigned char pi1, pi2, pi3, pi4; /* 4 palette indexes */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
180 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
181 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
|
182 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
183 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
184 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
185 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
|
186 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
187 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
|
188 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
189 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
190 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
191 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1)); |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
192 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
|
193 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
194 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
195 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
196 /* get the next 4 bytes from the stream, treat them as palette |
6903 | 197 * indexes, and output them rle_code times */ |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
198 CHECK_STREAM_PTR(4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
199 pi1 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
200 pi2 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
201 pi3 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
202 pi4 = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
203 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
204 CHECK_PIXEL_PTR(rle_code * 4); |
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--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
207 rgb[pixel_ptr++] = pi1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
208 rgb[pixel_ptr++] = pi2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
209 rgb[pixel_ptr++] = pi3; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
210 rgb[pixel_ptr++] = pi4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
211 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
212 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
213 /* copy the same pixel directly to output 4 times */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
214 rle_code *= 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
215 CHECK_STREAM_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
216 CHECK_PIXEL_PTR(rle_code); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
217 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
218 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
219 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
220 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
221 } |
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 row_ptr += row_inc; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
226 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
227 static void qtrle_decode_16bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
228 { |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
229 int rle_code; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
230 int pixel_ptr; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
231 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
232 unsigned short rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
233 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
234 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
|
235 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
236 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
237 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
238 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
|
239 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
240 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
|
241 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
242 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
243 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
244 pixel_ptr += (s->buf[stream_ptr++] - 1) * 2; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
245 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
|
246 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
247 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
248 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
249 CHECK_STREAM_PTR(2); |
4364 | 250 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
251 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
252 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
253 CHECK_PIXEL_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
254 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
255 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
256 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
257 pixel_ptr += 2; |
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 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
260 CHECK_STREAM_PTR(rle_code * 2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
261 CHECK_PIXEL_PTR(rle_code * 2); |
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 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
264 while (rle_code--) { |
4364 | 265 rgb16 = AV_RB16(&s->buf[stream_ptr]); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
266 stream_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
267 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
268 pixel_ptr += 2; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
269 } |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
272 row_ptr += row_inc; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
275 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
276 static void qtrle_decode_24bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
277 { |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
278 int rle_code; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
279 int pixel_ptr; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
280 int row_inc = s->frame.linesize[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
281 unsigned char r, g, b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
282 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
283 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
|
284 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
285 while (lines_to_change--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
286 CHECK_STREAM_PTR(2); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
287 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
|
288 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
289 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
|
290 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
291 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
292 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
293 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
294 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
|
295 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
296 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
297 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
298 CHECK_STREAM_PTR(3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
299 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
300 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
301 b = s->buf[stream_ptr++]; |
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 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
304 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
305 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
306 rgb[pixel_ptr++] = r; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
307 rgb[pixel_ptr++] = g; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
308 rgb[pixel_ptr++] = b; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
309 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
310 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
311 CHECK_STREAM_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
312 CHECK_PIXEL_PTR(rle_code * 3); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
313 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
314 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
315 while (rle_code--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
316 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
317 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
318 rgb[pixel_ptr++] = s->buf[stream_ptr++]; |
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 } |
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 row_ptr += row_inc; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
325 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
326 static void qtrle_decode_32bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
327 { |
2925
89ce06bb1c87
Make rle_code int everywhere instead of signed char.
reimar
parents:
2827
diff
changeset
|
328 int rle_code; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
329 int pixel_ptr; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
330 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
|
331 unsigned char a, r, g, b; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
332 unsigned int argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
333 unsigned char *rgb = s->frame.data[0]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
334 int pixel_limit = s->frame.linesize[0] * s->avctx->height; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
335 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
336 while (lines_to_change--) { |
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 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
|
339 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
340 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
|
341 if (rle_code == 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
342 /* there's another skip code in the stream */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
343 CHECK_STREAM_PTR(1); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
344 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; |
2827
deaf39d8381b
tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents:
2453
diff
changeset
|
345 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
|
346 } else if (rle_code < 0) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
347 /* decode the run length code */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
348 rle_code = -rle_code; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
349 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
|
350 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
351 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
352 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
353 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
|
354 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
|
355 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
356 CHECK_PIXEL_PTR(rle_code * 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--) { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
359 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
360 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
361 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
362 } else { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
363 CHECK_STREAM_PTR(rle_code * 4); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
364 CHECK_PIXEL_PTR(rle_code * 4); |
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 /* copy pixels directly to output */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
367 while (rle_code--) { |
2964
8f732838179d
correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents:
2925
diff
changeset
|
368 a = s->buf[stream_ptr++]; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
369 r = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
370 g = s->buf[stream_ptr++]; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
371 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
|
372 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
|
373 *(unsigned int *)(&rgb[pixel_ptr]) = argb; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
374 pixel_ptr += 4; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
375 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
376 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
377 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
378 row_ptr += row_inc; |
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 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
381 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6484
diff
changeset
|
382 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
|
383 { |
4827 | 384 QtrleContext *s = avctx->priv_data; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
385 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
386 s->avctx = avctx; |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7805
diff
changeset
|
387 switch (avctx->bits_per_coded_sample) { |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
388 case 1: |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
389 case 33: |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
390 avctx->pix_fmt = PIX_FMT_MONOWHITE; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
391 break; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
392 |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
393 case 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
394 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
395 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
396 case 34: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
397 case 36: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
398 case 40: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
399 avctx->pix_fmt = PIX_FMT_PAL8; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
400 break; |
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 case 16: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
403 avctx->pix_fmt = PIX_FMT_RGB555; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
404 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
405 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
406 case 24: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
407 avctx->pix_fmt = PIX_FMT_RGB24; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
408 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
409 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
410 case 32: |
4494
ce643a22f049
Replace deprecated PIX_FMT names by the newer variants.
diego
parents:
4364
diff
changeset
|
411 avctx->pix_fmt = PIX_FMT_RGB32; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
412 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
413 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
414 default: |
1807 | 415 av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7805
diff
changeset
|
416 avctx->bits_per_coded_sample); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
417 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
418 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
419 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
420 s->frame.data[0] = NULL; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
421 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
422 return 0; |
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 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
425 static int qtrle_decode_frame(AVCodecContext *avctx, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
426 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
427 AVPacket *avpkt) |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
428 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
429 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
430 int buf_size = avpkt->size; |
4827 | 431 QtrleContext *s = avctx->priv_data; |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
432 int header, start_line; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
433 int stream_ptr, height, row_ptr; |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
434 int has_palette = 0; |
1783
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->buf = buf; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
437 s->size = buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
438 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
439 s->frame.reference = 1; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
440 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
|
441 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
442 if (avctx->reget_buffer(avctx, &s->frame)) { |
1807 | 443 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
|
444 return -1; |
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 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
447 /* check if this frame is even supposed to change */ |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
448 if (s->size < 8) |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
449 goto done; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
450 |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
451 /* start after the chunk size */ |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
452 stream_ptr = 4; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
453 |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
454 /* fetch the header */ |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
455 header = AV_RB16(&s->buf[stream_ptr]); |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
456 stream_ptr += 2; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
457 |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
458 /* if a header is present, fetch additional decoding parameters */ |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
459 if (header & 0x0008) { |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
460 if(s->size < 14) |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
461 goto done; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
462 start_line = AV_RB16(&s->buf[stream_ptr]); |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
463 stream_ptr += 4; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
464 height = AV_RB16(&s->buf[stream_ptr]); |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
465 stream_ptr += 4; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
466 } else { |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
467 start_line = 0; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
468 height = s->avctx->height; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
469 } |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
470 row_ptr = s->frame.linesize[0] * start_line; |
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
471 |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7805
diff
changeset
|
472 switch (avctx->bits_per_coded_sample) { |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
473 case 1: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
474 case 33: |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
475 qtrle_decode_1bpp(s, stream_ptr, row_ptr, height); |
1783
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 2: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
479 case 34: |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
480 qtrle_decode_2n4bpp(s, stream_ptr, row_ptr, height, 2); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
481 has_palette = 1; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
482 break; |
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 case 4: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
485 case 36: |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
486 qtrle_decode_2n4bpp(s, stream_ptr, row_ptr, height, 4); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
487 has_palette = 1; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
488 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
489 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
490 case 8: |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
491 case 40: |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
492 qtrle_decode_8bpp(s, stream_ptr, row_ptr, height); |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
493 has_palette = 1; |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
494 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
495 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
496 case 16: |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
497 qtrle_decode_16bpp(s, stream_ptr, row_ptr, height); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
498 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
499 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
500 case 24: |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
501 qtrle_decode_24bpp(s, stream_ptr, row_ptr, height); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
502 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
503 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
504 case 32: |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
505 qtrle_decode_32bpp(s, stream_ptr, row_ptr, height); |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
506 break; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
507 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
508 default: |
1807 | 509 av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7805
diff
changeset
|
510 avctx->bits_per_coded_sample); |
1783
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 } |
7805
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
513 |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
514 if(has_palette) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
515 /* make the palette available on the way out */ |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
516 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
517 if (s->avctx->palctrl->palette_changed) { |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
518 s->frame.palette_has_changed = 1; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
519 s->avctx->palctrl->palette_changed = 0; |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
520 } |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
521 } |
d1ebbf1e4d50
add 1bpp decoding function and extend 4bpp function to
stefang
parents:
7761
diff
changeset
|
522 |
7761
94f82ed28dc4
reduce code duplication by moving common header parsing
stefang
parents:
7040
diff
changeset
|
523 done: |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
524 *data_size = sizeof(AVFrame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
525 *(AVFrame*)data = s->frame; |
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 /* always report that the buffer was completely consumed */ |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
528 return buf_size; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
529 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
530 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6484
diff
changeset
|
531 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
|
532 { |
4827 | 533 QtrleContext *s = avctx->priv_data; |
1783
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 if (s->frame.data[0]) |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
536 avctx->release_buffer(avctx, &s->frame); |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
537 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
538 return 0; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
539 } |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
540 |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
541 AVCodec qtrle_decoder = { |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
542 "qtrle", |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
543 CODEC_TYPE_VIDEO, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
544 CODEC_ID_QTRLE, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
545 sizeof(QtrleContext), |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
546 qtrle_decode_init, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
547 NULL, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
548 qtrle_decode_end, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
549 qtrle_decode_frame, |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
550 CODEC_CAP_DR1, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6903
diff
changeset
|
551 .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), |
1783
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
552 }; |
66ae3c109d90
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff
changeset
|
553 |