Skip to content

Commit 7418554

Browse files
authored
Merge pull request #50 from seiya-dev/dev
Tweak matrix guess by video size + Work with frame copy instead of just modifying it
2 parents db5c699 + 87baff4 commit 7418554

7 files changed

Lines changed: 154 additions & 95 deletions

File tree

docs/BUILD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- set PKG_CONFIG_PATH env `setx PKG_CONFIG_PATH "C:/lib/pkgconfig"`
88

99
* Clone repos
10-
- Clone `git clone https://github.com/seiya-dev/assrender.git`
10+
- Clone `git clone https://github.com/pinterf/assrender.git`
1111
- and clone libass as subdirectory `cd assrender && git clone https://github.com/libass/libass.git`
1212

1313
* Prequisite: avisynth.lib versions (x86 and x64)
@@ -30,7 +30,7 @@
3030

3131
### Linux
3232
* Clone repo
33-
- git clone https://github.com/seiya-dev/assrender
33+
- git clone https://github.com/pinterf/assrender
3434
- cd assrender
3535
- cmake -B build -S .
3636
- cmake --build build --clean-first

docs/CHANGELOG.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
## Change log
22

3-
### 0.36.0-dev.3 (20251202)
4-
* Use frame properties if they available for "YCbCr Matrix: None"
5-
6-
### 0.36.0-dev.2 (20251201)
7-
* Restore x86-32 assrender.dll build
8-
9-
### 0.36.0-dev.1 (20251201)
3+
### 0.36.0-dev.5 (20251209)
4+
* Fix hinting
5+
* Fix ass_set_storage_size not be called
106
* Switch submodule build system to meson
117
* Update avisynth(plus) headers to v12
8+
* Update libass to 0.17.4
129
* Unicode-safe file reading
1310
* Add frame size parameters
1411
* Add set_default_storage_size boolean
15-
* Update libass to 0.17.4
12+
* Use frame properties if they available for "YCbCr Matrix: None"
13+
* Work with frame copy instead of just modifying it
1614

1715
### 0.35 (20210304)
1816
* Windows MSVC: Update to libass v0.15
@@ -26,7 +24,7 @@
2624
* Fix: possible crash on initializing phase (buffer overread, linux crashed, Windows was just lucky)
2725

2826
### 0.34 (20210301)
29-
* Fix the fix: revert matrix change made in 0.33
27+
* Fix the fix: revert matrix change made in 0.33
3028
* Fix: Check matrix from .ASS file "YCbCr Matrix:" section besides "Video Colorspace:"
3129
Recognized values are "tv.601" and "tv.709"
3230

docs/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ Default is to use the ASS script's "YCbCr Matrix" or "Video Colorspace" property
8181

8282
Recognized .ASS properties: "TV.601" "TV.709", "PC.601" "PC.709" "TV.240m" "PC.240m" "TV.fcc" "PC.fcc" and "none".
8383

84-
"none" and "guess" decides upon on video resolution: width > 1280 or height > 576 → BT.709, else → BT.601.
85-
When no hint found in ASS script and 'colorspace' parameter is empty then the default is BT.601.
84+
"none" and "guess" determine the colorspace based on the video's `_Matrix` frame property if available. Otherwise, if the resolution is width > 1024 or height > 576, BT.709 is used; otherwise BT.601.
8685

8786
## Build instructions
8887
See: [BUILD.md](BUILD.md)

src/assrender.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ static const char* detect_bom(const char* buf, const size_t bufsize) {
5757
return "UTF-8";
5858
}
5959

60-
#ifdef _WIN32
61-
#define WIN32_LEAN_AND_MEAN
62-
#include <windows.h>
63-
#else
64-
#include <sys/stat.h>
65-
#endif
66-
6760
#ifdef _WIN32
6861
static wchar_t *utf8_to_utf16le(const char *data) {
6962
const int out_size = MultiByteToWideChar(CP_UTF8, 0, data, -1, NULL, 0);
@@ -216,7 +209,6 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
216209
AVS_FilterInfo* fi;
217210
AVS_Clip* c = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1);
218211
const AVS_VideoInfo *vi = &fi->vi;
219-
char e[250];
220212

