Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5548)

Unified Diff: chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js

Issue 2544203004: Display images in multiline Braille
Patch Set: Addressed Comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
diff --git a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
index 6cecbd94e22171373885a40e976446c256009725..4ce77f1f54229d363d8ff0c71402708c837e60a9 100644
--- a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
+++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
@@ -119,6 +119,68 @@ cvox.BrailleDisplayManager.prototype.setContent = function(
/**
+ * Takes an image, in the form of a data url, and displays it in braille
+ * onto the physical braille display and the virtual braille captions display.
+ * @param {!string} imageUrl The image, in the form of a data url.
+ */
+cvox.BrailleDisplayManager.prototype.setImageContent = function(imageUrl) {
+ if (!this.displayState_.available) {
+ return;
+ }
+
+ var rows = this.displayState_.textRowCount;
+ var columns = this.displayState_.textColumnCount;
+ var imageDataUrl = imageUrl;
+ var imgElement = document.createElement('img');
+ imgElement.src = imageDataUrl;
+ var canvas1 = document.createElement('canvas');
dmazzoni 2016/12/06 07:39:42 Nit: maybe just |canvas| since you don't have more
ultimatedbz 2016/12/07 22:03:48 Done.
+ var context = canvas1.getContext('2d');
+ canvas1.width = columns * 2;
+ canvas1.height = rows * 4;
+ context.drawImage(imgElement, 0, 0, canvas1.width, canvas1.height);
+ var imageData = context.getImageData(0, 0, canvas1.width, canvas1.height);
+ var data = imageData.data;
+ var outputData = [];
+
+ // Convert image to black and white.
+ for (var i = 0; i < data.length; i += 4) {
+ // Show if the alpha value is visible (above 20) and the pixel is not
+ // white (under 600).
+ var show = (data[i] +
+ data[i + 1] +
+ data[i + 2] <= 200 * 3) &&
+ (data[i + 3]) >= 20;
+ outputData.push(show);
+ }
+
+ // Convert to Braille.
+ var buf = new ArrayBuffer(rows * columns);
+ var view = new Uint8Array(buf);
+ var coordsToBrailleDot = [0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80];
+ for (var i = 0; i < rows; i++) {
+ for (var j = 0; j < columns; j++) {
+ //Index in braille array
+ var index = i * columns + j;
+ view[index] = 0;
+ for (var x = 0; x < 2; x++) {
+ for (var y = 0; y < 4; y++) {
+ if (outputData[((i * columns * 4 + j + y * columns) * 2 + x)] == 1)
+ view[index] += coordsToBrailleDot[x * 4 + y];
+ }
+ }
+ }
+ }
+
+ if (this.realDisplayState_.available) {
+ chrome.brailleDisplayPrivate.writeDots(buf, buf.byteLength, 1);
+ }
+ if (cvox.BrailleCaptionsBackground.isEnabled()) {
+ cvox.BrailleCaptionsBackground.setImageContent(buf, rows, columns);
+ }
+};
+
+
+/**
* Sets the command listener. When a command is invoked, the listener will be
* called with the BrailleKeyEvent corresponding to the command and the content
* that was present on the display when the command was invoked. The content

Powered by Google App Engine
This is Rietveld 408576698