1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at> |
3 |
|
|
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com> |
4 |
|
|
* |
5 |
|
|
* This file is part of FFmpeg. |
6 |
|
|
* |
7 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
8 |
|
|
* modify it under the terms of the GNU Lesser General Public |
9 |
|
|
* License as published by the Free Software Foundation; either |
10 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
* Lesser General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU Lesser General Public |
18 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "bytestream.h" |
23 |
|
|
#include "internal.h" |
24 |
|
|
|
25 |
|
|
#define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1)) |
26 |
|
|
#define WRITE_PIXELS(a, b, c, depth) \ |
27 |
|
|
do { \ |
28 |
|
|
val = CLIP(*a++, depth) << (10-depth); \ |
29 |
|
|
val |= (CLIP(*b++, depth) << (20-depth)) | \ |
30 |
|
|
(CLIP(*c++, depth) << (30-depth)); \ |
31 |
|
|
AV_WL32(dst, val); \ |
32 |
|
|
dst += 4; \ |
33 |
|
|
} while (0) |
34 |
|
|
|
35 |
|
800 |
static void RENAME(v210_enc)(AVCodecContext *avctx, |
36 |
|
|
uint8_t *dst, const AVFrame *pic) |
37 |
|
|
{ |
38 |
|
800 |
V210EncContext *s = avctx->priv_data; |
39 |
|
800 |
int aligned_width = ((avctx->width + 47) / 48) * 48; |
40 |
|
800 |
int stride = aligned_width * 8 / 3; |
41 |
|
800 |
int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4; |
42 |
|
|
int h, w; |
43 |
|
800 |
const TYPE *y = (const TYPE *)pic->data[0]; |
44 |
|
800 |
const TYPE *u = (const TYPE *)pic->data[1]; |
45 |
|
800 |
const TYPE *v = (const TYPE *)pic->data[2]; |
46 |
|
800 |
const int sample_size = 6 * s->RENAME(sample_factor); |
47 |
|
800 |
const int sample_w = avctx->width / sample_size; |
48 |
|
|
|
49 |
✓✓ |
180400 |
for (h = 0; h < avctx->height; h++) { |
50 |
|
|
uint32_t val; |
51 |
|
179600 |
w = sample_w * sample_size; |
52 |
|
179600 |
s->RENAME(pack_line)(y, u, v, dst, w); |
53 |
|
|
|
54 |
|
179600 |
y += w; |
55 |
|
179600 |
u += w >> 1; |
56 |
|
179600 |
v += w >> 1; |
57 |
|
179600 |
dst += sample_w * 16 * s->RENAME(sample_factor); |
58 |
|
|
|
59 |
✓✓ |
183000 |
for (; w < avctx->width - 5; w += 6) { |
60 |
|
3400 |
WRITE_PIXELS(u, y, v, DEPTH); |
61 |
|
3400 |
WRITE_PIXELS(y, u, y, DEPTH); |
62 |
|
3400 |
WRITE_PIXELS(v, y, u, DEPTH); |
63 |
|
3400 |
WRITE_PIXELS(y, v, y, DEPTH); |
64 |
|
|
} |
65 |
✓✗ |
179600 |
if (w < avctx->width - 1) { |
66 |
|
179600 |
WRITE_PIXELS(u, y, v, DEPTH); |
67 |
|
|
|
68 |
|
179600 |
val = CLIP(*y++, DEPTH) << (10-DEPTH); |
69 |
✗✓ |
179600 |
if (w == avctx->width - 2) { |
70 |
|
|
AV_WL32(dst, val); |
71 |
|
|
dst += 4; |
72 |
|
|
} |
73 |
|
|
} |
74 |
✓✗ |
179600 |
if (w < avctx->width - 3) { |
75 |
|
179600 |
val |= (CLIP(*u++, DEPTH) << (20-DEPTH)) | (CLIP(*y++, DEPTH) << (30-DEPTH)); |
76 |
|
179600 |
AV_WL32(dst, val); |
77 |
|
179600 |
dst += 4; |
78 |
|
|
|
79 |
|
179600 |
val = CLIP(*v++, DEPTH) << (10-DEPTH) | (CLIP(*y++, DEPTH) << (20-DEPTH)); |
80 |
|
179600 |
AV_WL32(dst, val); |
81 |
|
179600 |
dst += 4; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
179600 |
memset(dst, 0, line_padding); |
85 |
|
179600 |
dst += line_padding; |
86 |
|
179600 |
y += pic->linesize[0] / BYTES_PER_PIXEL - avctx->width; |
87 |
|
179600 |
u += pic->linesize[1] / BYTES_PER_PIXEL - avctx->width / 2; |
88 |
|
179600 |
v += pic->linesize[2] / BYTES_PER_PIXEL - avctx->width / 2; |
89 |
|
|
} |
90 |
|
800 |
} |