UNPKG

3.27 kBTypeScriptView Raw
1import { ALPHA_MODES } from '@pixi/constants';
2import { BaseImageResource } from './BaseImageResource';
3import type { Renderer } from '../../Renderer';
4import type { BaseTexture } from '../BaseTexture';
5import type { GLTexture } from '../GLTexture';
6export interface IImageResourceOptions {
7 /** Start loading process automatically when constructed. */
8 autoLoad?: boolean;
9 /** Whether its required to create a bitmap before upload. */
10 createBitmap?: boolean;
11 /** Load image using cross origin. */
12 crossorigin?: boolean | string;
13 /** Premultiply image alpha in bitmap. */
14 alphaMode?: ALPHA_MODES;
15}
16/**
17 * Resource type for HTMLImageElement.
18 * @memberof PIXI
19 */
20export declare class ImageResource extends BaseImageResource {
21 /** URL of the image source */
22 url: string;
23 /**
24 * If the image should be disposed after upload
25 * @default false
26 */
27 preserveBitmap: boolean;
28 /**
29 * If capable, convert the image using createImageBitmap API.
30 * @default PIXI.settings.CREATE_IMAGE_BITMAP
31 */
32 createBitmap: boolean;
33 /**
34 * Controls texture alphaMode field
35 * Copies from options
36 * Default is `null`, copies option from baseTexture
37 * @readonly
38 */
39 alphaMode: ALPHA_MODES;
40 /**
41 * The ImageBitmap element created for a {@link HTMLImageElement}.
42 * @default null
43 */
44 bitmap: ImageBitmap;
45 /**
46 * Promise when loading.
47 * @default null
48 */
49 private _load;
50 /** When process is completed */
51 private _process;
52 /**
53 * @param source - image source or URL
54 * @param options
55 * @param {boolean} [options.autoLoad=true] - start loading process
56 * @param {boolean} [options.createBitmap=PIXI.settings.CREATE_IMAGE_BITMAP] - whether its required to create
57 * a bitmap before upload
58 * @param {boolean} [options.crossorigin=true] - Load image using cross origin
59 * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.UNPACK] - Premultiply image alpha in bitmap
60 */
61 constructor(source: HTMLImageElement | string, options?: IImageResourceOptions);
62 /**
63 * Returns a promise when image will be loaded and processed.
64 * @param createBitmap - whether process image into bitmap
65 */
66 load(createBitmap?: boolean): Promise<ImageResource>;
67 /**
68 * Called when we need to convert image into BitmapImage.
69 * Can be called multiple times, real promise is cached inside.
70 * @returns - Cached promise to fill that bitmap
71 */
72 process(): Promise<ImageResource>;
73 /**
74 * Upload the image resource to GPU.
75 * @param renderer - Renderer to upload to
76 * @param baseTexture - BaseTexture for this resource
77 * @param glTexture - GLTexture to use
78 * @returns {boolean} true is success
79 */
80 upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean;
81 /** Destroys this resource. */
82 dispose(): void;
83 /**
84 * Used to auto-detect the type of resource.
85 * @param {*} source - The source object
86 * @returns {boolean} `true` if current environment support HTMLImageElement, and source is string or HTMLImageElement
87 */
88 static test(source: unknown): source is string | HTMLImageElement;
89}