FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
012v.c
Go to the documentation of this file.
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 
28 {
30  avctx->bits_per_raw_sample = 10;
31 
32  if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
33  avpriv_request_sample(avctx, "transparency");
34 
35  return 0;
36 }
37 
38 static int zero12v_decode_frame(AVCodecContext *avctx, void *data,
39  int *got_frame, AVPacket *avpkt)
40 {
41  int line = 0, ret;
42  const int width = avctx->width;
43  AVFrame *pic = data;
44  uint16_t *y, *u, *v;
45  const uint8_t *line_end, *src = avpkt->data;
46  int stride = avctx->width * 8 / 3;
47 
48  if (width == 1) {
49  av_log(avctx, AV_LOG_ERROR, "Width 1 not supported.\n");
50  return AVERROR_INVALIDDATA;
51  }
52  if (avpkt->size < avctx->height * stride) {
53  av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
54  avpkt->size, avctx->height * stride);
55  return AVERROR_INVALIDDATA;
56  }
57 
58  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
59  return ret;
60 
62  pic->key_frame = 1;
63 
64  y = (uint16_t *)pic->data[0];
65  u = (uint16_t *)pic->data[1];
66  v = (uint16_t *)pic->data[2];
67  line_end = avpkt->data + stride;
68 
69  while (line++ < avctx->height) {
70  while (1) {
71  uint32_t t = AV_RL32(src);
72  src += 4;
73  *u++ = t << 6 & 0xFFC0;
74  *y++ = t >> 4 & 0xFFC0;
75  *v++ = t >> 14 & 0xFFC0;
76 
77  if (src >= line_end - 1) {
78  *y = 0x80;
79  src++;
80  line_end += stride;
81  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
82  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
83  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
84  break;
85  }
86 
87  t = AV_RL32(src);
88  src += 4;
89  *y++ = t << 6 & 0xFFC0;
90  *u++ = t >> 4 & 0xFFC0;
91  *y++ = t >> 14 & 0xFFC0;
92  if (src >= line_end - 2) {
93  if (!(width & 1)) {
94  *y = 0x80;
95  src += 2;
96  }
97  line_end += stride;
98  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
99  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
100  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
101  break;
102  }
103 
104  t = AV_RL32(src);
105  src += 4;
106  *v++ = t << 6 & 0xFFC0;
107  *y++ = t >> 4 & 0xFFC0;
108  *u++ = t >> 14 & 0xFFC0;
109 
110  if (src >= line_end - 1) {
111  *y = 0x80;
112  src++;
113  line_end += stride;
114  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
115  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
116  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
117  break;
118  }
119 
120  t = AV_RL32(src);
121  src += 4;
122  *y++ = t << 6 & 0xFFC0;
123  *v++ = t >> 4 & 0xFFC0;
124  *y++ = t >> 14 & 0xFFC0;
125 
126  if (src >= line_end - 2) {
127  if (width & 1) {
128  *y = 0x80;
129  src += 2;
130  }
131  line_end += stride;
132  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
133  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
134  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
135  break;
136  }
137  }
138  }
139 
140  *got_frame = 1;
141 
142  return avpkt->size;
143 }
144 
146  .name = "012v",
147  .type = AVMEDIA_TYPE_VIDEO,
148  .id = AV_CODEC_ID_012V,
149  .init = zero12v_decode_init,
150  .decode = zero12v_decode_frame,
151  .capabilities = CODEC_CAP_DR1,
152  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
153 };