Browsers have poor support of image formats. Actually only GIF, JPG, PNG and WebP are supported.
I would like to had a new one : JBIG2
From the end user point of view, he will only download and install a chrome extension and his browser will be able to decode the new image format.
From the web developer point of view, new format will be transparent and compatible with tag img, canvas and css. To display JBIG2 images, he still uses :
<img src=“path/to/myImage.jbig2”>
or
var myImage = new Image();
myImage.addEventListener( 'load', function() {
// insert in canvas, when image is loaded
});
myImage.src = 'path/to/myImage.jbig2';
or
.my-class {
background-image: url( “path/to/myImage.jbig2”);
}
The problem isn’t the decoder itself. I foresee to use this one JBig2dec written in C language.
The problem is how to implement a new image decoder? In Chrome, when we have to run C code the best solution is to use Native Client Extension.
And even better, I can read on this NaCl web page :
Graphics, audio, and much more: Run native code modules that render 2D and 3D graphics, play audio, respond to mouse and keyboard events, run on multiple threads, and access memory directly all without requiring the user to install a plugin.
Multimedia applications: Codecs for processing sounds, images, and movies can be added to the browser in a Native Client module.
But unfortunately there is no documentation neither sample to implement a 2D graphic decoder. I just guess that I need to register an hook for the minetype image/jbig2.
Does anyone know how to implement a new image format decoder with NaCl ?
Yes, I think the solution you've described will mostly work, though you may need to load the image using an
<embed src="..." type="image/jbig2">
instead of<img>
.Basically, you will: