33 #define FETCH_NEXT_STREAM_BYTE() \
34 if (stream_ptr >= data_size) \
36 av_log(avctx, AV_LOG_ERROR, " MS RLE: stream ptr just went out of bounds (1)\n"); \
39 stream_byte = data[stream_ptr++];
42 const uint8_t *
data,
int data_size)
45 unsigned char rle_code;
46 unsigned char extra_byte, odd_pixel;
47 unsigned char stream_byte;
48 unsigned int pixel_ptr = 0;
50 int row_ptr = (avctx->
height - 1) * row_dec;
51 int frame_size = row_dec * avctx->
height;
54 while (row_ptr >= 0) {
56 rle_code = stream_byte;
60 if (stream_byte == 0) {
64 }
else if (stream_byte == 1) {
67 }
else if (stream_byte == 2) {
70 pixel_ptr += stream_byte;
72 row_ptr -= stream_byte * row_dec;
75 odd_pixel = stream_byte & 1;
76 rle_code = (stream_byte + 1) / 2;
77 extra_byte = rle_code & 0x01;
78 if (row_ptr + pixel_ptr + stream_byte > frame_size) {
83 for (i = 0; i < rle_code; i++) {
84 if (pixel_ptr >= avctx->
width)
87 pic->
data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
89 if (i + 1 == rle_code && odd_pixel)
91 if (pixel_ptr >= avctx->
width)
93 pic->
data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
103 if (row_ptr + pixel_ptr + stream_byte > frame_size) {
108 for (i = 0; i < rle_code; i++) {
109 if (pixel_ptr >= avctx->
width)
112 pic->
data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
114 pic->
data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
121 if (stream_ptr < data_size) {
122 av_log(avctx,
AV_LOG_ERROR,
" MS RLE: ended frame decode with bytes left over (%d < %d)\n",
123 stream_ptr, data_size);
132 const uint8_t *
data,
int srcsize)
134 uint8_t *output, *output_end;
135 const uint8_t* src =
data;
143 while(src < data + srcsize) {
149 if (line < 0 && !(src+1 < data + srcsize &&
AV_RB16(src) == 1)) {
166 output = pic->
data[0] + line * pic->
linesize[0] + pos * (depth >> 3);
170 if ((pic->
linesize[0] > 0 && output + p2 * (depth >> 3) > output_end)
171 ||(pic->
linesize[0] < 0 && output + p2 * (depth >> 3) < output_end)) {
172 src += p2 * (depth >> 3);
175 if ((depth == 8) || (depth == 24)) {
176 for(i = 0; i < p2 * (depth >> 3); i++) {
180 if(depth == 8 && (p2 & 1)) {
183 }
else if (depth == 16) {
184 for(i = 0; i < p2; i++) {
187 *(uint16_t*)output = pix16;
190 }
else if (depth == 32) {
191 for(i = 0; i < p2; i++) {
194 *(uint32_t*)output = pix32;
202 case 8: pix[0] = *src++;
207 case 24: pix[0] = *src++;
215 if ((pic->
linesize[0] > 0 && output + p1 * (depth >> 3) > output_end)
216 ||(pic->
linesize[0] < 0 && output + p1 * (depth >> 3) < output_end))
218 for(i = 0; i < p1; i++) {
220 case 8: *output++ = pix[0];
222 case 16: *(uint16_t*)output = pix16;
225 case 24: *output++ = pix[0];
229 case 32: *(uint32_t*)output = pix32;
244 const uint8_t*
data,
int data_size)