History

xwd: convert to bytestream2.

Ronald S. Bultje committed 14 years ago

Commit abe3c691 parent 5a3a9061 file · +34 −32Browse files

Unified · Split

libavcodec/xwddec.c+34−32
@@ -45,43 +45,43 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, · 44 unmodified lines
4545 uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
4646 uint32_t rgb[3];
4747 uint8_t *ptr;
48+ GetByteContext gb;
4849
4950 if (buf_size < XWD_HEADER_SIZE)
5051 return AVERROR_INVALIDDATA;
5152
52− header_size = bytestream_get_be32(&buf);
53− if (buf_size < header_size)
54− return AVERROR_INVALIDDATA;
53+ bytestream2_init(&gb, buf, buf_size);
54+ header_size = bytestream2_get_be32u(&gb);
5555
56− version = bytestream_get_be32(&buf);
56+ version = bytestream2_get_be32u(&gb);
5757 if (version != XWD_VERSION) {
5858 av_log(avctx, AV_LOG_ERROR, "unsupported version\n");
5959 return AVERROR_INVALIDDATA;
6060 }
6161
62− if (header_size < XWD_HEADER_SIZE) {
62+ if (buf_size < header_size || header_size < XWD_HEADER_SIZE) {
6363 av_log(avctx, AV_LOG_ERROR, "invalid header size\n");
6464 return AVERROR_INVALIDDATA;
6565 }
6666
67− pixformat = bytestream_get_be32(&buf);
68− pixdepth = bytestream_get_be32(&buf);
69− avctx->width = bytestream_get_be32(&buf);
70− avctx->height = bytestream_get_be32(&buf);
71− xoffset = bytestream_get_be32(&buf);
72− be = bytestream_get_be32(&buf);
73− bunit = bytestream_get_be32(&buf);
74− bitorder = bytestream_get_be32(&buf);
75− bpad = bytestream_get_be32(&buf);
76− bpp = bytestream_get_be32(&buf);
77− lsize = bytestream_get_be32(&buf);
78− vclass = bytestream_get_be32(&buf);
79− rgb[0] = bytestream_get_be32(&buf);
80− rgb[1] = bytestream_get_be32(&buf);
81− rgb[2] = bytestream_get_be32(&buf);
82− buf += 8;
83− ncolors = bytestream_get_be32(&buf);
84− buf += header_size - (XWD_HEADER_SIZE - 20);
67+ pixformat = bytestream2_get_be32u(&gb);
68+ pixdepth = bytestream2_get_be32u(&gb);
69+ avctx->width = bytestream2_get_be32u(&gb);
70+ avctx->height = bytestream2_get_be32u(&gb);
71+ xoffset = bytestream2_get_be32u(&gb);
72+ be = bytestream2_get_be32u(&gb);
73+ bunit = bytestream2_get_be32u(&gb);
74+ bitorder = bytestream2_get_be32u(&gb);
75+ bpad = bytestream2_get_be32u(&gb);
76+ bpp = bytestream2_get_be32u(&gb);
77+ lsize = bytestream2_get_be32u(&gb);
78+ vclass = bytestream2_get_be32u(&gb);
79+ rgb[0] = bytestream2_get_be32u(&gb);
80+ rgb[1] = bytestream2_get_be32u(&gb);
81+ rgb[2] = bytestream2_get_be32u(&gb);
82+ bytestream2_skipu(&gb, 8);
83+ ncolors = bytestream2_get_be32u(&gb);
84+ bytestream2_skipu(&gb, header_size - (XWD_HEADER_SIZE - 20));
8585
8686 av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n",
8787 pixformat, pixdepth, bunit, bitorder, bpad);
@@ -143,7 +143,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, · 55 unmodified lines
143143 return AVERROR_INVALIDDATA;
144144 }
145145
146− if (buf_size < header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize) {
146+ if (bytestream2_get_bytes_left(&gb) < ncolors * XWD_CMAP_SIZE + avctx->height * lsize) {
147147 av_log(avctx, AV_LOG_ERROR, "input buffer too small\n");
148148 return AVERROR_INVALIDDATA;
149149 }
@@ -192,7 +192,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, · 42 unmodified lines
192192 else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
193193 avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA;
194194 }
195− buf += ncolors * XWD_CMAP_SIZE;
195+ bytestream2_skipu(&gb, ncolors * XWD_CMAP_SIZE);
196196 break;
197197 default:
198198 av_log(avctx, AV_LOG_ERROR, "invalid visual class\n");
@@ -222,11 +222,13 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, · 23 unmodified lines
222222
223223 for (i = 0; i < ncolors; i++) {
224224
225− buf += 4; // skip colormap entry number
226− red = *buf; buf += 2;
227− green = *buf; buf += 2;
228− blue = *buf; buf += 2;
229− buf += 2; // skip bitmask flag and padding
225+ bytestream2_skipu(&gb, 4); // skip colormap entry number
226+ red = bytestream2_get_byteu(&gb);
227+ bytestream2_skipu(&gb, 1);
228+ green = bytestream2_get_byteu(&gb);
229+ bytestream2_skipu(&gb, 1);
230+ blue = bytestream2_get_byteu(&gb);
231+ bytestream2_skipu(&gb, 3); // skip bitmask flag and padding
230232
231233 dst[i] = red << 16 | green << 8 | blue;
232234 }
@@ -234,8 +236,8 @@ static int xwd_decode_frame(AVCodecContext *avctx, void *data, · 1 unmodified line
234236
235237 ptr = p->data[0];
236238 for (i = 0; i < avctx->height; i++) {
237− bytestream_get_buffer(&buf, ptr, rsize);
238− buf += lsize - rsize;
239+ bytestream2_get_bufferu(&gb, ptr, rsize);
240+ bytestream2_skipu(&gb, lsize - rsize);
239241 ptr += p->linesize[0];
240242 }
241243

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t