Advertisement
AZJIO

_HSB_to_RGB (.DLL)

Jan 11th, 2014
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. //Файл Test.cpp
  2.  
  3. //Включаем заголовочный файл "windows.h" в проект.
  4. #include "windows.h"
  5.  
  6. //Определяем идентификатор для экспорта функций.
  7. #define EXPORT __declspec(dllexport)
  8.  
  9. //Точка входа в динамически-подключаемую библиотеку (DLL).
  10. BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  11. {
  12.     switch (ul_reason_for_call)
  13.     {
  14.         case DLL_PROCESS_ATTACH:
  15.             break;
  16.         case DLL_THREAD_ATTACH:
  17.             break;
  18.         case DLL_THREAD_DETACH:
  19.             break;
  20.         case DLL_PROCESS_DETACH:
  21.             break;
  22.     }
  23.     return TRUE;
  24. }
  25.  
  26. //Функция _HSB_to_RGB.
  27. EXPORT int __stdcall _HSB_to_RGB(double nH, double nS, double nL, int iScale1, int iScale2, int iScale3)
  28. {
  29.     double nR = 0;
  30.     double nG = 0;
  31.     double nB = 0;
  32.     int Sector = 0;
  33.     double f = 0;
  34.     double p = 0;
  35.     double q = 0;
  36.     double t = 0;
  37.  
  38.     nL /= iScale3;
  39.  
  40.     if (nS = 0)
  41.         {
  42.             nR = nL;
  43.             nG = nR;
  44.             nB = nR;
  45.         }
  46.     else
  47.         {
  48.             while (nH >= iScale1) {nH -= iScale1;}
  49.  
  50.             nS /= iScale2;
  51.             nH /= iScale1 / 6;
  52.             Sector = (int) nH; // так как тип переменной int, то атоматическое приведение
  53.  
  54.             f = nH - (double) Sector;
  55.             p = nL * (1 - nS);
  56.             q = nL * (1 - nS * f);
  57.             t = nL * (1 - nS * (1 - f));
  58.             switch (Sector)
  59.                 {
  60.                     case 0:
  61.                         nR = nL;
  62.                         nG = t;
  63.                         nB = p;
  64.                         break;
  65.                     case 1:
  66.                         nR = q;
  67.                         nG = nL;
  68.                         nB = p;
  69.                         break;
  70.                     case 2:
  71.                         nR = p;
  72.                         nG = nL;
  73.                         nB = t;
  74.                         break;
  75.                     case 3:
  76.                         nR = p;
  77.                         nG = q;
  78.                         nB = nL;
  79.                         break;
  80.                     case 4:
  81.                         nR = t;
  82.                         nG = p;
  83.                         nB = nL;
  84.                         break;
  85.                     default:
  86.                         nR = nL;
  87.                         nG = p;
  88.                         nB = q;
  89.                 }
  90.             nR *= 255;
  91.             nG *= 255;
  92.             nB *= 255;
  93.         }
  94.     return nR;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement