annotate qtrle.c @ 11531:31033caa5344 libavcodec

Change ref_index structure so it matches how its organized in h264. Also revert the related error concealment hotfix.
author michael
date Tue, 23 Mar 2010 02:17:04 +0000
parents 5da84f0d0a55
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7823
diff changeset
38 #include "libavutil/intreadwrite.h"
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
39 #include "avcodec.h"
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
40
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
41 typedef struct QtrleContext {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
42
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
43 AVCodecContext *avctx;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
44 AVFrame frame;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
45
6315
9ac5c0cfeb56 mark qtrle input data as const.
reimar
parents: 5215
diff changeset
46 const unsigned char *buf;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
47 int size;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
48
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
49 } QtrleContext;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
50
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
51 #define CHECK_STREAM_PTR(n) \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
52 if ((stream_ptr + n) > s->size) { \
1807
db067aa9fc2b Use av_log
rtognimp
parents: 1783
diff changeset
53 av_log (s->avctx, AV_LOG_INFO, "Problem: stream_ptr out of bounds (%d >= %d)\n", \
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
54 stream_ptr + n, s->size); \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
55 return; \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
56 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
57
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
58 #define CHECK_PIXEL_PTR(n) \
2827
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
59 if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
60 av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
61 pixel_ptr + n, pixel_limit); \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
62 return; \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
63 } \
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
64
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
65 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
66 {
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
67 int rle_code;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
68 int pixel_ptr = 0;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
69 int row_inc = s->frame.linesize[0];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
70 unsigned char pi0, pi1; /* 2 8-pixel values */
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
71 unsigned char *rgb = s->frame.data[0];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
72 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
73 int skip;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
74
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
75 while (lines_to_change) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
76 CHECK_STREAM_PTR(2);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
77 skip = s->buf[stream_ptr++];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
78 rle_code = (signed char)s->buf[stream_ptr++];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
79 if (rle_code == 0)
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
80 break;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
81 if(skip & 0x80) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
82 lines_to_change--;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
83 row_ptr += row_inc;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
84 pixel_ptr = row_ptr + 2 * (skip & 0x7f);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
85 } else
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
86 pixel_ptr += 2 * skip;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
87 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
88
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
89 if (rle_code < 0) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
90 /* decode the run length code */
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
91 rle_code = -rle_code;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
92 /* 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
93 * of 8 pixels, and output them rle_code times */
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
94 CHECK_STREAM_PTR(2);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
95 pi0 = s->buf[stream_ptr++];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
96 pi1 = s->buf[stream_ptr++];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
97 CHECK_PIXEL_PTR(rle_code * 2);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
98
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
99 while (rle_code--) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
100 rgb[pixel_ptr++] = pi0;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
101 rgb[pixel_ptr++] = pi1;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
102 }
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
103 } else {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
104 /* copy the same pixel directly to output 2 times */
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
105 rle_code *= 2;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
106 CHECK_STREAM_PTR(rle_code);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
107 CHECK_PIXEL_PTR(rle_code);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
108
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
109 while (rle_code--)
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
110 rgb[pixel_ptr++] = s->buf[stream_ptr++];
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
111 }
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
112 }
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
113 }
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
114
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
115 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
116 int row_ptr, int lines_to_change, int bpp)
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
117 {
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
118 int rle_code, i;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
119 int pixel_ptr;
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
120 int row_inc = s->frame.linesize[0];
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
121 unsigned char pi[16]; /* 16 palette indices */
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
122 unsigned char *rgb = s->frame.data[0];
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
123 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
124 int num_pixels = (bpp == 4) ? 8 : 16;
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
125
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
126 while (lines_to_change--) {
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
127 CHECK_STREAM_PTR(2);
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
128 pixel_ptr = row_ptr + (num_pixels * (s->buf[stream_ptr++] - 1));
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
129
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
130 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
131 if (rle_code == 0) {
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
132 /* there's another skip code in the stream */
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
133 CHECK_STREAM_PTR(1);
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
134 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
135 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
136 } else if (rle_code < 0) {
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
137 /* decode the run length code */
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
138 rle_code = -rle_code;
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
139 /* get the next 4 bytes from the stream, treat them as palette
6903
0f63fc62ea8b consistency cosmetics: indices --> indexes
diego
parents: 6712
diff changeset
140 * indexes, and output them rle_code times */
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
141 CHECK_STREAM_PTR(4);
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
142 for (i = num_pixels-1; i >= 0; i--) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
143 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
144 stream_ptr+= ((i & ((num_pixels>>2)-1)) == 0);
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
145 }
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
146 CHECK_PIXEL_PTR(rle_code * num_pixels);
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
147 while (rle_code--) {
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
148 for (i = 0; i < num_pixels; i++)
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
149 rgb[pixel_ptr++] = pi[i];
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
150 }
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
151 } else {
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
152 /* copy the same pixel directly to output 4 times */
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
153 rle_code *= 4;
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
154 CHECK_STREAM_PTR(rle_code);
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
155 CHECK_PIXEL_PTR(rle_code*(num_pixels>>2));
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
156 while (rle_code--) {
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
157 if(bpp == 4) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
158 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
159 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
160 } else {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
161 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 6) & 0x03;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
162 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x03;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
163 rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 2) & 0x03;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
164 rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x03;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
165 }
2049
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
166 }
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
167 }
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
168 }
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
169 row_ptr += row_inc;
19c713e14316 Add support for qtrle4 (16 colors/gray levels)
rtognimp
parents: 1881
diff changeset
170 }
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
171 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
172
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
173 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
174 {
1808
9d860b33fd54 rle_code can overflow when multiplied by 4
rtognimp
parents: 1807
diff changeset
175 int rle_code;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
176 int pixel_ptr;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
177 int row_inc = s->frame.linesize[0];
6903
0f63fc62ea8b consistency cosmetics: indices --> indexes
diego
parents: 6712
diff changeset
178 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
179 unsigned char *rgb = s->frame.data[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
180 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
181
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
182 while (lines_to_change--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
183 CHECK_STREAM_PTR(2);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
184 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
185
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
186 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
187 if (rle_code == 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
188 /* there's another skip code in the stream */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
189 CHECK_STREAM_PTR(1);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
190 pixel_ptr += (4 * (s->buf[stream_ptr++] - 1));
2827
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
191 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
192 } else if (rle_code < 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
193 /* decode the run length code */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
194 rle_code = -rle_code;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
195 /* get the next 4 bytes from the stream, treat them as palette
6903
0f63fc62ea8b consistency cosmetics: indices --> indexes
diego
parents: 6712
diff changeset
196 * indexes, and output them rle_code times */
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
197 CHECK_STREAM_PTR(4);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
198 pi1 = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
199 pi2 = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
200 pi3 = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
201 pi4 = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
202
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
203 CHECK_PIXEL_PTR(rle_code * 4);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
204
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
205 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
206 rgb[pixel_ptr++] = pi1;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
207 rgb[pixel_ptr++] = pi2;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
208 rgb[pixel_ptr++] = pi3;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
209 rgb[pixel_ptr++] = pi4;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
210 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
211 } else {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
212 /* copy the same pixel directly to output 4 times */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
213 rle_code *= 4;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
214 CHECK_STREAM_PTR(rle_code);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
215 CHECK_PIXEL_PTR(rle_code);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
216
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
217 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
218 rgb[pixel_ptr++] = s->buf[stream_ptr++];
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 }
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 row_ptr += row_inc;
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 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
225
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
226 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
227 {
2925
89ce06bb1c87 Make rle_code int everywhere instead of signed char.
reimar
parents: 2827
diff changeset
228 int rle_code;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
229 int pixel_ptr;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
230 int row_inc = s->frame.linesize[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
231 unsigned short rgb16;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
232 unsigned char *rgb = s->frame.data[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
233 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
234
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
235 while (lines_to_change--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
236 CHECK_STREAM_PTR(2);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
237 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
238
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
239 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
240 if (rle_code == 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
241 /* there's another skip code in the stream */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
242 CHECK_STREAM_PTR(1);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
243 pixel_ptr += (s->buf[stream_ptr++] - 1) * 2;
2827
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
244 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
245 } else if (rle_code < 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
246 /* decode the run length code */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
247 rle_code = -rle_code;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
248 CHECK_STREAM_PTR(2);
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
249 rgb16 = AV_RB16(&s->buf[stream_ptr]);
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
250 stream_ptr += 2;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
251
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
252 CHECK_PIXEL_PTR(rle_code * 2);
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 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
255 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
256 pixel_ptr += 2;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
257 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
258 } else {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
259 CHECK_STREAM_PTR(rle_code * 2);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
260 CHECK_PIXEL_PTR(rle_code * 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 /* copy pixels directly to output */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
263 while (rle_code--) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
264 rgb16 = AV_RB16(&s->buf[stream_ptr]);
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
265 stream_ptr += 2;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
266 *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
267 pixel_ptr += 2;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
268 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
269 }
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 row_ptr += row_inc;
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
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
275 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
276 {
2925
89ce06bb1c87 Make rle_code int everywhere instead of signed char.
reimar
parents: 2827
diff changeset
277 int rle_code;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
278 int pixel_ptr;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
279 int row_inc = s->frame.linesize[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
280 unsigned char r, g, b;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
281 unsigned char *rgb = s->frame.data[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
282 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
283
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
284 while (lines_to_change--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
285 CHECK_STREAM_PTR(2);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
286 pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
287
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
288 while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
289 if (rle_code == 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
290 /* there's another skip code in the stream */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
291 CHECK_STREAM_PTR(1);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
292 pixel_ptr += (s->buf[stream_ptr++] - 1) * 3;
2827
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
293 CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
294 } else if (rle_code < 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
295 /* decode the run length code */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
296 rle_code = -rle_code;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
297 CHECK_STREAM_PTR(3);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
298 r = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
299 g = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
300 b = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
301
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
302 CHECK_PIXEL_PTR(rle_code * 3);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
303
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
304 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
305 rgb[pixel_ptr++] = r;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
306 rgb[pixel_ptr++] = g;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
307 rgb[pixel_ptr++] = b;
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 } else {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
310 CHECK_STREAM_PTR(rle_code * 3);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
311 CHECK_PIXEL_PTR(rle_code * 3);
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 /* copy pixels directly to output */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
314 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
315 rgb[pixel_ptr++] = s->buf[stream_ptr++];
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 }
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 row_ptr += row_inc;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
322 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
323 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
324
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
325 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
326 {
2925
89ce06bb1c87 Make rle_code int everywhere instead of signed char.
reimar
parents: 2827
diff changeset
327 int rle_code;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
328 int pixel_ptr;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
329 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
330 unsigned char a, r, g, b;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
331 unsigned int argb;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
332 unsigned char *rgb = s->frame.data[0];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
333 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
334
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
335 while (lines_to_change--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
336 CHECK_STREAM_PTR(2);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
337 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
338
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
339 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
340 if (rle_code == 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
341 /* there's another skip code in the stream */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
342 CHECK_STREAM_PTR(1);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
343 pixel_ptr += (s->buf[stream_ptr++] - 1) * 4;
2827
deaf39d8381b tinfoil patch: make sure pixel_ptr never goes negative
melanson
parents: 2453
diff changeset
344 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
345 } else if (rle_code < 0) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
346 /* decode the run length code */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
347 rle_code = -rle_code;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
348 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
349 a = s->buf[stream_ptr++];
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
350 r = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
351 g = s->buf[stream_ptr++];
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
352 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
353 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
354
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
355 CHECK_PIXEL_PTR(rle_code * 4);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
356
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
357 while (rle_code--) {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
358 *(unsigned int *)(&rgb[pixel_ptr]) = argb;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
359 pixel_ptr += 4;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
360 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
361 } else {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
362 CHECK_STREAM_PTR(rle_code * 4);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
363 CHECK_PIXEL_PTR(rle_code * 4);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
364
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
365 /* copy pixels directly to output */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
366 while (rle_code--) {
2964
8f732838179d correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents: 2925
diff changeset
367 a = s->buf[stream_ptr++];
1783
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++];
2964
8f732838179d correctly deal with the alpha channel in 32-bit QT RLE (courtesy of John
melanson
parents: 2925
diff changeset
371 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
372 *(unsigned int *)(&rgb[pixel_ptr]) = argb;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
373 pixel_ptr += 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 }
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 row_ptr += row_inc;
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 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
380
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
381 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
382 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
383 QtrleContext *s = avctx->priv_data;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
384
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
385 s->avctx = avctx;
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7805
diff changeset
386 switch (avctx->bits_per_coded_sample) {
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
387 case 1:
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
388 case 33:
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
389 avctx->pix_fmt = PIX_FMT_MONOWHITE;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
390 break;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
391
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
392 case 2:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
393 case 4:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
394 case 8:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
395 case 34:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
396 case 36:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
397 case 40:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
398 avctx->pix_fmt = PIX_FMT_PAL8;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
399 break;
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 case 16:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
402 avctx->pix_fmt = PIX_FMT_RGB555;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
403 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
404
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
405 case 24:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
406 avctx->pix_fmt = PIX_FMT_RGB24;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
407 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
408
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
409 case 32:
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4364
diff changeset
410 avctx->pix_fmt = PIX_FMT_RGB32;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
411 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
412
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
413 default:
1807
db067aa9fc2b Use av_log
rtognimp
parents: 1783
diff changeset
414 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
415 avctx->bits_per_coded_sample);
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
416 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
417 }
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 s->frame.data[0] = NULL;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
420
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
421 return 0;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
422 }
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 static int qtrle_decode_frame(AVCodecContext *avctx,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
425 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
426 AVPacket *avpkt)
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
427 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
428 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
429 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
430 QtrleContext *s = avctx->priv_data;
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
431 int header, start_line;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
432 int stream_ptr, height, row_ptr;
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
433 int has_palette = 0;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
434
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
435 s->buf = buf;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
436 s->size = buf_size;
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 s->frame.reference = 1;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
439 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
440 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
441 if (avctx->reget_buffer(avctx, &s->frame)) {
1807
db067aa9fc2b Use av_log
rtognimp
parents: 1783
diff changeset
442 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
443 return -1;
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
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
446 /* check if this frame is even supposed to change */
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
447 if (s->size < 8)
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
448 goto done;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
449
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
450 /* start after the chunk size */
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
451 stream_ptr = 4;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
452
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
453 /* fetch the header */
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
454 header = AV_RB16(&s->buf[stream_ptr]);
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
455 stream_ptr += 2;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
456
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
457 /* if a header is present, fetch additional decoding parameters */
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
458 if (header & 0x0008) {
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
459 if(s->size < 14)
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
460 goto done;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
461 start_line = AV_RB16(&s->buf[stream_ptr]);
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
462 stream_ptr += 4;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
463 height = AV_RB16(&s->buf[stream_ptr]);
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
464 stream_ptr += 4;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
465 } else {
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
466 start_line = 0;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
467 height = s->avctx->height;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
468 }
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
469 row_ptr = s->frame.linesize[0] * start_line;
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
470
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7805
diff changeset
471 switch (avctx->bits_per_coded_sample) {
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
472 case 1:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
473 case 33:
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
474 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
475 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
476
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
477 case 2:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
478 case 34:
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
479 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
480 has_palette = 1;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
481 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
482
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
483 case 4:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
484 case 36:
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
485 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
486 has_palette = 1;
1783
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 8:
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
490 case 40:
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
491 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
492 has_palette = 1;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
493 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
494
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
495 case 16:
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
496 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
497 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
498
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
499 case 24:
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
500 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
501 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
502
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
503 case 32:
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
504 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
505 break;
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 default:
1807
db067aa9fc2b Use av_log
rtognimp
parents: 1783
diff changeset
508 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
509 avctx->bits_per_coded_sample);
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
510 break;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
511 }
7805
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
512
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
513 if(has_palette) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
514 /* make the palette available on the way out */
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
515 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
516 if (s->avctx->palctrl->palette_changed) {
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
517 s->frame.palette_has_changed = 1;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
518 s->avctx->palctrl->palette_changed = 0;
d1ebbf1e4d50 add 1bpp decoding function and extend 4bpp function to
stefang
parents: 7761
diff changeset
519 }
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
7761
94f82ed28dc4 reduce code duplication by moving common header parsing
stefang
parents: 7040
diff changeset
522 done:
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
523 *data_size = sizeof(AVFrame);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
524 *(AVFrame*)data = s->frame;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
525
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
526 /* always report that the buffer was completely consumed */
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
527 return buf_size;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
528 }
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
529
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
530 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
531 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
532 QtrleContext *s = avctx->priv_data;
1783
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
533
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
534 if (s->frame.data[0])
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
535 avctx->release_buffer(avctx, &s->frame);
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
536
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
537 return 0;
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
538 }
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 AVCodec qtrle_decoder = {
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
541 "qtrle",
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
542 CODEC_TYPE_VIDEO,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
543 CODEC_ID_QTRLE,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
544 sizeof(QtrleContext),
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
545 qtrle_decode_init,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
546 NULL,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
547 qtrle_decode_end,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
548 qtrle_decode_frame,
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
549 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6903
diff changeset
550 .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
551 };
66ae3c109d90 initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
diff changeset
552