FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot/term/gd.trm at master · gnuplot/gnuplot · GitHub
gnuplot
gnuplot
Repository navigation
Code
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot
/
term
/
gd.trm
Copy path
More file actions
More file actions
Latest commit
History
History
History
3233 lines (2922 loc) · 99.1 KB
Breadcrumbs
gnuplot
/
term
/
gd.trm
Copy path
File metadata and controls
3233 lines (2922 loc) · 99.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Hello, Emacs, this is -*-C-*- */
/* GNUPLOT -- gd.trm */
/*[
* Copyright 1998, 2001, 2004
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* This file is included by ../term.c.
*
* This terminal driver supports PNG and JPEG output using
* GD library version 2
*
* To Use:
*
* set terminal png ?options ...?
*
* Where an option is:
*
* transparent - generate transparent PNGs. The first color will
* be the transparent one.
*
* interlace - generate interlaced PNGs.
*
* image size (in pixels)
*
* font size (tiny,small,medium,large,giant)
*
* font name (TrueType or Adobe Type 1 font name is passed to libgd)
*
* EAM Dec 2010: Obsolete!
* xrrggbb - sets the next color. x is the literal character 'x',
* rrggbb are the red green and blue components in hex. For example
* x00ff00 is green. The background color is set first, then the
* color borders, then the X & Y axis, then the plotting colors.
* (The weird color spec is in order to get around limitations
* in gnuplot's scanner.)
*
* This driver is modeled after the PBM driver pbm.trm.
*
* AUTHORS
* Sam Shen <sls@mh1.lbl.gov>
* Alex Woo <woo@playfair.stanford.edu>
* Ethan A Merritt <merritt@u.washington.edu>
*
* CONTRIBUTORS
* Alfred Reibenschuh <alfred.reibenschuh@it-austria.com> or <fredo@blackbox.at>
* Ben Laurie <ben@algroup.co.uk>
*
* This version outputs either indexed or truecolor (24-bit RGB) images
* The default size is 640x480 pixels.
*
******************************************************************************
* PLEASE READ *
* This driver uses the gd library, available from http://www.libgd.org *
* This driver allows you to use TrueType, OpenType, or Adobe Type 1 fonts. *
* If you have libgd version 2.0.36 or later, you may also be able to access *
* any fonts that are managed by the fontconfig utility. *
* You can use this driver without having any TrueType fonts installed, *
* but the default fonts are comparatively limited. *
******************************************************************************
*
* Petr Mikulik, Jan 1999: terminal entries for PM3D functionality
* Ethan Merritt, May 2001: modified gd/gif driver to produce png instead;
* added support for line width and TrueType fonts
* Shige Takeno, Mar 2011: deal with libgd built to use SJIS rather than UTF-8
* Ethan Merritt, Apr 2012: Don't claim to support versions 1.x of libgd
* kmiya@culti, Nov 2016: sixelgd terminal
*
* Ethan Merritt, Jun 2019:
* Revisit use of brush for thick lines with alpha channel
* + setting alpha in the brush itself works OK up to about lw 4.
* After that the repeated composition of the brush wipes out the transparency.
*
* Ethan Merritt Jan 2023:
* Newer antialiasing support in gdlib makes it actually work with the native
* implementation for linewidth > 1. But it requires truecolor.
* Conversely, using the brush alternative (via "rounded") has become very slow.
* CHANGE:
* Default to "set term png butt truecolor"
* gif and sixel default to "butt notruecolor"
*/
#define
GD_DEFINED_COLORS
96
/* Must not exceed size of pm3d_color_names_tbl[] */
#include
"driver.h"
#ifdef
TERM_REGISTER
register_term
(
png
)
#endif
#ifdef
TERM_PROTO
TERM_PUBLIC
void
PNG_options
(
void
);
TERM_PUBLIC
void
PNG_init
(
void
);
TERM_PUBLIC
void
PNG_graphics
(
void
);
TERM_PUBLIC
void
PNG_text
(
void
);
TERM_PUBLIC
void
PNG_linetype
(
int
linetype
);
TERM_PUBLIC
void
PNG_linewidth
(
double
linewidth
);
TERM_PUBLIC
void
PNG_move
(
unsigned
int
x
,
unsigned
int
y
);
TERM_PUBLIC
void
PNG_vector
(
unsigned
int
x
,
unsigned
int
y
);
TERM_PUBLIC
void
PNG_put_text
(
unsigned
int
x
,
unsigned
int
y
,
const
char
str
[]);
TERM_PUBLIC
int
PNG_justify_text
(
enum
JUSTIFY
mode
);
TERM_PUBLIC
void
PNG_point
(
unsigned
int
x
,
unsigned
int
y
,
int
number
);
TERM_PUBLIC
int
PNG_text_angle
(
float
ang
);
TERM_PUBLIC
void
PNG_reset
(
void
);
TERM_PUBLIC
int
PNG_set_font
(
const
char
*
fontname
);
TERM_PUBLIC
void
PNG_pointsize
(
double
ptsize
);
TERM_PUBLIC
void
PNG_boxfill
(
int
,
unsigned
int
,
unsigned
int
,
unsigned
int
,
unsigned
int
);
TERM_PUBLIC
int
PNG_make_palette
(
t_sm_palette
*
);
/* TERM_PUBLIC void PNG_previous_palette (void); */
TERM_PUBLIC
void
PNG_set_color
(
t_colorspec
*
);
TERM_PUBLIC
void
PNG_filled_polygon
(
int
,
gpiPoint
*
);
TERM_PUBLIC
void
PNG_image
(
unsigned
int
,
unsigned
int
,
coordval
*
,
gpiPoint
*
,
t_imagecolor
);
/* To support "set term png enhanced" */
TERM_PUBLIC
void
ENHGD_put_text
(
unsigned
int
x
,
unsigned
int
y
,
const
char
str
[]);
TERM_PUBLIC
void
ENHGD_OPEN
(
char
*
fontname
,
double
fontsize
,
double
base
,
TBOOLEAN
widthflag
,
TBOOLEAN
showflag
,
int
overprint
);
TERM_PUBLIC
void
ENHGD_FLUSH
(
void
);
TERM_PUBLIC
void
ENHGD_boxed_text
(
unsigned
int
,
unsigned
int
,
int
);
#include
<gd.h>
/* Include files for bitmap fonts */
#include
<gdfontt.h>
#include
<gdfonts.h>
#include
<gdfontl.h>
#include
<gdfontmb.h>
#include
<gdfontg.h>
/* some version test macros */
#define
GD_NUM_VERSION
(
major
,
minor
,
release
) \
(((major) * 10000) + ((minor) * 100) + (release))
#define
GD_THIS_VERSION
\
GD_NUM_VERSION(GD_MAJOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION)
#define
GD_MIN_VERSION
(
major
,
minor
,
release
) \
(GD_THIS_VERSION >= GD_NUM_VERSION(major, minor,release))
/* Before version 2.0.36, the libgd function gdFTUseFontConfig() didn't */
/* do what we need. Test for earlier versions and ignore it. */
#if
GD_MIN_VERSION
(
2
,
0
,
36
)
# define
gdUseFontConfig
(
x
) gdFTUseFontConfig(x)
#endif
#ifndef
gdUseFontConfig
# define
gdUseFontConfig
(
x
) 0
#endif
/* These intermediate functions are necessary on Windows since
the shared version of libgd uses a different calling convention
and there is no proper macro defined.
*/
#if
defined(
_WIN32
)
&&
!defined(
NONDLL
)
static
void
gp_gdImagePolygon
(
gdImagePtr
,
gdPointPtr
,
int
,
int
);
static
void
gp_gdImageFilledPolygon
(
gdImagePtr
,
gdPointPtr
,
int
,
int
);
#else
# define
gp_gdImagePolygon
gdImagePolygon
# define
gp_gdImageFilledPolygon
gdImageFilledPolygon
#endif
static
void
PNG_PointX
(
unsigned
int
,
unsigned
int
);
static
void
PNG_PointPlus
(
unsigned
int
,
unsigned
int
);
static
void
PNG_Triangle
(
unsigned
int
x
,
unsigned
int
y
,
int
direction
,
void
(
*
draw_func
)(
gdImagePtr
,
gdPointPtr
,
int
,
int
));
static
void
PNG_Diamond
(
unsigned
int
x
,
unsigned
int
y
,
void
(
*
draw_func
)(
gdImagePtr
,
gdPointPtr
,
int
,
int
));
static
void
PNG_init_brush
(
int
);
#define
GREG_XMAX
640
#define
GREG_YMAX
480
/* This will be the default font */
#define
gdfont
gdFontMediumBold
#define
PNG_VCHAR
13
#define
PNG_HCHAR
7
#define
PNG_TICSIZE
(GREG_YMAX/100)
#define
PNG_MAX_COLORS
256
#define
GOT_NEXT_PROTO
#endif
#ifndef
TERM_PROTO_ONLY
#ifdef
TERM_BODY
static
const
char
*
PNG_initialized
=
NULL
;
/* Which terminal was previously used? */
static
struct
{
gdImagePtr
image
;
gdFontPtr
font
;
unsigned
int
x
,
y
;
int
height
;
int
charh
,
charw
;
int
color
;
/* Magic index returned by libgd */
int
rgb
;
/* Our guess at the corresponding rgb */
int
n_colors
;
int
color_table
[
PNG_MAX_COLORS
];
int
rgb_table
[
PNG_MAX_COLORS
];
float
angle
;
enum
JUSTIFY
justify
;
int
flags
;
int
linetype
;
int
linewidth
;
TBOOLEAN
capbutt
;
/* use capbutt on lines with GD2, 20051205 MWS*/
TBOOLEAN
use_builtin
;
double
ttfsize
;
char
*
ttffont
;
gdFontPtr
default_font
;
char
*
default_ttffont
;
double
default_ttfsize
;
double
fontscale
;
TBOOLEAN
TrueColor
;
double
dashfraction
;
/* Where in a dot-dash pattern we left off */
/* Variables for animated gif support: */
TBOOLEAN
animate
;
/* Only gif supports animation */
TBOOLEAN
anchor
;
/* sixel and kitty treat it as synonym for "anchor" */
int
loop_count
;
/* Number of times to repeat sequence */
int
frame_count
;
/* Number of frames in animation */
int
frame_delay
;
/* Time between frames in .01 seconds */
TBOOLEAN
frame_optimization
;
gdImagePtr
previous_image
;
/* Needed to encode animation as a series of deltas */
}
png_state
=
{.
anchor
=
TRUE};
#define
PNG_USE_TRANSPARENT
1
#define
PNG_USE_INTERLACE
2
#define
PNG_USE_CROP
4
enum
PNG_id
{
PNG_TRANSPARENT
,
PNG_NOTRANSPARENT
,
PNG_INTERLACE
,
PNG_NOINTERLACE
,
PNG_CROP
,
PNG_NOCROP
,
/* Font size */
PNG_TINY
,
PNG_SMALL
,
PNG_MEDIUM
,
PNG_LARGE
,
PNG_GIANT
,
PNG_FONT
,
PNG_FONTSCALE
,
PNG_SIZE
,
PNG_BACKGROUND
,
PNG_ENHANCED
,
PNG_NOENHANCED
,
PNG_TRUECOLOR
,
PNG_NOTRUECOLOR
,
PNG_LINEWIDTH
,
PNG_BUTT
,
PNG_ROUNDED
,
PNG_DASHLENGTH
,
GIF_ANIMATE
,
GIF_DELAY
,
GIF_LOOP
,
GIF_NOOPT
,
GIF_OPT
,
PNG_ANCHOR
,
PNG_SCROLL
,
PNG_OTHER
};
#ifdef
Y
# undef
Y
#endif
#define
Y
(
y
) (png_state.height - (y))
static
int
PNG_XMAX
=
GREG_XMAX
;
static
int
PNG_YMAX
=
GREG_YMAX
;
static
const
int
PNG_POINT_SCALE
=
3
;
static
int
PNG_ps
=
3
;
unsigned
int
bounding_box
[
4
];
#define
GD_TEXTBOX_MARGIN
1.0
double
bounding_xmargin
=
GD_TEXTBOX_MARGIN
;
double
bounding_ymargin
=
GD_TEXTBOX_MARGIN
;
static
TBOOLEAN
ENHgd_show
=
TRUE;
static
TBOOLEAN
ENHgd_sizeonly
=
FALSE;
static
struct
gen_table
PNG_opts
[]
=
{
{
"trans$parent"
,
PNG_TRANSPARENT
},
{
"notran$sparent"
,
PNG_NOTRANSPARENT
},
{
"inter$lace"
,
PNG_INTERLACE
},
{
"nointer$lace"
,
PNG_NOINTERLACE
},
{
"crop"
,
PNG_CROP
},
{
"nocrop"
,
PNG_NOCROP
},
{
"ti$ny"
,
PNG_TINY
},
{
"s$mall"
,
PNG_SMALL
},
{
"m$edium"
,
PNG_MEDIUM
},
{
"l$arge"
,
PNG_LARGE
},
{
"g$iant"
,
PNG_GIANT
},
{
"fontscale"
,
PNG_FONTSCALE
},
{
"fo$nt"
,
PNG_FONT
},
{
"si$ze"
,
PNG_SIZE
},
{
"enh$anced"
,
PNG_ENHANCED
},
{
"noenh$anced"
,
PNG_NOENHANCED
},
{
"true$color"
,
PNG_TRUECOLOR
},
{
"notrue$color"
,
PNG_NOTRUECOLOR
},
{
"linew$idth"
,
PNG_LINEWIDTH
},
{
"anim$ate"
,
GIF_ANIMATE
},
/* gif animation options */
{
"anchor"
,
PNG_ANCHOR
},
/* sixel/kitty image drawn at top left */
{
"scroll"
,
PNG_SCROLL
},
/* sixel/kitty image scrolls with text */
{
"delay"
,
GIF_DELAY
},
{
"loop"
,
GIF_LOOP
},
{
"noopt$imize"
,
GIF_NOOPT
},
{
"opt$imize"
,
GIF_OPT
},
/* end of gif animation options */
{
"lw"
,
PNG_LINEWIDTH
},
{
"butt"
,
PNG_BUTT
},
{
"round$ed"
,
PNG_ROUNDED
},
{
"dashl$ength"
,
PNG_DASHLENGTH
},
{
"dl"
,
PNG_DASHLENGTH
},
{
"backg$round"
,
PNG_BACKGROUND
},
{
NULL
,
PNG_OTHER
}
};
#undef
MAXLINEWIDTH
#define
MAXLINEWIDTH
100
static
double
PNG_linewidth_factor
=
1.0
;
static
double
PNG_dashlength_factor
=
1.0
;
/* shige takeno:
* libgd can be built to prefer UTF-8 or SJIS encoding for Japanese.
* If it wants SJIS and we are currently in UTF8, convert.
* If it wants UTF8 and we are currently in SJIS, convert.
* conditional compilation flags:
* HAVE_ICONV (iconv library)
* JIS_GDLIB (using gdlib configured with -DJISX0208)
*/
#ifdef
HAVE_ICONV
#include
<iconv.h>
#endif
static
void
gd_iconv
(
char
*
*
string
);
/* EAM - gdImage structure to hold brushes for linewidth */
/* We will allocate and initialize these on demand */
typedef
struct
{
gdImagePtr
im
;
unsigned
int
last_rgb
;
int
bgnd
;
int
fgnd
;
}
PNG_BRUSH
;
static
PNG_BRUSH
*
PNG_brush
[
MAXLINEWIDTH
+
1
];
typedef
struct
{
gdImagePtr
im
;
unsigned
int
last_rgb
;
int
fillpar
;
}
PNG_FILL_TILE
;
static
PNG_FILL_TILE
PNG_fill_tile
=
{ (
gdImagePtr
)
0
,
0
,
0
};
/* To be used with libgd 2.0.34 to request Symbol encoding */
#ifdef
gdFTEX_Adobe_Custom
static
gdFTStringExtra
PNG_FONT_INFO
=
{
0
,
0
,
0
,
0
,
0
,
NULL
,
NULL
};
#endif
#if
defined(
_WIN32
)
&&
!defined(
NONDLL
)
static
void
gp_gdImagePolygon
(
gdImagePtr
im
,
gdPointPtr
p
,
int
n
,
int
c
)
{
gdImagePolygon
(
im
,
p
,
n
,
c
);
}
static
void
gp_gdImageFilledPolygon
(
gdImagePtr
im
,
gdPointPtr
p
,
int
n
,
int
c
)
{
gdImageFilledPolygon
(
im
,
p
,
n
,
c
);
}
#endif
/* Common code to crop the image around its bounding box, just before writing
down the file.
*/
static
void
image_do_crop
(
void
)
{
if
(
png_state
.
flags
&
PNG_USE_CROP
) {
int
x
,
y
,
x1
,
y1
,
x2
,
y2
,
flag
;
int
bg
=
png_state
.
color_table
[
0
];
/* index of the background color */
gdImagePtr
im_crop
;
for
(
flag
=
0
,
x1
=
0
;
x1
<
gdImageSX
(
png_state
.
image
)
-
1
;
x1
++
) {
for
(
y
=
0
;
y
<
gdImageSY
(
png_state
.
image
);
y
++
)
if
(
gdImageGetPixel
(
png_state
.
image
,
x1
,
y
)
!=
bg
) {
flag
=
1
;
break
; }
if
(
flag
)
break
;
}
for
(
flag
=
0
,
x2
=
gdImageSX
(
png_state
.
image
)
-
1
;
x2
>=
x1
;
x2
--
) {
for
(
y
=
0
;
y
<
gdImageSY
(
png_state
.
image
);
y
++
)
if
(
gdImageGetPixel
(
png_state
.
image
,
x2
,
y
)
!=
bg
) {
flag
=
1
;
break
; }
if
(
flag
)
break
;
}
for
(
flag
=
0
,
y1
=
0
;
y1
<
gdImageSY
(
png_state
.
image
)
-
1
;
y1
++
) {
for
(
x
=
x1
;
x
<=
x2
;
x
++
)
if
(
gdImageGetPixel
(
png_state
.
image
,
x
,
y1
)
!=
bg
) {
flag
=
1
;
break
; };
if
(
flag
)
break
;
}
for
(
flag
=
0
,
y2
=
gdImageSY
(
png_state
.
image
)
-
1
;
y2
>=
y1
;
y2
--
) {
for
(
x
=
x1
;
x
<=
x2
;
x
++
)
if
(
gdImageGetPixel
(
png_state
.
image
,
x
,
y2
)
!=
bg
) {
flag
=
1
;
break
; };
if
(
flag
)
break
;
}
x
=
x2
-
x1
+
1
;
/* width */
y
=
y2
-
y1
+
1
;
/* height */
if
(
png_state
.
TrueColor
)
im_crop
=
gdImageCreateTrueColor
(
x
,
y
);
else
im_crop
=
gdImageCreate
(
x
,
y
);
if
(!
im_crop
) {
int_warn
(
NO_CARET
,
"libgd: failed to create cropped image structure"
);
return
;
}
bg
=
gdImageColorAllocateAlpha
(
im_crop
,
255
,
255
,
255
,
127
);
/* FIXME: getting black background for truecolor & transparent */
gdImagePaletteCopy
(
im_crop
,
png_state
.
image
);
if
(
png_state
.
flags
&
PNG_USE_TRANSPARENT
) {
gdImageColorTransparent
(
im_crop
,
bg
);
/* WARNING: This is a work-around for strangeness in libgd, */
/* which doesn't copy transparent pixels in TrueColor images. */
if
(
png_state
.
TrueColor
)
gdImageColorTransparent
(
png_state
.
image
,
-1
);
}
else
gdImageColorTransparent
(
im_crop
,
-1
);
gdImageCopy
(
im_crop
,
png_state
.
image
,
0
,
0
,
x1
,
y1
,
x
,
y
);
gdImageDestroy
(
png_state
.
image
);
png_state
.
image
=
im_crop
;
/* Re-set transparency for sixelgd */
if
(
strcmp
(
"sixelgd"
,
term
->
name
)
==
0
&&
png_state
.
TrueColor
&&
(
png_state
.
flags
&
PNG_USE_TRANSPARENT
)) {
gdImageColorTransparent
(
png_state
.
image
,
png_state
.
color_table
[
0
]);
}
}
}
static
int
PNG_FillSolid
(
int
fillpar
);
static
int
PNG_FillPattern
(
int
fillpar
);
static
int
PNG_FillTransparent
(
int
fillpar
);
static
int
PNG_FillSolid
(
int
fillpar
)
{
int
red
=
(
png_state
.
rgb
>>
16
)
&
0xff
;
int
green
=
(
png_state
.
rgb
>>
8
)
&
0xff
;
int
blue
=
png_state
.
rgb
&
0xff
;
double
fact
=
(
double
)(
100
-
fillpar
)
*
0.01
;
int
color
;
if
(
fact
<=
0
||
fact
>=
1.0
)
return
png_state
.
color
;
red
+=
(
0xff
-
red
)
*
fact
;
green
+=
(
0xff
-
green
)
*
fact
;
blue
+=
(
0xff
-
blue
)
*
fact
;
color
=
gdImageColorExact
(
png_state
.
image
,
red
,
green
,
blue
);
if
(
color
<
0
) {
color
=
gdImageColorAllocate
(
png_state
.
image
,
red
,
green
,
blue
);
}
if
(
color
<
0
) {
color
=
gdImageColorClosest
(
png_state
.
image
,
red
,
green
,
blue
);
}
return
color
;
}
static
int
PNG_FillTransparent
(
int
fillpar
)
{
int
red
=
(
png_state
.
rgb
>>
16
)
&
0xff
;
int
green
=
(
png_state
.
rgb
>>
8
)
&
0xff
;
int
blue
=
png_state
.
rgb
&
0xff
;
int
alpha
=
127
*
(
double
)(
100
-
fillpar
) /
100.
;
return
gdImageColorExactAlpha
(
png_state
.
image
,
red
,
green
,
blue
,
alpha
);
}
static
int
PNG_FillPattern
(
int
style
)
{
int
rgb
=
png_state
.
rgb
;
int
brgb
=
png_state
.
rgb_table
[
0
];
int
fillpar
=
(
style
>>
4
) %
8
;
style
=
style
&
0xf
;
if
(!
PNG_fill_tile
.
im
||
rgb
!=
PNG_fill_tile
.
last_rgb
||
PNG_fill_tile
.
fillpar
!=
fillpar
) {
int
foreground
,
background
;
if
(
PNG_fill_tile
.
im
) {
gdImageDestroy
(
PNG_fill_tile
.
im
);
PNG_fill_tile
.
im
=
(
gdImagePtr
)
0
;
}
/* save new values */
PNG_fill_tile
.
fillpar
=
fillpar
;
PNG_fill_tile
.
last_rgb
=
rgb
;
/* create new tile */
if
(!((
PNG_fill_tile
.
im
=
gdImageCreate
(
8
,
8
))))
int_error
(
NO_CARET
,
"libgd: failed to create pattern-fill tile"
);
background
=
gdImageColorAllocate
(
PNG_fill_tile
.
im
,
(
brgb
>>
16
)
&
0xff
, (
brgb
>>
8
)
&
0xff
,
brgb
&
0xff
);
if
(
style
==
FS_TRANSPARENT_PATTERN
)
gdImageColorTransparent
(
PNG_fill_tile
.
im
,
background
);
gdImageFilledRectangle
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
7
,
background
);
/* foreground */
foreground
=
gdImageColorAllocate
(
PNG_fill_tile
.
im
,
(
rgb
>>
16
)
&
0xff
, (
rgb
>>
8
)
&
0xff
,
rgb
&
0xff
);
switch
(
fillpar
) {
case
0
:
/* no fill */
default
:
break
;
case
1
:
/* cross-hatch */
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
7
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
6
,
6
,
0
,
foreground
);
break
;
case
2
:
/* double cross-hatch */
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
7
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
6
,
6
,
0
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
2
,
2
,
0
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
7
,
3
,
3
,
7
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
4
,
0
,
7
,
3
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
4
,
3
,
7
,
foreground
);
break
;
case
3
:
/* solid */
gdImageFilledRectangle
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
7
,
foreground
);
break
;
case
4
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
7
,
foreground
);
break
;
case
5
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
7
,
7
,
0
,
foreground
);
break
;
case
6
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
0
,
3
,
7
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
4
,
0
,
7
,
7
,
foreground
);
break
;
case
7
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
7
,
3
,
0
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
4
,
7
,
7
,
0
,
foreground
);
break
;
case
8
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
0
,
7
,
3
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
4
,
7
,
7
,
foreground
);
break
;
case
9
:
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
3
,
7
,
0
,
foreground
);
gdImageLine
(
PNG_fill_tile
.
im
,
0
,
7
,
7
,
4
,
foreground
);
break
;
}
}
gdImageSetTile
(
png_state
.
image
,
PNG_fill_tile
.
im
);
return
(
int
)
gdTiled
;
}
static
void
PNG_PointX
(
unsigned
int
x
,
unsigned
int
y
)
{
gdImageLine
(
png_state
.
image
,
x
-
PNG_ps
,
y
-
PNG_ps
,
x
+
PNG_ps
,
y
+
PNG_ps
,
png_state
.
color
);
gdImageLine
(
png_state
.
image
,
x
+
PNG_ps
,
y
-
PNG_ps
,
x
-
PNG_ps
,
y
+
PNG_ps
,
png_state
.
color
);
}
static
void
PNG_PointPlus
(
unsigned
int
x
,
unsigned
int
y
)
{
gdImageLine
(
png_state
.
image
,
x
-
PNG_ps
,
y
,
x
+
PNG_ps
,
y
,
png_state
.
color
);
gdImageLine
(
png_state
.
image
,
x
,
y
-
PNG_ps
,
x
,
y
+
PNG_ps
,
png_state
.
color
);
}
static
void
PNG_Triangle
(
unsigned
int
x
,
unsigned
int
y
,
int
direction
,
void
(
*
draw_func
)(
gdImagePtr
,
gdPointPtr
,
int
,
int
))
{
int
delta
=
(
int
)((
1.33
*
(
double
)
PNG_ps
)
+
0.5
);
int
delta_
=
(
int
)((
0.67
*
(
double
)
PNG_ps
)
+
0.5
);
gdPoint
points
[
4
];
points
[
0
].
x
=
x
;
points
[
0
].
y
=
y
-
direction
*
delta
;
points
[
1
].
x
=
x
-
delta
;
points
[
1
].
y
=
y
+
direction
*
delta_
;
points
[
2
].
x
=
x
+
delta
;
points
[
2
].
y
=
y
+
direction
*
delta_
;
points
[
3
].
x
=
points
[
0
].
x
;
points
[
3
].
y
=
points
[
0
].
y
;
draw_func
(
png_state
.
image
,
points
,
4
,
png_state
.
color
);
}
static
void
PNG_Diamond
(
unsigned
int
x
,
unsigned
int
y
,
void
(
*
draw_func
)(
gdImagePtr
,
gdPointPtr
,
int
,
int
))
{
gdPoint
points
[
5
];
points
[
0
].
x
=
x
;
points
[
0
].
y
=
y
-
PNG_ps
;
points
[
1
].
x
=
x
+
PNG_ps
;
points
[
1
].
y
=
y
;
points
[
2
].
x
=
x
;
points
[
2
].
y
=
y
+
PNG_ps
;
points
[
3
].
x
=
x
-
PNG_ps
;
points
[
3
].
y
=
y
;
points
[
4
].
x
=
points
[
0
].
x
;
points
[
4
].
y
=
points
[
0
].
y
;
draw_func
(
png_state
.
image
,
points
,
5
,
png_state
.
color
);
}
/*
* _options() Called when terminal type is selected.
* This procedure should parse options on the command line. A list of the
* currently selected options should be stored in term_options[] in a form
* suitable for use with the set term command. term_options[] is used by
* the save command. Use options_null() if no options are available.
*/
TERM_PUBLIC
void
PNG_options
()
{
double
tmp
;
char
*
string
;
unsigned long
color
;
TBOOLEAN
gif_anim_option
=
FALSE;
/* set to TRUE if an animated gif option given */
if
(
PNG_initialized
!=
term
->
name
) {
PNG_initialized
=
term
->
name
;
term_options
[
0
]
=
'\0'
;
term
->
h_char
=
PNG_HCHAR
;
/* Default to medium font */
png_state
.
default_font
=
gdfont
;
png_state
.
n_colors
=
0
;
png_state
.
flags
=
0
;
png_state
.
use_builtin
=
FALSE;
png_state
.
ttffont
=
NULL
;
png_state
.
default_ttffont
=
NULL
;
png_state
.
default_ttfsize
=
0
;
png_state
.
fontscale
=
1
;
png_state
.
justify
=
CENTRE
;
PNG_linewidth_factor
=
1.0
;
PNG_dashlength_factor
=
1.0
;
png_state
.
capbutt
=
TRUE;
/* Change Jan 2023 */
if
(!
strcmp
(
term
->
name
,
"gif"
)
||
!
strcmp
(
term
->
name
,
"sixelgd"
))
png_state
.
TrueColor
=
FALSE;
else
png_state
.
TrueColor
=
TRUE;
#ifdef
_WIN32
/* Set the default search path for fonts to something useful. */
if
(
getenv
(
"GDFONTPATH"
)
==
NULL
) {
const
char
fonts
[]
=
"\\fonts"
;
char
*
windir
=
getenv
(
"windir"
);
if
(
windir
) {
char
*
gdfontpath
=
(
char
*
)
gp_alloc
(
strlen
(
windir
)
+
strlen
(
fonts
)
+
1
,
"GDFONTPATH"
);
if
(
gdfontpath
) {
strcpy
(
gdfontpath
,
windir
);
strcat
(
gdfontpath
,
fonts
);
SetEnvironmentVariableA
(
"GDFONTPATH"
,
gdfontpath
);
free
(
gdfontpath
);
}
}
}
#endif
}
else
{
if
(!
png_state
.
default_font
) {
int_warn
(
NO_CARET
,
"gd.trm: caught initialization error"
);
png_state
.
default_font
=
gdfont
;
}
}
/* Annoying hack to handle the case of 'set termoption' after */
/* we are already in animation mode. */
if
(
almost_equals
(
c_token
-
1
,
"termopt$ion"
))
FPRINTF
((
stderr
,
"gif: Maintaining animation state\n"
));
else
{
/* Otherwise reset animation parameters */
if
(
png_state
.
previous_image
)
gdImageDestroy
(
png_state
.
previous_image
);
png_state
.
animate
=
FALSE;
png_state
.
previous_image
=
NULL
;
png_state
.
frame_optimization
=
FALSE;
png_state
.
loop_count
=
0
;
/* And default font size */
term
->
h_char
=
PNG_HCHAR
;
png_state
.
default_ttfsize
=
0
;
PNG_linewidth_factor
=
1.0
;
PNG_dashlength_factor
=
1.0
;
/* Default to enhanced text */
term
->
flags
|=
TERM_ENHANCED_TEXT
;
term
->
put_text
=
ENHGD_put_text
;
}
while
(!
END_OF_COMMAND
) {
switch
(
lookup_table
(
&
PNG_opts
[
0
],
c_token
)) {
case
PNG_TRANSPARENT
:
png_state
.
flags
|=
PNG_USE_TRANSPARENT
;
++
c_token
;
break
;
case
PNG_NOTRANSPARENT
:
png_state
.
flags
&= ~
PNG_USE_TRANSPARENT
;
++
c_token
;
break
;
case
PNG_INTERLACE
:
png_state
.
flags
|=
PNG_USE_INTERLACE
;
++
c_token
;
break
;
case
PNG_NOINTERLACE
:
png_state
.
flags
&= ~
PNG_USE_INTERLACE
;
++
c_token
;
break
;
case
PNG_CROP
:
png_state
.
flags
|=
PNG_USE_CROP
;
++
c_token
;
break
;
case
PNG_NOCROP
:
png_state
.
flags
&= ~
PNG_USE_CROP
;
++
c_token
;
break
;
#ifdef
HAVE_GD_TTF
# define
UNSET_TTF_FONT
\
free(png_state.ttffont); \
png_state.ttffont = NULL; \
png_state.default_ttfsize = 2 * term->h_char - 2; \
png_state.use_builtin = TRUE;
#else
# define
UNSET_TTF_FONT
\
;
/* nothing to do */
#endif
case
PNG_TINY
:
png_state
.
default_font
=
gdFontGetTiny
();
term
->
v_char
=
png_state
.
default_font
->
h
;
term
->
h_char
=
png_state
.
default_font
->
w
;
++
c_token
;
UNSET_TTF_FONT
;
break
;
case
PNG_SMALL
:
png_state
.
default_font
=
gdFontGetSmall
();
term
->
v_char
=
png_state
.
default_font
->
h
;
term
->
h_char
=
png_state
.
default_font
->
w
;
++
c_token
;
UNSET_TTF_FONT
;
break
;
case
PNG_MEDIUM
:
png_state
.
default_font
=
gdFontGetMediumBold
();
term
->
v_char
=
png_state
.
default_font
->
h
;
term
->
h_char
=
png_state
.
default_font
->
w
;
++
c_token
;
UNSET_TTF_FONT
;
break
;
case
PNG_LARGE
:
png_state
.
default_font
=
gdFontGetLarge
();
term
->
v_char
=
png_state
.
default_font
->
h
;
term
->
h_char
=
png_state
.
default_font
->
w
;
++
c_token
;
UNSET_TTF_FONT
;
break
;
case
PNG_GIANT
:
png_state
.
default_font
=
gdFontGetGiant
();
term
->
v_char
=
png_state
.
default_font
->
h
;
term
->
h_char
=
png_state
.
default_font
->
w
;
++
c_token
;
UNSET_TTF_FONT
;
break
;
case
PNG_FONT
:
c_token
++
;
#ifdef
HAVE_GD_TTF
if
(
END_OF_COMMAND
) {
free
(
png_state
.
ttffont
);
png_state
.
ttffont
=
NULL
;
png_state
.
default_ttfsize
=
0
;
}
else
{
int
brect
[
8
];
char
*
err
;
char
*
s
;
if
(
isstringvalue
(
c_token
)
&&
(
s
=
try_to_get_string
())) {
char
*
comma
=
strrchr
(
s
,
','
);
double
fontsize
;
if
(
comma
&&
(
1
==
sscanf
(
comma
+
1
,
"%lf"
,
&
fontsize
))) {
png_state
.
default_ttfsize
=
fontsize
;
png_state
.
ttfsize
=
png_state
.
default_ttfsize
;
*
comma
=
'\0'
;
}
if
(
*
s
) {
free
(
png_state
.
ttffont
);
png_state
.
ttffont
=
s
;
}
else
{
continue
;
}
}
else
{
free
(
png_state
.
ttffont
);
png_state
.
ttffont
=
gp_alloc
(
token_len
(
c_token
)
+
1
,
"new font"
);
copy_str
(
png_state
.
ttffont
,
c_token
,
token_len
(
c_token
)
+
1
);
c_token
++
;
}
free
(
png_state
.
default_ttffont
);
png_state
.
default_ttffont
=
gp_strdup
(
png_state
.
ttffont
);
/* First try the old GDFONTPATH mechanism for locating fonts */
(
void
)
gdUseFontConfig
(
0
);
err
=
gdImageStringFT
(
NULL
,
&
brect
[
0
],
0
,
png_state
.
ttffont
,
png_state
.
default_ttfsize
*
png_state
.
fontscale
,
0.0
,
0
,
0
,
"test"
);
/* If that didn't work, try again using the fontconfig mechanism */
if
(
err
&&
gdUseFontConfig
(
1
)) {
err
=
gdImageStringFT
(
NULL
,
&
brect
[
0
],
0
,
png_state
.
ttffont
,
png_state
.
default_ttfsize
*
png_state
.
fontscale
,
0.0
,
0
,
0
,
"test"
);
}
/* If we still haven't found the font, punt to the internal non-TTF default set */
if
(
err
) {
fprintf
(
stderr
,
"%s when opening font %s, trying default\n"
,
err
,
png_state
.
ttffont
);
free
(
png_state
.
ttffont
);
free
(
png_state
.
default_ttffont
);
png_state
.
ttffont
=
NULL
;
png_state
.
default_ttffont
=
NULL
;
}
}
#else
c_token
++
;
fprintf
(
stderr
,
"No TTF font support, using internal non-scalable font\n"
);
#endif
break
;
# undef
UNSET_TTF_FONT
case
PNG_FONTSCALE
:
c_token
++
;
png_state
.
fontscale
=
END_OF_COMMAND
?
1
:
real_expression
();
if
(
png_state
.
fontscale
<=
0
)
png_state
.
fontscale
=
1.
;
break
;
case
PNG_SIZE
:
c_token
++
;
if
(
END_OF_COMMAND
) {
PNG_XMAX
=
GREG_XMAX
;
PNG_YMAX
=
GREG_YMAX
;
}
else
{
PNG_XMAX
=
real_expression
();
if
(
equals
(
c_token
,
","
)) {
c_token
++
;
PNG_YMAX
=
real_expression
();
}
if
(
PNG_XMAX
<=
0
)
PNG_XMAX
=
GREG_XMAX
;
if
(
PNG_YMAX
<=
0
)
PNG_YMAX
=
GREG_YMAX
;
}
term
->
ymax
=
PNG_YMAX
;
term
->
xmax
=
PNG_XMAX
;
/* EAM Apr 2003 - same tic size on both x and y axes */
term
->
v_tic
=
(
PNG_XMAX
<
PNG_YMAX
) ?
PNG_XMAX
/
100
:
PNG_YMAX
/
100
;
if
(
term
->
v_tic
<
1
)
term
->
v_tic
=
1
;
term
->
h_tic
=
term
->
v_tic
;
break
;
case
PNG_ENHANCED
:
term
->
flags
|=
TERM_ENHANCED_TEXT
;
term
->
put_text
=
ENHGD_put_text
;
++
c_token
;
break
;
case
PNG_NOENHANCED
:
term
->
flags
&= ~
TERM_ENHANCED_TEXT
;
term
->
put_text
=
PNG_put_text
;
++
c_token
;
break
;
case
PNG_TRUECOLOR
:
png_state
.
TrueColor
=
TRUE;
term
->
flags
|=
TERM_ALPHA_CHANNEL
;
c_token
++
;
break
;
case
PNG_NOTRUECOLOR
:
png_state
.
TrueColor
=
FALSE;
term
->
flags
&= ~
TERM_ALPHA_CHANNEL
;
c_token
++
;
break
;
case
PNG_LINEWIDTH
:
c_token
++
;
PNG_linewidth_factor
=
real_expression
();
if
(
PNG_linewidth_factor
<
0
)
PNG_linewidth_factor
=
1.0
;
break
;
case
PNG_DASHLENGTH
:
c_token
++
;
PNG_dashlength_factor
=
real_expression
();
if
(
PNG_dashlength_factor
<=
0.2
)
PNG_dashlength_factor
=
1.0
;
break
;
/* anchor/scroll choice for sixel and kitty in-terminal output */
case
PNG_ANCHOR
:
c_token
++
;
png_state
.
anchor
=
TRUE;
break
;
case
PNG_SCROLL
:
c_token
++
;
png_state
.
anchor
=
FALSE;
break
;
/* parse gif animation options */
case
GIF_ANIMATE
:
c_token
++
;
if
(
strncmp
(
"gif"
,
term
->
name
,
3
)
==
0
) {
gif_anim_option
=
1
;
}
else
if
(
strncmp
(
"sixel"
,
term
->
name
,
5
)
==
0
) {
png_state
.
anchor
=
TRUE;
break
;
}
else
if
(
strncmp
(
"kitty"
,
term
->
name
,
5
)
==
0
) {
png_state
.
anchor
=
TRUE;
break
;
}
else
{
int_error
(
c_token
,
"This terminal does not support animation"
);
}
png_state
.
animate
=
TRUE;
png_state
.
frame_count
=
0
;
png_state
.
frame_delay
=
10
;
png_state
.
frame_optimization
=
FALSE;
break
;
case
GIF_DELAY
:
if
(
strncmp
(
"gif"
,
term
->
name
,
3
))
int_warn
(
c_token
,
"This terminal does not support animation"
);
c_token
++
;
png_state
.
frame_delay
=
int_expression
();
if
(
png_state
.
frame_delay
<=
0
)
png_state
.
frame_delay
=
10
;
gif_anim_option
=
1
;
break
;
case
GIF_LOOP
:
if
(
strncmp
(
"gif"
,
term
->
name
,
3
))
int_warn
(
c_token
,
"This terminal does not support animation"
);
c_token
++
;
png_state
.
loop_count
=
int_expression
();
gif_anim_option
=
1
;
break
;
case
GIF_NOOPT
:
if
(
strncmp
(
"gif"
,
term
->
name
,
3
))
int_warn
(
c_token
,
"This terminal does not support animation"
);
c_token
++
;
png_state
.
frame_optimization
=
FALSE;
gif_anim_option
=
1
;
break
;
case
GIF_OPT
:
if
(
strncmp
(
"gif"
,
term
->
name
,
3
))
int_warn
(
c_token
,
"This terminal does not support animation"
);
c_token
++
;
png_state
.
frame_optimization
=
TRUE;
gif_anim_option
=
1
;
break
;
case
PNG_BUTT
:
png_state
.
capbutt
=
TRUE;
c_token
++
;
break
;
case
PNG_ROUNDED
:
png_state
.
capbutt
=
FALSE;
c_token
++
;
break
;
case
PNG_BACKGROUND
:
c_token
++
;
png_state
.
rgb_table
[
0
]
=
parse_color_name
();
png_state
.
n_colors
=
1
;
break
;
case
PNG_OTHER
:
default
:
/* not "size" */
string
=
gp_input_line
+
token
[
c_token
].
start_index
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL