micycle1 / PeasyGradients

Easy and sophisticated gradients in Processing
https://micycle1.github.io/PeasyGradients/
MIT License
16 stars 1 forks source link

Modify pixel loop iteration #4

Closed micycle1 closed 2 years ago

micycle1 commented 3 years ago

Make threads iterate over horizontal strips rather than squares to be more cache-friendly. This should also simplify the thread arguments.

Example

Change from this...

public Boolean call() {
    for (int y = offsetY, x; y < offsetY + pixelsY; y++) {
        for (x = offsetX; x < offsetX + pixelsX; x++) {
            gradientPG.pixels[gradientPG.width * (y + renderOffsetY)
                    + (x + renderOffsetX)] = col;
        }
    }

    return true;
}

...to something like this:

public Boolean call() {
    int pixel = startRow * p.width; // start at correct index; some row at x=0
    for (int y = 0, x; y < rows; y++) {
        for (x = 0; x < p.width; x++) { // FULL WIDTH
            gradientPG.pixels[pixel] = col;
                        pixel++;
        }
    }

    return true;
}
micycle1 commented 2 years ago

Fulfilled by https://github.com/micycle1/PeasyGradients/commit/5ae26daae61da6e3fdfcc1b6753cd1d3dfa5259b.