-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test I420 JPEG -> ImageDecoder -> VideoFrame -> WebGLTexture. (#3641)
This configuration (specifically, an I420 encoded JPEG) was broken in Chromium. Other red/green tests with different file formats can be added to the same test case later if desired. Associated with Chromium bug crbug.com/328284177 .
- Loading branch information
1 parent
49d8e00
commit 9aa16ea
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
sdk/tests/conformance/textures/misc/image-decoder-to-texture.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<!-- | ||
Copyright (c) 2024 The Khronos Group Inc. | ||
Use of this source code is governed by an MIT-style license that can be | ||
found in the LICENSE.txt file. | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Tests uploading VideoFrames from ImageDecoder to WebGL textures</title> | ||
<link rel="stylesheet" href="../../../resources/js-test-style.css"/> | ||
<script src="../../../js/js-test-pre.js"></script> | ||
<script src="../../../js/webgl-test-utils.js"></script> | ||
<script src="../../../js/tests/tex-image-and-sub-image-utils.js"></script> | ||
</head> | ||
<body onload="run()"> | ||
<canvas id="c" width="32" height="32"></canvas> | ||
<div id="description"></div> | ||
<div id="console"></div> | ||
<script> | ||
"use strict"; | ||
description(); | ||
let wtu = WebGLTestUtils; | ||
let tiu = TexImageUtils; | ||
let canvas = document.getElementById("c"); | ||
let gl = wtu.create3DContext(canvas); | ||
let program = tiu.setupTexturedQuad(gl, gl.RGBA); | ||
const resourcePath = "../../../resources/"; | ||
const tolerance = 15; | ||
const redColor = [255, 0, 0]; | ||
const greenColor = [0, 255, 0]; | ||
|
||
function output(str) | ||
{ | ||
debug(str); | ||
bufferedLogToConsole(str); | ||
} | ||
|
||
function checkColors(topColor, bottomColor) | ||
{ | ||
// Check a few pixels near the top and bottom and make sure they have | ||
// the right color. | ||
debug("Checking lower left corner"); | ||
wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | ||
"shouldBe " + bottomColor, tolerance); | ||
debug("Checking upper left corner"); | ||
wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | ||
"shouldBe " + topColor, tolerance); | ||
} | ||
|
||
async function testImage(filename, type) | ||
{ | ||
let response = await fetch(resourcePath + filename); | ||
let imageDecoder = new ImageDecoder({data: response.body, type: type}); | ||
let decodeResult = await imageDecoder.decode({frameIndex: 0}); | ||
if (!decodeResult.complete) { | ||
throw "Image decoding for " + filename + " failed"; | ||
} | ||
let frame = decodeResult.image; | ||
if (window.WebGL2RenderingContext && gl instanceof window.WebGL2RenderingContext) { | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, frame.width, frame.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, frame); | ||
} else { | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frame); | ||
} | ||
wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]); | ||
checkColors(greenColor, redColor); | ||
} | ||
|
||
async function run() | ||
{ | ||
if (!window.ImageDecoder) { | ||
debug("ImageDecoder API not supported - skipping test"); | ||
finishTest(); | ||
return; | ||
} | ||
|
||
let tex = gl.createTexture(); | ||
// Bind the texture to the default texture unit 0 | ||
gl.bindTexture(gl.TEXTURE_2D, tex); | ||
// Set up texture parameters | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | ||
|
||
const files = [ | ||
// Created using https://squoosh.app/ from red-green-512x512.png, using | ||
// MozJPEG encoder, Channels YCbCr, deselect "Auto subsample chroma", | ||
// set "Subsample chroma by" to 2. Leave other settings as-is. Creates | ||
// an I420 encoded JPEG, which was one of the problematic | ||
// configurations. | ||
["red-green-512x512-I420.jpg", "image/jpeg"], | ||
]; | ||
|
||
for (let f of files) { | ||
await testImage(f[0], f[1]); | ||
} | ||
|
||
finishTest(); | ||
} | ||
|
||
var successfullyParsed = true; | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.