1 | import { Observable } from '../data/observable';
|
2 | import { Screen } from '../platform';
|
3 | export class ImageAssetBase extends Observable {
|
4 | constructor() {
|
5 | super();
|
6 | this._options = { keepAspectRatio: true, autoScaleFactor: true };
|
7 | }
|
8 | get options() {
|
9 | return this._options;
|
10 | }
|
11 | set options(value) {
|
12 | this._options = value;
|
13 | }
|
14 | get nativeImage() {
|
15 | return this._nativeImage;
|
16 | }
|
17 | set nativeImage(value) {
|
18 | this._nativeImage = value;
|
19 | }
|
20 | getImageAsync(callback) {
|
21 |
|
22 | }
|
23 | }
|
24 | export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) {
|
25 | const widthCoef = sourceWidth / reqWidth;
|
26 | const heightCoef = sourceHeight / reqHeight;
|
27 | const aspectCoef = Math.min(widthCoef, heightCoef);
|
28 | return {
|
29 | width: Math.floor(sourceWidth / aspectCoef),
|
30 | height: Math.floor(sourceHeight / aspectCoef),
|
31 | };
|
32 | }
|
33 | export function getRequestedImageSize(src, options) {
|
34 | let reqWidth = options.width || Math.min(src.width, Screen.mainScreen.widthPixels);
|
35 | let reqHeight = options.height || Math.min(src.height, Screen.mainScreen.heightPixels);
|
36 | if (options && options.keepAspectRatio) {
|
37 | const safeAspectSize = getAspectSafeDimensions(src.width, src.height, reqWidth, reqHeight);
|
38 | reqWidth = safeAspectSize.width;
|
39 | reqHeight = safeAspectSize.height;
|
40 | }
|
41 | return {
|
42 | width: reqWidth,
|
43 | height: reqHeight,
|
44 | };
|
45 | }
|
46 |
|
\ | No newline at end of file |