From 74cb9e36748854c30a65b4701e2ef058bf5fece5 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sun, 5 Jan 2025 19:40:13 +0100 Subject: [PATCH] native_image: Autogenerate pixelmap functions Signed-off-by: Jonathan Schwender --- .../image_framework/src/native_image/image.rs | 21 -------- .../src/native_image/image/image_ffi.rs | 24 +++++++++ .../src/native_image/image_packer.rs | 39 -------------- .../image_packer/image_packer_ffi.rs | 54 +++++++++++++++++++ .../src/native_image/image_source.rs | 41 -------------- .../image_source/image_source_ffi.rs | 54 +++++++++++++++++++ scripts/generator/src/main.rs | 9 ++-- 7 files changed, 137 insertions(+), 105 deletions(-) diff --git a/components/multimedia/image_framework/src/native_image/image.rs b/components/multimedia/image_framework/src/native_image/image.rs index b868968..80b08f5 100644 --- a/components/multimedia/image_framework/src/native_image/image.rs +++ b/components/multimedia/image_framework/src/native_image/image.rs @@ -7,24 +7,3 @@ extern "C" {} mod image_ffi; pub use image_ffi::*; - -#[cfg(feature = "pixelmap")] -#[cfg_attr(docsrs, doc(cfg(feature = "pixelmap")))] -extern "C" { - - /// @brief Get byte buffer from an {@link OH_ImageNative} object by the component type. - /// - /// @param image Indicates the pointer to an {@link OH_ImageNative} object. - /// @param componentType Indicates the type of component. - /// @param nativeBuffer Indicates the pointer to the component buffer obtained. - /// @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. - /// returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if bad parameter. - /// @since 12 - #[cfg(feature = "api-12")] - #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] - pub fn OH_ImageNative_GetByteBuffer( - image: *mut OH_ImageNative, - componentType: u32, - nativeBuffer: *mut *mut crate::native_image::pixelmap::OH_NativeBuffer, - ) -> crate::native_image::common::Image_ErrorCode; -} diff --git a/components/multimedia/image_framework/src/native_image/image/image_ffi.rs b/components/multimedia/image_framework/src/native_image/image/image_ffi.rs index d1a087a..be67397 100644 --- a/components/multimedia/image_framework/src/native_image/image/image_ffi.rs +++ b/components/multimedia/image_framework/src/native_image/image/image_ffi.rs @@ -4,6 +4,7 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] use crate::native_image::common::*; +use ohos_sys_opaque_types::OH_NativeBuffer; /// Defines an OH_ImageNative object. /// @@ -60,6 +61,29 @@ extern "C" { types: *mut *mut u32, typeSize: *mut usize, ) -> Image_ErrorCode; + /// Get byte buffer from an [`OH_ImageNative`] object by the component type. + /// + /// # Arguments + /// + /// `image` - Indicates the pointer to an [`OH_ImageNative`] object. + /// + /// `componentType` - Indicates the type of component. + /// + /// `nativeBuffer` - Indicates the pointer to the component buffer obtained. + /// + /// # Returns + /// + /// Returns [`Image_ErrorCode`] IMAGE_SUCCESS - if the operation is successful. + /// returns [`Image_ErrorCode`] IMAGE_BAD_PARAMETER - if bad parameter. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ImageNative_GetByteBuffer( + image: *mut OH_ImageNative, + componentType: u32, + nativeBuffer: *mut *mut OH_NativeBuffer, + ) -> Image_ErrorCode; /// Get size of buffer from an [`OH_ImageNative`] object by the component type. /// /// # Arguments diff --git a/components/multimedia/image_framework/src/native_image/image_packer.rs b/components/multimedia/image_framework/src/native_image/image_packer.rs index 528f5e3..7f93687 100644 --- a/components/multimedia/image_framework/src/native_image/image_packer.rs +++ b/components/multimedia/image_framework/src/native_image/image_packer.rs @@ -48,42 +48,3 @@ extern "C" { ) -> crate::native_image::common::Image_ErrorCode; } - -#[cfg(feature = "pixelmap")] -#[cfg_attr(docsrs, doc(cfg(feature = "pixelmap")))] -extern "C" { - /// @brief Encoding a Pixelmap into the data with required format. - /// - /// @param imagePacker The imagePacker to use for packing. - /// @param options Indicates the encoding {@link OH_PackingOptions}. - /// @param pixelmap The pixelmap to be packed. - /// @param outData The output data buffer to store the packed image. - /// @param size A pointer to the size of the output data buffer. - /// @return Returns {@link Image_ErrorCode} - /// @since 12 - #[cfg(feature = "api-12")] - #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] - pub fn OH_ImagePackerNative_PackToDataFromPixelmap( - imagePacker: *mut OH_ImagePackerNative, - options: *mut OH_PackingOptions, - pixelmap: *mut crate::native_image::pixelmap::OH_PixelmapNative, - outData: *mut u8, - size: *mut usize, - ) -> crate::native_image::common::Image_ErrorCode; - /// @brief Encoding a Pixelmap into the a file with fd with required format - /// - /// @param imagePacker The image packer to use for packing. - /// @param options Indicates the encoding {@link OH_PackingOptions}. - /// @param pixelmap The pixelmap to be packed. - /// @param fd Indicates a writable file descriptor. - /// @return Returns {@link Image_ErrorCode} - /// @since 12 - #[cfg(feature = "api-12")] - #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] - pub fn OH_ImagePackerNative_PackToFileFromPixelmap( - imagePacker: *mut OH_ImagePackerNative, - options: *mut OH_PackingOptions, - pixelmap: *mut crate::native_image::pixelmap::OH_PixelmapNative, - fd: i32, - ) -> crate::native_image::common::Image_ErrorCode; -} diff --git a/components/multimedia/image_framework/src/native_image/image_packer/image_packer_ffi.rs b/components/multimedia/image_framework/src/native_image/image_packer/image_packer_ffi.rs index ea55360..2a7b7a0 100644 --- a/components/multimedia/image_framework/src/native_image/image_packer/image_packer_ffi.rs +++ b/components/multimedia/image_framework/src/native_image/image_packer/image_packer_ffi.rs @@ -4,6 +4,7 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] use crate::native_image::common::*; +use ohos_sys_opaque_types::OH_PixelmapNative; /// Define a ImagePacker struct type, used for ImagePacker pointer controls. /// @@ -246,6 +247,59 @@ extern "C" { pub fn OH_ImagePackerNative_Create( imagePacker: *mut *mut OH_ImagePackerNative, ) -> Image_ErrorCode; + /// Encoding a Pixelmap into the data with required format. + /// + /// # Arguments + /// + /// `imagePacker` - The imagePacker to use for packing. + /// + /// `options` - Indicates the encoding [`OH_PackingOptions`]. + /// + /// `pixelmap` - The pixelmap to be packed. + /// + /// `outData` - The output data buffer to store the packed image. + /// + /// `size` - A pointer to the size of the output data buffer. + /// + /// # Returns + /// + /// Returns [`Image_ErrorCode`] + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ImagePackerNative_PackToDataFromPixelmap( + imagePacker: *mut OH_ImagePackerNative, + options: *mut OH_PackingOptions, + pixelmap: *mut OH_PixelmapNative, + outData: *mut u8, + size: *mut usize, + ) -> Image_ErrorCode; + /// Encoding a Pixelmap into the a file with fd with required format + /// + /// # Arguments + /// + /// `imagePacker` - The image packer to use for packing. + /// + /// `options` - Indicates the encoding [`OH_PackingOptions`]. + /// + /// `pixelmap` - The pixelmap to be packed. + /// + /// `fd` - Indicates a writable file descriptor. + /// + /// # Returns + /// + /// Returns [`Image_ErrorCode`] + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ImagePackerNative_PackToFileFromPixelmap( + imagePacker: *mut OH_ImagePackerNative, + options: *mut OH_PackingOptions, + pixelmap: *mut OH_PixelmapNative, + fd: i32, + ) -> Image_ErrorCode; /// Releases an imagePacker object. /// /// # Arguments diff --git a/components/multimedia/image_framework/src/native_image/image_source.rs b/components/multimedia/image_framework/src/native_image/image_source.rs index 1a177ab..53e695c 100644 --- a/components/multimedia/image_framework/src/native_image/image_source.rs +++ b/components/multimedia/image_framework/src/native_image/image_source.rs @@ -7,44 +7,3 @@ extern "C" {} mod image_source_ffi; pub use image_source_ffi::*; - -#[cfg(feature = "pixelmap")] -#[cfg_attr(docsrs, doc(cfg(feature = "pixelmap")))] -extern "C" { - /// @brief Decodes an void pointer - /// based on the specified {@link OH_DecodingOptions} struct. - /// - /// @param source Indicates a void pointer(from ImageSource pointer convert). - /// @param options Indicates a pointer to the options for decoding the image source. - /// For details, see {@link OH_DecodingOptions}. - /// @param resPixMap Indicates a void pointer to the Pixelmap object obtained at the C++ native layer. - /// @return Returns {@link Image_ErrorCode} - /// @since 12 - #[cfg(feature = "api-12")] - #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] - pub fn OH_ImageSourceNative_CreatePixelmap( - source: *mut OH_ImageSourceNative, - options: *mut OH_DecodingOptions, - pixelmap: *mut *mut crate::native_image::pixelmap::OH_PixelmapNative, - ) -> crate::native_image::common::Image_ErrorCode; - /// @brief Decodes an void pointer - /// the Pixelmap objects at the C++ native layer - /// based on the specified {@link OH_DecodingOptions} struct. - /// - /// @param source Indicates a void pointer(from ImageSource pointer convert). - /// @param options Indicates a pointer to the options for decoding the image source. - /// For details, see {@link OH_DecodingOptions}. - /// @param resVecPixMap Indicates a pointer array to the Pixelmap objects obtained at the C++ native layer. - /// It cannot be a null pointer. - /// @param size Indicates a size of resVecPixMap. User can get size from {@link OH_ImageSourceNative_GetFrameCount}. - /// @return Returns {@link Image_ErrorCode} - /// @since 12 - #[cfg(feature = "api-12")] - #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] - pub fn OH_ImageSourceNative_CreatePixelmapList( - source: *mut OH_ImageSourceNative, - options: *mut OH_DecodingOptions, - resVecPixMap: *mut *mut crate::native_image::common::Image_ErrorCode, - size: usize, - ) -> crate::native_image::common::Image_ErrorCode; -} diff --git a/components/multimedia/image_framework/src/native_image/image_source/image_source_ffi.rs b/components/multimedia/image_framework/src/native_image/image_source/image_source_ffi.rs index cf703c1..14fce62 100644 --- a/components/multimedia/image_framework/src/native_image/image_source/image_source_ffi.rs +++ b/components/multimedia/image_framework/src/native_image/image_source/image_source_ffi.rs @@ -4,6 +4,7 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] use crate::native_image::common::*; +use ohos_sys_opaque_types::OH_PixelmapNative; /// Defines an image source object for the image interface. /// @@ -469,6 +470,59 @@ extern "C" { dataSize: usize, res: *mut *mut OH_ImageSourceNative, ) -> Image_ErrorCode; + /// Decodes an void pointer + /// based on the specified [`OH_DecodingOptions`] struct. + /// + /// # Arguments + /// + /// `source` - Indicates a void pointer(from ImageSource pointer convert). + /// + /// `options` - Indicates a pointer to the options for decoding the image source. + /// For details, see [`OH_DecodingOptions`]. + /// + /// `resPixMap` - Indicates a void pointer to the Pixelmap object obtained at the C++ native layer. + /// + /// # Returns + /// + /// Returns [`Image_ErrorCode`] + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ImageSourceNative_CreatePixelmap( + source: *mut OH_ImageSourceNative, + options: *mut OH_DecodingOptions, + pixelmap: *mut *mut OH_PixelmapNative, + ) -> Image_ErrorCode; + /// Decodes an void pointer + /// the Pixelmap objects at the C++ native layer + /// based on the specified [`OH_DecodingOptions`] struct. + /// + /// # Arguments + /// + /// `source` - Indicates a void pointer(from ImageSource pointer convert). + /// + /// `options` - Indicates a pointer to the options for decoding the image source. + /// For details, see [`OH_DecodingOptions`]. + /// + /// `resVecPixMap` - Indicates a pointer array to the Pixelmap objects obtained at the C++ native layer. + /// It cannot be a null pointer. + /// + /// `size` - Indicates a size of resVecPixMap. User can get size from [`OH_ImageSourceNative_GetFrameCount`]. + /// + /// # Returns + /// + /// Returns [`Image_ErrorCode`] + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ImageSourceNative_CreatePixelmapList( + source: *mut OH_ImageSourceNative, + options: *mut OH_DecodingOptions, + resVecPixMap: *mut *mut OH_PixelmapNative, + size: usize, + ) -> Image_ErrorCode; /// Obtains the delay time list from some ImageSource objects (such as GIF image sources). /// /// # Arguments diff --git a/scripts/generator/src/main.rs b/scripts/generator/src/main.rs index 9a7483f..f1ad63c 100644 --- a/scripts/generator/src/main.rs +++ b/scripts/generator/src/main.rs @@ -510,8 +510,7 @@ fn get_module_bindings_config(api_version: u32) -> Vec { builder // FIXME: Add necessary feature guards for `rawfile` and remove the blocklist .blocklist_function("^OH_ImageSourceNative_CreateFromRawFile") - // Todo: This function is hand-picked - .blocklist_function("^OH_ImageSourceNative_CreatePixelmap(List)?") + .raw_line("use ohos_sys_opaque_types::OH_PixelmapNative;") } // Todo: these bindings are hand-picked and feature guarded right now - autogenerate... "image_receiver" => { @@ -520,10 +519,12 @@ fn get_module_bindings_config(api_version: u32) -> Vec { "image_packer" => { builder .blocklist_function("^OH_ImagePackerNative_PackTo(Data|File)FromImageSource") - .blocklist_function("^OH_ImagePackerNative_PackTo(Data|File)FromPixelmap") + .raw_line("use ohos_sys_opaque_types::OH_PixelmapNative;") } "image" => { - builder.blocklist_function("^OH_ImageNative_GetByteBuffer") + builder + .raw_line("use ohos_sys_opaque_types::OH_NativeBuffer;") + } _ => builder, };