• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type colorSpaceManager from '@ohos.graphics.colorSpaceManager';
17
18export namespace image {
19
20  loadLibrary("image_ani_core");
21
22  enum DecodingDynamicRange {
23    AUTO = 0,
24    SDR = 1,
25    HDR = 2
26  }
27
28  enum PropertyKeyAni {
29    BITS_PER_SAMPLE = 'BitsPerSample',
30    ORIENTATION = 'Orientation',
31    IMAGE_LENGTH = 'ImageLength',
32    IMAGE_WIDTH = 'ImageWidth',
33    GPS_LATITUDE = 'GPSLatitude',
34    GPS_LONGITUDE = 'GPSLongitude',
35    GPS_LATITUDE_REF = 'GPSLatitudeRef',
36    GPS_LONGITUDE_REF = 'GPSLongitudeRef',
37    DATE_TIME_ORIGINAL = 'DateTimeOriginal',
38    EXPOSURE_TIME = 'ExposureTime',
39    SCENE_TYPE = 'SceneType',
40    ISO_SPEED_RATINGS = 'ISOSpeedRatings',
41    F_NUMBER = 'FNumber',
42    DATE_TIME = 'DateTime',
43    GPS_TIME_STAMP = 'GPSTimeStamp',
44    GPS_DATE_STAMP = 'GPSDateStamp',
45    IMAGE_DESCRIPTION = 'ImageDescription',
46    MAKE = 'Make',
47    MODEL = 'Model',
48    PHOTO_MODE = 'PhotoMode',
49    SENSITIVITY_TYPE = 'SensitivityType',
50    STANDARD_OUTPUT_SENSITIVITY = 'StandardOutputSensitivity',
51    RECOMMENDED_EXPOSURE_INDEX = 'RecommendedExposureIndex',
52    ISO_SPEED = 'ISOSpeedRatings',
53    APERTURE_VALUE = 'ApertureValue',
54    EXPOSURE_BIAS_VALUE = 'ExposureBiasValue',
55    METERING_MODE = 'MeteringMode',
56    LIGHT_SOURCE = 'LightSource',
57    FLASH = 'Flash',
58    FOCAL_LENGTH = 'FocalLength',
59    USER_COMMENT = 'UserComment',
60    PIXEL_X_DIMENSION = 'PixelXDimension',
61    PIXEL_Y_DIMENSION = 'PixelYDimension',
62    WHITE_BALANCE = 'WhiteBalance',
63    FOCAL_LENGTH_IN_35_MM_FILM = 'FocalLengthIn35mmFilm',
64    CAPTURE_MODE = 'HwMnoteCaptureMode',
65    PHYSICAL_APERTURE = 'HwMnotePhysicalAperture',
66    ROLL_ANGLE = 'HwMnoteRollAngle',
67    PITCH_ANGLE = 'HwMnotePitchAngle',
68    SCENE_FOOD_CONF = 'HwMnoteSceneFoodConf',
69    SCENE_STAGE_CONF = 'HwMnoteSceneStageConf',
70    SCENE_BLUE_SKY_CONF = 'HwMnoteSceneBlueSkyConf',
71    SCENE_GREEN_PLANT_CONF = 'HwMnoteSceneGreenPlantConf',
72    SCENE_BEACH_CONF = 'HwMnoteSceneBeachConf',
73    SCENE_SNOW_CONF = 'HwMnoteSceneSnowConf',
74    SCENE_SUNSET_CONF = 'HwMnoteSceneSunsetConf',
75    SCENE_FLOWERS_CONF = 'HwMnoteSceneFlowersConf',
76    SCENE_NIGHT_CONF = 'HwMnoteSceneNightConf',
77    SCENE_TEXT_CONF = 'HwMnoteSceneTextConf',
78    FACE_COUNT = 'HwMnoteFaceCount',
79    FOCUS_MODE = 'HwMnoteFocusMode',
80    COMPRESSION = 'Compression',
81    PHOTOMETRIC_INTERPRETATION = 'PhotometricInterpretation',
82    STRIP_OFFSETS = 'StripOffsets',
83    SAMPLES_PER_PIXEL = 'SamplesPerPixel',
84    ROWS_PER_STRIP = 'RowsPerStrip',
85    STRIP_BYTE_COUNTS = 'StripByteCounts',
86    X_RESOLUTION = 'XResolution',
87    Y_RESOLUTION = 'YResolution',
88    PLANAR_CONFIGURATION = 'PlanarConfiguration',
89    RESOLUTION_UNIT = 'ResolutionUnit',
90    TRANSFER_FUNCTION = 'TransferFunction',
91    SOFTWARE = 'Software',
92    ARTIST = 'Artist',
93    WHITE_POINT = 'WhitePoint',
94    PRIMARY_CHROMATICITIES = 'PrimaryChromaticities',
95    YCBCR_COEFFICIENTS = 'YCbCrCoefficients',
96    YCBCR_SUB_SAMPLING = 'YCbCrSubSampling',
97    YCBCR_POSITIONING = 'YCbCrPositioning',
98    REFERENCE_BLACK_WHITE = 'ReferenceBlackWhite',
99    COPYRIGHT = 'Copyright',
100    JPEG_INTERCHANGE_FORMAT = 'JPEGInterchangeFormat',
101    JPEG_INTERCHANGE_FORMAT_LENGTH = 'JPEGInterchangeFormatLength',
102    EXPOSURE_PROGRAM = 'ExposureProgram',
103    SPECTRAL_SENSITIVITY = 'SpectralSensitivity',
104    OECF = 'OECF',
105    EXIF_VERSION = 'ExifVersion',
106    DATE_TIME_DIGITIZED = 'DateTimeDigitized',
107    COMPONENTS_CONFIGURATION = 'ComponentsConfiguration',
108    SHUTTER_SPEED = 'ShutterSpeedValue',
109    BRIGHTNESS_VALUE = 'BrightnessValue',
110    MAX_APERTURE_VALUE = 'MaxApertureValue',
111    SUBJECT_DISTANCE = 'SubjectDistance',
112    SUBJECT_AREA = 'SubjectArea',
113    MAKER_NOTE = 'MakerNote',
114    SUBSEC_TIME = 'SubsecTime',
115    SUBSEC_TIME_ORIGINAL = 'SubsecTimeOriginal',
116    SUBSEC_TIME_DIGITIZED = 'SubsecTimeDigitized',
117    FLASHPIX_VERSION = 'FlashpixVersion',
118    COLOR_SPACE = 'ColorSpace',
119    RELATED_SOUND_FILE = 'RelatedSoundFile',
120    FLASH_ENERGY = 'FlashEnergy',
121    SPATIAL_FREQUENCY_RESPONSE = 'SpatialFrequencyResponse',
122    FOCAL_PLANE_X_RESOLUTION = 'FocalPlaneXResolution',
123    FOCAL_PLANE_Y_RESOLUTION = 'FocalPlaneYResolution',
124    FOCAL_PLANE_RESOLUTION_UNIT = 'FocalPlaneResolutionUnit',
125    SUBJECT_LOCATION = 'SubjectLocation',
126    EXPOSURE_INDEX = 'ExposureIndex',
127    SENSING_METHOD = 'SensingMethod',
128    FILE_SOURCE = 'FileSource',
129    CFA_PATTERN = 'CFAPattern',
130    CUSTOM_RENDERED = 'CustomRendered',
131    EXPOSURE_MODE = 'ExposureMode',
132    DIGITAL_ZOOM_RATIO = 'DigitalZoomRatio',
133    SCENE_CAPTURE_TYPE = 'SceneCaptureType',
134    GAIN_CONTROL = 'GainControl',
135    CONTRAST = 'Contrast',
136    SATURATION = 'Saturation',
137    SHARPNESS = 'Sharpness',
138    DEVICE_SETTING_DESCRIPTION = 'DeviceSettingDescription',
139    SUBJECT_DISTANCE_RANGE = 'SubjectDistanceRange',
140    IMAGE_UNIQUE_ID = 'ImageUniqueID',
141    GPS_VERSION_ID = 'GPSVersionID',
142    GPS_ALTITUDE_REF = 'GPSAltitudeRef',
143    GPS_ALTITUDE = 'GPSAltitude',
144    GPS_SATELLITES = 'GPSSatellites',
145    GPS_STATUS = 'GPSStatus',
146    GPS_MEASURE_MODE = 'GPSMeasureMode',
147    GPS_DOP = 'GPSDOP',
148    GPS_SPEED_REF = 'GPSSpeedRef',
149    GPS_SPEED = 'GPSSpeed',
150    GPS_TRACK_REF = 'GPSTrackRef',
151    GPS_TRACK = 'GPSTrack',
152    GPS_IMG_DIRECTION_REF = 'GPSImgDirectionRef',
153    GPS_IMG_DIRECTION = 'GPSImgDirection',
154    GPS_MAP_DATUM = 'GPSMapDatum',
155    GPS_DEST_LATITUDE_REF = 'GPSDestLatitudeRef',
156    GPS_DEST_LATITUDE = 'GPSDestLatitude',
157    GPS_DEST_LONGITUDE_REF = 'GPSDestLongitudeRef',
158    GPS_DEST_LONGITUDE = 'GPSDestLongitude',
159    GPS_DEST_BEARING_REF = 'GPSDestBearingRef',
160    GPS_DEST_BEARING = 'GPSDestBearing',
161    GPS_DEST_DISTANCE_REF = 'GPSDestDistanceRef',
162    GPS_DEST_DISTANCE = 'GPSDestDistance',
163    GPS_PROCESSING_METHOD = 'GPSProcessingMethod',
164    GPS_AREA_INFORMATION = 'GPSAreaInformation',
165    GPS_DIFFERENTIAL = 'GPSDifferential',
166    BODY_SERIAL_NUMBER = 'BodySerialNumber',
167    CAMERA_OWNER_NAME = 'CameraOwnerName',
168    COMPOSITE_IMAGE = 'CompositeImage',
169    COMPRESSED_BITS_PER_PIXEL = 'CompressedBitsPerPixel',
170    DNG_VERSION = 'DNGVersion',
171    DEFAULT_CROP_SIZE = 'DefaultCropSize',
172    GAMMA = 'Gamma',
173    ISO_SPEED_LATITUDE_YYY = 'ISOSpeedLatitudeyyy',
174    ISO_SPEED_LATITUDE_ZZZ = 'ISOSpeedLatitudezzz',
175    LENS_MAKE = 'LensMake',
176    LENS_MODEL = 'LensModel',
177    LENS_SERIAL_NUMBER = 'LensSerialNumber',
178    LENS_SPECIFICATION = 'LensSpecification',
179    NEW_SUBFILE_TYPE = 'NewSubfileType',
180    OFFSET_TIME = 'OffsetTime',
181    OFFSET_TIME_DIGITIZED = 'OffsetTimeDigitized',
182    OFFSET_TIME_ORIGINAL = 'OffsetTimeOriginal',
183    SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE = 'SourceExposureTimesOfCompositeImage',
184    SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE = 'SourceImageNumberOfCompositeImage',
185    SUBFILE_TYPE = 'SubfileType',
186    GPS_H_POSITIONING_ERROR = 'GPSHPositioningError',
187    PHOTOGRAPHIC_SENSITIVITY = 'PhotographicSensitivity',
188    BURST_NUMBER = 'HwMnoteBurstNumber',
189    FACE_CONF = 'HwMnoteFaceConf',
190    FACE_LEYE_CENTER = 'HwMnoteFaceLeyeCenter',
191    FACE_MOUTH_CENTER = 'HwMnoteFaceMouthCenter',
192    FACE_POINTER = 'HwMnoteFacePointer',
193    FACE_RECT = 'HwMnoteFaceRect',
194    FACE_REYE_CENTER = 'HwMnoteFaceReyeCenter',
195    FACE_SMILE_SCORE = 'HwMnoteFaceSmileScore',
196    FACE_VERSION = 'HwMnoteFaceVersion',
197    FRONT_CAMERA = 'HwMnoteFrontCamera',
198    SCENE_POINTER = 'HwMnoteScenePointer',
199    SCENE_VERSION = 'HwMnoteSceneVersion',
200    IS_XMAGE_SUPPORTED = 'HwMnoteIsXmageSupported',
201    XMAGE_MODE = 'HwMnoteXmageMode',
202    XMAGE_LEFT = 'HwMnoteXmageLeft',
203    XMAGE_TOP = 'HwMnoteXmageTop',
204    XMAGE_RIGHT = 'HwMnoteXmageRight',
205    XMAGE_BOTTOM = 'HwMnoteXmageBottom',
206    CLOUD_ENHANCEMENT_MODE = 'HwMnoteCloudEnhancementMode',
207    WIND_SNAPSHOT_MODE = 'HwMnoteWindSnapshotMode',
208    GIF_LOOP_COUNT = 'GIFLoopCount'
209  }
210
211  export enum AntiAliasingLevel {
212    NONE = 0,
213    LOW = 1,
214    MEDIUM = 2,
215    HIGH = 3,
216  }
217
218  enum HdrMetadataKey {
219    HDR_METADATA_TYPE = 0,
220    HDR_STATIC_METADATA = 1,
221    HDR_DYNAMIC_METADATA = 2,
222    HDR_GAINMAP_METADATA = 3,
223  }
224
225  enum HdrMetadataType {
226    NONE = 0,
227    BASE = 1,
228    GAINMAP = 2,
229    ALTERNATE = 3,
230  }
231
232  export enum PackingDynamicRange {
233    AUTO = 0,
234    SDR = 1,
235  }
236
237  export enum ScaleMode {
238    FIT_TARGET_SIZE = 0,
239    CENTER_CROP = 1
240  }
241
242  enum AuxiliaryPictureType {
243    GAINMAP = 1,
244    DEPTH_MAP = 2,
245    UNREFOCUS_MAP = 3,
246    LINEAR_MAP = 4,
247    FRAGMENT_MAP = 5,
248  }
249
250  enum MetadataType {
251    EXIF_METADATA = 1,
252    FRAGMENT_METADATA = 2,
253  }
254
255  export enum PixelMapFormat {
256    UNKNOWN = 0,
257    ARGB_8888 = 1,
258    RGB_565 = 2,
259    RGBA_8888 = 3,
260    BGRA_8888 = 4,
261    RGB_888 = 5,
262    ALPHA_8 = 6,
263    RGBA_F16 = 7,
264    NV21 = 8,
265    NV12 = 9,
266    RGBA_1010102 = 10,
267    YCBCR_P010 = 11,
268    YCRCB_P010 = 12,
269    ASTC_4x4 = 102
270  }
271
272  export enum AlphaType {
273    UNKNOWN = 0,
274    OPAQUE = 1,
275    PREMUL = 2,
276    UNPREMUL = 3
277  }
278
279  enum ResolutionQuality {
280    LOW = 1,
281    MEDIUM = 2,
282    HIGH = 3
283  }
284
285  // common
286  export interface Size {
287    width: int,
288    height: int,
289  }
290
291  class SizeInner implements Size {
292    constructor(w: int, h: int) {
293      this.width = w;
294      this.height = h;
295    }
296    width: int;
297    height: int;
298  }
299
300  export interface Region {
301    size: Size;
302    x: int;
303    y: int;
304  }
305
306  interface PositionArea {
307    pixels: ArrayBuffer;
308    offset: int;
309    stride: int;
310    region: Region;
311  }
312
313  export interface ImageInfo {
314    size: Size;
315    density: int;
316    stride: int;
317    pixelFormat: PixelMapFormat;
318    alphaType: AlphaType;
319    mimeType: string;
320    isHdr: boolean;
321  }
322
323  class ImageInfoInner implements ImageInfo {
324    size: Size = { width: 0, height: 0 };
325    density: int = 0;
326    stride: int = 0;
327    pixelFormat: PixelMapFormat = PixelMapFormat.UNKNOWN;
328    alphaType: AlphaType = AlphaType.UNKNOWN;
329    mimeType: string = "";
330    isHdr: boolean = false;
331  }
332  // end common
333
334  // pixelmap
335  export interface InitializationOptions {
336    size: Size;
337    srcPixelFormat?: PixelMapFormat;
338    pixelFormat?: PixelMapFormat;
339    editable?: boolean;
340    alphaType?: AlphaType;
341    scaleMode?: ScaleMode;
342  }
343
344  export interface PixelMap {
345    createAlphaPixelmapSync(): PixelMap;
346    createAlphaPixelmap(): Promise<PixelMap>;
347    getImageInfoSync(): ImageInfo;
348    getImageInfo(): Promise<ImageInfo>;
349    getBytesNumberPerRow(): int;
350    getPixelBytesNumber(): int;
351    readPixelsToBufferSync(buff: ArrayBuffer);
352    readPixelsToBuffer(buff: ArrayBuffer): Promise<void>;
353    scaleSync(x: double, y: double): void;
354    scaleSync(x: double, y: double, level: AntiAliasingLevel): void;
355    cropSync(region: Region): void;
356    crop(region: Region): Promise<void>;
357    flipSync(horizontal: boolean, vertical: boolean): void;
358    release(): Promise<void>;
359  }
360
361  class PixelMapInner implements PixelMap {
362    private nativeObj: long = 0;
363
364    constructor(context: long) {
365      if (this.nativeObj == 0) {
366        this.nativeObj = context;
367      }
368    }
369
370    native nativeCreateAlphaPixelmap(): PixelMap;
371
372    public createAlphaPixelmapSync(): PixelMap {
373      return this.nativeCreateAlphaPixelmap();
374    }
375
376    public createAlphaPixelmap(): Promise<PixelMap> {
377      return new Promise<PixelMap>((resolve: (v: PixelMap) => void, reject: (error: Error) => void) => {
378        const cb = (): PixelMap => {
379          return this.nativeCreateAlphaPixelmap();
380        };
381        taskpool.execute(cb)
382          .then((e: NullishType) => resolve(e as PixelMap));
383      });
384    }
385
386    native getBytesNumberPerRow(): int;
387
388    native nativeGetImageInfo(): ImageInfo;
389
390    public getImageInfoSync(): ImageInfo {
391      return this.nativeGetImageInfo();
392    }
393
394    public getImageInfo(): Promise<ImageInfo> {
395      return new Promise<ImageInfo>((resolve: (v: ImageInfo) => void, reject: (error: Error) => void) => {
396        const cb = (): ImageInfo => {
397          return this.nativeGetImageInfo();
398        };
399        taskpool.execute(cb)
400          .then((e: NullishType) => resolve(e as ImageInfo));
401      });
402    }
403
404    native getPixelBytesNumber(): int;
405
406    native nativeReadPixelsToBuffer(buff: ArrayBuffer): void;
407
408    public readPixelsToBufferSync(buff: ArrayBuffer): void {
409      return this.nativeReadPixelsToBuffer(buff);
410    }
411
412    public readPixelsToBuffer(buff: ArrayBuffer): Promise<void> {
413      return new Promise<void>((resolve: (v: Promise<void>) => void, reject: (error: Error) => void) => {
414        const cb = (): boolean => {
415          this.nativeReadPixelsToBuffer(buff);
416          return true;
417        };
418        taskpool.execute(cb)
419          .then((): void => resolve(Promise.resolve()));
420      });
421    }
422
423    native nativeScale(x: double, y: double, level: AntiAliasingLevel): void;
424
425    public scaleSync(x: double, y: double): void {
426      this.nativeScale(x, y, AntiAliasingLevel.NONE);
427    }
428    public scaleSync(x: double, y: double, level: AntiAliasingLevel): void {
429      this.nativeScale(x, y, level);
430    }
431
432    native nativeCrop(region: Region): void;
433
434    public cropSync(region: Region): void {
435      this.nativeCrop(region);
436    }
437    public crop(region: Region): Promise<void> {
438      return new Promise<void>((resolve: (v: Promise<void>) => void, reject: (error: Error) => void) => {
439        const cb = (): boolean => {
440          this.nativeCrop(region);
441          return true;
442        };
443        taskpool.execute(cb)
444          .then((): void => resolve(Promise.resolve()));
445      });
446    }
447
448    native nativeFlip(horizontal: boolean, vertical: boolean): void;
449
450    public flipSync(horizontal: boolean, vertical: boolean): void {
451      this.nativeFlip(horizontal, vertical);
452    }
453
454    native nativeRelease(): void;
455
456    public release(): Promise<void> {
457      return new Promise<void>((resolve: (v: Promise<void>) => void, reject: (error: Error) => void) => {
458        const cb = (): boolean => {
459          this.nativeRelease();
460          return true;
461        };
462        taskpool.execute(cb)
463          .then((): void => resolve(Promise.resolve()));
464      });
465    }
466  }
467
468  export native function createPixelMapSync(options: InitializationOptions): PixelMap;
469
470  // end pixelmap
471
472  // imageSource
473  export interface SourceOptions {
474    sourceDensity: int;
475    sourcePixelFormat?: PixelMapFormat;
476    sourceSize?: Size;
477  }
478
479  interface ImagePropertyOptions {
480    index?: int;
481    defaultValue?: string;
482  }
483
484  interface GetImagePropertyOptions {
485    index?: int;
486    defaultValue?: string;
487  }
488
489  export interface DecodingOptions {
490    index?: int;
491    sampleSize?: int;
492    rotate?: int;
493    editable?: boolean;
494    desiredSize?: Size;
495    desiredRegion?: Region;
496    desiredPixelFormat?: PixelMapFormat;
497    fitDensity?: int;
498    desiredColorSpace?: colorSpaceManager.ColorSpaceManager;
499    desiredDynamicRange?: DecodingDynamicRange;
500    resolutionQuality?: ResolutionQuality;
501  }
502
503  export interface ImageSource {
504    getImageInfoSync(index: int): ImageInfo;
505    getImageInfo(index: int): Promise<ImageInfo>;
506    createPixelMapSync(options?: DecodingOptions): PixelMap;
507    createPixelMap(options?: DecodingOptions): Promise<PixelMap>;
508    modifyImageProperty(key: string, value: string): void;
509    modifyImageProperties(records: Record<string, string | null>): Promise<void>;
510    getImageProperties(key: Array<string>): Promise<Record<string, string | null>>;
511    release(): void;
512  }
513
514  export class ImageSourceInner implements ImageSource {
515    private nativeObj: long = 0;
516
517    constructor(context: long) {
518      if (this.nativeObj == 0) {
519        this.nativeObj = context;
520      }
521    }
522
523    native nativeGetImageInfo(index: int): ImageInfo;
524    native nativeCreatePixelMap(options?: DecodingOptions): PixelMap;
525    private native modifyImageProperty(nativeObj: long, key: string, value: string): void;
526
527    native nativeModifyImageProperties(records: Record<string, string | null>): void;
528
529    modifyImageProperties(records: Record<string, string | null>): Promise<void> {
530      return new Promise<void>((resolve: (v: Promise<void>) => void, reject: (error: Error) => void) => {
531        const cb = (): boolean => {
532          this.nativeModifyImageProperties(records);
533          return true;
534        };
535        taskpool.execute(cb)
536          .then((): void => resolve(Promise.resolve()));
537      });
538    }
539
540    native nativeGetImageProperties(key: Array<string>): Record<string, string | null>;
541
542    public getImageProperties(key: Array<string>): Promise<Record<string, string | null>> {
543      return new Promise<Record<string, string | null>>(
544        (resolve: (v: Record<string, string | null>) => void, reject: (error: Error) => void) => {
545        const cb = (): Record<string, string | null> => {
546          return this.nativeGetImageProperties(key);
547        };
548        taskpool.execute(cb)
549          .then((e: NullishType) => resolve(e as Record<string, string | null>));
550      });
551    }
552
553    native release(): void;
554
555    public createPixelMapSync(options?: DecodingOptions): PixelMap {
556      return this.nativeCreatePixelMap(options);
557    }
558
559    public createPixelMap(options?: DecodingOptions): Promise<PixelMap> {
560      return new Promise<PixelMap>((resolve: (v: PixelMap) => void, reject: (error: Error) => void) => {
561        const cb = (): PixelMap => {
562          return this.nativeCreatePixelMap(options);
563        };
564        taskpool.execute(cb)
565          .then((e: NullishType) => resolve(e as PixelMap));
566      });
567    }
568
569    public modifyImageProperty(key: string, value: string): void {
570      this.modifyImageProperty(this.nativeObj, key, value);
571      return;
572    }
573
574    public getImageInfoSync(index: int): ImageInfo {
575      return this.nativeGetImageInfo(index);
576    }
577
578    public getImageInfo(index: int): Promise<ImageInfo> {
579      return new Promise<ImageInfo>((resolve: (v: ImageInfo) => void, reject: (error: Error) => void) => {
580        const cb = (): ImageInfo => {
581          return this.nativeGetImageInfo(index);
582        };
583        taskpool.execute(cb)
584          .then((e: NullishType) => resolve(e as ImageInfo));
585      });
586    }
587  }
588
589  native function nativeCreateImageSourceByUri(uri: string): ImageSource;
590  native function nativeCreateImageSourceByFd(fd: Int): ImageSource;
591
592  export function createImageSource(uri: string): ImageSource {
593    return nativeCreateImageSourceByUri(uri);
594  }
595  export function createImageSource(fd: Int): ImageSource {
596    return nativeCreateImageSourceByFd(fd);
597  }
598  // end imagesource
599
600  //imagepacker
601  interface PackingOptionsForSequence {
602    frameCount: int;
603    delayTimeList: Array<int>;
604    disposalTypes?: Array<int>;
605    loopCount?: int;
606  }
607
608  interface IPackingOption {
609    format: string;
610    quality: int;
611    bufferSize?: int;
612    desiredDynamicRange?: PackingDynamicRange;
613    needsPackProperties?: boolean;
614  }
615
616  export class PackingOption implements IPackingOption {
617    format: string = "";
618    quality: int = 0;
619    bufferSize?: int = 20971520;
620    desiredDynamicRange?: PackingDynamicRange = PackingDynamicRange.AUTO;
621    needsPackProperties?: boolean = false;
622  }
623
624  export interface ImagePacker {
625    packing(source: PixelMap, option: PackingOption): ArrayBuffer;
626    release(): void;
627    readonly supportedFormats: Array<string>;
628  }
629
630  class ImagePackerInner implements ImagePacker {
631    private nativeObj: long = 0;
632
633    constructor(context: long) {
634      if (this.nativeObj == 0) {
635        this.nativeObj = context;
636      }
637    }
638
639    native nativePackingWithPixelMap(source: PixelMap, option: PackingOption): ArrayBuffer;
640
641    native nativeRelease(): void;
642
643    public release(): void {
644      this.nativeRelease();
645    }
646
647    public packing(source: PixelMap, option: PackingOption): ArrayBuffer {
648      return this.nativePackingWithPixelMap(source, option);
649    }
650    supportedFormats: Array<string> = new Array<string>("jpg", "png");
651  }
652
653  export native function createImagePacker(): ImagePacker;
654  // end imagepcker
655
656  // metadata
657  type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata;
658
659  interface HdrStaticMetadata {
660    displayPrimariesX: Array<double>;
661    displayPrimariesY: Array<double>;
662    whitePointX: double;
663    whitePointY: double;
664    maxLuminance: double;
665    minLuminance: double;
666    maxContentLightLevel: double;
667    maxFrameAverageLightLevel: double;
668  }
669
670  interface GainmapChannel {
671    gainmapMax: double;
672    gainmapMin: double;
673    gamma: double;
674    baseOffset: double;
675    alternateOffset: double;
676  }
677
678  interface Metadata {
679    getProperties(key: Array<string>): Promise<Record<string, string | null>>
680    setProperties(records: Record<string, string | null>): Promise<void>
681    getAllProperties(): Promise<Record<string, string | null>>
682    clone(): Promise<Metadata>
683  }
684  // END Meta
685
686  interface HdrGainmapMetadata {
687    writerVersion: int;
688    miniVersion: int;
689    gainmapChannelCount: int;
690    useBaseColorFlag: boolean;
691    baseHeadroom: double;
692    alternateHeadroom: double;
693    channels: Array<GainmapChannel>;
694  }
695
696  // picture
697  interface Picture {
698    getMainPixelmap(): PixelMap;
699  }
700
701  export class PictureInner implements Picture {
702    private nativeObj: long = 0;
703
704    constructor(context: long) {
705      if (this.nativeObj == 0) {
706        this.nativeObj = context;
707      }
708    }
709
710    native getMainPixelmap(): PixelMap;
711  }
712
713  export native function createPicture(mainPixelmap: PixelMap): Picture;
714
715  interface AuxiliaryPicture {
716    writePixelsFromBuffer(data: ArrayBuffer): Promise<void>;
717    readPixelsToBuffer(): Promise<ArrayBuffer>;
718    getType(): AuxiliaryPictureType;
719    setMetadata(metadataType: MetadataType, metadata: Metadata): Promise<void>
720    getMetadata(metadataType: MetadataType): Promise<Metadata>
721    getAuxiliaryPictureInfo(): AuxiliaryPictureInfo;
722    setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void
723    release(): void
724  }
725
726  interface AuxiliaryPictureInfo {
727    auxiliaryPictureType: AuxiliaryPictureType;
728    size: Size;
729    rowStride: number;
730    pixelFormat: PixelMapFormat;
731    colorSpace: int;
732  }
733
734  interface DecodingOptionsForPicture {
735    desiredAuxiliaryPictures: Array<int>; // Array<AuxiliaryPictureType>
736  }
737} // namespace