GP32 copy a part of an image to another image


tam

Still Fresh
Joined
Sep 16, 2003
Messages
1
hello !

I just want to get a function that can copy a part of an image (image_src) from point x1, y1 (width, height of the part are known) to another image (image_dest) at point x2, y2 (width and height of this destination image are known).

like GpBitBlt does from a source image to screen, but instead of th screen I want the destination to be another image.

can anyone help me please ?
i try to copy each pixel by using a loop, but I'm lost in the coordinates and it doesn't work.

does anyone already done a function like this ? Thanks a lot !

note : the images are 8 bits C tables, done by gp32converter from 8 bits BMP files.
 
The GP32 screen buffer starts counting in the lower left corner and then count up until the top of the screen is reached. Then it counts further from the bottom, next row. So something like this:
Code:
3 7 11
2 6 10
1 5 9
0 4 8
This is different from the coordinate system which starts in the upper left corner.
Hope this makes sense.
 
Hi

Here's a function that should do what you need.
There's no error checking but as long as you pass it valid parameters it should work ok. :)

int image_copy(char * source, int source_x_offset, int source_y_offset, int copy_width, int copy_height, int source_image_width, int source_image_height, char * target, int target_x_offset, int target_y_offset, int target_image_width, int target_image_height)
{
int source_startpos;
int target_startpos;
int temp;
int z,zz=0;

target_startpos=(target_x_offset * target_image_height)+target_image_height-target_y_offset-copy_height;
temp=(source_y_offset-(source_image_height-copy_height));
if (temp<0) temp=temp*-1;
source_startpos=(source_x_offset * source_image_height)+temp;

for (z=0;z<copy_height;z++)
{
for (zz=0;zz<copy_width;zz++)
{
target[target_startpos+z+(zz * target_image_height)]=source[source_startpos+z+(zz * source_image_height)];
}
}
}


Dave
 
Back
Top