Skip to content
Snippets Groups Projects
Commit 2ff55c24 authored by Yann Roberge's avatar Yann Roberge
Browse files

Squelette fonctionnel, aucun traitement d'image

parent ea631132
No related branches found
No related tags found
No related merge requests found
......@@ -9,44 +9,75 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
// Load raw image to memory. Images should be in
int loadFrameFromDisk(const uint8_t* frameBuffer, int index) {
int loadFrameFromDisk(const PixelRGB8* imageRGB, int index) {
char filepath[100];
sprintf(filepath, "FRAME_IN_DIRECTORY/FRAME_IN_FILENAME%d", index);
int fd = open(filepath);
return read(fd, (void*) frameBuffer, FRAME_BUF_SIZE);
sprintf(filepath, "%s%s%d", FRAME_IN_DIRECTORY, FRAME_IN_FILENAME, index);
FILE* fd = fopen(filepath, "r");
int i, status;
for (i=0; i< IMG_AREA; i++) {
status = fread((void*) &imageRGB[i], BYTES_PER_PIXEL, 1, fd);
if (status < 0) {
fprintf(stderr, "Error while reading %s\n", filepath);
fclose(fd);
return status;
}
}
fclose(fd);
return 0;
}
int writeFrameToDisk(const uint8_t* frameBuffer, int index) {
int writeFrameToDisk(const PixelRGB8* imageRGB, int index) {
char filepath[100];
sprintf(filepath, "FRAME_OUT_DIRECTORY/FRAME_OUT_FILENAME%d", index);
int fd = open(filepath);
return write(fd, (void*) frameBuffer, FRAME_BUF_SIZE);
sprintf(filepath, "%s%s%d", FRAME_OUT_DIRECTORY, FRAME_OUT_FILENAME, index);
FILE* fd = fopen(filepath, "w");
int i, status;
for (i=0; i< IMG_AREA; i++) {
status = fwrite((void*) &imageRGB[i], BYTES_PER_PIXEL, 1, fd);
if (status < 0) {
fprintf(stderr, "Error while reading %s\n", filepath);
fclose(fd);
return status;
}
}
fclose(fd);
return 0;
}
correctPixelColor
// Convert to HSV
int correctPixelColor(const PixelRGB8* pixel, int deltaHue, int deltaSaturation, int deltaValue) {
// TODO: Implémenter
printf("Pixel: %d %d %d\n", pixel->red, pixel->green, pixel->blue);
// Convert to HSV
// Add corrections
// Add corrections
// Convert back to RGB
// Convert back to RGB
return 0;
}
// Pass hue, saturation and value (lightness / 2) corrections to args
int main(int argc, char* argv) {
// Start timing
const uint8_t frameBuffer[FRAME_BUF_SIZE];
// TODO: Mesurer le nombre d'image par secondes traitées. Objectif 30fps
const PixelRGB8 imageRGB[IMG_AREA];
int i, j;
for (i=0; i<N_IMAGES; i++) {
loadFrameFromDisk(frameBuffer, i);
loadFrameFromDisk(imageRGB, i);
// Apply correction to each pixel and write it back to the frame buffer
for (j=0; j<FRAME_BUF_SIZE; j+=3) {
correctPixelColor(frameBuffer[j], DELTA_HUE,
DELTA_SATURATION, DELTA_VALUE);
// Apply correction to each pixel
for (j=0; j<IMG_AREA; j++) {
correctPixelColor(&imageRGB[j], DELTA_HUE,
DELTA_SATURATION, DELTA_VALUE);
}
writeFrameToDisk(frameBuffer, i);
writeFrameToDisk(imageRGB, i);
}
// Stop timing
......
/*********************************************************
* Conversion d'image RGB­> HSV > RGB
* Date: 25-Mai-2021
* Auteur: Yann Roberge
*********************************************************/
#include <stdint.h>
// Image definition
#define N_IMAGES 100
#define IMG_WIDTH 640
#define IMG_HEIGHT 360
#define IMG_AREA (IMG_WIDTH * IMG_HEIGHT)
#define IMG_DEPTH 8 // bits
#define IMG_N_CHANNELS 3 // RGB
#define BYTES_PER_PIXEL (IMG_N_CHANNELS * IMG_DEPTH / 8)
#define FRAME_BUF_SIZE (IMG_AREA * BYTES_PER_PIXEL)
// Files and directories
#define FRAME_IN_DIRECTORY "/run/user/1000/gvfs/sftp:host=odroid,user=nas/media/raid/frames/"
#define FRAME_OUT_DIRECTORY "/run/user/1000/gvfs/sftp:host=odroid,user=nas/media/raid/frames_out/"
#define FRAME_IN_FILENAME "frame"
#define FRAME_OUT_FILENAME "frameout"
// Corrections to apply
#define DELTA_HUE 50
#define DELTA_SATURATION 50
#define DELTA_VALUE 50
// Pixel struct unpacked for processing
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t RESERVED;
} PixelRGB8;
// Functions
int loadFrameFromDisk(const PixelRGB8* imageRGB, int index);
int writeFrameToDisk(const PixelRGB8* imageRGB, int index);
int correctPixelColor(const PixelRGB8* pixel, int deltaHue, int deltaSaturation,
int deltaValue);
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