[Released] Photoshop plug-in for reading and writing ICO Icon files

Source: Internet
Author: User
Tags transparent color scale image

This is a file format plug-in I wrote for Photoshop. icoformat is used to read and write windows Icon files (the extension is ICO, cur ). PS plug-ins in the icon file format have been written by a foreigner many years ago. However, the plug-ins I provide now provide better functions and have enough reasons to replace the plug-ins provided by foreigners.

I do not remember the characteristics of the foreign plug-ins. The memory comparison is as follows:

(1) When a foreigner plug-in is selected in the file dialog box, the ICO file cannot be displayed. It may be because of a problem with his pipl resource writing. My plug-ins do not have this problem.

(2) When a foreigner's plug-in opens a file containing multiple images, it cannot be previewed. However, I provide a preview image on the dialog box, which is more friendly to users.

(3) Foreign plug-ins cannot handle the transparent part of the icon very well (in memory), but with my plug-ins, you can set the transparent part very well.

(4) Foreign plug-ins cannot save the multi-image anti-sawtooth icon of the XP system, while my plug-ins can save it as an anti-sawtooth icon, and automatically generate images of other quality and standard sizes (I think this is the most important reason to replace the foreign plug-in ).

(5) The image is degraded using the octotree.Algorithm, The image quality after the downgrade is better than that of software such as iconworkshop.

(6) my plug-in is Scripting-aware (that is, the plug-in parameters will be stored in the PS script system). You can remember your settings during runtime.

(7) my plug-in can open and save the cursor (cur) file. It seems that the plug-in of foreigners cannot. In addition, I may continue to develop other functions such as import icons from PE files.

The following describes and introduces the plug-in. This plug-in has a total of four dialogs, which are about the dialog box, the image selection dialog box (when opening the file), the transparent part of the Settings dialog box, and the image save option Setting dialog box. I will illustrate it one by one.

 

(1) Image Selection dialog box

 

When you open an icon that contains multiple images, the image selection dialog box is displayed:

Here, the user is required to select an image to be opened from the file. "adding and mask or alhpa as an independent channel" means that if it is an icon below 32 bpp, and mask is added to the new PS channel. If it is a 32 BPP icon, the alpha channel is added to the new PS channel. "Whether to display the board grid" is for the image preview image on the dialog box. If you select this option, you actually call the callback function in PS to draw the image, otherwise, it is drawn through the Win32 GDI function.

 

(2) image quality selection dialog box

 

When saving files, different dialog boxes are displayed based on the image mode. If the current image mode is RGB, the following dialog box is displayed, asking the user to set the icon for saving the quality. If you select the anti-sawtooth icon, I will automatically add other images of size and color quality to the file (the final file may contain 3 to 12 images, the number is determined based on the relationship between the file size and the standard image size). The anti-sawtooth icon generated by this plug-in is generated based on msdn's requirements for the icons used by the XP system, therefore, the anti-sawtooth icon generated by this plug-in can be directly imported to vs Windows applications.ProgramProject. For more information, see my previousArticle.

The following stretch mode option is only valid for the 32bpp anti-sawtooth icon, because only 32 BPP involves downgrading the image. Deleting a pixel means that when the pixels overlap, only one pixel on the image will be taken. Linear interpolation refers to a linear interpolation of a certain 4 pixels in the source graph. In principle, deleting pixels is less computation than linear interpolation, while linear interpolation may have a better scaling quality, but it is hard to feel too much difference.

If 16 BPP is selected, the saved image is the X-5-5-5 distribution image. The image degradation algorithm used when selecting 4 BPP or 8 BPP images is the eight-Cross Tree Algorithm (I have introduced it in the previous article ). Because the eight-tree algorithm may cause the image to change to the same color when the number of colors is small, I do not provide the option to save the image as a monochrome image (the minimum BPP is 4 ). The image quality effect after downgrading an icon is displayed:

By using this plug-in, you can easily convert a PNG image into a counter-tooth icon. You can open the PNG Image in PS and save it as an ico file.

 

(3) and mask Setting Dialog Box

 

When saving files, if the image is indexed, you must set the transparent part (and mask part ). The default option is to directly use the transparent information of the PS document, but this dialog box also allows you to set transparent information in other ways.

There are many settings. You can use the drop-down box to switch between them. Different Input interfaces may be provided below. You can set the transparent color to black, white, foreground, background, color of a sample point, a specified RGB color, or alpha channel (white to indicate transparent), or specify an index in a color table.

 

(4) dialog box

 

You can see it in the menu of PS: Help-about efficiency improvement tool-ico.... This dialog box is also carefully designed and compiled by me. It is quite beautiful. When you move the mouse in this dialog box, you can see the feedback of my blog website on the mouse, you can click on the URL, that is, call the default browser to open the URL. This is implemented through the callback suite provided by PS. I have introduced it in my previous tutorial on how to write the PS filter.

 

(5) other instructions:

 

This plug-in is based on my recent research on some published blogs. It starts from the image file format viewer, to the alphablend and anti-sawtooth icons to generate the eight-Tree Algorithm for indexed images, these articles are published for the purpose of technical preparation for this plug-in. It takes a lot of effort to develop this plug-in, including studying the ICO file format and ps sdk. References (for example, the eight-Tree Algorithm) have been introduced in previous blog posts, and are omitted here.

5.1 if the resolution of X and Y is not specified in the file, I will keep the default PS value in PS: 72 pixels/inch.

5.2 if the index image is enabled, you can view the current color table in the menu: Image-mode-color table. Because some software (such as ACDSee) cannot correctly parse the image whose color table is the actual number of colors, when I save the file, the color table is set to 16 or 256 instead of the actual number of colors.

5.3 this plug-in is especially applicable to the following users. I strongly recommend you install this plug-in to the following groups:

PS skilled users, Windows icon designers, programmers who like to participate in UI design, engineers, and other technical personnel (like me ).

This plug-in allows users to fully utilize the powerful image processing capabilities of Photoshop, instead of being limited to VC,. net and other ide's limited editing capabilities, so that you can use Photoshop to make more beautiful icons, of course, you can also easily convert many PNG materials on the network into icons used in programs.

I sincerely hope more people like it and use it. If you have any comments, suggestions, and requirements, you are welcome to leave a message on my blog or send an email to my mailbox (the mailbox address is in the bulletin board on the left ).

 

(6)Finally, the connection to download the release package of the plug-in is as follows:

 

(It also includes the ICO plug-in and Installation Tools of Version 2.0, oil painting filter, and drawtable filter ):

Http://files.cnblogs.com/hoodlum1980/PsPlugIns_V2013.zip

