- bump libczi git repo
Publish / Publish (crates.io) (push) Failing after 54s

- replace anyhow with custom error type
This commit is contained in:
w.pomp
2026-03-16 11:11:54 +01:00
parent d4899e275b
commit 0982944195
7 changed files with 270 additions and 249 deletions
+142 -142
View File
@@ -1,8 +1,8 @@
use crate::error::Error;
use crate::handle::*;
use crate::interop::*;
use crate::misc::*;
use crate::sys::*;
use anyhow::{Error, Result};
use std::ffi::{CStr, CString, c_char, c_int, c_ulong, c_void};
use std::mem::{ManuallyDrop, MaybeUninit};
use std::ops::Deref;
@@ -22,10 +22,10 @@ pub fn free<T: Ptr>(data: T) {
/// \\param \[out\] data If successful, a pointer to the allocated memory is put here. The memory must be freed using 'libCZI_Free'.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn allocate_memory<T: Ptr>(size: usize) -> Result<MaybeUninit<T>> {
pub fn allocate_memory<T: Ptr>(size: usize) -> Result<MaybeUninit<T>, Error> {
let mut data = MaybeUninit::<T>::uninit();
let mut ptr = data.as_mut_ptr() as *mut c_void;
LibCZIApiError::try_from(unsafe { libCZI_AllocateMemory(size as c_ulong, &mut ptr) })?;
lib_czi_error(unsafe { libCZI_AllocateMemory(size as c_ulong, &mut ptr) })?;
Ok(data)
}
@@ -35,10 +35,10 @@ impl LibCZIVersionInfo {
/// \\param \[out\] version_info If successful, the version information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_lib_czi_version_info() -> Result<LibCZIVersionInfo> {
pub fn get_lib_czi_version_info() -> Result<LibCZIVersionInfo, Error> {
let mut version_info = MaybeUninit::uninit();
let ptr = version_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_GetLibCZIVersionInfo(ptr) })?;
lib_czi_error(unsafe { libCZI_GetLibCZIVersionInfo(ptr) })?;
Ok(unsafe { LibCZIVersionInfo::assume_init(version_info) })
}
}
@@ -49,10 +49,10 @@ impl LibCZIBuildInformation {
/// \\param \[out\] build_info If successful, the build information is put here. Note that all strings must be freed by the caller (using 'libCZI_Free').
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get() -> Result<LibCZIBuildInformation> {
pub fn get() -> Result<LibCZIBuildInformation, Error> {
let mut build_info = MaybeUninit::uninit();
let ptr = build_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_GetLibCZIBuildInformation(ptr) })?;
lib_czi_error(unsafe { libCZI_GetLibCZIBuildInformation(ptr) })?;
Ok(unsafe { LibCZIBuildInformation::assume_init(build_info) })
}
}
@@ -63,10 +63,10 @@ impl CziReader {
/// \\param \[out\] reader_object If the operation is successful, a handle to the newly created reader object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create() -> Result<Self> {
pub fn create() -> Result<Self, Error> {
let mut reader = MaybeUninit::uninit();
let ptr = reader.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_CreateReader(ptr) })?;
lib_czi_error(unsafe { libCZI_CreateReader(ptr) })?;
Ok(unsafe { Self::assume_init(reader) })
}
@@ -77,8 +77,8 @@ impl CziReader {
/// \\param open_info Parameters controlling the operation.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn open(&self, open_info: ReaderOpenInfo) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReaderOpen(**self, open_info.as_ptr()) })?;
pub fn open(&self, open_info: ReaderOpenInfo) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReaderOpen(**self, open_info.as_ptr()) })?;
Ok(())
}
@@ -89,10 +89,10 @@ impl CziReader {
/// \\param \[out\] file_header_info_interop If successful, the retrieved information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_file_header_info(&self) -> Result<FileHeaderInfo> {
pub fn get_file_header_info(&self) -> Result<FileHeaderInfo, Error> {
let mut file_header_info = MaybeUninit::uninit();
let ptr = file_header_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_ReaderGetFileHeaderInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_ReaderGetFileHeaderInfo(**self, ptr) })?;
Ok(unsafe { FileHeaderInfo::assume_init(file_header_info) })
}
@@ -105,12 +105,10 @@ impl CziReader {
/// \\param \[out\] sub_block_object If successful, a handle to the sub-block object is put here; otherwise 'kInvalidObjectHandle'.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn read_sub_block(&self, index: i32) -> Result<SubBlock> {
pub fn read_sub_block(&self, index: i32) -> Result<SubBlock, Error> {
let mut sub_block = MaybeUninit::uninit();
let ptr = sub_block.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
libCZI_ReaderReadSubBlock(**self, index as c_int, ptr)
})?;
lib_czi_error(unsafe { libCZI_ReaderReadSubBlock(**self, index as c_int, ptr) })?;
Ok(unsafe { SubBlock::assume_init(sub_block) })
}
@@ -121,10 +119,10 @@ impl CziReader {
/// \\param \[out\] statistics If non-null, the simple statistics will be put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_statistics_simple(&self) -> Result<SubBlockStatistics> {
pub fn get_statistics_simple(&self) -> Result<SubBlockStatistics, Error> {
let mut statistics = MaybeUninit::uninit();
let ptr = statistics.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_ReaderGetStatisticsSimple(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_ReaderGetStatisticsSimple(**self, ptr) })?;
Ok(unsafe { SubBlockStatistics::assume_init(statistics) })
}
@@ -151,12 +149,12 @@ impl CziReader {
pub fn get_statistics_ex(
&self,
number_of_per_channel_bounding_boxes: i32,
) -> Result<(SubBlockStatisticsEx, i32)> {
) -> Result<(SubBlockStatisticsEx, i32), Error> {
let mut statistics = MaybeUninit::uninit();
let ptr = statistics.as_mut_ptr();
let number_of_per_channel_bounding_boxes =
Box::into_raw(Box::new(number_of_per_channel_bounding_boxes));
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_ReaderGetStatisticsEx(**self, ptr, number_of_per_channel_bounding_boxes)
})?;
Ok(unsafe {
@@ -190,11 +188,9 @@ impl CziReader {
/// is responsible for freeing this memory (by calling libCZI_Free).
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_pyramid_statistics(&self) -> Result<String> {
pub fn get_pyramid_statistics(&self) -> Result<String, Error> {
let mut ptr = MaybeUninit::<*mut c_char>::uninit();
LibCZIApiError::try_from(unsafe {
libCZI_ReaderGetPyramidStatistics(**self, ptr.as_mut_ptr())
})?;
lib_czi_error(unsafe { libCZI_ReaderGetPyramidStatistics(**self, ptr.as_mut_ptr()) })?;
let ptr = unsafe { ptr.assume_init() };
assert!(!ptr.is_null());
let statistics = unsafe { CStr::from_ptr(ptr) }
@@ -210,10 +206,10 @@ impl CziReader {
/// \\param \[out\] metadata_segment_object If successful, a handle to the metadata-segment object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_metadata_segment(&self) -> Result<MetadataSegment> {
pub fn get_metadata_segment(&self) -> Result<MetadataSegment, Error> {
let mut metadata_segment = MaybeUninit::uninit();
let ptr = metadata_segment.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_ReaderGetMetadataSegment(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_ReaderGetMetadataSegment(**self, ptr) })?;
Ok(unsafe { MetadataSegment::assume_init(metadata_segment) })
}
@@ -222,11 +218,9 @@ impl CziReader {
/// \\param reader_object The reader object.
/// \\param \[out\] count The number of available attachments is put here.
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_attachment_count(&self) -> Result<i32> {
pub fn get_attachment_count(&self) -> Result<i32, Error> {
let mut count = MaybeUninit::<c_int>::uninit();
LibCZIApiError::try_from(unsafe {
libCZI_ReaderGetAttachmentCount(**self, count.as_mut_ptr())
})?;
lib_czi_error(unsafe { libCZI_ReaderGetAttachmentCount(**self, count.as_mut_ptr()) })?;
Ok(unsafe { count.assume_init() })
}
@@ -238,12 +232,10 @@ impl CziReader {
/// \\param \[out\] attachment_info_interop If successful, the retrieved information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_attachment_info_from_directory(&self, index: i32) -> Result<AttachmentInfo> {
pub fn get_attachment_info_from_directory(&self, index: i32) -> Result<AttachmentInfo, Error> {
let mut attachment_info = MaybeUninit::uninit();
let ptr = attachment_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
libCZI_ReaderGetAttachmentInfoFromDirectory(**self, index, ptr)
})?;
lib_czi_error(unsafe { libCZI_ReaderGetAttachmentInfoFromDirectory(**self, index, ptr) })?;
Ok(unsafe { AttachmentInfo::assume_init(attachment_info) })
}
@@ -254,10 +246,10 @@ impl CziReader {
/// \\param \[out\] attachment_object If successful and index is valid, a handle representing the attachment object is put here. If the index is
/// invalid, then the handle will have the value 'kInvalidObjectHandle'.
/// \\returns An error-code indicating success or failure of the operation.
pub fn read_attachment(&self, index: i32) -> Result<Attachment> {
pub fn read_attachment(&self, index: i32) -> Result<Attachment, Error> {
let mut attachment = MaybeUninit::uninit();
let ptr = attachment.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_ReaderReadAttachment(**self, index, ptr) })?;
lib_czi_error(unsafe { libCZI_ReaderReadAttachment(**self, index, ptr) })?;
Ok(unsafe { Attachment::assume_init(attachment) })
}
@@ -267,8 +259,8 @@ impl CziReader {
/// \\param reader_object The reader object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseReader(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseReader(**self) })?;
Ok(())
}
@@ -280,10 +272,10 @@ impl CziReader {
/// \\param \[out\] sub_block_info_interop If successful, the retrieved information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn try_get_sub_block_info_for_index(&self, index: i32) -> Result<SubBlockInfo> {
pub fn try_get_sub_block_info_for_index(&self, index: i32) -> Result<SubBlockInfo, Error> {
let mut sub_block_info = MaybeUninit::uninit();
let ptr = sub_block_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_TryGetSubBlockInfoForIndex(**self, index, ptr) })?;
lib_czi_error(unsafe { libCZI_TryGetSubBlockInfoForIndex(**self, index, ptr) })?;
Ok(unsafe { SubBlockInfo::assume_init(sub_block_info) })
}
@@ -293,10 +285,12 @@ impl CziReader {
/// \\param accessor_object \[out\] If the operation is successful, a handle to the newly created single-channel-scaling-tile-accessor is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create_single_channel_tile_accessor(&self) -> Result<SingleChannelScalingTileAccessor> {
pub fn create_single_channel_tile_accessor(
&self,
) -> Result<SingleChannelScalingTileAccessor, Error> {
let mut accessor = MaybeUninit::uninit();
let ptr = accessor.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_CreateSingleChannelTileAccessor(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_CreateSingleChannelTileAccessor(**self, ptr) })?;
Ok(unsafe { SingleChannelScalingTileAccessor::assume_init(accessor) })
}
}
@@ -314,10 +308,10 @@ impl Drop for CziReader {
/// must be freed (by the caller) using 'libCZI_Free'.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_stream_classes_count(index: i32) -> Result<InputStreamClassInfo> {
pub fn get_stream_classes_count(index: i32) -> Result<InputStreamClassInfo, Error> {
let mut input_stream_class_info = MaybeUninit::uninit();
let ptr = input_stream_class_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_GetStreamClassInfo(index, ptr) })?;
lib_czi_error(unsafe { libCZI_GetStreamClassInfo(index, ptr) })?;
Ok(unsafe { InputStreamClassInfo::assume_init(input_stream_class_info) })
}
@@ -335,14 +329,14 @@ impl InputStream {
stream_class_name: impl AsRef<str>,
creation_property_bag: impl AsRef<str>,
stream_identifier: impl AsRef<str>,
) -> Result<Self> {
) -> Result<Self, Error> {
let mut stream = MaybeUninit::uninit();
let ptr = stream.as_mut_ptr();
let stream_class_name = ManuallyDrop::new(CString::new(stream_class_name.as_ref())?);
let creation_property_bag =
ManuallyDrop::new(CString::new(creation_property_bag.as_ref())?);
let stream_identifier = ManuallyDrop::new(CString::new(stream_identifier.as_ref())?);
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateInputStream(
stream_class_name.as_ptr(),
creation_property_bag.as_ptr(),
@@ -362,12 +356,10 @@ impl InputStream {
/// \\param \[out\] stream_object The output stream object that will hold the created stream.
/// \\return An error-code that indicates whether the operation is successful or not. Non-positive values indicates successful, positive values
/// indicates unsuccessful operation.
pub fn create_from_file_wide(file_name: Vec<u32>) -> Result<Self> {
pub fn create_from_file_wide(file_name: Vec<u32>) -> Result<Self, Error> {
let mut stream = MaybeUninit::uninit();
let ptr = stream.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
libCZI_CreateInputStreamFromFileWide(file_name.as_ptr(), ptr)
})?;
lib_czi_error(unsafe { libCZI_CreateInputStreamFromFileWide(file_name.as_ptr(), ptr) })?;
Ok(unsafe { Self::assume_init(stream) })
}
@@ -377,12 +369,12 @@ impl InputStream {
/// \\param \[out\] stream_object The output stream object that will hold the created stream.
/// \\return An error-code that indicates whether the operation is successful or not. Non-positive values indicates successful, positive values
/// indicates unsuccessful operation.
pub fn create_from_file_utf8<S: AsRef<str>>(file_name: S) -> Result<Self> {
pub fn create_from_file_utf8<S: AsRef<str>>(file_name: S) -> Result<Self, Error> {
let mut stream = MaybeUninit::uninit();
let ptr = stream.as_mut_ptr();
let file_name = ManuallyDrop::new(CString::new(file_name.as_ref())?);
// let file_name = file_name.as_ref().as_bytes().to_vec();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateInputStreamFromFileUTF8(file_name.as_ptr() as *const c_char, ptr)
})?;
Ok(unsafe { Self::assume_init(stream) })
@@ -396,10 +388,12 @@ impl InputStream {
/// \\param \[out\] stream_object If successful, the handle to the newly created input stream object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create_from_external(external_input_stream: ExternalInputStreamStruct) -> Result<Self> {
pub fn create_from_external(
external_input_stream: ExternalInputStreamStruct,
) -> Result<Self, Error> {
let mut stream = MaybeUninit::uninit();
let ptr = stream.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateInputStreamFromExternal(external_input_stream.as_ptr(), ptr)
})?;
Ok(unsafe { Self::assume_init(stream) })
@@ -413,8 +407,8 @@ impl InputStream {
/// \\param stream_object The input stream object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseInputStream(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseInputStream(**self) })?;
Ok(())
}
}
@@ -434,10 +428,10 @@ impl SubBlock {
/// \\param \[out\] bitmap_object If successful, the handle to the newly created bitmap object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create_bitmap(&self) -> Result<Bitmap> {
pub fn create_bitmap(&self) -> Result<Bitmap, Error> {
let mut bitmap = MaybeUninit::uninit();
let ptr = bitmap.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_SubBlockCreateBitmap(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_SubBlockCreateBitmap(**self, ptr) })?;
Ok(unsafe { Bitmap::assume_init(bitmap) })
}
@@ -447,10 +441,10 @@ impl SubBlock {
/// \\param \[out\] sub_block_info If successful, information about the sub-block object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_info(&self) -> Result<SubBlockInfo> {
pub fn get_info(&self) -> Result<SubBlockInfo, Error> {
let mut sub_block_info = MaybeUninit::uninit();
let ptr = sub_block_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_SubBlockGetInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_SubBlockGetInfo(**self, ptr) })?;
Ok(unsafe { SubBlockInfo::assume_init(sub_block_info) })
}
@@ -468,10 +462,10 @@ impl SubBlock {
/// \\param \[out\] data Pointer where the data is to be copied to. At most the initial content of 'size' bytes are copied.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_raw_data(&self, tp: RawDataType, size: i32) -> Result<(i32, Vec<u8>)> {
pub fn get_raw_data(&self, tp: RawDataType, size: i32) -> Result<(i32, Vec<u8>), Error> {
let mut data = Vec::<u8>::with_capacity(size as usize);
let size = Box::into_raw(Box::new(size as c_ulong));
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_SubBlockGetRawData(**self, tp as c_int, size, data.as_mut_ptr() as *mut c_void)
})?;
Ok((unsafe { *Box::from_raw(size) as i32 }, data))
@@ -482,8 +476,8 @@ impl SubBlock {
/// \\param sub_block_object The sub block object to be released.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseSubBlock(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseSubBlock(**self) })?;
Ok(())
}
}
@@ -499,10 +493,10 @@ impl Attachment {
/// \\param attachment_object The attachment object.
/// \\param \[out\] attachment_info Information about the attachment.
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_info(&self) -> Result<AttachmentInfo> {
pub fn get_info(&self) -> Result<AttachmentInfo, Error> {
let mut attachment_info = MaybeUninit::uninit();
let ptr = attachment_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_AttachmentGetInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_AttachmentGetInfo(**self, ptr) })?;
Ok(unsafe { AttachmentInfo::assume_init(attachment_info) })
}
@@ -515,10 +509,10 @@ impl Attachment {
/// \\param \[out\] data Pointer where the data is to be copied to. At most the initial content of 'size' bytes are copied.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_raw_data(&self, size: i32) -> Result<(i32, Vec<u8>)> {
pub fn get_raw_data(&self, size: i32) -> Result<(i32, Vec<u8>), Error> {
let mut data = Vec::<u8>::with_capacity(size as usize);
let size = Box::into_raw(Box::new(size as c_ulong));
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_AttachmentGetRawData(**self, size, data.as_mut_ptr() as *mut c_void)
})?;
Ok((unsafe { *Box::from_raw(size) as i32 }, data))
@@ -529,8 +523,8 @@ impl Attachment {
/// \\param attachment_object The attachment object to be released.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseAttachment(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseAttachment(**self) })?;
Ok(())
}
}
@@ -548,10 +542,10 @@ impl Bitmap {
/// \\param \[out\] bitmap_info If successful, information about the bitmap object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_info(&self) -> Result<BitmapInfo> {
pub fn get_info(&self) -> Result<BitmapInfo, Error> {
let mut bitmap_info = MaybeUninit::uninit();
let ptr = bitmap_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_BitmapGetInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_BitmapGetInfo(**self, ptr) })?;
Ok(unsafe { BitmapInfo::assume_init(bitmap_info) })
}
@@ -564,10 +558,10 @@ impl Bitmap {
/// \\param \[out\] lockInfo If successful, information about how to access the pixel data is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn lock(self) -> Result<LockedBitmap> {
pub fn lock(self) -> Result<LockedBitmap, Error> {
let mut bitmap_info = MaybeUninit::uninit();
let ptr = bitmap_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_BitmapLock(*self, ptr) })?;
lib_czi_error(unsafe { libCZI_BitmapLock(*self, ptr) })?;
let bitmap_lock_info = unsafe { BitmapLockInfo::assume_init(bitmap_info) };
Ok(LockedBitmap {
bitmap: self,
@@ -581,8 +575,8 @@ impl Bitmap {
/// \\param bitmap_object The bitmap object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseBitmap(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseBitmap(**self) })?;
Ok(())
}
}
@@ -590,7 +584,7 @@ impl Bitmap {
impl TryFrom<&SubBlock> for Bitmap {
type Error = Error;
fn try_from(sub_block: &SubBlock) -> Result<Self> {
fn try_from(sub_block: &SubBlock) -> Result<Self, Error> {
sub_block.create_bitmap()
}
}
@@ -627,8 +621,8 @@ impl LockedBitmap {
/// \\param bitmap_object The bitmap object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn unlock(self) -> Result<Bitmap> {
LibCZIApiError::try_from(unsafe { libCZI_BitmapUnlock(**self) })?;
pub fn unlock(self) -> Result<Bitmap, Error> {
lib_czi_error(unsafe { libCZI_BitmapUnlock(**self) })?;
Ok(self.bitmap.clone())
}
@@ -649,9 +643,9 @@ impl LockedBitmap {
height: u32,
pixel_type: PixelType,
stride: u32,
) -> Result<Bitmap> {
) -> Result<Bitmap, Error> {
let mut data = MaybeUninit::<Self>::uninit();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_BitmapCopyTo(
***self,
width,
@@ -674,10 +668,10 @@ impl MetadataSegment {
/// \\param \[out\] metadata_as_xml_interop If successful, the XML-metadata information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_metadata_as_xml(&self) -> Result<MetadataAsXml> {
pub fn get_metadata_as_xml(&self) -> Result<MetadataAsXml, Error> {
let mut metadata_as_xml_interop = MaybeUninit::uninit();
let ptr = metadata_as_xml_interop.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_MetadataSegmentGetMetadataAsXml(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_MetadataSegmentGetMetadataAsXml(**self, ptr) })?;
Ok(unsafe { MetadataAsXml::assume_init(metadata_as_xml_interop) })
}
@@ -687,10 +681,10 @@ impl MetadataSegment {
/// \\param \[in,out\] czi_document_info If successful, a handle to the newly created CZI-document-info object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_czi_document_info(&self) -> Result<CziDocumentInfo> {
pub fn get_czi_document_info(&self) -> Result<CziDocumentInfo, Error> {
let mut czi_document = MaybeUninit::uninit();
let ptr = czi_document.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_MetadataSegmentGetCziDocumentInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_MetadataSegmentGetCziDocumentInfo(**self, ptr) })?;
Ok(unsafe { CziDocumentInfo::assume_init(czi_document) })
}
@@ -699,8 +693,8 @@ impl MetadataSegment {
/// \\param metadata_segment_object The metadata-segment object to be released.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseMetadataSegment(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseMetadataSegment(**self) })?;
Ok(())
}
}
@@ -727,9 +721,9 @@ impl CziDocumentInfo {
/// \\param \[out\] general_document_info_json If successful, the general document information is put here. Note that the data must be freed using 'libCZI_Free' by the caller.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_general_document_info(&self) -> Result<String> {
pub fn get_general_document_info(&self) -> Result<String, Error> {
let mut ptr = MaybeUninit::<*mut c_char>::uninit();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CziDocumentInfoGetGeneralDocumentInfo(
**self,
ptr.as_mut_ptr() as *mut *mut c_void,
@@ -750,10 +744,10 @@ impl CziDocumentInfo {
/// \\param \[out\] scaling_info_interop If successful, the scaling information is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_scaling_info(&self) -> Result<ScalingInfo> {
pub fn get_scaling_info(&self) -> Result<ScalingInfo, Error> {
let mut scaling_info_interop = MaybeUninit::uninit();
let ptr = scaling_info_interop.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_CziDocumentInfoGetScalingInfo(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_CziDocumentInfoGetScalingInfo(**self, ptr) })?;
Ok(unsafe { ScalingInfo::assume_init(scaling_info_interop) })
}
@@ -764,10 +758,10 @@ impl CziDocumentInfo {
/// \\param \[in,out\] display_settings_handle If successful, a handle to the display-settings object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_display_settings(&self) -> Result<DisplaySettings> {
pub fn get_display_settings(&self) -> Result<DisplaySettings, Error> {
let mut display_settings = MaybeUninit::uninit();
let ptr = display_settings.as_mut_ptr();
LibCZIApiError::try_from(unsafe { libCZI_CziDocumentInfoGetDisplaySettings(**self, ptr) })?;
lib_czi_error(unsafe { libCZI_CziDocumentInfoGetDisplaySettings(**self, ptr) })?;
Ok(unsafe { DisplaySettings::assume_init(display_settings) })
}
@@ -778,9 +772,9 @@ impl CziDocumentInfo {
/// \\param \[out\] dimension_info_json If successful, the information is put here as JSON format. Note that the data must be freed using 'libCZI_Free' by the caller.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn get_dimension_info(&self, dimension_index: u32) -> Result<String> {
pub fn get_dimension_info(&self, dimension_index: u32) -> Result<String, Error> {
let mut ptr = MaybeUninit::<*mut c_char>::uninit();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CziDocumentInfoGetDimensionInfo(
**self,
dimension_index,
@@ -799,8 +793,8 @@ impl CziDocumentInfo {
/// \\param czi_document_info The CZI-document-info object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseCziDocumentInfo(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseCziDocumentInfo(**self) })?;
Ok(())
}
}
@@ -822,10 +816,10 @@ impl OutputStream {
///
/// \\return An error-code that indicates whether the operation is successful or not. Non-positive values indicates successful, positive values
/// indicates unsuccessful operation.
pub fn create_for_file_wide(file_name: Vec<u32>, overwrite: bool) -> Result<Self> {
pub fn create_for_file_wide(file_name: Vec<u32>, overwrite: bool) -> Result<Self, Error> {
let mut output_stream = MaybeUninit::uninit();
let ptr = output_stream.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateOutputStreamForFileWide(file_name.as_ptr(), overwrite, ptr)
})?;
Ok(unsafe { Self::assume_init(output_stream) })
@@ -839,11 +833,14 @@ impl OutputStream {
///
/// \\return An error-code that indicates whether the operation is successful or not. Non-positive values indicates successful, positive values
/// indicates unsuccessful operation.
pub fn create_for_file_utf8<S: AsRef<str>>(file_name: S, overwrite: bool) -> Result<Self> {
pub fn create_for_file_utf8<S: AsRef<str>>(
file_name: S,
overwrite: bool,
) -> Result<Self, Error> {
let mut output_stream = MaybeUninit::uninit();
let ptr = output_stream.as_mut_ptr();
let file_name = ManuallyDrop::new(CString::new(file_name.as_ref())?);
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateOutputStreamForFileUTF8(file_name.as_ptr(), overwrite, ptr)
})?;
Ok(unsafe { Self::assume_init(output_stream) })
@@ -857,8 +854,8 @@ impl OutputStream {
/// \\param output_stream_object The output stream object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseOutputStream(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseOutputStream(**self) })?;
Ok(())
}
@@ -870,10 +867,12 @@ impl OutputStream {
/// \\param \[out\] output_stream_object If successful, the handle to the newly created output stream object is put here.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create_from_external(external_input_stream: ExternalOutputStreamStruct) -> Result<Self> {
pub fn create_from_external(
external_input_stream: ExternalOutputStreamStruct,
) -> Result<Self, Error> {
let mut stream = MaybeUninit::uninit();
let ptr = stream.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CreateOutputStreamFromExternal(external_input_stream.as_ptr(), ptr)
})?;
Ok(unsafe { Self::assume_init(stream) })
@@ -899,11 +898,11 @@ impl CziWriter {
/// \\param options A JSON-formatted zero-terminated string (in UTF8-encoding) containing options for the writer creation.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn create<S: AsRef<str>>(options: S) -> Result<Self> {
pub fn create<S: AsRef<str>>(options: S) -> Result<Self, Error> {
let mut writer = MaybeUninit::uninit();
let ptr = writer.as_mut_ptr();
let options = ManuallyDrop::new(CString::new(options.as_ref())?);
LibCZIApiError::try_from(unsafe { libCZI_CreateWriter(ptr, options.as_ptr()) })?;
lib_czi_error(unsafe { libCZI_CreateWriter(ptr, options.as_ptr()) })?;
Ok(unsafe { Self::assume_init(writer) })
}
@@ -924,9 +923,13 @@ impl CziWriter {
/// \\param parameters A JSON-formatted zero-terminated string (in UTF8-encoding) containing options for the writer initialization.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn init<S: AsRef<str>>(&self, output_stream: &OutputStream, parameters: S) -> Result<()> {
pub fn init<S: AsRef<str>>(
&self,
output_stream: &OutputStream,
parameters: S,
) -> Result<(), Error> {
let parameters = ManuallyDrop::new(CString::new(parameters.as_ref())?);
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_WriterCreate(**self, **output_stream, parameters.as_ptr())
})?;
Ok(())
@@ -938,10 +941,8 @@ impl CziWriter {
/// \\param add_sub_block_info_interop Information describing the sub-block to be added.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn add_sub_block(&self, add_sub_block_info: AddSubBlockInfo) -> Result<()> {
LibCZIApiError::try_from(unsafe {
libCZI_WriterAddSubBlock(**self, add_sub_block_info.as_ptr())
})?;
pub fn add_sub_block(&self, add_sub_block_info: AddSubBlockInfo) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_WriterAddSubBlock(**self, add_sub_block_info.as_ptr()) })?;
Ok(())
}
@@ -951,10 +952,8 @@ impl CziWriter {
/// \\param add_attachment_info_interop Information describing the attachment to be added.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn add_attachement(&self, add_attachment_info: AddAttachmentInfo) -> Result<()> {
LibCZIApiError::try_from(unsafe {
libCZI_WriterAddAttachment(**self, add_attachment_info.as_ptr())
})?;
pub fn add_attachement(&self, add_attachment_info: AddAttachmentInfo) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_WriterAddAttachment(**self, add_attachment_info.as_ptr()) })?;
Ok(())
}
@@ -964,10 +963,8 @@ impl CziWriter {
/// \\param write_metadata_info_interop Information describing the metadata to be added.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn write_metadata(&self, write_metadata_info: WriteMetadataInfo) -> Result<()> {
LibCZIApiError::try_from(unsafe {
libCZI_WriterWriteMetadata(**self, write_metadata_info.as_ptr())
})?;
pub fn write_metadata(&self, write_metadata_info: WriteMetadataInfo) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_WriterWriteMetadata(**self, write_metadata_info.as_ptr()) })?;
Ok(())
}
@@ -978,8 +975,8 @@ impl CziWriter {
/// \\param writer_object Handle to the writer object that is to be closed.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn close(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_WriterClose(**self) })?;
pub fn close(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_WriterClose(**self) })?;
Ok(())
}
@@ -988,8 +985,8 @@ impl CziWriter {
/// \\param writer_object Handle to the writer object that is to be released.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseWriter(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseWriter(**self) })?;
Ok(())
}
}
@@ -1010,10 +1007,10 @@ impl SingleChannelScalingTileAccessor {
/// \\param size \[out\] The size of the tile accessor. It contains width and height information.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn calc_size(&self, roi: IntRect, zoom: f32) -> Result<IntSize> {
pub fn calc_size(&self, roi: IntRect, zoom: f32) -> Result<IntSize, Error> {
let mut size = MaybeUninit::uninit();
let ptr = size.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_SingleChannelTileAccessorCalcSize(**self, roi.as_ptr(), zoom, ptr)
})?;
Ok(unsafe { IntSize::assume_init(size) })
@@ -1035,10 +1032,10 @@ impl SingleChannelScalingTileAccessor {
roi: IntRect,
zoom: f32,
options: AccessorOptions,
) -> Result<Bitmap> {
) -> Result<Bitmap, Error> {
let mut bitmap = MaybeUninit::uninit();
let ptr = bitmap.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_SingleChannelTileAccessorGet(
**self,
coordinate.as_ptr(),
@@ -1056,8 +1053,8 @@ impl SingleChannelScalingTileAccessor {
/// \\param accessor_object The accessor object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseCreateSingleChannelTileAccessor(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseCreateSingleChannelTileAccessor(**self) })?;
Ok(())
}
}
@@ -1084,10 +1081,10 @@ impl DisplaySettings {
&self,
channel_index: i32,
sixteen_or_eight_bits_lut: bool,
) -> Result<CompositionChannelInfo> {
) -> Result<CompositionChannelInfo, Error> {
let mut composition_channel_info = MaybeUninit::uninit();
let ptr = composition_channel_info.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CompositorFillOutCompositionChannelInfoInterop(
**self,
channel_index,
@@ -1098,10 +1095,13 @@ impl DisplaySettings {
Ok(unsafe { CompositionChannelInfo::assume_init(composition_channel_info) })
}
pub fn get_channel_display_settings(&self, channel_id: i32) -> Result<ChannelDisplaySettings> {
pub fn get_channel_display_settings(
&self,
channel_id: i32,
) -> Result<ChannelDisplaySettings, Error> {
let mut channel_display_setting = MaybeUninit::uninit();
let ptr = channel_display_setting.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_DisplaySettingsGetChannelDisplaySettings(**self, channel_id, ptr)
})?;
Ok(unsafe { ChannelDisplaySettings::assume_init(channel_display_setting) })
@@ -1112,8 +1112,8 @@ impl DisplaySettings {
/// \\param display_settings_handle The display settings object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseDisplaySettings(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseDisplaySettings(**self) })?;
Ok(())
}
}
@@ -1138,10 +1138,10 @@ pub fn compositor_do_multi_channel_composition(
channel_count: i32,
source_bitmaps: Vec<Bitmap>,
channel_info: CompositionChannelInfo,
) -> Result<Bitmap> {
) -> Result<Bitmap, Error> {
let mut bitmap = MaybeUninit::uninit();
let ptr = bitmap.as_mut_ptr();
LibCZIApiError::try_from(unsafe {
lib_czi_error(unsafe {
libCZI_CompositorDoMultiChannelComposition(
channel_count,
source_bitmaps.as_ptr() as *const BitmapObjectHandle,
@@ -1158,8 +1158,8 @@ impl ChannelDisplaySettings {
/// \\param channel_display_settings_handle The channel-display settings object.
///
/// \\returns An error-code indicating success or failure of the operation.
pub fn release(&self) -> Result<()> {
LibCZIApiError::try_from(unsafe { libCZI_ReleaseDisplaySettings(**self) })?;
pub fn release(&self) -> Result<(), Error> {
lib_czi_error(unsafe { libCZI_ReleaseDisplaySettings(**self) })?;
Ok(())
}
}