summaryrefslogtreecommitdiff
path: root/support/dktools/bmeps3.ctr
blob: a16cbc11cfdb9b24216c5dcedf97af24e784f190 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2011-xxxx
SPDX-License-Identifier:	BSD-3-Clause



%%	header

%%	module

#include "dk3all.h"
#if 0
#include "dkt-version.h"
#endif
#include "dk4vers.h"
#include "dk3bif.h"
#include "dk3bmeo.h"
#include "dk3bmeps.h"
#include "dk3bm.h"



$!trace-include



/**	Help text shown if no help file is found.
*/
static dkChar const * const bmeps3_default_help_text[] = {
$!text	macro=dkT

NAME

  bmpp - Bitmap to PS/PDF converter

SYNOPSIS

  bmpp [-l<driver>[.<mode>][,<key>[=<value>]...]] [<options>] <file(s)>

DESCRIPTION

The program converts bitmap images from PNG, JPEG, or TIFF to PS/EPS and PDF.

Drivers:
- ps
  PostScript file, can be used to print.
- eps
  Encapsulated PostScript (EPS), image for inclusion into documents.
- pdf
  Portable document format (PDF).
- bb
  Bounding box information only, no image.

Output modes:
- object
  Object which can embedded into a text or drawing by a text processing
  or drawing software.
- image
  Image for stand-alone viewing.
- document
  Fit the output to a given paper size for printing.

OPTIONS

-h
--help
	Show help text.

-v
--version
	Show version number.

-L
--license-terms
	Shows license terms.

-t <type>
	Input image type, "png", "jpeg", or "tiff", must be specified when
	processing standard input or if the input file name suffix does
	not indicate the type.

-m
	Make mode: Avoid unnecessary conversions if output file is up to date.
	Only used when processing a directory.

-s
	Write to standard output, not to a file.

-o <key>[=<value>]
	Detailed conversion options.

NAME=VALUE PAIRS

The key=value pairs set detailed conversion options. For boolean
settings the value can be omitted, the presence of the name sets the option
to active.
The following keys (and values) can be used:

level=<pslevel>
	PS level, "2" or "3".  Default: 3.

color[=<boolean>]
	Color output for PS/EPS output. For PDF output color is
	always enabled. This setting is ignored when passing DCT data from
	JPEG files to output directly.
	Default: On.

dsc[=<boolean>]
	DSC comments when producing PS/EPS output.
	Default: Off, except for ps.document.

draft[=<boolean>]
	Draft mode (small placeholder image only). Default: Off.

predictor=<predictor>
	Predictor for flate compressions, "tiff", "sub", "up",
	"average", or "paeth". Default: none.

duplex[=<boolean>]
	Duplex mode when producing documents. Default: Off.

tumble[=<boolean>]
	Tumble in addition to duplex mode. Default: Off.

dct[=<boolean>]
	Direct pass-through of DCT encoded data found in JPEG
	files. Default: On.

bg=<int>:<int>:<int>[:<boolean>]
	Default background RGB color to be used if the input file
	does not contain a background color chunk. The optional boolean value
	at the end can be used to enforce this background over the background
	chunk. RGB values are in the range 0...255.
	Default: White, off.

interpolation[=<boolean>]
	Image interpolation. Default: On.

jpeg-interpolation[=<boolean>]
	Image interpolation if DCT data is passed through directly.
	Default: Off.

resolution=<resolution>
	Resolution, either "1:1" (use a 1 point x 1 point square for
	each source pixel), "chunk" (use resolution data from image) or an
	integer value for dpi.
	Default: 1:1 for objects, chunk for images,
	fit to paper size for documents.

paper=<paper>
	Paper size for documents. The paper size must be configured
	in a dk3paper.conf file. Only one from "resolution" or "paper" can be
	used.

make[=<boolean>]
	Make mode when processing directories.
	Default: Off.

bpc[=<boolean>]
	Reduce the number of bits per component. Default: On.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

PREFERENCES

/print/ps/level
	Default PS level, 2 or 3.

EXAMPLES

bmpp -lps.document,level=2,paper=A4,duplex,bpc myfax.tif
	converts a fax TIFF file "myfax.tif" to "myfax.ps" for a PS 2 printer.

bmpp -l pdf.document,paper=A4,duplex fax.tif
	creates a PDF file fax.pdf.

bmpp -l ps.object screenshot.png
	creates a PS object file screenshot.ps for use with latex/dvips.

bmpp -l pdf.object screenshot.png
	creates a PDF object file screenshot.pdf for use with pdflatex.

bmpp -l ps.image file.png
	creates a PS image file.ps.

bmpp -l pdf.image file.png
	creates a PDF image file.pdf.

FILES

dk3paper.conf
	If paper=... the named paper size must be configured in a
	dk3paper.conf file.

RESTRICTIONS

The program uses the TIFFReadRGBAImage() function from the libtiff library to
read TIFF images. The input file must meet the following conditions:
- The file must be compliant to the "TIFF baseline v6.0 standard".
- The number of bits of component must be 8 or less.
- The frames must not be too large, the system must be able to allocate the
  4*w*h bytes needed for image date in one piece.

TIFF refers to a group of different compression and encoding mechanisms.
A TIFF file is a sequence of data chunks, each data chunk contains a tag
(chunk type identifier). A lot of tags is defined in standards, i.e. the
"TIFF baseline v6.0 standard". Some software vendors add vendor-specific
or non-standard tags when writing TIFF files.
So when processing TIFF files in bmpp, you should not be surprised to see
warnings or error messages about unknown TIFF tags.
Neither bmpp nor the tifflib library are to blame for this, it's the
responsibility of the people adding the non-standard tags.
Sometimes bmpp can read the image despite of the warnings/errors.

If you create bitmaps you want to process with bmpp, you should create PNG
images instead of TIFF images if you have the choice.

AUTHOR

Dirk Krause

HISTORY

The bmpp program replaces the bmeps program found in previous versions of
dktools.

COPYRIGHT AND LICENSE

Run
  bmpp --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/bmpp%20manual/
	The DK tools and libraries homepage contains more information about
	bmpp and other programs.

http://sourceforge.net/p/gxhints/wiki/Home/
	The Graphics Conversion Hints page recommends programs and shows
	procedures for conversions between recent vector graphics formats.

http://netpbm.sourceforge.net (especially pnmtops)
	NetPBM is a toolkit for graphics images, including conversion of
	images between a variety of different formats.

$!end
};



/**	Strings used to show version number.
*/
static dkChar const * const dk3bm_version_strings[] = {
dkT("bmpp "),
DKT_VERSION_DK
};


/**	Options used by bmeps.
*/
static dk3_option_t const bmeps3_options[] = {
  { dkT('l'), dkT("language"), 1 },
  { dkT('m'), dkT("make"), 0 },
  { dkT('s'), dkT("stdout"), 0 },
  { dkT('t'), dkT("type"), 1 },
  { dkT('h'), dkT("help"), 0 },
  { dkT('v'), dkT("version"), 0 },
  { dkT('L'), dkT("license-terms"), 0 },
  { dkT('\0'),dkT("license"), 0 }
};

/**	Number of options in @a bmeps3_options.
*/
static size_t const bmeps3_szoptions =
sizeof(bmeps3_options)/sizeof(dk3_option_t);



/**	Names of supported input types.
*/
static dkChar const * const	bmeps3_image_type_names[] = {
$!string-table macro=dkT
png
jpg
jpeg
tif
tiff
$!end
};



/**	Suffixes for output files.
*/
static dkChar const * const	bmeps3_output_suffixes[] = {
dkT(".ps"),
dkT(".eps"),
dkT(".pdf"),
dkT(".bb")
};



/**	Strings, not localized.
*/
static dkChar const * const bmeps3_kw[] = {
$!string-table macro=dkT
#
#   0: Program name
#
dktools
#
#   1: String table name
#
bmeps3.str
#
#   2: Option keyword
#
option
$!end
};



/**	License overview text.
*/
static dkChar const * const bmeps3_overview_license[] = {
dkT(""),
dkT("Overview"),
dkT("========"),
dkT("This software uses code from the following projects either directly"),
dkT("or as a library:"),
dkT(""),
dkT("dktools\t\tDirk Krause's tools and libraries."),
dkT("\t\tSee http://sourceforge.net/p/dktools/wiki/Home/ for information."),
#if DK3_HAVE_PNG_H
dkT(""),
dkT("libpng\t\tPNG reference library."),
dkT("\t\tSee http://www.libpng.org/pub/png/libpng.html for information."),
#endif
#if DK3_HAVE_JPEGLIB_H
dkT(""),
dkT("jpeg\t\tIndependent JPEG groups free JPEG library."),
dkT("\t\tSee http://www.ijg.org/ for information."),
#endif
#if DK3_HAVE_TIFF_H
dkT(""),
dkT("libtiff\t\tTIFF library."),
dkT("\t\tSee http://www.remotesensing.org/libtiff/ for information."),
#endif
#if DK3_HAVE_ZLIB_H
dkT(""),
dkT("zlib\t\tCompression library."),
dkT("\t\tSee http://www.zlib.net/ for information."),
#endif
dkT(""),
dkT("Your use of the bmpp/wxbmpp program must be in compliance with the"),
dkT("license conditions for the dktools project and the license conditions"),
dkT("for all the libraries used by bmpp."),
dkT(""),
NULL
};



/**	License terms for the dktools project itself.
*/
static dkChar const * const bmpp_dk_license[] = {
$!text	macro=dkT
License for the dktools project
===============================
Copyright (c) 2011-2016, Dirk Krause
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above 
  copyright notice, this list of conditions and the following
  disclaimer in the documentation and/or other materials
  provided with the distribution.
* Neither the name of the copyright holder(s) nor the names of
  contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

$!end
};

#if DK3_HAVE_PNG_H
static dkChar const * const bmpp_png_license[] = {
$!text macro=dkT

libpng license
==============

This copy of the libpng notices is provided for your convenience.  In case of
any discrepancy between this copy and the notices in the file png.h that is
included in the libpng distribution, the latter shall prevail.

COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:

If you modify libpng you may insert additional notices immediately following
this sentence.

This code is released under the libpng license.

libpng versions 1.2.6, August 15, 2004, through 1.2.46, July 9, 2011, are
Copyright (c) 2004, 2006-2009 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors

   Cosmin Truta

libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.0.6
with the following individuals added to the list of Contributing Authors

   Simon-Pierre Cadieux
   Eric S. Raymond
   Gilles Vollant

and with the following additions to the disclaimer:

   There is no warranty against interference with your enjoyment of the
   library or against infringement.  There is no warranty that our
   efforts or the library will fulfill any of your particular purposes
   or needs.  This library is provided with all faults, and the entire
   risk of satisfactory quality, performance, accuracy, and effort is with
   the user.

libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-0.96,
with the following individuals added to the list of Contributing Authors:

   Tom Lane
   Glenn Randers-Pehrson
   Willem van Schaik

libpng versions 0.89, June 1996, through 0.96, May 1997, are
Copyright (c) 1996, 1997 Andreas Dilger
Distributed according to the same disclaimer and license as libpng-0.88,
with the following individuals added to the list of Contributing Authors:

   John Bowler
   Kevin Bracey
   Sam Bushell
   Magnus Holmgren
   Greg Roelofs
   Tom Tanner

libpng versions 0.5, May 1995, through 0.88, January 1996, are
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.

For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:

   Andreas Dilger
   Dave Martindale
   Guy Eric Schalnat
   Paul Schmidt
   Tim Wegner

The PNG Reference Library is supplied "AS IS".  The Contributing Authors
and Group 42, Inc. disclaim all warranties, expressed or implied,
including, without limitation, the warranties of merchantability and of
fitness for any purpose.  The Contributing Authors and Group 42, Inc.
assume no liability for direct, indirect, incidental, special, exemplary,
or consequential damages, which may result from the use of the PNG
Reference Library, even if advised of the possibility of such damage.

Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:

1. The origin of this source code must not be misrepresented.

2. Altered versions must be plainly marked as such and must not
   be misrepresented as being the original source.

3. This Copyright notice may not be removed or altered from any
   source or altered source distribution.

The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
supporting the PNG file format in commercial products.  If you use this
source code in a product, acknowledgment is not required but would be
appreciated.


A "png_get_copyright" function is available, for convenient use in "about"
boxes and the like:

   printf("%s",png_get_copyright(NULL));

Also, the PNG logo (in PNG format, of course) is supplied in the
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).

Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is a
certification mark of the Open Source Initiative.

Glenn Randers-Pehrson
glennrp at users.sourceforge.net
July 9, 2011
$!end
};
#endif
#if DK3_HAVE_JPEGLIB_H
static dkChar const * const bmpp_jpeg_license[] = {
$!text macro=dkT

jpeglib license
===============

In plain English:

1. We don't promise that this software works.  (But if you find any bugs,
   please let us know!)
2. You can use this software for whatever you want.  You don't have to pay us.
3. You may not pretend that you wrote this software.  If you use it in a
   program, you must acknowledge somewhere in your documentation that
   you've used the IJG code.

