MCPcopy Index your code
hub / github.com/tensorflow/tfjs / downloadTextureData

Function downloadTextureData

tfjs-react-native/src/camera/camera_webgl_util.ts:59–97  ·  view source on GitHub ↗
(
    gl: WebGL2RenderingContext, texture: WebGLTexture,
    dims: Dimensions)

Source from the content-addressed store, hash-verified

57 * @param dims
58 */
59export function downloadTextureData(
60 gl: WebGL2RenderingContext, texture: WebGLTexture,
61 dims: Dimensions): Uint8Array {
62 const {width, height, depth} = dims;
63 const pixels = new Uint8Array(width * height * depth);
64
65 if (!fboCache.has(gl)) {
66 fboCache.set(gl, createFrameBuffer(gl));
67 }
68 const fbo = fboCache.get(gl);
69
70 webgl_util.callAndCheck(gl, () => {
71 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
72 });
73
74 webgl_util.callAndCheck(gl, () => {
75 gl.activeTexture(gl.TEXTURE0);
76 gl.bindTexture(gl.TEXTURE_2D, texture);
77 });
78
79 webgl_util.callAndCheck(gl, () => {
80 const level = 0;
81 gl.framebufferTexture2D(
82 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, level);
83 });
84
85 webgl_util.callAndCheck(gl, () => {
86 const format = depth === 3 ? gl.RGB : gl.RGBA;
87 const x = 0;
88 const y = 0;
89 gl.readPixels(x, y, width, height, format, gl.UNSIGNED_BYTE, pixels);
90 });
91
92 // Unbind framebuffer
93 webgl_util.callAndCheck(gl, () => {
94 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
95 });
96 return pixels;
97}
98
99/**
100 * Upload image data to a texture.

Callers 1

fromTextureFunction · 0.90

Calls 4

createFrameBufferFunction · 0.85
hasMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…