36 unsigned char rle_code;
37 unsigned char extra_byte, odd_pixel;
38 unsigned char stream_byte;
43 while (line >= 0 && pixel_ptr <= avctx->
width) {
46 "MS RLE: bytestream overrun, %dx%d left\n",
47 avctx->
width - pixel_ptr, line);
50 rle_code = stream_byte = bytestream2_get_byteu(gb);
53 stream_byte = bytestream2_get_byte(gb);
54 if (stream_byte == 0) {
58 }
else if (stream_byte == 1) {
61 }
else if (stream_byte == 2) {
63 stream_byte = bytestream2_get_byte(gb);
64 pixel_ptr += stream_byte;
65 stream_byte = bytestream2_get_byte(gb);
69 odd_pixel = stream_byte & 1;
70 rle_code = (stream_byte + 1) / 2;
71 extra_byte = rle_code & 0x01;
72 if (pixel_ptr + 2*rle_code - odd_pixel > avctx->
width ||
75 "MS RLE: frame/stream ptr just went out of bounds (copy)\n");
79 for (i = 0; i < rle_code; i++) {
80 if (pixel_ptr >= avctx->
width)
82 stream_byte = bytestream2_get_byteu(gb);
83 pic->
data[0][line * pic->
linesize[0] + pixel_ptr] = stream_byte >> 4;
85 if (i + 1 == rle_code && odd_pixel)
87 if (pixel_ptr >= avctx->
width)
89 pic->
data[0][line * pic->
linesize[0] + pixel_ptr] = stream_byte & 0x0F;
99 if (pixel_ptr + rle_code > avctx->
width + 1) {
101 "MS RLE: frame ptr just went out of bounds (run) %d %d %d\n", pixel_ptr, rle_code, avctx->
width);
104 stream_byte = bytestream2_get_byte(gb);
105 for (i = 0; i < rle_code; i++) {
106 if (pixel_ptr >= avctx->
width)
109 pic->
data[0][line * pic->
linesize[0] + pixel_ptr] = stream_byte >> 4;
111 pic->
data[0][line * pic->
linesize[0] + pixel_ptr] = stream_byte & 0x0F;
120 "MS RLE: ended frame decode with %d bytes left over\n",
142 p1 = bytestream2_get_byteu(gb);
144 p2 = bytestream2_get_byte(gb);
147 if (bytestream2_get_be16(gb) == 1) {
151 "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);
176 if (output + p2 * (depth >> 3) > output_end) {
184 if ((depth == 8) || (depth == 24)) {
186 output += p2 * (depth >> 3);
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);
206 if (output + p1 * (depth >> 3) > output_end)
211 pix[0] = bytestream2_get_byte(gb);
212 memset(output, pix[0], p1);
216 pix16 = bytestream2_get_le16(gb);
217 for(i = 0; i < p1; i++) {
218 *(uint16_t*)output = pix16;
223 pix[0] = bytestream2_get_byte(gb);
224 pix[1] = bytestream2_get_byte(gb);
225 pix[2] = bytestream2_get_byte(gb);
226 for(i = 0; i < p1; i++) {
233 pix32 = bytestream2_get_le32(gb);
234 for(i = 0; i < p1; i++) {
235 *(uint32_t*)output = pix32;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
int ff_msrle_decode(AVCodecContext *avctx, AVFrame *pic, int depth, GetByteContext *gb)
Decode stream in MS RLE format into frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVFrame *pic, int depth, GetByteContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
int width
picture width / height.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int msrle_decode_pal4(AVCodecContext *avctx, AVFrame *pic, GetByteContext *gb)