In legalese:

The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose.  This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.

This software is copyright (C) 1991-1998, Thomas G. Lane.
All Rights Reserved except as specified below.

Permission is hereby granted to use, copy, modify, and distribute this
software (or portions thereof) for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code for this software is distributed, then this
README file must be included, with this copyright and no-warranty notice
unaltered; and any additions, deletions, or changes to the original files
must be clearly indicated in accompanying documentation.
(2) If only executable code is distributed, then the accompanying
documentation must state that "this software is based in part on the work of
the Independent JPEG Group".
(3) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.

These conditions apply to any software derived from or based on the IJG code,
not just to the unmodified library.  If you use our work, you ought to
acknowledge us.

Permission is NOT granted for the use of any IJG author's name or company name
in advertising or publicity relating to this software or products derived from
it.  This software may be referred to only as "the Independent JPEG Group's
software".

We specifically permit and encourage the use of this software as the basis of
commercial products, provided that all warranty or liability claims are
assumed by the product vendor.


ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
ansi2knr.c is NOT covered by the above copyright and conditions, but instead
by the usual distribution terms of the Free Software Foundation; principally,
that you must include source code if you redistribute it.  (See the file
ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
of any program generated from the IJG code, this does not limit you more than
the foregoing paragraphs do.

The Unix configuration script "configure" was produced with GNU Autoconf.
It is copyright by the Free Software Foundation but is freely distributable.
The same holds for its supporting scripts (config.guess, config.sub,
ltconfig, ltmain.sh).  Another support script, install-sh, is copyright
by M.I.T. but is also freely distributable.

It appears that the arithmetic coding option of the JPEG spec is covered by
patents owned by IBM, AT&T, and Mitsubishi.  Hence arithmetic coding cannot
legally be used without obtaining one or more licenses.  For this reason,
support for arithmetic coding has been removed from the free JPEG software.
(Since arithmetic coding provides only a marginal gain over the unpatented
Huffman mode, it is unlikely that very many implementations will support it.)
So far as we are aware, there are no patent restrictions on the remaining
code.

The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent, GIF reading support has
been removed altogether, and the GIF writer has been simplified to produce
"uncompressed GIFs".  This technique does not use the LZW algorithm; the
resulting GIF files are larger than usual, but are readable by all standard
GIF decoders.

We are required to state that
    "The Graphics Interchange Format(c) is the Copyright property of
    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
    CompuServe Incorporated."

$!end
};
#endif
#if DK3_HAVE_TIFF_H
static dkChar const * const bmpp_tiff_license[] = {
$!text macro=dkT

libtiff license
===============

Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.

Permission to use, copy, modify, distribute, and sell this software and 
its documentation for any purpose is hereby granted without fee, provided
that (i) the above copyright notices and this permission notice appear in
all copies of the software and related documentation, and (ii) the names of
Sam Leffler and Silicon Graphics may not be used in any advertising or
publicity relating to the software without the specific, prior written
permission of Sam Leffler and Silicon Graphics.

THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  

IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
OF THIS SOFTWARE.

$!end
};
#endif
#if DK3_HAVE_ZLIB_H
static dkChar const * const bmpp_zlib_license[] = {
$!text macro=dkT

zlib license
============

 (C) 1995-2004 Jean-loup Gailly and Mark Adler

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Jean-loup Gailly        Mark Adler
  jloup@gzip.org          madler@alumni.caltech.edu

If you use the zlib library in a product, we would appreciate *not*
receiving lengthy legal documents to sign. The sources are provided
for free but without warranty of any kind.  The library has been
entirely written by Jean-loup Gailly and Mark Adler; it does not
include third-party code.

If you redistribute modified sources, we would appreciate that you include
in the file ChangeLog history information documenting your changes. Please
read the FAQ for more information on the distribution of modified source
versions.

$!end
};
#endif



/**	Show one section of text.
	@param	ltext	Text to show.
*/
static
void
bmeps3_show_one_license(dkChar const * const *ltext)
{
  dkChar const * const *	sptr;
  sptr = ltext;
  while(*sptr) {
    dk3sf_fputs(*(sptr++), stdout);
    dk3sf_fputc(dkT('\n'), stdout);
  }
}



