Skip to content

Commit

Permalink
native_image: Autogenerate pixelmap functions
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Jan 5, 2025
1 parent 57084ed commit 74cb9e3
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 105 deletions.
21 changes: 0 additions & 21 deletions components/multimedia/image_framework/src/native_image/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>OH_ImageNative</b> object.
///
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>Pixelmap</b> 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 <b>Pixelmap</b> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -246,6 +247,59 @@ extern "C" {
pub fn OH_ImagePackerNative_Create(
imagePacker: *mut *mut OH_ImagePackerNative,
) -> Image_ErrorCode;
/// Encoding a <b>Pixelmap</b> 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 <b>Pixelmap</b> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>Pixelmap</b> 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 <b>Pixelmap</b> 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 <b>Pixelmap</b> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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 <b>Pixelmap</b> 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 <b>Pixelmap</b> 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 <b>Pixelmap</b> 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 <b>ImageSource</b> objects (such as GIF image sources).
///
/// # Arguments
Expand Down
9 changes: 5 additions & 4 deletions scripts/generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ fn get_module_bindings_config(api_version: u32) -> Vec<DirBindingsConf> {
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" => {
Expand All @@ -520,10 +519,12 @@ fn get_module_bindings_config(api_version: u32) -> Vec<DirBindingsConf> {
"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,
};
Expand Down

0 comments on commit 74cb9e3

Please sign in to comment.