diff --git a/src/pixeldata_utils.c b/src/pixeldata_utils.c new file mode 100644 index 0000000..4860739 --- /dev/null +++ b/src/pixeldata_utils.c @@ -0,0 +1,22 @@ +// +// Created by marcsello on 03/11/2020. +// + +#include "pixeldata_utils.h" + +uint8_t flip_image(const uint8_t *source, uint8_t *destination, uint64_t data_length, uint64_t width, uint64_t height) { + + if ((width*height*3) != data_length) { + return IMAGE_FLIP_FAIL; + } + + for (uint64_t i = 0; i < height; i++) { + for (uint64_t j = 0; j < width; j++) { + destination[(i * width + j) * 3] = source[((height - i - 1) * width + j) * 3]; + destination[(i * width + j) * 3 + 1] = source[((height - i - 1) * width + j) * 3 + 1]; + destination[(i * width + j) * 3 + 2] = source[((height - i - 1) * width + j) * 3 + 2]; + } + } + + return IMAGE_FLIP_SUCCESS; +} \ No newline at end of file diff --git a/src/pixeldata_utils.h b/src/pixeldata_utils.h new file mode 100644 index 0000000..04ca1de --- /dev/null +++ b/src/pixeldata_utils.h @@ -0,0 +1,15 @@ +// +// Created by marcsello on 03/11/2020. +// + +#ifndef CAFF_PREVIEWER_PIXELDATA_UTILS_H +#define CAFF_PREVIEWER_PIXELDATA_UTILS_H + +#include + +#define IMAGE_FLIP_SUCCESS 0 +#define IMAGE_FLIP_FAIL 0 + +uint8_t flip_image(const uint8_t* source, uint8_t* destination, uint64_t data_length, uint64_t width, uint64_t height); + +#endif //CAFF_PREVIEWER_PIXELDATA_UTILS_H