/src/ffmpeg/libavformat/dvdclut.c
Line | Count | 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 | 0 | { |
32 | 0 | AVBPrint bp; |
33 | |
|
34 | 0 | if (clut_size != FF_DVDCLUT_CLUT_SIZE) |
35 | 0 | return AVERROR(EINVAL); |
36 | | |
37 | 0 | av_bprint_init(&bp, 0, FF_DVDCLUT_EXTRADATA_SIZE); |
38 | |
|
39 | 0 | av_bprintf(&bp, "palette: "); |
40 | |
|
41 | 0 | for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) |
42 | 0 | av_bprintf(&bp, "%06"PRIx32"%s", clut[i], |
43 | 0 | i != (FF_DVDCLUT_CLUT_LEN - 1) ? ", " : ""); |
44 | |
|
45 | 0 | av_bprintf(&bp, "\n"); |
46 | |
|
47 | 0 | return ff_bprint_to_codecpar_extradata(par, &bp); |
48 | 0 | } |
49 | | |
50 | | int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size) |
51 | 0 | { |
52 | 0 | int y, cb, cr; |
53 | 0 | uint8_t r, g, b; |
54 | 0 | int r_add, g_add, b_add; |
55 | |
|
56 | 0 | if (clut_size != FF_DVDCLUT_CLUT_SIZE) |
57 | 0 | return AVERROR(EINVAL); |
58 | | |
59 | 0 | for (int i = 0; i < FF_DVDCLUT_CLUT_LEN; i++) { |
60 | 0 | y = (clut[i] >> 16) & 0xFF; |
61 | 0 | cr = (clut[i] >> 8) & 0xFF; |
62 | 0 | cb = clut[i] & 0xFF; |
63 | |
|
64 | 0 | YUV_TO_RGB1_CCIR(cb, cr); |
65 | |
|
66 | 0 | y = (y - 16) * FIX(255.0 / 219.0); |
67 | 0 | r = av_clip_uint8((y + r_add - 1024) >> SCALEBITS); |
68 | 0 | g = av_clip_uint8((y + g_add - 1024) >> SCALEBITS); |
69 | 0 | b = av_clip_uint8((y + b_add - 1024) >> SCALEBITS); |
70 | |
|
71 | 0 | clut[i] = (r << 16) | (g << 8) | b; |
72 | 0 | } |
73 | |
|
74 | 0 | return 0; |
75 | 0 | } |