Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I guess you are trying to implement your solution from this post.

Here is an alternative way to loop over the pixels. Its slower then old c-style but faster then the unoptimized version:

for (size_t y = 0; y < imageHeight - 1; ++y)
{
    for (size_t x = 0; x < imageWidth - 1; ++x)
    {
        idx = y * imageWidth + x;
        //Look straigth right
        pimg[idx + 1]
        //Look straigth down
        pimg[idx + imageWidth];
        //Look down right
        pimg[idx + imageWidth + 1]
    }
}

Ofcourse you have to stop at maxCol-1/maxRow-1 so you stay within the boundaries of image. You can add a special case for the last row, where i just look at the right side or something like this. Dont get me wrong you can also use old c-style but you need aditional checks inorder to know when a new row starts.

Hope this helps.

I guess you are trying to implement your solution from this post.

Here is an alternative way to loop over the pixels. Its slower then old c-style but faster then the unoptimized version:

for (size_t y = 0; y < imageHeight - 1; ++y)
{
    for (size_t x = 0; x < imageWidth - 1; ++x)
    {
        idx = y * imageWidth + x;
        //Look straigth right
        pimg[idx + 1]
        //Look straigth down
        pimg[idx + imageWidth];
        //Look down right
        pimg[idx + imageWidth + 1]
    }
}

Ofcourse you have to stop at maxCol-1/maxRow-1 so you stay within the boundaries of image. You can add a special case for the last row, where i you just look at the right side or something like this. Dont get me wrong you can also use old c-style but you need aditional checks inorder to know when a new row starts.

Hope this helps.