@@ -250,9 +250,59 @@ if (pi := rc['pre-interp'])['enabled'].lower() in YES:
250
250
model_path = relative_model_path
251
251
252
252
og_format = clip .format
253
- og_matrix = clip .get_frame (0 ).props ._Matrix
254
- clip = core .resize .Bicubic (clip = clip , format = vs .RGBS )
255
253
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 )
256
306
factor = pi ['factor' ].strip ('x' )
257
307
258
308
if pi ['masking' ] in YES :
@@ -278,7 +328,7 @@ if (pi := rc['pre-interp'])['enabled'].lower() in YES:
278
328
original_clip = og_clip
279
329
)
280
330
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 )
282
332
# eprint(f"og_matrix:{og_matrix}")
283
333
# eprint(f"pre-interp\n{clip}")
284
334
# pre-interp
0 commit comments