📄 gradient.c
字号:
/*
* ReactOS W32 Subsystem
* Copyright (C) 1998 - 2004 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: gradient.c 26402 2007-04-18 19:07:11Z cwittich $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: GDI Driver Gradient Functions
* FILE: subsys/win32k/eng/gradient.c
* PROGRAMER: Thomas Weidenmueller
* REVISION HISTORY:
* 3/7/1999: Created
*/
#include <w32k.h>
#define NDEBUG
#include <debug.h>
/* MACROS *********************************************************************/
const LONG LINC[2] = {-1, 1};
#define VERTEX(n) (pVertex + gt->n)
#define COMPAREVERTEX(a, b) ((a)->x == (b)->x && (a)->y == (b)->y)
#define VCMPCLR(a,b,c,color) (a->color != b->color || a->color != c->color)
#define VCMPCLRS(a,b,c) \
!(!VCMPCLR(a,b,c,Red) || !VCMPCLR(a,b,c,Green) || !VCMPCLR(a,b,c,Blue))
#define MOVERECT(r,x,y) \
r.left += x; r.right += x; \
r.top += y; r.bottom += y
/* Horizontal/Vertical gradients */
#define HVINITCOL(Col, id) \
c[id] = v1->Col >> 8; \
dc[id] = abs((v2->Col >> 8) - c[id]); \
ec[id] = -(dy >> 1); \
ic[id] = LINC[(v2->Col >> 8) > c[id]]
#define HVSTEPCOL(id) \
ec[id] += dc[id]; \
while(ec[id] > 0) \
{ \
c[id] += ic[id]; \
ec[id] -= dy; \
}
/* FUNCTIONS ******************************************************************/
BOOL FASTCALL
IntEngGradientFillRect(
IN SURFOBJ *psoDest,
IN CLIPOBJ *pco,
IN XLATEOBJ *pxlo,
IN TRIVERTEX *pVertex,
IN ULONG nVertex,
IN PGRADIENT_RECT gRect,
IN RECTL *prclExtents,
IN POINTL *pptlDitherOrg,
IN BOOL Horizontal)
{
SURFOBJ *OutputObj;
TRIVERTEX *v1, *v2;
RECTL rcGradient, rcSG;
RECT_ENUM RectEnum;
BOOL EnumMore;
ULONG i;
POINTL Translate;
INTENG_ENTER_LEAVE EnterLeave;
LONG y, dy, c[3], dc[3], ec[3], ic[3];
v1 = (pVertex + gRect->UpperLeft);
v2 = (pVertex + gRect->LowerRight);
rcGradient.left = min(v1->x, v2->x);
rcGradient.right = max(v1->x, v2->x);
rcGradient.top = min(v1->y, v2->y);
rcGradient.bottom = max(v1->y, v2->y);
rcSG = rcGradient;
MOVERECT(rcSG, pptlDitherOrg->x, pptlDitherOrg->y);
if(Horizontal)
{
dy = abs(rcGradient.right - rcGradient.left);
}
else
{
dy = abs(rcGradient.bottom - rcGradient.top);
}
if(!IntEngEnter(&EnterLeave, psoDest, &rcSG, FALSE, &Translate, &OutputObj))
{
return FALSE;
}
if((v1->Red != v2->Red || v1->Green != v2->Green || v1->Blue != v2->Blue) && dy > 1)
{
CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_RIGHTDOWN, 0);
do
{
RECT FillRect;
ULONG Color;
if(Horizontal)
{
EnumMore = CLIPOBJ_bEnum(pco, (ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
for (i = 0; i < RectEnum.c && RectEnum.arcl[i].top <= rcSG.bottom; i++)
{
if(IntGdiIntersectRect(&FillRect, (PRECT)&RectEnum.arcl[i], (PRECT)&rcSG))
{
HVINITCOL(Red, 0);
HVINITCOL(Green, 1);
HVINITCOL(Blue, 2);
for(y = rcSG.left; y < FillRect.right; y++)
{
if(y >= FillRect.left)
{
Color = XLATEOBJ_iXlate(pxlo, RGB(c[0], c[1], c[2]));
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_VLine(
OutputObj, y, FillRect.top, FillRect.bottom, Color);
}
HVSTEPCOL(0);
HVSTEPCOL(1);
HVSTEPCOL(2);
}
}
}
continue;
}
/* vertical */
EnumMore = CLIPOBJ_bEnum(pco, (ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
for (i = 0; i < RectEnum.c && RectEnum.arcl[i].top <= rcSG.bottom; i++)
{
if(IntGdiIntersectRect(&FillRect, (PRECT)&RectEnum.arcl[i], (PRECT)&rcSG))
{
HVINITCOL(Red, 0);
HVINITCOL(Green, 1);
HVINITCOL(Blue, 2);
for(y = rcSG.top; y < FillRect.bottom; y++)
{
if(y >= FillRect.top)
{
Color = XLATEOBJ_iXlate(pxlo, RGB(c[0], c[1], c[2]));
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_HLine(
OutputObj, FillRect.left, FillRect.right, y, Color);
}
HVSTEPCOL(0);
HVSTEPCOL(1);
HVSTEPCOL(2);
}
}
}
} while(EnumMore);
return IntEngLeave(&EnterLeave);
}
/* rectangle has only one color, no calculation required */
CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_RIGHTDOWN, 0);
do
{
RECT FillRect;
ULONG Color = XLATEOBJ_iXlate(pxlo, RGB(v1->Red, v1->Green, v1->Blue));
EnumMore = CLIPOBJ_bEnum(pco, (ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
for (i = 0; i < RectEnum.c && RectEnum.arcl[i].top <= rcSG.bottom; i++)
{
if(IntGdiIntersectRect(&FillRect, (PRECT)&RectEnum.arcl[i], (PRECT)&rcSG))
{
for(; FillRect.top < FillRect.bottom; FillRect.top++)
{
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_HLine(
OutputObj, FillRect.left, FillRect.right, FillRect.top, Color);
}
}
}
} while(EnumMore);
return IntEngLeave(&EnterLeave);
}
/* Fill triangle with solid color */
#define S_FILLLINE(linefrom,lineto) \
if(sx[lineto] < sx[linefrom]) \
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_HLine(OutputObj, max(sx[lineto], FillRect.left), min(sx[linefrom], FillRect.right), sy, Color); \
else \
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_HLine(OutputObj, max(sx[linefrom], FillRect.left), min(sx[lineto], FillRect.right), sy, Color);
#define S_DOLINE(a,b,line) \
ex[line] += dx[line]; \
while(ex[line] > 0 && x[line] != destx[line]) \
{ \
x[line] += incx[line]; \
sx[line] += incx[line]; \
ex[line] -= dy[line]; \
}
#define S_GOLINE(a,b,line) \
if(y >= a->y && y <= b->y) \
{
#define S_ENDLINE(a,b,line) \
}
#define S_INITLINE(a,b,line) \
x[line] = a->x; \
sx[line] = a->x + pptlDitherOrg->x; \
dx[line] = abs(b->x - a->x); \
dy[line] = abs(b->y - a->y); \
incx[line] = LINC[b->x > a->x]; \
ex[line] = -(dy[line]>>1); \
destx[line] = b->x
/* Fill triangle with gradient */
#define INITCOL(a,b,line,col,id) \
c[line][id] = a->col >> 8; \
dc[line][id] = abs((b->col >> 8) - c[line][id]); \
ec[line][id] = -(dy[line]>>1); \
ic[line][id] = LINC[(b->col >> 8) > c[line][id]]
#define STEPCOL(a,b,line,col,id) \
ec[line][id] += dc[line][id]; \
while(ec[line][id] > 0) \
{ \
c[line][id] += ic[line][id]; \
ec[line][id] -= dy[line]; \
}
#define FINITCOL(linefrom,lineto,colid) \
gc[colid] = c[linefrom][colid]; \
gd[colid] = abs(c[lineto][colid] - gc[colid]); \
ge[colid] = -(gx >> 1); \
gi[colid] = LINC[c[lineto][colid] > gc[colid]]
#define FDOCOL(linefrom,lineto,colid) \
ge[colid] += gd[colid]; \
while(ge[colid] > 0) \
{ \
gc[colid] += gi[colid]; \
ge[colid] -= gx; \
}
#define FILLLINE(linefrom,lineto) \
gx = abs(sx[lineto] - sx[linefrom]); \
gxi = LINC[sx[linefrom] < sx[lineto]]; \
FINITCOL(linefrom, lineto, 0); \
FINITCOL(linefrom, lineto, 1); \
FINITCOL(linefrom, lineto, 2); \
for(g = sx[linefrom]; g != sx[lineto]; g += gxi) \
{ \
if(InY && g >= FillRect.left && g < FillRect.right) \
{ \
Color = XLATEOBJ_iXlate(pxlo, RGB(gc[0], gc[1], gc[2])); \
DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_PutPixel(OutputObj, g, sy, Color); \
} \
FDOCOL(linefrom, lineto, 0); \
FDOCOL(linefrom, lineto, 1); \
FDOCOL(linefrom, lineto, 2); \
}
#define DOLINE(a,b,line) \
STEPCOL(a, b, line, Red, 0); \
STEPCOL(a, b, line, Green, 1); \
STEPCOL(a, b, line, Blue, 2); \
ex[line] += dx[line]; \
while(ex[line] > 0 && x[line] != destx[line]) \
{ \
x[line] += incx[line]; \
sx[line] += incx[line]; \
ex[line] -= dy[line]; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -