●EXORフィルタ1
・アウトライン

  1.空のプロジェクト作成
     - Win32 Dynamic-Link Library
     - 空のDLL プロジェクト
  2.ソースファイルの追加
     - exor.cpp
     - exor.pipl
  3. リソーススクリプトの新規作成
     - exor.rc を新規作成
     - エディタで開いて, #include "exor.pipl" を追記
  4.インクルードパスの設定
     - PhotoshopAPI/Photoshop
     - PhotoshopAPI/pica_sp
     - common/Includes
  5.出力ファイル名の変更
     - exor.8bf
  6.ビルド
  7.プラグインをコピー

・exor.cpp

#include "PIDefines.h"
#include "PIFilter.h"

//----------------------------------------------------------------------------
// 諸定義
#define BIN 0xaa
FilterRecord * gFR = NULL;
int32        * gDataHandle   = NULL;
int16 DoStart(void);

//----------------------------------------------------------------------------
// DllMain -  Windowsから呼び出される関数。
//----------------------------------------------------------------------------
BOOL APIENTRY DllMain(HANDLE , DWORD , LPVOID ) { return true; }

//----------------------------------------------------------------------------
//    PluginMain - Photoshopから呼び出される関数。
//----------------------------------------------------------------------------
DLLExport MACPASCAL void PluginMain(const int16 selector,
                                    FilterRecord *filterRecord,
                                    int32 *data,
                                    int16 *result)
{
    // update our global parameters
    gFR         = filterRecord;
    gDataHandle = data;

    // do the command according to the selector
    switch (selector)
    {
        case filterSelectorStart:
            *result = DoStart();
            break;
        case filterSelectorAbout:
        case filterSelectorParameters:
        case filterSelectorPrepare:
        case filterSelectorContinue:
        case filterSelectorFinish:
            break;
    }
}

//----------------------------------------------------------------------------
// DoStart - フィルタの本処理
//----------------------------------------------------------------------------
int16 DoStart( void )
{
    // gFR-> といちいち打つのが嫌なので、ポインタを設定する
    Rect * filterRect = & gFR->filterRect;
    Rect * outRect    = & gFR->outRect;

    // 諸定数
    int16 width  = filterRect->right  - filterRect->left;
    int16 height = filterRect->bottom - filterRect->top ;
    int16 expectedPlanes = 3;

    // outRect に代入して、フィルタの対象を設定する。
    *outRect = *filterRect;

    for (uint16 ch = 0; ch < expectedPlanes; ch++)
    {
        // フィルタを適用するチャンネルを設定する
        gFR->outLoPlane = gFR->inLoPlane = ch;
        gFR->outHiPlane = gFR->inHiPlane = ch;
    
        // 上記の設定で advanceState を呼び出して、画像のコピーを作成する
        int16 res = gFR->advanceState();
        if ( res != noErr ) return res;

        // 実際のフィルタ処理
        uint8 * pix = (uint8*) gFR->outData;
        for(int y=0; y < height; y++)
        {
            uint8 * pix1 = pix + width;
            for(; pix < pix1; pix++) *pix ^= BIN;
            pix += gFR->outRowBytes - width;
        }
    }

    // outRect を空に設定して、フィルタ対象が残っていないことを伝える
    memset( outRect, 0, sizeof(Rect) );

    return noErr;
}

・exor.r

#include "PIGeneral.h"

#define plugInName            "eXoR0"
#define vendorName            "ymtkyk"

resource 'PiPL' ( 16000, plugInName, purgeable )
{
    {
        Kind { Filter },
        Name { plugInName },
        Category { vendorName },
        Version { (latestFilterVersion >> 16) | latestFilterSubVersion },
        CodeWin32X86 { "PluginMain" },
            
        EnableInfo { "in (PSHOP_ImageMode, RGBMode )" }
    }
};

・pipl の生成(cl と cnvtpipl の実行)

    cl /EP /DWIN32=1 /Tc.\exor.r > .\exor.rr
    cnvtpipl.exe .\exor.rr .\exor.pipl
    del .\exor.rr