MCPcopy Create free account
hub / github.com/HumbleUI/Skija / pixelSorting

Method pixelSorting

examples/scenes/src/BitmapImageScene.java:115–140  ·  view source on GitHub ↗
(Canvas canvas, ByteBuffer pixels, ImageInfo info)

Source from the content-addressed store, hash-verified

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}

Callers 1

drawMethod · 0.95

Calls 6

luminocityMethod · 0.95
phaseMethod · 0.80
getColorTypeMethod · 0.65
getWidthMethod · 0.65
getHeightMethod · 0.65
getBytesPerPixelMethod · 0.65

Tested by

no test coverage detected