Untitled
raw download clone
TEXT
views 14
,
size 1079 b
void printImage(const Image& img)
{
    for(int i=0;i<img.height;i++)
    {
        for(int j=0;j<img.width;j++)
        {
            cout << img.pixels[i*img.width + j] << " ";
        }
        cout << endl;
    }
}

Image halve(const Image& img)
{
    Image halveImg;
    halveImg.height = (img.height+1)/2;
    halveImg.width = (img.width+1)/2;
    int n = 0; // height
    int m = 0; // width
    for(int i=0;i<img.height;i++)
    {
        for(int j=0;j<img.width;j++)
        {
            if( i%2 == 0 && j%2 == 0 )
            {
                halveImg.pixels[n*halveImg.width+m] = img.pixels[i*img.width + j];
                    m++;
                    n++;
                if( m == halveImg.width )
                {
                    if( n < halveImg.height )
                    {
                        m = 0;
                    }
                    else 
                    {
                        n = 0;
                        m = 0;
                    }
                }
            }
        }
    }

}
close fullscreen
Login or Register to edit or fork this paste. It's free.