|
13 | 13 | Comment, |
14 | 14 | CommentPosition, |
15 | 15 | ass_escape, |
| 16 | + convert_color, |
16 | 17 | convert_timestamp, |
17 | 18 | read_comments_from_protobuf, |
18 | 19 | read_comments_from_xml, |
@@ -467,45 +468,6 @@ def mark_comment_row(rows: list[Comment | None], comment: Comment, row: int): |
467 | 468 | pass |
468 | 469 |
|
469 | 470 |
|
470 | | -def ass_escape_py(s): |
471 | | - def replace_leading_space(s): |
472 | | - sstrip = s.strip(" ") |
473 | | - slen = len(s) |
474 | | - if slen == len(sstrip): |
475 | | - return s |
476 | | - else: |
477 | | - llen = slen - len(s.lstrip(" ")) |
478 | | - rlen = slen - len(s.rstrip(" ")) |
479 | | - return "".join(("\u2007" * llen, sstrip, "\u2007" * rlen)) |
480 | | - |
481 | | - return "\\N".join( |
482 | | - replace_leading_space(i) or " " |
483 | | - for i in str(s).replace("\\", "\\\\").replace("{", "\\{").replace("}", "\\}").split("\n") |
484 | | - ) |
485 | | - |
486 | | - |
487 | | -def convert_color(RGB, width=1280, height=576): |
488 | | - if RGB == 0x000000: |
489 | | - return "000000" |
490 | | - elif RGB == 0xFFFFFF: |
491 | | - return "FFFFFF" |
492 | | - R = (RGB >> 16) & 0xFF |
493 | | - G = (RGB >> 8) & 0xFF |
494 | | - B = RGB & 0xFF |
495 | | - if width < 1280 and height < 576: |
496 | | - return f"{B:02X}{G:02X}{R:02X}" |
497 | | - else: # VobSub always uses BT.601 colorspace, convert to BT.709 |
498 | | - |
499 | | - def clip_byte(x): |
500 | | - return 255 if x > 255 else 0 if x < 0 else round(x) |
501 | | - |
502 | | - return "{:02X}{:02X}{:02X}".format( # noqa: UP032 |
503 | | - clip_byte(R * 0.00956384088080656 + G * 0.03217254540203729 + B * 0.95826361371715607), |
504 | | - clip_byte(R * -0.10493933142075390 + G * 1.17231478191855154 + B * -0.06737545049779757), |
505 | | - clip_byte(R * 0.91348912373987645 + G * 0.07858536372532510 + B * 0.00792551253479842), |
506 | | - ) |
507 | | - |
508 | | - |
509 | 471 | def convert_type2(row, height, bottom_reserved): |
510 | 472 | return height - bottom_reserved - row |
511 | 473 |
|
|
0 commit comments