Update web-platform-tests to revision 687b6cba3385c4c2ca85f44fe072961e651621b5

This commit is contained in:
WPT Sync Bot 2019-04-08 21:47:49 -04:00
parent cd579f6746
commit 1a4444a557
45 changed files with 594 additions and 259 deletions

View file

@ -263,25 +263,43 @@ function extractImageData(img) {
}
function decodeImageData(rgba) {
var rgb = new Uint8ClampedArray(rgba.length);
let decodedBytes = new Uint8ClampedArray(rgba.length);
let decodedLength = 0;
// RGBA -> RGB.
var rgb_length = 0;
for (var i = 0; i < rgba.length; ++i) {
// Skip alpha component.
if (i % 4 == 3)
continue;
for (var i = 0; i + 12 <= rgba.length; i += 12) {
// A single byte is encoded in three pixels. 8 pixel octets (among
// 9 octets = 3 pixels * 3 channels) are used to encode 8 bits,
// the most significant bit first, where `0` and `255` in pixel values
// represent `0` and `1` in bits, respectively.
// This encoding is used to avoid errors due to different color spaces.
const bits = [];
for (let j = 0; j < 3; ++j) {
bits.push(rgba[i + j * 4 + 0]);
bits.push(rgba[i + j * 4 + 1]);
bits.push(rgba[i + j * 4 + 2]);
// rgba[i + j * 4 + 3]: Skip alpha channel.
}
// The last one element is not used.
bits.pop();
// Decode a single byte.
let byte = 0;
for (let j = 0; j < 8; ++j) {
byte <<= 1;
if (bits[j] >= 128)
byte |= 1;
}
// Zero is the string terminator.
if (rgba[i] == 0)
if (byte == 0)
break;
rgb[rgb_length++] = rgba[i];
decodedBytes[decodedLength++] = byte;
}
// Remove trailing nulls from data.
rgb = rgb.subarray(0, rgb_length);
var string_data = (new TextDecoder("ascii")).decode(rgb);
decodedBytes = decodedBytes.subarray(0, decodedLength);
var string_data = (new TextDecoder("ascii")).decode(decodedBytes);
return JSON.parse(string_data);
}

View file

@ -60,20 +60,17 @@ class Image:
def encode_string_as_bmp_image(string_data):
data_bytes = array.array("B", string_data)
num_bytes = len(data_bytes)
# Convert data bytes to color data (RGB).
# Encode data bytes to color data (RGB), one bit per channel.
# This is to avoid errors due to different color spaces used in decoding.
color_data = []
num_components = 3
rgb = [0] * num_components
i = 0
for byte in data_bytes:
component_index = i % num_components
rgb[component_index] = byte
if component_index == (num_components - 1) or i == (num_bytes - 1):
color_data.append(tuple(rgb))
rgb = [0] * num_components
i += 1
p = [int(x) * 255 for x in '{0:08b}'.format(byte)]
color_data.append((p[0], p[1], p[2]))
color_data.append((p[3], p[4], p[5]))
color_data.append((p[6], p[7], 0))
# Render image.
num_pixels = len(color_data)