본문 바로가기
C++

Adobe Photoshop Plugin Project

by leo21c 2013. 12. 11.
SMALL

참고: adobe_photoshop_cs5_sdk_win/pluginsdk/documentation/html/pgwinplugins.html

Creating plug-in modules for Windows


위의 참고 주소와 같이 SDK에서 제공하는 정보입니다.

아래 내용을 보면 기존 Sample 프로젝트를 기초로 해서 새로운 프로젝트를 만드는 것을 확인할 수 있습니다. 따라서 자기기 만들고자 하는 plugin을 선택합니다. 예를 들어 filter라면 아래와 같은 프로젝트를 선택해도 됩니다. 그러나 format plugin이라면 simpleformat를 선택해서 만들 수도 있습니다.

simpleformat를 기준으로 만들어 볼 경우 아래와 같이 진행을 하면 큰 문제가 없습니다. 파란색으로 표시한 부분을 주의해서 처리합니다.

SDK에서 제시한 방식으로 프로젝트를 만들었지만 빌드 에러가 발생했습니다. 그래서 최종 선택한 방식은 같은 형식의 Plugin sample 소스를 기초로 Workspace를 비롯한 모든 소스 파일을 열어 이름을 내가 원하는 것으로 변경을 해서 사용을 했습니다. 

simpleformat을 기초로 해서 제작을 했으며 내가 원하는 것은 다른 파일 확장자이기 때문에 관련된 내용을 모두 바꾸고 이름도 변경을 해서 빌드 후 photoshop plugin 폴더에 놓고 테스트 한 결과 원하는 파일 포멧이 나타나는 것을 확인 했습니다.

Create a Project Workspace

All Windows Photoshop plug-ins have three basic properties. They are shared libraries, they have a PiPL resource, and they have a program entrypoint or main function.

  1. Launch Microsoft Visual C++ 2005, or Visual Studio 2005.
  2. Choose from the menu "File" > "New" > "Project".
  3. Under Project Types, select "Win32"
  4. From the list of templates, choose "Win32 Project".
  5. In the "Name:" field, type "myfilter" (or the name of your plug-in).
  6. In the "Location:" field, type in the location for your project. Set the path similar to the following:C:\Adobe Photoshop 10.0 SDK\samplecode\filter\myfilter\win.
  7. Do not check "Create Directory for Solution"
  8. Click "OK".

  9. The "Win32 Application Wizard" appears.
  10. Click "Next".
  11. Select Application Type: "DLL'
  12. Select Additional Options: "Empty Project".
  13. Click "Finish".
  14. The project appears in the Solutions Explorer.

Move the Project

When creating a new project, Visual C++ makes a new folder and puts the project there. In this case, we want the files up a level, directly in themyfilter\win folder to be consistent with the Mac environment.

Note:
You can skip this step for your projects. Please make a note of your level change when using the relative paths later in this document.
  1. Close Visual C++, and navigate to location C:\Adobe Photoshop 10.0 SDK\samplecode\filter\myfilter\win\myfilter. We want it up a level.
  2. Select all the files and copy them.
  3. Move them up a level (..\samplecode\filter\myfilter\win).
  4. Delete the win\myfilter folder that the files where copied from.

Add the Main Source File

Now you have a blank project to work from. The first step is to add the main source file, which subsequently allows us to enter build settings for a C++ project. To do this, we copy the main source file from the dissolve filter.

  1. Launch Visual C++ by double clicking on the myfilter.vcproj file.
  2. Choose from the menu, "File" > "Open".
  3. Navigate to the location of the main source file you want to copy. (C:\Adobe Photoshop 10.0 SDK\samplecode\filter\invert\common)
  4. Select "File" > "Save Dissolve.cpp As"
  5. Navigate to the ..\samplecode\filter\myfilter\common directory.
  6. Save the file as "myfilter.cpp"
  7. Under the Solution Explorer navigation bar, right click on the "Source Files" folder.
  8. Select "Add" > "Existing Item".
  9. Navigate to the ..\samplecode\filter\myfilter\common directory.
  10. Select file "myfilter.cpp".
  11. Edit the file to replace occurances of "dissolve" with "myfilter".
  12. Save and close the "myfilter.cpp".

Add Other Necessary Source Files

Most projects that you copy from have additional source and header files you need to include in order for the project to build. The dissolve example does not have an include file of its own, but it does require several common source files (from ..\samplecode\common\sources) that provide support utilites for the plug-in. We need to add these .cpp files to the project. Any common header files required by the plug-in are pulled in during the build step by providing an additional include directory.

  1. Under the Solution Explorer navigation bar, right click on the "Source Files" folder.
  2. Select "Add" > "Existing Item".
  3. Navigate to the ..\samplecode\common\sources directory.
  4. Double click on "FilterBigDocument.cpp".
  5. Repeat the previous set of steps to add "PIDLLInstance.cpp".
  6. Repeat the previous set of steps to add "PIUSuites.cpp".
  7. Repeat the previous set of steps to add "PIWinUI.cpp".
  8. Repeat the previous set of steps to add "PropertyUtils.cpp".

Add a Resource File

You must add a resource file (.rc), which holds an include to the PiPL resource file created in the next step.

  1. Choose from the menu "File" > "New" > "File".
  2. Under "Categories" select "Visual C++".
  3. Under "Templates" select "Resource Template File (.rct)".
  4. A "ResTempl1.rct" folder appears in the edit pane.
  5. Right click on the folder and select "Add Resource"
  6. When the "Add Resource" box appears, select "Dialog".
  7. Click "New" to add the dialog to the resource file.
  8. Close the resource editor.
  9. Choose from the menu "File" > "Save ResTempl1.rct".
  10. The "Save File As" dialog box pops up.
  11. Navigate to the location ..\samplecode\filter\myfilter\win.
  12. Choose "Save As Type" to be "Resouce Script (.rc)".
  13. Save the file as myfilter.rc.
  14. Open the resource file in the text editor.
    1. To do this, choose "File" > "Open".
    2. Navigate to the folder where the myfilter.rc file is located.
    3. Single click on the file.
    4. Click on the down arrow next to the "Open" button, choose "Open With".
    5. When the "Open With" box appears, select "Source Code (Text) Editor".
    6. Click "OK"
    7. A question dialog appears informing you that myfilter.rc is already open. Select "Yes", indicating you want to close the file.
  15. The myfilter.rc file opens in the edit pane in text mode.
  16. On approximately line 76, replace the line: "\r\n" with the line: "#include ""temp\\myfilter.pipl""\r\n"
  17. Scroll down to the end of the file to approximately line 93.
  18. Between line containing "#ifndef APSTUDIO_INVOKED" and the line containing "#endif" insert the following text: #include "temp\\myfilter.pipl"
  19. Change all occurrences of "Dissolve" with your plug-in's name, "myfilter" for this example.
  20. Save "myfilter.rc".
  21. In the Solution Explorer navigation pane, right click on "Resource Files".
  22. Select "Add" > "Existing Item".
  23. Browse to and double click on the "myfilter.rc" file that you just created.

Add a PiPL Resource File

We now need to create the PiPL resource (.r) file for the plug-in. We do this by copying the PiPL resource file from the dissolve project. Once the file is built, we will add the custom build settings for the PiPL, described in the next step.

  1. Choose from the menu "File" > "Open" > "File".
  2. Navigate to the directory containing the PiPL resource file you want to copy. For this example, that is:C:\Adobe Photoshop 10.0 SDK\samplecode\filter\dissolve\common
  3. Select "File" > "Save Dissolve.r As"
  4. Navigate to the ..\samplecode\filter\myfilter\common directory.
  5. Save the file as "myfilter.r"
  6. Edit the file to replace occurances of "dissolve" with "myfilter".
  7. Save and close "myfilter.r".
  8. In the Solution Explorer navigation pane, right click on "Resource Files".
  9. Select "Add" > "Existing Item".
  10. In the "Files of Type" box, select "All Files (*.*)".
  11. Browse to and double click on the "myfilter.r" file that you just created.
  12. When the box appears asking if you want to create custom build rules, click "No". (We will do this from the file's property page, instead.)

Enter Custom Build Settings for PiPL

Next we will enter the custom build rules for the PiPL resource file. You need to convert a Mac OS resource file into a Windows-compatible resource. You do this using the Visual C++ custom build step and the CNVTPIPL.EXE found in the SDK.

  1. In the Solution Explorer navigation pane, right click on the "myfilter.r" file.
  2. Select "Properties".
  3. The Property Page dialog box for myfilter.r appears.
  4. In the "Configuration:" field, select "All Configurations", indicating this rule applies to all types of builds.
  5. Click on the "+" next to "Custom Build Step", then click on "General".
  6. Click on "Command Line", then on the ellipsis icon at the end of the line. There are three lines to enter into the custom build command line box. (NOTE: You need to change the paths if you placed your project in a different folder.)
    1. First, create a temporary .rr file, by entering the following as the first line in the box, and this must all be on a single line, not split on two lines as it is shown here:
        cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP 
        /I..\..\..\Common\Resources /EP /DWIN32=1 /Tc"$(InputPath)" > "$(IntDir)\$(InputName).rr"
      
    2. Next, enter the command to invoke CNVTPIPL.EXE:
        ..\..\..\resources\cnvtpipl.exe "$(IntDir)\$(InputName).rr" "$(IntDir)\$(InputName).pipl"
      
    3. Finally, enter the command to delete the temporary file.
        del "$(IntDir)\$(InputName).rr"
      
  7. Click on "Outputs", and then on the down arrow at the end of the line.
  8. Enter the following into the box:
    $(IntDir)\$(InputName).pipl
    
  9. Click "OK".

Enter Overall Build Settings for the Project

At this point the project is set up with all the appropriate files. You must now change the project settings to build a proper Photoshop plug-in. We do this by using the Property Page for the project, and modifying each of the sections of the build process.

  1. In the Solution Explorer navigation pane, right click on the "myfilter" project icon.
  2. Select Properties.
  3. Under "Configuration Properties, click on the "General" item.
    1. In the "Configuration:" field, select "All Configurations".
    2. In both the "Intermediate Directory" and "Output Directory" sections, type "temp".
    3. In the "Inherited Property Project Sheets" enter:
        $(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops
      
    4. Select "Apply". Your property page should look something like:
  4. Click on the "+' next to the "C/C++" item.
    1. Click on "General" under C++.
      1. Enter the following paths into "Additional Include Directories" (NOTE: If you did not put your plug-in into the SDK, these relative paths will not work. Make sure your paths point to these folders that are in the Photoshop SDK.)
            ..\..\..\Common, 
            ..\..\..\Common\includes, 
            ..\..\..\..\PhotoshopAPI,
            ..\..\..\..\PhotoshopAPI\ADM,
            ..\..\..\..\PhotoshopAPI\Photoshop,
            ..\..\..\..\PhotoshopAPI\General,
            ..\..\..\..\PhotoshopAPI\PICA_SP
        
      2. Set "Detect 64-bit portability issues" to "No".
      3. Click Apply. Your properties page should look something like:
    2. Click on the "Preprocessor" item.
      1. Select "Preprocessor Definitions", then select the ellipsis at the end of the line to view the preprocessor options.
      2. Set the preprocessor defintions to the following list:
            ISOLATION_AWARE_ENABLED
            WIN32
            _DEBUG
            _WINDOWS
            _USRDLL
            Dissolve_EXPORTS
        
      3. The following preprocessor defintions should come from the inherited section:
            _VC80_UPGRADE=0x0710
            _WINDLL
            _MBCS
        
      4. If inherited items are different, or incomplete, then deselect the "Inherit from parent or project defaults" check box, and enter the three items above directly into the preprocessor definitions box.
    3. Click on the "Output Files" item.
      1. In the "Configurations:" field, select "Release".
      2. For "ASM List Location", "Object File Name", and "Database File Name", enter.\..\..\..\Output\Objs\myfilter\Release//
      3. Click Apply.
      4. In the "Configurations:" field, select "Debug".
      5. For "ASM List Location", "Object File Name", and "Database File Name", enter.\..\..\..\Output\Objs\myfilter\Debug//
      6. Click Apply.
    4. Click on the "Advanced" item.
      1. In the "Configurations:" field, select "All Configurations".
      2. In the "Compile As" field, select "Default".
    5. Click on the "-" next to the "C/C++" item, to close the list of C++ options.
  5. Click on the "+" next to the "Linker" item.
    1. Click on the "General" item.
      1. In the "Configurations:" field, select "Release".
      2. In the "Output File" field, enter: ..\..\..\Output\Win\Release\myfilter.8bf Replacing "myfilter with the name of your plug-in. (.8bf is the extension for filter plug-in files.)
      3. In the "Enable Incremental Linking field", select "Yes"
      4. Click Apply.
      5. In the "Configurations:" field, select "Debug".
      6. In the "Output File" field, enter: ..\..\..\Output\Win\Debug\myfilter.8bf
      7. In the "Enable Incremental Linking field", select "Yes"
      8. Click Apply.
    2. Click on the "Input" item.
      1. In the "Configurations:" field, select "All Configurations".
      2. In the "Additional Dependencies" field, enter odbc32.lib odbccp32.lib version.lib
      3. Click Apply.
      4. Click OK.

Building the Plug-in

Now you are ready to build the plug-in.

  1. Choose from the menu "Build" > "Build myfilter", or "Build" > "Build Solution".
  2. If the plug-in builds correctly, you will find the plug-in executable file in ..\..\..\Output\Win\Release\myfilter.8bf or..\..\..\Output\Win\Debug\myfilter.8bf
  3. If the plug-in does not build correctly, check all the steps above and ensure you have followed them correctly. As a final check, you can verify all the project property pages of your new plug-in with the project property pages of the plug-in you copied from.

Installing plug-in modules

To install a plug-in module, copy the .8B* files into the directory referred to in the Photoshop INI file with the profile string PLUGINDIRECTORY. See Finding the plug-in directory in Windows.

When Adobe Photoshop first executes, it searches the files in the PLUGINDIRECTORY, looking for plug-in modules. When it finds a plug-in, it checks its version number. If the version is supported, it adds name of the plug-in to the appropriate menu or to the list of extensions to be executed.

Each kind of plug-in module has its own 4-byte resource type. For example, acquisition modules have the code 8BAM.

The actual resource type must be specified as _8BAM in your resource files to avoid a syntax error caused by the first character being a number.

For example, Adobe Photoshop searches for Import modules by examining the resources of all files in PLUGINDIRECTORY with file extension .8B* for resource type _8BAM. For each 8BAM, the integer value which uniquely identifies the resource, nameID, must be consecutively numbered starting at 1.

LIST

'C++' 카테고리의 다른 글

GetProcessMemoryInfo function  (0) 2014.03.04
VirtualQuery function  (0) 2014.03.04
MFC 표준 컨트롤에서 컨트롤 파생  (0) 2014.02.14
MFC Custom Controls  (0) 2014.01.20
Adobe Photoshop SDK  (0) 2013.12.11