Skip to main content

ClipFile

Struct ClipFile 

Source
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 changed

Fields§

§project: Project

The Project row.

§canvas: Canvas

The canvas settings.

§layers: LayerTree

The layer tree, read at open (call ClipFile::reload after changing Layer rows).

Implementations§

Source§

impl ClipFile

Source

pub fn animation(&self) -> Result<Option<Animation>>

The animation data, None when the file has no timeline.

Source

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

pub fn set_frame_range( &mut self, timeline_id: i64, start: i64, end: i64, ) -> Result<()>

Change a timeline’s playback range (0-based first frame, frame after the last), as CSP’s 再生フレーム settings store it.

Source

pub fn set_cel_keys( &mut self, timeline_id: i64, folder_id: i64, keys: &[(i64, String)], ) -> Result<()>

Replace the cel keys of an animation folder in a timeline: each (0-based frame, cel layer name) shows that cel from that frame on. The folder must already have a cel track in the timeline.

Source§

impl ClipFile

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Reads and parses a file. The file is not kept open or changed.

Source

pub fn from_bytes(data: Vec<u8>) -> Result<Self>

Parses the bytes of a .clip.

Source

pub fn from_container(container: Container) -> Result<Self>

Opens the database of a parsed container and reads the typed views.

Source

pub fn container(&self) -> &Container

The parsed container (chunks of the file as opened).

Source

pub fn database(&self) -> &Connection

The embedded database (in memory; changes are saved by ClipFile::to_bytes).

Source

pub fn schema(&self) -> Result<Schema>

The parameter scheme registry (ParamScheme / ElemScheme).

Source

pub fn version_info(&self) -> Result<VersionInfo>

Which CSP generation saved the file (see crate::version).

Source

pub fn reload(&mut self) -> Result<()>

Re-read the typed views after changing the database.

Source

pub fn external(&self, id: &str) -> Option<&[u8]>

Payload of an external chunk, None when the id is not stored.

Source

pub fn external_ids(&self) -> impl Iterator<Item = &str>

Ids of the external chunks, in file order.

Source

pub fn set_external(&mut self, id: &str, payload: Vec<u8>)

Store (or replace) an external chunk’s payload.

Source

pub fn remove_external(&mut self, id: &str) -> bool

Removes an external chunk. Returns whether it was there.

Source

pub fn row(&self, table: &str, main_id: i64) -> Result<Option<Row>>

One row by MainId.

Source

pub fn mipmap(&self, main_id: i64) -> Result<Option<Mipmap>>

A mipmap and its levels.

Source

pub fn offscreen(&self, main_id: i64) -> Result<Option<Offscreen>>

Parse an Offscreen row and its block data (if stored).

Source

pub fn mipmap_base(&self, mipmap_id: i64) -> Result<Option<Offscreen>>

The full-size offscreen of a mipmap (its first level).

Source

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).

Source

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.

Source

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.

Source

pub fn layer_mask( &self, layer: &Layer, ) -> Result<Option<(GrayImage, (i64, i64))>>

The layer mask (0 = hidden, 255 = shown) and its canvas position.

Source

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.

Source

pub fn preview(&self) -> Result<Option<RgbaImage>>

The preview CSP saved with the file (CanvasPreview, a PNG).

Source

pub fn external_references(&self) -> Result<Vec<(String, String, String)>>

Every external chunk id referenced from the database (table, column, id).

Source

pub fn file_id(&self) -> [u8; 16]

The 16-byte file id in the Head chunk.

Source

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.

Source

pub fn is_modified(&self) -> bool

Whether anything was changed since the file was opened.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

The file’s bytes. Unchanged files are returned as read.

Source

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

Source

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).

Source

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.

Source

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

Source

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

Source

pub fn renew_file_id(&mut self)

Give the saved file a new random id (see ClipFile::set_file_id).

Source

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.

Source

pub fn set_layer_value( &mut self, layer_id: i64, column: &str, value: Value, ) -> Result<()>

Set one Layer column.

Source

pub fn set_layer_name(&mut self, layer_id: i64, name: &str) -> Result<()>

Renames a layer (LayerName).

Source

pub fn set_layer_opacity(&mut self, layer_id: i64, opacity: f64) -> Result<()>

Opacity 0.0..=1.0 (stored as 0..=256).

Source

pub fn set_layer_blend(&mut self, layer_id: i64, mode: BlendMode) -> Result<()>

Sets the blend mode (LayerComposite).

Source

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).

Source

pub fn set_layer_clipping( &mut self, layer_id: i64, clipping: bool, ) -> Result<()>

Clips the layer to the layer below, or not (LayerClip).

Source

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

Source

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.

Source

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).

Source

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.

Source

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

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.