File: 01_libjpeg-support.patch

package info (click to toggle)
xloadimage 4.1-27
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,880 kB
  • sloc: ansic: 36,063; makefile: 306; asm: 284; sh: 144
file content (1544 lines) | stat: -rw-r--r-- 43,754 bytes parent folder | download | duplicates (2)
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
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
From: Yoshida Hiroshi <BXH04165@nifty.ne.jp>
Subject: Add support for libjpeg6b and other misc fixes.
 Also convert to autoconf.

--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,51 @@
+#
+# Makefile for autoconf tutorial
+#
+
+CC = @CC@
+DEFS = @DEFS@
+CFLAGS = @CFLAGS@
+XLIB = @X_LIBS@ @X_PRE_LIBS@ -lX11 @X_EXTRA_LIBS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+
+SRCS = bright.c clip.c cmuwmraster.c compress.c config.c \
+dither.c faces.c fbm.c fill.c gif.c halftone.c imagetypes.c img.c jpeg.c \
+mac.c mc_tables.c mcidas.c merge.c misc.c new.c niff.c options.c \
+pbm.c pcx.c pdsuncomp.c reduce.c rle.c rlelib.c root.c rotate.c \
+send.c smooth.c sunraster.c tiff.c undither.c value.c vff.c \
+vicar.c window.c xbitmap.c xloadimage.c xpixmap.c xwd.c zio.c zoom.c
+
+OBJS = $(SRCS:.c=.o)
+PROG = xloadimage
+
+all: $(PROG) uufilter
+
+$(PROG): $(OBJS)
+	./build-info
+	$(CC) $(CFLAGS) -c $(DEFS) build.c
+	$(CC) -o $@ $(OBJS) build.o$(LDFLAGS) $(XLIB) $(LIBS)
+
+uufilter: uufilter.c
+	$(CC) $(CFLAGS) $(DEFS) uufilter.c -o $@
+
+.c.o: config.h image.h
+	$(CC) $(CFLAGS) -c $(DEFS) $<
+
+build.c:
+	./build-info
+clean:
+	rm -f $(PROG) uufilter build.c *.o
+
+distclean:
+	make clean
+	rm -f config.log config.cache config.status config.h Makefile
+
+config.h.in: configure.ac
+	autoheader
+
+configure: configure.ac
+	autoconf
+
+Makefile: Makefile.in
+	./configure
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,30 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(xloadimage.c)
+AC_CONFIG_HEADER(config.h)
+
+dnl Checks for programs.
+AC_PROG_CC
+
+dnl Checks for header files.
+AC_PATH_XTRA
+AC_HEADER_STDC
+AC_CHECK_HEADERS(malloc.h strings.h sys/time.h unistd.h)
+
+dnl Checks for libraries.
+dnl Replace `main' with a function in -lm:
+AC_CHECK_LIB(m, main)
+dnl Replace `main' with a function in -lz:
+AC_CHECK_LIB(z, main)
+dnl Replace `main' with a function in -ljpeg:
+AC_CHECK_LIB(jpeg, main)
+dnl Replace `main' with a function in -ltiff:
+AC_CHECK_LIB(tiff, main)
+
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+
+dnl Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS(mkdir select)
+
+AC_OUTPUT(Makefile)
--- /dev/null
+++ b/configure.scan
@@ -0,0 +1,32 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(buildshar.c)
+
+dnl Checks for programs.
+AC_PROG_CC
+
+dnl Checks for libraries.
+dnl Replace `main' with a function in -lX11:
+AC_CHECK_LIB(X11, main)
+dnl Replace `main' with a function in -lXext:
+AC_CHECK_LIB(Xext, main)
+dnl Replace `main' with a function in -ljpeg:
+AC_CHECK_LIB(jpeg, main)
+dnl Replace `main' with a function in -lm:
+AC_CHECK_LIB(m, main)
+dnl Replace `main' with a function in -ltiff:
+AC_CHECK_LIB(tiff, main)
+dnl Replace `main' with a function in -lz:
+AC_CHECK_LIB(z, main)
+
+dnl Checks for header files.
+AC_PATH_X
+AC_HEADER_STDC
+AC_CHECK_HEADERS(malloc.h strings.h sys/time.h unistd.h)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+
+dnl Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS(mkdir select)
+
+AC_OUTPUT(Makefile)
--- a/fbm.c
+++ b/fbm.c
@@ -45,12 +45,12 @@ static int  fbmin_img_bits;	       /* co
 static int  fbmin_img_rowlen;	       /* length of one row of data */
 static int  fbmin_img_plnlen;	       /* length of one plane of data */
 static int  fbmin_img_clrlen;	       /* length of the colormap */
-static int  fbmin_img_aspect;	       /* image aspect ratio */
+static double  fbmin_img_aspect;	       /* image aspect ratio */
 static int  fbmin_img_physbits;	       /* physical bits per pixel */
 static char *fbmin_img_title;		/* name of image */
 static char *fbmin_img_credit;		/* credit for image */
 
-static fbmin_image_test()
+static int fbmin_image_test()
 {
   if (fbmin_img_width < 1 || fbmin_img_width > 32767) {
     fprintf (stderr, "Invalid width (%d) on input\n", fbmin_img_width);
@@ -93,7 +93,7 @@ static fbmin_image_test()
   }
 
   if (fbmin_img_aspect < 0.01 || fbmin_img_aspect > 100.0) {
-    fprintf (stderr, "Invalid aspect ratio %lg on input\n",
+    fprintf (stderr, "Invalid aspect ratio %1.3f on input\n",
 	     fbmin_img_aspect);
     return FBMIN_ERR_BAD_SD;
   }
@@ -133,7 +133,7 @@ ZFILE *s;
   fbmin_img_rowlen   = atoi(phdr.rowlen);
   fbmin_img_plnlen   = atoi(phdr.plnlen);
   fbmin_img_clrlen   = atoi(phdr.clrlen);
-  fbmin_img_aspect   = atoi(phdr.aspect);
+  fbmin_img_aspect   = atof(phdr.aspect);
   fbmin_img_physbits = atoi(phdr.physbits);
   fbmin_img_title    = phdr.title;
   fbmin_img_credit   = phdr.credits;
--- a/image.h
+++ b/image.h
@@ -8,6 +8,10 @@
  * copyright information.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "copyright.h"
 
 #include <stdio.h>
--- a/imagetypes.c
+++ b/imagetypes.c
@@ -17,6 +17,7 @@
 /* SUPPRESS 560 */
 
 extern int errno;
+extern int findImage(char *name, char *fullname);
 
 /* load a named image
  */
--- a/imagetypes.h
+++ b/imagetypes.h
@@ -28,10 +28,10 @@ Image *pdsLoad();
 #else
 Image *vicarLoad();
 #endif
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 Image *jpegLoad();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 Image *tiffLoad();
 #endif
 
@@ -56,18 +56,18 @@ int pdsIdent();
 #else
 int vicarIdent();
 #endif
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 int jpegIdent();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 int tiffIdent();
 #endif
 
 void niffDump();
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 void jpegDump();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 void tiffDump();
 #endif
 void pbmDump();
@@ -85,10 +85,10 @@ struct {
   niffIdent,      niffLoad,      niffDump,    "niff",      "Native Image File Format (NIFF)",
   sunRasterIdent, sunRasterLoad, NULL,        "sunraster", "Sun Rasterfile",
   gifIdent,       gifLoad,       NULL,        "gif",       "GIF Image",
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
   jpegIdent,      jpegLoad,      jpegDump,    "jpeg",      "JFIF-style JPEG Image",
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
   tiffIdent,      tiffLoad,      tiffDump,    "tiff",      "TIFF image",
 #endif
   fbmIdent,       fbmLoad,       NULL,        "fbm",       "FBM Image",
--- a/img.c
+++ b/img.c
@@ -413,7 +413,7 @@ static Image *load_img(name)
      char *name;
 {
   ZFILE           *file;
-  Image           *image;
+  Image           *image = NULL;
   unsigned long    w, h, nplanes, headlength, scanwidth;
   int              colors;
   long             i, dummy;
@@ -632,9 +632,9 @@ static Image *load_ximg(name)
 {
   void            transferRGBMap();
   ZFILE          *file;
-  Image          *image;
+  Image          *image = NULL;
   unsigned long   w, h, nplanes, scanwidth;
-  int             i, color, colors;
+  int             color, colors;
   struct RGB_LIST
   {
     unsigned int red;
--- a/jpeg.c
+++ b/jpeg.c
@@ -4,509 +4,314 @@
  * free JPEG software.  See jpeg.README for more information.
  *
  * This code is based on example.c from the IJG v4 distribution.
+ * 1998/08/19: Change for IJG v6.0a. dump Progressive JPEG support.
  */
 
 #include "image.h"	/* xloadimage declarations */
-#include "jpeg.conf.h"  /* definitions used in jpeg directory */
-#include "jpeg/jinclude.h" /* IJG declarations */
+#ifdef HAVE_LIBJPEG
+#include "options.h"
+#include <jpeglib.h>
+#include <jerror.h>
 #include <setjmp.h>	/* need setjmp/longjmp */
 
-/* Error-catching routines */
+#undef  DEBUG
+/* #define  DEBUG */
+#undef  debug
+
+#ifdef DEBUG
+# define debug(xx)	fprintf(stderr,xx)
+#else
+# define debug(xx)
+#endif
+
+static Image *image;    /* xloadimage image being returned */
 
 static char *filename;
-static unsigned int verbose;
-static unsigned int identify;
 static jmp_buf setjmp_buffer;	/* for return to caller */
-static external_methods_ptr emethods; /* needed for access to message_parm */
+ZFILE * zinput_file;	/* tells input routine where to read JPEG */
+static JOCTET jpeg_read_buff[1024 * 16];
 
-static void
-trace_message (msgtext)
-     char *msgtext;
+/*
+ * source manager
+ */
+static void init_source( j_decompress_ptr cinfo)
 {
-  fprintf(stderr, "jpegLoad: %s - ", filename);
-  fprintf(stderr, msgtext,
-	  emethods->message_parm[0], emethods->message_parm[1],
-	  emethods->message_parm[2], emethods->message_parm[3],
-	  emethods->message_parm[4], emethods->message_parm[5],
-	  emethods->message_parm[6], emethods->message_parm[7]);
-  fprintf(stderr, "\n");	/* there is no \n in the format string! */
-}
 
-static void
-error_exit (msgtext)
-     char *msgtext;
-{
-  trace_message(msgtext);	/* report the error message */
-  (*emethods->free_all) ();	/* clean up memory allocation & temp files */
-  longjmp(setjmp_buffer, 1);	/* return control to outer routine */
+    debug("init_source()");
 }
 
+static boolean fill_input_buffer( j_decompress_ptr cinfo)
+{
+    struct jpeg_source_mgr *src = cinfo->src;
 
-/* Output-acceptance routines */
-
-static Image *image;		/* xloadimage image being returned */
-static int rows_put;		/* Number of rows copied to image */
-
-
-static void
-output_init (cinfo)
-     decompress_info_ptr cinfo;
-/* Initialize for output */
-{
-  int i;
-
-  if (cinfo->out_color_space == CS_GRAYSCALE) {
-    image = newRGBImage(cinfo->image_width,cinfo->image_height,8);
-    image->title = dupString(filename);
-    /* set a linear map */
-    for(i=0;i<256;i++) {
-      *(image->rgb.red + i) = 
-	*(image->rgb.green + i) = 
-	  *(image->rgb.blue + i) = i<<8;
-    }
-    image->rgb.used = 256;
-  } else if (cinfo->out_color_space == CS_RGB) {
-    image = newTrueImage(cinfo->image_width,cinfo->image_height);
-    image->title = dupString(filename);
-  } else {
-    image = NULL;
-    ERREXIT(cinfo->emethods, "Cannot cope with JPEG image colorspace");
-  }
-  rows_put = 0;
+    debug("fill_input_buffer()");
+#ifdef DEBUG
+    fprintf( stderr,"fill_input_buffer(): %d  ",src->bytes_in_buffer);
+#endif
+    src->next_input_byte = jpeg_read_buff;
+    src->bytes_in_buffer = zread(zinput_file,
+				 jpeg_read_buff, sizeof(jpeg_read_buff));
+    if(src->bytes_in_buffer <= 0){
+	WARNMS(cinfo, JWRN_JPEG_EOF);
+	jpeg_read_buff[0] = 0xFF;
+	jpeg_read_buff[1] = JPEG_EOI;
+	src->bytes_in_buffer = 2;
+    }
+    return TRUE;
+}
+
+static void skip_input_data( j_decompress_ptr cinfo, long num_bytes)
+{
+    int rest;
+    struct jpeg_source_mgr *src = cinfo->src;
+
+    debug("skip_input_data()");
+#ifdef DEBUG
+    fprintf(stderr,": %ld,%d  ", num_bytes, src->bytes_in_buffer);
+#endif
+    if( num_bytes < 1) return;
+    rest = src->bytes_in_buffer;
+    if( num_bytes < rest) {
+	src->next_input_byte += num_bytes;
+	src->bytes_in_buffer -= num_bytes;;
+	return;
+    }
+    num_bytes -= rest;
+    while( num_bytes--) {
+	zgetc(zinput_file);
+    }
+    fill_input_buffer(cinfo);
 }
 
-
-static void
-put_color_map (cinfo, num_colors, colormap)
-     decompress_info_ptr cinfo;
-     int num_colors;
-     JSAMPARRAY colormap;
-/* Write the color map -- should not be called */
+static boolean resync_to_restart( j_decompress_ptr cinfo, int desired)
 {
-  fprintf(stderr, "put_color_map called: there is a bug here somewhere!\n");
+    return jpeg_resync_to_restart( cinfo, desired);
 }
 
-
-static void
-put_pixel_rows (cinfo, num_rows, pixel_data)
-     decompress_info_ptr cinfo;
-     int num_rows;
-     JSAMPIMAGE pixel_data;
-/* Write some rows of output data */
-{
-  register unsigned char *bufp;
-  register JSAMPROW ptr0, ptr1, ptr2;
-  register long col;
-  long width = cinfo->image_width;
-  int row;
-  
-  if (cinfo->out_color_space == CS_GRAYSCALE) {
-    bufp = image->data + rows_put * width;
-    /* Assume JSAMPLE == chars */
-    for (row = 0; row < num_rows; row++) {
-      bcopy(pixel_data[0][row],bufp,width);
-      bufp += width;
-    }
-  } else {
-    bufp = image->data + rows_put * width * 3;
-    for (row = 0; row < num_rows; row++) {
-      ptr0 = pixel_data[0][row];
-      ptr1 = pixel_data[1][row];
-      ptr2 = pixel_data[2][row];
-      for (col = width; col > 0; col--) {
-	*bufp++ = *ptr0++;
-	*bufp++ = *ptr1++;
-	*bufp++ = *ptr2++;
-      }
-    }
-  }
-  rows_put += num_rows;
+static void term_source( j_decompress_ptr cinfo)
+{
+    debug("term_source()");
 }
 
-
+/*
+ *  error manager
+ */
 static void
-output_term (cinfo)
-     decompress_info_ptr cinfo;
-/* Finish up at the end of the output */
+output_message ( j_common_ptr cominfo)
 {
-  /* No work here */
-}
-
+    char buf[JMSG_LENGTH_MAX];
 
-/* Input-file-reading routine */
-
-
-static ZFILE * input_file;	/* tells input routine where to read JPEG */
+    (*cominfo->err->format_message)(cominfo, buf);
+    fprintf(stderr, "jpegLoad: %s - %s\n", filename, buf);
+}
 
 
-static int
-read_jpeg_data (cinfo)
-     decompress_info_ptr cinfo;
+static void error_exit (j_common_ptr cominfo)
 {
-  cinfo->next_input_byte = cinfo->input_buffer + MIN_UNGET;
-
-  cinfo->bytes_in_buffer = zread(input_file,
-				 (byte *)cinfo->next_input_byte,
-				 JPEG_BUF_SIZE);
-  
-  if (cinfo->bytes_in_buffer <= 0) {
-    WARNMS(cinfo->emethods, "Premature EOF in JPEG file");
-    cinfo->next_input_byte[0] = (char) 0xFF;
-    cinfo->next_input_byte[1] = (char) 0xD9; /* EOI marker */
-    cinfo->bytes_in_buffer = 2;
-  }
-
-  return JGETC(cinfo);
+    output_message( cominfo);
+    longjmp(setjmp_buffer, 1);	/* return control to outer routine */
 }
 
 
-/*  Required control-hook routine */
-
-
 static void
-d_ui_method_selection (cinfo)
-     decompress_info_ptr cinfo;
+jpegInfo (cinfo)
+     j_decompress_ptr cinfo;
 {
-  /* if grayscale input, force grayscale output; */
-  /* else leave the output colorspace as set by main routine. */
-  if (cinfo->jpeg_color_space == CS_GRAYSCALE)
-    cinfo->out_color_space = CS_GRAYSCALE;
-
-  /* Create display of image parameters */
-  if (verbose) {
+    /* Create display of image parameters */
     printf("%s is a %dx%d JPEG image, color space ", filename,
 	   cinfo->image_width, cinfo->image_height);
     switch (cinfo->jpeg_color_space) {
-    case CS_UNKNOWN:
-      printf("Unknown");
-      break;
-    case CS_GRAYSCALE:
-      printf("Grayscale");
-      break;
-    case CS_RGB:
-      printf("RGB");
-      break;
-    case CS_YCbCr:
-      printf("YCbCr");
-      break;
-    case CS_YIQ:
-      printf("YIQ");
-      break;
-    case CS_CMYK:
-      printf("CMYK");
-      break;
+    case JCS_GRAYSCALE:
+	printf("Grayscale");
+	break;
+    case JCS_RGB:
+	printf("RGB");
+	break;
+    case JCS_YCbCr:
+	printf("YCbCr");
+	break;
+    case JCS_CMYK:
+	printf("CMYK");
+	break;
+    case JCS_YCCK:
+	printf("YCCK");
+	break;
+    case JCS_UNKNOWN:
+    default:
+	printf("Unknown");
+	break;
     }
     printf(", %d comp%s,", cinfo->num_components,
-	   cinfo->num_components ? "s." : ".");
+	   (cinfo->num_components - 1) ? "s" : "");
+    if (cinfo->progressive_mode)
+	printf(" Progressive,");
     if (cinfo->arith_code)
-      printf(" Arithmetic coding\n");
+	printf(" Arithmetic coding.\n");
     else
-      printf(" Huffman coding\n");
-  }
-
-  /* Turn off caching beyond this point of the file */
-  znocache(input_file);
-
-  /* If we only wanted to identify the image, abort now */
-  if (identify) {
-    (*emethods->free_all) ();	/* clean up memory allocation & temp files */
-    longjmp(setjmp_buffer, 10);	/* return control with success code */
-  }
-
-  /* select output routines */
-  cinfo->methods->output_init = output_init;
-  cinfo->methods->put_color_map = put_color_map;
-  cinfo->methods->put_pixel_rows = put_pixel_rows;
-  cinfo->methods->output_term = output_term;
+	printf(" Huffman coding.\n");
 }
 
 
 /* Main control routine for loading */
 
-
 Image *
-jpegLoad (fullname, name, vbose)
+jpegLoad (fullname, name, verbose)
      char *fullname, *name;
-     unsigned int vbose;
+     unsigned int verbose;
 {
-  struct Decompress_info_struct cinfo;
-  struct Decompress_methods_struct dc_methods;
-  struct External_methods_struct e_methods;
-
-  input_file = zopen(fullname);	/* Open the input file */
-  if (input_file == NULL)
-    return NULL;
-
-  /* Quick check to see if file starts with JPEG SOI marker */
-  if (zgetc(input_file) != 0xFF || zgetc(input_file) != 0xD8) {
-    zclose(input_file);
-    return NULL;
-  }
+    struct jpeg_decompress_struct cinfo;
+    struct jpeg_source_mgr src_mgr;
+    struct jpeg_error_mgr err_mgr;
+    int i, row_stride;
+    byte *bufp;
+
+    zinput_file = zopen(fullname);	/* Open the input file */
+    if (zinput_file == NULL)
+	return NULL;
+    filename = name;		/* copy parms to static vars */
+    image = NULL;		/* in case we fail before creating image */
+
+    jpeg_create_decompress(&cinfo);
+    src_mgr.init_source = init_source;
+    src_mgr.fill_input_buffer = fill_input_buffer;
+    src_mgr.skip_input_data = skip_input_data;
+    src_mgr.resync_to_restart = resync_to_restart;
+    src_mgr.term_source = term_source;
+    cinfo.src = &src_mgr;	/* links to method structs */
+    err_mgr.error_exit = error_exit; /* supply error-exit routine */
+    err_mgr.output_message = output_message;
+    err_mgr.trace_level = 0;	/* default = no tracing */
+    err_mgr.num_warnings = 0;	/* no warnings emitted yet */
+    cinfo.err = jpeg_std_error(&err_mgr);
+
+    src_mgr.bytes_in_buffer = 0;
+    fill_input_buffer( &cinfo);
+    /* Quick check to see if file starts with JPEG SOI marker */
+    if(jpeg_read_buff[0] != 0xFF || jpeg_read_buff[1] != 0xD8) {
+	zclose(zinput_file);
+	return NULL;
+    }
+
+    /* prepare setjmp context for possible exit from error_exit */
+    if (setjmp(setjmp_buffer)) {
+	/* If we get here, the JPEG code has signaled an error. */
+	/* Return as much of the image as we could get. */
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return image;
+    }
+
+    jpeg_read_header(&cinfo, TRUE);
+    if (verbose) jpegInfo(&cinfo);
+    /* Turn off caching beyond this point of the file */
+    znocache(zinput_file);
+    jpeg_start_decompress(&cinfo);
+
+    switch (cinfo.out_color_space) {
+    case JCS_GRAYSCALE:
+	image = newRGBImage(cinfo.image_width,cinfo.image_height,8);
+	image->title = dupString(filename);
+	/* set a linear map */
+	for(i=0;i<256;i++) {
+	    *(image->rgb.red + i) =
+		*(image->rgb.green + i) =
+		*(image->rgb.blue + i) = i << 8;
+	}
+	image->rgb.used = 256;
+	break;
+    case JCS_RGB:
+	image = newTrueImage(cinfo.image_width,cinfo.image_height);
+	image->title = dupString(filename);
+	break;
+    default:
+	image = NULL;
+	ERREXITS(&cinfo, 1, "Cannot cope with JPEG image colorspace");
+    }
+
+    row_stride = cinfo.output_width * cinfo.output_components;
+    bufp = image->data;
+    while (cinfo.output_scanline < cinfo.output_height) {
+	jpeg_read_scanlines(&cinfo, &bufp, 1);
+	bufp += row_stride;
+    }
+
+    jpeg_finish_decompress(&cinfo);
+    jpeg_destroy_decompress(&cinfo);
+    zclose(zinput_file);		/* Done, close the input file */
 
-  filename = name;		/* copy parms to static vars */
-  verbose = vbose;
-  identify = 0;
-
-  image = NULL;			/* in case we fail before creating image */
-
-  cinfo.methods = &dc_methods;	/* links to method structs */
-  cinfo.emethods = &e_methods;
-  emethods = &e_methods;	/* save struct addr for possible access */
-  e_methods.error_exit = error_exit; /* supply error-exit routine */
-  e_methods.trace_message = trace_message; /* supply trace-message routine */
-  e_methods.trace_level = 0;	/* default = no tracing */
-  e_methods.num_warnings = 0;	/* no warnings emitted yet */
-  e_methods.first_warning_level = 0; /* display first corrupt-data warning */
-  e_methods.more_warning_level = 3; /* but suppress additional ones */
-
-  /* prepare setjmp context for possible exit from error_exit */
-  if (setjmp(setjmp_buffer)) {
-    /* If we get here, the JPEG code has signaled an error. */
-    /* Return as much of the image as we could get. */
-    zclose(input_file);
     return image;
-  }
-
-  jselmemmgr(&e_methods);	/* select std memory allocation routines */
-
-  /* Set up default decompression parameters. */
-  j_d_defaults(&cinfo, TRUE);
-
-  /* Override default methods */
-  dc_methods.d_ui_method_selection = d_ui_method_selection;
-  dc_methods.read_jpeg_data = read_jpeg_data;
-
-  /* Insert fake SOI into the input buffer --- needed cause we read it above */
-  cinfo.next_input_byte = cinfo.input_buffer + MIN_UNGET;
-  cinfo.next_input_byte[0] = (char) 0xFF;
-  cinfo.next_input_byte[1] = (char) 0xD8; /* SOI marker */
-  cinfo.bytes_in_buffer = 2;
-
-  /* Set up to read a JFIF or baseline-JPEG file. */
-  /* This is the only JPEG file format currently supported. */
-  jselrjfif(&cinfo);
-
-  /* Here we go! */
-  jpeg_decompress(&cinfo);
-
-  zclose(input_file);		/* Done, close the input file */
-
-  return image;
 }
 
 
-/* Main control routine for identifying JPEG without loading */
-
-
+/*
+  Main control routine for identifying JPEG without loading
+  return 0: Not jpeg file.
+  */
 int
 jpegIdent (fullname, name)
      char *fullname, *name;
 {
-  struct Decompress_info_struct cinfo;
-  struct Decompress_methods_struct dc_methods;
-  struct External_methods_struct e_methods;
-
-  input_file = zopen(fullname);	/* Open the input file */
-  if (input_file == NULL)
-    return 0;
-
-  /* Quick check to see if file starts with JPEG SOI marker */
-  if (zgetc(input_file) != 0xFF || zgetc(input_file) != 0xD8) {
-    zclose(input_file);
-    return 0;
-  }
+    struct jpeg_decompress_struct cinfo;
+    struct jpeg_source_mgr src_mgr;
+    struct jpeg_error_mgr err_mgr;
+
+    zinput_file = zopen(fullname);	/* Open the input file */
+    if (zinput_file == NULL)
+	return 0;
+
+    filename = name;		/* copy parms to static vars */
+
+    jpeg_create_decompress(&cinfo);
+    src_mgr.init_source = init_source;
+    src_mgr.fill_input_buffer = fill_input_buffer;
+    src_mgr.skip_input_data = skip_input_data;
+    src_mgr.resync_to_restart = resync_to_restart;
+    src_mgr.term_source = term_source;
+    cinfo.src = &src_mgr;	/* links to method structs */
+    err_mgr.error_exit = error_exit; /* supply error-exit routine */
+    err_mgr.output_message = output_message;
+    err_mgr.trace_level = 0;	/* default = no tracing */
+    err_mgr.num_warnings = 0;	/* no warnings emitted yet */
+    cinfo.err = jpeg_std_error(&err_mgr);
+
+    src_mgr.bytes_in_buffer = 0;
+    fill_input_buffer( &cinfo);
+    /* Quick check to see if file starts with JPEG SOI marker */
+    if(jpeg_read_buff[0] != 0xFF || jpeg_read_buff[1] != 0xD8) {
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return 0;
+    }
+
+    /* prepare setjmp context for expected exit via longjmp */
+    if (setjmp(setjmp_buffer)) {
+	/* If we get here, the JPEG code has signaled an error. */
+	/* Return 0 since error in the headers means the image is unloadable. */
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return 0;
+    }
+
+    jpeg_read_header(&cinfo, TRUE);
+    jpegInfo(&cinfo);
+    /* Turn off caching beyond this point of the file */
+    znocache(zinput_file);
+    jpeg_destroy_decompress(&cinfo);
+    zclose(zinput_file);
 
-  /* We want to find and display the image dimensions, and also
-   * verify that the header markers are not corrupt.  To do this,
-   * we fire up the JPEG decoder as normal, but when d_ui_method_selection
-   * is called, we abort the process by longjmp'ing back here.
-   * This works nicely since the headers are all read at that point.
-   */
-
-  filename = name;		/* copy parms to static vars */
-  verbose = 1;
-  identify = 1;
-
-  cinfo.methods = &dc_methods;	/* links to method structs */
-  cinfo.emethods = &e_methods;
-  emethods = &e_methods;	/* save struct addr for possible access */
-  e_methods.error_exit = error_exit; /* supply error-exit routine */
-  e_methods.trace_message = trace_message; /* supply trace-message routine */
-  e_methods.trace_level = 0;	/* default = no tracing */
-  e_methods.num_warnings = 0;	/* no warnings emitted yet */
-  e_methods.first_warning_level = 0; /* display first corrupt-data warning */
-  e_methods.more_warning_level = 3; /* but suppress additional ones */
-
-  /* prepare setjmp context for expected exit via longjmp */
-  switch (setjmp(setjmp_buffer)) {
-  case 0:
-    /* First time thru, keep going */
-    break;
-  case 10:
-    /* Successful exit from d_ui_method_selection; return A-OK */
-    zclose(input_file);
     return 1;
-  default:
-    /* If we get here, the JPEG code has signaled an error. */
-    /* Return 0 since error in the headers means the image is unloadable. */
-    zclose(input_file);
-    return 0;
-  }
-
-  jselmemmgr(&e_methods);	/* select std memory allocation routines */
-
-  /* Set up default decompression parameters. */
-  j_d_defaults(&cinfo, TRUE);
-
-  /* Override default methods */
-  dc_methods.d_ui_method_selection = d_ui_method_selection;
-  dc_methods.read_jpeg_data = read_jpeg_data;
-
-  /* Insert fake SOI into the input buffer --- needed cause we read it above */
-  cinfo.next_input_byte = cinfo.input_buffer + MIN_UNGET;
-  cinfo.next_input_byte[0] = (char) 0xFF;
-  cinfo.next_input_byte[1] = (char) 0xD8; /* SOI marker */
-  cinfo.bytes_in_buffer = 2;
-
-  /* Set up to read a JFIF or baseline-JPEG file. */
-  /* This is the only JPEG file format currently supported. */
-  jselrjfif(&cinfo);
-
-  /* Here we go! */
-  jpeg_decompress(&cinfo);
-
-  /* Don't expect to get here since d_ui_method_selection should do longjmp */
-
-  zclose(input_file);
-  return 0;
-}
-
-/* information necessary to extract image data
- */
-static struct {
-  Image *image;
-  byte *current_row;
-  unsigned int bytes_per_row;
-} ReadInfo;
-
-static void input_init(cinfo)
-compress_info_ptr cinfo;
-{
-  /* this is done in jpegDump()
-   */
-}
-
-static void input_term(cinfo)
-compress_info_ptr cinfo;
-{
-  /* there is no shutdown necessary
-   */
-}
-
-/* this reads a single raster line
- */
-static void read_row(cinfo, pixel_rows)
-     compress_info_ptr cinfo;
-     JSAMPARRAY pixel_rows;
-{
-  register int x;
-  register int pixlen;
-  register byte *src_row_ptr;
-  register byte *dest_red_ptr;
-  register byte *dest_green_ptr;
-  register byte *dest_blue_ptr;
-  register Pixel pixval;
-  register byte mask;
-
-  switch (ReadInfo.image->type) {
-  case IBITMAP:
-    mask = 0x80;
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    for (x = 0; x < cinfo->image_width; x++) {
-      pixval = ((*src_row_ptr & mask) > 0 ? 1 : 0);
-
-      /* we use the "red" color value under the assumption that they
-       * are all equal.  that can be wrong if the user used -foreground
-       * or -background.  I don't care right now.
-       */
-      *(dest_red_ptr++) = ReadInfo.image->rgb.red[pixval] >> 8;
-      mask >>= 1;
-      if (mask == 0) {
-	mask = 0x80;
-	src_row_ptr++;
-      }
-    }
-    break;
-
-  case IRGB:
-    /* this expands the pixel value into its components
-     */
-    pixlen = ReadInfo.image->pixlen;
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    dest_green_ptr = (byte *)pixel_rows[1];
-    dest_blue_ptr = (byte *)pixel_rows[2];
-    for (x = 0; x < cinfo->image_width; x++) {
-      pixval = memToVal(src_row_ptr, pixlen);
-      *(dest_red_ptr++) = ReadInfo.image->rgb.red[pixval] >> 8;
-      *(dest_green_ptr++) = ReadInfo.image->rgb.green[pixval] >> 8;
-      *(dest_blue_ptr++) = ReadInfo.image->rgb.blue[pixval] >> 8;
-      src_row_ptr += pixlen;
-    }
-    break;
-
-  case ITRUE:
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    dest_green_ptr = (byte *)pixel_rows[1];
-    dest_blue_ptr = (byte *)pixel_rows[2];
-    for (x = 0; x < cinfo->image_width; x++) {
-      *(dest_red_ptr++) = *(src_row_ptr++);
-      *(dest_green_ptr++) = *(src_row_ptr++);
-      *(dest_blue_ptr++) = *(src_row_ptr++);
-    }
-    break;
-  }
-  ReadInfo.current_row += ReadInfo.bytes_per_row;
 }
 
 /*
- * This routine gets control after the input file header has been read.
- * It must determine what output JPEG file format is to be written,
- * and make any other compression parameter changes that are desirable.
+ * Dump Jpeg
  */
 
-static void
-c_ui_method_selection (cinfo)
-     compress_info_ptr cinfo;
-{
-  /* If the input is gray scale, generate a monochrome JPEG file. */
-  if (cinfo->in_color_space == CS_GRAYSCALE)
-    j_monochrome_default(cinfo);
-  jselwjfif(cinfo);
-}
-
 /* parse options passed to jpegDump
  */
-static void parseOptions(cinfo, options, verbose)
-     compress_info_ptr cinfo;
-     char *options;
-     int verbose;
+static void parseOptions(j_compress_ptr cinfo, char *options, int verbose)
 {
   char *name, *value;
 
-  /* (Re-)initialize the system-dependent error and memory managers. */
-  jselerror(cinfo->emethods);	/* error/trace message routines */
-  jselmemmgr(cinfo->emethods);	/* memory allocation routines */
-  cinfo->methods->c_ui_method_selection = c_ui_method_selection;
-
-  /* Set up default JPEG parameters. */
-  /* Note that default -quality level here need not, and does not,
-   * match the default scaling for an explicit -qtables argument.
-   */
-  j_c_defaults(cinfo, 75, FALSE); /* default quality level = 75 */
-
   while (getNextTypeOption(&options, &name, &value) > 0) {
     if (!strncmp("arithmetic", name, strlen(name))) {
       /* Use arithmetic coding. */
@@ -524,7 +329,7 @@ static void parseOptions(cinfo, options,
       /* Force a monochrome JPEG file to be generated. */
       if (verbose)
 	printf("  Creating a grayscale/monochrome file.\n");
-      j_monochrome_default(cinfo);
+      jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
     }
     else if (!strncmp("nointerleave", name, strlen(name))) {
       /* Create noninterleaved file. */
@@ -536,16 +341,18 @@ static void parseOptions(cinfo, options,
       fprintf(stderr, "jpegDump: sorry, multiple-scan support was not compiled\n");
 #endif
     }
+    else if (!strncmp("progressive", name, strlen(name))) {
+      /* Enable progressive JPEG. */
+      if (verbose)
+	printf("  Progressive JPEG.\n");
+      jpeg_simple_progression (cinfo);
+    }
     else if (!strncmp("optimize", name, strlen(name)) ||
 	     !strncmp("optimise", name, strlen(name))) {
       /* Enable entropy parm optimization. */
-#ifdef ENTROPY_OPT_SUPPORTED
       if (verbose)
 	printf("  Optimizing entropy.\n");
       cinfo->optimize_coding = TRUE;
-#else
-      fprintf(stderr, "jpegDump: sorry, entropy optimization was not compiled\n");
-#endif
     }
     else if (!strncmp("quality", name, strlen(name))) {
       /* Quality factor (quantization table scaling factor). */
@@ -561,7 +368,7 @@ static void parseOptions(cinfo, options,
 	 */
 	if (verbose)
 	  printf("  Using a quality factor of %d.\n", val);
-	j_set_quality(cinfo, val, FALSE);
+	jpeg_set_quality(cinfo, val, FALSE);
 #if 0
 	/* Change scale factor in case -qtables is present. */
 	q_scale_factor = j_quality_scaling(val);
@@ -626,74 +433,134 @@ static void parseOptions(cinfo, options,
   }
 }
 
-void jpegDump(image, options, file, verbose)
-    Image *image;
-    char *options;
-    char *file;
-{
-  struct Compress_info_struct cinfo;
-  struct Compress_methods_struct c_methods;
-  struct External_methods_struct e_methods;
-
-  if (verbose)
-    printf("Dumping JFIF-style JPEG image to %s.\n", file);
-
-  /* Set up links to method structures. */
-  cinfo.methods = &c_methods;
-  cinfo.emethods = &e_methods;
-
-  /* set up "input methods" that handle "reading" from our image file
-   */
-  cinfo.methods->input_init = input_init;
-  cinfo.methods->input_term = input_term;
-  cinfo.methods->get_input_row = read_row;
-
-  /* set up output file; there is no input file
-   */
-  cinfo.input_file = NULL;
-  cinfo.output_file = fopen(file, "w");
-  if (cinfo.output_file == NULL) {
-    perror(file);
-    return;
-  }
+/* this reads a single raster line
+ */
 
-  ReadInfo.image = image;
-  ReadInfo.current_row = image->data;
+byte *current_row;
+unsigned int bytes_per_row;
 
-  /* parse the options the user gave us
-   */
-  parseOptions(&cinfo, options, verbose);
-
-  /* set up image information
-   */
-  cinfo.image_width = image->width;
-  cinfo.image_height = image->height;
-
-  switch (image->type) {
-  case IBITMAP:
-    ReadInfo.bytes_per_row = (image->width / 8) + (image->width % 8 ? 1 : 0);
-    cinfo.input_components = 1;
-    cinfo.in_color_space = CS_GRAYSCALE;
-    cinfo.data_precision = 8;
-    break;
-  case IRGB:
-    ReadInfo.bytes_per_row = image->width * image->pixlen;
-    cinfo.input_components = 3;
-    cinfo.in_color_space = CS_RGB;
-    cinfo.data_precision = 8;
-    break;
-  case ITRUE:
-    ReadInfo.bytes_per_row = image->width * image->pixlen;
-    cinfo.input_components = 3;
-    cinfo.in_color_space = CS_RGB;
-    cinfo.data_precision = 8;
-    break;
-  }
+static byte *read_row(Image *image, byte *pixel_rows)
+{
+    int x;
+    int pixlen;
+    byte *src_row_ptr = current_row;
+    byte *dest_row_ptr = pixel_rows;
+    Pixel pixval;
+    byte mask;
+
+    switch (image->type) {
+    case IBITMAP:
+	mask = 0x80;
+	for (x = 0; x < image->width; x++) {
+	    pixval = ((*src_row_ptr & mask) > 0 ? 1 : 0);
+
+	    /* we use the "red" color value under the assumption that they
+	     * are all equal.  that can be wrong if the user used -foreground
+	     * or -background.  I don't care right now.
+	     */
+	    *dest_row_ptr++ = image->rgb.red[pixval] >> 8;
+	    mask >>= 1;
+	    if (mask == 0) {
+		mask = 0x80;
+		src_row_ptr++;
+	    }
+	}
+	break;
 
-  /* compress, baby
-   */
-  jpeg_compress(&cinfo);
+    case IRGB:
+	/* this expands the pixel value into its components
+	 */
+	pixlen = image->pixlen;
+	for (x = 0; x < image->width; x++) {
+	    pixval = memToVal(src_row_ptr, pixlen);
+	    *dest_row_ptr++ = image->rgb.red[pixval] >> 8;
+	    *dest_row_ptr++ = image->rgb.green[pixval] >> 8;
+	    *dest_row_ptr++ = image->rgb.blue[pixval] >> 8;
+	    src_row_ptr += pixlen;
+	}
+	break;
+
+    case ITRUE:
+	return current_row;
+	break;
+    }
+    return pixel_rows;
+}
+
+void jpegDump(Image *image, char *options, char *file, int verbose)
+{
+    struct jpeg_compress_struct cinfo;
+    struct jpeg_error_mgr jerr;
+    FILE * outfile;		/* target file */
+    JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
+
+    cinfo.err = jpeg_std_error(&jerr);
+    jpeg_create_compress(&cinfo);
+
+    if ((outfile = fopen(file, "w")) == NULL) {
+	perror(file);
+	return;
+    }
+    jpeg_stdio_dest(&cinfo, outfile);
+
+    cinfo.image_width = image->width;
+    cinfo.image_height = image->height;
+
+    /* set # of color components per pixel & colospace fo input image */
+    switch (image->type) {
+    case IBITMAP:
+	bytes_per_row = (image->width / 8) + (image->width % 8 ? 1 : 0);
+	cinfo.input_components = 1;
+	cinfo.in_color_space = JCS_GRAYSCALE;
+	row_pointer[0] = lmalloc( cinfo.image_width * cinfo.input_components);
+	break;
+    case IRGB:
+	bytes_per_row = image->width * image->pixlen;
+	cinfo.input_components = 3;
+	cinfo.in_color_space = JCS_RGB;    /* colorspace of input image */
+	row_pointer[0] = lmalloc( cinfo.image_width * cinfo.input_components);
+	break;
+    case ITRUE:
+	bytes_per_row = image->width * image->pixlen;
+	cinfo.input_components = 3;
+	cinfo.in_color_space = JCS_RGB;    /* colorspace of input image */
+	row_pointer[0] = image->data;
+	break;
+    }
+    /* Now use the library's routine to set default compression parameters.
+     * (You must set at least cinfo.in_color_space before calling this,
+     * since the defaults depend on the source color space.)
+     */
+    jpeg_set_defaults(&cinfo);
+    /* Now you can set any non-default parameters you wish to.
+     * Here we just illustrate the use of quality (quantization table) scaling:
+     */
+    jpeg_set_quality(&cinfo, 75, TRUE /* limit to baseline-JPEG values */);
+    if( cinfo.in_color_space == JCS_GRAYSCALE)
+	jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE);
+    parseOptions(&cinfo, options, verbose);
+
+    jpeg_start_compress(&cinfo, TRUE);
+
+    current_row = image->data;
+    while (cinfo.next_scanline < cinfo.image_height) {
+	/* jpeg_write_scanlines expects an array of pointers to scanlines.
+	 * Here the array is only one element long, but you could pass
+	 * more than one scanline at a time if that's more convenient.
+	 */
+	row_pointer[0] = read_row(image, row_pointer[0]);
+	(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
+	current_row += bytes_per_row;
+    }
 
-  fclose(cinfo.output_file);
-  return;
+    jpeg_finish_compress(&cinfo);
+    fclose(outfile);
+    jpeg_destroy_compress(&cinfo);
+    if (image->type == IBITMAP || image->type == IRGB) {
+	lfree( row_pointer[0]);
+    }
 }
+
+#else /* !HAVE_LIBJPEG */
+static int unused;
+#endif /* !HAVE_LIBJPEG */
--- a/misc.c
+++ b/misc.c
@@ -32,8 +32,10 @@ static char *signalName(sig)
   switch (sig) {
   case SIGSEGV:
     return("SEGV");
+#ifdef	SIGBUS
   case SIGBUS:
     return("BUS");
+#endif
   case SIGFPE:
     return("FPE");
   case SIGILL:
--- a/niff.c
+++ b/niff.c
@@ -8,6 +8,7 @@
  * this is in the public domain.
  */
 
+#include <unistd.h>
 #include "image.h"
 #include "niff.h"
 
@@ -17,8 +18,7 @@ static void babble(name, header, title)
 {
   printf("%s is a %dx%d ", name,
 	 memToVal(header->width, 4),
-	 memToVal(header->height, 4),
-	 memToVal(header->depth, 4));
+	 memToVal(header->height, 4));
   if (memToVal(header->version, 4) != NIFF_VERSION)
     printf("version %d ", memToVal(header->version, 4));
   printf("NIFF ");
@@ -121,8 +121,8 @@ Image *niffLoad(fullname, name, verbose)
   struct niff_header header;
   char *title;
   unsigned int width, height, depth;
-  Image *image;
-  unsigned int data_size;
+  Image *image = NULL;
+  unsigned int data_size = 0;
 
   if (! (zf= zopen(fullname)))
     return(NULL);
@@ -191,7 +191,7 @@ void niffDump(image, options, filename,
   unsigned int a;
   struct niff_header header;
   struct niff_cmap cmap;
-  unsigned int data_size;
+  unsigned int data_size = 0;
 
   if (verbose)
     printf("Dumping NIFF image to %s.\n", filename);
--- a/pbm.c
+++ b/pbm.c
@@ -12,6 +12,7 @@
  */
 
 #include "image.h"
+#include "options.h"
 #include "pbm.h"
 
 /* SUPPRESS 558 */
@@ -188,14 +189,14 @@ Image *pbmLoad(fullname, name, verbose)
      char         *fullname, *name;
      unsigned int  verbose;
 { ZFILE        *zf;
-  Image        *image;
+  Image        *image = NULL;
   int           pbm_type;
   int           x, y;
   int           width, height, maxval, depth;
   unsigned int  linelen;
   byte          srcmask, destmask;
   byte         *destptr, *destline;
-  int           src, size;
+  int           src = 0, size;
   int           red, grn, blu;
 
   if (! (zf= zopen(fullname)))
--- a/rlelib.c
+++ b/rlelib.c
@@ -980,7 +980,8 @@ struct sv_globals * globals;
  *	Returns code.
  */
 
-rle_get_error( code, pgmname, fname )
+int rle_get_error( code, pgmname, fname )
+int code;
 char *pgmname;
 char *fname;
 {
@@ -1595,7 +1596,7 @@ int magic[16][16];
 
 	total = size * size;
 
-	i = 0;
+	i = bx = by = 0;
 	li = -1;
 	for(j=0;j<total;j++)	
 	{
--- a/sunraster.c
+++ b/sunraster.c
@@ -240,7 +240,8 @@ Image *sunRasterLoad(fullname, name, ver
   case RTIFF: /* sorry, don't even know what these are */
   case RIFF:
   default:
-    fprintf(stderr, "%s: Unsupported Sun Rasterfile image type (sorry)\n");
+    fprintf(stderr, "%s: Unsupported Sun Rasterfile image type (sorry)\n",
+	    name);
     return(NULL);
   }
 
--- a/tiff.c
+++ b/tiff.c
@@ -5,10 +5,10 @@
  * jim frost 09.05.93
  */
 
-#ifdef HAS_TIFF
-
 #include "image.h"
-#include "tiff/tiffio.h"
+#ifdef HAVE_LIBTIFF
+
+#include <tiffio.h>
 
 /* this structure contains all the information we care about WRT a TIFF
  * image.
@@ -217,7 +217,7 @@ static void babble(name, info)
 	   compressionName(info->compression));
   }
   if (info->title)
-    printf("Titled \"%s\"");
+    printf("Titled \"%s\"", info->title);
   printf("\n");
 }
 
@@ -227,14 +227,14 @@ int tiffIdent(fullname, name)
   struct tiff_info info;
 
   tiff = is_tiff(fullname, name, &info);
-  babble(name, info);
   if (tiff == NULL)
     return(0);
+  babble(name, &info);
   if (tiff == (TIFF *)-1) /* is TIFF, but can't open it */
     return(1);
   TIFFClose(tiff);
 
-  babble(fullname, name, info);
+/*  babble(fullname, name, info); */
   return(1);
 }
 
@@ -404,6 +404,7 @@ Image *tiffLoad(fullname, name, verbose)
     if (info.samplesperpixel != 3) {
       fprintf(stderr,
 	      "%s: Can't handle TIFF RGB images with %d samples per pixel, sorry\n",
+	      fullname,
 	      info.samplesperpixel);
       image = NULL;
       break;
@@ -624,6 +625,6 @@ void tiffDump(image, options, file, verb
   TIFFClose(out);
 }
 
-#else /* !HAS_TIFF */
+#else /* !HAVE_LIBTIFF */
 static int unused;
-#endif /* !HAS_TIFF */
+#endif /* !HAVE_LIBTIFF */
--- a/uufilter.c
+++ b/uufilter.c
@@ -11,8 +11,9 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
-main(argc, argv)
+int main(argc, argv)
      int argc;
      char **argv;
 {
@@ -64,7 +65,7 @@ main(argc, argv)
       fprintf(stderr, "Ignoring header line: %s\n", buf);
   }
   if (feof(inf)) {
-    fprintf(stderr, "No 'begin' line, sorry.\n", infilename);
+    fprintf(stderr, "%s: No 'begin' line, sorry.\n", infilename);
     exit(1);
   }
 
--- a/vff.c
+++ b/vff.c
@@ -29,6 +29,7 @@
  */
 
 
+#include <ctype.h>
 #include "image.h"
 
 #define HEAD_BUF_SIZE	2048
--- a/window.c
+++ b/window.c
@@ -15,7 +15,7 @@
 #include <X11/Xatom.h>
 #include <signal.h>
 #include <errno.h>
-#include <sys/types.h>
+#include <sys/time.h>
 #ifdef HAS_POLL
 #include <poll.h>
 #else /* !HAS_POLL */
@@ -616,13 +616,13 @@ char imageInWindow(disp, scrn, image, gl
     lastx= (winwidth || winheight); /* user set size flag */
     if (!winwidth) {
       winwidth= image->width;
-      if (winwidth > DisplayWidth(disp, scrn) * 0.9)
-	winwidth= DisplayWidth(disp, scrn) * 0.9;
+      if (winwidth > DisplayWidth(disp, scrn) * 0.98)
+	winwidth= DisplayWidth(disp, scrn) * 0.98;
     }
     if (!winheight) {
       winheight= image->height;
-      if (winheight > DisplayHeight(disp, scrn) * 0.9)
-	winheight= DisplayHeight(disp, scrn) * 0.9;
+      if (winheight > DisplayHeight(disp, scrn) * 0.95)
+	winheight= DisplayHeight(disp, scrn) * 0.95;
     }
   }
 
@@ -902,10 +902,25 @@ char imageInWindow(disp, scrn, image, gl
 
     switch (event.any.type) {
     case ButtonPress:
-      if (event.button.button == 1) {
+      switch (event.button.button) {
+      case 1:
 	lastx= event.button.x;
 	lasty= event.button.y;
 	break;
+      case 3:
+	if (delay)
+	  alarm(0);
+	{
+	   Cursor cursor;
+	   cursor= swa_view.cursor;
+	   swa_view.cursor= XCreateFontCursor(disp, XC_watch);
+	   XChangeWindowAttributes(disp, ViewportWin, CWCursor, &swa_view);
+	   XFreeCursor(disp, cursor);
+	   XFlush(disp);
+	   cleanUpImage(disp, scrn, swa_view.cursor, pixmap,
+			image, ximageinfo);
+	}
+	return(' ');
       }
       break;
 
--- a/xbitmap.c
+++ b/xbitmap.c
@@ -132,7 +132,7 @@ Image *xbitmapLoad(fullname, name, verbo
   char          name_and_type[MAX_SIZE];
   char         *type;
   int           value;
-  int           v10p;
+  int           v10p = 0;
   unsigned int  linelen, dlinelen;
   unsigned int  x, y;
   unsigned int  w = 0, h = 0;
--- a/xloadimage.c
+++ b/xloadimage.c
@@ -18,8 +18,6 @@
 #endif
 #include <signal.h>
 
-extern double atof();
-
 char *ProgramName= "xloadimage";
 
 /* if an image loader needs to have our display and screen, it will get
@@ -192,7 +190,9 @@ main(argc, argv)
    */
 
   signal(SIGSEGV, internalError);
+#ifdef	SIGBUS
   signal(SIGBUS, internalError);
+#endif
   signal(SIGFPE, internalError);
   signal(SIGILL, internalError);
 #if defined(_AIX) && defined(_IBMR2)