如何在Chrome浏览器中编写新的图像格式解码器 [英] How to write a new image format decoder in Chrome Browser

查看:389
本文介绍了如何在Chrome浏览器中编写新的图像格式解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器对图像格式的支持很差。实际上只支持GIF,JPG,PNG和WebP。



我想要一个新的:



从最终用户的角度来看,他只会下载并安装Chrome扩展程序,他的浏览器将能够解码新的图像格式。

从web开发者的角度来看,新格式将是透明的,并且与标签img,canvas和css兼容。要显示JBIG2图像,他仍然使用:


 < img src =path / to / myImage.jbig2> 

  var myImage = new Image(); 
myImage.addEventListener('load',function(){
//在图片加载时在画布中插入
});
myImage.src ='path / to / myImage.jbig2';

.my-class {
background-image:url(path / to / myImage.jbig2);
}

问题不在于解码器本身。我预计会使用这种用C语言编写的 JBig2dec



问题是如何实现一个新的图像解码器?
在Chrome中,当我们必须运行C代码时,最好的解决方案是使用 Native Client Extension



甚至更好,我可以在这个NaCl网页上阅读:


图形,音频以及更多:运行渲染2D和3D图形,播放音频,响应鼠标和键盘事件,在多个线程上运行并直接访问内存的本地代码模块所有这些都不需要用户安装插件。

多媒体应用程序:用于处理声音,图像和电影的编解码器可以添加到浏览器在一个Native Client模块中。


但不幸的是,没有任何文档可以实现2D图形解码器。我只是猜测我需要为minetype注册钩子 image / jbig2。

有谁知道如何用NaCl来实现一个新的图像格式解码器?

解决方案

是的,我认为你所描述的解决方案大部分都是可行的,尽管你可能需要使用< embed src =...type =图片加载图片/ jbig2> ,而不是< img> p

基本上,你将:


  1. 使用 Native Client SDK

  2. 添加PPAPI插件入口点。查看NaCl SDK中的任何示例,或这里

  3. 在派生的实例
  4. a>类,实现虚拟函数 HandleDocumentLoad 。当您的Native Client插件用作mimetype加载器时,将调用此函数。您可以使用传递的 URLLoader 对象来读取您的JBig2文件。
  5. 创建一个 2D图形环境,并在其中显示解码图像的内容。查看NaCl SDK中的Graphics2D示例(examples / api / graphics2d)。

  6. 制作一个 Chrome扩展程序将自己注册为JBig2 Native Client mimetype处理程序(正如您已经找到的那样)。


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:

  1. Compile the JBig2 decoder using the Native Client SDK
  2. Add the PPAPI plugin entry point. See any of the examples in the NaCl SDK, or the tutorial here.
  3. In your derived Instance class, implement the virtual function HandleDocumentLoad. This function will be called when your Native Client plugin is used as a mimetype loader. You can use the URLLoader object that is passed to read your JBig2 file.
  4. Create a 2D graphics context, and display the contents of the decoded image in it. Take a look at the Graphics2D example in the NaCl SDK (examples/api/graphics2d).
  5. Make a Chrome extension that registers itself as a JBig2 Native Client mimetype handler (as you've already found).

这篇关于如何在Chrome浏览器中编写新的图像格式解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