Implementation of Photoshop's key technologies Series 1: Layers

Source: Internet
Author: User

In the field of Image Processing (non-recognition), Adobe Photoshop is an absolute giant in the industry, its rich functions and efficient processing capabilities have won the favor of art, printing, scientific research, networks, and other people. As a programmer, apart from the developer coding capabilities of Adobe, I am eager to know what secrets are hidden in its charming appearance. In this series of articles, the author will try to explain how to implement layers in his own way through a series of simple descriptions.

One of the simplest and easiest ways to think of is that each layer is a class. Indeed, this is a feasible and extremely effective method, which is also used in my imageshop, as a result, the following describes some of the conditions required to implement layers in this way.

Assume that the name of our layer class is cimage. First, we need a function: loadpicturefromfile, which is to load the image from the file. This is described in a separate chapter. After obtaining a complete set of image data, we will record the width, height, and depth of the image (I .e., pattern, divided into bitmap, index color, gray level, RGB, imageshop can also be divided into rb24 and rgb32), scan row width (for later computing speed), color palette (if any), and the first address of the image in memory. Then we need to show him, which we will discuss below.

After loading the image, because it is a member of the layer, we also need to define other attributes, such as the left and top of the layer) visibility, caption, blendmode, and hasmask. In the cimage class, we only need to provide these attributes, you don't have to worry about the implementation methods of these attributes.

With the above foundation, we also need a class or control to manage and organize these classes. The control is defined as layercontainer, he is responsible for the final output of all layers and the external representation of each layer (User Interface). To facilitate the display of some properties of each layer, we also define a control called layeritem, the control provides attributes such as visible, caption, and hasmask that are equivalent to external display to bind each layer. In layercontainer, use the addbackgroundlayer, addlayer, deletelayer, deletelayer, duplicatelayer, and movelayer functions to coordinate the positions of each layer. The addbackgroundlayer function determines the size of the entire image canvas. In order to display a mixed image, we also need to define a special cimage class. The width and height of this class are the same as the size of the canvas, then, the final blending effect is calculated based on the blending mode and transparency of each layer. Considering the display of 32-bit images with transparent channels and the implementation of transparency, the cimage class for output display must define 32-bit. For images of different modes, although this will increase the amount of computing used for output to a certain extent, the programming implementation is much easier.

For image output, if the canvas is computed every time you make changes to the properties of the layer, the output speed is unbearable, especially for the response process of some mouse. In fact, there is no need to do so. On a computer, the screen is only that big, no matter how big your original image is, the display range is certain, that is, the area of change that the user can feel is limited (the screen size-minus your menu, status bar, toolbar, and some other space). Therefore, we only need to calculate the part to be updated, and call related functions to update him.

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.