Files
go-darknet/image.c
Julian Langschaedel 7e34b459e6 DarknetImage move float conversion into c code
imgTofloat32 + fill_image_f32 took more than double the time since tofloat created needless allocations and iterate over each pixel, and fill_image in c then iterate over each pixel*3 again just to move it into the c image.
2022-03-02 19:19:47 +01:00

29 lines
783 B
C

#include <darknet.h>
void fill_image_f32(image* im, int w, int h, int c, float* data) {
int i;
for (i = 0; i < w*h*c; i++) {
im->data[i] = data[i];
}
}
void set_data_f32_val(float* data, int index, float value) {
data[index] = value;
}
void to_float_and_fill_image(image* im, int w, int h, uint8_t* data) {
int x, y, idx_source;
int pixel_count = w * h;
int idx = 0;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
idx_source = (y*w + x) * 4;
im->data[(pixel_count*0) + idx] = (float)data[idx_source] / 255;
im->data[(pixel_count*1) + idx] = (float)data[idx_source+1] / 255;
im->data[(pixel_count*2) + idx] = (float)data[idx_source+2] / 255;
idx++;
}
}
}