csp-format 0.1.0__tar.gz

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.
Files changed (35) hide show
  1. csp_format-0.1.0/LICENSE +21 -0
  2. csp_format-0.1.0/MANIFEST.in +3 -0
  3. csp_format-0.1.0/PKG-INFO +84 -0
  4. csp_format-0.1.0/README.md +63 -0
  5. csp_format-0.1.0/csp_format/__init__.py +31 -0
  6. csp_format-0.1.0/csp_format/animation.py +499 -0
  7. csp_format-0.1.0/csp_format/assets/__init__.py +14 -0
  8. csp_format-0.1.0/csp_format/assets/c2f.py +42 -0
  9. csp_format-0.1.0/csp_format/assets/colorset.py +93 -0
  10. csp_format-0.1.0/csp_format/assets/material.py +135 -0
  11. csp_format-0.1.0/csp_format/assets/serial.py +323 -0
  12. csp_format-0.1.0/csp_format/assets/shortcut.py +120 -0
  13. csp_format-0.1.0/csp_format/assets/subtool.py +321 -0
  14. csp_format-0.1.0/csp_format/assets/tar.py +66 -0
  15. csp_format-0.1.0/csp_format/clip.py +478 -0
  16. csp_format-0.1.0/csp_format/cmc.py +193 -0
  17. csp_format-0.1.0/csp_format/container.py +79 -0
  18. csp_format-0.1.0/csp_format/errors.py +5 -0
  19. csp_format-0.1.0/csp_format/image.py +119 -0
  20. csp_format-0.1.0/csp_format/offscreen.py +241 -0
  21. csp_format-0.1.0/csp_format/text.py +145 -0
  22. csp_format-0.1.0/csp_format/vector.py +139 -0
  23. csp_format-0.1.0/csp_format/version.py +132 -0
  24. csp_format-0.1.0/csp_format.egg-info/PKG-INFO +84 -0
  25. csp_format-0.1.0/csp_format.egg-info/SOURCES.txt +33 -0
  26. csp_format-0.1.0/csp_format.egg-info/dependency_links.txt +1 -0
  27. csp_format-0.1.0/csp_format.egg-info/top_level.txt +1 -0
  28. csp_format-0.1.0/pyproject.toml +31 -0
  29. csp_format-0.1.0/setup.cfg +4 -0
  30. csp_format-0.1.0/tests/data/anim.clip +0 -0
  31. csp_format-0.1.0/tests/data/files.txt +1 -0
  32. csp_format-0.1.0/tests/data/layers.clip +0 -0
  33. csp_format-0.1.0/tests/test_animation.py +117 -0
  34. csp_format-0.1.0/tests/test_assets.py +212 -0
  35. csp_format-0.1.0/tests/test_reader.py +298 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nanikasheila
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include LICENSE
2
+ recursive-include tests *.py
3
+ include tests/data/*.clip tests/data/files.txt
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: csp-format
3
+ Version: 0.1.0
4
+ Summary: Read CLIP STUDIO PAINT files (.clip, .cmc) and its other files with the Python standard library only
5
+ Author: nanikasheila
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format
8
+ Project-URL: Documentation, https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/python/README.md
9
+ Project-URL: Changelog, https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/CHANGELOG.md
10
+ Keywords: clip-studio-paint,csp,clip,cmc,manga
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: File Formats
16
+ Classifier: Topic :: Multimedia :: Graphics
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: license-file
21
+
22
+ # csp_format (Python)
23
+
24
+ Read CLIP STUDIO PAINT files (`.clip`, `.cmc`) and its sub tools, auto
25
+ actions, colour and gradient sets and materials (`csp_format.assets`) with
26
+ the Python standard library only. It follows the same rules as the Rust
27
+ crate `csp-format`, and both give the same results on 719 real files. For
28
+ writing and rendering, use the Rust crates or the `cspf` command. Not made
29
+ or endorsed by CELSYS. Documentation: [GitHub](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format);
30
+ the [specification](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/README.md) lists what is not yet understood.
31
+
32
+ CLIP STUDIO PAINT のファイル(`.clip` / `.cmc`)と、サブツール・オートアクション・カラーセット・グラデーションセット・素材(`csp_format.assets`)を Python の標準ライブラリだけで読む実装。
33
+ 規則は Rust の `csp-format` と同じで、実ファイル 719 件で両者の結果が一致することを確かめている([V7](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/validation/V7-python.md)、assets は [W5](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/assets/validation/W5-python.md))。
34
+ 書き込みと合成描画は Rust 側(`cspf`)を使う。CELSYS の公式のものではない。
35
+ 仕様と未解明の項目は [仕様書](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/README.md#未解明の項目)。
36
+
37
+ ```sh
38
+ pip install csp-format
39
+ ```
40
+
41
+ ```python
42
+ from csp_format import read_animation, read_clip, read_cmc
43
+
44
+ with read_clip("page.clip") as clip:
45
+ print(clip.canvas.width_px, clip.canvas.height_px)
46
+ for layer, depth in clip.root.walk():
47
+ print(" " * depth, layer.kind, layer.name)
48
+ found = clip.layer_pixels(layer) # (Image, (x, y)) か None
49
+ if found:
50
+ image, origin = found
51
+ open(f"{layer.main_id}.png", "wb").write(image.to_png())
52
+ for item in clip.vector_objects(layer): # 線・図形(レイヤー座標)
53
+ print(item.brush_size, len(item.raw_points))
54
+ for block in clip.text_blocks(layer): # テキスト(吹き出しごと)
55
+ print(block.text, block.attributes.font_size)
56
+
57
+ with read_clip("anim.clip") as clip:
58
+ animation = read_animation(clip) # タイムラインがなければ None
59
+ timeline = animation.timelines[animation.current]
60
+ state = animation.frame_state(clip, animation.current, frame=0) # フレームは 0 始まり
61
+ print(timeline.name, timeline.frame_rate, state.cels) # フォルダー → 表示するセル
62
+
63
+ with read_cmc("work.cmc") as work:
64
+ for path in work.page_file_paths():
65
+ print(path)
66
+ ```
67
+
68
+ | 機能 | API |
69
+ |---|---|
70
+ | キャンバス設定(px、仕上がり枠・基本枠) | `clip.canvas` |
71
+ | レイヤーツリーと種別(13 種) | `clip.root`, `clip.iter_layers()`, `clip.find_layer(id)` |
72
+ | 画素(カラー・グレー・2 値・初期色) | `clip.layer_pixels(layer)`, `clip.layer_pixels_in_box(layer, box)`, `clip.stored_pixel_boxes(layer)` |
73
+ | マスク・サムネイル・プレビュー | `clip.layer_mask(layer)`, `clip.layer_thumbnail(layer)`, `clip.preview()` |
74
+ | ベクター・テキスト | `clip.vector_payloads(layer)`, `clip.vector_objects(layer)`, `clip.text_blocks(layer)` |
75
+ | 任意のテーブル | `clip.database`(メモリー上の複製), `clip.row(table, id)` |
76
+ | .cmc のページ順・ページのサムネイル | `work.pages()`, `work.page_file_paths()`, `work.page_thumbnail(node)` |
77
+ | アニメーション(タイムライン・セル・キーフレーム・2D カメラ) | `read_animation(clip)`, `animation.frame_state(clip, index, frame)`([08 章](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/08-animation.md)) |
78
+ | トラックのキー("cmt " 文書の読み書き) | `csp_format.animation.parse_document`, `document_bytes`, `unpack_chunk` |
79
+ | サブツール・オートアクション・カラーセット・グラデーションセット・ショートカット・素材 | `csp_format.assets`(`subtool`, `serial`, `colorset`, `shortcut`, `material`, `c2f`, `tar`) |
80
+
81
+ 画像は `Image(width, height, rgba)`(RGBA、非乗算)。Pillow へは
82
+ `PIL.Image.frombytes("RGBA", (image.width, image.height), bytes(image.rgba))`。
83
+
84
+ テスト: リポジトリでは `python -m unittest discover -s python/tests`、sdist を展開した場所では `python -m unittest discover -s tests`。
@@ -0,0 +1,63 @@
1
+ # csp_format (Python)
2
+
3
+ Read CLIP STUDIO PAINT files (`.clip`, `.cmc`) and its sub tools, auto
4
+ actions, colour and gradient sets and materials (`csp_format.assets`) with
5
+ the Python standard library only. It follows the same rules as the Rust
6
+ crate `csp-format`, and both give the same results on 719 real files. For
7
+ writing and rendering, use the Rust crates or the `cspf` command. Not made
8
+ or endorsed by CELSYS. Documentation: [GitHub](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format);
9
+ the [specification](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/README.md) lists what is not yet understood.
10
+
11
+ CLIP STUDIO PAINT のファイル(`.clip` / `.cmc`)と、サブツール・オートアクション・カラーセット・グラデーションセット・素材(`csp_format.assets`)を Python の標準ライブラリだけで読む実装。
12
+ 規則は Rust の `csp-format` と同じで、実ファイル 719 件で両者の結果が一致することを確かめている([V7](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/validation/V7-python.md)、assets は [W5](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/assets/validation/W5-python.md))。
13
+ 書き込みと合成描画は Rust 側(`cspf`)を使う。CELSYS の公式のものではない。
14
+ 仕様と未解明の項目は [仕様書](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/README.md#未解明の項目)。
15
+
16
+ ```sh
17
+ pip install csp-format
18
+ ```
19
+
20
+ ```python
21
+ from csp_format import read_animation, read_clip, read_cmc
22
+
23
+ with read_clip("page.clip") as clip:
24
+ print(clip.canvas.width_px, clip.canvas.height_px)
25
+ for layer, depth in clip.root.walk():
26
+ print(" " * depth, layer.kind, layer.name)
27
+ found = clip.layer_pixels(layer) # (Image, (x, y)) か None
28
+ if found:
29
+ image, origin = found
30
+ open(f"{layer.main_id}.png", "wb").write(image.to_png())
31
+ for item in clip.vector_objects(layer): # 線・図形(レイヤー座標)
32
+ print(item.brush_size, len(item.raw_points))
33
+ for block in clip.text_blocks(layer): # テキスト(吹き出しごと)
34
+ print(block.text, block.attributes.font_size)
35
+
36
+ with read_clip("anim.clip") as clip:
37
+ animation = read_animation(clip) # タイムラインがなければ None
38
+ timeline = animation.timelines[animation.current]
39
+ state = animation.frame_state(clip, animation.current, frame=0) # フレームは 0 始まり
40
+ print(timeline.name, timeline.frame_rate, state.cels) # フォルダー → 表示するセル
41
+
42
+ with read_cmc("work.cmc") as work:
43
+ for path in work.page_file_paths():
44
+ print(path)
45
+ ```
46
+
47
+ | 機能 | API |
48
+ |---|---|
49
+ | キャンバス設定(px、仕上がり枠・基本枠) | `clip.canvas` |
50
+ | レイヤーツリーと種別(13 種) | `clip.root`, `clip.iter_layers()`, `clip.find_layer(id)` |
51
+ | 画素(カラー・グレー・2 値・初期色) | `clip.layer_pixels(layer)`, `clip.layer_pixels_in_box(layer, box)`, `clip.stored_pixel_boxes(layer)` |
52
+ | マスク・サムネイル・プレビュー | `clip.layer_mask(layer)`, `clip.layer_thumbnail(layer)`, `clip.preview()` |
53
+ | ベクター・テキスト | `clip.vector_payloads(layer)`, `clip.vector_objects(layer)`, `clip.text_blocks(layer)` |
54
+ | 任意のテーブル | `clip.database`(メモリー上の複製), `clip.row(table, id)` |
55
+ | .cmc のページ順・ページのサムネイル | `work.pages()`, `work.page_file_paths()`, `work.page_thumbnail(node)` |
56
+ | アニメーション(タイムライン・セル・キーフレーム・2D カメラ) | `read_animation(clip)`, `animation.frame_state(clip, index, frame)`([08 章](https://github.com/nanikasheila/CLIP_STUDIO_PAINT_Format/blob/main/docs/spec/08-animation.md)) |
57
+ | トラックのキー("cmt " 文書の読み書き) | `csp_format.animation.parse_document`, `document_bytes`, `unpack_chunk` |
58
+ | サブツール・オートアクション・カラーセット・グラデーションセット・ショートカット・素材 | `csp_format.assets`(`subtool`, `serial`, `colorset`, `shortcut`, `material`, `c2f`, `tar`) |
59
+
60
+ 画像は `Image(width, height, rgba)`(RGBA、非乗算)。Pillow へは
61
+ `PIL.Image.frombytes("RGBA", (image.width, image.height), bytes(image.rgba))`。
62
+
63
+ テスト: リポジトリでは `python -m unittest discover -s python/tests`、sdist を展開した場所では `python -m unittest discover -s tests`。
@@ -0,0 +1,31 @@
1
+ """Read CLIP STUDIO PAINT files (.clip, .cmc) with the Python standard library only.
2
+
3
+ from csp_format import read_clip
4
+ with read_clip("page.clip") as clip:
5
+ for layer in clip.iter_layers():
6
+ found = clip.layer_pixels(layer) # (Image, (x, y)) or None
7
+ ...
8
+
9
+ Images are plain RGBA (``Image.width``, ``height``, ``rgba``); with Pillow,
10
+ ``PIL.Image.frombytes("RGBA", (image.width, image.height), bytes(image.rgba))``.
11
+ Animation (timelines, cels, keyframes, 2D camera): :mod:`csp_format.animation`.
12
+ The format is described in ``docs/spec``; the Rust crate in ``crates/``
13
+ also writes and renders files.
14
+ """
15
+ __version__ = "0.1.0"
16
+
17
+ from .animation import Animation, FrameState, Timeline, Track, read_animation
18
+ from .clip import Canvas, ClipFile, Layer, read_clip
19
+ from .cmc import CanvasNode, CmcFile, CmcProject, PageSlot, read_cmc
20
+ from .container import Container
21
+ from .errors import CspFormatError
22
+ from .image import Image, decode_png
23
+ from .text import Attributes, TextBlock
24
+ from .vector import Point, VectorObject, parse_vector_data
25
+ from .version import VersionInfo, read_version_info
26
+
27
+ __all__ = [
28
+ "Animation", "Attributes", "Canvas", "CanvasNode", "ClipFile", "CmcFile", "CmcProject", "Container",
29
+ "CspFormatError", "FrameState", "Image", "Layer", "PageSlot", "Point", "TextBlock", "Timeline", "Track", "VectorObject",
30
+ "VersionInfo", "decode_png", "parse_vector_data", "read_animation", "read_clip", "read_cmc", "read_version_info",
31
+ ]