home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / digifoto / winmorph / setup.exe / {code:GetWaxDir} / Plugins / Scripts / FADE.C < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-02  |  3.9 KB  |  149 lines

  1. #include <string.h>
  2. int FadeMain(HANDLE hStream, ImagePluginApplyParams *psParams, int r, int g, int b, int bDouble, int bReverse)
  3. {
  4.     int nSrcPercent, nLength, i;
  5.     int nPos;
  6.     ImageSample *psSrc, *psDst;
  7.  
  8.     nLength = psParams->dwWidth*psParams->dwHeight;
  9.  
  10.     // if reverse dir, change the frame pos appropriately.
  11.     nPos = psParams->dwPos;
  12.  
  13.     psSrc = psParams->psSrcSample;
  14.     psDst = psParams->psDstSample;
  15.  
  16.     nSrcPercent = (nPos*256)/(psParams->dwFrames-1);
  17.     if (bDouble)
  18.     {
  19.         nSrcPercent = nSrcPercent*2;
  20.         if (nSrcPercent > 256)
  21.             nSrcPercent = 512-nSrcPercent;
  22.     }
  23.     if (bReverse)
  24.         nSrcPercent=256-nSrcPercent;
  25.  
  26.     if (r >= 0)
  27.     {
  28.         // use the colour.
  29.         memset(psDst, 255, nLength*sizeof(ImageSample));
  30.         for (i=0; i<nLength; i++)
  31.         {
  32.             int c;
  33.             c = psSrc[i].r; psDst[i].r = c+(((r-c)*nSrcPercent)>>8);
  34.             c = psSrc[i].g; psDst[i].g = c+(((g-c)*nSrcPercent)>>8);
  35.             c = psSrc[i].b; psDst[i].b = c+(((b-c)*nSrcPercent)>>8);
  36.         }
  37.     }
  38.     else
  39.     {
  40.         // just modify alpha.
  41.         memcpy(psDst, psSrc, nLength*sizeof(ImageSample));
  42.         for (i=0; i<nLength; i++)
  43.             psDst[i].a = (psDst[i].a*nSrcPercent)>>8;
  44.     }
  45.  
  46.     return 0;
  47. }
  48.  
  49. int FadeToBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
  50. {
  51.     return FadeMain(hStream, psParams, 0, 0, 0, 0, 0);
  52. }
  53.  
  54. int FadeToWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
  55. {
  56.     return FadeMain(hStream, psParams, 255, 255, 255, 0, 0);
  57. }
  58.  
  59. int FadeToRed(HANDLE hStream, ImagePluginApplyParams *psParams)
  60. {
  61.     return FadeMain(hStream, psParams, 255, 0, 0, 0, 0);
  62. }
  63.  
  64. int FadeToGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
  65. {
  66.     return FadeMain(hStream, psParams, 0, 255, 0, 0, 0);
  67. }
  68.  
  69. int FadeToBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
  70. {
  71.     return FadeMain(hStream, psParams, 0, 0, 255, 0, 0);
  72. }
  73.  
  74. int FadeToCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
  75. {
  76.     return FadeMain(hStream, psParams, 0, 255, 255, 0, 0);
  77. }
  78.  
  79. int FadeToMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
  80. {
  81.     return FadeMain(hStream, psParams, 255, 0, 255, 0, 0);
  82. }
  83.  
  84. int FadeToYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
  85. {
  86.     return FadeMain(hStream, psParams, 255, 255, 0, 0, 0);
  87. }
  88.  
  89. int FadeFromBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
  90. {
  91.     return FadeMain(hStream, psParams, 0, 0, 0, 0, 1);
  92. }
  93.  
  94. int FadeFromWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
  95. {
  96.     return FadeMain(hStream, psParams, 255, 255, 255, 0, 1);
  97. }
  98.  
  99. int FadeFromRed(HANDLE hStream, ImagePluginApplyParams *psParams)
  100. {
  101.     return FadeMain(hStream, psParams, 255, 0, 0, 0, 1);
  102. }
  103.  
  104. int FadeFromGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
  105. {
  106.     return FadeMain(hStream, psParams, 0, 255, 0, 0, 1);
  107. }
  108.  
  109. int FadeFromBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
  110. {
  111.     return FadeMain(hStream, psParams, 0, 0, 255, 0, 1);
  112. }
  113.  
  114. int FadeFromCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
  115. {
  116.     return FadeMain(hStream, psParams, 0, 255, 255, 0, 1);
  117. }
  118.  
  119. int FadeFromMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
  120. {
  121.     return FadeMain(hStream, psParams, 255, 0, 255, 0, 1);
  122. }
  123.  
  124. int FadeFromYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
  125. {
  126.     return FadeMain(hStream, psParams, 255, 255, 0, 0, 1);
  127. }
  128.  
  129. int FadeIn(HANDLE hStream, ImagePluginApplyParams *psParams)
  130. {
  131.     return FadeMain(hStream, psParams, -1, 0, 0, 0, 0);
  132. }
  133.  
  134. int FadeOut(HANDLE hStream, ImagePluginApplyParams *psParams)
  135. {
  136.     return FadeMain(hStream, psParams, -1, 0, 0, 0, 1);
  137. }
  138.  
  139. int FadeInAndOut(HANDLE hStream, ImagePluginApplyParams *psParams)
  140. {
  141.     return FadeMain(hStream, psParams, -1, 0, 0, 1, 0);
  142. }
  143.  
  144. int FadeOutAndIn(HANDLE hStream, ImagePluginApplyParams *psParams)
  145. {
  146.     return FadeMain(hStream, psParams, -1, 0, 0, 1, 1);
  147. }
  148.  
  149.