1 |
- {"ast":null,"code":"import _asyncToGenerator from \"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\n/**\n * Transform some pixel data to a base64 string\n * @param pixels defines the pixel data to transform to base64\n * @param size defines the width and height of the (texture) data\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\n * @returns The base64 encoded string or null\n */\nexport function GenerateBase64StringFromPixelData(pixels, size, invertY = false) {\n const width = size.width;\n const height = size.height;\n if (pixels instanceof Float32Array) {\n let len = pixels.byteLength / pixels.BYTES_PER_ELEMENT;\n const npixels = new Uint8Array(len);\n while (--len >= 0) {\n let val = pixels[len];\n if (val < 0) {\n val = 0;\n } else if (val > 1) {\n val = 1;\n }\n npixels[len] = val * 255;\n }\n pixels = npixels;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n return null;\n }\n const imageData = ctx.createImageData(width, height);\n const castData = imageData.data;\n castData.set(pixels);\n ctx.putImageData(imageData, 0, 0);\n if (invertY) {\n const canvas2 = document.createElement(\"canvas\");\n canvas2.width = width;\n canvas2.height = height;\n const ctx2 = canvas2.getContext(\"2d\");\n if (!ctx2) {\n return null;\n }\n ctx2.translate(0, height);\n ctx2.scale(1, -1);\n ctx2.drawImage(canvas, 0, 0);\n return canvas2.toDataURL(\"image/png\");\n }\n return canvas.toDataURL(\"image/png\");\n}\n/**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null\n */\nexport function GenerateBase64StringFromTexture(texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = texture._readPixelsSync(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n}\n/**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null wrapped in a promise\n */\nexport function GenerateBase64StringFromTextureAsync(_x) {\n return _GenerateBase64StringFromTextureAsync.apply(this, arguments);\n}\n/**\n * Class used to host copy specific utilities\n * (Back-compat)\n */\nfunction _GenerateBase64StringFromTextureAsync() {\n _GenerateBase64StringFromTextureAsync = _asyncToGenerator(function* (texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = yield texture.readPixels(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n });\n return _GenerateBase64StringFromTextureAsync.apply(this, arguments);\n}\nexport const CopyTools = {\n /**\n * Transform some pixel data to a base64 string\n * @param pixels defines the pixel data to transform to base64\n * @param size defines the width and height of the (texture) data\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\n * @returns The base64 encoded string or null\n */\n GenerateBase64StringFromPixelData,\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null\n */\n GenerateBase64StringFromTexture,\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null wrapped in a promise\n */\n GenerateBase64StringFromTextureAsync\n};","map":{"version":3,"names":["GenerateBase64StringFromPixelData","pixels","size","invertY","width","height","Float32Array","len","byteLength","BYTES_PER_ELEMENT","npixels","Uint8Array","val","canvas","document","createElement","ctx","getContext","imageData","createImageData","castData","data","set","putImageData","canvas2","ctx2","translate","scale","drawImage","toDataURL","GenerateBase64StringFromTexture","texture","faceIndex","level","internalTexture","getInternalTexture","_readPixelsSync","getSize","GenerateBase64StringFromTextureAsync","_x","_GenerateBase64StringFromTextureAsync","apply","arguments","_asyncToGenerator","readPixels","CopyTools"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/copyTools.js"],"sourcesContent":["/**\n * Transform some pixel data to a base64 string\n * @param pixels defines the pixel data to transform to base64\n * @param size defines the width and height of the (texture) data\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\n * @returns The base64 encoded string or null\n */\nexport function GenerateBase64StringFromPixelData(pixels, size, invertY = false) {\n const width = size.width;\n const height = size.height;\n if (pixels instanceof Float32Array) {\n let len = pixels.byteLength / pixels.BYTES_PER_ELEMENT;\n const npixels = new Uint8Array(len);\n while (--len >= 0) {\n let val = pixels[len];\n if (val < 0) {\n val = 0;\n }\n else if (val > 1) {\n val = 1;\n }\n npixels[len] = val * 255;\n }\n pixels = npixels;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n return null;\n }\n const imageData = ctx.createImageData(width, height);\n const castData = imageData.data;\n castData.set(pixels);\n ctx.putImageData(imageData, 0, 0);\n if (invertY) {\n const canvas2 = document.createElement(\"canvas\");\n canvas2.width = width;\n canvas2.height = height;\n const ctx2 = canvas2.getContext(\"2d\");\n if (!ctx2) {\n return null;\n }\n ctx2.translate(0, height);\n ctx2.scale(1, -1);\n ctx2.drawImage(canvas, 0, 0);\n return canvas2.toDataURL(\"image/png\");\n }\n return canvas.toDataURL(\"image/png\");\n}\n/**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null\n */\nexport function GenerateBase64StringFromTexture(texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = texture._readPixelsSync(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n}\n/**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null wrapped in a promise\n */\nexport async function GenerateBase64StringFromTextureAsync(texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = await texture.readPixels(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n}\n/**\n * Class used to host copy specific utilities\n * (Back-compat)\n */\nexport const CopyTools = {\n /**\n * Transform some pixel data to a base64 string\n * @param pixels defines the pixel data to transform to base64\n * @param size defines the width and height of the (texture) data\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\n * @returns The base64 encoded string or null\n */\n GenerateBase64StringFromPixelData,\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null\n */\n GenerateBase64StringFromTexture,\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null wrapped in a promise\n */\n GenerateBase64StringFromTextureAsync,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iCAAiCA,CAACC,MAAM,EAAEC,IA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AMC,eAAe,GAAGH,OAAO,CAACI,kBAAkB,CAAC,CAAC;IACpD,IAAI,CAACD,eAAe,EAAE;MAClB,OAAO,IAAI;IACf;IACA,MAAMjC,MAAM,SAAS8B,OAAO,CAACa,UAAU,CAACZ,SAAS,EAAEC,KAAK,CAAC;IACzD,IAAI,CAAChC,MAAM,EAAE;MACT,OAAO,IAAI;IACf;IACA,OAAOD,iCAAiC,CAACC,MAAM,EAAE8B,OAAO,CAACM,OAAO,CAAC,CAAC,EAAEH,eAAe,CAAC/B,OAAO,CAAC;EAChG,CAAC;EAAA,OAAAqC,qCAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAKD,OAAO,MAAMG,SAAS,GAAG;EACrB;AACJ;AACA;AACA;AACA;AACA;AACA;EACI7C,iCAAiC;EACjC;AACJ;AACA;AACA;AACA;AACA;AACA;EACI8B,+BAA+B;EAC/B;AACJ;AACA;AACA;AACA;AACA;AACA;EACIQ;AACJ,CAAC","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}
|