![]() |
Adobe Photoshop SDK |
|
Writing Format Plug-insFormat plug-in modules, sometimes referred to as Image Format, or File Format modules, are used to add new file types to the Open, Save, and Save As commands. Adobe Photoshop ships with several file format modules including GIF, MacPaint, and BMP. Import and Export modules may also be used to read and write files. You should create a Format module if you want your users to treat your files in the same fashion as native Photoshop files. Use a Format module if:
You may not want to use a Format module if:
For descriptions of the sample Format plug-ins provided with the SDK, see Format Samples. Format Module OperationsFile Format plug-in modules have two main functions: reading an image from a file, and writing an image to a file. Reading a file is a two step process:
Writing a file consists of three sequences:
Format Modules and ScriptingThe scripting system passes its parameters at every selector call. While it is possible to use the scripting system to store all your parameters, for backwards compatibility, it is recommended you track your parameters with your own globals. Once your globals are initialized, you should read your scripting-passed parameters and override your globals with them.
This way, the scripting system overrides your parameters, but you can use the initial values if the scripting system is unavailable or has parameter errors, and you can use your globals to pass between your functions. See the individual selector descriptions in Format Module for details on scripting within the selector invocations. File Filtering SequenceWhen the user selects a file with the Open command from the file menu, there may be one or more Format modules that list the Mac OS file type or Windows file extension as a supported format. For each such plug-in module, Photoshop calls the plug-in with formatSelectorFilterFile. The plug-in module should then examine the file to determine whether the file is one that it can process, and indicate this in its result parameter: if (module can read this file) *result = noErr; else *result = formatCannotRead; If more than one format module can read the file, Photoshop uses the following priority scheme to determine which plug-in module to use:
![]() Format Read SequenceIf the plug-in module returns ![]() Writing a FileWriting a file involves either two or three distinct sequences, each similar in structure. The details of these sequences are shown below. When a document is first saved, Photoshop calls your Format plug-in in this order:
After a document has been saved once, each time the user saves the file again, the plug-in is called without the options sequence:
Error Handling when Writing in Format Plug-insWhen writing a file, if your plug-in module sets ![]() Write Options SequenceWhen the user invokes a Format plug-in by selecting Save or Save As commands, Photoshop initially calls it with the options sequence of selector values shown in the figure below. After the document has been saved once, the options sequence is no longer invoked. The actions the Format plug-in needs to take for these selectors are discussed in more detail in Format Module. ![]() Write Estimate SequenceWhen the user invokes a Format plug-in by selecting Save or Save As commands, if the file has been saved before, Photoshop calls the plug-in with the estimate sequence of selector values shown in the figure below. The first time a document is saved, Photoshop invokes the options sequence, followed by the estimate sequence. The actions the Format plug-in needs to take for these selectors are discussed in more detail in Format Module.
![]() Write SequenceOnce Photoshop has called the plug-in with the estimate sequence, it follows that with subsequent calls to the plug-in with the write sequence of selector values shown in the figure below. The actions the Format plug-in needs to take for these selectors are discussed in more detail in Format Module.
![]() |