|
|
int Scroll_Bitmap(BITMAP_IMAGE_PTR image, int dx, int dy)
{
// this function scrolls a bitmap
BITMAP_IMAGE temp_image; // temp image buffer
// are the parms valid
if (!image || (dx==0 && dy==0))
return(0);
// scroll on x-axis first
if (dx!=0)
{
// step 1: normalize scrolling amount
dx %= image->width;
// step 2: which way?
if (dx > 0)
{
// scroll right
// create bitmap to hold region that is scrolled around
Create_Bitmap(&temp_image, 0, 0, dx, image->height, image->bpp);
// 拷贝被卷掉的那部分到新建的temp_image中(后一个的Copy_Bitmap就是把temp_image中的部分拷到需要的地方)copy region we are going to scroll and wrap around
Copy_Bitmap(&temp_image,0,0,
image, image->width-dx,0,
dx, image->height);
// set some pointers up
UCHAR *source_ptr = image->buffer; // start of each line
int shift = (image->bpp >> 3)*dx;
// now scroll image to right "scroll" pixels
for (int y=0; y < image->height; y++)
{
// scroll the line over
memmove(source_ptr+shift, source_ptr, (image->width-dx)*(image->bpp >> 3));
// advance to the next line
source_ptr+=((image->bpp >> 3)*image->width);
} // end for
// and now copy it back
Copy_Bitmap(image, 0,0, &temp_image,0,0,
dx, image->height);
} // end if
else if (dx<0){雷同,不写了}
///////////////////////X轴部分是书上的,可以横向卷动,以下是我加入的Y轴的部分,上下移动时却变成花屏,满屏都是竖线//////////////////////////
else
if (dy!=0)
{
dy%= image->height;
/*if(dy >0)
{
// scroll right
// create bitmap to hold region that is scrolled around
Create_Bitmap(&temp_image, 0, 0, image->width, dy , image->bpp);
// copy region we are going to scroll and wrap around
Copy_Bitmap(&temp_image,0,0,
image, 0, image->height-dy,
image->width, dy );
// set some pointers up
UCHAR *source_ptr = image->buffer; // start of each line
int shift = (image->bpp >> 3)* image->width*dy;
// now scroll image to right "scroll" pixels
for (int y=0; y < image->height; y++)
{
// scroll the line over
memmove(source_ptr+((image->bpp >> 3)*image->width)*dy, source_ptr, image->width*(image->bpp >> 3));
// advance to the next line
source_ptr+=((image->bpp >> 3)*image->width);
} // end for
// and now copy it back
Copy_Bitmap(image, 0,0, &temp_image,0,0,
image->width, dy );
} // end if
} // end scroll on x-axis
// return success
return(1);
} // end Scroll_Bitmap
*/
///////////////////////////////////////////////////////////
究竟错哪了,我认为步长要改为mempitch而不时用image->width,但编译时说此变量未申明,要怎么办
|
|