UnZipTerrainData.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2017 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './createTaskProcessorWorker', './pako_inflate-8ea163f9', './unzip-b0fc9445'], function (when, createTaskProcessorWorker, pako_inflate, unzip) { 'use strict';
  24. var unzipwasmReady = false;
  25. unzip.unzip.onRuntimeInitialized = function() {
  26. unzipwasmReady = true;
  27. };
  28. var unzipwasm = unzip.unzip.cwrap('unzip', 'number', ['number', 'number', 'number', 'number']);
  29. var freec = unzip.unzip.cwrap('freePointer', null, ['number']);
  30. function unzipWithwasm(datazip) {
  31. var unzipsize = datazip.length * 4;
  32. var offset = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * unzipsize); //开辟内存
  33. var tar = new Uint8Array(unzipsize);
  34. unzip.unzip.HEAPU8.set(tar, offset / Uint8Array.BYTES_PER_ELEMENT);
  35. var offset1 = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * datazip.length);
  36. unzip.unzip.HEAPU8.set(datazip, offset1 / Uint8Array.BYTES_PER_ELEMENT);
  37. var resultLen;
  38. while ((resultLen = unzipwasm(offset, unzipsize, offset1, datazip.length)) == 0) {
  39. freec(offset); //释放内存
  40. unzipsize *= 4;
  41. offset = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * unzipsize);
  42. tar = new Uint8Array(unzipsize);
  43. unzip.unzip.HEAPU8.set(tar, offset / Uint8Array.BYTES_PER_ELEMENT);
  44. }
  45. var res = new Uint8Array(unzip.unzip.HEAPU8.buffer, offset, resultLen);
  46. datazip = null;
  47. tar = null;
  48. var buffer = new Uint8Array(res);
  49. freec(offset);
  50. freec(offset1);
  51. return buffer;
  52. }
  53. function UnZipTerrainData(parameters, transferableObjects) {
  54. var buffer = parameters.data;
  55. var dataZip = new Uint8Array(buffer);
  56. var unzipBuffer;
  57. if (unzipwasmReady === true) {
  58. unzipBuffer = unzipWithwasm(dataZip);
  59. return {
  60. data : unzipBuffer
  61. };
  62. } else {
  63. unzipBuffer = pako_inflate.pako.inflate(dataZip).buffer;
  64. }
  65. transferableObjects.push(unzipBuffer);
  66. return {
  67. data : new Uint8Array(unzipBuffer)
  68. };
  69. }
  70. var UnZipTerrainData$1 = createTaskProcessorWorker(UnZipTerrainData);
  71. return UnZipTerrainData$1;
  72. });