此代码来源于microwindows中的代码,将解压出来的位图缩放。
#define DEFINE_COPY_ROW(name, type) /
static void name(type *src, int src_w, type *dst, int dst_w) /
{ /
int i; /
int pos, inc; /
type pixel = 0; /
/
pos = 0x10000; /
inc = (src_w << 16) / dst_w; /
for ( i=dst_w; i>0; --i ) { /
while ( pos >= 0x10000L ) { /
pixel = *src++; /
pos -= 0x10000L; /
} /
*dst++ = pixel; /
pos += inc; /
} /
}
//DEFINE_COPY_ROW(copy_row1, unsigned char)
//DEFINE_COPY_ROW(copy_row2, unsigned short)
DEFINE_COPY_ROW(copy_row4, unsigned long)
/*static void copy_row3(unsigned char *src, int src_w, unsigned char *dst,
int dst_w)
{
int i;
int pos, inc;
unsigned char r = 0;
unsigned char g = 0;
unsigned char b = 0;
pos = 0x10000;
inc = (src_w << 16) / dst_w;
for ( i=dst_w; i>0; --i ) {
while ( pos >= 0x10000L ) {
b = *src++;
g = *src++;
r = *src++;
pos -= 0x10000L;
}
*dst++ = b;
*dst++ = g;
*dst++ = r;
pos += inc;
}
}*/
//src bytesperpixel equals dst bytesperpixel
//pSrc -- source image buffer
//full_src -- source image actual rect
//srcrect -- blit source image rect
//pDst -- destination image buffer
//full_dst -- destination image actual rect
//dstrect -- blit destination image rect
void StretchImage( uint8 *pSrc, Rect *full_src, Rect *srcrect, uint8 *pDest, Rect *full_dst, Rect *dstrect)
{
uint32 pos,inc;
uint32 src_row, dst_maxrow,dst_row,bytesperpixel,count=0;
uint8 *dstp,*srcp=0;
if((full_src == NULL) || (full_dst == NULL))
return ;
/* Verify the blit rectangles */
if ( srcrect )
{
if ( (srcrect->x < 0) || (srcrect->y < 0) ||
((srcrect->x+srcrect->width) > full_src->width) ||
((srcrect->y+srcrect->height) > full_src->height) )
{
printf(" StretchImage: invalid source rect/n");
return;
}
}
else
srcrect = full_src;
if( dstrect )
{
/* if stretching to nothing, return*/
if (!dstrect->width || !dstrect->height)
return;
if ( (dstrect->x < 0) || (dstrect->y < 0) ||
((dstrect->x+dstrect->width) > full_dst->width) ||
((dstrect->y+dstrect->height) > full_dst->height) )
{
printf(" StretchImage: invalid dest rect/n");
return;
}
}
else
dstrect = full_dst;
/* Set up the data... */
pos = 0x10000L;
inc = (srcrect->height << 16) / dstrect->height;
src_row = srcrect->y;
dst_row = dstrect->y;
bytesperpixel = 4;
/* Perform the stretch blit */
printf((DISABLE,"(%ld,%ld,%ld,%ld),(%ld,%ld,%ld,%ld)/n",
srcrect->x,srcrect->y,srcrect->width,srcrect->height,
dstrect->x,dstrect->y,dstrect->width,dstrect->height));
for ( dst_maxrow = dst_row+dstrect->height; dst_row<dst_maxrow; ++dst_row )
{
dstp = pDest + (dst_row*full_dst->width*bytesperpixel) + (dstrect->x * bytesperpixel);
while ( pos >= 0x10000L ) {
srcp = pSrc + (src_row*full_src->width*bytesperpixel)
+ (srcrect->x*bytesperpixel);
++src_row;
pos -= 0x10000L;
}
count++;
copy_row4((unsigned long *)srcp, srcrect->width,
(unsigned long *)dstp, dstrect->width);
/*switch (bytesperpixel)
{
case 1:
copy_row1(srcp, src_width, dstp, dst_width);
break;
case 2:
copy_row2((unsigned short *)srcp, src_width,
(unsigned short *)dstp, dst_width);
break;
case 3:
copy_row3(srcp, src_width, dstp, dst_width);
break;
case 4:
copy_row4((unsigned long *)srcp, src_width,
(unsigned long *)dstp, dst_width);
break;
}*/
pos += inc;
}
}