Skip to content

Commit a2be019

Browse files
couleurmpo5
andcommitted
circumvent incomplete color info
Co-Authored-By: Eva <42466980+po5@users.noreply.github.com>
1 parent 3900f1e commit a2be019

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

target/jamba.vpy

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,59 @@ if (pi := rc['pre-interp'])['enabled'].lower() in YES:
250250
model_path = relative_model_path
251251

252252
og_format = clip.format
253-
og_matrix = clip.get_frame(0).props._Matrix
254-
clip = core.resize.Bicubic(clip=clip, format=vs.RGBS)
255253

254+
# taken github user cid-chan from Irrational-Encoding-Wizardry/vs-engine
255+
# https://github.com/Irrational-Encoding-Wizardry/vs-engine/commit/36595806cfee0a07a70406d27dfed2d1f6c7e57e
256+
def yuv_heuristic(width: int, height: int) :
257+
result = {}
258+
259+
if width >= 3840:
260+
result["matrix_in_s"] = "2020ncl"
261+
elif width >= 1280:
262+
result["matrix_in_s"] = "709"
263+
elif height == 576:
264+
result["matrix_in_s"] = "470bg"
265+
else:
266+
result["matrix_in_s"] = "170m"
267+
268+
if width >= 3840:
269+
result["transfer_in_s"] = "st2084"
270+
elif width >= 1280:
271+
result["transfer_in_s"] = "709"
272+
elif height == 576:
273+
result["transfer_in_s"] = "470bg"
274+
else:
275+
result["transfer_in_s"] = "601"
276+
277+
if width >= 3840:
278+
result["primaries_in_s"] = "2020"
279+
elif width >= 1280:
280+
result["primaries_in_s"] = "709"
281+
elif height == 576:
282+
result["primaries_in_s"] = "470bg"
283+
else:
284+
result["primaries_in_s"] = "170m"
285+
286+
result["range_in_s"] = "limited"
287+
288+
# ITU-T H.273 (07/2021), Note at the bottom of pg. 20
289+
if width >= 3840:
290+
result["chromaloc_in_s"] = "top_left"
291+
else:
292+
result["chromaloc_in_s"] = "left"
293+
294+
return result
295+
296+
297+
heuristic = yuv_heuristic(clip.width, clip.height)
298+
299+
not_in_heuristic = {}
300+
301+
for key, value in heuristic.items():
302+
not_in_heuristic[key.replace('_in', '')] = value
303+
304+
305+
clip = core.resize.Bicubic(clip, format=vs.RGBS, **heuristic)
256306
factor = pi['factor'].strip('x')
257307

258308
if pi['masking'] in YES:
@@ -278,7 +328,7 @@ if (pi := rc['pre-interp'])['enabled'].lower() in YES:
278328
original_clip=og_clip
279329
)
280330

281-
clip = core.resize.Bicubic(clip=clip, format=og_format, matrix=og_matrix)
331+
clip = core.resize.Bicubic(clip=clip, format=og_format, **not_in_heuristic)
282332
# eprint(f"og_matrix:{og_matrix}")
283333
# eprint(f"pre-interp\n{clip}")
284334
# pre-interp

0 commit comments

Comments
 (0)