Skip to content

Commit

Permalink
README: Add percetual encoding idea
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnor committed Jun 4, 2016
1 parent 3c9546c commit 163dd63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ Putting serialized IPLD structure into database/IPFS as JSON blob?
[GEGL](http://gegl.org), the image processing library used by imgflo-server and GIMP
* Consider extending for video
## Ideas
### Perceptual encoding
Right now, we can deducplicate parts of images when the encoded representation of tiles are identical.
However even the tiniest, impercievable change, like a 1 bit quantification error, will invalidate deduplication.
Some [existing discussion here](https://github.com/ipfs/faq/issues/15), with references to academic papers.
## Contributors
* [@Kubuxu](https://github.com/Kubuxu)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"mocha": "^2.5.3"
},
"dependencies": {
"canvas": "^1.3.16",
"ipfs-api": "^4.1.0",
"ipfs-ipld": "^2.0.0",
"ipld": "^0.6.0"
Expand Down
19 changes: 19 additions & 0 deletions src/image.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

ipfsIPLD = require 'ipfs-ipld'
ipld = require 'ipld'
Canvas = require 'canvas'
Image = Canvas.Image

# TODO: use a plain JS object or class, with have save/load to IPLD/MerkleDAG
serializeImage = (shape, tilehashes) ->
image =
'ipld-image-version': 1
Expand Down Expand Up @@ -41,6 +44,22 @@ repeatedImage = (shape, tilehash) ->
tiles.push tilehash
return tiles

# TODO: don't instead render into memory, find out how to concat PNG IDAT chunks
# TODO: support cropping
# TODO: support
renderBlob = (image) ->
imageSize =
x: image.tilesize.x*image.tiles.x
y: image.tilesize.y*image.tiles.y
console.log ''

canvas = new Canvas(200, 200)
img = new Image;
img.src = canvas.toBuffer();
ctx.drawImage(img, 0, 0, 50, 50);
ctx.drawImage(img, 50, 0, 50, 50);
ctx.drawImage(img, 100, 0, 50, 50);

module.exports =
repeat: repeatedImage
construct: serializeImage
Expand Down

0 comments on commit 163dd63

Please sign in to comment.