content/canvas/test/webgl-conformance/conformance/textures/gl-teximage.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <title>WebGL texImage2D conformance test.</title>
michael@0 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 12 <script src="../../resources/js-test-pre.js"></script>
michael@0 13 <script src="../resources/webgl-test.js"> </script>
michael@0 14 <script src="../resources/webgl-test-utils.js"> </script>
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <canvas id="example" width="256" height="16" style="width: 256px; height: 48px;"></canvas>
michael@0 18 <div id="description"></div>
michael@0 19 <div id="console"></div>
michael@0 20 <script>
michael@0 21 description("Test texImage2D conversions.");
michael@0 22 var wtu = WebGLTestUtils;
michael@0 23 var gl = wtu.create3DContext("example");
michael@0 24 gl.disable(gl.DITHER);
michael@0 25 var program = wtu.setupTexturedQuad(gl);
michael@0 26
michael@0 27 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 28
michael@0 29 var imgURLs = [
michael@0 30 '../resources/gray-ramp-256-with-128-alpha.png',
michael@0 31 '../resources/gray-ramp-256.png',
michael@0 32 '../resources/gray-ramp-default-gamma.png',
michael@0 33 '../resources/gray-ramp-gamma0.1.png',
michael@0 34 '../resources/gray-ramp-gamma1.0.png',
michael@0 35 '../resources/gray-ramp-gamma2.0.png',
michael@0 36 '../resources/gray-ramp-gamma4.0.png',
michael@0 37 '../resources/gray-ramp-gamma9.0.png',
michael@0 38 '../resources/gray-ramp.png',
michael@0 39 '../resources/zero-alpha.png',
michael@0 40 '../resources/3x3.png',
michael@0 41 '../resources/blue-1x1.jpg',
michael@0 42 '../resources/red-indexed.png',
michael@0 43 '../resources/green-2x2-16bit.png',
michael@0 44 '../resources/small-square-with-colorspin-profile.jpg',
michael@0 45 '../resources/small-square-with-colorspin-profile.png',
michael@0 46 '../resources/small-square-with-cie-rgb-profile.png',
michael@0 47 '../resources/small-square-with-colormatch-profile.png',
michael@0 48 '../resources/small-square-with-e-srgb-profile.png',
michael@0 49 '../resources/small-square-with-smpte-c-profile.png',
michael@0 50 '../resources/small-square-with-srgb-iec61966-2.1-profile.png'];
michael@0 51
michael@0 52
michael@0 53 wtu.loadImagesAsync(imgURLs, runTests);
michael@0 54
michael@0 55 function runTests(imgs) {
michael@0 56 var loc = gl.getUniformLocation(program, "tex");
michael@0 57 gl.uniform1i(loc, 0);
michael@0 58
michael@0 59 gl.disable(gl.BLEND);
michael@0 60 gl.disable(gl.DEPTH_TEST);
michael@0 61
michael@0 62 var width = gl.canvas.width;
michael@0 63 var height = gl.canvas.height;
michael@0 64
michael@0 65 function checkPixel(buf, x, y, color) {
michael@0 66 var off = (y * width + x) * 4;
michael@0 67 var msg = "pixel " + x + ", " + y + " should be " +
michael@0 68 color[0] + ", " +
michael@0 69 color[1] + ", " +
michael@0 70 color[2] + ", " +
michael@0 71 color[3] + " was " +
michael@0 72 buf[off + 0] + ", " +
michael@0 73 buf[off + 1] + ", " +
michael@0 74 buf[off + 2] + ", " +
michael@0 75 buf[off + 3];
michael@0 76
michael@0 77 for (var ii = 0; ii < 4; ++ii) {
michael@0 78 if (buf[off + ii] != color[ii]) {
michael@0 79 testFailed(msg);
michael@0 80 return;
michael@0 81 }
michael@0 82 }
michael@0 83 testPassed(msg);
michael@0 84 }
michael@0 85
michael@0 86 function checkPixelRange(buf, x, y, color, allowedRange) {
michael@0 87 var off = (y * width + x) * 4;
michael@0 88 var msg = "pixel " + x + ", " + y + " should be within " +
michael@0 89 allowedRange + " units of " +
michael@0 90 color[0] + ", " +
michael@0 91 color[1] + ", " +
michael@0 92 color[2] + ", " +
michael@0 93 color[3];
michael@0 94 var subMsg = " was " +
michael@0 95 buf[off + 0] + ", " +
michael@0 96 buf[off + 1] + ", " +
michael@0 97 buf[off + 2] + ", " +
michael@0 98 buf[off + 3];
michael@0 99 // When running in WebKit's test harness, we don't want to print the
michael@0 100 // pixel value when the test passes, because different machines might
michael@0 101 // have different results and we record the text output.
michael@0 102 var inDumpRenderTree = window.layoutTestController;
michael@0 103 for (var ii = 0; ii < 4; ++ii) {
michael@0 104 if (Math.abs(buf[off + ii] - color[ii]) > allowedRange) {
michael@0 105 testFailed(msg + subMsg);
michael@0 106 return;
michael@0 107 }
michael@0 108 }
michael@0 109 testPassed(msg + (inDumpRenderTree ? "" : subMsg));
michael@0 110 }
michael@0 111
michael@0 112 var tex = gl.createTexture();
michael@0 113 gl.bindTexture(gl.TEXTURE_2D, tex);
michael@0 114 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
michael@0 115 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
michael@0 116 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
michael@0 117 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
michael@0 118
michael@0 119 var buf = new Uint8Array(width * height * 4);
michael@0 120
michael@0 121 debug("");
michael@0 122 debug("check pixels are NOT pre-multiplied");
michael@0 123 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 124 imgs['../resources/zero-alpha.png']);
michael@0 125 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 126 wtu.drawQuad(gl);
michael@0 127 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 128
michael@0 129 var left = 0;
michael@0 130 var middle = Math.floor(width / 2);
michael@0 131 var right = width - 1;
michael@0 132 var bottom = 0;
michael@0 133 var center = Math.floor(height / 2);
michael@0 134 var top = height - 1;
michael@0 135 checkPixel(buf, left, top, [ 0, 0, 0, 255]);
michael@0 136 checkPixel(buf, middle, top, [255, 0, 255, 255]);
michael@0 137 checkPixel(buf, right, top, [ 0, 0, 255, 255]);
michael@0 138 checkPixel(buf, left, center, [128, 128, 128, 255]);
michael@0 139 checkPixel(buf, middle, center, [255, 255, 255, 255]);
michael@0 140 checkPixel(buf, right, center, [ 0, 255, 255, 255]);
michael@0 141 checkPixel(buf, left, bottom, [255, 0, 0, 255]);
michael@0 142 checkPixel(buf, middle, bottom, [255, 255, 0, 255]);
michael@0 143 checkPixel(buf, right, bottom, [ 0, 255, 0, 255]);
michael@0 144
michael@0 145 debug("");
michael@0 146 debug("check quantization");
michael@0 147 var quantInfo = [
michael@0 148 {format: gl.RGBA, type: gl.UNSIGNED_BYTE, counts: [256, 256, 256, 256]},
michael@0 149 {format: gl.RGBA, type: gl.UNSIGNED_SHORT_4_4_4_4, counts: [ 16, 16, 16, 16]},
michael@0 150 {format: gl.RGB, type: gl.UNSIGNED_SHORT_5_6_5, counts: [ 32, 64, 32, 1]},
michael@0 151 {format: gl.RGBA, type: gl.UNSIGNED_SHORT_5_5_5_1, counts: [ 32, 32, 32, 2]}];
michael@0 152 for (var qq = 0; qq < quantInfo.length; ++qq) {
michael@0 153 var info = quantInfo[qq];
michael@0 154 gl.texImage2D(
michael@0 155 gl.TEXTURE_2D, 0, info.format, info.format, info.type,
michael@0 156 imgs['../resources/gray-ramp-256.png']);
michael@0 157 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 158 wtu.drawQuad(gl);
michael@0 159 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 160 var counts = [{ }, { }, { }, { }];
michael@0 161 var numUniqueValues = [0, 0, 0, 0];
michael@0 162 // Count the number of unique values in each channel.
michael@0 163 for (var ii = 0; ii < width * height * 4; ii += 4) {
michael@0 164 for (var jj = 0; jj < 4; ++jj) {
michael@0 165 var v = buf[ii + jj];
michael@0 166 if (!counts[jj][v]) {
michael@0 167 counts[jj][v] = 1;
michael@0 168 ++numUniqueValues[jj];
michael@0 169 } else {
michael@0 170 ++counts[jj][v];
michael@0 171 }
michael@0 172 }
michael@0 173 }
michael@0 174 for (var ii = 0; ii < 4; ++ii) {
michael@0 175 assertMsg(numUniqueValues[ii] == info.counts[ii],
michael@0 176 "There should be " + info.counts[ii] +
michael@0 177 " unique values in channel " + ii + ". Found " +
michael@0 178 numUniqueValues[ii]);
michael@0 179 }
michael@0 180 }
michael@0 181
michael@0 182 debug("");
michael@0 183 debug("Check that gamma settings don't effect 8bit pngs");
michael@0 184 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
michael@0 185 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 186 imgs['../resources/gray-ramp-default-gamma.png']);
michael@0 187 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 188 wtu.drawQuad(gl);
michael@0 189 var ref = new Uint8Array(width * height * 4);
michael@0 190 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, ref);
michael@0 191
michael@0 192 var gammaImages = [
michael@0 193 '../resources/gray-ramp-gamma0.1.png',
michael@0 194 '../resources/gray-ramp-gamma1.0.png',
michael@0 195 '../resources/gray-ramp-gamma2.0.png',
michael@0 196 '../resources/gray-ramp-gamma4.0.png',
michael@0 197 '../resources/gray-ramp-gamma9.0.png'];
michael@0 198 for (var ii = 0; ii < gammaImages.length; ++ii) {
michael@0 199 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 200 imgs[gammaImages[ii]]);
michael@0 201 wtu.drawQuad(gl);
michael@0 202 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 203 var same = true;
michael@0 204 for (var jj = 0; jj < width * height * 4; ++jj) {
michael@0 205 if (buf[jj] != ref[jj]) {
michael@0 206 same = false;
michael@0 207 break;
michael@0 208 }
michael@0 209 }
michael@0 210 assertMsg(same, "pixels should be same regardless of gamma settings.");
michael@0 211 }
michael@0 212
michael@0 213 debug("");
michael@0 214 debug("check pixels are UN pre-multiplied");
michael@0 215 for (var ii = 0; ii < 2; ++ii) {
michael@0 216 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
michael@0 217 if (ii == 0) {
michael@0 218 var canvas2d = document.createElement("canvas");
michael@0 219 canvas2d.width = 256;
michael@0 220 canvas2d.height = 1;
michael@0 221 var ctx = canvas2d.getContext("2d");
michael@0 222 ctx.drawImage(imgs['../resources/gray-ramp-256-with-128-alpha.png'], 0, 0);
michael@0 223 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, canvas2d);
michael@0 224 } else {
michael@0 225 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 226 imgs['../resources/gray-ramp-256-with-128-alpha.png']);
michael@0 227 }
michael@0 228 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 229 wtu.drawQuad(gl);
michael@0 230 var buf = new Uint8Array(width * height * 4);
michael@0 231 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 232 var lt128Count = [0, 0, 0];
michael@0 233 var ge128Count = [0, 0, 0];
michael@0 234 for (var jj = 0; jj < width; ++jj) {
michael@0 235 var off = jj * 4;
michael@0 236 for (var cc = 0; cc < 3; ++cc) {
michael@0 237 if (buf[off + cc] < 128) {
michael@0 238 ++lt128Count[cc];
michael@0 239 } else {
michael@0 240 ++ge128Count[cc];
michael@0 241 }
michael@0 242 }
michael@0 243 }
michael@0 244 // Not sure the exact count here because gamma does effect drawing into the
michael@0 245 // canvas but it should be close to 50% so I'll pass 45%
michael@0 246 for (var jj = 0; jj < 3; ++jj) {
michael@0 247 assertMsg(ge128Count[jj] > 256 * 0.45,
michael@0 248 "Half the pixels in channel " + jj +
michael@0 249 " should be >= 128,128,128. found " +
michael@0 250 ((ge128Count[jj] / 256) * 100).toFixed() + "%");
michael@0 251 assertMsg(lt128Count[jj] > 256 * 0.45,
michael@0 252 "Half the pixels in channel " + jj +
michael@0 253 " should be < 128,128,128. found " +
michael@0 254 ((lt128Count[jj] / 256) * 100).toFixed() + "%");
michael@0 255 }
michael@0 256 }
michael@0 257
michael@0 258 debug("");
michael@0 259 debug("check canvas pixels are UN pre-multiplied");
michael@0 260 var canvas2d = document.createElement("canvas");
michael@0 261 canvas2d.width = 1;
michael@0 262 canvas2d.height = 1;
michael@0 263 var ctx = canvas2d.getContext("2d");
michael@0 264 ctx.fillStyle ="rgba(255,255,255,0.5)";
michael@0 265 ctx.fillRect(0, 0, 256, 1);
michael@0 266 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
michael@0 267 wtu.drawQuad(gl);
michael@0 268 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 269 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 270 checkPixelRange(buf, 0, 0, [255, 255, 255, 127], 4);
michael@0 271
michael@0 272 debug("");
michael@0 273 debug("check canvas pixels are pre-multiplied");
michael@0 274 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
michael@0 275 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
michael@0 276 wtu.drawQuad(gl);
michael@0 277 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 278 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
michael@0 279 checkPixelRange(buf, 0, 0, [127, 127, 127, 127], 4);
michael@0 280
michael@0 281
michael@0 282 debug("");
michael@0 283 debug("check pixels are pre-multiplied");
michael@0 284 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
michael@0 285 // TODO(gman): use different texture that won't pass on failure
michael@0 286 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
michael@0 287 imgs['../resources/zero-alpha.png']);
michael@0 288 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 289 wtu.drawQuad(gl);
michael@0 290 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 291
michael@0 292 var same = true;
michael@0 293 for (var jj = 0; jj < width * height * 4; ++jj) {
michael@0 294 if (buf[jj] != 0) {
michael@0 295 same = false;
michael@0 296 break;
michael@0 297 }
michael@0 298 }
michael@0 299 assertMsg(same, "pixels should all be 0.");
michael@0 300
michael@0 301 debug("");
michael@0 302 debug("check pixels are flipped");
michael@0 303 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
michael@0 304 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
michael@0 305 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 306 imgs['../resources/3x3.png']);
michael@0 307 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 308 wtu.drawQuad(gl);
michael@0 309 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 310
michael@0 311 checkPixel(buf, left, top, [255, 0, 0, 255]);
michael@0 312 checkPixel(buf, middle, top, [255, 255, 0, 255]);
michael@0 313 checkPixel(buf, right, top, [255, 0, 0, 255]);
michael@0 314 checkPixel(buf, left, center, [255, 0, 255, 255]);
michael@0 315 checkPixel(buf, middle, center, [255, 0, 0, 255]);
michael@0 316 checkPixel(buf, right, center, [ 0, 255, 0, 255]);
michael@0 317 checkPixel(buf, left, bottom, [ 0, 0, 0, 255]);
michael@0 318 checkPixel(buf, middle, bottom, [ 0, 0, 255, 255]);
michael@0 319 checkPixel(buf, right, bottom, [255, 0, 0, 255]);
michael@0 320
michael@0 321 debug("");
michael@0 322 debug("check uploading of images with no alpha channel works");
michael@0 323 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
michael@0 324 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
michael@0 325 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 326 imgs['../resources/blue-1x1.jpg']);
michael@0 327 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 328 wtu.drawQuad(gl);
michael@0 329 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 330 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
michael@0 331 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
michael@0 332
michael@0 333 debug("");
michael@0 334 debug("check uploading of 16-bit images");
michael@0 335 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
michael@0 336 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
michael@0 337 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 338 imgs['../resources/green-2x2-16bit.png']);
michael@0 339 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 340 wtu.drawQuad(gl);
michael@0 341 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 342 checkPixelRange(buf, middle, center, [ 15, 121, 0, 255], 10);
michael@0 343 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
michael@0 344
michael@0 345 debug("");
michael@0 346 debug("check uploading of images with ICC profiles");
michael@0 347 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
michael@0 348 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
michael@0 349 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
michael@0 350
michael@0 351 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 352 imgs['../resources/small-square-with-colorspin-profile.jpg']);
michael@0 353 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 354 wtu.drawQuad(gl);
michael@0 355 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 356 // The image is red. However, if we ignore the color profile, it is blue.
michael@0 357 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
michael@0 358
michael@0 359 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 360 imgs['../resources/small-square-with-colorspin-profile.png']);
michael@0 361 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 362 wtu.drawQuad(gl);
michael@0 363 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 364 // The image is red. However, if we ignore the color profile, it is blue.
michael@0 365 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
michael@0 366
michael@0 367 var iccPNGs = [
michael@0 368 '../resources/small-square-with-cie-rgb-profile.png',
michael@0 369 '../resources/small-square-with-colormatch-profile.png',
michael@0 370 '../resources/small-square-with-e-srgb-profile.png',
michael@0 371 '../resources/small-square-with-smpte-c-profile.png',
michael@0 372 '../resources/small-square-with-srgb-iec61966-2.1-profile.png'];
michael@0 373 for (var ii = 0; ii < iccPNGs.length; ++ii) {
michael@0 374 var buf2 = new Uint8Array(width * height * 4);
michael@0 375 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 376 imgs[iccPNGs[ii]]);
michael@0 377 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 378 wtu.drawQuad(gl);
michael@0 379 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf2);
michael@0 380 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
michael@0 381 var same = true;
michael@0 382 for (var jj = 0; jj < buf.length; ++jj) {
michael@0 383 if (buf[jj] != buf2[jj]) {
michael@0 384 same = false;
michael@0 385 break;
michael@0 386 }
michael@0 387 }
michael@0 388 assertMsg(same, "uploading PNGs with same data but various ICC profiles should generate the same results");
michael@0 389 }
michael@0 390
michael@0 391 debug("");
michael@0 392 debug("check uploading of indexed PNG images");
michael@0 393 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
michael@0 394 imgs['../resources/red-indexed.png']);
michael@0 395 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 396 wtu.drawQuad(gl);
michael@0 397 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 398 // The image should be red.
michael@0 399 checkPixelRange(buf, middle, center, [ 255, 0, 0, 255 ], 10);
michael@0 400
michael@0 401 debug("")
michael@0 402 debug("check calling texImage2D with NULL clears the texture");
michael@0 403 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB,
michael@0 404 imgs['../resources/red-indexed.png'].width,
michael@0 405 imgs['../resources/red-indexed.png'].height,
michael@0 406 0, gl.RGB, gl.UNSIGNED_BYTE, null);
michael@0 407 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
michael@0 408 wtu.drawQuad(gl);
michael@0 409 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 410 // The image should be white.
michael@0 411 checkPixelRange(buf, middle, center, [ 0, 0, 0, 255 ], 10);
michael@0 412
michael@0 413 debug("");
michael@0 414 successfullyParsed = true;
michael@0 415 shouldBeTrue("successfullyParsed");
michael@0 416 debug('<br /><span class="pass">TEST COMPLETE</span>');
michael@0 417 notifyFinishedToHarness();
michael@0 418 }
michael@0 419 </script>
michael@0 420 </body>
michael@0 421 </html>
michael@0 422

mercurial