FloatImg/v4l2/rgb2fimg.c
2019-08-15 05:50:40 +02:00

102 lines
2.0 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include "../floatimg.h"
#include "funcs.h"
/* --------------------------------------------------------------------- */
int x_upscaler(unsigned char *src, int w, int h, FloatImg *d)
{
int x, y, xx, yy;
// float *rp, *gp, *bp;
float r, g, b;
static unsigned short modz;
// rp = d->R, gp = d->G, bp = d->B;
for (y=0; y<h; y++) {
yy = (y*2) + ! (modz & 1);
for (x=0; x<w; x++) {
xx = (x*2) + ! (modz & 2);
r = (float)*src++;
g = (float)*src++;
b = (float)*src++;
fimg_plot_rgb(d, xx, yy, r, g, b);
}
}
modz++;
return -1;
}
/* --------------------------------------------------------------------- */
int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d)
{
int iter, size;
float *rp, *gp, *bp;
size = w * h;
rp = d->R, gp = d->G, bp = d->B;
for (iter=0; iter<size; iter++) {
*rp++ = (float)*src++;
*gp++ = (float)*src++;
*bp++ = (float)*src++;
}
return 0;
}
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
int x_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d)
{
int iter, size;
float *rp, *gp, *bp;
size = w * h;
rp = d->R, gp = d->G, bp = d->B;
for (iter=0; iter<size; iter++) {
*rp++ += (float)*src++;
*gp++ += (float)*src++;
*bp++ += (float)*src++;
}
return 0;
}
int x_rgb2file(unsigned char *src, int w, int h, char *fname)
{
FloatImg buff;
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d '%s' )\n", __func__,
src, w, h, fname);
#endif
foo = fimg_create(&buff, w, h, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "Crash on create in %s %s\n", __FILE__, __func__);
exit(1);
}
foo = x_rgb2fimg(src, w, h, &buff);
if (foo) {
fprintf(stderr, "Crash on bit massage in %s %s\n", __FILE__, __func__);
exit(1);
}
foo = fimg_dump_to_file(&buff, fname, 0);
if (foo) {
fprintf(stderr, "Crash on dump in %s %s\n", __FILE__, __func__);
exit(1);
}
fimg_destroy(&buff);
return -1;
}
/* --------------------------------------------------------------------- */