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

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