C interface for conversion
This commit is contained in:
parent
23ff5fe6a8
commit
f94f53185c
|
@ -81,47 +81,6 @@ pub fn convert_in_memory(in_file: Vec<u8>, format: SupportedFileTypes, parameter
|
|||
Ok(compressed_converted_image)
|
||||
}
|
||||
}
|
||||
|
||||
// match output_format {
|
||||
// ImageFormat::Png => {
|
||||
// let mut decoder = WebPDecoder::new(Cursor::new(compressed_converted_image.as_slice()))
|
||||
// .map_err(|e| CaesiumError {
|
||||
// message: e.to_string(),
|
||||
// code: 10405,
|
||||
// })?;
|
||||
// let bytes_per_pixel = if decoder.has_alpha() { 4 } else { 3 };
|
||||
// let (width, height) = decoder.dimensions();
|
||||
// let mut data = vec![0; width as usize * height as usize * bytes_per_pixel];
|
||||
// decoder.read_image(&mut data)
|
||||
// .map_err(|e| CaesiumError {
|
||||
// message: e.to_string(),
|
||||
// code: 10406,
|
||||
// })?;
|
||||
// let mut output_image_with_metadata: Vec<u8> = Vec::new();
|
||||
// let mut encoder = WebPEncoder::new(&mut output_image_with_metadata);
|
||||
// if iccp.is_some() {
|
||||
// encoder.set_icc_profile(iccp.unwrap_or(Bytes::new()).to_vec());
|
||||
// }
|
||||
// if exif.is_some() {
|
||||
// encoder.set_exif_metadata(exif.unwrap_or(Bytes::new()).to_vec());
|
||||
// }
|
||||
//
|
||||
// let color_type = match bytes_per_pixel {
|
||||
// 4 => Rgba8,
|
||||
// _ => Rgb8
|
||||
// };
|
||||
// encoder.encode(data.as_slice(), width, height, color_type)
|
||||
// .map_err(|e| CaesiumError {
|
||||
// message: e.to_string(),
|
||||
// code: 10407,
|
||||
// })?;
|
||||
//
|
||||
// Ok(output_image_with_metadata)
|
||||
// }
|
||||
// _ => {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
Ok(compressed_converted_image)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::os::raw::c_char;
|
|||
|
||||
use tiff::encoder::compression::DeflateLevel::{Balanced, Best, Fast};
|
||||
|
||||
use crate::{ChromaSubsampling, compress, compress_to_size, CSParameters, error, initialize_parameters};
|
||||
use crate::{ChromaSubsampling, compress, compress_to_size, convert, CSParameters, error, initialize_parameters, SupportedFileTypes};
|
||||
use crate::TiffCompression::{Deflate, Lzw, Packbits, Uncompressed};
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -66,6 +66,24 @@ pub unsafe extern "C" fn c_compress_to_size(
|
|||
))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
pub unsafe extern "C" fn c_convert(
|
||||
input_path: *const c_char,
|
||||
output_path: *const c_char,
|
||||
format: SupportedFileTypes,
|
||||
params: CCSParameters,
|
||||
) -> CCSResult {
|
||||
let parameters = c_set_parameters(params);
|
||||
|
||||
c_return_result(convert(
|
||||
CStr::from_ptr(input_path).to_str().unwrap().to_string(),
|
||||
CStr::from_ptr(output_path).to_str().unwrap().to_string(),
|
||||
¶meters,
|
||||
format
|
||||
))
|
||||
}
|
||||
|
||||
fn c_return_result(result: error::Result<()>) -> CCSResult {
|
||||
let mut error_message = CString::new("").unwrap();
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@ pub fn compress_to_size(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn convert(input_path: String, output_path: String, format: SupportedFileTypes, parameters: &CSParameters) -> Result<(), CaesiumError> {
|
||||
pub fn convert(input_path: String, output_path: String, parameters: &CSParameters, format: SupportedFileTypes) -> Result<(), CaesiumError> {
|
||||
|
||||
let file_type = get_filetype_from_path(&input_path);
|
||||
|
||||
|
@ -345,7 +345,7 @@ pub fn convert(input_path: String, output_path: String, format: SupportedFileTyp
|
|||
message: e.to_string(),
|
||||
code: 10410,
|
||||
})?;
|
||||
let output_buffer = convert_in_memory(in_file, format, parameters).map_err(|e| CaesiumError {
|
||||
let output_buffer = convert_in_memory(in_file, parameters, format).map_err(|e| CaesiumError {
|
||||
message: e.to_string(),
|
||||
code: 10411,
|
||||
})?;
|
||||
|
@ -362,7 +362,7 @@ pub fn convert(input_path: String, output_path: String, format: SupportedFileTyp
|
|||
|
||||
Ok(())
|
||||
}
|
||||
pub fn convert_in_memory(in_file: Vec<u8>, format: SupportedFileTypes, parameters: &CSParameters) -> Result<Vec<u8>, CaesiumError> {
|
||||
pub fn convert_in_memory(in_file: Vec<u8>, parameters: &CSParameters, format: SupportedFileTypes) -> Result<Vec<u8>, CaesiumError> {
|
||||
convert::convert_in_memory(in_file, format, parameters)
|
||||
}
|
||||
|
||||
|
@ -412,6 +412,7 @@ fn validate_parameters(parameters: &CSParameters) -> error::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum SupportedFileTypes {
|
||||
Jpeg,
|
||||
|
|
Loading…
Reference in New Issue