36 unsigned char rle_code;
37 unsigned char extra_byte, odd_pixel;
38 unsigned char stream_byte;
39 unsigned int pixel_ptr = 0;
41 int row_ptr = (avctx->
height - 1) * row_dec;
42 int frame_size = row_dec * avctx->
height;
45 while (row_ptr >= 0) {
48 "MS RLE: bytestream overrun, %d rows left\n",
52 rle_code = stream_byte = bytestream2_get_byteu(gb);
55 stream_byte = bytestream2_get_byte(gb);
56 if (stream_byte == 0) {
60 }
else if (stream_byte == 1) {
63 }
else if (stream_byte == 2) {
65 stream_byte = bytestream2_get_byte(gb);
66 pixel_ptr += stream_byte;
67 stream_byte = bytestream2_get_byte(gb);
68 row_ptr -= stream_byte * row_dec;
71 odd_pixel = stream_byte & 1;
72 rle_code = (stream_byte + 1) / 2;
73 extra_byte = rle_code & 0x01;
74 if (row_ptr + pixel_ptr + stream_byte > frame_size ||
77 "MS RLE: frame/stream ptr just went out of bounds (copy)\n");
81 for (i = 0; i < rle_code; i++) {
82 if (pixel_ptr >= avctx->
width)
84 stream_byte = bytestream2_get_byteu(gb);
85 pic->
data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
87 if (i + 1 == rle_code && odd_pixel)
89 if (pixel_ptr >= avctx->
width)
91 pic->
data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
101 if (row_ptr + pixel_ptr + stream_byte > frame_size) {
103 "MS RLE: frame ptr just went out of bounds (run)\n");
106 stream_byte = bytestream2_get_byte(gb);
107 for (i = 0; i < rle_code; i++) {
108 if (pixel_ptr >= avctx->
width)
111 pic->
data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
113 pic->
data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
122 "MS RLE: ended frame decode with %d bytes left over\n",
134 uint8_t *output, *output_end;
143 p1 = bytestream2_get_byteu(gb);
145 p2 = bytestream2_get_byte(gb);
148 if (bytestream2_get_be16(gb) == 1) {
152 "Next line is beyond picture bounds (%d bytes left)\n",
163 p1 = bytestream2_get_byte(gb);
164 p2 = bytestream2_get_byte(gb);
171 output = pic->
data[0] + line * pic->
linesize[0] + pos * (depth >> 3);
175 if ((pic->
linesize[0] > 0 && output + p2 * (depth >> 3) > output_end) ||
176 (pic->
linesize[0] < 0 && output + p2 * (depth >> 3) < output_end)) {
184 if ((depth == 8) || (depth == 24)) {
185 for(i = 0; i < p2 * (depth >> 3); i++) {
186 *output++ = bytestream2_get_byteu(gb);
189 if(depth == 8 && (p2 & 1)) {
192 }
else if (depth == 16) {
193 for(i = 0; i < p2; i++) {
194 *(uint16_t*)output = bytestream2_get_le16u(gb);
197 }
else if (depth == 32) {
198 for(i = 0; i < p2; i++) {
199 *(uint32_t*)output = bytestream2_get_le32u(gb);
207 case 8: pix[0] = bytestream2_get_byte(gb);
209 case 16: pix16 = bytestream2_get_le16(gb);
211 case 24: pix[0] = bytestream2_get_byte(gb);
212 pix[1] = bytestream2_get_byte(gb);
213 pix[2] = bytestream2_get_byte(gb);
215 case 32: pix32 = bytestream2_get_le32(gb);
218 if ((pic->
linesize[0] > 0 && output + p1 * (depth >> 3) > output_end) ||
219 (pic->
linesize[0] < 0 && output + p1 * (depth >> 3) < output_end))
221 for(i = 0; i < p1; i++) {
223 case 8: *output++ = pix[0];
225 case 16: *(uint16_t*)output = pix16;
228 case 24: *output++ = pix[0];
232 case 32: *(uint32_t*)output = pix32;