/**	Show license for the program itself and for the used libraries.
*/
static
void
bmeps3_show_license(void)
{
  bmeps3_show_one_license(bmeps3_overview_license);
  bmeps3_show_one_license(bmpp_dk_license);
#if DK3_HAVE_PNG_H
  bmeps3_show_one_license(bmpp_png_license);
#endif
#if DK3_HAVE_JPEGLIB_H
  bmeps3_show_one_license(bmpp_jpeg_license);
#endif
#if DK3_HAVE_TIFF_H
  bmeps3_show_one_license(bmpp_tiff_license);
#endif
#if DK3_HAVE_ZLIB_H
  bmeps3_show_one_license(bmpp_zlib_license);
#endif
}



/**	Process a complete directory.
	@param	bmeo	Conversion options.
	@param	fnb	File name for directory.
	@param	app	Application structure for diagnostics.
	@return	1 on success, 0 on error.
*/
static
int
bmeps3_process_directory(
  dk3_bm_eps_options_t		*bmeo,
  dkChar const			*fnb,
  dk3_app_t			*app
)
{
  dkChar		 fni[DK3_MAX_PATH];	/* Input file name. */
  dkChar		 fno[DK3_MAX_PATH];	/* output file name. */
  dkChar const * const	*msg;			/* Localized message texts. */
  dk3_dir_t		*dir;			/* Directory. */
  dkChar const		*en;			/* Full file name. */
  dkChar const		*sn;			/* Short file name. */
  dkChar const		*nsptr;			/* Suffix output file. */
  dkChar const		*oldsourcefile;		/* Old source file name. */
  dkChar		*sptr;			/* Suffix input file. */
  dk3_stat_t const	*es;			/* Stat info input file. */
  dk3_stat_t		 stb;			/* Stat buffer output file. */
  int			 mustrun;		/* Flag: Must convert file. */
  int			 sit;			/* Image type. */
  int			 back	= 0;
  $? "+ bmeps3_process_directory"
  msg = dk3app_messages(
    app,
    dk3bmep_str_get_string_table_name(),
    (dkChar const **)dk3bmep_str_get_message_texts()
  );
  if(!(msg)) {
    msg = dk3bmep_str_get_message_texts();
  }
  oldsourcefile = dk3app_get_source_file(app);
  dir = dk3dir_open_app(fnb, app);
  if(dir) {			$? ". dr: %d", bmeo->dr
    back = 1;			$? ". bmeo.app: %!8s", TR_8PTR(bmeo->app)
    while(dk3dir_get_next_file(dir)) {	$? ". yet another entry"
      en = dk3dir_get_fullname(dir);	$? ". entry \"%!ds\"", en
      sn = dk3dir_get_shortname(dir);
      es = dk3dir_get_stat(dir);
      if((en) && (es)) {		$? ". have name and stat"
        if(dk3bif_type_supported(sit = dk3bif_check_file_name(en))) { $? ". ok"
	  if(((es->ft) & (~(DK3_FT_SYMLINK))) == DK3_FT_REGULAR) {	$? ".ft"
	    mustrun = 1;
	    if(bmeo->make) {
	      if(dk3str_len(en) < DK3_SIZEOF(fni,dkChar)) {
	        dk3str_cpy_not_overlapped(fni, en);
		dk3str_cpy_not_overlapped(fno, en);
		sptr = dk3str_get_suffix(fno);
		if(sptr) {
		  *sptr = dkT('\0');	$? ". dr: %d", bmeo->dr
		  if((bmeo->dr >= 0) && (bmeo->dr <= 3)) {
		    nsptr = bmeps3_output_suffixes[bmeo->dr];
		    if((dk3str_len(fno) + dk3str_len(nsptr))
		       < DK3_SIZEOF(fno,dkChar)
		    )
		    {
		      dk3str_cpy_not_overlapped(sptr, nsptr); $? ". check \"%!ds\"", fno
		      if(dk3sf_stat_app(&stb, fno, NULL)) {
		        if(stb.mod > es->mod) {
			  mustrun = 0;
			}
		      }
		    }
		  }
		}
	      }
	    }
	    if(mustrun) {	$? ". run for \"%!ds\" dr: %d", en, bmeo->dr
	      dk3app_log_3(app, DK3_LL_PROGRESS, msg, 41, 42, ((sn) ? sn : en));
	      dk3app_set_source_file(app, ((sn) ? sn : en));
	      if(!dk3bm_process_file_name(bmeo,en,sit,0,1000,NULL)) {
		back = 0;
	      }
	      dk3app_set_source_file(app, oldsourcefile);
	      dk3app_log_3(app, DK3_LL_PROGRESS, msg, 43, 44, ((sn) ? sn : en));
	    } else {		$? ". no need to run for \"%!ds\"", en
	      dk3app_log_3(app, DK3_LL_PROGRESS, msg, 45, 46, ((sn) ? sn : en));
	    }
	  } else {			$? ". not a regular file"
	  }
	} else {			$? ". no need to process this file"
	}
      } else {				$? "! name or stat missing"
        back = 0;
        /* BUG: Should be handled by dk3dir. */
      }
    }
    dk3dir_close(dir);
  } else {				$? "! failed to open dir"
    /* ERROR: Failed to open directory! */
  }
  dk3app_set_source_file(app, oldsourcefile);
  $? "- bmeps3_process_directory %d", back
  return back;
}




