Monday, January 4, 2010

Expanding Photoshop's Horizons: Plugins, Scripts and Flash



Working in any large scale creative team means big work flow problems at one time or another. Solving these problems often means creating custom tools for key pieces of software such as Maya, 3D Studio Max and yes, Photoshop. Compared to other major DCCs Photoshop is very inflexible which can lead to both frustration and innovation. Maya for example allows you to strip back the entire application if need be and customise almost every facet of it's inner workings. Photoshop does not. However the introduction of CS4 and soon the next iteration CS5 brings some major improvements to customisability of Photoshop bringing it closer to Game and Film production pipelines.

In this and the following posts I will explain the different ways Photoshop can be expanded and customised, giving examples of exposing some development voodoo, some of which may not be exactly what Adobe wants you to hear but it gets the job done. I will be posting links to the latest section articles on this page as I write them.  When giving more specific examples of of writing scripts etc I will be focusing more on development work flow rather than language How Tos.


In this post I will introduce the main concepts of expanding Photoshop CS4 from simple to complex. These articles may be read by people of all skill levels so all I'll assume is a good understanding of Photoshop concepts and UI.


Actions and Automation
Actions and automation are the simplest ways to make tasks easier and faster. An action is a macro recording of a series of events triggered by the user such as opening a file, deleting a layer or applying a filter. Automation is applying an action automatically over multiple images such as a folder of PSDs.

Pros:
  • Very easy for anyone of a team to create and use.
  • Easily imported and exported from Photoshop.
  • Can include functionality from 3rd party plugins.
Cons:
  • No automatic way of distribution to team members.
  • Not every function in Photoshop is captured by the action system.
  • Linear execution, no logic etc.


Scripting has been the main way of expanding Photoshop since the early days. Scripts can be created in Javascript, VBScript and Applescript. I will only cover JavaScript in these articles since it is by far the most popular and the one that I know. Most functionality has native Javascript DOM support and there is also a plugin which allows you to listen to Photoshop's internal workings which can be scripted with a bit of work. Scripts can be hooked into Photoshop events and called when a file is opened for example. Modal tool windows can be created to add UI elements and also communication with Flash panels is implemented.

Pros:
  • Large community support base.
  • Many free scripts are available to download and study.
  • Using the Script Logger output any Photoshop functionality can be scripted.
  • Excellent IDE and debugging tools which integrate well with Photoshop.
  • Works on all platforms (Win x86, Win x64, OSX) without the need to recompile.
Cons:
  • Can be slow to execute.
  • Not all Photoshop functionality has native scripting exposure and resorting to using the Script Logger output can be difficult and cryptic.
  • Can only create modal tool windows.


Flash Panels
Flash Panels are the newest and best way to add floating panels and UI heavy tools. Flash Panels are developed in Flex Builder (Soon to be Flash Builder which is currently in beta) using ActionScript and MXML. Flash Panels come in two flavours: PatchPanel and CSXS Panels which expose different elements of Photoshop to Flash. Anything that can be done in Flash can be done in these panels including Pixel Bender shaders and network support.

Pros:
  • Can create floating tool panels which integrate into the Photoshop UI.
  • Can be used in other packages such as Illustrator.
  • Can control most of Photoshop and hook into Photoshop events.
  • When setup can debug Flash Panels as they execute in Photoshop.
Cons:
  • Need to learn Flex IDE and MXML.
  • Can slow down if large amounts of complex UI are shown.
  • Can be tricky if MXML includes are not setup correctly.
  • Debug setup can be a pain and often crashes.

COM Automation (Windows only)
COM Automation is an older windows technology that has been superseded by parts of .Net, however it still has it's uses.  It defines a standard way of applications to publish an external interface so other applications can hook ino them.  The greate part is with a little Visual Studio magic the COM interfaces can be converted to .Net assemblies and used with C# and other .Net languages.


Pros:
  • Can utilise your existing programming skills in other languages such as C#.
  • Easily integrates inot existing external pipelines and systems.
Cons:
  • Tools are completely external so no UI integration etc.
  • Can be hard to debug.

Pixel Bender Filters
Pixel Bender is Adobes propriety shader language similar to Cg or HLSL. Pixel Bender shaders can be used inside flash or as a filter in Photoshop, After Effects etc. This is a bit of a niche but is still a big part of Photoshop use in some companies / markets and much easier to create than native plugins.

Pros:
  • Shader language is straight forward.
  • Fast execution speed.
  • Utilises graphics hardware.
Cons:
  • Pixel Bender IDE is basic pre-release software and sometime frustrating to use.
  • No debugging options.
  • May be discrepancies between IDE and Photoshop results.



JavaScript Extensions
JavaScript extensions can be very powerful. I have only had experience creating DLLs for windows but am sure its is just as easy to create OSX extensions. JavaScript extensions are coded in C++ so almost anything is possible including using other DLLs and even managed code. For a test example I created a DLL which was compiled with CLR (enabling the .Net framework) which then loaded an assembly DLL created in C# which spawned a windows form which was correctly parented to the main Photoshop window using Win32 API calls. A recent development on the Adobe Labs Patch Panel forum suggest that native wrappers for JavaScript extensions DLL might be written in Flex and used with Flash panels but I have not confirmed this.

Pros:
  • Can expose almost any functionality to JavaScript such as calls to .Net.
  • MIGHT be able to be integrated into Flash panels natively.
  • Existing DLLs can be used to access databases etc.
Cons:
  • Need at least C language knowledge.
  • Not many examples from Adobe and almost no information online.


Plugins
Plugins are the ultimate in extending Photoshop. They are written in C++ and can be used to reach into the depths of Photoshop's API. There are several major types of plugins including File I/O, Filters, Layer types etc. Since they are the most tightly integrated extension they do things on a lower level and execute quickly.

Pros: 
  • Fast Execution. 
  • Low level API access allowing integral parts of Photoshop to be expanded such as adding new file types etc.
Cons:
  • Knowledge of advanced C++ techniques needed.
  • Some examples come with the SDK but little documentation on “How To”.


Where to Start
ExtendScripts (using JavaScript) seems to be the best place to start assuming you have a good understanding of Photoshop's UI and work flow. Most general features of the JavaScript language will work so if you have any prior knowledge of C, C#, ActionScript etc you will pick it up quickly. The IDE is mature and makes debugging your scripts while they are executing within Photoshop very easy. Once you have some scripting experience under your belt it will be much easier to create Flash Panels, JavaScript extensions and plugins since most Photoshop programming terms run common through all areas.


3 comments: