Compare commits

..

2 Commits

Author SHA1 Message Date
tTh
35e5947fdb you can now set the image size in genplot2 2022-11-26 11:39:22 +01:00
tTh
5f80203592 wip 2022-11-26 11:13:34 +01:00
10 changed files with 217 additions and 25 deletions

View File

@ -198,6 +198,31 @@
..************..
..************..
................
55
................
..************..
..************..
................
.............**.
.............**.
.............**.
.............**.
.............**.
.............**.
................
................
................
................
.............**.
.............**.
.............**.
.............**.
.............**.
.............**.
................
................
................
................
56
................
..************..
@ -223,6 +248,31 @@
..************..
..************..
................
57
................
..************..
..************..
................
.**..........**.
.**..........**.
.**..........**.
.**..........**.
.**..........**.
.**..........**.
................
..************..
..************..
................
.............**.
.............**.
.............**.
.............**.
.............**.
.............**.
................
..************..
..************..
................
60
................
................

View File

@ -34,3 +34,7 @@ RANLIB=wc -c
# modify it 'as you like'
AR=ar
#
# and valgrind is your friend
#

5
Tests/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
a.scratch
*.tga

15
Tests/essai_genplot2.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
echo "------------------------------------------"
echo "GO" | ./mk_dessin.awk > a.scratch
wc a.scratch
echo "------------------------------------------"
../Tools/genplot2 -s 640x480
errcode=$?
echo "code retour genplot2 = " $errcode
echo "------------------------------------------"
echo "------------------------------------------"

27
Tests/mk_dessin.awk Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/awk -f
# ce joli programme fabrique un fichier de donnees qui sera
# utile au bon deroulement de 'essai_genplot2.sh'
BEGIN { nbretraits = 20000 }
END {
for (trait=0; trait<nbretraits; trait++)
{
if (0.498 > rand())
{
posx += rand()
posy += rand()
print posx, posy, 1
}
else
{
posx -= rand()
posy -= rand()
print posx, posy, 2
}
}
}
# job done

4
Tools/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.tga
*.scratch

View File

@ -13,12 +13,14 @@
/* non portable but useful function */
char *strdup(const char *s);
#define DEBUG_LEVEL 1
#define IN_FONCTION
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
int
cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg)
int cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg)
{
int idx = 0;
@ -48,8 +50,7 @@ fprintf(stderr, "%s : %s not found\n", __func__, mot);
return -1;
}
/*::------------------------------------------------------------------::*/
int
liste_mots_clefs(mot_clef *liste, int flag)
int liste_mots_clefs(mot_clef *liste, int flag)
{
mot_clef *pmc;
@ -79,7 +80,7 @@ return 0;
/*::------------------------------------------------------------------::*/
/*
* INPUT str string to scan for an integer
* pval pointer to the retrun value
* pval pointer to the return value
* k * not used *
*
* OUTPUT 1 successfuly make a conversion
@ -104,6 +105,31 @@ fprintf(stderr, "%s: %s: '%s' -> %ld -> %d\n",
return 1;
}
/*::------------------------------------------------------------------::*/
/* Thu 17 Nov 2022
* input str a string like '640x480'
* pw, ph pointers to result
*
* output 0 on ok, INVALID_PARAM on error
*/
int parse_size_param(char *str, int *pw, int *ph)
{
int tw, th, foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__,
str, pw, ph);
#endif
foo = sscanf(str, "%dx%d", &tw, &th);
if (2 != foo) {
fprintf(stderr, "%s: fail %d on '%s'\n", __func__, foo, str);
return INVALID_PARAM;
}
/* fprintf(stderr, " %d %d\n", tw, th); */
*pw = tw; *ph = th;
return 0;
}
/*::------------------------------------------------------------------::*/
/* input: str string to scan for four csv int
prect rectangle struct who need datas
@ -149,14 +175,15 @@ while (NULL != cptr) {
idx++;
}
free(cptr);
return 0;
}
/*::------------------------------------------------------------------::*/
static Param params[NB_PARAMS];
int
parse_parametres(int argc, char *argv[], char *types, int prem)
int parse_parametres(int argc, char *argv[], char *types, int prem)
{
int foo, idxt;
int entier;
@ -363,11 +390,11 @@ return params[rang].p.i;
}
/*::------------------------------------------------------------------::*/
int
must_be_verbose(void)
static int verboselevel;
int must_be_verbose(void)
{
char *envvar;
envvar = getenv(NOM_VAR_ENV_VERBOSE);
if ((envvar!=NULL) && !strcmp(envvar, "yes"))
{
@ -378,9 +405,24 @@ if ((envvar!=NULL) && !strcmp(envvar, "yes"))
}
return 0;
}
/* new Fri 18 Nov 2022 11:48:06 PM CET */
int set_verbosity(int level)
{
int tmplevel;
tmplevel = verboselevel;
verboselevel = level;
return tmplevel;
}
int get_verbosity(void)
{
return verboselevel;
}
/*::------------------------------------------------------------------::*/
int
dump_command_line(int argc, char *argv[], int force)
int dump_command_line(int argc, char *argv[], int force)
{
char *envvar;
int flag=0, foo;

View File

@ -6,6 +6,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "tga_outils.h"
@ -63,7 +65,7 @@ RGBA rgba;
int idx;
#if DEBUG_LEVEL
fprintf(stderr, "\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;
@ -88,28 +90,60 @@ Image_TGA_save(filename, image, 0);
return 0;
}
/*::------------------------------------------------------------------::*/
void help_me(char *proggy)
{
fprintf(stderr, "%s build %s %s\n", proggy, __DATE__, __TIME__);
puts("options:");
puts("\t-v\t\tdo some blablage");
puts("\t-s WxH\t\tset image size");
}
/*::------------------------------------------------------------------::*/
int main(int argc, char *argv[])
{
char *filename, *image;
FILE *fp;
int outw, outh; /* size of output pic */
double x, y, xmin, ymin, xmax, ymax;
double fx, fy, f, X, Y;
double xC, yC, XC, YC, c1, c2;
int v, nbp, opt, foo;
int v, nbp;
/* setting some default values */
outw = XMAX; outh = YMAX;
filename = "a.scratch"; image = "image.tga";
/*---------- processing command line arguments */
if (argc<=1) filename = "a.scratch";
else filename = argv[1];
while ((opt = getopt(argc, argv, "hs:v")) != -1) {
switch (opt) {
case 'h':
help_me(argv[0]);
exit(0);
case 's': /* size of output pic */
foo = parse_size_param(optarg, &outw, &outh);
break;
case 'v':
break;
default:
fprintf(stderr, "invalid opt %d\n", opt);
exit(1);
break;
}
}
if (argc<=optind) filename = "a.scratch";
else filename = argv[optind];
if (argc<=2) image = "image.tga";
else image = argv[2];
if (argc<=optind+1) image = "image.tga";
else image = argv[optind+1];
fprintf(stderr, "argc %d optind %d file '%s' image '%s'\n",
argc, optind, filename, image);
/*----------- 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, "*** Genplot2 v 1.0.9 (dwtfywl) 1995,2010,2022 TontonTh \n");
fprintf(stderr, " picsize : %d %d\n", outw, outh);
#endif
/*----------- opening input file and getting MIN and MAX values */
@ -137,20 +171,26 @@ if (nbp == 0)
fprintf(stderr, "omg, I'v found _ZERO_ points for plotting...\n");
exit(2);
}
if (nbp == 1)
{
fprintf(stderr, "omg, I can't do any job with only one point.\n");
exit(2);
}
fprintf(stderr, "Genplot2: found %d points\n", nbp);
/*---------- computing coefficients (temporary hack !-) */
fx = (XMAX-XMIN-1)/(xmax-xmin);
fy = (YMAX-YMIN-1)/(ymax-ymin);
fx = (outw-XMIN-1)/(xmax-xmin);
fy = (outh-YMIN-1)/(ymax-ymin);
#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);
XC = 0.5*(XMIN+outw); YC = 0.5*(YMIN+outh);
c1 = XC-f*xC; c2 = YC-f*yC;
@ -159,7 +199,7 @@ fprintf(stderr, "c1 = %12f c2 = %12f\n", c1, c2);
#endif
/*------------- and now, plotting the image ! */
initgr(XMAX, YMAX);
initgr(outw, outh);
fp = fopen(filename, "r");
puts("");

View File

@ -19,6 +19,7 @@
* 27 Dec 2009: v0.42 prise en compte des champs d'altitude.
* 06 Mar 2010: v0.43 introduction du 'df3 tool'.
* 27 Jan 2014: V0.52 added : 'parse_rect_param'.
* 18 Nov 2022: Vx.xx added parse_size_param
*/
#define TGA_OUTILS_COPYLEFT "(dwtfywl) TontonTh 2022"
@ -74,8 +75,12 @@ int cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg);
/* le flag ne sert a rien, mais il faut le mettre a 42 */
int liste_mots_clefs(mot_clef *liste, int flag);
int get_verbosity(void);
int set_verbosity(int level);
int parse_int_param(char *str, int *pval, int k);
int parse_rect_param(char *str, Image_Rect *prect, int k);
int parse_size_param(char *str, int *pw, int *ph);
int parse_parametres(int ac, char *av[], char *types, int prem);
void print_parametres(void);

View File

@ -4,7 +4,7 @@
http:///la.buvette.org/devel/libimage/
*/
#ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 39"
#define IMAGE_VERSION_STRING "0.4.51 pl 41"
/*::------------------------------------------------------------------::*/
/*