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

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

Issue 2544203004: Display images in multiline Braille
Patch Set: Rebased back onto Master 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 91352693897ff7619798b5995d8ec6485060c439..a8e0b69d77e4c58b22abfd3df7292088e9a2182f 100644
--- a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
+++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
@@ -87,6 +87,8 @@ cvox.BrailleDisplayManager = function(translatorManager) {
*/
this.brailleToText_ = [];
+ this.displayingImage_ = false;
+
translatorManager.addChangeListener(function() {
this.translateContent_(this.content_, this.expansionType_);
}.bind(this));
@@ -134,11 +136,75 @@ cvox.BrailleDisplayManager.CURSOR_DOTS_ = 1 << 6 | 1 << 7;
*/
cvox.BrailleDisplayManager.prototype.setContent = function(
content, expansionType) {
+ this.displayingImage_ = false;
this.translateContent_(content, expansionType);
};
/**
+ * 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.
David Tseng 2016/12/08 16:44:22 primitive type doesn't require nullable i.e. @para
ultimatedbz 2016/12/08 19:29:05 Done.
+ */
+cvox.BrailleDisplayManager.prototype.setImageContent = function(imageUrl) {
+ this.displayingImage_ = true;
+ 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 canvas = document.createElement('canvas');
+ var context = canvas.getContext('2d');
+ canvas.width = columns * 2;
+ canvas.height = rows * 4;
+ context.drawImage(imgElement, 0, 0, canvas.width, canvas.height);
+ var imageData = context.getImageData(0, 0, canvas.width, canvas.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]) == 255;
+ outputData.push(show);
+ }
+
+ // Convert to Braille.
+ var buf = new ArrayBuffer(rows * columns);
+ var view = new Uint8Array(buf);
+ var coordsToBrailleDot = [0x1, 0x2, 0x4, 0x40, 0x8, 0x10, 0x20, 0x80];
+ for (var i = 0; i < rows; i++) {
+ for (var j = 0; j < columns; j++) {
+ //Index in braille array
David Tseng 2016/12/08 16:44:22 nit: period at end.
ultimatedbz 2016/12/08 19:29:05 Done.
+ 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)])
+ 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
@@ -190,7 +256,7 @@ cvox.BrailleDisplayManager.prototype.onCaptionsStateChanged_ = function() {
/** @private */
cvox.BrailleDisplayManager.prototype.refresh_ = function() {
- if (!this.displayState_.available) {
+ if (!this.displayState_.available || this.displayingImage_) {
David Tseng 2016/12/08 16:44:22 Panning support in v2? TODO(dmazzoni) perhaps? You
return;
}
var viewPort = this.panStrategy_.viewPort;

Powered by Google App Engine
This is Rietveld 408576698