15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import when from "../ThirdParty/when.js";
import Check from "./Check.js";
import defaultValue from "./defaultValue.js";
import defined from "./defined.js";
import Resource from "./Resource.js";
 
/**
 * @private
 */
function loadImageFromTypedArray(options) {
  var uint8Array = options.uint8Array;
  var format = options.format;
  var request = options.request;
  var flipY = defaultValue(options.flipY, false);
  var skipColorSpaceConversion = defaultValue(
    options.skipColorSpaceConversion,
    false
  );
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.object("uint8Array", uint8Array);
  Check.typeOf.string("format", format);
  //>>includeEnd('debug');
 
  var blob = new Blob([uint8Array], {
    type: format,
  });
 
  var blobUrl;
  return Resource.supportsImageBitmapOptions()
    .then(function (result) {
      if (result) {
        return when(
          Resource.createImageBitmapFromBlob(blob, {
            flipY: flipY,
            premultiplyAlpha: false,
            skipColorSpaceConversion: skipColorSpaceConversion,
          })
        );
      }
 
      blobUrl = window.URL.createObjectURL(blob);
      var resource = new Resource({
        url: blobUrl,
        request: request,
      });
 
      return resource.fetchImage({
        flipY: flipY,
        skipColorSpaceConversion: skipColorSpaceConversion,
      });
    })
    .then(function (result) {
      if (defined(blobUrl)) {
        window.URL.revokeObjectURL(blobUrl);
      }
      return result;
    })
    .otherwise(function (error) {
      if (defined(blobUrl)) {
        window.URL.revokeObjectURL(blobUrl);
      }
      return when.reject(error);
    });
}
export default loadImageFromTypedArray;