#include /////////////////////////////////////////// // /// Data structure passed from CC3 // typedef struct { float FilterSettings[10]; DWORD FilterCustomData[256]; } SETTINGS; typedef struct { DWORD *pPixels; int Width; int Height; float ViewWidth; float ViewHeight; SETTINGS *Settings; float ViewLowX; float ViewLowY; float ViewHighX; float ViewHighY; int ViewPixelWidth; int ViewPixelHeight; void *CopyPixel; // Address to a function to copy pixels "typedef (__stdcall *T_CopyPixel)(UINT *pDest, UINT *pSrc);" // Sun info float SunAzimuth; // Range [0 .. 2*pi) - The angle to the sun. Mathematical angle (0° along the X-axis, going CCW) float SunHeight; // Range [pi/2 .. pi] - pi/2 is along the horizon, pi is straight up. int SunIntensity; // Range [0 .. 255] - The intensity value used for roof shading } FILTERDATA; /////////////////////////////////////////// // /// Possible states // #define CMD_FILTER_NAMES 0 #define CMD_HAS_EDIT_DIALOG 1 #define CMD_EDIT_OPTIONS 2 #define CMD_PARAMETER_NAMES 3 #define CMD_SET_DEFAULT_VALUES 4 #define CMD_RUN_FILTER 5 #define CMD_HELP 6 #define CMD_WHAT_IS_RETURNED 7 /////////////////////////////////////////// // /// The DLL entry point - a good place to init and release memory // BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } /////////////////////////////////////////// // /// Our filter :-) // BOOL ApplyTransparency(FILTERDATA *pData) { DWORD AlphaValue; int NumPixels; BYTE *p; // Convert opacity (in %) to Alpha value AlphaValue=(int)(255*pData->Settings->FilterSettings[0]/100); // Make sure it is in range if(AlphaValue<1) return FALSE; if(AlphaValue>255) AlphaValue=255; // Go through the bitmap and change the alpha value p=((BYTE *)pData->pPixels)+3; NumPixels=pData->Width*pData->Height; while(NumPixels-->0) { if(*p) { if(*p==255) *p=(BYTE)AlphaValue; else *p = (BYTE)(((DWORD)*p * AlphaValue) >> 8); } p+=4; } return TRUE; } /////////////////////////////////////////// // /// Interface to CC3 // // // Parameters // // Cmd - The current command // Num - Internal filter number // pData - Data structure (only used for CMD_EDIT_OPTIONS, // CMD_SET_DEFAULT_VALUES and CMD_RUN_FILTER) __declspec(dllexport) unsigned int __stdcall CC2Filter(int Cmd, int Num, FILTERDATA *pData) { switch(Cmd) { //////////////////////////////////////////////////////////////////////////// // /// Asking for list of filters // // We should return a string with "Name1\0Name2\0" case CMD_FILTER_NAMES: return (DWORD)"Transparency\0"; //////////////////////////////////////////////////////////////////////////// // /// Are we doing our own parameters box? // // Return TRUE if we want to do our own dialog box for options case CMD_HAS_EDIT_DIALOG: return FALSE; //////////////////////////////////////////////////////////////////////////// // /// Edit our data (if we returned TRUE above) // // pData has no pixel pointer and the others refer to screen and drawing extents. // // return TRUE if edit is successful (i.e. user pressed OK) case CMD_EDIT_OPTIONS: return FALSE; //////////////////////////////////////////////////////////////////////////// // /// Send list of parameter names to edit // // Return list of strings case CMD_PARAMETER_NAMES: switch(Num) { case 0: return (DWORD)"Opacity (%)\0"; } return FALSE; //////////////////////////////////////////////////////////////////////////// // /// Set default parameters // // pData has no pixel pointer and the others refer to screen and drawing extents. case CMD_SET_DEFAULT_VALUES: switch(Num) { case 0: pData->Settings->FilterSettings[0]=50; break; } return FALSE; //////////////////////////////////////////////////////////////////////////// // /// Apply filter // // pData set to data for sheet bitmap and size of current view // case CMD_RUN_FILTER: switch(Num) { case 0: return ApplyTransparency(pData); } return FALSE; //////////////////////////////////////////////////////////////////////////// // /// User pressed help button // // return FALSE if no help was displayed // case CMD_HELP: return FALSE; //////////////////////////////////////////////////////////////////////////// // /// What will the filter return // // Allowed values: // // 0 = complete bitmap (with effect and original) // 1 = just the effect. CC3 has to add the original on top later // For exdample shadows and glows uses this. It also forces // these filters to be applied first. case CMD_WHAT_IS_RETURNED: return 0; } return 0; }