@clipen/clipen-cli 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
- package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
- package/apps/web/dist/favicon.svg +1 -0
- package/apps/web/dist/index.html +16 -0
- package/bin/clipen.js +157 -0
- package/clipen +18 -0
- package/install +25 -0
- package/package.json +52 -4
- package/pyproject.toml +28 -0
- package/requirements/asr-runtime.txt +13 -0
- package/requirements/runtime.txt +20 -0
- package/src/clipen/__init__.py +3 -0
- package/src/clipen/analysis/__init__.py +89 -0
- package/src/clipen/analysis/artifacts.py +416 -0
- package/src/clipen/analysis/audio.py +392 -0
- package/src/clipen/analysis/evidence.py +102 -0
- package/src/clipen/analysis/evidence_service.py +751 -0
- package/src/clipen/analysis/image_similarity.py +143 -0
- package/src/clipen/analysis/keyframes.py +171 -0
- package/src/clipen/analysis/models.py +230 -0
- package/src/clipen/analysis/qwen_worker.py +629 -0
- package/src/clipen/analysis/resources.py +21 -0
- package/src/clipen/analysis/runtime.py +64 -0
- package/src/clipen/analysis/service.py +626 -0
- package/src/clipen/analysis/setup.py +935 -0
- package/src/clipen/analysis/setup_cli.py +117 -0
- package/src/clipen/analysis/storage.py +2046 -0
- package/src/clipen/analysis/transcription.py +948 -0
- package/src/clipen/analysis/visual.py +176 -0
- package/src/clipen/annotations/__init__.py +10 -0
- package/src/clipen/annotations/models.py +22 -0
- package/src/clipen/annotations/storage.py +380 -0
- package/src/clipen/annotations/suggestions.py +120 -0
- package/src/clipen/asr_release.py +139 -0
- package/src/clipen/bootstrap.py +967 -0
- package/src/clipen/cli.py +84 -0
- package/src/clipen/controller/__init__.py +17 -0
- package/src/clipen/controller/app.py +1470 -0
- package/src/clipen/controller/server.py +543 -0
- package/src/clipen/domain/__init__.py +30 -0
- package/src/clipen/domain/errors.py +5 -0
- package/src/clipen/domain/media_time.py +117 -0
- package/src/clipen/domain/timeline.py +584 -0
- package/src/clipen/domain/validation.py +15 -0
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
- package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
- package/src/clipen/editing/README.md +115 -0
- package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
- package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
- package/src/clipen/editing/__init__.py +15 -0
- package/src/clipen/editing/agent.py +13 -0
- package/src/clipen/editing/agent_models.py +134 -0
- package/src/clipen/editing/agent_repository.py +757 -0
- package/src/clipen/editing/agent_tools.py +532 -0
- package/src/clipen/editing/alignment.py +110 -0
- package/src/clipen/editing/alignment_setup.py +108 -0
- package/src/clipen/editing/alignment_worker.py +22 -0
- package/src/clipen/editing/change_report.py +71 -0
- package/src/clipen/editing/compiler.py +41 -0
- package/src/clipen/editing/component_looks.py +107 -0
- package/src/clipen/editing/component_review.py +78 -0
- package/src/clipen/editing/coordinator.py +374 -0
- package/src/clipen/editing/editorial_review.py +187 -0
- package/src/clipen/editing/evidence_jobs.py +295 -0
- package/src/clipen/editing/history_changes.py +131 -0
- package/src/clipen/editing/music_choices.py +15 -0
- package/src/clipen/editing/production_catalog.py +192 -0
- package/src/clipen/editing/production_limits.py +59 -0
- package/src/clipen/editing/production_media.py +226 -0
- package/src/clipen/editing/production_preview.py +180 -0
- package/src/clipen/editing/production_progress.py +141 -0
- package/src/clipen/editing/production_requirements.py +50 -0
- package/src/clipen/editing/production_tools.py +596 -0
- package/src/clipen/editing/program_audio.py +118 -0
- package/src/clipen/editing/program_direction.py +49 -0
- package/src/clipen/editing/program_story.py +53 -0
- package/src/clipen/editing/program_subtitles.py +134 -0
- package/src/clipen/editing/programme_review.py +73 -0
- package/src/clipen/editing/prompt_history.py +47 -0
- package/src/clipen/editing/recut.py +127 -0
- package/src/clipen/editing/refinement_references.py +188 -0
- package/src/clipen/editing/resolve_export.py +616 -0
- package/src/clipen/editing/resolve_titles.py +234 -0
- package/src/clipen/editing/skill_tools.py +575 -0
- package/src/clipen/editing/source_dialogue.py +82 -0
- package/src/clipen/editing/speech_coverage.py +30 -0
- package/src/clipen/editing/speech_quality.py +6 -0
- package/src/clipen/editing/tool_receipts.py +52 -0
- package/src/clipen/editing/versions.py +161 -0
- package/src/clipen/editing/visual_preview.py +93 -0
- package/src/clipen/editing/workbench.py +74 -0
- package/src/clipen/filesystem.py +25 -0
- package/src/clipen/finishing/README.md +103 -0
- package/src/clipen/finishing/__init__.py +1 -0
- package/src/clipen/finishing/audio.py +149 -0
- package/src/clipen/finishing/catalog.py +181 -0
- package/src/clipen/finishing/models.py +14 -0
- package/src/clipen/finishing/renderer.py +26 -0
- package/src/clipen/mcp_editing/__init__.py +5 -0
- package/src/clipen/mcp_editing/__main__.py +40 -0
- package/src/clipen/mcp_editing/server.py +353 -0
- package/src/clipen/media/__init__.py +50 -0
- package/src/clipen/media/discovery.py +266 -0
- package/src/clipen/media/models.py +360 -0
- package/src/clipen/media/preview.py +147 -0
- package/src/clipen/media/probe.py +446 -0
- package/src/clipen/media/service.py +317 -0
- package/src/clipen/media/storage.py +742 -0
- package/src/clipen/music_vocabulary.py +5 -0
- package/src/clipen/planning/__init__.py +9 -0
- package/src/clipen/planning/models.py +240 -0
- package/src/clipen/power.py +23 -0
- package/src/clipen/projects/__init__.py +26 -0
- package/src/clipen/projects/agent_schema.py +94 -0
- package/src/clipen/projects/annotation_schema.py +40 -0
- package/src/clipen/projects/deletion.py +269 -0
- package/src/clipen/projects/evidence_schema.py +52 -0
- package/src/clipen/projects/finishing_schema.py +34 -0
- package/src/clipen/projects/models.py +192 -0
- package/src/clipen/projects/picker.py +256 -0
- package/src/clipen/projects/preview_schema.py +29 -0
- package/src/clipen/projects/service.py +175 -0
- package/src/clipen/projects/storage.py +1478 -0
- package/src/clipen/projects/timeline_schema.py +32 -0
- package/src/clipen/projects/validation_schema.py +28 -0
- package/src/clipen/provider_registry.py +75 -0
- package/src/clipen/providers/__init__.py +43 -0
- package/src/clipen/providers/account.py +194 -0
- package/src/clipen/providers/claude.py +375 -0
- package/src/clipen/providers/claude_editing.py +111 -0
- package/src/clipen/providers/codex.py +1036 -0
- package/src/clipen/providers/codex_editing.py +91 -0
- package/src/clipen/providers/editing_agent.py +565 -0
- package/src/clipen/providers/errors.py +51 -0
- package/src/clipen/providers/recovery.py +270 -0
- package/src/clipen/py.typed +1 -0
- package/src/clipen/rendering/__init__.py +12 -0
- package/src/clipen/rendering/cover.py +126 -0
- package/src/clipen/rendering/custom_components.py +240 -0
- package/src/clipen/rendering/custom_render.py +197 -0
- package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/manifest.json +145 -0
- package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
- package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
- package/src/clipen/rendering/production_effects.py +64 -0
- package/src/clipen/rendering/program_components.py +193 -0
- package/src/clipen/rendering/program_creator.py +649 -0
- package/src/clipen/rendering/program_identities.py +255 -0
- package/src/clipen/rendering/program_motion.py +141 -0
- package/src/clipen/rendering/program_studio.py +168 -0
- package/src/clipen/rendering/program_styles.py +235 -0
- package/src/clipen/rendering/program_subtitles.py +52 -0
- package/src/clipen/rendering/renderer.py +708 -0
- package/src/clipen/rendering/storage.py +243 -0
- package/src/clipen/rendering/titles.py +360 -0
- package/src/clipen/skills/__init__.py +4 -0
- package/src/clipen/skills/builtin/SKILL.md +72 -0
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
- package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
- package/src/clipen/skills/builtin/components.json +133 -0
- package/src/clipen/skills/builtin/font_sources.json +20 -0
- package/src/clipen/skills/builtin/font_styles.json +329 -0
- package/src/clipen/skills/builtin/manifest.json +32 -0
- package/src/clipen/skills/builtin/presets.json +8 -0
- package/src/clipen/skills/builtin/references/captions.md +14 -0
- package/src/clipen/skills/builtin/references/channel-design.md +37 -0
- package/src/clipen/skills/builtin/references/editing.md +30 -0
- package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/graphics.md +59 -0
- package/src/clipen/skills/builtin/references/review.md +16 -0
- package/src/clipen/skills/builtin/references/sound.md +8 -0
- package/src/clipen/skills/builtin/references/story.md +7 -0
- package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
- package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/templates.json +284 -0
- package/src/clipen/skills/builtin/visual_styles.json +1074 -0
- package/src/clipen/skills/catalog.py +218 -0
- package/src/clipen/skills/library.py +131 -0
- package/src/clipen/skills/package.py +231 -0
- package/src/clipen/skills/visual_styles.py +44 -0
- package/src/clipen/workspace.py +210 -0
- package/uninstall +25 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Deterministic in-picture graphics for versioned programme skill packages."""
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
from PIL import Image, ImageDraw
|
|
5
|
+
|
|
6
|
+
from .titles import TitleRenderError
|
|
7
|
+
from .program_motion import FAMILIES, layout, motion_frames, draw_motion_graphic
|
|
8
|
+
from .program_styles import skin, style_font, load_style_font, styled_text_length, draw_styled_graphic, type_outline
|
|
9
|
+
from . import program_identities
|
|
10
|
+
from . import program_creator
|
|
11
|
+
from . import custom_components
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def animation_boundaries(item, profile, timeline=None):
|
|
15
|
+
if custom_components.is_custom(profile):
|
|
16
|
+
# A free design can change on any frame; the frames themselves say where.
|
|
17
|
+
return custom_components.changes(timeline, item, profile) if timeline is not None else set(range(item.start_frame, item.start_frame+item.duration_frames+1))
|
|
18
|
+
motion = profile["presets"]["motion"]
|
|
19
|
+
if program_creator.is_creator(profile):
|
|
20
|
+
entry_length, exit_length = program_creator.frames(profile)
|
|
21
|
+
else:
|
|
22
|
+
entry_length, exit_length = motion_frames(profile["component_id"],profile) if profile["component_id"] in FAMILIES else (motion["entry_frames"], motion["exit_frames"])
|
|
23
|
+
entry = min(entry_length, item.duration_frames)
|
|
24
|
+
exit_frames = min(exit_length, item.duration_frames)
|
|
25
|
+
return {item.start_frame+n for n in
|
|
26
|
+
(*range(entry+1), *range(item.duration_frames-exit_frames, item.duration_frames+1))}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _bounds(draw, font_path, timeline, item, profile):
|
|
30
|
+
if program_creator.is_creator(profile):
|
|
31
|
+
return program_creator.layout(draw, font_path, timeline, item, profile)
|
|
32
|
+
if program_identities.identity(profile):
|
|
33
|
+
return program_identities.layout(draw, font_path, timeline, item, profile)
|
|
34
|
+
if profile['component_id'] in FAMILIES:
|
|
35
|
+
return layout(draw, font_path, timeline, item, profile)
|
|
36
|
+
if skin(profile) == 'studio':
|
|
37
|
+
from .program_studio import layout as studio_layout
|
|
38
|
+
return studio_layout(draw, font_path, timeline, item, profile)
|
|
39
|
+
font_path=style_font(font_path,profile)
|
|
40
|
+
typography=profile['presets'].get('typography',{})
|
|
41
|
+
scale = typography.get('reaction',.064) if profile["component_id"] == "reaction" else typography.get('component_primary',.038)
|
|
42
|
+
font = load_style_font(font_path,max(14,round(timeline.height*scale)),profile)
|
|
43
|
+
primary,_,detail=item.text.partition('\n')
|
|
44
|
+
detail_font=load_style_font(font_path,max(12,round(timeline.height*typography.get('component_detail',.024))),profile,role='detail')
|
|
45
|
+
width = max(styled_text_length(primary,font), styled_text_length(detail,detail_font) if detail else 0)
|
|
46
|
+
pad = max(8, round(timeline.height*.016))
|
|
47
|
+
x, y = round(timeline.width*profile["x"]), round(timeline.height*profile["y"])
|
|
48
|
+
box_width=max(math.ceil(width)+pad*2,round(timeline.width*.15))
|
|
49
|
+
box_height=round(timeline.height*scale*1.65)+pad
|
|
50
|
+
if profile['component_id']!='reaction':box_height+=round(timeline.height*.025)
|
|
51
|
+
if detail:box_height+=round(timeline.height*.038)
|
|
52
|
+
if box_width > timeline.width*.58 or x+box_width > timeline.width*.95 or y+box_height > timeline.height*.77:
|
|
53
|
+
raise TitleRenderError("program_component_overflow")
|
|
54
|
+
return (x, y, x+box_width, y+box_height), font, pad
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _draw(draw, font_path, timeline, item, profile, relative_frame=None):
|
|
58
|
+
if program_creator.is_creator(profile):
|
|
59
|
+
return program_creator.draw_graphic(draw, font_path, timeline, item, profile, relative_frame)
|
|
60
|
+
identity = program_identities.identity(profile)
|
|
61
|
+
if profile["component_id"] in FAMILIES and not identity:
|
|
62
|
+
return draw_motion_graphic(draw, font_path, timeline, item, profile, relative_frame)
|
|
63
|
+
bounds, font, pad = _bounds(draw, font_path, timeline, item, profile)
|
|
64
|
+
motion = profile["presets"]["motion"]
|
|
65
|
+
relative = motion["entry_frames"] if relative_frame is None else relative_frame
|
|
66
|
+
entering = min(1., max(0., (relative+1)/motion["entry_frames"]))
|
|
67
|
+
leaving = min(1., (item.duration_frames-relative)/motion["exit_frames"])
|
|
68
|
+
opacity = min(entering, leaving)
|
|
69
|
+
eased = 1-(1-entering)**3
|
|
70
|
+
dx = round((1-eased)*timeline.width*motion["entry_distance_ratio"])
|
|
71
|
+
x, y, right, bottom = bounds
|
|
72
|
+
x -= dx
|
|
73
|
+
right -= dx
|
|
74
|
+
palette = profile["presets"]["palette"]
|
|
75
|
+
|
|
76
|
+
def color(name):
|
|
77
|
+
r, g, b, a = palette[name]
|
|
78
|
+
return (r, g, b, round(a*opacity))
|
|
79
|
+
|
|
80
|
+
kind = profile["component_id"]
|
|
81
|
+
primary,_,detail=item.text.partition('\n')
|
|
82
|
+
stroke = max(2, round(timeline.height*.004))
|
|
83
|
+
if identity:
|
|
84
|
+
program_identities.draw_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
|
|
85
|
+
elif skin(profile)!="variety":
|
|
86
|
+
draw_styled_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
|
|
87
|
+
elif kind == "reaction":
|
|
88
|
+
draw.text((x+pad, y+pad//2), primary, font=font, fill=color("accent"),
|
|
89
|
+
stroke_width=type_outline(profile,font,stroke*2), stroke_fill=color("ink"))
|
|
90
|
+
if detail:
|
|
91
|
+
detail_font=load_style_font(font_path,max(12,round(timeline.height*.024)),profile,role='detail')
|
|
92
|
+
draw.text((x+pad,y+pad+round(timeline.height*.075)),detail,font=detail_font,fill=color('paper'),
|
|
93
|
+
stroke_width=stroke,stroke_fill=color('ink'))
|
|
94
|
+
# A short pair of ticks gives an actual reaction a shared programme
|
|
95
|
+
# accent without turning every dialogue line into a reaction graphic.
|
|
96
|
+
draw.line((x-pad//2,y+pad,x-pad,y-pad//2),fill=color('accent'),width=stroke)
|
|
97
|
+
draw.line((right+pad//2,y+pad,right+pad,y-pad//2),fill=color('accent'),width=stroke)
|
|
98
|
+
else:
|
|
99
|
+
# Narrow editorial labels sit inside the footage, with no full-screen
|
|
100
|
+
# background. A shared accent edge and typography form programme identity.
|
|
101
|
+
draw.rectangle((x+3, y+4, right+3, bottom+4), fill=(0, 0, 0, round(75*opacity)))
|
|
102
|
+
draw.rectangle((x, y, right, bottom), fill=color("ink"))
|
|
103
|
+
draw.rectangle((x, y, x+stroke*2, bottom), fill=color("secondary" if kind == "person" else "accent"))
|
|
104
|
+
typography=profile['presets'].get('typography',{})
|
|
105
|
+
kicker_font=load_style_font(font_path,max(10,round(timeline.height*typography.get('component_kicker',.017))),profile,role='detail')
|
|
106
|
+
kicker=profile.get('eyebrow') or {'location':'現場','person':'人物','fact':'資訊','pointer':'看這裡','circle':'細節'}[kind]
|
|
107
|
+
draw.text((x+pad,y+pad//2),kicker,font=kicker_font,fill=color('secondary' if kind=='person' else 'accent'))
|
|
108
|
+
primary_y=y+pad//2+round(timeline.height*.027)
|
|
109
|
+
draw.text((x+pad,primary_y),primary,font=font,fill=color("paper"))
|
|
110
|
+
if detail:
|
|
111
|
+
detail_font=load_style_font(font_path,max(12,round(timeline.height*typography.get('component_detail',.024))),profile,role='detail')
|
|
112
|
+
draw.text((x+pad,primary_y+round(timeline.height*.052)),detail,font=detail_font,fill=color('paper'))
|
|
113
|
+
draw.line((x+pad,bottom-pad//2,right-pad,bottom-pad//2),fill=color("accent"),width=max(1,stroke//2))
|
|
114
|
+
if kind not in {"pointer", "circle"}:
|
|
115
|
+
return bounds
|
|
116
|
+
target = profile["target"]
|
|
117
|
+
tx, ty = target["x"]*timeline.width, target["y"]*timeline.height
|
|
118
|
+
radius = target["radius"]*min(timeline.width, timeline.height)
|
|
119
|
+
if kind == "circle":
|
|
120
|
+
rect = (tx-radius, ty-radius, tx+radius, ty+radius)
|
|
121
|
+
draw.arc(rect, -90, -90+max(2, round(360*eased)), fill=color("accent"), width=stroke*2)
|
|
122
|
+
else:
|
|
123
|
+
origin = (right, (y+bottom)/2)
|
|
124
|
+
angle = math.atan2(ty-origin[1], tx-origin[0])
|
|
125
|
+
tip = (origin[0]+(tx-origin[0])*eased, origin[1]+(ty-origin[1])*eased)
|
|
126
|
+
draw.line((origin, tip), fill=color("ink"), width=stroke*3)
|
|
127
|
+
draw.line((origin, tip), fill=color("accent"), width=stroke)
|
|
128
|
+
size = max(9, timeline.height*.025)
|
|
129
|
+
points = [tip, (tip[0]-size*math.cos(angle-.45), tip[1]-size*math.sin(angle-.45)),
|
|
130
|
+
(tip[0]-size*math.cos(angle+.45), tip[1]-size*math.sin(angle+.45))]
|
|
131
|
+
draw.polygon(points, fill=color("accent"))
|
|
132
|
+
return bounds
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class _Canvas:
|
|
136
|
+
"""A timeline seen at another size, so every style's own proportions scale with it."""
|
|
137
|
+
def __init__(self, timeline, width, height):
|
|
138
|
+
self._timeline, self.width, self.height = timeline, width, height
|
|
139
|
+
|
|
140
|
+
def __getattr__(self, name):
|
|
141
|
+
return getattr(self._timeline, name)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _scaled(timeline, profile):
|
|
145
|
+
"""For a graphic a person resized: a larger or smaller canvas to draw it on, and where to place
|
|
146
|
+
that canvas so the graphic keeps its top-left corner. None at its designed size."""
|
|
147
|
+
scale = profile.get("scale", 1)
|
|
148
|
+
if scale == 1:
|
|
149
|
+
return None
|
|
150
|
+
canvas = _Canvas(timeline, max(2, round(timeline.width*scale)), max(2, round(timeline.height*scale)))
|
|
151
|
+
return canvas, (round(timeline.width*profile["x"]) - round(canvas.width*profile["x"]),
|
|
152
|
+
round(timeline.height*profile["y"]) - round(canvas.height*profile["y"]))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def component_bounds(draw, font_path, timeline, item, profile):
|
|
156
|
+
"""The graphic's box on the picture, after any size a person chose."""
|
|
157
|
+
if custom_components.is_custom(profile):
|
|
158
|
+
box = custom_components.bounds(timeline, item, profile)
|
|
159
|
+
dx, dy = round(profile.get("x", 0)*timeline.width), round(profile.get("y", 0)*timeline.height)
|
|
160
|
+
return (box or (dx, dy, dx, dy)), None, 0
|
|
161
|
+
scaled = _scaled(timeline, profile)
|
|
162
|
+
if scaled is None:
|
|
163
|
+
return _bounds(draw, font_path, timeline, item, profile)
|
|
164
|
+
canvas, (dx, dy) = scaled
|
|
165
|
+
(left, top, right, bottom), font, pad = _bounds(draw, font_path, canvas, item, profile)
|
|
166
|
+
box = (left+dx, top+dy, right+dx, bottom+dy)
|
|
167
|
+
# Enlarged, it must still clear the picture's edge and the subtitles at the bottom.
|
|
168
|
+
if box[0] < 0 or box[1] < 0 or box[2] > timeline.width*.97 or box[3] > timeline.height*.8:
|
|
169
|
+
raise TitleRenderError("program_component_overflow")
|
|
170
|
+
return box, font, pad
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def draw_program_component(draw, font_path, timeline, item, profile, relative_frame=None):
|
|
174
|
+
if custom_components.is_custom(profile):
|
|
175
|
+
return custom_components.draw(draw, timeline, item, profile, relative_frame)
|
|
176
|
+
scaled = _scaled(timeline, profile)
|
|
177
|
+
if scaled is None:
|
|
178
|
+
return _draw(draw, font_path, timeline, item, profile, relative_frame)
|
|
179
|
+
canvas, (dx, dy) = scaled
|
|
180
|
+
component_bounds(draw, font_path, timeline, item, profile)
|
|
181
|
+
# Drawn at its new size on a canvas of its own, so type stays sharp instead of being resampled.
|
|
182
|
+
layer = Image.new("RGBA", (canvas.width, canvas.height), (0, 0, 0, 0))
|
|
183
|
+
result = _draw(ImageDraw.Draw(layer), font_path, canvas, item, profile, relative_frame)
|
|
184
|
+
target = draw._image
|
|
185
|
+
sx, sy, tx, ty = max(0, -dx), max(0, -dy), max(0, dx), max(0, dy)
|
|
186
|
+
width, height = min(layer.width-sx, target.width-tx), min(layer.height-sy, target.height-ty)
|
|
187
|
+
if width > 0 and height > 0:
|
|
188
|
+
piece = layer.crop((sx, sy, sx+width, sy+height))
|
|
189
|
+
if target.mode == "RGBA":
|
|
190
|
+
target.alpha_composite(piece, (tx, ty))
|
|
191
|
+
else:
|
|
192
|
+
target.paste(piece, (tx, ty), piece)
|
|
193
|
+
return result
|