Pistol_Pete
Messages postés
1053
Date d'inscription
samedi 2 octobre 2004
Statut
Membre
Dernière intervention
9 juillet 2013
7
2 avril 2008 à 22:15
Oui je veux bien mais le probleme c'est que l'on aura jamais le meme degrader avce nos deux alogorithmes...
Alors que la tu sais ce que tu dois obtenir.
Voila ma version HSL:
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0501
#include <windows.h>
//#include "resource.h"
HINSTANCE hinst;
HWND hmain;
char szappname[] = "Degrader";
HBITMAP hBmp;
UCHAR *ucBits=0;
double Hue_2_RGB(double v1,double v2,double vH ) //Function Hue_2_RGB
{
if ( vH < 0 ) vH += 1;
if ( vH > 1 ) vH -= 1;
if ( ( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6 * vH );
if ( ( 2 * vH ) < 1 ) return ( v2 );
if ( ( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( 0.666666 ) - vH ) * 6 );
return v1;
}
void HSL_to_RGB(double H,double S,double L,double *R,double *G,double*B)
{
double tmp1,tmp2;
H=(double)H/239; //h,s,l compris entre 0 et 1
S=(double)S/240;
L=(double)L/240;
if(S==0)
{
*R = 255 * L;
*G = 255 * L;
*B = 255 * L;
}
else
{
if(L<0.5)tmp2 = L * (1 + S);
else tmp2 = (L + S) - (L * S);
tmp1=2 * L - tmp2;
*R = 255 * Hue_2_RGB( tmp1, tmp2, H + ( 0.333333 ) );
*G = 255 * Hue_2_RGB( tmp1, tmp2, H );
*B = 255 * Hue_2_RGB( tmp1, tmp2, H - ( 0.333333) );
}
}
void DegraderHSL(UCHAR *ucBits)
{
int i,j;
double R,G,B;
for(i=0;i<240;i++)
for(j=0;j<240;j++) {
HSL_to_RGB(i,240-j,120,&R,&G,&B);
ucBits[(i+j*240)*4]=(int)B;
ucBits[(i+j*240)*4+1]=(int)G;
ucBits[(i+j*240)*4+2]=(int)R;
}
}
LRESULT CALLBACK AppWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam)
{
static int cx=800,cy=600;
switch(mssg)
{
case WM_CREATE:
ucBits = new UCHAR[240*240*4];
if(ucBits==0)exit(0);
hBmp=CreateBitmap(240,240,1,32,ucBits);
memset(ucBits,0,240*240*4);
DegraderHSL(ucBits);
SetBitmapBits (hBmp,240*240*4,ucBits);
break;
case WM_PAINT:
HDC hdc,hdcMem;
HBITMAP hBmpTmp;
PAINTSTRUCT ps;
hdc = BeginPaint (hmain, &ps) ;
hdcMem = CreateCompatibleDC(NULL);
hBmpTmp = (HBITMAP)SelectObject(hdcMem,hBmp);
SetStretchBltMode(hdc,HALFTONE);
StretchBlt (hdc, 0, 0, cx, cy,hdcMem, 0, 0,240,240, MERGECOPY) ;
DeleteObject(hBmpTmp);
DeleteDC(hdcMem);
EndPaint(hmain, &ps);
break;
case WM_SIZE:
cx = LOWORD (lParam) ;
cy = HIWORD (lParam) ;
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, mssg, wParam, lParam);
}
DWORD __stdcall InitInstance()
{
WNDCLASSEX wndcls;
memset(&wndcls, 0, sizeof(WNDCLASSEX));
wndcls.cbSize = sizeof(WNDCLASSEX);
wndcls.lpfnWndProc = AppWndProc;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.hInstance = hinst;
wndcls.lpszClassName = szappname;
wndcls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndcls.hCursor = LoadCursor(0, IDC_ARROW);
if(!RegisterClassEx(&wndcls)) return 0;
hmain = CreateWindowEx(0, szappname, szappname, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hinst, NULL);
return (hmain != 0);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE x, PSTR y, int z)
{
MSG msg;
hinst = hInstance;
if(!InitInstance()) return 0;
ShowWindow(hmain, SW_NORMAL);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}