From a69acf0acec74e2faee6384c1c927cdfe706f0a1 Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Mon, 24 Jan 2022 11:38:09 +0800 Subject: [PATCH 1/3] add image sdk Signed-off-by: zhang-xiaobo1997 --- api/@ohos.multimedia.image.d.ts | 543 ++++++++++++++++++++++++++++++++ 1 file changed, 543 insertions(+) create mode 100644 api/@ohos.multimedia.image.d.ts diff --git a/api/@ohos.multimedia.image.d.ts b/api/@ohos.multimedia.image.d.ts new file mode 100644 index 0000000000..5a42b65788 --- /dev/null +++ b/api/@ohos.multimedia.image.d.ts @@ -0,0 +1,543 @@ +/* +* Copyright (C) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { AsyncCallback } from './basic'; + +declare namespace image { + + /** + * Enumerates pixel map formats. + */ + enum PixelMapFormat { + /** + * Indicates an unknown pixel map format. + */ + UNKNOWN = 0, + + /** + * Indicates that each pixel is stored on 32 bits. Components A, R, G, and B each occupies 8 bits + * and are stored from the higher-order to the lower-order bits. + */ + ARGB_8888 = 1, + + /** + * Indicates that each pixel is stored on 16 bits. Only the R, G, and B components are encoded + * from the higher-order to the lower-order bits: red is stored with 5 bits of precision, + * green is stored with 6 bits of precision, and blue is stored with 5 bits of precision. + */ + RGB_565 = 2 + } + + /** + * Enumerates color spaces. + */ + enum ColorSpace { + /** + * Indicates an unknown color space. + */ + UNKNOWN = 0, + + /** + * Indicates the color space based on SMPTE RP 431-2-2007 and IEC 61966-2.1:1999. + */ + DISPLAY_P3 = 1, + + /** + * Indicates the standard red green blue (SRGB) color space based on IEC 61966-2.1:1999. + */ + SRGB = 2, + + /** + * Indicates the SRGB using a linear transfer function based on the IEC 61966-2.1:1999 standard. + */ + LINEAR_SRGB = 3, + + /** + * Indicates the color space based on IEC 61966-2-2:2003. + */ + EXTENDED_SRGB = 4, + + /** + * Indicates the color space based on IEC 61966-2-2:2003. + */ + LINEAR_EXTENDED_SRGB = 5, + + /** + * Indicates the color space based on the standard illuminant with D50 as the white point. + */ + GENERIC_XYZ = 6, + + /** + * Indicates the color space using CIE XYZ D50 as the profile conversion space. + */ + GENERIC_LAB = 7, + + /** + * Indicates the color space based on SMPTE ST 2065-1:2012. + */ + ACES = 8, + + /** + * Indicates the color space based on Academy S-2014-004. + */ + ACES_CG = 9, + + /** + * Indicates the color space based on Adobe RGB (1998). + */ + ADOBE_RGB_1998 = 10, + + /** + * Indicates the color space based on SMPTE RP 431-2-2007. + */ + DCI_P3 = 11, + + /** + * Indicates the color space based on Rec.ITU-R BT.709-5. + */ + ITU_709 = 12, + + /** + * Indicates the color space based on Rec.ITU-R BT.2020-1. + */ + ITU_2020 = 13, + + /** + * Indicates the color space based on ISO 22028-2:2013. + */ + ROMM_RGB = 14, + + /** + * Indicates the color space based on the NTSC 1953 standard. + */ + NTSC_1953 = 15, + + /** + * Indicates the color space based on SMPTE C. + */ + SMPTE_C = 16 + } + + /** + * Enumerates alpha types. + */ + enum AlphaType { + /** + * Indicates an unknown alpha type. + */ + UNKNOWN = 0, + + /** + * Indicates that the image has no alpha channel, or all pixels in the image are fully opaque. + */ + OPAQUE = 1, + + /** + * Indicates that RGB components of each pixel in the image are premultiplied by alpha. + */ + PREMUL = 2, + + /** + * Indicates that RGB components of each pixel in the image are independent of alpha and are not premultiplied by alpha. + */ + UNPREMUL = 3 + } + + /** + * Enum for image formats. + * @since 8 + */ + enum ImageFormat { + /** + * YCBCR422 semi-planar format. + * @since 8 + */ + YCBCR_422_SP = 1000, + + /** + * JPEG encoding format. + * @since 8 + */ + JPEG = 2000 + } + + enum ComponentType { + YUV_Y = 1, + YUV_U = 2, + YUV_V = 3, + JPEG = 4, + } + + /** + * Creates an ImageReceiver instance. + * @param width The default width in pixels of the Images that this receiver will produce. + * @param height The default height in pixels of the Images that this receiver will produce. + * @param format The format of the Image that this receiver will produce. This must be one of the + * {@link ImageFormat} constants. Note that not all formats are supported, like ImageFormat.NV21. + * @param capacity The maximum number of images the user will want to access simultaneously. + */ + function createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver; + + /** + * Describes image color components. + * @Since 8 + */ + interface Component { + /** + * Component type. + * @Since 8 + */ + readonly componentType: ComponentType; + /** + * Row stride. + * @Since 8 + */ + readonly rowStride: number; + /** + * Pixel stride. + * @Since 8 + */ + readonly pixelStride: number; + /** + * Component buffer. + * @Since 8 + */ + readonly byteBuffer: ArrayBuffer; + } + + /** + * Provides basic image operations, including obtaining image information, and reading and writing image data. + * @Since 8 + */ + interface Image { + /** + * Sets or gets the image area to crop, default is size. + * @since 8 + */ + clipRect: Region; + + /** + * Image size. + * @since 8 + */ + readonly size: number; + + /** + * Image format. + * @since 8 + */ + readonly format: number; + + /** + * Get component buffer from image. + * @since 8 + */ + getComponent(componentType: ComponentType, callback: AsyncCallback): void; + getComponent(componentType: ComponentType): Promise; + + /** + * Release current image to receive another. + * @since 8 + */ + release(callback: AsyncCallback): void; + release(): Promise; + } + + /** + * Image receiver object. + * @Since 8 + */ + interface ImageReceiver { + /** + * Image size. + * @Since 8 + */ + readonly size: Size; + + /** + * Image capacity. + * @Since 8 + */ + readonly capacity: number; + + /** + * Image format. + * @Since 8 + */ + readonly format: ImageFormat; + + /** + * get an id which indicates a surface and can be used to set to Camera or other component can receive a surface + * @Since 8 + */ + getReceivingSurfaceId(callback: AsyncCallback): void; + getReceivingSurfaceId(): Promise; + + /** + * Get lasted image from receiver + * @since 8 + */ + readLatestImage(callback: AsyncCallback): void; + readLatestImage(): Promise; + + /** + * Get next image from receiver + * @since 8 + */ + readNextImage(callback: AsyncCallback): void; + readNextImage(): Promise; + + /** + * Subscribe callback when receiving an image + * @since 8 + */ + on(type: 'imageArrival', callback: AsyncCallback): void; + + /** + * Release instance. + * @since 8 + */ + release(callback: AsyncCallback): void; + release(): Promise; + } + + /** + * Describes the size of an image. + */ + interface Size { + height: number; + width: number; + } + + interface Region { + size: Size; + x: number; + y: number; + } + + interface PositionArea { + pixels: ArrayBuffer; + offset: number; + stride: number; + region: Region; + } + + /** + * Describes image information. + */ + interface ImageInfo { + size: Size; + pixelFormat: PixelMapFormat; + colorSpace: ColorSpace; + alphaType: AlphaType; + } + + /** + * Describes the option for image packing. + */ + interface PackingOption { + /** + * Multipurpose Internet Mail Extensions (MIME) format of the target image, for example, image/jpeg. + */ + format: string; + + /** + * Quality of the target image. The value is an integer ranging from 0 to 100. A larger value indicates better + */ + quality: number; + } + + interface DecodingOptions { + // Indicates the sampling size based on which an image is scaled down. + sampleSize: number; + + // Indicates the rotation angle, ranging from 0 to 360 + rotateDegrees: number; + + // Specifies whether pixel values of the pixel map to be decoded can be edited. + editable: boolean; + + // Indicates the expected output size + desiredSize: Size; + + // Indicates an image area to be decoded. + desiredRegion: Region; + + // Indicates the pixel format of a decoded image, which is defined by PixelFormat. + desiredPixelFormat: PixelMapFormat; + + // reused current pixelmap buffer address for a new created pixelmap + reusedPixelMap: PixelMap; + } + + enum ScaleMode { + CENTER_CROP = 1, // Indicates the effect that scales an image to fill the target image area and center-crops the part outside the area. + FIT_TARGET_SIZE = 2, // Indicates the effect that fits the image into the target size. + } + + interface InitializationOptions { + // Indicates the expected alpha type of the pixel map to be created + alphaType: AlphaType; + + // Specifies whether pixel values of the pixel map to be created can be edited + editable: boolean; + + // Indicates the expected format of the pixel map to be created + pixelFormat: PixelMapFormat; + + // Indicates the scaling effect used when the aspect ratio of the original image is different from that of the target image + scaleMode: ScaleMode; + + // Indicates the expected size of the pixel map to be created + size: Size; + } + + /** + * Creates an ImageSource instance. + */ + function createImageSource(uri: string): ImageSource; + + // create a imagesource based on fd + function createImageSource(fd: number): ImageSource; + + // Creates an ImageSource based on a ArrayBuffer and source options. + function createImageSource(data: ArrayBuffer): ImageSource; + + // Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) + // and the data source described by a pixel color array, start offset, and number of pixels in a row. + function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions): Promise; + function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions, callback: AsyncCallback): void; + + + function createIncrementalSource(data: ArrayBuffer): ImageSource; + + /** + * Creates an ImagePacker instance. + */ + function createImagePacker(): ImagePacker; + + interface PixelMap { + // read all pixels to an buffer + readPixelsToBuffer(dst: ArrayBuffer): Promise; + readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback): void; + + // read pixels from a specified area into an buffer + readPixels(area: PositionArea): Promise>; + readPixels(area: PositionArea, callback: AsyncCallback>): void; + + // write pixels to a specified area + writePixels(area: PositionArea): Promise; + writePixels(area: PositionArea, callback: AsyncCallback): void; + + // write array buffer to pixelmap + writeBufferToPixels(src: ArrayBuffer): Promise; + writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback): void; + + // obtains basic image information. + getImageInfo(): Promise; + getImageInfo(callback: AsyncCallback): void; + + // get bytes number per row. + getBytesNumberPerRow(): Promise; + getBytesNumberPerRow(callback: AsyncCallback): void; + + // get bytes buffer for a pixelmap. + getPixelBytesNumber(): Promise; + getPixelBytesNumber(callback: AsyncCallback): void; + + // release pixelmap + release(): void; + + readonly isEditable: boolean; + } + + interface ImageSource { + /** + * Obtains information about an image with the specified sequence number and uses a callback to return the result. + */ + getImageInfo(index: number, callback: AsyncCallback): void; + + /** + * Obtains information about this image and uses a callback to return the result. + */ + getImageInfo(callback: AsyncCallback): void; + + /** + * Get image information from image source. + */ + getImageInfo(index?: number): Promise; + + // Obtains the integer value of a specified property key for an image at the given index in the ImageSource. + getImagePropertyInt(index:number, key: string, defaultValue: number): Promise; + getImagePropertyInt(index:number, key: string, defaultValue: number, callback: AsyncCallback): void; + + // Obtains the string value of a specified image property key. + getImagePropertyString(key: string): Promise; + getImagePropertyString(key: string, callback: AsyncCallback): void; + + // Decodes source image data based on a specified index location in the ImageSource and creates a pixel map. + createPixelMap(index: number, options: DecodingOptions, callback: AsyncCallback): void; + createPixelMap(opts: DecodingOptions, callback: AsyncCallback): void; + + // Updates incremental data to an image data source using a byte array with specified offset and length. + updateData(data: Array, isFinal: boolean, offset?: number, length?: number): Promise; + updateData(data: Array, isFinal: boolean, offset: number, length: number, callback: AsyncCallback): void; + updateData(data: Array, isFinal: boolean, callback: AsyncCallback): void; + + /** + * Releases an ImageSource instance and uses a callback to return the result. + */ + release(callback: AsyncCallback): void; + + /** + * Releases an ImageSource instance and uses a promise to return the result. + */ + release(): Promise; + + /** + * Supported image formats. + */ + readonly supportedFormats: Array; + } + + interface ImagePacker { + /** + * Compresses or packs an image and uses a callback to return the result. + */ + packing(source: ImageSource, option: PackingOption, callback: AsyncCallback>): void; + + /** + * Compresses or packs an image and uses a promise to return the result. + */ + packing(source: ImageSource, option: PackingOption): Promise>; + + /** + * Releases an ImagePacker instance and uses a callback to return the result. + */ + release(callback: AsyncCallback): void; + + /** + * Releases an ImagePacker instance and uses a promise to return the result. + */ + release(): Promise; + + /** + * Supported image formats. + */ + readonly supportedFormats: Array; + } +} + +export default image; \ No newline at end of file -- Gitee From 8bb1cc456f586edd0f000244f78a7cce9f23edaa Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Mon, 24 Jan 2022 15:57:32 +0800 Subject: [PATCH 2/3] Add interface to sdk Signed-off-by: zhang-xiaobo1997 --- api/@ohos.multimedia.image.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/@ohos.multimedia.image.d.ts b/api/@ohos.multimedia.image.d.ts index 5a42b65788..0584d7bd81 100644 --- a/api/@ohos.multimedia.image.d.ts +++ b/api/@ohos.multimedia.image.d.ts @@ -420,7 +420,7 @@ declare namespace image { function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions): Promise; function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions, callback: AsyncCallback): void; - + // Create a incremental image source. function createIncrementalSource(data: ArrayBuffer): ImageSource; /** -- Gitee From 3d5fff32c220c714af2c65473efa27042fedf839 Mon Sep 17 00:00:00 2001 From: zhang-xiaobo1997 Date: Thu, 27 Jan 2022 09:33:53 +0800 Subject: [PATCH 3/3] Add image dts 7.0 Signed-off-by: zhang-xiaobo1997 --- api/@ohos.multimedia.image.d.ts | 776 +++++++++++++++++++------------- 1 file changed, 465 insertions(+), 311 deletions(-) diff --git a/api/@ohos.multimedia.image.d.ts b/api/@ohos.multimedia.image.d.ts index 0584d7bd81..a18e101c59 100644 --- a/api/@ohos.multimedia.image.d.ts +++ b/api/@ohos.multimedia.image.d.ts @@ -15,499 +15,625 @@ import { AsyncCallback } from './basic'; +/** + * @name image + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @import import image from '@ohos.multimedia.image'; + * @devices phone, tablet, tv, wearable, car + */ declare namespace image { /** * Enumerates pixel map formats. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @import import image from '@ohos.multimedia.image' + * @devices phone, tablet, tv, wearable, car */ enum PixelMapFormat { /** - * Indicates an unknown pixel map format. + * Indicates an unknown format. */ UNKNOWN = 0, - /** - * Indicates that each pixel is stored on 32 bits. Components A, R, G, and B each occupies 8 bits - * and are stored from the higher-order to the lower-order bits. - */ - ARGB_8888 = 1, - /** * Indicates that each pixel is stored on 16 bits. Only the R, G, and B components are encoded * from the higher-order to the lower-order bits: red is stored with 5 bits of precision, * green is stored with 6 bits of precision, and blue is stored with 5 bits of precision. */ - RGB_565 = 2 + RGB_565 = 2, + + /** + * Indicates that each pixel is stored on 32 bits. Components R, G, B, and A each occupies 8 bits + * and are stored from the higher-order to the lower-order bits. + */ + RGBA_8888 = 3, } /** - * Enumerates color spaces. + * Describes the size of an image. */ - enum ColorSpace { + interface Size { /** - * Indicates an unknown color space. + * Height + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - UNKNOWN = 0, + height: number; /** - * Indicates the color space based on SMPTE RP 431-2-2007 and IEC 61966-2.1:1999. + * Width + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - DISPLAY_P3 = 1, + width: number; + } + /** + * Enumerates exchangeable image file format (Exif) information types of an image. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @import import image from '@ohos.multimedia.image' + * @devices phone, tablet, tv, wearable, car + */ + enum PropertyKey { /** - * Indicates the standard red green blue (SRGB) color space based on IEC 61966-2.1:1999. + * Number of bits in each pixel of an image. */ - SRGB = 2, + BITS_PER_SAMPLE = "BitsPerSample", /** - * Indicates the SRGB using a linear transfer function based on the IEC 61966-2.1:1999 standard. + * Image rotation mode. */ - LINEAR_SRGB = 3, + ORIENTATION = "Orientation", /** - * Indicates the color space based on IEC 61966-2-2:2003. + * Image length. */ - EXTENDED_SRGB = 4, + IMAGE_LENGTH = "ImageLength", /** - * Indicates the color space based on IEC 61966-2-2:2003. + * Image width. */ - LINEAR_EXTENDED_SRGB = 5, + IMAGE_WIDTH = "ImageWidth", /** - * Indicates the color space based on the standard illuminant with D50 as the white point. + * GPS latitude. */ - GENERIC_XYZ = 6, + GPS_LATITUDE = "GPSLatitude", /** - * Indicates the color space using CIE XYZ D50 as the profile conversion space. + * GPS longitude. */ - GENERIC_LAB = 7, + GPS_LONGITUDE = "GPSLongitude", /** - * Indicates the color space based on SMPTE ST 2065-1:2012. + * GPS latitude reference. For example, N indicates north latitude and S indicates south latitude. */ - ACES = 8, + GPS_LATITUDE_REF = "GPSLatitudeRef", /** - * Indicates the color space based on Academy S-2014-004. + * GPS longitude reference. For example, E indicates east longitude and W indicates west longitude. */ - ACES_CG = 9, + GPS_LONGITUDE_REF = "GPSLongitudeRef" + } + /** + * Describes region information. + */ + interface Region { /** - * Indicates the color space based on Adobe RGB (1998). + * Image size. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - ADOBE_RGB_1998 = 10, + size: Size; /** - * Indicates the color space based on SMPTE RP 431-2-2007. + * x-coordinate at the upper left corner of the image. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - DCI_P3 = 11, + x: number; /** - * Indicates the color space based on Rec.ITU-R BT.709-5. + * y-coordinate at the upper left corner of the image. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - ITU_709 = 12, + y: number; + } + /** + * Describes area information in an image. + */ + interface PositionArea { /** - * Indicates the color space based on Rec.ITU-R BT.2020-1. + * Image data that will be read or written. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - ITU_2020 = 13, + pixels: ArrayBuffer; /** - * Indicates the color space based on ISO 22028-2:2013. + * Offset for data reading. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - ROMM_RGB = 14, + offset: number; /** - * Indicates the color space based on the NTSC 1953 standard. + * Number of bytes to read. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - NTSC_1953 = 15, + stride: number; /** - * Indicates the color space based on SMPTE C. + * Region to read. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - SMPTE_C = 16 + region: Region; } /** - * Enumerates alpha types. + * Describes image information. */ - enum AlphaType { - /** - * Indicates an unknown alpha type. - */ - UNKNOWN = 0, - + interface ImageInfo { /** - * Indicates that the image has no alpha channel, or all pixels in the image are fully opaque. + * Indicates image dimensions specified by a {@link Size} interface. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - OPAQUE = 1, + size: Size; + } + /** + * Describes the option for image packing. + */ + interface PackingOption { /** - * Indicates that RGB components of each pixel in the image are premultiplied by alpha. + * Multipurpose Internet Mail Extensions (MIME) format of the target image, for example, image/jpeg. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - PREMUL = 2, + format: string; /** - * Indicates that RGB components of each pixel in the image are independent of alpha and are not premultiplied by alpha. + * Quality of the target image. The value is an integer ranging from 0 to 100. A larger value indicates better + * image quality but larger space occupied. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - UNPREMUL = 3 + quality: number; } - + /** - * Enum for image formats. - * @since 8 + * Describes image properties. */ - enum ImageFormat { + interface GetImagePropertyOptions { /** - * YCBCR422 semi-planar format. - * @since 8 + * Index of an image. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - YCBCR_422_SP = 1000, + index?: number; /** - * JPEG encoding format. - * @since 8 + * Default property value. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - JPEG = 2000 + defaultValue?: string; } - enum ComponentType { - YUV_Y = 1, - YUV_U = 2, - YUV_V = 3, - JPEG = 4, - } - - /** - * Creates an ImageReceiver instance. - * @param width The default width in pixels of the Images that this receiver will produce. - * @param height The default height in pixels of the Images that this receiver will produce. - * @param format The format of the Image that this receiver will produce. This must be one of the - * {@link ImageFormat} constants. Note that not all formats are supported, like ImageFormat.NV21. - * @param capacity The maximum number of images the user will want to access simultaneously. - */ - function createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver; - /** - * Describes image color components. - * @Since 8 + * Describes image decoding parameters. */ - interface Component { - /** - * Component type. - * @Since 8 - */ - readonly componentType: ComponentType; - /** - * Row stride. - * @Since 8 - */ - readonly rowStride: number; + interface DecodingOptions { /** - * Pixel stride. - * @Since 8 + * Number of image frames. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - readonly pixelStride: number; + index?: number; + /** - * Component buffer. - * @Since 8 + * Sampling ratio of the image pixel map. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - readonly byteBuffer: ArrayBuffer; - } + sampleSize?: number; - /** - * Provides basic image operations, including obtaining image information, and reading and writing image data. - * @Since 8 - */ - interface Image { /** - * Sets or gets the image area to crop, default is size. - * @since 8 + * Rotation angle of the image pixel map. The value ranges from 0 to 360. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - clipRect: Region; + rotate?: number; /** - * Image size. - * @since 8 + * Whether the image pixel map is editable. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - readonly size: number; + editable?: boolean; /** - * Image format. - * @since 8 + * Width and height of the image pixel map. The value (0, 0) indicates that the pixels are decoded + * based on the original image size. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - readonly format: number; + desiredSize?: Size; /** - * Get component buffer from image. - * @since 8 + * Cropping region of the image pixel map. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - getComponent(componentType: ComponentType, callback: AsyncCallback): void; - getComponent(componentType: ComponentType): Promise; + desiredRegion?: Region; /** - * Release current image to receive another. - * @since 8 + * Data format of the image pixel map. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car */ - release(callback: AsyncCallback): void; - release(): Promise; + desiredPixelFormat?: PixelMapFormat; } /** - * Image receiver object. - * @Since 8 + * Creates an ImageSource instance based on the URI. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param uri Image source URI. + * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. */ - interface ImageReceiver { - /** - * Image size. - * @Since 8 - */ - readonly size: Size; + function createImageSource(uri: string): ImageSource; + + /** + * Creates an ImageSource instance based on the file descriptor. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param fd ID of a file descriptor. + * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. + */ + function createImageSource(fd: number): ImageSource; + /** + * Creates an ImagePacker instance. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return Returns the ImagePacker instance if the operation is successful; returns null otherwise. + */ + function createImagePacker(): ImagePacker; + + interface PixelMap { /** - * Image capacity. - * @Since 8 + * Whether the image pixel map can be edited. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' */ - readonly capacity: number; + readonly isEditable: boolean; /** - * Image format. - * @Since 8 + * Reads image pixel map data and writes the data to an ArrayBuffer. This method uses + * a promise to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param dst A buffer to which the image pixel map data will be written. + * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. */ - readonly format: ImageFormat; + readPixelsToBuffer(dst: ArrayBuffer): Promise; /** - * get an id which indicates a surface and can be used to set to Camera or other component can receive a surface - * @Since 8 + * Reads image pixel map data and writes the data to an ArrayBuffer. This method uses + * a callback to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param dst A buffer to which the image pixel map data will be written. + * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. */ - getReceivingSurfaceId(callback: AsyncCallback): void; - getReceivingSurfaceId(): Promise; + readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback): void; /** - * Get lasted image from receiver - * @since 8 + * Reads image pixel map data in an area. This method uses a promise to return the data read. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param area Area from which the image pixel map data will be read. + * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. */ - readLatestImage(callback: AsyncCallback): void; - readLatestImage(): Promise; + readPixels(area: PositionArea): Promise; /** - * Get next image from receiver - * @since 8 + * Reads image pixel map data in an area. This method uses a callback to return the data read. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param area Area from which the image pixel map data will be read. + * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. */ - readNextImage(callback: AsyncCallback): void; - readNextImage(): Promise; + readPixels(area: PositionArea, callback: AsyncCallback): void; /** - * Subscribe callback when receiving an image - * @since 8 + * Writes image pixel map data to the specified area. This method uses a promise to return + * the operation result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param area Area to which the image pixel map data will be written. + * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. */ - on(type: 'imageArrival', callback: AsyncCallback): void; + writePixels(area: PositionArea): Promise; /** - * Release instance. - * @since 8 + * Writes image pixel map data to the specified area. This method uses a callback to return + * the operation result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param area Area to which the image pixel map data will be written. + * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. */ - release(callback: AsyncCallback): void; - release(): Promise; - } - - /** - * Describes the size of an image. - */ - interface Size { - height: number; - width: number; - } - - interface Region { - size: Size; - x: number; - y: number; - } - - interface PositionArea { - pixels: ArrayBuffer; - offset: number; - stride: number; - region: Region; - } - - /** - * Describes image information. - */ - interface ImageInfo { - size: Size; - pixelFormat: PixelMapFormat; - colorSpace: ColorSpace; - alphaType: AlphaType; - } + writePixels(area: PositionArea, callback: AsyncCallback): void; - /** - * Describes the option for image packing. - */ - interface PackingOption { /** - * Multipurpose Internet Mail Extensions (MIME) format of the target image, for example, image/jpeg. + * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. This method + * uses a promise to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param src A buffer from which the image data will be read. + * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. */ - format: string; + writeBufferToPixels(src: ArrayBuffer): Promise; /** - * Quality of the target image. The value is an integer ranging from 0 to 100. A larger value indicates better + * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. This method + * uses a callback to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param src A buffer from which the image data will be read. + * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. */ - quality: number; - } - - interface DecodingOptions { - // Indicates the sampling size based on which an image is scaled down. - sampleSize: number; - - // Indicates the rotation angle, ranging from 0 to 360 - rotateDegrees: number; - - // Specifies whether pixel values of the pixel map to be decoded can be edited. - editable: boolean; - - // Indicates the expected output size - desiredSize: Size; - - // Indicates an image area to be decoded. - desiredRegion: Region; - - // Indicates the pixel format of a decoded image, which is defined by PixelFormat. - desiredPixelFormat: PixelMapFormat; - - // reused current pixelmap buffer address for a new created pixelmap - reusedPixelMap: PixelMap; - } - - enum ScaleMode { - CENTER_CROP = 1, // Indicates the effect that scales an image to fill the target image area and center-crops the part outside the area. - FIT_TARGET_SIZE = 2, // Indicates the effect that fits the image into the target size. - } - - interface InitializationOptions { - // Indicates the expected alpha type of the pixel map to be created - alphaType: AlphaType; - - // Specifies whether pixel values of the pixel map to be created can be edited - editable: boolean; - - // Indicates the expected format of the pixel map to be created - pixelFormat: PixelMapFormat; - - // Indicates the scaling effect used when the aspect ratio of the original image is different from that of the target image - scaleMode: ScaleMode; - - // Indicates the expected size of the pixel map to be created - size: Size; - } - - /** - * Creates an ImageSource instance. - */ - function createImageSource(uri: string): ImageSource; - - // create a imagesource based on fd - function createImageSource(fd: number): ImageSource; - - // Creates an ImageSource based on a ArrayBuffer and source options. - function createImageSource(data: ArrayBuffer): ImageSource; - - // Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) - // and the data source described by a pixel color array, start offset, and number of pixels in a row. - function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions): Promise; - function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions, callback: AsyncCallback): void; - - // Create a incremental image source. - function createIncrementalSource(data: ArrayBuffer): ImageSource; - - /** - * Creates an ImagePacker instance. - */ - function createImagePacker(): ImagePacker; - - interface PixelMap { - // read all pixels to an buffer - readPixelsToBuffer(dst: ArrayBuffer): Promise; - readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback): void; - - // read pixels from a specified area into an buffer - readPixels(area: PositionArea): Promise>; - readPixels(area: PositionArea, callback: AsyncCallback>): void; - - // write pixels to a specified area - writePixels(area: PositionArea): Promise; - writePixels(area: PositionArea, callback: AsyncCallback): void; - - // write array buffer to pixelmap - writeBufferToPixels(src: ArrayBuffer): Promise; writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback): void; - // obtains basic image information. + /** + * Obtains pixel map information about this image. This method uses a promise to return the information. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return A Promise instance used to return the image pixel map information. If the operation fails, an error message is returned. + */ getImageInfo(): Promise; + + /** + * Obtains pixel map information about this image. This method uses a callback to return the information. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback used to return the image pixel map information. If the operation fails, an error message is returned. + */ getImageInfo(callback: AsyncCallback): void; - // get bytes number per row. - getBytesNumberPerRow(): Promise; - getBytesNumberPerRow(callback: AsyncCallback): void; + /** + * Obtains the number of bytes in each line of the image pixel map. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return Number of bytes in each line. + */ + getBytesNumberPerRow(): number; - // get bytes buffer for a pixelmap. - getPixelBytesNumber(): Promise; - getPixelBytesNumber(callback: AsyncCallback): void; + /** + * Obtains the total number of bytes of the image pixel map. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return Total number of bytes. + */ + getPixelBytesNumber(): number; - // release pixelmap - release(): void; + /** + * Releases this PixelMap object. This method uses a callback to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback invoked for instance release. If the operation fails, an error message is returned. + */ + release(callback: AsyncCallback): void; - readonly isEditable: boolean; + /** + * Releases this PixelMap object. This method uses a promise to return the result. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return A Promise instance used to return the instance release result. If the operation fails, an error message is returned. + */ + release(): Promise; } interface ImageSource { /** - * Obtains information about an image with the specified sequence number and uses a callback to return the result. + * Obtains information about an image with the specified sequence number and uses a callback + * to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param index Sequence number of an image. + * @param callback Callback used to return the image information. */ getImageInfo(index: number, callback: AsyncCallback): void; /** * Obtains information about this image and uses a callback to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback used to return the image information. */ getImageInfo(callback: AsyncCallback): void; /** * Get image information from image source. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param index Sequence number of an image. If this parameter is not specified, the default value 0 is used. + * @return A Promise instance used to return the image information. */ getImageInfo(index?: number): Promise; - // Obtains the integer value of a specified property key for an image at the given index in the ImageSource. - getImagePropertyInt(index:number, key: string, defaultValue: number): Promise; - getImagePropertyInt(index:number, key: string, defaultValue: number, callback: AsyncCallback): void; + /** + * Creates a PixelMap object based on image decoding parameters. This method uses a promise to + * return the object. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param options Image decoding parameters. + * @return A Promise instance used to return the PixelMap object. + */ + createPixelMap(options?: DecodingOptions): Promise; + + /** + * Creates a PixelMap object. This method uses a callback to return the object. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback used to return the PixelMap object. + */ + createPixelMap(callback: AsyncCallback): void; - // Obtains the string value of a specified image property key. - getImagePropertyString(key: string): Promise; - getImagePropertyString(key: string, callback: AsyncCallback): void; + /** + * Creates a PixelMap object based on image decoding parameters. This method uses a callback to + * return the object. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param options Image decoding parameters. + * @param callback Callback used to return the PixelMap object. + */ + createPixelMap(options: DecodingOptions, callback: AsyncCallback): void; - // Decodes source image data based on a specified index location in the ImageSource and creates a pixel map. - createPixelMap(index: number, options: DecodingOptions, callback: AsyncCallback): void; - createPixelMap(opts: DecodingOptions, callback: AsyncCallback): void; + /** + * Obtains the value of a property in an image with the specified index. This method uses a + * promise to return the property value in a string. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param key Name of the property whose value is to be obtained. + * @param options Index of the image. + * @return A Promise instance used to return the property value. If the operation fails, the default value is returned. + */ + getImageProperty(key:string, options?: GetImagePropertyOptions): Promise; - // Updates incremental data to an image data source using a byte array with specified offset and length. - updateData(data: Array, isFinal: boolean, offset?: number, length?: number): Promise; - updateData(data: Array, isFinal: boolean, offset: number, length: number, callback: AsyncCallback): void; - updateData(data: Array, isFinal: boolean, callback: AsyncCallback): void; + /** + * Obtains the value of a property in this image. This method uses a callback to return the + * property value in a string. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param key Name of the property whose value is to be obtained. + * @param callback Callback used to return the property value. If the operation fails, an error message is returned. + */ + getImageProperty(key:string, callback: AsyncCallback): void; + + /** + * Obtains the value of a property in an image with the specified index. This method uses + * a callback to return the property value in a string. + * @since 7 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param key Name of the property whose value is to be obtained. + * @param options Index of the image. + * @param callback Callback used to return the property value. If the operation fails, the default value is returned. + */ + getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback): void; /** * Releases an ImageSource instance and uses a callback to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback to return the operation result. */ release(callback: AsyncCallback): void; /** * Releases an ImageSource instance and uses a promise to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return A Promise instance used to return the operation result. */ release(): Promise; /** * Supported image formats. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' */ readonly supportedFormats: Array; } @@ -515,26 +641,54 @@ declare namespace image { interface ImagePacker { /** * Compresses or packs an image and uses a callback to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param source Image to be processed. + * @param option Option for image packing. + * @param callback Callback used to return the packed data. */ - packing(source: ImageSource, option: PackingOption, callback: AsyncCallback>): void; + packing(source: ImageSource, option: PackingOption, callback: AsyncCallback): void; /** * Compresses or packs an image and uses a promise to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param source Image to be processed. + * @param option Option for image packing. + * @return A Promise instance used to return the compressed or packed data. */ - packing(source: ImageSource, option: PackingOption): Promise>; + packing(source: ImageSource, option: PackingOption): Promise; /** * Releases an ImagePacker instance and uses a callback to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @param callback Callback to return the operation result. */ release(callback: AsyncCallback): void; /** * Releases an ImagePacker instance and uses a promise to return the result. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' + * @return A Promise instance used to return the operation result. */ release(): Promise; /** * Supported image formats. + * @since 6 + * @SysCap SystemCapability.Multimedia.Image + * @devices phone, tablet, tv, wearable, car + * @import import image from '@ohos.multimedia.image' */ readonly supportedFormats: Array; } -- Gitee