Skip to content
Snippets Groups Projects
Commit 2ea4739b authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Fixed bug in cava

parent 20d22368
No related branches found
No related tags found
No related merge requests found
......@@ -5,29 +5,33 @@
#include "cam_pipe_utility.h"
//#include "pipe_stages.h"
uint8_t *read_image_from_binary(char *file_path, int *row_size, int *col_size) {
uint8_t *read_image_from_binary(char *file_path, size_t *row_size,
size_t *col_size) {
uint8_t *image;
FILE *fp = fopen(file_path, "r");
int chan_size;
if (fread(row_size, sizeof(int), 1, fp) != 1)
int row_size_tmp, col_size_tmp;
if (fread(&row_size_tmp, sizeof(int), 1, fp) != 1)
assert("Failed to read row size from binary file!");
if (fread(col_size, sizeof(int), 1, fp) != 1)
if (fread(&col_size_tmp, sizeof(int), 1, fp) != 1)
assert("Failed to read col size from binary file!");
if (fread(&chan_size, sizeof(int), 1, fp) != 1)
assert("Failed to read row size from binary file!");
assert(chan_size == CHAN_SIZE && "Channel size read from the binary file "
"doesn't equal to the default value!\n");
int size = *row_size * *col_size * CHAN_SIZE;
size_t size = (size_t)row_size_tmp * col_size_tmp * CHAN_SIZE;
image = malloc_aligned(sizeof(uint8_t) * size);
if (fread(image, sizeof(uint8_t), size, fp) != size)
assert("Failed to read the image from binary file!");
fclose(fp);
*row_size = (size_t)row_size_tmp;
*col_size = (size_t)col_size_tmp;
return image;
}
void write_image_to_binary(char *file_path, uint8_t *image, int row_size,
int col_size) {
void write_image_to_binary(char *file_path, uint8_t *image, size_t row_size,
size_t col_size) {
FILE *fp = fopen(file_path, "w");
int shape[3] = {row_size, col_size, CHAN_SIZE};
......
......@@ -4,9 +4,10 @@
#include "pipe_stages.h"
#include "utility.h"
uint8_t *read_image_from_binary(char *file_path, int *row_size, int *col_size);
void write_image_to_binary(char *file_path, uint8_t *image, int row_size,
int col_size);
uint8_t *read_image_from_binary(char *file_path, size_t *row_size,
size_t *col_size);
void write_image_to_binary(char *file_path, uint8_t *image, size_t row_size,
size_t col_size);
float *transpose_mat(float *inmat, int width, int height);
void convert_hwc_to_chw(uint8_t *input, int row_size, int col_size,
uint8_t **result);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment