Self of web Worker

Source: Internet
Author: User

    • A self object, which is the global object representing the worker in this scope.
    • The translation of the Self object is unknown.

1 //Call the Invertimage method, this worker receives a message from the calling script.2 //The ' Self ' object contains the-Methods a Web worker can access apart from those it3 //defines and creates itself4 //The Invertimage method is called when the worker receives a message from the script that made the call. The "Self" object contains a method that the Web worker can access only those methods that are defined and created by the Web worker itself. 5Self.addeventlistener ("message", Invertimage,false);6 7 //Define a function to take an image and invert it, pixel by pixel, using it raw data8 //defines a function that is used as the raw data to receive an image, in pixels to perform the inverse operation on a granular basis. 9 functionInvertimage (e) {Ten  One     //The ' data ' property of the ' message ' event contains the pixel data passed from A     //The calling script -     //The "Data" property of the "message" event contains the pixel data contained in the script from which the call was made.  -     varMessage =E.data, the  -         //The ' data ' property of the message passed contains the RAW image pixel data -         //The "data" attribute in the sent message contains the pixel data of the original image.  -Imagepixels =Message.data, +x = 0, -Len =imagepixels.length; +  A     //Loop through each pixel, inverting its value within the original pixel data array. at     //Pixel data is arranged in groups of 4 values, representing the red, green, blue, and -     //Opacity values of each of the visible screen pixel. We therefore loop through in jumps of 4 -     //On each iteration -     //loops through each pixel so that the values held in the array of the original pixel data are inverted. The pixel data is grouped by 4 values, representing the red, green, blue, and transparency values of the pixels seen on the screen, respectively. Therefore, the addend of each iteration of the loop is 4.  -      for(; x < len; x + = 4) { -  in         //to invert a pixel's value, subtract it from the maximum possible value, which is 255 -         //to reverse a pixel value, you can subtract it with the maximum possible value (that is, 255).  toIMAGEPIXELS[X] = 255-Imagepixels[x]; +Imagepixels[x + 1] = 255-imagepixels[x + 1]; -Imagepixels[x + 2] = 255-imagepixels[x + 2]; the     } *  $     //Finally, post a message containing the updated pixel data back to the calling scriptPanax Notoginseng     //Finally, the message containing the updated pixel data is sent back to the script that made the call.  - self.postmessage (message); the}

Self of web Worker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.