• self object, which is the global object representing the worker in this scope.
  • 对self对象的译法,未知妥否。
 // Call the invertImage method when this worker receives a message from the calling script.
// The ‘self’ object contains the only methods a web worker can access apart from those it
// defines and creates itself
//当此worker收到自来于发出调用的脚本的消息时,调用invertImage方法。“self”对象所包含的web worker所能访问的方法就只有那些由web worker自己本身进行定义和创建的方法。
self.addEventListener("message", invertImage, false); // Define a function to take an image and invert it, pixel by pixel, using its raw data
//定义一个函数,用作接收图像的原始数据,按像素来逐粒逐粒地实施反相操作。
function invertImage(e) { // The ‘data’ property of the ‘message’ event contains the pixel data passed from
// the calling script
//“message”事件的“data”属性包含着从发出调用的脚本所包含的像素数据。
var message = e.data, // The ‘data’ property of the message passed contains the raw image pixel data
//所发送过来的消息中的“data”属性包含着原始图像的像素数据。
imagePixels = message.data,
x = 0,
len = imagePixels.length; // Loop through each pixel, inverting its value within the original pixel data array.
// Pixel data is arranged in groups of 4 values, representing the red, green, blue, and
// opacity values of each visible screen pixel. We therefore loop through in jumps of 4
// on each iteration
//循环遍历每一粒像素,使原始像素数据的数组中所保存的值反相。像素数据按4个值进行分组,分别表示屏幕上所见像素的红、绿、蓝和透明度数值。因此,循环的每轮迭代的加数为4。
for (; x < len; x += 4) { // To invert a pixel’s value, subtract it from the maximum possible value, which is 255
//要对像素值进行反相,可以用最大的可能值(即255)进行相减。
imagePixels[x] = 255 - imagePixels[x];
imagePixels[x + 1] = 255 - imagePixels[x + 1];
imagePixels[x + 2] = 255 - imagePixels[x + 2];
} // Finally, post a message containing the updated pixel data back to the calling script
//最后,把包含着更新后的像素数据的消息发送回至发出调用的脚本。
self.postMessage(message);
}

最新文章

  1. 研究SVM时安装的一些工具的方法
  2. Android学习参考
  3. [UVa1213]Sum of Different Primes(递推,01背包)
  4. IAR EWARM Example Download List
  5. python扩展实现方法--python与c混和编程
  6. NIO组件Selector详解
  7. linxu 挂载分区
  8. [LeetCode]题解(python):133-Clone Graph
  9. iOS图片缓存框架SDWebImage
  10. shell 字符串
  11. PHP字符串替换str_replace()函数4种用法详解
  12. Jmeter(二十五)_Xpath关联
  13. ruby klb.rb irb
  14. springmvc的前端控制器
  15. ADRC-active disturbance rejection control-自抗扰控制器
  16. Hibernate 二(一级缓存,多表设计之一对多)
  17. format格式化和函数
  18. 2018.11.07 codeforces559C. Gerald and Giant Chess(dp+组合数学)
  19. [javaSE] IO流(装饰设计模式)
  20. WPF实现夜间模式

热门文章

  1. go语言interface学习
  2. InnoDB引擎中的索引与算法9
  3. java 接口方法超时异常处理 设置超时时间
  4. CrawlSpider ---&gt; 通用爬虫 项目流程
  5. Python——DataFrame转list(包含两种)
  6. Codeforces 1187 F - Expected Square Beauty
  7. python中常见的日期处理方法
  8. MySQL之profiling性能分析(在5.6.14版本被丢弃)
  9. string::clear
  10. XSS攻击(跨站攻击)