2019-11-15 06:07:06 +01:00
|
|
|
/*
|
|
|
|
* contrast.c - part of libfloatimg
|
|
|
|
*/
|
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-11-15 06:07:06 +01:00
|
|
|
/*
|
|
|
|
* if the second parameter is NULL, operate 'in-place'
|
|
|
|
*/
|
2019-11-12 00:20:28 +01:00
|
|
|
int fimg_square_root(FloatImg *s, FloatImg *d, double maxval)
|
|
|
|
{
|
|
|
|
int nbre, idx;
|
|
|
|
double dval;
|
|
|
|
|
|
|
|
if (s->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : type %d invalide\n",
|
|
|
|
__func__, s->type);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL==d) {
|
|
|
|
d = s;
|
|
|
|
}
|
2019-11-15 06:07:06 +01:00
|
|
|
else {
|
|
|
|
if (d->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : dst type %d invalide\n",
|
|
|
|
__func__, d->type);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 00:20:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
nbre = s->width * s->height * 3;
|
|
|
|
|
|
|
|
for (idx=0; idx<nbre; idx++) {
|
|
|
|
dval = s->R[idx] / maxval;
|
|
|
|
d->R[idx] = maxval * sqrt(dval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int fimg_power_2(FloatImg *s, FloatImg *d, double maxval)
|
|
|
|
{
|
|
|
|
int nbre, idx;
|
|
|
|
double dval;
|
|
|
|
|
|
|
|
if (s->type != FIMG_TYPE_RGB) {
|
2019-11-14 14:23:12 +01:00
|
|
|
fprintf(stderr, "%s : src type %d invalide\n",
|
2019-11-12 00:20:28 +01:00
|
|
|
__func__, s->type);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL==d) {
|
|
|
|
d = s;
|
|
|
|
}
|
2019-11-14 14:23:12 +01:00
|
|
|
else {
|
|
|
|
if (d->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : dst type %d invalide\n",
|
2019-11-15 06:07:06 +01:00
|
|
|
__func__, d->type);
|
2019-11-14 14:23:12 +01:00
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 00:20:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
nbre = s->width * s->height * 3;
|
|
|
|
|
|
|
|
for (idx=0; idx<nbre; idx++) {
|
|
|
|
dval = s->R[idx] / maxval;
|
|
|
|
d->R[idx] = maxval * dval * dval;
|
|
|
|
}
|
|
|
|
|
2019-11-14 14:23:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
#macro Cos_01( X )
|
|
|
|
(0.5-0.5*cos( 3.141592654 * X))
|
|
|
|
#end
|
|
|
|
*/
|
|
|
|
int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval)
|
|
|
|
{
|
|
|
|
int nbre, idx;
|
|
|
|
double dval;
|
|
|
|
|
|
|
|
if (s->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : type %d invalide\n",
|
|
|
|
__func__, s->type);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL==d) {
|
|
|
|
d = s;
|
|
|
|
}
|
2019-11-15 06:07:06 +01:00
|
|
|
else {
|
|
|
|
if (d->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : dst type %d invalide\n",
|
|
|
|
__func__, d->type);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 14:23:12 +01:00
|
|
|
|
|
|
|
nbre = s->width * s->height * 3;
|
|
|
|
|
|
|
|
for (idx=0; idx<nbre; idx++) {
|
|
|
|
dval = s->R[idx] / maxval;
|
|
|
|
|
|
|
|
d->R[idx] = maxval * (0.5 - 0.5 * cos(3.141592654*dval));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2019-11-12 00:20:28 +01:00
|
|
|
}
|
2019-11-14 14:23:12 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
2019-11-12 00:20:28 +01:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-11-14 14:23:12 +01:00
|
|
|
|