1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
// Example program
// <written by> <date>
//STD includes
#include <iostream> //#include <string> not needed
//Function Declaration(s)
void pictureCrop(int src[], int width, int height, int startR, int startC, int subW, int subH, int dest[]);
//Main function //start to program
int main()
{
int src[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};//16, 4x4. test.
int dest[]={};
pictureCrop(src, 4, 4, 2, 2, 2, 2, dest); //4x4 img; start @2,2; make 2x2 copy.
std::cout << src[0] << src[1] << src[2] << src[3] << '\n';
std::cout << src[4] << src[5] << src[6] << src[7] << '\n';
std::cout << src[8] << src[9] << src[10] << src[11] << '\n';
std::cout << src[12] << src[13] << src[14] << src[15] << '\n';
std::cout << "\n\n"; //spacer
std::cout << dest[0] << dest[1] << '\n';
std::cout << dest[2] << dest[3] << '\n';
return 0;
}
void pictureCrop(int src[], int width, int height, int startR, int startC, int subW, int subH, int dest[])
{
int count = 0; //counts through the dest array
for (int i=startC; i<startC+subH; i++)
{
for (int j=startR; j<startR+subW; j++)
{
dest[count] = src[(width*i)+j]; //EOL math is (width*i)+j
count++;
}
}
}
|