1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/reftest/encoders-lossless/encoder.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +<html class="reftest-wait"> 1.5 +<head> 1.6 + <title>Image reftest wrapper</title> 1.7 + <link rel="stylesheet" href="ImageDocument.css"> 1.8 + <style type="text/css"> 1.9 + #image_from_encoder { background-color: rgb(10, 100, 250); } 1.10 + </style> 1.11 + 1.12 + <script> 1.13 + // Parse out the URL command line params 1.14 + // Valid options are: 1.15 + // - img=<reference image to use> 1.16 + // - mime=<mime type> 1.17 + // - options=<canvas toDataURL encoder options> 1.18 + // Example: 1.19 + // encoder.html?img=escape(reference_image.png) 1.20 + // &mime=escape(image/ico) 1.21 + // &options=escape(-moz-parse-options:bpp=24;format=png) 1.22 + var getVars = {}; 1.23 + function buildValue(sValue) 1.24 + { 1.25 + if (/^\s*$/.test(sValue)) { 1.26 + return null; 1.27 + } 1.28 + if (/^(true|false)$/i.test(sValue)) { 1.29 + return sValue.toLowerCase() === "true"; 1.30 + } 1.31 + if (isFinite(sValue)) { 1.32 + return parseFloat(sValue); 1.33 + } 1.34 + if (isFinite(Date.parse(sValue))) { 1.35 + return new Date(sValue); 1.36 + } 1.37 + return sValue; 1.38 + } 1.39 + if (window.location.search.length > 1) { 1.40 + var couple, couples = window.location.search.substr(1).split("&"); 1.41 + for (var couplId = 0; couplId < couples.length; couplId++) { 1.42 + couple = couples[couplId].split("="); 1.43 + getVars[unescape(couple[0])] = couple.length > 1 ? 1.44 + buildValue(unescape(couple[1])) : null; 1.45 + } 1.46 + } 1.47 + 1.48 + // Create the image that we will load the reference image to 1.49 + var img = new Image(); 1.50 + 1.51 + // Create the canvas that we will draw the image img onto and 1.52 + // eventually call toDataURL to invoke the encoder on 1.53 + var canvas = document.createElement("canvas"); 1.54 + 1.55 + // Starts the test by loading the reference image 1.56 + function runTest() 1.57 + { 1.58 + // Load the reference image to start the test 1.59 + img.onload = onReferenceImageLoad; 1.60 + img.onerror = onReferenceImageLoad; 1.61 + img.src = getVars.img; 1.62 + } 1.63 + 1.64 + // Once the encoded image from the canvas is loaded we can 1.65 + // let the reftest compare 1.66 + function onEncodedImageLoad() 1.67 + { 1.68 + document.documentElement.removeAttribute("class"); 1.69 + } 1.70 + 1.71 + // Once the image loads async, we then draw the image onto the canvas, 1.72 + // and call canvas.toDataURL to invoke the encoder, and then set a new 1.73 + // image to the encoded data URL 1.74 + function onReferenceImageLoad() 1.75 + { 1.76 + // mimeType will hold the mime type of which encoder to invoke 1.77 + var mimeType = getVars.mime; 1.78 + // parseOptions will hold the encoder options to use 1.79 + var parseOptions = getVars.options; 1.80 + 1.81 + // Obtain the canvas and draw the reference image 1.82 + canvas.width = img.width; 1.83 + canvas.height = img.height; 1.84 + var ctx = canvas.getContext('2d') 1.85 + ctx.drawImage(img, 0, 0); 1.86 + 1.87 + // Obtain the data URL with parsing options if specified 1.88 + var dataURL; 1.89 + if (parseOptions) 1.90 + dataURL = canvas.toDataURL(mimeType, parseOptions); 1.91 + else 1.92 + dataURL = canvas.toDataURL(mimeType); 1.93 + 1.94 + // Setup async image loaded events 1.95 + var image_from_encoder = document.getElementById('image_from_encoder'); 1.96 + image_from_encoder.onload = onEncodedImageLoad; 1.97 + image_from_encoder.onerror = onEncodedImageLoad; 1.98 + 1.99 + // Only set the image if we have the correct mime type 1.100 + // because we want to fail the ref test if toDataURL fell 1.101 + // back to image/png 1.102 + if (dataURL.substring(0, mimeType.length+5) == "data:" + mimeType) { 1.103 + // Set the image to the BMP data URL 1.104 + image_from_encoder.src = dataURL; 1.105 + } else { 1.106 + // Blank image so that we won't have to timeout the reftest 1.107 + image_from_encoder.src = "data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D"; 1.108 + } 1.109 + }; 1.110 + </script> 1.111 +</head> 1.112 + 1.113 +<body onload="runTest()"> 1.114 +<img id="image_from_encoder"> 1.115 +</body> 1.116 +</html>