/**	Copy contents of one file to another.
	@param	fipoout	Destination file.
	@param	fipoin	Source file.
	@param	app	Application structure for diagnostics.
	@return	1 on success, 0 on error.
*/
static
int
bmeps3_copy_files(FILE *fipoout, FILE *fipoin, dk3_app_t *app)
{
  char		bu[4096];	/* Buffer for data. */
  size_t	rb;		/* Number of bytes read. */
  int		cc;		/* Flag: Can continue. */
  int		back = 1;
  do {
    cc = 0;
    rb = dk3sf_fread_app(bu, 1, sizeof(bu), fipoin, app);
    if(rb > 0) {
      cc = 1;
      if(!dk3sf_fwrite_app(bu, 1, rb, fipoout, app)) {
        back = 0; cc = 0;
      }
    }
  } while(cc);
  return back;
}




/**	Run with application structure and localized messages.
	@param	app	Application structure.
	@param	msg	Localized messages.
	@param	optset	Option set.
	@return	1 on success, 0 on error.
*/
static
int
bmeps3_run_with_optset(
  dk3_app_t		*app,
  dkChar const * const	*msg,
  dk3_option_set_t	*optset
)
{
  dkChar		 fnb[DK3_MAX_PATH];	/* File name. */
  dk3_bm_eps_options_t	 bmeo;		/* Conversion option set. */
  dk3_stat_t		 stb;		/* Stat buffer. */
  dk3_dir_t		*fne;		/* File name expander. */
  dk3_stat_t const	*es;		/* Entry (file) stat information. */
  FILE			*fipo;		/* Temporary file. */
  dkChar const		*larg;		/* Option argument. */
  dkChar const		*fo;		/* Further opt currently processed. */
  dkChar const		*en;		/* Entry (file) name. */
  int			 fonum;		/* Number of further options. */
  int			 i;		/* Traverse options and arguments. */
  int			 sit;		/* Standard input image type. */
  int			 numargs;	/* Number of command line args. */
  int			 found;		/* Flag: At least one file found. */
#if DK3_ON_WINDOWS
  int			 oldmode;	/* Stdin mode before start. */
#endif
  int			 back	= 0;
  $? "+ bmeps3_run_with_optset"
  sit = DK3_BIF_IMAGE_TYPE_UNKNOWN;
  dk3bmeo_init(&bmeo);
  bmeo.app = app;			$? ". app: %!8s", TR_8PTR(app)
  back = 1;				$? ". dr: %d", bmeo.dr
  if(dk3opt_is_set(optset, dkT('l'))) {
    larg = dk3opt_get_short_arg(optset, dkT('l'));
    if(larg) {
      if(!dk3bmeo_set_language(&bmeo, larg, app)) {
        back = 0;
	/* ERROR during option processing! */
      }
      bmeo.app = app;
    } else {
      /* BUG: Option -l set, but no argument. Should be handled by dk3opt. */
    }
  }					$? ". dr: %d", bmeo.dr
  if(dk3opt_is_set(optset, dkT('m'))) {
    bmeo.make = 1;
  }
  if(dk3opt_is_set(optset, dkT('s'))) {
    bmeo.to_stdout = 1;
  }
  if(dk3opt_is_set(optset, dkT('t'))) {
    larg = dk3opt_get_short_arg(optset, dkT('t'));
    if(larg) {
      switch(dk3str_array_index(bmeps3_image_type_names, larg, 0)) {
        case 0: {
	  sit = DK3_BIF_IMAGE_TYPE_PNG;
	} break;
	case 1: case 2: {
	  sit = DK3_BIF_IMAGE_TYPE_JPEG;
	} break;
	case 3: case 4: {
	  sit = DK3_BIF_IMAGE_TYPE_TIFF;
	} break;
	default: {
	  /* ERROR: Unknown file type ... */
	  dk3app_log_3(app, DK3_LL_ERROR, msg, 63, 64, larg);
	  back = 0;
	} break;
      }
    } else {
      /*  BUG: Option -t set, but no argument. Should be handled by dk3opt. */
    }
  }
  if(back) {
    if((fonum = dk3opt_get_num_fo(optset)) > 0) {
      for(i = 0; i < fonum; i++) {
        fo = dk3opt_get_fo(optset, i);
	if(fo) {
	  if(!dk3bmeo_apply_option(&bmeo, fo, msg)) {
	    back = 0;
	    /* ERROR: Error while adding option! */
	  }
	} else {
	  /* BUG: Option not available. Should be handled by dk3opt. */
	}
      }
    }
  }					$? ". dr: %d", bmeo.dr
  if(back) {
    if(dk3opt_is_set(optset, dkT('h'))
       || dk3opt_is_set(optset, dkT('v'))
       || dk3opt_is_set(optset, dkT('L'))
    )
    {
      if(dk3opt_is_set(optset, dkT('v'))) {
        /* Print version number */
	dk3sf_initialize_stdout();
	dk3sf_fputs(dk3bm_version_strings[0], stdout);
	dk3sf_fputs(dk3bm_version_strings[1], stdout);
	dk3sf_fputc(dkT('\n'), stdout);
      }
      if(dk3opt_is_set(optset, dkT('L'))) {
        dk3sf_initialize_stdout();
	bmeps3_show_license();
      } else {
        if(dk3opt_is_set_long(optset, dkT("license"))) {
	  dk3sf_initialize_stdout();
	  bmeps3_show_license();
	}
      }
      if(dk3opt_is_set(optset, dkT('h'))) {
        dk3sf_initialize_stdout();
        dk3app_help(app, dkT("bmpp3.txt"), bmeps3_default_help_text);
      }
    } else {
      dk3bmeo_check(&bmeo, 0, NULL);	$? ". dr: %d", bmeo.dr
      numargs = dk3opt_get_num_args(optset);
      if(numargs > 0) {		$? ". file and/or directory names."
        for(i = 0; i < numargs; i++) {
          larg = dk3opt_get_arg(optset, i);
	  if(larg) {
	    if(dk3str_len(larg) < DK3_SIZEOF(fnb,dkChar)) {
	      dk3str_cpy_not_overlapped(fnb, larg);
	      dk3str_correct_filename(fnb);
	      if(dk3sf_must_expand(fnb)) {	$? ". must expand fnb"
	        found = 0;
	        fne = dk3dir_fne_open_app(fnb, app);
	        if(fne) {
	          while(dk3dir_get_next_file(fne)) {
		    en = dk3dir_get_fullname(fne);
		    es = dk3dir_get_stat(fne);
		    if((en) && (es)) {
		      if(((es->ft) & (~(DK3_FT_SYMLINK))) == DK3_FT_REGULAR) {
		        sit = DK3_BIF_IMAGE_TYPE_UNKNOWN;
		        if(!dk3bm_process_file_name(&bmeo,en,sit,0,1000,NULL))
		        {
		          back = 0;
		        }
		      } else {
		        /* ERROR: Not a regular file! */
			dk3app_log_i3(app, DK3_LL_ERROR, 255, 256, fnb);
		      }
		    } else {
		      /* BUG: Should be handled by dk3dir. */
		      back = 0;
		    }
		  }
	          dk3dir_close(fne);
		  if(!(found)) {
		    back = 0;
		    /* ERROR: No such file! */
		    dk3app_log_i3(app, DK3_LL_ERROR, 215, 216, fnb);
		  }
	        } else {
	          /* ERROR: Failed to expand file name! */
		  back = 0;
	        }
	      } else {				$? ". use fnb directly"
	        if(dk3sf_stat_app(&stb, fnb, app)) {
	          switch((stb.ft) & (~(DK3_FT_SYMLINK))) {
		    case DK3_FT_DIRECTORY: {
		      if(!bmeps3_process_directory(&bmeo, fnb, app)) {
		        back = 0;
		      }
		    } break;
		    case DK3_FT_REGULAR: {
		      if(!dk3bm_process_file_name(&bmeo,fnb,sit,0,1000,NULL)) {
		        back = 0;
		      }
		    } break;
		    default: {
		      /* ERROR: Illegal file type! */
		      back = 0;
		      dk3app_log_3(app, DK3_LL_ERROR, msg, 65, 66, fnb);
		    } break;
		  }
	        } else {
	          /* ERROR: No information about file! */
		  back = 0;
	        }
	      }
	    } else {
	      /* ERROR: File name too long! */
	      back = 0;
	      dk3app_log_i3(app, DK3_LL_ERROR, 65, 66, larg);
	    }
	  } else {		$? "! arg not available"
	    /* BUG: Option not available, should be handled by dk3opt. */
	  }
        }
      } else {			$? ". no arguments, process standard input."
        if(sit != DK3_BIF_IMAGE_TYPE_UNKNOWN) {
	  if(dk3app_get_temp_file_name(app, fnb, DK3_SIZEOF(fnb,dkChar))) {
	    fipo = dk3sf_fopen_app(fnb, dk3app_not_localized(53), app);
	    if(fipo) {
#if DK3_ON_WINDOWS
	      oldmode = _setmode(_fileno(stdin), _O_BINARY);
#endif
	      i = bmeps3_copy_files(fipo, stdin, app);
#if DK3_ON_WINDOWS
	      _setmode(_fileno(stdin), oldmode);
#endif
#if VERSION_BEFORE_2012_04_19
	      fclose(fipo);
#else
	      if(!dk3sf_fclose_fn_app(fipo, fnb, app)) {
	        i = 0;
	      }
#endif
	      if(i) {
	        bmeo.to_stdout = 1;
	        back = dk3bm_process_file_name(&bmeo,fnb,sit,0,1000,NULL);
	      }
	    } else {
	      /* ERROR: Failed to open file for writing! */
	      back = 0;
	    }
	  } else {
	    back = 0;
	    /* ERROR: Failed to obtain temporary file name! */
	  }
        } else {
          /* ERROR: No file type specified for standard input! */
	  back = 0;
	  dk3app_log_1(app, DK3_LL_ERROR, msg, 67);
        }
      }
    }
  }
  $? "- bmeps3_run_with_optset %d", back
  return back;
}



/**	Run with application structure and localized messages.
	@param	app	Application structure.
	@param	msg	Localized messages.
	@return	1 on success, 0 on error.
*/
static
int
bmeps3_run_with_app(dk3_app_t *app, dkChar const * const *msg)
{
  dk3_option_set_t	*optset;	/* Options provided on command line. */
  int			back	= 0;
  $? "+ bmeps3_run_with_app"
  optset = dk3opt_open_from_app(
    bmeps3_options,
    bmeps3_szoptions,
    dkT('o'),
    bmeps3_kw[2],
    app
  );
  if(optset) {		$? ". optset"
    if(0 == dk3opt_get_error_code(optset)) {	$? ". optset no error"
      back = bmeps3_run_with_optset(app, msg, optset);
    } else {					$? "! optset error"
      /* ERROR: Error in options */
    }
    dk3opt_close(optset);
  } else {		$? "! optset"
  } $? "- bmeps3_run_with_app %d", back
  return back;
}



/**	The main() function.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	0 on success, any other value indicates an error.
*/
DK3_MAIN
{
  dk3_app_t		*app;	/* Application structure. */
  dkChar const * const	*msg;	/* Localizd messages. */
  int			 exval;	/* Exit code. */

  $!trace-init bmeps3.deb
  $? "+ main"
  exval = 1;
  app = dk3app_open_command(
    argc, (dkChar const * const *)argv, bmeps3_kw[0]
  );
  if(app) {			$? ". app ok"
    msg = dk3app_messages(
      app,
      dk3bmep_str_get_string_table_name(),
      (dkChar const **)dk3bmep_str_get_message_texts()
    );
    if(msg) {			$? ". msg ok"
      if(bmeps3_run_with_app(app, msg)) {
        exval = 0;
      }
    } else {			$? "! msg"
      /* BUG: Should not happen, as the fucntion returns the default array! */
    }
    dk3app_close(app);
  } else {			$? "! app"
    /* ERROR: Memory */
    fputs("ERROR: Not enough memory (RAM/swap space)!\n", stderr);
    fflush(stderr);
  }
  $? "- main %d", exval
  $!trace-end
  fflush(stdout);
  exit(exval); return exval;
}