Пример #1
0
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ SetPixel16
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// Ignores attempts to read outside of bounds
void CBLCanvas::SetPixel16(
	SInt16			inX,
	SInt16			inY,
	TBLColour16		inCol)
{
	RGBColour		colour;

	BlastColour16ToRGBColour(inCol,&colour);
	
	SetPixelRGB(inX,inY,colour);
}
Пример #2
0
static int ColorDlgProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
    PSCOLORDIA scld;

    switch (message) {
    case MSG_INITDIALOG:
        {
            int i, j;
            Uint8 r, g, b;
            HDC hdc, mdc;
            
            scld = (PSCOLORDIA)lParam;
            SetWindowAdditionalData (hDlg, (LPARAM)scld);

            hdc = GetClientDC (hDlg);
            scld->SpaceDC = CreateCompatibleDCEx(hdc, scld->sp_w, scld->sp_h);
            mdc = CreateCompatibleDCEx (hdc, 360, 256);
            for (i =  0; i < 360; i ++) {
                for (j = 0; j < 256; j ++) {
                    HSV2RGB (i, j, 200, &r, &g, &b);
                    SetPixelRGB(mdc, i, 256-j, r, g, b);
                }
            }
            
            StretchBlt(mdc, 0, 0, 360, 256, scld->SpaceDC, 0, 0, scld->sp_w, scld->sp_h, 0);
            DeleteMemDC(mdc);
            ReleaseDC(hdc);
        }        
        break;

    case MSG_CLOSE:
        EndDialog (hDlg, SELCOLOR_CANCEL);
        break;

    case MSG_DESTROY:
        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);
        DeleteMemDC (scld->SpaceDC);
        break;

    case MSG_PAINT:
    {
        HDC hdc;

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);
        hdc = BeginPaint (hDlg);
        DrawAllSpace (hdc, scld);
        EndPaint (hDlg, hdc);
        return 0;
    }

    case MSG_COMMAND:
    {
        int msg = HIWORD(wParam);
        int id = LOWORD(wParam);

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);

        if (msg == EN_CONTCHANGED) {
            UpdateValue (hDlg, id, scld);
        }

        switch(id) {
        case IDC_CANCEL:
            EndDialog (hDlg, SELCOLOR_CANCEL);
            break;
        case IDC_OK:
            scld->H = scld->clrh;
            scld->S = scld->clrs;
            scld->V = scld->clrv;
            HSV2RGB (scld->clrh, scld->clrs, scld->clrv, &scld->R, &scld->G, &scld->B);
            scld->PIXEL = RGB2Pixel (HDC_SCREEN, scld->R, scld->G, scld->B);
            EndDialog (hDlg, SELCOLOR_OK);
            break;
        }
        break;
    }

    case MSG_LBUTTONDOWN:
    {
        int x = LOSWORD (lParam);
        int y = HISWORD (lParam);

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);

        if (PtInRect (&scld->rcSpace, x, y)) {
            HDC dc = GetClientDC (hDlg);
            scld->clrh = (x-scld->rcSpace.left)*360/RECTW(scld->rcSpace);
            scld->clrs = 256-(y-scld->rcSpace.top)*256/RECTH(scld->rcSpace);
            DrawAllSpace (dc, scld);
            SetValue (hDlg, scld);
            ReleaseDC (dc);
        }

        if (PtInRect(&scld->rcYSpace, x,y)) {
            HDC dc = GetClientDC (hDlg);
            scld->clrv = (y-scld->rcYSpace.top)*256 / RECTH(scld->rcYSpace);
            DrawAllSpace (dc, scld);
            SetValue (hDlg, scld);
            ReleaseDC (dc);
        }
    }
    }
    return DefaultDialogProc (hDlg, message, wParam, lParam);
}
Пример #3
0
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ ApplyMatrix
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// Applies an arbitary image matrix to the rectangle specified.
void CBLCanvas::ApplyMatrix(
	const CBLMatrix	&inMatrix,				// the matrix
	CBLCanvas		&inSourceCanvas,		// the canvas containing the source image
	const Rect		&inSourceRect,			// the source rectangle
	SInt16			inDestX,				// x dest
	SInt16			inDestY)				// y dest
{
	SInt16			x,y,spreadLeft,spreadRight,spreadUp,spreadDown,xm,ym,sourceX,sourceY;
	RGBColour		workCol;
	SInt32			r,g,b,element,scale;

	// Calculate the # of pix in each direction we should take into account
	spreadRight=spreadLeft=(inMatrix.GetWidth()-1)/2;
	if ((inMatrix.GetWidth()&1)==0)
		spreadRight++;
	spreadUp=spreadDown=(inMatrix.GetHeight()-1)/2;
	if ((inMatrix.GetHeight()&1)==0)
		spreadDown++;
	
	// Calc dest rect
	Rect			destRect=inSourceRect;	

	// Indent the dest rect so that we don't go outside of it for our pixels
	// (should do proper clipping really so the effect can be applied right up to the edge of the rect)
	destRect.top+=spreadUp;
	destRect.bottom-=spreadDown;
	destRect.left+=spreadLeft;
	destRect.right-=spreadRight;
	inDestX+=spreadLeft;			// adjust dest to leep it all aligned
	inDestY+=spreadUp;

	inDestX-=destRect.left;
	inDestY-=destRect.top;
	FOffset(destRect,inDestX,inDestY);
				
	// For each pixel on the screen	
	for (y=destRect.top; y<destRect.bottom; y++)
	{
		for (x=destRect.left; x<destRect.right; x++)
		{
			r=g=b=0;						// clear the working colour
			sourceX=x-inDestX-spreadLeft;	// top left calc source coords
			sourceY=y-inDestY-spreadUp;
		
			for (ym=0; ym<inMatrix.GetHeight(); ym++)
			{			
				for (xm=0; xm<inMatrix.GetWidth(); xm++)
				{
					element=inMatrix.GetElement(xm,ym);
					
					if (element)
					{
						inSourceCanvas.GetPixelRGB(sourceX+xm,sourceY+ym,workCol);
						r+=((SInt32)workCol.red)*element;
						g+=((SInt32)workCol.green)*element;
						b+=((SInt32)workCol.blue)*element;
					}					
				}
			}

			r/=inMatrix.GetScale();
			g/=inMatrix.GetScale();
			b/=inMatrix.GetScale();
			
			workCol.red=Limit(r,0,0xFFFF);
			workCol.green=Limit(g,0,0xFFFF);
			workCol.blue=Limit(b,0,0xFFFF);
			
			SetPixelRGB(x,y,workCol);
		}
	}
	
	if (mInvalCanvasAsDraw)
		InvalCanvasRect(destRect);
}