diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-03-28 05:23:46 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-03-28 05:26:24 +0100 |
commit | 296e63efa56f1fb454cafb5c7f54dfb80cbfbab4 (patch) | |
tree | 03b3e65e5267e1fe5870603ec59999ef3d139fee /libavcodec/xbmdec.c | |
parent | 6bd05ed8bb3010322a9285a29e0ea8b0934b63e9 (diff) | |
parent | 678082b409aca711f9cf991df6b0200116489322 (diff) | |
download | ffmpeg-296e63efa56f1fb454cafb5c7f54dfb80cbfbab4.tar.gz |
Merge commit '678082b409aca711f9cf991df6b0200116489322'
* commit '678082b409aca711f9cf991df6b0200116489322':
X-Bitmap decoder
Conflicts:
Changelog
libavcodec/Makefile
libavcodec/allcodecs.c
libavcodec/version.h
libavcodec/xbmdec.c
See: a0340dfbd78df7639715056937011d2d414aaeed
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/xbmdec.c')
-rw-r--r-- | libavcodec/xbmdec.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c index 2976bec8ac..b9a46d74d0 100644 --- a/libavcodec/xbmdec.c +++ b/libavcodec/xbmdec.c @@ -20,17 +20,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avstring.h" + #include "avcodec.h" #include "internal.h" #include "mathops.h" -#include "libavutil/avstring.h" - -static av_cold int xbm_decode_init(AVCodecContext *avctx) -{ - avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; - - return 0; -} static int convert(uint8_t x) { @@ -47,33 +41,42 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { AVFrame *p = data; + int ret, linesize, i, j; + int width = 0; + int height = 0; const uint8_t *end, *ptr = avpkt->data; uint8_t *dst; - int ret, linesize, i, j; + avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; end = avpkt->data + avpkt->size; - while (!avctx->width || !avctx->height) { + while (!width || !height) { char name[256]; int number, len; ptr += strcspn(ptr, "#"); + if (ptr >= avpkt->data + avpkt->size) { + av_log(avctx, AV_LOG_ERROR, "End of file reached.\n"); + return AVERROR_INVALIDDATA; + } if (sscanf(ptr, "#define %255s %u", name, &number) != 2) { av_log(avctx, AV_LOG_ERROR, "Unexpected preprocessor directive\n"); return AVERROR_INVALIDDATA; } len = strlen(name); - if ((len > 6) && !avctx->height && !memcmp(name + len - 7, "_height", 7)) { - avctx->height = number; - } else if ((len > 5) && !avctx->width && !memcmp(name + len - 6, "_width", 6)) { - avctx->width = number; + if ((len > 6) && !height && !memcmp(name + len - 7, "_height", 7)) { + height = number; + } else if ((len > 5) && !width && !memcmp(name + len - 6, "_width", 6)) { + width = number; } else { - av_log(avctx, AV_LOG_ERROR, "Unknown define '%s'\n", name); - return AVERROR_INVALIDDATA; + av_log(avctx, AV_LOG_WARNING, "Unknown define '%s'\n", name); } ptr += strcspn(ptr, "\n\r") + 1; } + if ((ret = ff_set_dimensions(avctx, width, height)) < 0) + return ret; + if ((ret = ff_get_buffer(avctx, p, 0)) < 0) return ret; @@ -94,7 +97,8 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data, val = (val << 4) + convert(*ptr); *dst++ = ff_reverse[val]; } else { - av_log(avctx, AV_LOG_ERROR, "Unexpected data at '%.8s'\n", ptr); + av_log(avctx, AV_LOG_ERROR, + "Unexpected data at %.8s.\n", ptr); return AVERROR_INVALIDDATA; } } @@ -113,7 +117,6 @@ AVCodec ff_xbm_decoder = { .long_name = NULL_IF_CONFIG_SMALL("XBM (X BitMap) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_XBM, - .init = xbm_decode_init, .decode = xbm_decode_frame, .capabilities = CODEC_CAP_DR1, }; |