Nevermind, scratch my solution. I read wrong and mine shifts the image UP instead of DOWN. Sorry.
Geez. What were you thinking.
If you shift down one row you will shift one row out of the array. This is the same as bit shifting too far for the data type to handle. For right shifts the rightmost bit will be shifted out of the value and for left shifts, the leftmost will be shifted out. You cannot shift a 25x25 image down one row and then back up, w/o first placing the outgoing row in memory somewhere so you can stick it back in later.
However if you are drawing from an array in memory, then you can shift the starting offset down one row which will shift the image up one row and vice versa.
Code:
int iOffset=0;
int iStartOffset=iOffset;
int iX=0,iY=0;
for (int i=0;i<iImageSize;i++)
{
PutPixel(iX,iY,pImage[iOffset]);
iOffset++;
iCol++;
if (iCol>iImageWidth)
{
iCol=0;
iRow++;
iStartOffset+=iImageWidth;
iOffset=iStartOffset;
}
if (iRow>iImageHeight) break;
}
If you change iOffset to iOffset=iImageWidth*(desired_row) this will cause the drawing to start desired_row(s) into the image.
So:
Code:
iOffset+=iImageWidth; //down 1 row
iOffset-=iImageWidth; //up 1 row
That code assumes the drawing always starts at 0,0.
A better way would be to use scroll values for x and y and compute starting row and column based on these value. Then compute the starting offset from the starting row and column and save it in iOffset and iStartOffset. The rest is already done. You may want to check if row>iWindowHeight and if col>iWindowWidth. If so, you need to react accordingly. There is no need to actually alter the memory, just alter what is displayed.
This is a good pre-cursor for a tile engine. Rendering a bitmap is no different than a tile engine except that each 'tile' in a bitmap is exactly 1 pixel. Tile's are just larger 'pixels' if you will when it comes down to rendering them on screen. The memory operations are nearly identical. Rendering bitmaps is 'draw pixel from memory at x,y' and rendering tiles is 'draw tile (array of pixels) from memory at x,y'. But they are both 'paint by the number'.
In this method there are no memory write's and the memory is never changed. What is changed is where we start 'rendering from memory'. This uses a linear array with no multiplies in the loop. If you add keyboard input for ways to scroll the image, it will scroll so fast you will prob need to put a delay in the loop.