update examples
This commit is contained in:
parent
adb3355975
commit
679dc34dfa
3 changed files with 29 additions and 34 deletions
|
@ -4,7 +4,7 @@ Load the image module.
|
||||||
Ox.load('Image', function() {
|
Ox.load('Image', function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Load a sample image (about which you can read more on
|
Load a sample image (which has its own entry in
|
||||||
<a href="see http://en.wikipedia.org/wiki/Lenna">Wikipedia</a>).
|
<a href="see http://en.wikipedia.org/wiki/Lenna">Wikipedia</a>).
|
||||||
*/
|
*/
|
||||||
Ox.Image('png/lenna256.png', function(image) {
|
Ox.Image('png/lenna256.png', function(image) {
|
||||||
|
@ -52,8 +52,8 @@ Ox.load('Image', function() {
|
||||||
match = value.match(/^(\w+)\((.*?)\)$/),
|
match = value.match(/^(\w+)\((.*?)\)$/),
|
||||||
fn = match[1], args;
|
fn = match[1], args;
|
||||||
/*
|
/*
|
||||||
The <code>map</code> method takes a function as its argument, which
|
The `map` method takes a function as its argument, which we can't
|
||||||
we can't <code>JSON.parse</code>, but have to <code>eval</code>.
|
`JSON.parse`, but have to `eval`.
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
args = JSON.parse('[' + match[2] + ']');
|
args = JSON.parse('[' + match[2] + ']');
|
||||||
|
@ -61,21 +61,19 @@ Ox.load('Image', function() {
|
||||||
args = [eval('f = ' + match[2])];
|
args = [eval('f = ' + match[2])];
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
The <code>src</code> and <code>encode</code> methods are
|
The `src` and `encode` methods are asynchronous and take a callback
|
||||||
asynchronous and take a callback function.
|
function.
|
||||||
*/
|
*/
|
||||||
if (fn == 'src' || fn == 'encode') {
|
if (fn == 'src' || fn == 'encode') {
|
||||||
image[fn].apply(null, args.concat(function(image) {
|
image[fn].apply(null, args.concat(function(image) {
|
||||||
$image.attr({src: image.src()});
|
$image.attr({src: image.src()});
|
||||||
}));
|
}));
|
||||||
/*
|
/*
|
||||||
The <code>decode</code> method is asynchronous too, and its callback
|
The `decode` method is asynchronous too, and its callback function
|
||||||
function gets passed a string.
|
gets passed a string.
|
||||||
*/
|
*/
|
||||||
} else if (fn == 'decode') {
|
} else if (fn == 'decode') {
|
||||||
image[fn].apply(null, args.concat(function(str) {
|
image[fn].apply(null, args.concat(alert));
|
||||||
alert(str);
|
|
||||||
}));
|
|
||||||
/*
|
/*
|
||||||
All other methods simply return the image.
|
All other methods simply return the image.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
/*
|
/*
|
||||||
Ox.Image provides a pair of methods, <code>encode</code> and
|
Ox.Image provides a pair of methods, `encode` and `decode`, which can be used
|
||||||
<code>decode</code>, which can be used for
|
for <a href="http://en.wikipedia.org/wiki/Steganography">steganography</a>, i.e.
|
||||||
<a href="http://en.wikipedia.org/wiki/Steganography">steganography</a>, i.e. to
|
to add a hidden message to an image.<br><br> The signature of the `encode`
|
||||||
add a hidden message to an image.<br><br>
|
function is `image.encode(message, deflate, mode, callback)`. `deflate` turns
|
||||||
The signature of the <code>encode</code> function is
|
deflate-compression on or off, and `mode` determines which bits of the image the
|
||||||
<code>image.encode(message, deflate, mode, callback)</code>.
|
message will be written to — but for most purposes, the default values
|
||||||
<code>deflate</code> turns deflate-compression on or off, and <code>mode</code>
|
(`true` and `0`) are fine, so `deflate` and `mode` can be omitted.
|
||||||
determines which bits of the image the message will be written to — but
|
|
||||||
for most purposes, the default values (<code>true</code> and <code>0</code>)
|
In this example, we demonstrate a valid use case for `deflate` and `mode`: To
|
||||||
are fine, so <code>deflate</code> and <code>mode</code> can be omitted.<br>
|
encode an decoy message (a line of text), which will be relatively easy to
|
||||||
<br>
|
detect, and then the the actual message, (another image, itself containing
|
||||||
In this example, we demonstrate a valid use case for <code>deflate</code> and
|
another line of text), which will be harder to detect.
|
||||||
<code>mode</code>: To encode an decoy message (a line of text), which will be
|
|
||||||
relatively easy to detect, and then the the actual message, (another image,
|
|
||||||
itself containing another line of text), which will be harder to detect.
|
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -33,14 +30,14 @@ Ox.load('Image', function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
So we first encode two lines text into two images, by writing them bit by
|
So we first encode two lines text into two images, by writing them bit by
|
||||||
bit (without compression, <code>deflate = false</code>), into the least
|
bit (without compression, `deflate = false`), into the least significant bit
|
||||||
significant bit of each 8-bit RGB value (<code>mode = 1</code>). Then we
|
of each 8-bit RGB value (`mode = 1`). Then we encode one image into the
|
||||||
encode one image into the other: We take the (deflate-compressed,
|
other: We take the (deflate-compressed, `deflate = true`) data URL of the
|
||||||
<code>deflate = true</code>) data URL of the source image and flip, if
|
source image and flip, if needed, the second least significant bit of each
|
||||||
needed, the second least significant bit of each RGB value of the target
|
RGB value of the target image, so that the number of bits set to 1, modulo 2
|
||||||
image, so that the number of bits set to 1, modulo 2 (for example: 10101010
|
(for example: 10101010 -> 0), is the bit we're encoding (`mode = -1`). As
|
||||||
-> 0), is the bit we're encoding (<code>mode = -1</code>). As the least
|
the least significant bit remains untouched, this will preserve the encoded
|
||||||
significant bit remains untouched, this will preserve the encoded text.
|
text.
|
||||||
*/
|
*/
|
||||||
function encode(callback) {
|
function encode(callback) {
|
||||||
status('Load iceland.png');
|
status('Load iceland.png');
|
||||||
|
|
|
@ -4,7 +4,7 @@ This is probably the easiest way of displaying a complex data structure...
|
||||||
|
|
||||||
Ox.load('UI', function() {
|
Ox.load('UI', function() {
|
||||||
|
|
||||||
Ox.getJSON(Ox.PATH + '/Ox.Geo/json/Ox.Geo.json', function(data) {
|
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) {
|
||||||
|
|
||||||
Ox.TreeList({data: data}).appendTo(Ox.$body);
|
Ox.TreeList({data: data}).appendTo(Ox.$body);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue