pixel/default
Pixel Sort
- kind
- pixel sorting
- sorted by
- brightness
pick a language to open the code
def luma(pixel): r, g, b = pixel return (r * 299 + g * 587 + b * 114) // 1000 def sort_row(pixels, w, y, threshold): x = 0 while x < w: if luma(pixels[y * w + x]) < threshold: x += 1 continue end = x while end < w and luma(pixels[y * w + end]) >= threshold: end += 1 span = pixels[y * w + x:y * w + end] span.sort(key=luma) pixels[y * w + x:y * w + end] = span x = end
function luma(pixel) { return (pixel.r * 299 + pixel.g * 587 + pixel.b * 114) / 1000; } function sortRow(pixels, w, y, threshold) { let x = 0; while (x < w) { if (luma(pixels[y * w + x]) < threshold) { x++; continue; } let end = x; while (end < w && luma(pixels[y * w + end]) >= threshold) end++; const span = pixels.slice(y * w + x, y * w + end); span.sort((p, q) => luma(p) - luma(q)); for (let k = 0; k < span.length; k++) pixels[y * w + x + k] = span[k]; x = end; } }
static int luma(Pixel p) { return (p.r * 299 + p.g * 587 + p.b * 114) / 1000; } static int by_luma(const void* left, const void* right) { return luma(*(const Pixel*)left) - luma(*(const Pixel*)right); } void sort_row(Pixel pixels[], int w, int y, int threshold) { int x = 0; while (x < w) { if (luma(pixels[y * w + x]) < threshold) { x++; continue; } int end = x; while (end < w && luma(pixels[y * w + end]) >= threshold) end++; qsort(pixels + y * w + x, end - x, sizeof(Pixel), by_luma); x = end; } }
static int luma(const Pixel& p) { return (p.r * 299 + p.g * 587 + p.b * 114) / 1000; } void sort_row(std::vector<Pixel>& pixels, int w, int y, int threshold) { int x = 0; while (x < w) { if (luma(pixels[y * w + x]) < threshold) { x++; continue; } int end = x; while (end < w && luma(pixels[y * w + end]) >= threshold) end++; auto row = pixels.begin() + y * w; std::sort(row + x, row + end, [](const Pixel& p, const Pixel& q) { return luma(p) < luma(q); }); x = end; } }
static int Luma(Pixel p) { return (p.R * 299 + p.G * 587 + p.B * 114) / 1000; } static void SortRow(Pixel[] pixels, int w, int y, int threshold) { int x = 0; while (x < w) { if (Luma(pixels[y * w + x]) < threshold) { x++; continue; } int end = x; while (end < w && Luma(pixels[y * w + end]) >= threshold) end++; Array.Sort(pixels, y * w + x, end - x, Comparer<Pixel>.Create((p, q) => Luma(p) - Luma(q))); x = end; } }
static int luma(Pixel p) { return (p.r * 299 + p.g * 587 + p.b * 114) / 1000; } static void sortRow(Pixel[] pixels, int w, int y, int threshold) { int x = 0; while (x < w) { if (luma(pixels[y * w + x]) < threshold) { x++; continue; } int end = x; while (end < w && luma(pixels[y * w + end]) >= threshold) end++; Arrays.sort(pixels, y * w + x, y * w + end, (p, q) -> luma(p) - luma(q)); x = end; } }