forked from tTh/FloatImg
67 lines
1.3 KiB
C
67 lines
1.3 KiB
C
/*
|
|
* FloatImg library from tTh
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "../floatimg.h"
|
|
|
|
/* -------------------------------------------------------------- */
|
|
/* global vars from main
|
|
*/
|
|
extern int verbosity;
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int fimg_mix_rgb_gray(FloatImg *img, float mix)
|
|
{
|
|
int x, y, p;
|
|
float gr;
|
|
|
|
if (FIMG_TYPE_RGB != img->type) {
|
|
fprintf(stderr, "%s bad type\n", __func__);
|
|
return -6;
|
|
}
|
|
|
|
for (y=0; y<img->height; y++) {
|
|
p = y * img->width;
|
|
for (x=0; x<img->width; x++) {
|
|
|
|
gr = (img->R[p] + img->G[p] + img->R[p]) / 3.0;
|
|
|
|
img->R[p] = ((gr * mix) + (img->R[p] * (1.0-mix))) / 2.0;
|
|
img->G[p] = ((gr * mix) + (img->G[p] * (1.0-mix))) / 2.0;
|
|
img->B[p] = ((gr * mix) + (img->B[p] * (1.0-mix))) / 2.0;
|
|
|
|
p++; /* next pixel in the row */
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
int fimg_shift_to_zero(FloatImg *s, FloatImg *d, float coefs[6])
|
|
{
|
|
int sz, idx;
|
|
|
|
sz = s->width * s->height;
|
|
|
|
if (FIMG_TYPE_RGB != img->type) {
|
|
fprintf(stderr, "%s bad type\n", __func__);
|
|
return -6;
|
|
}
|
|
|
|
for (idx=0; idx<sz; idx++) {
|
|
d->R[idx] = s->R[idx] - coefs[0];
|
|
d->G[idx] = s->G[idx] - coefs[2];
|
|
d->B[idx] = s->B[idx] - coefs[4];
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|