small tweaks
This commit is contained in:
parent
8d9c91f1b7
commit
2e0809b691
3
Lib/.gitignore
vendored
Normal file
3
Lib/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
*.png
|
||||||
|
|
14
Lib/image.c
14
Lib/image.c
@ -19,7 +19,7 @@ Image_print_version(int flag)
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
fflush(stdout);
|
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);
|
IMAGE_VERSION_STRING);
|
||||||
if (flag)
|
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->magic = 0L; /* mark dirty/invalid. */
|
||||||
im->type = IMAGE_NONE; /* -1, et tusors */
|
im->type = IMAGE_NONE; /* -1, et tusors */
|
||||||
|
|
||||||
if (im->Rpix != NULL)
|
if (im->Rpix != NULL) {
|
||||||
{
|
|
||||||
for (line=0; line<im->height; line++)
|
for (line=0; line<im->height; line++)
|
||||||
if (im->Rpix[line] != NULL) free(im->Rpix[line]);
|
if (im->Rpix[line] != NULL) free(im->Rpix[line]);
|
||||||
free(im->Rpix); im->Rpix = NULL;
|
free(im->Rpix); im->Rpix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (im->Gpix != NULL)
|
if (im->Gpix != NULL) {
|
||||||
{
|
|
||||||
for (line=0; line<im->height; line++)
|
for (line=0; line<im->height; line++)
|
||||||
if (im->Gpix[line] != NULL) free(im->Gpix[line]);
|
if (im->Gpix[line] != NULL) free(im->Gpix[line]);
|
||||||
free(im->Gpix); im->Gpix = NULL;
|
free(im->Gpix); im->Gpix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (im->Bpix != NULL)
|
if (im->Bpix != NULL) {
|
||||||
{
|
|
||||||
for (line=0; line<im->height; line++)
|
for (line=0; line<im->height; line++)
|
||||||
if (im->Bpix[line] != NULL) free(im->Bpix[line]);
|
if (im->Bpix[line] != NULL) free(im->Bpix[line]);
|
||||||
free(im->Bpix); im->Bpix = NULL;
|
free(im->Bpix); im->Bpix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (im->Apix != NULL)
|
if (im->Apix != NULL) {
|
||||||
{
|
|
||||||
for (line=0; line<im->height; line++)
|
for (line=0; line<im->height; line++)
|
||||||
if (im->Apix[line] != NULL) free(im->Apix[line]);
|
if (im->Apix[line] != NULL) free(im->Apix[line]);
|
||||||
free(im->Apix); im->Apix = NULL;
|
free(im->Apix); im->Apix = NULL;
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
#include "../tthimage.h"
|
#include "../tthimage.h"
|
||||||
|
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
int
|
int Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
|
||||||
Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
|
|
||||||
{
|
{
|
||||||
int x, y, foo, N;
|
int x, y, foo, N;
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
|
67
Lib/png.c
67
Lib/png.c
@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
|
------ libtthimage ------
|
||||||
PNG aka "portable network graphics"s.
|
PNG aka "portable network graphics"s.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
@ -16,46 +18,69 @@
|
|||||||
#include "../tthimage.h"
|
#include "../tthimage.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* les infos et le code ici viennent de
|
* http://www.libpng.org/pub/png/pngbook.html
|
||||||
* 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);
|
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);
|
ZLIB_VERSION, zlib_version);
|
||||||
}
|
}
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
Image_Desc * Image_PNG_alloc_load(char *fname, int k)
|
Image_Desc * Image_PNG_alloc_load(char *fname, int k)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, "%s ( '%s' %d )\n", __func__, fname, k);
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k);
|
||||||
writepng_version_info();
|
write_png_version_info();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NULL;
|
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)
|
int Image_save_as_PNG(Image_Desc *img, char *fname, int p1, int p2)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int x, y, foo;
|
int x, y, foo;
|
||||||
png_uint_32 pngv;
|
png_structp png;
|
||||||
|
png_infop info;
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, "%s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
|
fprintf(stderr, ">>> %s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
|
||||||
writepng_version_info();
|
write_png_version_info();
|
||||||
#endif
|
#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;
|
return FULL_NUCKED;
|
||||||
}
|
}
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <png.h>
|
||||||
|
|
||||||
#include "../tthimage.h"
|
#include "../tthimage.h"
|
||||||
|
|
||||||
|
void write_png_version_info(void);
|
||||||
|
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
@ -15,12 +18,10 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
Image_Desc *img;
|
Image_Desc *img;
|
||||||
int foo;
|
int foo;
|
||||||
char *fname = "foo.png";
|
char *fname = "proto.png";
|
||||||
|
|
||||||
Image_print_version(0);
|
Image_print_version(0);
|
||||||
|
|
||||||
writepng_version_info();
|
|
||||||
|
|
||||||
if (2==argc) {
|
if (2==argc) {
|
||||||
fname = argv[1];
|
fname = argv[1];
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ Tester, c'est douter.
|
|||||||
Pas grand chose.
|
Pas grand chose.
|
||||||
|
|
||||||
Allez quand même voir `config.sh` et `functions.sh` pour avoir une idée
|
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 ?
|
## 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.
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#define XMIN 0
|
#define XMIN 0
|
||||||
#define YMIN 0
|
#define YMIN 0
|
||||||
#define XMAX 4096 /* constant from a 'dddd' */
|
#define XMAX 640 /* constant from a 'dddd' */
|
||||||
#define YMAX 4096 /* constant from a 'dddd' */
|
#define YMAX 480 /* constant from a 'dddd' */
|
||||||
|
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
static Image_Desc *image;
|
static Image_Desc *image;
|
||||||
@ -23,20 +23,22 @@ int initgr(int largeur, int hauteur)
|
|||||||
{
|
{
|
||||||
int foo, r, v, b, dummy;
|
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");
|
fprintf(stderr, "hu hu, 'man addswap' :)\n");
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\tinitgr %d %d\n", largeur, hauteur);
|
printf("Genplot2: initgr %d %d\n", largeur, hauteur);
|
||||||
for (foo=0; foo<8; foo++)
|
for (foo=0; foo<8; foo++) {
|
||||||
{
|
#if DEBUG_LEVEL
|
||||||
printf("\tPal(%d) = ", foo);
|
printf("\tPal(%d) = ", foo);
|
||||||
|
#endif
|
||||||
r = foo & 1 ? 255 : 0;
|
r = foo & 1 ? 255 : 0;
|
||||||
v = foo & 2 ? 255 : 0;
|
v = foo & 2 ? 255 : 0;
|
||||||
b = foo & 4 ? 255 : 0;
|
b = foo & 4 ? 255 : 0;
|
||||||
|
#if DEBUG_LEVEL
|
||||||
printf("%02X %02X %02X\n", r, v, b);
|
printf("%02X %02X %02X\n", r, v, b);
|
||||||
|
#endif
|
||||||
map.red[foo] = r;
|
map.red[foo] = r;
|
||||||
map.green[foo] = v;
|
map.green[foo] = v;
|
||||||
map.blue[foo] = b;
|
map.blue[foo] = b;
|
||||||
@ -49,7 +51,7 @@ return 0;
|
|||||||
int move(int x, int y)
|
int move(int x, int y)
|
||||||
{
|
{
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
printf("\tMOVE %5d %5d\n", x, y);
|
fprintf(stderr, "\tMOVE %5d %5d\n", x, y);
|
||||||
#endif
|
#endif
|
||||||
curX = x; curY = y;
|
curX = x; curY = y;
|
||||||
return 0;
|
return 0;
|
||||||
@ -61,7 +63,7 @@ RGBA rgba;
|
|||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#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
|
#endif
|
||||||
|
|
||||||
idx = color % 8;
|
idx = color % 8;
|
||||||
@ -80,7 +82,7 @@ return 0;
|
|||||||
int endgr(char *filename)
|
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);
|
Image_TGA_save(filename, image, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -104,17 +106,15 @@ else filename = argv[1];
|
|||||||
if (argc<=2) image = "image.tga";
|
if (argc<=2) image = "image.tga";
|
||||||
else image = argv[2];
|
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 --- */
|
/*----------- 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);
|
fprintf(stderr, "hardcoded picsize : %d %d\n", XMAX, YMAX);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*----------- opening input file and getting MIN and MAX values */
|
/*----------- 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");
|
perror("fichier d'entree");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -122,16 +122,13 @@ if ((fp = fopen(filename, "r"))==NULL)
|
|||||||
nbp = 0;
|
nbp = 0;
|
||||||
xmin = 9999999; xmax = -9999999;
|
xmin = 9999999; xmax = -9999999;
|
||||||
ymin = 9999999; ymax = -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++;
|
nbp++;
|
||||||
|
|
||||||
if (x > xmax) xmax = x;
|
if (x > xmax) xmax = x;
|
||||||
if (x < xmin) xmin = x;
|
if (x < xmin) xmin = x;
|
||||||
|
|
||||||
if (y > ymax) ymax = y;
|
if (y > ymax) ymax = y;
|
||||||
if (y < ymin) ymin = y;
|
if (y < ymin) ymin = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
@ -147,23 +144,26 @@ fprintf(stderr, "Genplot2: found %d points\n", nbp);
|
|||||||
|
|
||||||
fx = (XMAX-XMIN-1)/(xmax-xmin);
|
fx = (XMAX-XMIN-1)/(xmax-xmin);
|
||||||
fy = (YMAX-YMIN-1)/(ymax-ymin);
|
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);
|
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);
|
||||||
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;
|
c1 = XC-f*xC; c2 = YC-f*yC;
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, "c1 = %12f c2 = %12f\n", c1, c2);
|
fprintf(stderr, "c1 = %12f c2 = %12f\n", c1, c2);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*------------- and now, plotting the image ! */
|
/*------------- and now, plotting the image ! */
|
||||||
|
|
||||||
initgr(XMAX, YMAX);
|
initgr(XMAX, YMAX);
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
puts("");
|
puts("");
|
||||||
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 )
|
while ( fscanf(fp, "%lf %lf %d", &x, &y, &v) == 3 ) {
|
||||||
{
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, "%12f %12f %d\n", x, y, v);
|
fprintf(stderr, "%12f %12f %d\n", x, y, v);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user