MCPcopy Create free account
hub / github.com/JetBrains/skija / pixelSorting

Method pixelSorting

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

Source from the content-addressed store, hash-verified

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

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