this is a big mess
This commit is contained in:
@@ -13,7 +13,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
|
||||
equalize.o fimg-fits.o saturation.o histogram.o \
|
||||
hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \
|
||||
displacement.o dithering.o plasmas.o incrustator.o \
|
||||
killrgb.o recurse.o pixelize.o
|
||||
killrgb.o recurse.o pixelize.o decomprgb.o
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
@@ -37,6 +37,9 @@ tests.o: tests.c tests.h $(DEPS)
|
||||
|
||||
# ###
|
||||
|
||||
decomprgb.o: decomprgb.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
pixelize.o: pixelize.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
||||
149
funcs/decomprgb.c
Normal file
149
funcs/decomprgb.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* DECOMPOSITION RGB
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
/* some dirty macros */
|
||||
|
||||
#define pixidx(fi,x,y) (((y)*fi->width)+(x))
|
||||
|
||||
#define getRpix(fi,x,y) (fi->R[ pixidx(fi,(x),(y)) ])
|
||||
#define getGpix(fi,x,y) (fi->G[ pixidx(fi,(x),(y)) ])
|
||||
#define getBpix(fi,x,y) (fi->B[ pixidx(fi,(x),(y)) ])
|
||||
|
||||
/* A lot of strange and usefull parenthesis */
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
static float compute_z_value(float r, float g, float b)
|
||||
{
|
||||
double dval;
|
||||
|
||||
|
||||
|
||||
return 42.0;
|
||||
}
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
int fimg_decomp_rgbz_color(FloatImg *psrc, FloatImg *pdst, int k)
|
||||
{
|
||||
int x, y, x2, y2;
|
||||
int w2, h2, idx;
|
||||
float cumul, vgray;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
||||
psrc, pdst, k);
|
||||
#endif
|
||||
|
||||
fimg_clear(pdst);
|
||||
|
||||
w2 = psrc->width/2; h2 = psrc->height/2;
|
||||
|
||||
for (y=0; y<h2; y++)
|
||||
{
|
||||
y2 = y * 2;
|
||||
for (x=0; x<w2; x++) {
|
||||
x2 = x * 2;
|
||||
|
||||
cumul = getRpix(psrc, x2, y2) +
|
||||
getRpix(psrc, x2, y2+1) +
|
||||
getRpix(psrc, x2+1, y2) +
|
||||
getRpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray = cumul;
|
||||
pdst->R[pixidx(pdst,x,y)] = cumul;
|
||||
|
||||
cumul = getGpix(psrc, x2, y2) +
|
||||
getGpix(psrc, x2, y2+1) +
|
||||
getGpix(psrc, x2+1, y2) +
|
||||
getGpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
pdst->G[pixidx(pdst,x+w2,y)] = cumul;
|
||||
|
||||
cumul = getBpix(psrc, x2, y2) +
|
||||
getBpix(psrc, x2, y2+1) +
|
||||
getBpix(psrc, x2+1, y2) +
|
||||
getBpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
pdst->B[pixidx(pdst,x,y+h2)] = cumul;
|
||||
|
||||
idx = pixidx(pdst,x+w2,y+h2);
|
||||
pdst->R[idx] = pdst->G[idx] = \
|
||||
pdst->B[idx] = vgray / 3.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
/* PUTAIN LE COPIER/COLLÉ DE BATARD !!! */
|
||||
|
||||
int fimg_decomp_rgbz_gray(FloatImg *psrc, FloatImg *pdst, int k)
|
||||
{
|
||||
int x, y, x2, y2;
|
||||
int w2, h2, idx;
|
||||
float cumul, vgray;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
||||
psrc, pdst, k);
|
||||
#endif
|
||||
|
||||
fimg_clear(pdst);
|
||||
|
||||
w2 = psrc->width/2; h2 = psrc->height/2;
|
||||
|
||||
for (y=0; y<h2; y++)
|
||||
{
|
||||
y2 = y * 2;
|
||||
for (x=0; x<w2; x++) {
|
||||
x2 = x * 2;
|
||||
|
||||
cumul = getRpix(psrc, x2, y2) +
|
||||
getRpix(psrc, x2, y2+1) +
|
||||
getRpix(psrc, x2+1, y2) +
|
||||
getRpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray = cumul;
|
||||
idx = pixidx(pdst,x,y);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
cumul = getGpix(psrc, x2, y2) +
|
||||
getGpix(psrc, x2, y2+1) +
|
||||
getGpix(psrc, x2+1, y2) +
|
||||
getGpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
idx = pixidx(pdst,x+w2,y);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
cumul = getBpix(psrc, x2, y2) +
|
||||
getBpix(psrc, x2, y2+1) +
|
||||
getBpix(psrc, x2+1, y2) +
|
||||
getBpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
idx = pixidx(pdst,x,y+h2);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
idx = pixidx(pdst,x+w2,y+h2);
|
||||
pdst->R[idx] = pdst->G[idx] = \
|
||||
pdst->B[idx] = vgray / 3.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
@@ -44,6 +44,7 @@ if (verbosity) {
|
||||
|
||||
tiff = TIFFOpen(fname, "w");
|
||||
if (NULL==tiff) {
|
||||
fprintf(stderr, "erreur TIFFOpen\n");
|
||||
return -6;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,37 +3,52 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k)
|
||||
/* nouveau 10 octobre 2021 dans la roulotte de Terreblanque */
|
||||
|
||||
#define LARGEUR 16
|
||||
|
||||
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int largeur)
|
||||
{
|
||||
int line, col, loop, idx;
|
||||
float cr, cg, cb; /* cumuls */
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, k);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, largeur);
|
||||
#endif
|
||||
|
||||
if (fimg_images_not_compatible(psrc, pdst)) {
|
||||
fprintf(stderr, "%s: err compatibility\n", __func__);
|
||||
return -8;
|
||||
}
|
||||
|
||||
switch(largeur) {
|
||||
case 8: case 16: case 32:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "pixeliz bad width %d\n", largeur);
|
||||
return -77;
|
||||
}
|
||||
|
||||
for (line=0; line<psrc->height; line++) {
|
||||
for (col=0; col<psrc->width; col+=8) {
|
||||
for (col=0; col<psrc->width; col+=largeur) {
|
||||
cr = cg = cb = 0.0;
|
||||
idx = line * psrc->width + col;
|
||||
for (loop=0; loop<8; loop++) {
|
||||
for (loop=0; loop<largeur; loop++) {
|
||||
cr += psrc->R[idx+loop];
|
||||
cg += psrc->G[idx+loop];
|
||||
cb += psrc->B[idx+loop];
|
||||
}
|
||||
for (loop=0; loop<8; loop++) {
|
||||
pdst->R[idx+loop] = cr / 8.0;
|
||||
pdst->G[idx+loop] = cg / 8.0;
|
||||
pdst->B[idx+loop] = cb / 8.0;
|
||||
for (loop=0; loop<largeur; loop++) {
|
||||
pdst->R[idx+loop] = cr / (float)largeur;
|
||||
pdst->G[idx+loop] = cg / (float)largeur;
|
||||
pdst->B[idx+loop] = cb / (float)largeur;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +56,47 @@ for (line=0; line<psrc->height; line++) {
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* un essai dans la roulotte :)
|
||||
* 11 oct 2021 : premier jet, essai concluant, mais nécessite
|
||||
* du travail sur les rand() pour être plus 'noisy'
|
||||
*
|
||||
*/
|
||||
int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur)
|
||||
{
|
||||
static int count = 0;
|
||||
static int flag = 0;
|
||||
int foo;
|
||||
|
||||
if (0==count) {
|
||||
if (flag) {
|
||||
count = irand2(5, 10);
|
||||
flag = ! flag;
|
||||
}
|
||||
else {
|
||||
count = irand2(20, 40);
|
||||
flag = ! flag;
|
||||
}
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s c=%d f=%c\n", __func__,
|
||||
count, flag?'T':'F');
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s: count=%d flag=%d\n", __func__, count, flag);
|
||||
}
|
||||
|
||||
foo = fimg_pixelize_h_0(psrc, pdst, flag ? 8 : 32);
|
||||
if (foo) {
|
||||
fprintf(stderr, "PANIC in %s\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
count--; /* nice trick bro */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
31
funcs/sfx4.c
31
funcs/sfx4.c
@@ -40,5 +40,36 @@ for (y=0; y<src->height; y++) {
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* see also:
|
||||
sfx3.c:fimg_crump_hard()
|
||||
*/
|
||||
int fimg_split_level(FloatImg *src, FloatImg *dst, int notused)
|
||||
{
|
||||
float means[4];
|
||||
float in[3], out[3];
|
||||
int foo, idx, surface;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, src, dst, notused);
|
||||
#endif
|
||||
|
||||
foo = fimg_meanvalues(src, means);
|
||||
if (foo) {
|
||||
return -66;
|
||||
}
|
||||
|
||||
surface = src->width*src->height;
|
||||
for(idx=0; idx<surface; idx++) {
|
||||
if (src->R[idx]<means[0]) dst->R[idx]=src->R[idx]*2.0;
|
||||
else dst->R[idx]=(src->R[idx]-means[0])*2.0;
|
||||
if (src->G[idx]<means[1]) dst->G[idx]=src->G[idx]*2.0;
|
||||
else dst->G[idx]=(src->G[idx]-means[1])*2.0;
|
||||
if (src->B[idx]<means[2]) dst->B[idx]=src->B[idx]*2.0;
|
||||
else dst->B[idx]=(src->B[idx]-means[2])*2.0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
11
funcs/t.c
11
funcs/t.c
@@ -24,7 +24,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
|
||||
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
|
||||
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
|
||||
Geometrie, FileType, Mirror, KillRGB,
|
||||
Pixelize };
|
||||
Pixelize,SplitLevel,DecompRgbz };
|
||||
typedef struct {
|
||||
char *name;
|
||||
int Cmd;
|
||||
@@ -54,6 +54,8 @@ Command commands[] = {
|
||||
{ "mirror", Mirror },
|
||||
{ "killrgb", KillRGB },
|
||||
{ "pixelize", Pixelize },
|
||||
{ "spltlvl", SplitLevel },
|
||||
{ "decomprgbz", DecompRgbz },
|
||||
{ NULL, 0 }
|
||||
} ;
|
||||
|
||||
@@ -225,7 +227,12 @@ switch(opt) {
|
||||
case Pixelize:
|
||||
foo = essai_pixelize(filename, outfile);
|
||||
break;
|
||||
|
||||
case SplitLevel:
|
||||
foo = essai_split_level(filename, outfile, 0);
|
||||
break;
|
||||
case DecompRgbz:
|
||||
foo = essai_decomprgb(filename, outfile);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "'%s' is a bad command\n", command);
|
||||
exit(1);
|
||||
|
||||
@@ -46,6 +46,40 @@ if (foo) {
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_decomprgb(char *inf, char *outf)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %s %s )\n", __func__, inf, outf);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 1);
|
||||
|
||||
foo = fimg_decomp_rgbz_gray(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s:%s(): fail %d line %d\n",
|
||||
__FILE__, __func__, foo, __LINE__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
@@ -104,7 +138,7 @@ fimg_clone(&src, &dst, 0);
|
||||
/* run the crappy code */
|
||||
foo = fimg_mirror(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in fimg_mirrot\n", foo);
|
||||
fprintf(stderr, "err %d in fimg_mirror\n", foo);
|
||||
return -6;
|
||||
}
|
||||
|
||||
@@ -114,6 +148,36 @@ if (foo) {
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_split_level(char *inf, char *outf, int flags)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' 0x%X )\n", __func__,
|
||||
inf, outf, flags);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 0);
|
||||
foo = fimg_split_level(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in split_level\n", foo);
|
||||
return -6;
|
||||
}
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef);
|
||||
int essai_miroir(char *inf, char *outf, int flags);
|
||||
int essai_killrgb(char *inf, char *outf);
|
||||
int essai_decomprgb(char *inf, char *outf);
|
||||
int essai_split_level(char *inf, char *outf, int flags);
|
||||
|
||||
int essai_displacement(char *infile, char *outfile);
|
||||
int essai_qsort_rgb(char *infile, char *outfile);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -53,6 +54,12 @@ if (1 == foo) {
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Mon 11 Oct 2021 08:28:27 PM CEST */
|
||||
int irand2(int offset, int modulo)
|
||||
{
|
||||
return offset + (rand() % modulo);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int file_type_from_name(char *name)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user