FFmpeg
Loading...
Searching...
No Matches
dvdclut.c
Go to the documentation of this file.
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"
23#include "libavutil/common.h"
24
25#include "dvdclut.h"
26#include "internal.h"
27
28int ff_dvdclut_palette_extradata_cat(const uint32_t *clut,
29 const size_t clut_size,
31{
32 AVBPrint bp;
33
34 if (clut_size != FF_DVDCLUT_CLUT_SIZE)
35 return AVERROR(EINVAL);
36
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
50int 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
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}
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:122
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:69
AVBPrint public header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
common internal and external API header
#define av_clip_uint8
Definition common.h:106
int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size)
Definition dvdclut.c:50
int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, const size_t clut_size, AVCodecParameters *par)
Definition dvdclut.c:28
#define FF_DVDCLUT_CLUT_SIZE
Definition dvdclut.h:29
#define FF_DVDCLUT_CLUT_LEN
Definition dvdclut.h:28
#define FF_DVDCLUT_EXTRADATA_SIZE
Definition dvdclut.h:27
#define AVERROR(e)
Definition error.h:45
#define r
Definition input.c:42
#define b
Definition input.c:43
#define FIX(x)
Definition jrevdct.c:148
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition utils.c:593
Various defines for YUV<->RGB conversion.
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition colorspace.h:34
#define SCALEBITS
Definition colorspace.h:30
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
const char * g
Definition vf_curves.c:128
static double cr(void *priv, double x, double y)
Definition vf_geq.c:248
static double cb(void *priv, double x, double y)
Definition vf_geq.c:247