small tweaks

This commit is contained in:
tTh 2022-09-13 00:11:53 +02:00
parent 8d9c91f1b7
commit 2e0809b691
7 changed files with 85 additions and 61 deletions

3
Lib/.gitignore vendored Normal file
View File

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

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,21 +18,14 @@
#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",
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
PNG_LIBPNG_VER_STRING, png_libpng_ver);
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
ZLIB_VERSION, zlib_version);
}
/*::------------------------------------------------------------------::*/
@ -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