zoukankan      html  css  js  c++  java
  • web worker 的 self

    • self object, which is the global object representing the worker in this scope.
    • 对self对象的译法,未知妥否。
     1 // Call the invertImage method when this worker receives a message from the calling script.
     2 // The ‘self’ object contains the only methods a web worker can access apart from those it
     3 // defines and creates itself
     4 //当此worker收到自来于发出调用的脚本的消息时,调用invertImage方法。“self”对象所包含的web worker所能访问的方法就只有那些由web worker自己本身进行定义和创建的方法。
     5 self.addEventListener("message", invertImage, false);
     6 
     7 // Define a function to take an image and invert it, pixel by pixel, using its raw data
     8 //定义一个函数,用作接收图像的原始数据,按像素来逐粒逐粒地实施反相操作。
     9 function invertImage(e) {
    10 
    11     // The ‘data’ property of the ‘message’ event contains the pixel data passed from
    12     // the calling script
    13     //“message”事件的“data”属性包含着从发出调用的脚本所包含的像素数据。
    14     var message = e.data,
    15 
    16         // The ‘data’ property of the message passed contains the raw image pixel data
    17         //所发送过来的消息中的“data”属性包含着原始图像的像素数据。
    18         imagePixels = message.data,
    19         x = 0,
    20         len = imagePixels.length;
    21 
    22     // Loop through each pixel, inverting its value within the original pixel data array.
    23     // Pixel data is arranged in groups of 4 values, representing the red, green, blue, and
    24     // opacity values of each visible screen pixel. We therefore loop through in jumps of 4
    25     // on each iteration
    26     //循环遍历每一粒像素,使原始像素数据的数组中所保存的值反相。像素数据按4个值进行分组,分别表示屏幕上所见像素的红、绿、蓝和透明度数值。因此,循环的每轮迭代的加数为4。
    27     for (; x < len; x += 4) {
    28 
    29         // To invert a pixel’s value, subtract it from the maximum possible value, which is 255
    30         //要对像素值进行反相,可以用最大的可能值(即255)进行相减。
    31         imagePixels[x] = 255 - imagePixels[x];
    32         imagePixels[x + 1] = 255 - imagePixels[x + 1];
    33         imagePixels[x + 2] = 255 - imagePixels[x + 2];
    34     }
    35 
    36     // Finally, post a message containing the updated pixel data back to the calling script
    37     //最后,把包含着更新后的像素数据的消息发送回至发出调用的脚本。
    38     self.postMessage(message);
    39 }
  • 相关阅读:
    dup/dup2函数
    read/write函数
    lseek函数
    流程控制
    vim普通模式
    vim实用技巧1
    python源代码解读
    python变量命名规则
    python之字符串2
    Docker系列文章
  • 原文地址:https://www.cnblogs.com/da3j/p/4287050.html
Copyright © 2011-2022 走看看