Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* DVD-Video subpicture CLUT (Color Lookup Table) utilities |
3 |
|
|
* |
4 |
|
|
* This file is part of FFmpeg. |
5 |
|
|
* |
6 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public |
8 |
|
|
* License as published by the Free Software Foundation; either |
9 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
* Lesser General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU Lesser General Public |
17 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "libavutil/bprint.h" |
22 |
|
|
#include "libavutil/colorspace.h" |
23 |
|
|
#include "libavutil/common.h" |
24 |
|
|
|
25 |
|
|
#include "dvdclut.h" |
26 |
|
|
#include "internal.h" |
27 |
|
|
|
28 |
|
✗ |
int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, |
29 |
|
|
const size_t clut_size, |
30 |
|
|
AVCodecParameters *par) |
31 |
|
|
{ |
32 |
|
|
AVBPrint bp; |
33 |
|
|
|
34 |
|
✗ |
if (clut_size != FF_DVDCLUT_CLUT_SIZE) |
35 |
|
✗ |
return AVERROR(EINVAL); |
36 |
|
|
|
37 |
|
✗ |
av_bprint_init(&bp, 0, FF_DVDCLUT_EXTRADATA_SIZE); |
38 |
|
|
|
39 |
|
✗ |
av_bprintf(&bp, "palette: "); |
40 |
|
|
|
41 |
|
✗ |
for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) |
42 |
|
✗ |
av_bprintf(&bp, "%06"PRIx32"%s", clut[i], |
43 |
|
|
i != (FF_DVDCLUT_CLUT_LEN - 1) ? ", " : ""); |
44 |
|
|
|
45 |
|
✗ |
av_bprintf(&bp, "\n"); |
46 |
|
|
|
47 |
|
✗ |
return ff_bprint_to_codecpar_extradata(par, &bp); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
✗ |
int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size) |
51 |
|
|
{ |
52 |
|
|
int y, cb, cr; |
53 |
|
|
uint8_t r, g, b; |
54 |
|
|
int r_add, g_add, b_add; |
55 |
|
|
|
56 |
|
✗ |
if (clut_size != FF_DVDCLUT_CLUT_SIZE) |
57 |
|
✗ |
return AVERROR(EINVAL); |
58 |
|
|
|
59 |
|
✗ |
for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) { |
60 |
|
✗ |
y = (clut[i] >> 16) & 0xFF; |
61 |
|
✗ |
cr = (clut[i] >> 8) & 0xFF; |
62 |
|
✗ |
cb = clut[i] & 0xFF; |
63 |
|
|
|
64 |
|
✗ |
YUV_TO_RGB1_CCIR(cb, cr); |
65 |
|
|
|
66 |
|
✗ |
y = (y - 16) * FIX(255.0 / 219.0); |
67 |
|
✗ |
r = av_clip_uint8((y + r_add - 1024) >> SCALEBITS); |
68 |
|
✗ |
g = av_clip_uint8((y + g_add - 1024) >> SCALEBITS); |
69 |
|
✗ |
b = av_clip_uint8((y + b_add - 1024) >> SCALEBITS); |
70 |
|
|
|
71 |
|
✗ |
clut[i] = (r << 16) | (g << 8) | b; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
return 0; |
75 |
|
|
} |
76 |
|
|
|