web worker 的 self
2024-09-05 05:27:58
- A
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);
}
最新文章
- 研究SVM时安装的一些工具的方法
- Android学习参考
- [UVa1213]Sum of Different Primes(递推,01背包)
- IAR EWARM Example Download List
- python扩展实现方法--python与c混和编程
- NIO组件Selector详解
- linxu 挂载分区
- [LeetCode]题解(python):133-Clone Graph
- iOS图片缓存框架SDWebImage
- shell 字符串
- PHP字符串替换str_replace()函数4种用法详解
- Jmeter(二十五)_Xpath关联
- ruby klb.rb irb
- springmvc的前端控制器
- ADRC-active disturbance rejection control-自抗扰控制器
- Hibernate 二(一级缓存,多表设计之一对多)
- format格式化和函数
- 2018.11.07 codeforces559C. Gerald and Giant Chess(dp+组合数学)
- [javaSE] IO流(装饰设计模式)
- WPF实现夜间模式