pub struct ClipFile {
pub project: Project,
pub canvas: Canvas,
pub layers: LayerTree,
/* private fields */
}Expand description
An opened .clip file.
use csp_format::ClipFile;
let mut file = ClipFile::open("page0001.clip")?;
println!("{} x {} px", file.canvas.width_px, file.canvas.height_px);
for (layer, depth) in file.layers.flatten() {
println!("{}{} ({})", " ".repeat(depth), layer.name, layer.kind.name());
}
// Arbitrary columns are in the embedded SQLite database.
let rows = csp_format::database::select_all(file.database(), "Layer")?;
assert_eq!(rows.len(), file.layers.layers.len());
file.reload()?;
file.save("copy.clip")?; // byte-identical while nothing was changedFields§
§project: ProjectThe Project row.
canvas: CanvasThe canvas settings.
layers: LayerTreeThe layer tree, read at open (call ClipFile::reload after changing Layer rows).
Implementations§
Source§impl ClipFile
impl ClipFile
Sourcepub fn animation(&self) -> Result<Option<Animation>>
pub fn animation(&self) -> Result<Option<Animation>>
The animation data, None when the file has no timeline.
Sourcepub fn set_frame_rate(
&mut self,
timeline_id: i64,
frame_rate: f64,
) -> Result<()>
pub fn set_frame_rate( &mut self, timeline_id: i64, frame_rate: f64, ) -> Result<()>
Change a timeline’s frame rate. Keys stay on their frames: CSP
stretches each track’s TimeClip by old / new rate (measured).
Source§impl ClipFile
impl ClipFile
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Reads and parses a file. The file is not kept open or changed.
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self>
pub fn from_bytes(data: Vec<u8>) -> Result<Self>
Parses the bytes of a .clip.
Sourcepub fn from_container(container: Container) -> Result<Self>
pub fn from_container(container: Container) -> Result<Self>
Opens the database of a parsed container and reads the typed views.
Sourcepub fn database(&self) -> &Connection
pub fn database(&self) -> &Connection
The embedded database (in memory; changes are saved by ClipFile::to_bytes).
Sourcepub fn schema(&self) -> Result<Schema>
pub fn schema(&self) -> Result<Schema>
The parameter scheme registry (ParamScheme / ElemScheme).
Sourcepub fn version_info(&self) -> Result<VersionInfo>
pub fn version_info(&self) -> Result<VersionInfo>
Which CSP generation saved the file (see crate::version).
Sourcepub fn external(&self, id: &str) -> Option<&[u8]>
pub fn external(&self, id: &str) -> Option<&[u8]>
Payload of an external chunk, None when the id is not stored.
Sourcepub fn external_ids(&self) -> impl Iterator<Item = &str>
pub fn external_ids(&self) -> impl Iterator<Item = &str>
Ids of the external chunks, in file order.
Sourcepub fn set_external(&mut self, id: &str, payload: Vec<u8>)
pub fn set_external(&mut self, id: &str, payload: Vec<u8>)
Store (or replace) an external chunk’s payload.
Sourcepub fn remove_external(&mut self, id: &str) -> bool
pub fn remove_external(&mut self, id: &str) -> bool
Removes an external chunk. Returns whether it was there.
Sourcepub fn offscreen(&self, main_id: i64) -> Result<Option<Offscreen>>
pub fn offscreen(&self, main_id: i64) -> Result<Option<Offscreen>>
Parse an Offscreen row and its block data (if stored).
Sourcepub fn mipmap_base(&self, mipmap_id: i64) -> Result<Option<Offscreen>>
pub fn mipmap_base(&self, mipmap_id: i64) -> Result<Option<Offscreen>>
The full-size offscreen of a mipmap (its first level).
Sourcepub fn layer_pixels(
&self,
layer: &Layer,
) -> Result<Option<(RgbaImage, (i64, i64))>>
pub fn layer_pixels( &self, layer: &Layer, ) -> Result<Option<(RgbaImage, (i64, i64))>>
The stored pixels of a layer and where their top-left lies on the canvas. None when the layer stores no pixels (CSP renders vector, text and similar layers itself when opening the file).
Sourcepub fn layer_pixels_in_box(
&self,
layer: &Layer,
region: (i64, i64, i64, i64),
) -> Result<RgbaImage>
pub fn layer_pixels_in_box( &self, layer: &Layer, region: (i64, i64, i64, i64), ) -> Result<RgbaImage>
The layer’s pixels inside the canvas box (x0, y0, x1, y1),
transparent where none are stored. Only the blocks the box overlaps
are decoded.
Sourcepub fn stored_pixel_boxes(
&self,
layer: &Layer,
) -> Result<Vec<(i64, i64, i64, i64)>>
pub fn stored_pixel_boxes( &self, layer: &Layer, ) -> Result<Vec<(i64, i64, i64, i64)>>
Canvas boxes (x0, y0, x1, y1) of the 256-pixel blocks of the layer
that store data, found without decompressing anything.
Sourcepub fn layer_mask(
&self,
layer: &Layer,
) -> Result<Option<(GrayImage, (i64, i64))>>
pub fn layer_mask( &self, layer: &Layer, ) -> Result<Option<(GrayImage, (i64, i64))>>
The layer mask (0 = hidden, 255 = shown) and its canvas position.
Sourcepub fn layer_thumbnail(&self, layer: &Layer) -> Result<Option<RgbaImage>>
pub fn layer_thumbnail(&self, layer: &Layer) -> Result<Option<RgbaImage>>
The layer palette thumbnail (Layer.LayerRenderThumbnail →
LayerThumbnail.ThumbnailOffscreen). None when there is none or it
stores no pixels.
Sourcepub fn preview(&self) -> Result<Option<RgbaImage>>
pub fn preview(&self) -> Result<Option<RgbaImage>>
The preview CSP saved with the file (CanvasPreview, a PNG).
Sourcepub fn external_references(&self) -> Result<Vec<(String, String, String)>>
pub fn external_references(&self) -> Result<Vec<(String, String, String)>>
Every external chunk id referenced from the database (table, column, id).
Sourcepub fn set_file_id(&mut self, id: [u8; 16])
pub fn set_file_id(&mut self, id: [u8; 16])
Give the saved file another id. CSP gives every “Save As” copy a new id and treats files with the same id as the same document: a copy opened while the original is open shows the original’s cached canvas until something is redrawn. Edited copies should get a new id.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Whether anything was changed since the file was opened.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>>
pub fn to_bytes(&self) -> Result<Vec<u8>>
The file’s bytes. Unchanged files are returned as read.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<()>
pub fn save(&self, path: impl AsRef<Path>) -> Result<()>
Writes ClipFile::to_bytes to a file.
path is replaced if it exists, and nothing checks whether it is
the file this was read from. Saving over the source is possible (its
bytes were read into memory), but a failed or interrupted write then
loses the original; keeping inputs intact is the caller’s job. The
cspf tool refuses an output that is one of its inputs.
Source§impl ClipFile
impl ClipFile
Sourcepub fn prepare_copy_from(&mut self, source: &ClipFile) -> Result<()>
pub fn prepare_copy_from(&mut self, source: &ClipFile) -> Result<()>
Give this file the tables, columns and brush styles a layer copied
from source needs (LAYER_TABLES, share_rows).
Sourcepub fn copy_layer_from(
&mut self,
source: &ClipFile,
layer_id: i64,
options: CopyLayer<'_>,
) -> Result<i64>
pub fn copy_layer_from( &mut self, source: &ClipFile, layer_id: i64, options: CopyLayer<'_>, ) -> Result<i64>
Copy layer layer_id of source (its row, without children) and the
rows it links to (vector data and the like) into this file; return
the new layer’s id.
The copy keeps its position (LayerOffsetX/Y), gets a new uuid and
new render offscreens, and loses what it cannot carry
(DROPPED_LAYER_LINKS: the layer mask, a frame folder’s images, 3D,
rulers). A raster layer’s stored pixels are copied with the area they
are stored in (which may reach past the canvas); other layers get
offscreens the size of this canvas, which CSP draws into when it opens
the file. Call ClipFile::prepare_copy_from first.
Sourcepub fn add_frame_images(&mut self, folder_id: i64) -> Result<()>
pub fn add_frame_images(&mut self, folder_id: i64) -> Result<()>
Give a frame folder (コマ枠フォルダー) copied with
ClipFile::copy_layer_from its mask and border images: offscreens
the size of the canvas with no pixels stored, which CSP draws from
the frames when it opens the file (CSP saves a frame folder’s so).
Source§impl ClipFile
impl ClipFile
Sourcepub fn create(canvas: &NewCanvas) -> Result<ClipFile>
pub fn create(canvas: &NewCanvas) -> Result<ClipFile>
A new file: root folder, paper (unless paper is None) and one
empty raster layer, ready for ClipFile::set_layer_pixels and
ClipFile::add_raster_layer. Call ClipFile::update_preview
after drawing.
Source§impl ClipFile
impl ClipFile
Sourcepub fn renew_file_id(&mut self)
pub fn renew_file_id(&mut self)
Give the saved file a new random id (see ClipFile::set_file_id).
Sourcepub fn set_layer_pixels(
&mut self,
layer_id: i64,
image: &RgbaImage,
position: (i64, i64),
) -> Result<()>
pub fn set_layer_pixels( &mut self, layer_id: i64, image: &RgbaImage, position: (i64, i64), ) -> Result<()>
Replace a raster layer’s pixels. image is placed with its top-left
at canvas position position; pixels outside the layer’s offscreen
are dropped. Only colour layers are supported.
Sourcepub fn set_layer_value(
&mut self,
layer_id: i64,
column: &str,
value: Value,
) -> Result<()>
pub fn set_layer_value( &mut self, layer_id: i64, column: &str, value: Value, ) -> Result<()>
Set one Layer column.
Sourcepub fn set_layer_name(&mut self, layer_id: i64, name: &str) -> Result<()>
pub fn set_layer_name(&mut self, layer_id: i64, name: &str) -> Result<()>
Renames a layer (LayerName).
Sourcepub fn set_layer_opacity(&mut self, layer_id: i64, opacity: f64) -> Result<()>
pub fn set_layer_opacity(&mut self, layer_id: i64, opacity: f64) -> Result<()>
Opacity 0.0..=1.0 (stored as 0..=256).
Sourcepub fn set_layer_blend(&mut self, layer_id: i64, mode: BlendMode) -> Result<()>
pub fn set_layer_blend(&mut self, layer_id: i64, mode: BlendMode) -> Result<()>
Sets the blend mode (LayerComposite).
Sourcepub fn set_layer_visible(&mut self, layer_id: i64, visible: bool) -> Result<()>
pub fn set_layer_visible(&mut self, layer_id: i64, visible: bool) -> Result<()>
Shows or hides a layer (LayerVisibility bit 0; the other bits are kept).
Sourcepub fn set_layer_clipping(
&mut self,
layer_id: i64,
clipping: bool,
) -> Result<()>
pub fn set_layer_clipping( &mut self, layer_id: i64, clipping: bool, ) -> Result<()>
Clips the layer to the layer below, or not (LayerClip).
Sourcepub fn update_preview(&mut self) -> Result<bool>
pub fn update_preview(&mut self) -> Result<bool>
Re-render CanvasPreview from the layers (call after editing pixels
so file browsers show the new content).
Source§impl ClipFile
impl ClipFile
Sourcepub fn next_main_id(&self, table: &str) -> Result<i64>
pub fn next_main_id(&self, table: &str) -> Result<i64>
The next MainId for table: one above both ElemScheme.MaxIndex
and the largest id in the table; MaxIndex is moved up to it.
Sourcepub fn add_layer(
&mut self,
parent: i64,
kind: NewLayer,
name: &str,
) -> Result<i64>
pub fn add_layer( &mut self, parent: i64, kind: NewLayer, name: &str, ) -> Result<i64>
Add a layer on top of the children of folder parent and return
its id. Raster layers start empty (see ClipFile::set_layer_pixels).
Sourcepub fn add_raster_layer(
&mut self,
name: &str,
image: &RgbaImage,
position: (i64, i64),
) -> Result<i64>
pub fn add_raster_layer( &mut self, name: &str, image: &RgbaImage, position: (i64, i64), ) -> Result<i64>
Add a raster layer on top of the root folder’s children holding
image with its top-left at canvas position position.
Sourcepub fn remove_layer(&mut self, layer_id: i64) -> Result<()>
pub fn remove_layer(&mut self, layer_id: i64) -> Result<()>
Remove a layer (a folder with everything in it): its rows, mipmaps, thumbnails, offscreens and their external chunks. The root folder cannot be removed.
Source§impl ClipFile
impl ClipFile
Sourcepub fn update_story_numbers(&mut self, first_right: bool) -> Result<()>
pub fn update_story_numbers(&mut self, first_right: bool) -> Result<()>
Write the page’s own ページ番号 and ノンブル into its story info texts
(update_page_number, update_nombre), after its
ComicPageIndex or the work’s story settings changed.