Note: If the link here is invalid, refer to the link in another article (Release Version 2.0.

 

(7) installation method:

 

Copy the "icoformat.8bi" file to the file format plug-in directory ① of Photoshop, for example, c: \ Program Files \ Adobe \ Photoshop CS \ efficiency tool \ file format \, and restart ps. Check if the following menu is available in the PS menu: "Help-about efficiency improvement tool-ico...", it indicates that the plug-in has been installed successfully.

(8) update records (bug level:H:Extremely important; M: Medium; L: irrelevant ):

 

8.1 m: when the quality is saved below 32bpp, the logic for setting andmask is adjusted (all smaller than 255 in alpha channel are set to transparent) to avoid displaying a stiff shadow. 2010-12-17.

8.2 h:Fixed the bug that the alpha channel also uses linear interpolation when saving the 32bpp anti-sawtooth icon and selecting linear interpolation (the correct method is that the alpha channel still uses the delete pixel method to generate ). This bug may cause non-transparent pixels to become transparent when generating images of other sizes. It is worth mentioning that this bug was introduced by 8.1. 2:04:15.

8.3 L: fixed the following BUG: Open the index image in the icon and deselect the "enable image transparency" option, but the result is still transparent. 3:36:08.

8.4 h:The pipl resource of the plug-in is adjusted so that the filter can directly obtain the transparent information of the document from the PS (the user does not need to explicitly provide additional channels ). Adjusted linear interpolationCodeAnd avoid merging pixels with the transparent (black) on the source image. 0:55:23.

8.5 m: adjusted the logic for generating the 32 BPP icon and directly degraded the image from the data in the PS document (the color was occasionally missing when the original method produced the index image, for unknown reasons ). 1:41:08.

8.6 L: added the option to store a single image as 32 BPP. 2:05:30.

8.7 L: when reading the index image, set the transparency Method to the previous one. The application transparency can be ensured to be more accurate, and the application of the 16-color image will be transparent. For the 256-color image, try to find the color that is not used on the image as the transparent color, so the application may not be transparent. The main disadvantage of this method is that the 16-color index image may be upgraded to a 256-color image when saved as a file. 2:57:17.

8.8 L: slightly adjusted the linear ing method for reading the pixel values of 16 BPP images (with little impact ). .

 

(9) Thanks:

 

Thanks to Chris Cox (Adobe employee) for replying to my questions on the official forum.

Website of the Photoshop SDK section of the adoble Forum:

Http://forums.adobe.com/community/photoshop/photoshop_sdk

 

(10) References:

 

10.1 eight-tree algorithm (address omitted ).

10.2 Photoshop SDK (6.0, CS ).

10.3 iconpro (sample provided in the msdn technical documentation ).

 

(11) Glossary used in this article

 

11.1 BPP (bits per pixel)

That is, the bit depth of the image. It indicates the number of digits used by each pixel (one byte contains eight digits ). For example, for an RGB true color bitmap, each pixel is represented in three bytes, and its BPP is 24. The bitwise depth of a black-and-white image (Binary Bitmap) is 1. The bit depth of the 16-color index image is 4 (each byte can represent two pixels), and the bit depth of the 256-color index image is 8 (each byte represents one pixel ). Generally, the bitwise depth divided by 8 indicates the number of bytes in each pixel.

The gray-scale image we often say is not a proprietary format, but a special 256-color index image. Its color palette features the R, G, the three components of B are equal. The color of the 256 color palette ranges from (0, 0, 0) to (255,255,255). Therefore, the value of the image data is essentially a color index, but it can also be understood as its gray brightness.

 

11.2 antialias)

Here is my personal translation method, which may not be accurate enough. It may be called anti-aliasing to better meet the habits of more people. This is a technology that uses translucent pixels to eliminate the sense of sawtooth. First of all, we need to know that the reason for the Sawtooth effect is that the display displays images using a dense matrix grid, GDI sets lattice pixels Based on Computer Image algorithms (essentially converts mathematical analog signals into digital signals after discretization). This type of rendering line looks like a stairway. The non-smooth mutation of adjacent pixels results in a sawtooth view.

More complex techniques for rendering straight lines require partial transparent pixels and opaque pixels. Pixels are set to solid colors or mixed colors with the background color (depending on their closeness to a straight line ). This rendering method is called to eliminate the sawtooth, which can generate a more smooth and soft straight line visually.

The anti-sawtooth icon mentioned in this Article refers to the 32 BPP image. That is, each pixel is represented in four bytes, representing the R, G, B, A (lpha), an alpha channel that is more than an ordinary RGB bitmap, used to describe the transparency of the pixel. Therefore, you can specify the transparency of the pixel to produce a Soft Fusion with the background, that is, to achieve the anti-sawtooth effect.

① The PS plug-in directory usually refers to $ (PS install DIR) \ plug-ins, as long as the third-party plug-in files (. 8b *) in this directory, PS will scan and try to load the 8B * file in this directory at startup. The plug-in type is not determined by the extension name, but by its pipl attribute. In this directory, you can create subdirectories according to the plug-in type. For example, filter and file format, but note that you only need to put the file in the PS plug-in directory and the file will be loaded by PS. The plug-in directory can be obtained by searching the registry at the following locations:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Adobe \ Photoshop \ (version, for example, 8.0) \ pluginpath

However, for the Chinese version of ps cs, this value remains in the English version path (not in Chinese), so it is wrong, this makes it a little difficult to provide a simpler and easier-to-use Installation Tool for the plug-in. For the English version, it can be considered as the plug-ins subdirectory under the PS installation directory.

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.