It appears the sort functions, while sorting appropriately, are operating on the wrong sets of pixels or sub-pixel values (based on whether or not the algorithm uses Uint8array or Uint32array respectively) resulting in gradients from black to white. These sort operations should operate on pixel values resorting in sorting the colors specifically (and not the numbers that represent each channel value in the pixel.)
It appears the sort functions, while sorting appropriately, are operating on the wrong sets of pixels or sub-pixel values (based on whether or not the algorithm uses Uint8array or Uint32array respectively) resulting in gradients from black to white. These sort operations should operate on pixel values resorting in sorting the colors specifically (and not the numbers that represent each channel value in the pixel.)