LCOV - code coverage report
Current view: top level - src/libavcodec - 012v.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 69 80 86.2 %
Date: 2017-01-24 04:42:20 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * 012v decoder
       3             :  *
       4             :  * Copyright (C) 2012 Carl Eugen Hoyos
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "avcodec.h"
      24             : #include "internal.h"
      25             : #include "libavutil/intreadwrite.h"
      26             : 
      27           2 : static av_cold int zero12v_decode_init(AVCodecContext *avctx)
      28             : {
      29           2 :     avctx->pix_fmt             = AV_PIX_FMT_YUV422P16;
      30           2 :     avctx->bits_per_raw_sample = 10;
      31             : 
      32           2 :     if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
      33           0 :         avpriv_request_sample(avctx, "transparency");
      34             : 
      35           2 :     return 0;
      36             : }
      37             : 
      38           1 : static int zero12v_decode_frame(AVCodecContext *avctx, void *data,
      39             :                                 int *got_frame, AVPacket *avpkt)
      40             : {
      41             :     int line, ret;
      42           1 :     const int width = avctx->width;
      43           1 :     AVFrame *pic = data;
      44             :     uint16_t *y, *u, *v;
      45           1 :     const uint8_t *line_end, *src = avpkt->data;
      46           1 :     int stride = avctx->width * 8 / 3;
      47             : 
      48           1 :     if (width <= 1 || avctx->height <= 0) {
      49           0 :         av_log(avctx, AV_LOG_ERROR, "Dimensions %dx%d not supported.\n", width, avctx->height);
      50           0 :         return AVERROR_INVALIDDATA;
      51             :     }
      52             : 
      53           1 :     if (   avctx->codec_tag == MKTAG('0', '1', '2', 'v')
      54           1 :         && avpkt->size % avctx->height == 0
      55           1 :         && avpkt->size / avctx->height * 3 >= width * 8)
      56           1 :         stride = avpkt->size / avctx->height;
      57             : 
      58           1 :     if (avpkt->size < avctx->height * stride) {
      59           0 :         av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
      60           0 :                avpkt->size, avctx->height * stride);
      61           0 :         return AVERROR_INVALIDDATA;
      62             :     }
      63             : 
      64           1 :     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
      65           0 :         return ret;
      66             : 
      67           1 :     pic->pict_type = AV_PICTURE_TYPE_I;
      68           1 :     pic->key_frame = 1;
      69             : 
      70           1 :     line_end = avpkt->data + stride;
      71         241 :     for (line = 0; line < avctx->height; line++) {
      72         240 :         uint16_t y_temp[6] = {0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000};
      73         240 :         uint16_t u_temp[3] = {0x8000, 0x8000, 0x8000};
      74         240 :         uint16_t v_temp[3] = {0x8000, 0x8000, 0x8000};
      75             :         int x;
      76         240 :         y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
      77         240 :         u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
      78         240 :         v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
      79             : 
      80       12720 :         for (x = 0; x < width; x += 6) {
      81             :             uint32_t t;
      82             : 
      83       12720 :             if (width - x < 6 || line_end - src < 16) {
      84         240 :                 y = y_temp;
      85         240 :                 u = u_temp;
      86         240 :                 v = v_temp;
      87             :             }
      88             : 
      89       12720 :             if (line_end - src < 4)
      90           0 :                 break;
      91             : 
      92       12720 :             t = AV_RL32(src);
      93       12720 :             src += 4;
      94       12720 :             *u++ = t <<  6 & 0xFFC0;
      95       12720 :             *y++ = t >>  4 & 0xFFC0;
      96       12720 :             *v++ = t >> 14 & 0xFFC0;
      97             : 
      98       12720 :             if (line_end - src < 4)
      99           0 :                 break;
     100             : 
     101       12720 :             t = AV_RL32(src);
     102       12720 :             src += 4;
     103       12720 :             *y++ = t <<  6 & 0xFFC0;
     104       12720 :             *u++ = t >>  4 & 0xFFC0;
     105       12720 :             *y++ = t >> 14 & 0xFFC0;
     106             : 
     107       12720 :             if (line_end - src < 4)
     108           0 :                 break;
     109             : 
     110       12720 :             t = AV_RL32(src);
     111       12720 :             src += 4;
     112       12720 :             *v++ = t <<  6 & 0xFFC0;
     113       12720 :             *y++ = t >>  4 & 0xFFC0;
     114       12720 :             *u++ = t >> 14 & 0xFFC0;
     115             : 
     116       12720 :             if (line_end - src < 4)
     117           0 :                 break;
     118             : 
     119       12720 :             t = AV_RL32(src);
     120       12720 :             src += 4;
     121       12720 :             *y++ = t <<  6 & 0xFFC0;
     122       12720 :             *v++ = t >>  4 & 0xFFC0;
     123       12720 :             *y++ = t >> 14 & 0xFFC0;
     124             : 
     125       12720 :             if (width - x < 6)
     126         240 :                 break;
     127             :         }
     128             : 
     129         240 :         if (x < width) {
     130         240 :             y = x   + (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
     131         240 :             u = x/2 + (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
     132         240 :             v = x/2 + (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
     133         240 :             memcpy(y, y_temp, sizeof(*y) * (width - x));
     134         240 :             memcpy(u, u_temp, sizeof(*u) * (width - x + 1) / 2);
     135         240 :             memcpy(v, v_temp, sizeof(*v) * (width - x + 1) / 2);
     136             :         }
     137             : 
     138         240 :         line_end += stride;
     139         240 :         src = line_end - stride;
     140             :     }
     141             : 
     142           1 :     *got_frame = 1;
     143             : 
     144           1 :     return avpkt->size;
     145             : }
     146             : 
     147             : AVCodec ff_zero12v_decoder = {
     148             :     .name           = "012v",
     149             :     .long_name      = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
     150             :     .type           = AVMEDIA_TYPE_VIDEO,
     151             :     .id             = AV_CODEC_ID_012V,
     152             :     .init           = zero12v_decode_init,
     153             :     .decode         = zero12v_decode_frame,
     154             :     .capabilities   = AV_CODEC_CAP_DR1,
     155             : };

Generated by: LCOV version 1.12