testSVGPremultipliedAlpha.js 2.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{Pos2us as e}from"../2d/engine/webgl/DefaultVertexAttributeLayouts.js";import{BufferObject as r}from"./BufferObject.js";import{TargetType as t,DepthStencilTargetType as i,TextureType as n,TextureWrapMode as o,PixelFormat as a,PixelType as s,TextureSamplingMode as p,Usage as g,ClearBufferBit as m,PrimitiveType as d}from"./enums.js";import{FramebufferObject as l}from"./FramebufferObject.js";import{Texture as u}from"./Texture.js";import{VertexArrayObject as c}from"./VertexArrayObject.js";async function f(f){const w=new Image;if(w.src="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='5' height='5' version='1.1' viewBox='0 0 5 5' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='5' height='5' fill='%23f00' fill-opacity='.5'/%3E%3C/svg%3E%0A",w.width=5,w.height=5,await w.decode(),!f.gl)return!0;const _=new l(f,{colorTarget:t.TEXTURE,depthStencilTarget:i.NONE},{target:n.TEXTURE_2D,wrapMode:o.CLAMP_TO_EDGE,pixelFormat:a.RGBA,dataType:s.UNSIGNED_BYTE,samplingMode:p.NEAREST,width:1,height:1}),E=r.createVertex(f,g.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),h=new c(f,new Map([["a_pos",0]]),e,{geometry:E}),v="\n precision highp float;\n\n attribute vec2 a_pos;\n varying vec2 v_uv;\n\n void main() {\n v_uv = a_pos;\n gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0);\n }\n ",T="\n precision highp float;\n\n varying vec2 v_uv;\n uniform sampler2D u_texture;\n\n void main() {\n gl_FragColor = texture2D(u_texture, v_uv);\n }\n ",x=f.programCache.acquire(v,T,new Map([["a_pos",0]]));f.useProgram(x);const A=new u(f,{dataType:s.UNSIGNED_BYTE,pixelFormat:a.RGBA,preMultiplyAlpha:!1,wrapMode:o.CLAMP_TO_EDGE,samplingMode:p.LINEAR},w);f.bindTexture(A,0),x.setUniform1i("u_texture",0);const b=f.getBoundFramebufferObject(),{x:y,y:B,width:C,height:F}=f.getViewport();f.bindFramebuffer(_),f.setViewport(0,0,1,1),f.setClearColor(0,0,0,0),f.setBlendingEnabled(!1),f.clearSafe(m.COLOR_BUFFER_BIT),f.bindVAO(h),f.drawArrays(d.TRIANGLE_STRIP,0,4);const R=new Uint8Array(4);return _.readPixels(0,0,1,1,a.RGBA,s.UNSIGNED_BYTE,R),x.dispose(),h.dispose(!1),E.dispose(),_.dispose(),A.dispose(),f.setViewport(y,B,C,F),f.bindFramebuffer(b),w.src="",255===R[0]}export{f as testSVGPremultipliedAlpha};