[FFmpeg-devel] [PATCH v4] lavc/rawdec: Use AV_PIX_FMT_PAL8 for 1-bit raw QuickTime video

Michael Niedermayer michael at niedermayer.cc
Mon Jan 18 12:02:10 CET 2016


On Mon, Jan 18, 2016 at 08:43:50AM +0100, Mats Peterson wrote:
> Eliminated some calculations inside loops.
> 
> Mats

>  raw.c    |    4 ++--
>  rawdec.c |   49 +++++++++++++++++++++++++++++++------------------
>  2 files changed, 33 insertions(+), 20 deletions(-)
> fc79f935e8da23cc724a5a766e81b1fee6fa0f49  0001-lavc-rawdec-Use-AV_PIX_FMT_PAL8-for-1-bit-raw-QuickT.patch
> From e836bfee99b6de39acfe023c3a50b4e5b53f82e1 Mon Sep 17 00:00:00 2001
> From: Mats Peterson <matsp888 at yahoo.com>
> Date: Mon, 18 Jan 2016 08:40:57 +0100
> Subject: [PATCH v4] lavc/rawdec: Use AV_PIX_FMT_PAL8 for 1-bit raw QuickTime video
> 
> Match the use of AV_PIX_FMT_PAL8 for 1-bit QuickTime Animation in
> lavc/qtrle. To reiterate, 1-bit video is not necessary black & white in
> QuickTime, merely bi-level. The two colors can be any color. The palette,
> either included in the sample description, or the default Macintosh
> palette (black & white for 1-bit video) will be set in lavf/qtpalette.
> See the QuickTime File Format Specification for details.
> 
> ---
>  libavcodec/raw.c    |    4 ++--
>  libavcodec/rawdec.c |   49 +++++++++++++++++++++++++++++++------------------
>  2 files changed, 33 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/raw.c b/libavcodec/raw.c
> index cda70ac..3f2cc11 100644
> --- a/libavcodec/raw.c
> +++ b/libavcodec/raw.c
> @@ -255,13 +255,13 @@ const PixelFormatTag avpriv_pix_fmt_bps_avi[] = {
>  };
>  
>  const PixelFormatTag avpriv_pix_fmt_bps_mov[] = {
> -    { AV_PIX_FMT_MONOWHITE, 1 },
> +    { AV_PIX_FMT_PAL8,      1 },
>      { AV_PIX_FMT_PAL8,      2 },
>      { AV_PIX_FMT_PAL8,      4 },
>      { AV_PIX_FMT_PAL8,      8 },
>      { AV_PIX_FMT_RGB555BE, 16 },
>      { AV_PIX_FMT_RGB24,    24 },
>      { AV_PIX_FMT_ARGB,     32 },
> -    { AV_PIX_FMT_MONOWHITE,33 },
> +    { AV_PIX_FMT_PAL8,     33 },
>      { AV_PIX_FMT_NONE,      0 },

the decoder should check the palette, and if it differs from
black+white use PAL8
users quite possible could complain if monochrome raw files suddenly
become 8 times as large when its not needed


>  };
> diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
> index 50cee39..0f765af 100644
> --- a/libavcodec/rawdec.c
> +++ b/libavcodec/rawdec.c
> @@ -41,7 +41,7 @@ typedef struct RawVideoContext {
>      AVBufferRef *palette;
>      int frame_size;  /* size of the frame in bytes */
>      int flip;
> -    int is_2_4_bpp; // 2 or 4 bpp raw in avi/mov
> +    int is_1_2_4_bpp; // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov
>      int is_yuv2;
>      int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16
>      int tff;
> @@ -159,12 +159,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
>  
>      AVFrame   *frame   = data;
>  
> -    if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
> +    if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2
> +            || avctx->bits_per_coded_sample == 1) &&
>          avctx->pix_fmt == AV_PIX_FMT_PAL8 &&
>         (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) {
> -        context->is_2_4_bpp = 1;
> +        context->is_1_2_4_bpp = 1;
>          context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
> -                                                       FFALIGN(avctx->width, 16),
> +                                                       FFALIGN(avctx->width, 32),
>                                                         avctx->height, 1);
>      } else {
>          context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16;
> @@ -174,7 +175,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
>      if (context->frame_size < 0)
>          return context->frame_size;
>  
> -    need_copy = !avpkt->buf || context->is_2_4_bpp || context->is_yuv2 || context->is_lt_16bpp;
> +    need_copy = !avpkt->buf || context->is_1_2_4_bpp || context->is_yuv2 || context->is_lt_16bpp;
>  
>      frame->pict_type        = AV_PICTURE_TYPE_I;
>      frame->key_frame        = 1;
> @@ -201,26 +202,38 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
>      if (!frame->buf[0])
>          return AVERROR(ENOMEM);
>  
> -    //2bpp and 4bpp raw in avi and mov (yes this is ugly ...)
> -    if (context->is_2_4_bpp) {
> -        int i;
> +    // 1 bpp raw in mov, and 2 or 4 bpp raw in avi/mov
> +    if (context->is_1_2_4_bpp) {
> +        int i, j = 0;
>          uint8_t *dst = frame->buf[0]->data;
>          buf_size = context->frame_size - AVPALETTE_SIZE;


>          if (avctx->bits_per_coded_sample == 4) {
> -            for (i = 0; 2 * i + 1 < buf_size && i<avpkt->size; i++) {
> -                dst[2 * i + 0] = buf[i] >> 4;
> -                dst[2 * i + 1] = buf[i] & 15;
> +            for (i = 0; j + 1 < buf_size && i<avpkt->size; i++) {
> +                dst[j++] = buf[i] >> 4;
> +                dst[j++] = buf[i] & 15;
>              }

thats unrelated and should be in a seperate patch if it is faster
if its not faster it should not be done

you can test the speed with START/STOP_TIMER


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160118/f7bb408b/attachment.sig>


More information about the ffmpeg-devel mailing list