X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fpnmdec.c;h=01f9dade1a736075d0d1a41811c9780d5ee2d99d;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=958c5e43b07c05a23f7146937070797dafe9a8fa;hpb=41cd5af3250ef976f0a48adeb6dbccc9b2683e58;p=ffmpeg diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index 958c5e43b07..01f9dade1a7 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -46,6 +46,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0; unsigned char *ptr; int components, sample_len, ret; + float scale; s->bytestream_start = s->bytestream = (uint8_t *)buf; @@ -132,7 +133,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, init_put_bits(&pb, ptr, linesize); for(j=0; jwidth * components; j++){ unsigned int c=0; - int v=0; + unsigned v=0; if(s->type < 4) while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' )) s->bytestream++; @@ -143,7 +144,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, v = (*s->bytestream++)&1; } else { /* read a sequence of digits */ - for (k = 0; k < 5 && c <= 9; k += 1) { + for (k = 0; k < 6 && c <= 9; k += 1) { v = 10*v + c; c = (*s->bytestream++) - '0'; } @@ -172,7 +173,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } else if (upgrade == 2) { unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval; for (j = 0; j < n / 2; j++) { - v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + v = AV_RB16(s->bytestream + 2*j); ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; } } @@ -226,7 +227,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; for (i = 0; i < avctx->height; i++) { for (j = 0; j < n / 2; j++) { - v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + v = AV_RB16(s->bytestream + 2*j); ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; } s->bytestream += n; @@ -238,13 +239,13 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, h = avctx->height >> 1; for (i = 0; i < h; i++) { for (j = 0; j < n / 2; j++) { - v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + v = AV_RB16(s->bytestream + 2*j); ptr1[j] = (v * f + 16384) >> 15; } s->bytestream += n; for (j = 0; j < n / 2; j++) { - v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + v = AV_RB16(s->bytestream + 2*j); ptr2[j] = (v * f + 16384) >> 15; } s->bytestream += n; @@ -254,6 +255,72 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } } break; + case AV_PIX_FMT_GBRPF32: + if (avctx->width * avctx->height * 12 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + scale = 1.f / s->scale; + if (s->endian) { + float *r, *g, *b; + + r = (float *)p->data[2]; + g = (float *)p->data[0]; + b = (float *)p->data[1]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + r[j] = av_int2float(AV_RL32(s->bytestream+0)) * scale; + g[j] = av_int2float(AV_RL32(s->bytestream+4)) * scale; + b[j] = av_int2float(AV_RL32(s->bytestream+8)) * scale; + s->bytestream += 12; + } + + r += p->linesize[2] / 4; + g += p->linesize[0] / 4; + b += p->linesize[1] / 4; + } + } else { + float *r, *g, *b; + + r = (float *)p->data[2]; + g = (float *)p->data[0]; + b = (float *)p->data[1]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + r[j] = av_int2float(AV_RB32(s->bytestream+0)) * scale; + g[j] = av_int2float(AV_RB32(s->bytestream+4)) * scale; + b[j] = av_int2float(AV_RB32(s->bytestream+8)) * scale; + s->bytestream += 12; + } + + r += p->linesize[2] / 4; + g += p->linesize[0] / 4; + b += p->linesize[1] / 4; + } + } + break; + case AV_PIX_FMT_GRAYF32: + if (avctx->width * avctx->height * 4 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + scale = 1.f / s->scale; + if (s->endian) { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(AV_RL32(s->bytestream)) * scale; + s->bytestream += 4; + } + g += p->linesize[0] / 4; + } + } else { + float *g = (float *)p->data[0]; + for (int i = 0; i < avctx->height; i++) { + for (int j = 0; j < avctx->width; j++) { + g[j] = av_int2float(AV_RB32(s->bytestream)) * scale; + s->bytestream += 4; + } + g += p->linesize[0] / 4; + } + } + break; } *got_frame = 1; @@ -262,7 +329,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, #if CONFIG_PGM_DECODER -AVCodec ff_pgm_decoder = { +const AVCodec ff_pgm_decoder = { .name = "pgm", .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), .type = AVMEDIA_TYPE_VIDEO, @@ -274,7 +341,7 @@ AVCodec ff_pgm_decoder = { #endif #if CONFIG_PGMYUV_DECODER -AVCodec ff_pgmyuv_decoder = { +const AVCodec ff_pgmyuv_decoder = { .name = "pgmyuv", .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), .type = AVMEDIA_TYPE_VIDEO, @@ -286,7 +353,7 @@ AVCodec ff_pgmyuv_decoder = { #endif #if CONFIG_PPM_DECODER -AVCodec ff_ppm_decoder = { +const AVCodec ff_ppm_decoder = { .name = "ppm", .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), .type = AVMEDIA_TYPE_VIDEO, @@ -298,7 +365,7 @@ AVCodec ff_ppm_decoder = { #endif #if CONFIG_PBM_DECODER -AVCodec ff_pbm_decoder = { +const AVCodec ff_pbm_decoder = { .name = "pbm", .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), .type = AVMEDIA_TYPE_VIDEO, @@ -310,7 +377,7 @@ AVCodec ff_pbm_decoder = { #endif #if CONFIG_PAM_DECODER -AVCodec ff_pam_decoder = { +const AVCodec ff_pam_decoder = { .name = "pam", .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), .type = AVMEDIA_TYPE_VIDEO, @@ -320,3 +387,15 @@ AVCodec ff_pam_decoder = { .capabilities = AV_CODEC_CAP_DR1, }; #endif + +#if CONFIG_PFM_DECODER +const AVCodec ff_pfm_decoder = { + .name = "pfm", + .long_name = NULL_IF_CONFIG_SMALL("PFM (Portable FloatMap) image"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_PFM, + .priv_data_size = sizeof(PNMContext), + .decode = pnm_decode_frame, + .capabilities = AV_CODEC_CAP_DR1, +}; +#endif