221213
const char* f = avs_as_string(avs_array_elt(args, 1));
222214
const char* vfr = avs_as_string(avs_array_elt(args, 2));
@@ -318,7 +310,7 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
318310
if (!strcasecmp(strrchr(f, '.'), ".srt")) {
319311
FILE* fp = open_utf8_filename(f, "r");
320312
if (!fp) {
321-
sprintf(e, "AssRender: input file '%s' does not exist or is not a regular file", f);
313+
const char* e = avs_sprintf(env, "AssRender: input file '%s' does not exist or is not a regular file", f);
322314
v = avs_new_value_error(e);
323315
avs_release_clip(c);
324316
return v;
@@ -330,15 +322,15 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
330322

331323
fp = open_utf8_filename(f, "rb");
332324
if (!fp) {
333-
sprintf(e, "AssRender: input file '%s' does not exist or is not a regular file", f);
325+
const char* e = avs_sprintf(env, "AssRender: input file '%s' does not exist or is not a regular file", f);
334326
v = avs_new_value_error(e);
335327
avs_release_clip(c);
336328
return v;
337329
}
338330

339331
buf = read_file_bytes(fp, &bufsize);
340332
if (!buf) {
341-
sprintf(e, "AssRender: unable to read '%s'", f);
333+
const char* e = avs_sprintf(env, "AssRender: unable to read '%s'", f);
342334
v = avs_new_value_error(e);
343335
avs_release_clip(c);
344336
return v;
@@ -358,7 +350,7 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
358350
}
359351

360352
if (!ass) {
361-
sprintf(e, "AssRender: unable to parse '%s'", f);
353+
const char* e = avs_sprintf(env, "AssRender: unable to parse '%s'", f);
362354
v = avs_new_value_error(e);
363355
avs_release_clip(c);
364356
return v;
@@ -371,7 +363,7 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
371363
FILE* fh = open_utf8_filename(vfr, "r");
372364

373365
if (!fh) {
374-
sprintf(e, "AssRender: could not read timecodes file '%s'", vfr);
366+
const char* e = avs_sprintf(env, "AssRender: could not read timecodes file '%s'", vfr);
375367
v = avs_new_value_error(e);
376368
avs_release_clip(c);
377369
return v;
@@ -380,7 +372,7 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
380372
data->isvfr = 1;
381373

382374
if (fscanf(fh, "# timecode format v%d", &ver) != 1) {
383-
sprintf(e, "AssRender: invalid timecodes file '%s'", vfr);
375+
const char* e = avs_sprintf(env, "AssRender: invalid timecodes file '%s'", vfr);
384376
v = avs_new_value_error(e);
385377
avs_release_clip(c);
386378
return v;
@@ -450,13 +442,6 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
450442
color_mt = MATRIX_BT2020;
451443
}
452444
else if (!strcasecmp(tmpcsp, "none") || !strcasecmp(tmpcsp, "guess")) {
453-
/* not yet
454-
* Theoretically only for 10 and 12 bits:
455-
if (fi->vi.width > 1920 || fi->vi.height > 1080)
456-
color_mt = MATRIX_BT2020;
457-
else
458-
*/
459-
460445
int mt_from_props_ok = 0;
461446
matrix_type mt_from_props = MATRIX_NONE;
462447

@@ -467,10 +452,16 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
467452
if (mt_from_props_ok && mt_from_props != MATRIX_NONE) {
468453
color_mt = mt_from_props;
469454
} else {
470-
if (vi->width >= 1280 || vi->height >= 576) {
471-
color_mt = MATRIX_PC709;
455+
/* not yet
456+
* Theoretically only for 10 and 12 bits:
457+
if (fi->vi.width > 1920 || fi->vi.height > 1080)
458+
color_mt = MATRIX_BT2020;
459+
else
460+
*/
461+
if (vi->width > 1024 || vi->height > 576) {
462+
color_mt = MATRIX_BT709;
472463
} else {
473-
color_mt = MATRIX_PC601;
464+
color_mt = MATRIX_BT601;
474465
}
475466
}
476467
}
@@ -501,7 +492,6 @@ AVS_Value AVSC_CC assrender_create(AVS_ScriptEnvironment* env, AVS_Value args,
501492
return v;
502493
}
503494

504-
505495
switch (fi->vi.pixel_type)
506496
{
507497
case AVS_CS_YV12:

src/assrender.h

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,50 @@
99
#include <string.h>
1010
#include <time.h>
1111
#include <ass/ass.h>
12+
13+
#ifdef _WIN32
14+
# define WIN32_LEAN_AND_MEAN
15+
# include <windows.h>
16+
#else
17+
# include <sys/stat.h>
18+
#endif
19+
1220
#include "avs/config.h"
1321
#ifdef AVS_WINDOWS
14-
#include "avisynth_c.h"
22+
# include "avisynth_c.h"
1523
#else
16-
#include <avisynth/avisynth_c.h>
24+
# include <avisynth/avisynth_c.h>
1725
#endif
1826

1927
#if defined(_MSC_VER)
20-
#define __NO_ISOCEXT
21-
#define __NO_INLINE__
28+
# define __NO_ISOCEXT
29+
# define __NO_INLINE__
2230

23-
#define strcasecmp _stricmp
24-
#define atoll _atoi64
31+
# define strcasecmp _stricmp
32+
# define atoll _atoi64
2533
#endif
2634

2735
typedef struct {
28-
// premultiplied coefficients for integer scaled arithmetics
29-
int y_r, y_g, y_b;
30-
int u_r, u_g, u_b;
31-
int v_r, v_g, v_b;
32-
int offset_y;
33-
bool valid;
36+
// premultiplied coefficients for integer scaled arithmetics
37+
int y_r, y_g, y_b;
38+
int u_r, u_g, u_b;
39+
int v_r, v_g, v_b;
40+
int offset_y;
41+
bool valid;
3442
} ConversionMatrix;
3543

3644
typedef enum {
37-
MATRIX_NONE = 0,
38-
MATRIX_BT601,
39-
MATRIX_PC601,
40-
MATRIX_BT709,
41-
MATRIX_PC709,
42-
MATRIX_PC2020,
43-
MATRIX_BT2020,
44-
MATRIX_TVFCC,
45-
MATRIX_PCFCC,
46-
MATRIX_TV240M,
47-
MATRIX_PC240M
45+
MATRIX_NONE = 0,
46+
MATRIX_BT601,
47+
MATRIX_PC601,
48+
MATRIX_BT709,
49+
MATRIX_PC709,
50+
MATRIX_PC2020,
51+
MATRIX_BT2020,
52+
MATRIX_TVFCC,
53+
MATRIX_PCFCC,
54+
MATRIX_TV240M,
55+
MATRIX_PC240M
4856
} matrix_type;
4957

5058
typedef void (* fPixel)(uint8_t** sub_img, uint8_t** data, uint32_t* pitch, uint32_t width, uint32_t height);

src/include/avs/capi.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
#endif
4444

4545
#ifdef __cplusplus
46-
# define EXTERN_C extern "C"
46+
# define AVS_EXTERN_C extern "C"
4747
#else
48-
# define EXTERN_C
48+
# define AVS_EXTERN_C
4949
#endif
5050

5151
#ifdef AVS_WINDOWS
@@ -99,20 +99,20 @@
9999
# else
100100
# define AVSC_EXPORT
101101
# endif
102-
# define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
102+
# define AVSC_API(ret, name) AVS_EXTERN_C AVSC_EXPORT ret AVSC_CC name
103103
#else
104-
# define AVSC_EXPORT EXTERN_C
105-
# define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name
104+
# define AVSC_EXPORT AVS_EXTERN_C
105+
# define AVSC_API(ret, name) AVS_EXTERN_C ret AVSC_CC name
106106
#endif
107107
#else
108-
# define AVSC_EXPORT EXTERN_C __declspec(dllexport)
108+
# define AVSC_EXPORT AVS_EXTERN_C __declspec(dllexport)
109109
# ifndef AVS_STATIC_LIB
110110
# define AVSC_IMPORT __declspec(dllimport)
111111
# else
112112
# define AVSC_IMPORT
113113
# endif
114114
# ifndef AVSC_NO_DECLSPEC
115-
# define AVSC_API(ret, name) EXTERN_C AVSC_IMPORT ret AVSC_CC name
115+
# define AVSC_API(ret, name) AVS_EXTERN_C AVSC_IMPORT ret AVSC_CC name
116116
# else
117117
# define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
118118
# endif

0 commit comments

Comments
 (0)