forked from idevelop/ascii-camera
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
229 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
Copyright (c) 2013 Andrei Gheorghe | ||
MIT License | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
Copyright (c) 2013 Andrei Gheorghe | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>ascii cam</title> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="css/main.css"/> | ||
</head> | ||
<body> | ||
<h1 id="info">Please allow this page to access your camera.</h1> | ||
|
||
<div id="notSupported"> | ||
<h1>Your browser does not support the Camera API.</h1> | ||
<img src="http://idevelop.github.com/ascii-camera/images/screenshot.png" align="center" /> | ||
</div> | ||
|
||
<pre id="ascii"></pre> | ||
|
||
<a href="https://github.com/idevelop/ascii-camera" id="fork" target="_blank"><img src="images/forkme.png" alt="Fork me on GitHub"></a> | ||
|
||
<script src="script/camera.js"></script> | ||
<script src="script/ascii.js"></script> | ||
<script src="script/app.js"></script> | ||
</body> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>ascii cam</title> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="css/main.css"/> | ||
</head> | ||
<body> | ||
<h1 id="info">Please allow this page to access your camera.</h1> | ||
|
||
<div id="notSupported"> | ||
<h1>Your browser does not support the Camera API.</h1> | ||
<img src="http://idevelop.github.com/ascii-camera/images/screenshot.png" align="center" /> | ||
</div> | ||
|
||
<pre id="ascii"></pre> | ||
|
||
<a href="https://github.com/idevelop/ascii-camera" id="fork" target="_blank"><img src="images/forkme.png" alt="Fork me on GitHub"></a> | ||
|
||
<script src="script/camera.js"></script> | ||
<script src="script/ascii.js"></script> | ||
<script src="script/app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
/* | ||
* ASCII Camera | ||
* http://idevelop.github.com/ascii-camera/ | ||
* | ||
* Copyright 2013, Andrei Gheorghe (http://github.com/idevelop) | ||
* Released under the MIT license | ||
*/ | ||
|
||
(function() { | ||
var asciiContainer = document.getElementById("ascii"); | ||
|
||
camera.init({ | ||
width: 160, | ||
height: 120, | ||
fps: 30, | ||
mirror: true, | ||
|
||
onFrame: function(canvas) { | ||
ascii.fromCanvas(canvas, { | ||
// contrast: 128, | ||
callback: function(asciiString) { | ||
asciiContainer.innerHTML = asciiString; | ||
} | ||
}); | ||
}, | ||
|
||
onSuccess: function() { | ||
document.getElementById("info").style.display = "none"; | ||
}, | ||
|
||
onError: console.error, | ||
|
||
onNotSupported: function() { | ||
document.getElementById("info").style.display = "none"; | ||
document.getElementById("notSupported").style.display = "block"; | ||
} | ||
}); | ||
/* | ||
* ASCII Camera | ||
* http://idevelop.github.com/ascii-camera/ | ||
* | ||
* Copyright 2013, Andrei Gheorghe (http://github.com/idevelop) | ||
* Released under the MIT license | ||
*/ | ||
|
||
(function() { | ||
var asciiContainer = document.getElementById("ascii"); | ||
|
||
camera.init({ | ||
width: 160, | ||
height: 120, | ||
fps: 30, | ||
mirror: true, | ||
|
||
onFrame: function(canvas) { | ||
ascii.fromCanvas(canvas, { | ||
// contrast: 128, | ||
callback: function(asciiString) { | ||
asciiContainer.innerHTML = asciiString; | ||
} | ||
}); | ||
}, | ||
|
||
onSuccess: function() { | ||
document.getElementById("info").style.display = "none"; | ||
}, | ||
|
||
onError: console.error, | ||
|
||
onNotSupported: function() { | ||
document.getElementById("info").style.display = "none"; | ||
document.getElementById("notSupported").style.display = "block"; | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
// Author: Andrei Gheorghe (http://github.com/idevelop) | ||
|
||
var ascii = (function() { | ||
function asciiFromCanvas(canvas, options) { | ||
// Original code from http://www.nihilogic.dk/labs/jsascii/ | ||
// Heavily modified by Andrei Gheorghe (http://github.com/idevelop) | ||
|
||
var characters = (" .,:;i1tfLCG08@").split(""); | ||
|
||
var context = canvas.getContext("2d"); | ||
var canvasWidth = canvas.width; | ||
var canvasHeight = canvas.height; | ||
|
||
var asciiCharacters = ""; | ||
|
||
// calculate contrast factor | ||
// http://www.dfstudios.co.uk/articles/image-processing-algorithms-part-5/ | ||
var contrastFactor = (259 * (options.contrast + 255)) / (255 * (259 - options.contrast)); | ||
|
||
var imageData = context.getImageData(0, 0, canvasWidth, canvasHeight); | ||
for (var y = 0; y < canvasHeight; y += 2) { // every other row because letters are not square | ||
for (var x = 0; x < canvasWidth; x++) { | ||
// get each pixel's brightness and output corresponding character | ||
|
||
var offset = (y * canvasWidth + x) * 4; | ||
|
||
var color = { | ||
red: imageData.data[offset], | ||
green: imageData.data[offset + 1], | ||
blue: imageData.data[offset + 2], | ||
alpha: imageData.data[offset + 3] | ||
}; | ||
|
||
// increase the contrast of the image so that the ASCII representation looks better | ||
// http://www.dfstudios.co.uk/articles/image-processing-algorithms-part-5/ | ||
var contrastedColor = { | ||
red: bound(Math.floor((color.red - 128) * contrastFactor) + 128, [0, 255]), | ||
green: bound(Math.floor((color.green - 128) * contrastFactor) + 128, [0, 255]), | ||
blue: bound(Math.floor((color.blue - 128) * contrastFactor) + 128, [0, 255]), | ||
alpha: color.alpha | ||
}; | ||
|
||
// calculate pixel brightness | ||
// http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color | ||
var brightness = (0.299 * contrastedColor.red + 0.587 * contrastedColor.green + 0.114 * contrastedColor.blue) / 255; | ||
|
||
var character = characters[(characters.length - 1) - Math.round(brightness * (characters.length - 1))]; | ||
|
||
asciiCharacters += character; | ||
} | ||
|
||
asciiCharacters += "\n"; | ||
} | ||
|
||
options.callback(asciiCharacters); | ||
} | ||
|
||
function bound(value, interval) { | ||
return Math.max(interval[0], Math.min(interval[1], value)); | ||
} | ||
|
||
return { | ||
fromCanvas: function(canvas, options) { | ||
options = options || {}; | ||
options.contrast = (typeof options.contrast === "undefined" ? 128 : options.contrast); | ||
options.callback = options.callback || doNothing; | ||
|
||
return asciiFromCanvas(canvas, options); | ||
} | ||
}; | ||
})(); | ||
// Author: Andrei Gheorghe (http://github.com/idevelop) | ||
|
||
var ascii = (function() { | ||
function asciiFromCanvas(canvas, options) { | ||
// Original code by Jacob Seidelin (http://www.nihilogic.dk/labs/jsascii/) | ||
// Heavily modified by Andrei Gheorghe (http://github.com/idevelop) | ||
|
||
var characters = (" .,:;i1tfLCG08@").split(""); | ||
|
||
var context = canvas.getContext("2d"); | ||
var canvasWidth = canvas.width; | ||
var canvasHeight = canvas.height; | ||
|
||
var asciiCharacters = ""; | ||
|
||
// calculate contrast factor | ||
// http://www.dfstudios.co.uk/articles/image-processing-algorithms-part-5/ | ||
var contrastFactor = (259 * (options.contrast + 255)) / (255 * (259 - options.contrast)); | ||
|
||
var imageData = context.getImageData(0, 0, canvasWidth, canvasHeight); | ||
for (var y = 0; y < canvasHeight; y += 2) { // every other row because letters are not square | ||
for (var x = 0; x < canvasWidth; x++) { | ||
// get each pixel's brightness and output corresponding character | ||
|
||
var offset = (y * canvasWidth + x) * 4; | ||
|
||
var color = { | ||
red: imageData.data[offset], | ||
green: imageData.data[offset + 1], | ||
blue: imageData.data[offset + 2], | ||
alpha: imageData.data[offset + 3] | ||
}; | ||
|
||
// increase the contrast of the image so that the ASCII representation looks better | ||
// http://www.dfstudios.co.uk/articles/image-processing-algorithms-part-5/ | ||
var contrastedColor = { | ||
red: bound(Math.floor((color.red - 128) * contrastFactor) + 128, [0, 255]), | ||
green: bound(Math.floor((color.green - 128) * contrastFactor) + 128, [0, 255]), | ||
blue: bound(Math.floor((color.blue - 128) * contrastFactor) + 128, [0, 255]), | ||
alpha: color.alpha | ||
}; | ||
|
||
// calculate pixel brightness | ||
// http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color | ||
var brightness = (0.299 * contrastedColor.red + 0.587 * contrastedColor.green + 0.114 * contrastedColor.blue) / 255; | ||
|
||
var character = characters[(characters.length - 1) - Math.round(brightness * (characters.length - 1))]; | ||
|
||
asciiCharacters += character; | ||
} | ||
|
||
asciiCharacters += "\n"; | ||
} | ||
|
||
options.callback(asciiCharacters); | ||
} | ||
|
||
function bound(value, interval) { | ||
return Math.max(interval[0], Math.min(interval[1], value)); | ||
} | ||
|
||
return { | ||
fromCanvas: function(canvas, options) { | ||
options = options || {}; | ||
options.contrast = (typeof options.contrast === "undefined" ? 128 : options.contrast); | ||
options.callback = options.callback || doNothing; | ||
|
||
return asciiFromCanvas(canvas, options); | ||
} | ||
}; | ||
})(); |
Oops, something went wrong.