Compare commits

..

2 Commits

Author SHA1 Message Date
tTh
2e0809b691 small tweaks 2022-09-13 00:11:53 +02:00
tTh
8d9c91f1b7 + Image_cadre_std2 2022-09-12 23:35:54 +02:00
9 changed files with 140 additions and 74 deletions

3
Lib/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.png

View File

@ -135,8 +135,7 @@ return foo;
* 3 octobre 2009 : il faudra la renommer pour etre XXX
* en accord avec 'tga_cadre' qui la nomme "sweep". XXX
*/
int
Image_cadre_C(Image_Desc *im, int r, int g, int b, int n)
int Image_cadre_C(Image_Desc *im, int r, int g, int b, int n)
{
int x, y, x2, y2, ir, ig, ib;
float fx, fy;
@ -150,8 +149,7 @@ fn = (float)(n*n);
x2 = im->width / 2;
y2 = im->height / 2;
for (y=0; y<im->height; y++)
{
for (y=0; y<im->height; y++) {
/*
* distance au bord HAUT BAS le plus proche
*/
@ -159,8 +157,7 @@ for (y=0; y<im->height; y++)
else fy = (float)((im->height - y)-1);
fy = fy*fy;
for (x=0; x<im->width; x++)
{
for (x=0; x<im->width; x++) {
/*
* distance au bord DROITE GAUCHE le plus proche
*/
@ -172,8 +169,7 @@ for (y=0; y<im->height; y++)
if (fx < fy) d = fx;
else d = fy;
if (d < fn)
{
if (d < fn) {
coef = d / fn;
ir = (im->Rpix[y])[x];
ig = (im->Gpix[y])[x];
@ -470,5 +466,49 @@ for (y=0; y<im->height; y++)
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/* nouveau : Mon 12 Sep 2022 10:47:18 PM CEST
*/
int Image_cadre_std2(Image_Desc *im, int r, int g, int b, int nh, int nv)
{
int x, y;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d %d %d %d )\n", __func__,
im, r, g, b, nh, nv);
#endif
for (y=0; y<im->height; y++)
{
for (x=0; x<nv; x++)
{
(im->Rpix[y])[x] = r;
(im->Gpix[y])[x] = g;
(im->Bpix[y])[x] = b;
}
for (x=0; x<nv; x++)
{
Image_plotRGB(im, x+im->width - nv, y, r, g, b);
}
}
for (x=0; x<im->width; x++)
{
for (y=0; y<nh; y++)
{
(im->Rpix[y])[x] = r;
(im->Gpix[y])[x] = g;
(im->Bpix[y])[x] = b;
}
for (y=0; y<nh; y++)
{
(im->Rpix[y+im->height-nh])[x] = r;
(im->Gpix[y+im->height-nh])[x] = g;
(im->Bpix[y+im->height-nh])[x] = b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* et maintenant ? on peut aller voir 'cadres2.c' ? */
/*::------------------------------------------------------------------::*/

View File

@ -19,7 +19,7 @@ Image_print_version(int flag)
char *ptr;
fflush(stdout);
printf("-+- This is the `tthimage' library v%s (dwtfywl 2022) tTh\n",
printf("-+- This is the `tthimage' library v%s (wtfyw 2022) tTh\n",
IMAGE_VERSION_STRING);
if (flag)
{
@ -594,29 +594,25 @@ fprintf(stderr, " %p %p %p %p\n", im->Rpix, im->Gpix, im->Bpix, im->Apix);
im->magic = 0L; /* mark dirty/invalid. */
im->type = IMAGE_NONE; /* -1, et tusors */
if (im->Rpix != NULL)
{
if (im->Rpix != NULL) {
for (line=0; line<im->height; line++)
if (im->Rpix[line] != NULL) free(im->Rpix[line]);
free(im->Rpix); im->Rpix = NULL;
}
if (im->Gpix != NULL)
{
if (im->Gpix != NULL) {
for (line=0; line<im->height; line++)
if (im->Gpix[line] != NULL) free(im->Gpix[line]);
free(im->Gpix); im->Gpix = NULL;
}
if (im->Bpix != NULL)
{
if (im->Bpix != NULL) {
for (line=0; line<im->height; line++)
if (im->Bpix[line] != NULL) free(im->Bpix[line]);
free(im->Bpix); im->Bpix = NULL;
}
if (im->Apix != NULL)
{
if (im->Apix != NULL) {
for (line=0; line<im->height; line++)
if (im->Apix[line] != NULL) free(im->Apix[line]);
free(im->Apix); im->Apix = NULL;

View File

@ -11,8 +11,7 @@
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int
Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
int Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
{
int x, y, foo, N;
int r, g, b;

View File

@ -1,10 +1,12 @@
/*
------ libtthimage ------
PNG aka "portable network graphics"s.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <png.h>
@ -16,17 +18,10 @@
#include "../tthimage.h"
/*
* les infos et le code ici viennent de
* http://www.libpng.org/pub/png/pngbook.html
*/
/* static mainprog_info wpng_info; */
/*::------------------------------------------------------------------::*/
static void writepng_version_info(void)
void write_png_version_info(void)
{
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
PNG_LIBPNG_VER_STRING, png_libpng_ver);
@ -38,24 +33,54 @@ Image_Desc * Image_PNG_alloc_load(char *fname, int k)
{
#if DEBUG_LEVEL
fprintf(stderr, "%s ( '%s' %d )\n", __func__, fname, k);
writepng_version_info();
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k);
write_png_version_info();
#endif
return NULL;
}
/*::------------------------------------------------------------------::*/
/*
* http://zarb.org/~gc/html/libpng.html
* https://gist.github.com/niw/5963798
*/
int Image_save_as_PNG(Image_Desc *img, char *fname, int p1, int p2)
{
FILE *fp;
int x, y, foo;
png_uint_32 pngv;
png_structp png;
png_infop info;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
writepng_version_info();
fprintf(stderr, ">>> %s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
write_png_version_info();
#endif
fp = fopen(fname, "wb");
if (NULL == fp) {
perror(fname);
return BASIC_IO_WR_ERR;
}
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct(png);
if (setjmp(png_jmpbuf(png))) abort();
png_init_io(png, fp);
png_set_IHDR( png,
info,
img->width, img->height,
8,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT );
png_write_info(png, info);
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/

View File

@ -5,8 +5,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
#include "../tthimage.h"
void write_png_version_info(void);
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/
@ -15,12 +18,10 @@ int main(int argc, char *argv[])
{
Image_Desc *img;
int foo;
char *fname = "foo.png";
char *fname = "proto.png";
Image_print_version(0);
writepng_version_info();
if (2==argc) {
fname = argv[1];
}

View File

@ -7,8 +7,8 @@ Tester, c'est douter.
Pas grand chose.
Allez quand même voir `config.sh` et `functions.sh` pour avoir une idée
du désastre actuel
du désastre actuel. Il reste beaucoup de choses à faire.
## Mais encore ?
Dans le répertoire `Lib/` il y a un `essais.c` assez prometeur.
Dans le répertoire `Lib/` il y a un `essais.c` assez prometteur.

View File

@ -11,8 +11,8 @@
#define XMIN 0
#define YMIN 0
#define XMAX 4096 /* constant from a 'dddd' */
#define YMAX 4096 /* constant from a 'dddd' */
#define XMAX 640 /* constant from a 'dddd' */
#define YMAX 480 /* constant from a 'dddd' */
/*::------------------------------------------------------------------::*/
static Image_Desc *image;
@ -23,20 +23,22 @@ int initgr(int largeur, int hauteur)
{
int foo, r, v, b, dummy;
if ((image=Image_alloc(largeur, hauteur, 3))==NULL)
{
if (NULL==(image=Image_alloc(largeur, hauteur, 3))) {
fprintf(stderr, "hu hu, 'man addswap' :)\n");
exit(3);
}
printf("\n\tinitgr %d %d\n", largeur, hauteur);
for (foo=0; foo<8; foo++)
{
printf("Genplot2: initgr %d %d\n", largeur, hauteur);
for (foo=0; foo<8; foo++) {
#if DEBUG_LEVEL
printf("\tPal(%d) = ", foo);
#endif
r = foo & 1 ? 255 : 0;
v = foo & 2 ? 255 : 0;
b = foo & 4 ? 255 : 0;
#if DEBUG_LEVEL
printf("%02X %02X %02X\n", r, v, b);
#endif
map.red[foo] = r;
map.green[foo] = v;
map.blue[foo] = b;
@ -49,7 +51,7 @@ return 0;
int move(int x, int y)
{
#if DEBUG_LEVEL
printf("\tMOVE %5d %5d\n", x, y);
fprintf(stderr, "\tMOVE %5d %5d\n", x, y);
#endif
curX = x; curY = y;
return 0;
@ -61,7 +63,7 @@ RGBA rgba;
int idx;
#if DEBUG_LEVEL
printf("\tDRAW %5d %5d to %5d %5d\n", curX, curY, x, y);
fprintf(stderr, "\tDRAW %5d %5d to %5d %5d\n", curX, curY, x, y);
#endif
idx = color % 8;
@ -80,7 +82,7 @@ return 0;
int endgr(char *filename)
{
fprintf(stderr, "saving '%s'\n", filename);
fprintf(stderr, "genplot2 is saving to '%s'\n", filename);
Image_TGA_save(filename, image, 0);
return 0;
@ -104,17 +106,15 @@ else filename = argv[1];
if (argc<=2) image = "image.tga";
else image = argv[2];
fprintf(stderr, "*** Genplot2 v 1.0.4 [%s] (dwtfywl) 1995,2010 TontonTh \n",
TGA_OUTILS_VERSION);
/*----------- giving to the yuser some useless informations --- */
#if DEBUG_LEVEL
fprintf(stderr, "*** Genplot2 v 1.0.8 (dwtfywl) 1995,2010,2022 TontonTh \n");
fprintf(stderr, "hardcoded picsize : %d %d\n", XMAX, YMAX);
#endif
/*----------- opening input file and getting MIN and MAX values */
if ((fp = fopen(filename, "r"))==NULL)
{
if ((fp = fopen(filename, "r"))==NULL) {
perror("fichier d'entree");
exit(1);
}
@ -122,16 +122,13 @@ if ((fp = fopen(filename, "r"))==NULL)
nbp = 0;
xmin = 9999999; xmax = -9999999;
ymin = 9999999; ymax = -9999999;
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 )
{
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 ) {
nbp++;
if (x > xmax) xmax = x;
if (x < xmin) xmin = x;
if (y > ymax) ymax = y;
if (y < ymin) ymin = y;
}
fclose(fp);
@ -147,23 +144,26 @@ fprintf(stderr, "Genplot2: found %d points\n", nbp);
fx = (XMAX-XMIN-1)/(xmax-xmin);
fy = (YMAX-YMIN-1)/(ymax-ymin);
fprintf(stderr, "\nfc = %12f fy = %12f\n", fx, fy);
#if DEBUG_LEVEL
fprintf(stderr, "fc = %12f fy = %12f\n", fx, fy);
#endif
f = (fx<fy?fx:fy);
xC = 0.5*(xmin+xmax); yC = 0.5*(ymin+ymax);
XC = 0.5*(XMIN+XMAX); YC = 0.5*(YMIN+YMAX);
c1 = XC-f*xC; c2 = YC-f*yC;
#if DEBUG_LEVEL
fprintf(stderr, "c1 = %12f c2 = %12f\n", c1, c2);
#endif
/*------------- and now, plotting the image ! */
initgr(XMAX, YMAX);
fp = fopen(filename, "r");
puts("");
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 )
{
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 ) {
#if DEBUG_LEVEL
fprintf(stderr, "%12f %12f %d\n", x, y, v);
#endif

View File

@ -4,7 +4,7 @@
http:///la.buvette.org/devel/libimage/
*/
#ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 18"
#define IMAGE_VERSION_STRING "0.4.51 pl 21"
/*::------------------------------------------------------------------::*/
/*
@ -1113,10 +1113,12 @@ int Image_pix2ptl(Image_Desc *img, int seuil, Image_PtList *ptl);
int Image_cadre_A(Image_Desc *im);
int Image_cadre_B(Image_Desc *im, int larg);
int Image_cadre_cracra(Image_Desc *im, int larg, int k);
int Image_cadre_C(Image_Desc *, int, int, int, int);
int Image_cadre_C(Image_Desc *, int r, int g, int b, int sz);
int Image_cadre_bruit(Image_Desc *, int, int, int, int);
int Image_cadre_E(Image_Desc *, int, int, int, int);
int Image_cadre_std2(Image_Desc *im, int r, int g, int b, int nh, int nv);
int Image_cadre_pattern_0(Image_Desc *, Image_Desc *, int);
int Image_cadre_pattern_1(Image_Desc *im, Image_Desc *pat, int n);
int Image_cadre_pattern_2(Image_Desc *im, Image_Desc *pat, int n);