FFmpeg
Loading...
Searching...
No Matches
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 "codec_internal.h"
25#include "decode.h"
27
29{
31 avctx->bits_per_raw_sample = 10;
32
33 if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
34 avpriv_request_sample(avctx, "transparency");
35
36 return 0;
37}
38
40 int *got_frame, AVPacket *avpkt)
41{
42 int line, ret;
43 const int width = avctx->width;
44 uint16_t *y, *u, *v;
45 const uint8_t *line_end, *src = avpkt->data;
46 int stride = avctx->width * 8 / 3;
47
49 av_log(avctx, AV_LOG_ERROR, "Dimensions %dx%d not supported.\n", width, avctx->height);
51 }
52
53 if ( avctx->codec_tag == MKTAG('0', '1', '2', 'v')
54 && avpkt->size % avctx->height == 0
55 && avpkt->size / avctx->height * 3 >= width * 8)
56 stride = avpkt->size / avctx->height;
57
58 if (avpkt->size < avctx->height * stride) {
59 av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
60 avpkt->size, avctx->height * stride);
62 }
63
64 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
65 return ret;
66
67 line_end = avpkt->data + stride;
68 for (line = 0; line < avctx->height; line++) {
69 uint16_t y_temp[6] = {0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000};
70 uint16_t u_temp[3] = {0x8000, 0x8000, 0x8000};
71 uint16_t v_temp[3] = {0x8000, 0x8000, 0x8000};
72 int x;
73 y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
74 u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
75 v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
76
77 for (x = 0; x < width; x += 6) {
78 uint32_t t;
79
80 if (width - x < 6 || line_end - src < 16) {
81 y = y_temp;
82 u = u_temp;
83 v = v_temp;
84 }
85
86 if (line_end - src < 4)
87 break;
88
89 t = AV_RL32(src);
90 src += 4;
91 *u++ = t << 6 & 0xFFC0;
92 *y++ = t >> 4 & 0xFFC0;
93 *v++ = t >> 14 & 0xFFC0;
94
95 if (line_end - src < 4)
96 break;
97
98 t = AV_RL32(src);
99 src += 4;
100 *y++ = t << 6 & 0xFFC0;
101 *u++ = t >> 4 & 0xFFC0;
102 *y++ = t >> 14 & 0xFFC0;
103
104 if (line_end - src < 4)
105 break;
106
107 t = AV_RL32(src);
108 src += 4;
109 *v++ = t << 6 & 0xFFC0;
110 *y++ = t >> 4 & 0xFFC0;
111 *u++ = t >> 14 & 0xFFC0;
112
113 if (line_end - src < 4)
114 break;
115
116 t = AV_RL32(src);
117 src += 4;
118 *y++ = t << 6 & 0xFFC0;
119 *v++ = t >> 4 & 0xFFC0;
120 *y++ = t >> 14 & 0xFFC0;
121
122 if (width - x < 6)
123 break;
124 }
125
126 if (x < width) {
127 y = x + (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
128 u = x/2 + (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
129 v = x/2 + (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
130 memcpy(y, y_temp, sizeof(*y) * (width - x));
131 memcpy(u, u_temp, sizeof(*u) * ((width - x + 1) / 2));
132 memcpy(v, v_temp, sizeof(*v) * ((width - x + 1) / 2));
133 }
134
135 line_end += stride;
136 src = line_end - stride;
137 }
138
139 *got_frame = 1;
140
141 return avpkt->size;
142}
143
145 .p.name = "012v",
146 CODEC_LONG_NAME("Uncompressed 4:2:2 10-bit"),
147 .p.type = AVMEDIA_TYPE_VIDEO,
148 .p.id = AV_CODEC_ID_012V,
149 .init = zero12v_decode_init,
151 .p.capabilities = AV_CODEC_CAP_DR1,
152};
static av_cold int zero12v_decode_init(AVCodecContext *avctx)
Definition 012v.c:28
static int zero12v_decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_frame, AVPacket *avpkt)
Definition 012v.c:39
const FFCodec ff_zero12v_decoder
Definition 012v.c:144
Libavcodec external API header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_012V
Definition codec_id.h:251
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_RL32(p)
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
#define av_cold
Definition attributes.h:117
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
#define stride
#define avpriv_request_sample(...)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89