(Canvas canvas, ByteBuffer pixels, ImageInfo info)
| 113 | } |
| 114 | |
| 115 | public void pixelSorting(Canvas canvas, ByteBuffer pixels, ImageInfo info) { |
| 116 | var threshold = 100 + phase() * 100; |
| 117 | // var threshold = 0.4f + phase() * 0.4f; |
| 118 | var colorType = info.getColorType(); |
| 119 | Comparator<Integer> cmp = (a, b) -> Float.compare(luminocity(colorType, a), luminocity(colorType, b)); |
| 120 | for (int x = 0; x < info.getWidth(); ++x) { |
| 121 | // read pixels |
| 122 | Integer column[] = new Integer[info.getHeight()]; |
| 123 | for (int y = 0; y < info.getHeight(); ++y) |
| 124 | column[y] = pixels.getInt((y * info.getWidth() + x) * info.getBytesPerPixel()); // Assume RGBA_8888 |
| 125 | |
| 126 | // sort pixels |
| 127 | var lastIdx = 0; |
| 128 | for (int y = 0; y < info.getHeight() - 1; ++y) { |
| 129 | if (Math.abs(luminocity(colorType, column[y]) - luminocity(colorType, column[y + 1])) > threshold) { |
| 130 | Arrays.parallelSort(column, lastIdx, y, cmp); |
| 131 | lastIdx = y; |
| 132 | } |
| 133 | } |
| 134 | Arrays.parallelSort(column, lastIdx, info.getHeight(), cmp); |
| 135 | |
| 136 | // write pixels |
| 137 | for (int y = 0; y < info.getHeight(); ++y) |
| 138 | pixels.putInt((y * info.getWidth() + x) * info.getBytesPerPixel(), column[y]); |
| 139 | } |
| 140 | } |
| 141 | } |
no test coverage detected