forked from tTh/FloatImg
more clenaup, expect more bugs
This commit is contained in:
parent
706e218ff0
commit
3632dc1680
12
floatimg.h
12
floatimg.h
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
* floatimg.h
|
||||
* ugly code from tTh
|
||||
* http://la.buvette.org/photos/cumul
|
||||
*/
|
||||
|
||||
#define FIMG_VERSION 122
|
||||
#define FIMG_VERSION 124
|
||||
|
||||
/*
|
||||
* in memory descriptor
|
||||
|
@ -174,12 +175,12 @@ float fimg_get_maxvalue(FloatImg *head);
|
|||
int fimg_get_minmax_rgb(FloatImg *head, float mmvals[6]);
|
||||
int fimg_meanvalues(FloatImg *head, float means[4]);
|
||||
int fimg_to_gray(FloatImg *head);
|
||||
void fimg_add_cste(FloatImg *fi, float value);
|
||||
void fimg_mul_cste(FloatImg *fi, float value);
|
||||
int fimg_add_cste(FloatImg *fi, float value);
|
||||
int fimg_mul_cste(FloatImg *fi, float value);
|
||||
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused);
|
||||
void fimg_drand48(FloatImg *fi, float kmul);
|
||||
int fimg_count_negativ(FloatImg *fi);
|
||||
int fimg_clamp_negativ(FloatImg *fi);
|
||||
long fimg_count_negativ(FloatImg *fi);
|
||||
long fimg_clamp_negativ(FloatImg *fi);
|
||||
|
||||
/* various funcs modules */
|
||||
int fimg_load_from_png(char *filename, FloatImg *fimg);
|
||||
|
@ -190,6 +191,7 @@ int fimg_save_as_bmp(FloatImg *src, char *outname, int flags);
|
|||
|
||||
int fimg_test_pattern(FloatImg *fimg, int type, double dval);
|
||||
int fimg_draw_something(FloatImg *fimg);
|
||||
int fimg_multirandom(FloatImg *fimg, long nbpass);
|
||||
|
||||
/* file is 'funcs/utils.c' */
|
||||
void fimg_print_minmax(float minmax[6], char *titre);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* classif.c
|
||||
* Detection de contours
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -26,7 +26,7 @@ int tbl[] = /* deep magic inside */
|
|||
1, 1, 0, 1,
|
||||
1, 0, 1, 1,
|
||||
1, 1, 1, 0
|
||||
};
|
||||
}; /* please explain */
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, reverse);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */
|
||||
|
||||
|
@ -48,7 +47,11 @@ dltg = minmax[3] - minmax[2];
|
|||
dltb = minmax[5] - minmax[4];
|
||||
|
||||
in = out = 0;
|
||||
|
||||
/*
|
||||
* BE WARNED !
|
||||
* This code doesn't work as expected, so I have to
|
||||
* rewrite it, maybe when the pandemic is closed...
|
||||
*/
|
||||
for (y=0; y<psrc->height; y++) {
|
||||
|
||||
for (x=0; x<psrc->width; x++) {
|
||||
|
|
|
@ -26,45 +26,36 @@ fprintf(stderr, ">>> %s ( %p '%s' 0x%X )\n", __func__,
|
|||
|
||||
filetype = format_from_extension(fname);
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "file %s : type %d\n", fname, filetype);
|
||||
fprintf(stderr, "file %s have type %d\n", fname, filetype);
|
||||
}
|
||||
|
||||
switch(filetype) {
|
||||
|
||||
case FILE_TYPE_FIMG:
|
||||
foo = fimg_dump_to_file(pic, fname, 0);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_PNM:
|
||||
foo = fimg_save_as_pnm(pic, fname, 0);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_PNG:
|
||||
foo = fimg_save_as_png(pic, fname, 0);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_TGA:
|
||||
fprintf(stderr, "%s: FILE_TYPE_TGA not implemented\n",
|
||||
__func__);
|
||||
foo = -666;
|
||||
break;
|
||||
|
||||
case FILE_TYPE_TIFF:
|
||||
foo = fimg_write_as_tiff(pic, fname, 0);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_FITS:
|
||||
foo = fimg_save_R_as_fits(pic, fname, 0);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_BMP:
|
||||
fprintf(stderr, "%s: file type BMP not implemented\n", __func__);
|
||||
foo = -666;
|
||||
|
||||
default:
|
||||
foo = -1789;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (foo) {
|
||||
|
|
|
@ -26,6 +26,10 @@ if (dst->type != FIMG_TYPE_RGB) {
|
|||
fprintf(stderr, "%s: dst type %d invalid\n", __func__, dst->type);
|
||||
return -99;
|
||||
}
|
||||
if (fimg_images_not_compatible(src, dst)) {
|
||||
fprintf(stderr, "%s: src & dst not comatibles\n", __func__);
|
||||
return -98;
|
||||
}
|
||||
|
||||
/* aliasing some vars for cleaner code */
|
||||
pr = src->R; pg = src->G; pb = src->B;
|
||||
|
@ -146,7 +150,6 @@ h = img->height; w = img->width;
|
|||
for (idx=0; idx<h; idx++) {
|
||||
|
||||
#define FAST 1
|
||||
|
||||
#if FAST
|
||||
img->R[idx*w] = 0.0;
|
||||
img->G[idx*w] = 0.0;
|
||||
|
|
|
@ -43,7 +43,6 @@ switch (plane) {
|
|||
return -66;
|
||||
}
|
||||
|
||||
|
||||
remove(outname); /* Delete old file if it already exists */
|
||||
if (fits_create_file(&fptr, outname, &status)) {
|
||||
fits_report_error(stderr, status);
|
||||
|
@ -53,7 +52,6 @@ if (fits_create_file(&fptr, outname, &status)) {
|
|||
naxes[0] = src->width; naxes[1] = src->height;
|
||||
if (verbosity) fimg_describe(src, "to be saved as FITS");
|
||||
|
||||
|
||||
if ( fits_create_img(fptr, bitpix, naxis, naxes, &status) ) {
|
||||
fits_report_error(stderr, status);
|
||||
return -10;
|
||||
|
|
|
@ -54,9 +54,9 @@ TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 3); // RGB
|
|||
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 16); // 0->65535
|
||||
|
||||
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
|
||||
sprintf(ligne, "lib FloatImg %d by tTh", FIMG_VERSION);
|
||||
sprintf(ligne, "lib FloatImg v %d by tTh", FIMG_VERSION);
|
||||
TIFFSetField(tiff, TIFFTAG_SOFTWARE, ligne);
|
||||
|
||||
foo = src->width * 3;
|
||||
|
@ -66,7 +66,6 @@ if (verbosity) fprintf(stderr, "default strip size %d\n", foo);
|
|||
TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, foo);
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
|
||||
ptr = linebuff;
|
||||
idx = y * src->width;
|
||||
|
||||
|
@ -78,7 +77,6 @@ for (y=0; y<src->height; y++) {
|
|||
}
|
||||
|
||||
TIFFWriteScanline(tiff, linebuff, y, 0);
|
||||
|
||||
idx += src->width;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ float rgb[3], moy;
|
|||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, ghist, sz);
|
||||
#endif
|
||||
|
||||
if (FIMG_TYPE_RGB != src->type) {
|
||||
fprintf(stderr, "%s: bad type %d of image\n", __func__, src->type);
|
||||
return -97;
|
||||
}
|
||||
|
||||
maxval = fimg_get_maxvalue(src);
|
||||
|
||||
fprintf(stderr, "maximum is %f\n", maxval);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
testing some random funcs.
|
||||
|
||||
*/
|
||||
* This is an eternal WIP, sorry...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -56,7 +55,6 @@ for (x=0; x<fimg->width; x++) {
|
|||
// fprintf(stderr, " %6d %f\n", x, val);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -88,14 +86,14 @@ for (y=1; y<fimg->height; y++) {
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_multirandom(FloatImg *fimg)
|
||||
int fimg_multirandom(FloatImg *fimg, long nbpass)
|
||||
{
|
||||
int foo, x, y;
|
||||
|
||||
#define RI ( (rand()/7) + (rand()/9) )
|
||||
#define RD ( (drand48()/7) + (drand48()/7) )
|
||||
|
||||
for (foo=0; foo<100000000; foo++)
|
||||
for (foo=0; foo<nbpass; foo++)
|
||||
{
|
||||
x = RI % fimg->width;
|
||||
y = RI % fimg->height;
|
||||
|
|
|
@ -34,7 +34,7 @@ return 0;
|
|||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* wtf ? ther's no way to have the black at the bottom ?
|
||||
* To have the black at the bottom, use a negative dcoef
|
||||
*/
|
||||
int fimg_vdeg_a(FloatImg *img, double dcoef)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,9 @@ for (foo=0; foo<nbpix; foo++) {
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* parameter fval is not used, why ?
|
||||
*/
|
||||
int fimg_killcolors_b(FloatImg *fimg, float fval)
|
||||
{
|
||||
int nbpix, foo;
|
||||
|
|
|
@ -145,12 +145,10 @@ opt = lookup_cmd(command);
|
|||
switch(opt) {
|
||||
case Equalize:
|
||||
foo = essai_equalize(filename); break;
|
||||
|
||||
case Sfx0:
|
||||
foo = essai_sfx0(filename); break;
|
||||
case F3x3:
|
||||
foo = essai_filtrage_3x3(filename); break;
|
||||
|
||||
case MIRE:
|
||||
foo = essai_mire(filename, 0);
|
||||
break;
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
*/
|
||||
|
||||
int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef)
|
||||
{
|
||||
FloatImg src, dst;
|
||||
|
@ -273,6 +272,9 @@ else {
|
|||
abort();
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX need more work on this function !
|
||||
*/
|
||||
foo = fimg_equalize_compute(&src, NULL, 666.666);
|
||||
fprintf(stderr, "equalize compute --> %d\n", foo);
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
/*
|
||||
* FloatImg from tTh - 2021
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -15,7 +17,6 @@ fprintf(stderr, "\t\tminmax %s\n", titre);
|
|||
fprintf(stderr, "red\t\t%10f %10f\n", minmax[0], minmax[1]);
|
||||
fprintf(stderr, "green\t\t%10f %10f\n", minmax[2], minmax[3]);
|
||||
fprintf(stderr, "blue\t\t%10f %10f\n", minmax[4], minmax[5]);
|
||||
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int parse_WxH(char *str, int *pw, int *ph)
|
||||
|
@ -33,7 +34,6 @@ if (2 != foo) {
|
|||
fprintf(stderr, "%s : arg '%s' is invalid\n", __func__, str);
|
||||
return foo;
|
||||
}
|
||||
|
||||
*pw = w; *ph = h;
|
||||
|
||||
return 2;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue