From c8e9f3e3b14a5fc1e789b6e8b8fd352665ba2d48 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Fri, 5 Jul 2024 01:58:00 -0500 Subject: [PATCH] Improved documentation --- cz/src/dynamic.rs | 39 +++++++++++++++++++++------------------ experimental/src/main.rs | 4 ++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cz/src/dynamic.rs b/cz/src/dynamic.rs index 6c2d1a4..8e28e5c 100644 --- a/cz/src/dynamic.rs +++ b/cz/src/dynamic.rs @@ -144,14 +144,14 @@ impl DynamicCz { // Do things with palettes if let Some(pal) = &self.palette { // Use the existing palette to palette the image - output_bitmap = rgba_to_indexed(self.bitmap(), pal)?; + output_bitmap = rgba_to_indexed(self.as_raw(), pal)?; for rgba in pal.colors() { output.write_all(rgba.as_slice())?; } } else { // Generate a palette and corresponding indexed bitmap if there is none - let result = indexed_gen_palette(self.bitmap(), self.header())?; + let result = indexed_gen_palette(self.as_raw(), self.header())?; output_bitmap = result.0; let palette = result.1; @@ -221,17 +221,15 @@ impl DynamicCz { Ok(()) } - /// Create a CZ# image from RGBA bytes. The bytes *must* be RGBA, as it is - /// used internally for operations + /// Create a CZ# image from RGBA bytes. The bytes *must* be RGBA, as that + /// is the only format that is used internally. pub fn from_raw( version: CzVersion, - depth: u16, width: u16, height: u16, bitmap: Vec, ) -> Self { - let mut header_common = CommonHeader::new(version, width, height); - header_common.set_depth(depth); + let header_common = CommonHeader::new(version, width, height); Self { header_common, @@ -241,15 +239,15 @@ impl DynamicCz { } } - /// Set a specific header for the image, this basica + /// Set a specific header for the image. pub fn with_header(mut self, header: CommonHeader) -> Self { self.header_common = header; self } - /// Add an [`ExtendedHeader`] to the image. This header controls things like - /// cropping and offsets in the game engine + /// Set an [`ExtendedHeader`] to be used for the image. This header + /// controls things like cropping and offsets in the game engine. pub fn with_extended_header(mut self, ext_header: ExtendedHeader) -> Self { if ext_header.offset_width.is_some() { self.header_common.set_length(36) @@ -262,24 +260,28 @@ impl DynamicCz { self } - /// Retrieve a reference to the palette if it exists, otherwise [`None`] - /// is returned + /// Remove an extended header if the image has one, else this does nothing. + pub fn clear_extended_header(&mut self) { + self.header_extended = None + } + + /// Returns a reference to the palette if it exists. pub fn palette(&self) -> &Option { &self.palette } - /// Retrieve a mutable reference to the palette if it exists, otherwise - /// [`None`] is returned + /// Returns a mutable reference to the palette if it exists. pub fn palette_mut(&mut self) -> &mut Option { &mut self.palette } /// Remove the image palette, which forces palette regeneration on save - /// for bit depths 8 or less - pub fn remove_palette(&mut self) { + /// for images with a bit depth of 8. + pub fn clear_palette(&mut self) { *self.palette_mut() = None } + /// Returns a reference to the [`CommonHeader`] of the image. pub fn header(&self) -> &CommonHeader { &self.header_common } @@ -292,11 +294,12 @@ impl DynamicCz { header.clone_into(&mut self.header_common) } - pub fn bitmap(&self) -> &Vec { + /// Returns the underlying raw buffer. + pub fn as_raw(&self) -> &Vec { &self.bitmap } - pub fn into_bitmap(self) -> Vec { + pub fn into_raw(self) -> Vec { self.bitmap } diff --git a/experimental/src/main.rs b/experimental/src/main.rs index 1446347..fdb9a0a 100644 --- a/experimental/src/main.rs +++ b/experimental/src/main.rs @@ -2,7 +2,7 @@ fn main() { let mut cz_file = cz::open("test_file.cz3").unwrap(); cz_file.save_as_png("test.png").unwrap(); - cz_file.header_mut().set_version(3).unwrap(); + cz_file.header_mut().set_version(4).unwrap(); - cz_file.save_as_cz("test_file.cz2").unwrap(); + cz_file.save_as_cz("test_file.cz4").unwrap(); }