Skip to content

Commit

Permalink
add BT.2020 support
Browse files Browse the repository at this point in the history
  • Loading branch information
pingplug committed Feb 2, 2015
1 parent ec685f4 commit d96e470
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ string srt_font:
Defaults to whatever Fontconfig chooses for “sans-serif”.
string colorspace:
The color space of your (YUV) video. Possible values:
- Rec2020, BT.2020
- Rec709, BT.709
- Rec601, BT.601
Default is to use the ASS script’s “Video Colorspace” property, else guess
based on video resolution (width > 1280 or height > 576 → BT.709).
based on video resolution (width > 1920 or height > 1080 → BT.2020,
then width > 1280 or height > 576 → BT.709).
6 changes: 5 additions & 1 deletion src/assrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
data->colorspace = BT709;
else if (!strcasecmp(tmpcsp, "bt.601") || !strcasecmp(tmpcsp, "rec601"))
data->colorspace = BT601;
else if (!strcasecmp(tmpcsp, "bt.2020") || !strcasecmp(tmpcsp, "rec2020"))
data->colorspace = BT2020;
else {
if (fi->vi.width > 1280 || fi->vi.height > 576)
if (fi->vi.width > 1920 || fi->vi.height > 1080)
data->colorspace = BT2020;
else if (fi->vi.width > 1280 || fi->vi.height > 576)
data->colorspace = BT709;
else
data->colorspace = BT601;
Expand Down
3 changes: 2 additions & 1 deletion src/assrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

enum csp {
BT601,
BT709
BT709,
BT2020
};

enum plane { Y, U, V };
Expand Down
10 changes: 8 additions & 2 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ void blit444(ASS_Image* img, uint8_t* dataY, uint8_t* dataU, uint8_t* dataV,
y = rgb2y709(img->color);
u = rgb2u709(img->color);
v = rgb2v709(img->color);
} else {
} else if (colorspace == BT601) {
y = rgb2y601(img->color);
u = rgb2u601(img->color);
v = rgb2v601(img->color);
} else {
y = rgb2y2020(img->color);
u = rgb2u2020(img->color);
v = rgb2v2020(img->color);
}

opacity = 255 - _a(img->color);
Expand Down Expand Up @@ -262,8 +266,10 @@ AVS_VideoFrame* AVSC_CC assrender_get_frame(AVS_FilterInfo* p, int n)

if (ud->colorspace == BT709) {
y = rgb2y709(img->color);
} else {
} else if (ud->colorspace == BT601) {
y = rgb2y601(img->color);
} else {
y = rgb2y2020(img->color);
}

uint8_t opacity = 255 - _a(img->color);
Expand Down
4 changes: 4 additions & 0 deletions src/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#define rgb2u709(c) ((div65536(-6596 * _r(c) - 22189 * _g(c) + 28784 * _b(c)) + 128))
#define rgb2v709(c) ((div65536(28784 * _r(c) - 26145 * _g(c) - 2639 * _b(c)) + 128))

#define rgb2y2020(c) ((div65536(14786 * _r(c) + 38160 * _g(c) + 3338 * _b(c)) + 16))
#define rgb2u2020(c) ((div65536(-8038 * _r(c) - 20746 * _g(c) + 28784 * _b(c)) + 128))
#define rgb2v2020(c) ((div65536(28784 * _r(c) - 26469 * _g(c) - 2315 * _b(c)) + 128))

#define blend(srcA, srcC, dstC) \
((div255(srcA * srcC + (255 - srcA) * dstC)))
#define scale(srcA, srcC, dstC) \
Expand Down

0 comments on commit d96e470

Please sign in to comment.