|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-3-8 21:40:34
|
显示全部楼层
源程序( 由整数运算实现,性能非常高):
#include "Include.h"
/*============================================================================*/
/*============================================================================*/
int gdev_stretch_blt( struct DC *dst_pdc,int dst_x,int dst_y,int dst_dx,int dst_dy,
struct DC *src_pdc,int src_x,int src_y,int src_dx,int src_dy,
GUI_ROP rop)
{
COORD xx,yy,xx0,yy0;
int x_scal,y_scal;
GUI_COLOR color;
////
//调整x,y缩放系数(算法优化:除法->乘法->加法)
x_scal =(1.0/((float)dst_dx/(float)src_dx))*65536.0;
y_scal =(1.0/((float)dst_dy/(float)src_dy))*65536.0;
xx =src_x;
yy =src_y;
dst_dx +=dst_x; //计算dst_x的结束坐标
dst_dy +=dst_y; //计算dst_y的结束坐标
for(yy0=dst_y;yy0<dst_dy;yy0++)
{
for(xx0=dst_x;xx0<dst_dx;xx0++)
{
color=src_pdc->GetPixel(src_pdc,HIWORD(xx),HIWORD(yy));
dst_pdc->PutPixel(dst_pdc,LOWORD(xx0),LOWORD(yy0),color);
xx+=x_scal;
}
xx =src_x;
yy +=y_scal;
}
return 1;
}
/*============================================================================*/
static U32 StretchBltTestProc(HWND hwnd,U32 msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc0,hdc1,hdc;
RTC_TIME time;
char buf[40];
static int dx,dy,x_inc,y_inc;
COORD x,y;
RECT rc;
////
switch(msg)
{
case MSG_CREATE:
TimerCreate(hwnd,0x3000,100);
dx=0;
dy=0;
x_inc=4;
y_inc=8;
break;
////
case MSG_CHAR:
switch(wParam)
{
case VK_LEFT:
GetWindowRect(hwnd,&rc);
MoveWindow(hwnd,rc.x-8,rc.y);
break;
////
case VK_RIGHT:
GetWindowRect(hwnd,&rc);
MoveWindow(hwnd,rc.x+8,rc.y);
break;
////
case VK_UP:
GetWindowRect(hwnd,&rc);
MoveWindow(hwnd,rc.x,rc.y-8);
break;
////
case VK_DOWN:
GetWindowRect(hwnd,&rc);
MoveWindow(hwnd,rc.x,rc.y+8);
break;
////
}
break;
////
case MSG_COMMAND:
{
U16 code,id;
////
code =HIWORD(wParam);
id =LOWORD(wParam);
////
}
break;
///////
case MSG_ERASEBKGND:
if(1)
{
RECT rc;
/////
hdc =GetClientDC(hwnd);
GetWindowClientRect(hwnd,&rc);
FillRectangle(hdc,0,0,rc.dx,rc.dy,GetWindowBkColor(hwnd));
ReleaseDC(hdc);
}
break;
////
case MSG_TIMER:
GetWindowClientRect(hwnd,&rc);
if(dx<=0) x_inc =4;
if(dy<=0) y_inc =8;
if(dx>=rc.dx) x_inc =-4;
if(dy>=rc.dy) y_inc =-8;
dx+=x_inc;
dy+=y_inc;
InvalidateRect(hwnd,0,1);
break;
////////////
case MSG_PAINT:
hdc=BeginPaint(hwnd);
hdc0 =CreateMemDC(64,16);
FontSetSize(hdc0,12);
GetWindowClientRect(hwnd,&rc);
RTC_GetTime(&time);
StrPrintf(buf,"%02d:%02d:%02d",time.Hour,time.Min,time.Sec);
Label(hdc0,0,0,64,16,RGB(00,24,00),RGB(60,160,00),RGB(0,0,0),CENTER,buf);
//FillRectangle(hdc,0,0,rc.dx,rc.dy,RGB(80,80,120));
x =(rc.dx-dx)>>1;
y =(rc.dy-dy)>>1;
x =MAX(0,x);
y =MAX(0,y);
dx =MIN(rc.dx,dx);
dy =MIN(rc.dy,dy);
StretchBlt(hdc,x,y,dx,dy,hdc0,0,0,64,16,0);
StrPrintf(buf,"宽度:%d,高度:%d ",dx,dy);
TextOut(hdc,4,4,RGB(255,0,0),RGB_TRANS,buf);
ReleaseDC(hdc0);
EndPaint(hwnd,hdc);
break;
////
default: DefaultWindowProc(hwnd,msg,wParam,lParam);
}
return MSG_NULL;
}
/*============================================================================*/
void StretchBltTest(void)
{
HWND hwnd;
MSG msg;
////
hwnd =CreateMainWindow( 80,80,240,180,
RGB(80,80,120),
WS_CAPTION|WS_BORDER,
0,
StretchBltTestProc,
"StretchBlt 函数演示");
ShowWindow(hwnd,0);
while(GetMessage(&msg,hwnd))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DestroyMainWindow(hwnd);
}
/*============================================================================*/ |
|