forked from tTh/FloatImg
more clenaup, expect more bugs
This commit is contained in:
@@ -39,9 +39,7 @@ if (s->type != FIMG_TYPE_RGB) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) {
|
||||
d = s;
|
||||
}
|
||||
if (NULL==d) { d = s; }
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : dst type %d invalide\n",
|
||||
@@ -76,9 +74,7 @@ if (s->type != FIMG_TYPE_RGB) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) {
|
||||
d = s;
|
||||
}
|
||||
if (NULL==d) { d = s; }
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s: dst type %d invalide\n",
|
||||
@@ -119,9 +115,7 @@ if (s->type != FIMG_TYPE_RGB) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) {
|
||||
d = s;
|
||||
}
|
||||
if (NULL==d) { d = s; }
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : dst type %d invalide\n",
|
||||
@@ -155,9 +149,7 @@ if (s->type != FIMG_TYPE_RGB) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) {
|
||||
d = s;
|
||||
}
|
||||
if (NULL==d) { d = s; }
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : dst type %d invalide\n",
|
||||
|
||||
@@ -42,9 +42,9 @@ fprintf(stderr, "*** FloatImg library, alpha %d (%s, %s)\n",
|
||||
FIMG_VERSION, __DATE__, __TIME__);
|
||||
|
||||
if (51 == k) {
|
||||
puts("+--------------------+");
|
||||
puts("| Pastis is coming. |");
|
||||
puts("+--------------------+");
|
||||
puts("+------------------------+");
|
||||
puts("| Pastis is coming soon |");
|
||||
puts("+------------------------+");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -118,7 +118,7 @@ if ( ! fimg_type_is_valid(type) ) {
|
||||
|
||||
/*
|
||||
* what to do if we've got a descriptor for an image
|
||||
* already allocated ?
|
||||
* already allocated ? and how to check that ?
|
||||
*/
|
||||
memset(fimg, 0, sizeof(FloatImg));
|
||||
|
||||
@@ -135,10 +135,11 @@ if (FIMG_TYPE_RGB == type) {
|
||||
}
|
||||
|
||||
if (FIMG_TYPE_RGBA == type) {
|
||||
fimg->G = (float *)plane_alloc(size);
|
||||
fimg->B = (float *)plane_alloc(size);
|
||||
fimg->A = (float *)plane_alloc(size);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,9 +166,8 @@ if (NULL == fimg->R) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
|
||||
free(fimg->R);
|
||||
if (FIMG_TYPE_RGB==fimg->type) {
|
||||
if (FIMG_TYPE_RGB == fimg->type) {
|
||||
free(fimg->G);
|
||||
free(fimg->B);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ return 0;
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_clone(FloatImg *old, FloatImg *new, int flags)
|
||||
{
|
||||
int foo;
|
||||
int foo, size;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p 0x%x )\n", __func__, old, new, flags);
|
||||
@@ -197,9 +197,11 @@ if (foo) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (flags & 0x01) {
|
||||
/* XXX copy all the pixels's datas */
|
||||
|
||||
if (flags & 0x01) { /* copy pixels values */
|
||||
size = old->width * old->height * sizeof(float);
|
||||
memcpy(new->R, old->R, size);
|
||||
memcpy(new->G, old->G, size);
|
||||
memcpy(new->B, old->B, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -240,7 +242,7 @@ if ( ! fimg_type_is_valid(fimg->type) ) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
size = fimg->width * fimg->height * fimg->type * sizeof(float);
|
||||
size = fimg->width * fimg->height * sizeof(float);
|
||||
memset(fimg->R, 0, size);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -40,7 +40,7 @@ fclose(fp);
|
||||
fprintf(stderr, " magic [%s]\n", filehead.magic);
|
||||
#endif
|
||||
|
||||
if (strncmp(filehead.magic, "FIMG", 4)) {
|
||||
if (memcmp(filehead.magic, "FIMG", 4)) {
|
||||
fprintf(stderr, "'%s' is not a fimg file.\n", fname);
|
||||
return -3;
|
||||
}
|
||||
@@ -169,6 +169,7 @@ int fimg_create_from_dump(char *fname, FloatImg *head)
|
||||
{
|
||||
FILE *fp;
|
||||
int foo, size;
|
||||
long nbread;
|
||||
FimgFileHead filehead;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
@@ -205,10 +206,10 @@ if (foo) {
|
||||
}
|
||||
|
||||
size = filehead.w * filehead.h;
|
||||
foo = 0;
|
||||
foo += fread(head->R, sizeof(float), size, fp);
|
||||
foo += fread(head->G, sizeof(float), size, fp);
|
||||
foo += fread(head->B, sizeof(float), size, fp);
|
||||
nbread = 0;
|
||||
nbread += fread(head->R, sizeof(float), size, fp);
|
||||
nbread += fread(head->G, sizeof(float), size, fp);
|
||||
nbread += fread(head->B, sizeof(float), size, fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
||||
@@ -77,11 +77,6 @@ for (idx=0; idx<surface; idx++) {
|
||||
if (fval < mmvals[4]) mmvals[4] = fval;
|
||||
else if (fval > mmvals[5]) mmvals[5] = fval;
|
||||
}
|
||||
#if 0
|
||||
for (foo=0; foo<6; foo++) {
|
||||
fprintf(stderr, "%3d %g\n", foo, mmvals[foo]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return -0;
|
||||
}
|
||||
@@ -97,10 +92,10 @@ if (surface < 1) return -1;
|
||||
memset(accus, 0, 4*sizeof(double));
|
||||
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
accus[0] += head->R[idx];
|
||||
accus[0] += (double)head->R[idx];
|
||||
if (head->type > 2) { /* WTF ? */
|
||||
accus[1] += head->G[idx];
|
||||
accus[2] += head->B[idx];
|
||||
accus[1] += (double)head->G[idx];
|
||||
accus[2] += (double)head->B[idx];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +117,6 @@ return 0;
|
||||
Mais c,a ne semble pas etre la bonne methode. Il faut aller voir :
|
||||
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
|
||||
*/
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* more elaborate functions are in fimg-2gray.c
|
||||
@@ -144,17 +138,17 @@ for (foo=0; foo<(head->width*head->height); foo++) {
|
||||
add += head->B[foo];
|
||||
head->R[foo] = head->G[foo] = head->B[foo] = add / 3.0;
|
||||
}
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
void fimg_add_cste(FloatImg *fi, float value)
|
||||
int fimg_add_cste(FloatImg *fi, float value)
|
||||
{
|
||||
int nbre, idx;
|
||||
|
||||
if (fi->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
__func__, fi->type);
|
||||
return;
|
||||
return -44;
|
||||
}
|
||||
|
||||
nbre = fi->width * fi->height ;
|
||||
@@ -166,12 +160,13 @@ for (idx=0; idx<nbre; idx++) {
|
||||
fi->G[idx] += value;
|
||||
fi->B[idx] += value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_count_negativ(FloatImg *fi)
|
||||
long fimg_count_negativ(FloatImg *fi)
|
||||
{
|
||||
int nbre, idx;
|
||||
int count;
|
||||
long count;
|
||||
|
||||
if (fi->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
@@ -183,19 +178,19 @@ nbre = fi->width * fi->height;
|
||||
|
||||
count = 0;
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
if (fi->R[idx] < 0.0) count++;
|
||||
if (fi->G[idx] < 0.0) count++;
|
||||
if (fi->B[idx] < 0.0) count++;
|
||||
if (fi->R[idx] < 0.0) count++;
|
||||
if (fi->G[idx] < 0.0) count++;
|
||||
if (fi->B[idx] < 0.0) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* nouveau 29 fevrier 2020 */
|
||||
int fimg_clamp_negativ(FloatImg *fi)
|
||||
long fimg_clamp_negativ(FloatImg *fi)
|
||||
{
|
||||
int nbre, idx;
|
||||
int count;
|
||||
long count;
|
||||
|
||||
if (fi->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
@@ -203,13 +198,18 @@ if (fi->type != FIMG_TYPE_RGB) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
nbre = fi->width * fi->height * fi->type;
|
||||
nbre = fi->width * fi->height;
|
||||
|
||||
count = 0;
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
if (fi->R[idx] < 0.0) {
|
||||
fi->R[idx] = 0.0;
|
||||
count++;
|
||||
fi->R[idx] = 0.0; count++;
|
||||
}
|
||||
if (fi->G[idx] < 0.0) {
|
||||
fi->G[idx] = 0.0; count++;
|
||||
}
|
||||
if (fi->B[idx] < 0.0) {
|
||||
fi->B[idx] = 0.0; count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,14 +229,14 @@ for (idx=0; idx<nbre; idx++) {
|
||||
return count;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
void fimg_mul_cste(FloatImg *fi, float value)
|
||||
int fimg_mul_cste(FloatImg *fi, float value)
|
||||
{
|
||||
int nbre, idx;
|
||||
|
||||
if ( (fi->type != FIMG_TYPE_RGB) && (fi->type != FIMG_TYPE_GRAY) ) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
__func__, fi->type);
|
||||
return;
|
||||
return -44;
|
||||
}
|
||||
|
||||
nbre = fi->width * fi->height;
|
||||
@@ -255,8 +255,12 @@ if (fi->type == FIMG_TYPE_GRAY) {
|
||||
fi->R[idx] *= value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* oh, please explain the usecase of this function !
|
||||
*/
|
||||
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused)
|
||||
{
|
||||
double coef;
|
||||
|
||||
@@ -190,9 +190,7 @@ switch(head->type) {
|
||||
break;
|
||||
}
|
||||
|
||||
fputs("\n", fp);
|
||||
|
||||
fclose(fp);
|
||||
fputs("\n", fp); fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* timers.c
|
||||
* timers.c BUGS INSIDE ?
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -29,9 +29,11 @@ static int rgb_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
|
||||
{
|
||||
int picsize, idx;
|
||||
|
||||
picsize = d->width * d->height * 3; /* rude hack ? */
|
||||
picsize = d->width * d->height;
|
||||
for (idx=0; idx<picsize; idx++) {
|
||||
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
|
||||
d->G[idx] = (coef * s1->G[idx]) + ((1.0-coef) * s2->G[idx]);
|
||||
d->B[idx] = (coef * s1->B[idx]) + ((1.0-coef) * s2->B[idx]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -17,7 +17,6 @@ extern int verbosity; /* must be declared around main() */
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* A + B -> D
|
||||
* why is this func so slow ?
|
||||
*/
|
||||
int fimg_add_3(FloatImg *a, FloatImg *b, FloatImg *d)
|
||||
{
|
||||
@@ -63,9 +62,6 @@ if (FIMG_TYPE_RGB != a->type || FIMG_TYPE_RGB != b->type) {
|
||||
|
||||
nbpixels = a->width * a->height;
|
||||
|
||||
/* are we cache-friendly here ?
|
||||
* we need an accurate benchmarking... */
|
||||
|
||||
for (idx=0; idx<nbpixels; idx++) {
|
||||
b->R[idx] += a->R[idx];
|
||||
b->G[idx] += a->G[idx];
|
||||
|
||||
35
lib/t.c
35
lib/t.c
@@ -26,44 +26,9 @@ B = fimg_timer_get(uuuh);
|
||||
|
||||
fprintf(stderr, " %f %f\n", A, B);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int essai_normalize(void)
|
||||
{
|
||||
FloatImg A;
|
||||
float val;
|
||||
int foo;
|
||||
|
||||
#if 0
|
||||
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s err create A %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_drand48(&A, 255.0);
|
||||
val = fimg_get_maxvalue(&A);
|
||||
fprintf(stderr, "BEFORE max pixel %f\n", val);
|
||||
|
||||
A.fval = 255.0; A.count = 1;
|
||||
|
||||
foo = fimg_normalize(&A, 1.0, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s err normalize A %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
val = fimg_get_maxvalue(&A);
|
||||
fprintf(stderr, "AFTER max pixel %f\n", val);
|
||||
|
||||
fimg_destroy(&A);
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
#define WI 1024
|
||||
#define HI 768
|
||||
|
||||
Reference in New Issue
Block a user