FFmpeg
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"
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 
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 
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 }
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:247
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
b
#define b
Definition: input.c:41
YUV_TO_RGB1_CCIR
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition: colorspace.h:34
ff_dvdclut_yuv_to_rgb
int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size)
Definition: dvdclut.c:50
ff_bprint_to_codecpar_extradata
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:577
FF_DVDCLUT_CLUT_LEN
#define FF_DVDCLUT_CLUT_LEN
Definition: dvdclut.h:28
FF_DVDCLUT_CLUT_SIZE
#define FF_DVDCLUT_CLUT_SIZE
Definition: dvdclut.h:29
colorspace.h
g
const char * g
Definition: vf_curves.c:128
dvdclut.h
internal.h
FIX
#define FIX(x)
Definition: jrevdct.c:148
FF_DVDCLUT_EXTRADATA_SIZE
#define FF_DVDCLUT_EXTRADATA_SIZE
Definition: dvdclut.h:27
ff_dvdclut_palette_extradata_cat
int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, const size_t clut_size, AVCodecParameters *par)
Definition: dvdclut.c:28
bprint.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
common.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
SCALEBITS
#define SCALEBITS
Definition: colorspace.h:30
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:248