Commit abe3c697 authored by Ronald S. Bultje's avatar Ronald S. Bultje

xwd: convert to bytestream2.

parent 5a3a906b
...@@ -45,43 +45,43 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, ...@@ -45,43 +45,43 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
uint32_t pixformat, pixdepth, bunit, bitorder, bpad; uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
uint32_t rgb[3]; uint32_t rgb[3];
uint8_t *ptr; uint8_t *ptr;
GetByteContext gb;
if (buf_size < XWD_HEADER_SIZE) if (buf_size < XWD_HEADER_SIZE)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
header_size = bytestream_get_be32(&buf); bytestream2_init(&gb, buf, buf_size);
if (buf_size < header_size) header_size = bytestream2_get_be32u(&gb);
return AVERROR_INVALIDDATA;
version = bytestream_get_be32(&buf); version = bytestream2_get_be32u(&gb);
if (version != XWD_VERSION) { if (version != XWD_VERSION) {
av_log(avctx, AV_LOG_ERROR, "unsupported version\n"); av_log(avctx, AV_LOG_ERROR, "unsupported version\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (header_size < XWD_HEADER_SIZE) { if (buf_size < header_size || header_size < XWD_HEADER_SIZE) {
av_log(avctx, AV_LOG_ERROR, "invalid header size\n"); av_log(avctx, AV_LOG_ERROR, "invalid header size\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
pixformat = bytestream_get_be32(&buf); pixformat = bytestream2_get_be32u(&gb);
pixdepth = bytestream_get_be32(&buf); pixdepth = bytestream2_get_be32u(&gb);
avctx->width = bytestream_get_be32(&buf); avctx->width = bytestream2_get_be32u(&gb);
avctx->height = bytestream_get_be32(&buf); avctx->height = bytestream2_get_be32u(&gb);
xoffset = bytestream_get_be32(&buf); xoffset = bytestream2_get_be32u(&gb);
be = bytestream_get_be32(&buf); be = bytestream2_get_be32u(&gb);
bunit = bytestream_get_be32(&buf); bunit = bytestream2_get_be32u(&gb);
bitorder = bytestream_get_be32(&buf); bitorder = bytestream2_get_be32u(&gb);
bpad = bytestream_get_be32(&buf); bpad = bytestream2_get_be32u(&gb);
bpp = bytestream_get_be32(&buf); bpp = bytestream2_get_be32u(&gb);
lsize = bytestream_get_be32(&buf); lsize = bytestream2_get_be32u(&gb);
vclass = bytestream_get_be32(&buf); vclass = bytestream2_get_be32u(&gb);
rgb[0] = bytestream_get_be32(&buf); rgb[0] = bytestream2_get_be32u(&gb);
rgb[1] = bytestream_get_be32(&buf); rgb[1] = bytestream2_get_be32u(&gb);
rgb[2] = bytestream_get_be32(&buf); rgb[2] = bytestream2_get_be32u(&gb);
buf += 8; bytestream2_skipu(&gb, 8);
ncolors = bytestream_get_be32(&buf); ncolors = bytestream2_get_be32u(&gb);
buf += header_size - (XWD_HEADER_SIZE - 20); bytestream2_skipu(&gb, header_size - (XWD_HEADER_SIZE - 20));
av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n", av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n",
pixformat, pixdepth, bunit, bitorder, bpad); pixformat, pixdepth, bunit, bitorder, bpad);
...@@ -143,7 +143,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, ...@@ -143,7 +143,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (buf_size < header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize) { if (bytestream2_get_bytes_left(&gb) < ncolors * XWD_CMAP_SIZE + avctx->height * lsize) {
av_log(avctx, AV_LOG_ERROR, "input buffer too small\n"); av_log(avctx, AV_LOG_ERROR, "input buffer too small\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -192,7 +192,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, ...@@ -192,7 +192,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000) else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA; avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA;
} }
buf += ncolors * XWD_CMAP_SIZE; bytestream2_skipu(&gb, ncolors * XWD_CMAP_SIZE);
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "invalid visual class\n"); av_log(avctx, AV_LOG_ERROR, "invalid visual class\n");
...@@ -222,11 +222,13 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, ...@@ -222,11 +222,13 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
for (i = 0; i < ncolors; i++) { for (i = 0; i < ncolors; i++) {
buf += 4; // skip colormap entry number bytestream2_skipu(&gb, 4); // skip colormap entry number
red = *buf; buf += 2; red = bytestream2_get_byteu(&gb);
green = *buf; buf += 2; bytestream2_skipu(&gb, 1);
blue = *buf; buf += 2; green = bytestream2_get_byteu(&gb);
buf += 2; // skip bitmask flag and padding bytestream2_skipu(&gb, 1);
blue = bytestream2_get_byteu(&gb);
bytestream2_skipu(&gb, 3); // skip bitmask flag and padding
dst[i] = red << 16 | green << 8 | blue; dst[i] = red << 16 | green << 8 | blue;
} }
...@@ -234,8 +236,8 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, ...@@ -234,8 +236,8 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data,
ptr = p->data[0]; ptr = p->data[0];
for (i = 0; i < avctx->height; i++) { for (i = 0; i < avctx->height; i++) {
bytestream_get_buffer(&buf, ptr, rsize); bytestream2_get_bufferu(&gb, ptr, rsize);
buf += lsize - rsize; bytestream2_skipu(&gb, lsize - rsize);
ptr += p->linesize[0]; ptr += p->linesize[0];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment