new: add quick_select

This commit is contained in:
wyj
2025-12-07 13:14:36 -05:00
parent 17165cca66
commit 1f7eb8cb36
3 changed files with 67 additions and 8 deletions
+10 -8
View File
@@ -4,6 +4,7 @@
#include <stdio.h>
#include "write_png.h"
#include "common.h"
#include "quick_select.h"
static inline double linear_to_srgb(double x){
if (x <= 0.0) return 0.0;
@@ -14,13 +15,14 @@ static inline double linear_to_srgb(double x){
int buffer_normalize_srgb(double *buffer, int W, int H) {
double max = 0;
for (int j = 0; j < H; j++) {
for (int i = 0; i < W; i++) {
for (int c = 0; c < 3; c++) {
if (max < buffer[color_index(i, j, c)]) max = buffer[color_index(i, j, c)];
}
}
}
//for (int j = 0; j < H; j++) {
// for (int i = 0; i < W; i++) {
// for (int c = 0; c < 3; c++) {
// if (max < buffer[color_index(i, j, c)]) max = buffer[color_index(i, j, c)];
// }
// }
//}
max = percentile(buffer, W*H*3, cutperc);
printf("max in the buffer: %g\n", max);
if (max == 0) return 1;
for (int j = 0; j < H; j++) {
@@ -48,7 +50,7 @@ int write_png(char *filename, double *buffer, int W, int H) {
if (v < 0) v = 0;
if (v > 255) v = 255;
img[color_index(i, j, c)] = (uint8_t) v;
printf("i: %d, j: %d, c:%d, buffer=%g, v=%d\n", i,j,c,buffer[color_index(i, j, c)],v);
//printf("i: %d, j: %d, c:%d, buffer=%g, v=%d\n", i,j,c,buffer[color_index(i, j, c)],v);
}
}
}