Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
d374ea0c80
70 changed files with 10269 additions and 10266 deletions
  1. 133 133
      panda/src/mpg123/audio.c
  2. 253 253
      panda/src/mpg123/common.c
  3. 1 1
      panda/src/mpg123/decode.c
  4. 14 14
      panda/src/mpg123/decode_ntom.c
  5. 12 12
      panda/src/mpg123/equalizer.c
  6. 4 4
      panda/src/mpg123/getbits.c
  7. 268 268
      panda/src/mpg123/httpget.c
  8. 1 1
      panda/src/mpg123/layer1.c
  9. 3 3
      panda/src/mpg123/layer2.c
  10. 19 19
      panda/src/mpg123/layer3.c
  11. 156 156
      panda/src/mpg123/mpgbuffer.c
  12. 102 102
      panda/src/mpg123/readers.c
  13. 1 1
      panda/src/mpg123/tabinit.c
  14. 15 15
      panda/src/mpg123/vbrhead.c
  15. 131 131
      panda/src/mpg123/xfermem.c
  16. 94 91
      panda/src/pnm/bitio.c
  17. 381 381
      panda/src/pnm/libpbm1.c
  18. 36 36
      panda/src/pnm/libpbm2.c
  19. 26 26
      panda/src/pnm/libpbm3.c
  20. 19 19
      panda/src/pnm/libpbm4.c
  21. 267 267
      panda/src/pnm/libpbm5.c
  22. 42 42
      panda/src/pnm/libpgm1.c
  23. 34 34
      panda/src/pnm/libpgm2.c
  24. 43 43
      panda/src/pnm/libpnm1.c
  25. 41 41
      panda/src/pnm/libpnm2.c
  26. 214 214
      panda/src/pnm/libpnm3.c
  27. 303 303
      panda/src/pnm/libpnm4.c
  28. 79 79
      panda/src/pnm/libppm1.c
  29. 54 54
      panda/src/pnm/libppm2.c
  30. 83 83
      panda/src/pnm/libppm3.c
  31. 354 354
      panda/src/pnm/libppm5.c
  32. 204 204
      panda/src/pnmimagetypes/color.c
  33. 168 168
      panda/src/pnmimagetypes/colrops.c
  34. 125 125
      panda/src/pnmimagetypes/header.c
  35. 58 58
      panda/src/pnmimagetypes/resolu.c
  36. 407 407
      panda/src/tiff/mkg3states.c
  37. 31 31
      panda/src/tiff/mkspans.c
  38. 98 98
      panda/src/tiff/tif_apple.c
  39. 129 129
      panda/src/tiff/tif_aux.c
  40. 30 30
      panda/src/tiff/tif_ccittrle.c
  41. 14 14
      panda/src/tiff/tif_close.c
  42. 55 55
      panda/src/tiff/tif_compress.c
  43. 642 642
      panda/src/tiff/tif_dir.c
  44. 219 219
      panda/src/tiff/tif_dirinfo.c
  45. 473 473
      panda/src/tiff/tif_dirread.c
  46. 459 459
      panda/src/tiff/tif_dirwrite.c
  47. 46 46
      panda/src/tiff/tif_dumpmode.c
  48. 13 13
      panda/src/tiff/tif_error.c
  49. 482 482
      panda/src/tiff/tif_fax3.c
  50. 48 48
      panda/src/tiff/tif_fax4.c
  51. 16 16
      panda/src/tiff/tif_flush.c
  52. 475 475
      panda/src/tiff/tif_getimage.c
  53. 1 1
      panda/src/tiff/tif_jpeg.c
  54. 592 592
      panda/src/tiff/tif_lzw.c
  55. 72 72
      panda/src/tiff/tif_machdep.c
  56. 34 34
      panda/src/tiff/tif_msdos.c
  57. 89 89
      panda/src/tiff/tif_next.c
  58. 225 225
      panda/src/tiff/tif_open.c
  59. 174 174
      panda/src/tiff/tif_packbits.c
  60. 514 514
      panda/src/tiff/tif_print.c
  61. 375 375
      panda/src/tiff/tif_read.c
  62. 45 45
      panda/src/tiff/tif_strip.c
  63. 38 38
      panda/src/tiff/tif_swab.c
  64. 84 84
      panda/src/tiff/tif_thunder.c
  65. 103 103
      panda/src/tiff/tif_tile.c
  66. 45 45
      panda/src/tiff/tif_unix.c
  67. 1 1
      panda/src/tiff/tif_version.c
  68. 109 109
      panda/src/tiff/tif_vms.c
  69. 14 14
      panda/src/tiff/tif_warning.c
  70. 379 379
      panda/src/tiff/tif_write.c

+ 133 - 133
panda/src/mpg123/audio.c

@@ -51,10 +51,10 @@ static char *channel_name[NUM_CHANNELS] =
 
 static int channels[NUM_CHANNELS] = { 1 , 2 };
 static int rates[NUM_RATES] = { 
-	 8000, 11025, 12000, 
-	16000, 22050, 24000,
-	32000, 44100, 48000,
-	8000	/* 8000 = dummy for user forced */
+         8000, 11025, 12000, 
+        16000, 22050, 24000,
+        32000, 44100, 48000,
+        8000    /* 8000 = dummy for user forced */
 
 };
 static int encodings[NUM_ENCODINGS] = {
@@ -70,81 +70,81 @@ static char capabilities[NUM_CHANNELS][NUM_ENCODINGS][NUM_RATES];
 
 void audio_capabilities(struct audio_info_struct *ai)
 {
-	int fmts;
-	int i,j,k,k1=NUM_RATES-1;
-	struct audio_info_struct ai1 = *ai;
+        int fmts;
+        int i,j,k,k1=NUM_RATES-1;
+        struct audio_info_struct ai1 = *ai;
 
         if (param.outmode != DECODE_AUDIO) {
-		memset(capabilities,1,sizeof(capabilities));
-		return;
-	}
-
-	memset(capabilities,0,sizeof(capabilities));
-	if(param.force_rate) {
-		rates[NUM_RATES-1] = param.force_rate;
-		k1 = NUM_RATES;
-	}
-
-	if(audio_open(&ai1) < 0) {
-		perror("audio");
-		exit(1);
-	}
-
-	for(i=0;i<NUM_CHANNELS;i++) {
-		for(j=0;j<NUM_RATES;j++) {
-			ai1.channels = channels[i];
-			ai1.rate = rates[j];
-			fmts = audio_get_formats(&ai1);
-			if(fmts < 0)
-				continue;
-			for(k=0;k<NUM_ENCODINGS;k++) {
-				if((fmts & encodings[k]) == encodings[k])
-					capabilities[i][k][j] = 1;
-			}
-		}
-	}
-
-	audio_close(&ai1);
-
-	if(param.verbose > 1) {
-		fprintf(stderr,"\nAudio capabilities:\n        |");
-		for(j=0;j<NUM_ENCODINGS;j++) {
-			fprintf(stderr," %5s |",audio_val2name[j].sname);
-		}
-		fprintf(stderr,"\n --------------------------------------------------------\n");
-		for(k=0;k<k1;k++) {
-			fprintf(stderr," %5d  |",rates[k]);
-			for(j=0;j<NUM_ENCODINGS;j++) {
-				if(capabilities[0][j][k]) {
-					if(capabilities[1][j][k])
-						fprintf(stderr,"  M/S  |");
-					else
-						fprintf(stderr,"   M   |");
-				}
-				else if(capabilities[1][j][k])
-					fprintf(stderr,"   S   |");
-				else
-					fprintf(stderr,"       |");
-			}
-			fprintf(stderr,"\n");
-		}
-		fprintf(stderr,"\n");
-	}
+                memset(capabilities,1,sizeof(capabilities));
+                return;
+        }
+
+        memset(capabilities,0,sizeof(capabilities));
+        if(param.force_rate) {
+                rates[NUM_RATES-1] = param.force_rate;
+                k1 = NUM_RATES;
+        }
+
+        if(audio_open(&ai1) < 0) {
+                perror("audio");
+                exit(1);
+        }
+
+        for(i=0;i<NUM_CHANNELS;i++) {
+                for(j=0;j<NUM_RATES;j++) {
+                        ai1.channels = channels[i];
+                        ai1.rate = rates[j];
+                        fmts = audio_get_formats(&ai1);
+                        if(fmts < 0)
+                                continue;
+                        for(k=0;k<NUM_ENCODINGS;k++) {
+                                if((fmts & encodings[k]) == encodings[k])
+                                        capabilities[i][k][j] = 1;
+                        }
+                }
+        }
+
+        audio_close(&ai1);
+
+        if(param.verbose > 1) {
+                fprintf(stderr,"\nAudio capabilities:\n        |");
+                for(j=0;j<NUM_ENCODINGS;j++) {
+                        fprintf(stderr," %5s |",audio_val2name[j].sname);
+                }
+                fprintf(stderr,"\n --------------------------------------------------------\n");
+                for(k=0;k<k1;k++) {
+                        fprintf(stderr," %5d  |",rates[k]);
+                        for(j=0;j<NUM_ENCODINGS;j++) {
+                                if(capabilities[0][j][k]) {
+                                        if(capabilities[1][j][k])
+                                                fprintf(stderr,"  M/S  |");
+                                        else
+                                                fprintf(stderr,"   M   |");
+                                }
+                                else if(capabilities[1][j][k])
+                                        fprintf(stderr,"   S   |");
+                                else
+                                        fprintf(stderr,"       |");
+                        }
+                        fprintf(stderr,"\n");
+                }
+                fprintf(stderr,"\n");
+        }
 }
 
 static int rate2num(int r)
 {
-	int i;
-	for(i=0;i<NUM_RATES;i++) 
-		if(rates[i] == r)
-			return i;
-	return -1;
+        int i;
+        for(i=0;i<NUM_RATES;i++) 
+                if(rates[i] == r)
+                        return i;
+        return -1;
 }
 
 
 static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f2,int c)
 {
-	int i;
+        int i;
 
         if(rn >= 0) {
                 for(i=f0;i<f2;i++) {
@@ -152,11 +152,11 @@ static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f
                                 ai->rate = rates[rn];
                                 ai->format = encodings[i];
                                 ai->channels = channels[c];
-				return 1;
+                                return 1;
                         }
                 }
         }
-	return 0;
+        return 0;
 
 }
 
@@ -166,64 +166,64 @@ static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f
  */
 void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
 {
-	int rn;
-	int f0=0;
-	
-	if(param.force_8bit) {
-		f0 = 2;
-	}
-
-	c--; /* stereo=1 ,mono=0 */
-
-	if(param.force_mono >= 0)
-		c = 0;
-	if(param.force_stereo)
-		c = 1;
-
-	if(param.force_rate) {
-		rn = rate2num(param.force_rate);
-		if(audio_fit_cap_helper(ai,rn,f0,2,c))
-			return;
-		if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-			return;
-
-		if(c == 1 && !param.force_stereo)
-			c = 0;
-		else if(c == 0 && !param.force_mono)
-			c = 1;
-
-		if(audio_fit_cap_helper(ai,rn,f0,2,c))
-			return;
-		if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-			return;
-
-		fprintf(stderr,"No supported rate found!\n");
-		exit(1);
-	}
-
-	rn = rate2num(r>>0);
-	if(audio_fit_cap_helper(ai,rn,f0,2,c))
-		return;
-	rn = rate2num(r>>1);
-	if(audio_fit_cap_helper(ai,rn,f0,2,c))
-		return;
-	rn = rate2num(r>>2);
-	if(audio_fit_cap_helper(ai,rn,f0,2,c))
-		return;
-
-	rn = rate2num(r>>0);
-	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-		return;
-	rn = rate2num(r>>1);
-	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-		return;
-	rn = rate2num(r>>2);
-	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-		return;
+        int rn;
+        int f0=0;
+
+        if(param.force_8bit) {
+                f0 = 2;
+        }
+
+        c--; /* stereo=1 ,mono=0 */
+
+        if(param.force_mono >= 0)
+                c = 0;
+        if(param.force_stereo)
+                c = 1;
+
+        if(param.force_rate) {
+                rn = rate2num(param.force_rate);
+                if(audio_fit_cap_helper(ai,rn,f0,2,c))
+                        return;
+                if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+                        return;
+
+                if(c == 1 && !param.force_stereo)
+                        c = 0;
+                else if(c == 0 && !param.force_mono)
+                        c = 1;
+
+                if(audio_fit_cap_helper(ai,rn,f0,2,c))
+                        return;
+                if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+                        return;
+
+                fprintf(stderr,"No supported rate found!\n");
+                exit(1);
+        }
+
+        rn = rate2num(r>>0);
+        if(audio_fit_cap_helper(ai,rn,f0,2,c))
+                return;
+        rn = rate2num(r>>1);
+        if(audio_fit_cap_helper(ai,rn,f0,2,c))
+                return;
+        rn = rate2num(r>>2);
+        if(audio_fit_cap_helper(ai,rn,f0,2,c))
+                return;
+
+        rn = rate2num(r>>0);
+        if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+                return;
+        rn = rate2num(r>>1);
+        if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+                return;
+        rn = rate2num(r>>2);
+        if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+                return;
 
 
         if(c == 1 && !param.force_stereo)
-		c = 0;
+                c = 0;
         else if(c == 0 && !param.force_mono)
                 c = 1;
 
@@ -247,19 +247,19 @@ void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
                 return;
 
-	fprintf(stderr,"No supported rate found!\n");
-	exit(1);
+        fprintf(stderr,"No supported rate found!\n");
+        exit(1);
 }
 
 char *audio_encoding_name(int format)
 {
-	int i;
+        int i;
 
-	for(i=0;i<NUM_ENCODINGS;i++) {
-		if(audio_val2name[i].val == format)
-			return audio_val2name[i].name;
-	}
-	return "Unknown";
+        for(i=0;i<NUM_ENCODINGS;i++) {
+                if(audio_val2name[i].val == format)
+                        return audio_val2name[i].name;
+        }
+        return "Unknown";
 }
 
 #if !defined(SOLARIS) && !defined(__NetBSD__) || defined(NAS)

+ 253 - 253
panda/src/mpg123/common.c

@@ -58,23 +58,23 @@ static int decode_header(struct frame *fr,unsigned long newhead);
 void audio_flush(int outmode, struct audio_info_struct *ai)
 {
     if (pcm_point) {
-	switch (outmode) {
-	case DECODE_FILE:
-	    write (OutputDescriptor, pcm_sample, pcm_point);
-	    break;
-	case DECODE_AUDIO:
-	    audio_play_samples (ai, pcm_sample, pcm_point);
-	    break;
-	case DECODE_BUFFER:
-	    write (buffer_fd[1], pcm_sample, pcm_point);
-	    break;
-	case DECODE_WAV:
-	case DECODE_CDR:
-	case DECODE_AU:
-	    wav_write(pcm_sample, pcm_point);
-	    break;
-	}
-	pcm_point = 0;
+        switch (outmode) {
+        case DECODE_FILE:
+            write (OutputDescriptor, pcm_sample, pcm_point);
+            break;
+        case DECODE_AUDIO:
+            audio_play_samples (ai, pcm_sample, pcm_point);
+            break;
+        case DECODE_BUFFER:
+            write (buffer_fd[1], pcm_sample, pcm_point);
+            break;
+        case DECODE_WAV:
+        case DECODE_CDR:
+        case DECODE_AU:
+            wav_write(pcm_sample, pcm_point);
+            break;
+        }
+        pcm_point = 0;
     }
 }
 
@@ -93,7 +93,7 @@ void (*catchsignal(int signum, void(*handler)()))()
     sigemptyset(&new_sa.sa_mask);
     new_sa.sa_flags = 0;
     if (sigaction(signum, &new_sa, &old_sa) == -1)
-	return ((void (*)()) -1);
+        return ((void (*)()) -1);
     return (old_sa.sa_handler);
 }
 #endif
@@ -108,17 +108,17 @@ int head_check(unsigned long head)
 {
 /* fprintf(stderr,"HC"); */
     if( (head & 0xffe00000) != 0xffe00000)
-	return FALSE;
+        return FALSE;
     if(!((head>>17)&3))
-	return FALSE;
+        return FALSE;
     if( ((head>>12)&0xf) == 0xf)
-	return FALSE;
+        return FALSE;
     if( ((head>>10)&0x3) == 0x3 )
-	return FALSE;
+        return FALSE;
 #if 0
     /* this would match on MPEG1/Layer1 streams with CRC = off */
     if ((head & 0xffff0000) == 0xffff0000)
-	return FALSE;
+        return FALSE;
 #endif
 
     return TRUE;
@@ -137,129 +137,129 @@ int read_frame(struct frame *fr)
     fsizeold=fr->framesize;       /* for Layer3 */
 
     if (param.halfspeed) {
-	static int halfphase = 0;
-	if (halfphase--) {
-	    bsi.bitindex = 0;
-	    bsi.wordpointer = (unsigned char *) bsbuf;
-	    if (fr->lay == 3)
-		memcpy (bsbuf, ssave, ssize);
-	    return 1;
-	}
-	else
-	    halfphase = param.halfspeed - 1;
+        static int halfphase = 0;
+        if (halfphase--) {
+            bsi.bitindex = 0;
+            bsi.wordpointer = (unsigned char *) bsbuf;
+            if (fr->lay == 3)
+                memcpy (bsbuf, ssave, ssize);
+            return 1;
+        }
+        else
+            halfphase = param.halfspeed - 1;
     }
 
  read_again:
     if(!rd->head_read(rd,&newhead))
-	return FALSE;
+        return FALSE;
 
     if(1 || oldhead != newhead || !oldhead) {
 
     init_resync:
 
-	fr->header_change = 2;
-	if(oldhead) {
-	    if((oldhead & 0xc00) == (newhead & 0xc00)) {
-		if( (oldhead & 0xc0) == 0 && (newhead & 0xc0) == 0)
-		    fr->header_change = 1; 
-		else if( (oldhead & 0xc0) > 0 && (newhead & 0xc0) > 0)
-		    fr->header_change = 1;
-	    }
-	}
+        fr->header_change = 2;
+        if(oldhead) {
+            if((oldhead & 0xc00) == (newhead & 0xc00)) {
+                if( (oldhead & 0xc0) == 0 && (newhead & 0xc0) == 0)
+                    fr->header_change = 1; 
+                else if( (oldhead & 0xc0) > 0 && (newhead & 0xc0) > 0)
+                    fr->header_change = 1;
+            }
+        }
 
 
 #ifdef SKIP_JUNK
-	if(!firsthead && !head_check(newhead) ) {
-	    int i;
-
-	    fprintf(stderr,"Junk at the beginning %08lx\n",newhead);
-
-	    /* I even saw RIFF headers at the beginning of MPEG streams ;( */
-	    if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F') {
-		if(!rd->head_read(rd,&newhead))
-		    return 0;
-		while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a') {
-		    if(!rd->head_shift(rd,&newhead))
-			return 0;
-		}
-		if(!rd->head_read(rd,&newhead))
-		    return 0;
-		/* fprintf(stderr,"Skipped RIFF header!\n"); */
-		goto read_again;
-	    }
-	    {
-		/* step in byte steps through next 64K */
-		for(i=0;i<65536;i++) {
-		    if(!rd->head_shift(rd,&newhead))
-			return 0;
-		    if(head_check(newhead))
-			break;
-		}
-		if(i == 65536) {
-		    fprintf(stderr,"Giving up searching valid MPEG header\n");
-		    return 0;
-		}
-	    }
-	    /* 
-	     * should we additionaly check, whether a new frame starts at
-	     * the next expected position? (some kind of read ahead)
-	     * We could implement this easily, at least for files.
-	     */
-	}
+        if(!firsthead && !head_check(newhead) ) {
+            int i;
+
+            fprintf(stderr,"Junk at the beginning %08lx\n",newhead);
+
+            /* I even saw RIFF headers at the beginning of MPEG streams ;( */
+            if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F') {
+                if(!rd->head_read(rd,&newhead))
+                    return 0;
+                while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a') {
+                    if(!rd->head_shift(rd,&newhead))
+                        return 0;
+                }
+                if(!rd->head_read(rd,&newhead))
+                    return 0;
+                /* fprintf(stderr,"Skipped RIFF header!\n"); */
+                goto read_again;
+            }
+            {
+                /* step in byte steps through next 64K */
+                for(i=0;i<65536;i++) {
+                    if(!rd->head_shift(rd,&newhead))
+                        return 0;
+                    if(head_check(newhead))
+                        break;
+                }
+                if(i == 65536) {
+                    fprintf(stderr,"Giving up searching valid MPEG header\n");
+                    return 0;
+                }
+            }
+            /* 
+             * should we additionaly check, whether a new frame starts at
+             * the next expected position? (some kind of read ahead)
+             * We could implement this easily, at least for files.
+             */
+        }
 #endif
 
-	if( (newhead & 0xffe00000) != 0xffe00000) {
-	    if (!param.quiet)
-		fprintf(stderr,"Illegal Audio-MPEG-Header 0x%08lx at offset 0x%lx.\n",
-			newhead,rd->tell(rd)-4);
-	    /* and those ugly ID3 tags */
-	    if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8)) {
-		rd->skip_bytes(rd,124);
-		fprintf(stderr,"Skipped ID3 Tag!\n");
-		goto read_again;
-	    }
-	    if (param.tryresync) {
-		int try = 0;
-		/* Read more bytes until we find something that looks
-		   reasonably like a valid header.  This is not a
-		   perfect strategy, but it should get us back on the
-		   track within a short time (and hopefully without
-		   too much distortion in the audio output).  */
-		do {
-		    try++;
-		    if(!rd->head_shift(rd,&newhead))
-			return 0;
-		    if (!oldhead)
-			goto init_resync;       /* "considered harmful", eh? */
-
-		} while ((newhead & HDRCMPMASK) != (oldhead & HDRCMPMASK)
-			 && (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK));
-		if (!param.quiet)
-		    fprintf (stderr, "Skipped %d bytes in input.\n", try);
-	    }
-	    else
-		return (0);
-	}
+        if( (newhead & 0xffe00000) != 0xffe00000) {
+            if (!param.quiet)
+                fprintf(stderr,"Illegal Audio-MPEG-Header 0x%08lx at offset 0x%lx.\n",
+                        newhead,rd->tell(rd)-4);
+            /* and those ugly ID3 tags */
+            if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8)) {
+                rd->skip_bytes(rd,124);
+                fprintf(stderr,"Skipped ID3 Tag!\n");
+                goto read_again;
+            }
+            if (param.tryresync) {
+                int try = 0;
+                /* Read more bytes until we find something that looks
+                   reasonably like a valid header.  This is not a
+                   perfect strategy, but it should get us back on the
+                   track within a short time (and hopefully without
+                   too much distortion in the audio output).  */
+                do {
+                    try++;
+                    if(!rd->head_shift(rd,&newhead))
+                        return 0;
+                    if (!oldhead)
+                        goto init_resync;       /* "considered harmful", eh? */
+
+                } while ((newhead & HDRCMPMASK) != (oldhead & HDRCMPMASK)
+                         && (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK));
+                if (!param.quiet)
+                    fprintf (stderr, "Skipped %d bytes in input.\n", try);
+            }
+            else
+                return (0);
+        }
 
 /* fprintf(stderr,"+"); */
 
-	if (!firsthead) {
-	    if(!decode_header(fr,newhead)) {
+        if (!firsthead) {
+            if(!decode_header(fr,newhead)) {
 /* fprintf(stderr,"A"); */
-		goto read_again;
-	    }
-	    firsthead = newhead;
+                goto read_again;
+            }
+            firsthead = newhead;
 
-	}
-	else if(!decode_header(fr,newhead)) {
+        }
+        else if(!decode_header(fr,newhead)) {
 /* fprintf(stderr,"B: %08lx\n",newhead); */
-	    return 0;
+            return 0;
         }
 
 /* fprintf(stderr,"-"); */
     }
     else
-	fr->header_change = 0;
+        fr->header_change = 0;
 
 /* fprintf(stderr,"FS: %d\n",fr->framesize); */
 
@@ -270,7 +270,7 @@ int read_frame(struct frame *fr)
 
     /* read main data into memory */
     if(!rd->read_frame_body(rd,bsbuf,fr->framesize))
-	return 0;
+        return 0;
 
     { 
       /* Test */
@@ -288,7 +288,7 @@ int read_frame(struct frame *fr)
     bsi.wordpointer = (unsigned char *) bsbuf;
 
     if (param.halfspeed && fr->lay == 3)
-	memcpy (ssave, bsbuf, ssize);
+        memcpy (ssave, bsbuf, ssize);
 
     return 1;
 }
@@ -303,28 +303,28 @@ int back_frame(struct reader *rds,struct frame *fr,int num)
     unsigned long newhead;
   
     if(!firsthead)
-	return 0;
+        return 0;
   
     bytes = (fr->framesize+8)*(num+2);
   
     if(rds->back_bytes(rds,bytes) < 0)
-	return -1;
+        return -1;
     if(!rds->head_read(rds,&newhead))
-	return -1;
+        return -1;
   
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
-	if(!rds->head_shift(rds,&newhead))
-	    return -1;
+        if(!rds->head_shift(rds,&newhead))
+            return -1;
     }
   
     if(rds->back_bytes(rds,4) <0)
-	return -1;
+        return -1;
 
     read_frame(fr);
     read_frame(fr);
   
     if(fr->lay == 3) {
-	set_pointer(512);
+        set_pointer(512);
     }
   
     return 0;
@@ -339,32 +339,32 @@ static int decode_header(struct frame *fr,unsigned long newhead)
 {
     if(!head_check(newhead)) {
         fprintf(stderr,"Oopps header is wrong\n");
-	return 0;
+        return 0;
     }
 
     if( newhead & (1<<20) ) {
-	fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
-	fr->mpeg25 = 0;
+        fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
+        fr->mpeg25 = 0;
     }
     else {
-	fr->lsf = 1;
-	fr->mpeg25 = 1;
+        fr->lsf = 1;
+        fr->mpeg25 = 1;
     }
     
     if (!param.tryresync || !oldhead) {
-	/* If "tryresync" is true, assume that certain
-	   parameters do not change within the stream! */
-	fr->lay = 4-((newhead>>17)&3);
-	if( ((newhead>>10)&0x3) == 0x3) {
-	    fprintf(stderr,"Stream error\n");
-	    exit(1);
-	}
-	if(fr->mpeg25) {
-	    fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
-	}
-	else
-	    fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
-	fr->error_protection = ((newhead>>16)&0x1)^0x1;
+        /* If "tryresync" is true, assume that certain
+           parameters do not change within the stream! */
+        fr->lay = 4-((newhead>>17)&3);
+        if( ((newhead>>10)&0x3) == 0x3) {
+            fprintf(stderr,"Stream error\n");
+            exit(1);
+        }
+        if(fr->mpeg25) {
+            fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
+        }
+        else
+            fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
+        fr->error_protection = ((newhead>>16)&0x1)^0x1;
     }
 
     fr->bitrate_index = ((newhead>>12)&0xf);
@@ -381,8 +381,8 @@ static int decode_header(struct frame *fr,unsigned long newhead)
     oldhead = newhead;
 
     if(!fr->bitrate_index) {
-	fprintf(stderr,"Free format not supported: (head %08lx)\n",newhead);
-	return (0);
+        fprintf(stderr,"Free format not supported: (head %08lx)\n",newhead);
+        return (0);
     }
 
     switch(fr->lay) {
@@ -398,11 +398,11 @@ static int decode_header(struct frame *fr,unsigned long newhead)
         break;
     case 3:
         if(fr->lsf)
-	    ssize = (fr->stereo == 1) ? 9 : 17;
+            ssize = (fr->stereo == 1) ? 9 : 17;
         else
-	    ssize = (fr->stereo == 1) ? 17 : 32;
+            ssize = (fr->stereo == 1) ? 17 : 32;
         if(fr->error_protection)
-	    ssize += 2;
+            ssize += 2;
         fr->framesize  = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
         fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
         fr->framesize = fr->framesize + fr->padding - 4;
@@ -423,10 +423,10 @@ void print_rheader(struct frame *fr)
 
     /* version, layer, freq, mode, channels, bitrate, BPF */
     fprintf(stderr,"@I %s %s %ld %s %d %d %d\n",
-	    mpeg_type[fr->lsf],layers[fr->lay],freqs[fr->sampling_frequency],
-	    modes[fr->mode],fr->stereo,
-	    tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
-	    fr->framesize+4);
+            mpeg_type[fr->lsf],layers[fr->lay],freqs[fr->sampling_frequency],
+            modes[fr->mode],fr->stereo,
+            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
+            fr->framesize+4);
 }
 #endif
 
@@ -436,15 +436,15 @@ void print_header(struct frame *fr)
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
 
     fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", 
-	    fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-	    layers[fr->lay],freqs[fr->sampling_frequency],
-	    modes[fr->mode],fr->mode_ext,fr->framesize+4);
+            fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+            layers[fr->lay],freqs[fr->sampling_frequency],
+            modes[fr->mode],fr->mode_ext,fr->framesize+4);
     fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
-	    fr->stereo,fr->copyright?"Yes":"No",
-	    fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
-	    fr->emphasis);
+            fr->stereo,fr->copyright?"Yes":"No",
+            fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
+            fr->emphasis);
     fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n",
-	    tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
+            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
 }
 
 void print_header_compact(struct frame *fr)
@@ -453,22 +453,22 @@ void print_header_compact(struct frame *fr)
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
  
     fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
-	    fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-	    layers[fr->lay],
-	    tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
-	    freqs[fr->sampling_frequency], modes[fr->mode]);
+            fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+            layers[fr->lay],
+            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
+            freqs[fr->sampling_frequency], modes[fr->mode]);
 }
 
 void print_id3_tag(unsigned char *buf)
 {
     struct id3tag {
-	char tag[3];
-	char title[30];
-	char artist[30];
-	char album[30];
-	char year[4];
-	char comment[30];
-	unsigned char genre;
+        char tag[3];
+        char title[30];
+        char artist[30];
+        char album[30];
+        char year[4];
+        char comment[30];
+        unsigned char genre;
     };
     struct id3tag *tag = (struct id3tag *) buf;
     char title[31]={0,};
@@ -479,7 +479,7 @@ void print_id3_tag(unsigned char *buf)
     char genre[31]={0,};
 
     if(param.quiet)
-	return;
+        return;
 
     strncpy(title,tag->title,30);
     strncpy(artist,tag->artist,30);
@@ -488,11 +488,11 @@ void print_id3_tag(unsigned char *buf)
     strncpy(comment,tag->comment,30);
 
     if ( tag->genre < sizeof(genre_table)/sizeof(*genre_table) ) {
-	strncpy(genre, genre_table[tag->genre], 30);
+        strncpy(genre, genre_table[tag->genre], 30);
     } else {
-	strncpy(genre,"Unknown",30);
+        strncpy(genre,"Unknown",30);
     }
-	
+
     fprintf(stderr,"Title  : %-30s  Artist: %s\n",title,artist);
     fprintf(stderr,"Album  : %-30s  Year  : %4s\n",album,year);
     fprintf(stderr,"Comment: %-30s  Genre : %s\n",comment,genre);
@@ -510,7 +510,7 @@ char *strndup (const char *src, int num)
     char *dst;
 
     if (!(dst = (char *) malloc(num+1)))
-	return (NULL);
+        return (NULL);
     dst[num] = '\0';
     return (strncpy(dst, src, num));
 }
@@ -533,36 +533,36 @@ int split_dir_file (const char *path, char **dname, char **fname)
     char *slashpos;
 
     if ((slashpos = strrchr(path, '/'))) {
-	*fname = slashpos + 1;
-	*dname = strdup(path); /* , 1 + slashpos - path); */
-	if(!(*dname)) {
-	    perror("memory");
-	    exit(1);
-	}
-	(*dname)[1 + slashpos - path] = 0;
-	if (lastdir && !strcmp(lastdir, *dname)) {
-	    /***   same as previous directory   ***/
-	    free (*dname);
-	    *dname = lastdir;
-	    return 0;
-	}
-	else {
-	    /***   different directory   ***/
-	    if (lastdir)
-		free (lastdir);
-	    lastdir = *dname;
-	    return 1;
-	}
+        *fname = slashpos + 1;
+        *dname = strdup(path); /* , 1 + slashpos - path); */
+        if(!(*dname)) {
+            perror("memory");
+            exit(1);
+        }
+        (*dname)[1 + slashpos - path] = 0;
+        if (lastdir && !strcmp(lastdir, *dname)) {
+            /***   same as previous directory   ***/
+            free (*dname);
+            *dname = lastdir;
+            return 0;
+        }
+        else {
+            /***   different directory   ***/
+            if (lastdir)
+                free (lastdir);
+            lastdir = *dname;
+            return 1;
+        }
     }
     else {
-	/***   no directory specified   ***/
-	if (lastdir) {
-	    free (lastdir);
-	    lastdir = NULL;
-	};
-	*dname = NULL;
-	*fname = (char *)path;
-	return 0;
+        /***   no directory specified   ***/
+        if (lastdir) {
+            free (lastdir);
+            lastdir = NULL;
+        };
+        *dname = NULL;
+        *fname = (char *)path;
+        return 0;
     }
 }
 
@@ -570,7 +570,7 @@ void set_pointer(long backstep)
 {
     bsi.wordpointer = bsbuf + ssize - backstep;
     if (backstep)
-	memcpy(bsi.wordpointer,bsbufold+fsizeold-backstep,backstep);
+        memcpy(bsi.wordpointer,bsbufold+fsizeold-backstep,backstep);
     bsi.bitindex = 0; 
 }
 
@@ -582,18 +582,18 @@ double compute_bpf(struct frame *fr)
 
     switch(fr->lay) {
     case 1:
-	bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
-	bpf *= 12000.0 * 4.0;
-	bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
-	break;
+        bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
+        bpf *= 12000.0 * 4.0;
+        bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
+        break;
     case 2:
     case 3:
-	bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
+        bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
         bpf *= 144000;
-	bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
-	break;
+        bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
+        break;
     default:
-	bpf = 1.0;
+        bpf = 1.0;
     }
 
     return bpf;
@@ -617,24 +617,24 @@ double compute_tpf(struct frame *fr)
 long compute_buffer_offset(struct frame *fr)
 {
     long bufsize;
-	
+
     /*
      * buffermem->buf[0] holds output sampling rate,
      * buffermem->buf[1] holds number of channels,
      * buffermem->buf[2] holds audio format of output.
      */
-	
+
     if(!param.usebuffer || !(bufsize=xfermem_get_usedspace(buffermem))
        || !buffermem->buf[0] || !buffermem->buf[1])
-	return 0;
+        return 0;
 
     bufsize = (long)((double) bufsize / buffermem->buf[0] / 
-		     buffermem->buf[1] / compute_tpf(fr));
-	
+                     buffermem->buf[1] / compute_tpf(fr));
+
     if((buffermem->buf[2] & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
-	return bufsize/2;
+        return bufsize/2;
     else
-	return bufsize;
+        return bufsize;
 }
 
 void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *ai)
@@ -645,23 +645,23 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     char outbuf[256];
 
     if(!rd || !fr) 
-	return;
+        return;
 
     outbuf[0] = 0;
 
 #ifndef GENERIC
     {
-	struct timeval t;
-	fd_set serr;
-	int n,errfd = fileno(stderr);
+        struct timeval t;
+        fd_set serr;
+        int n,errfd = fileno(stderr);
 
-	t.tv_sec=t.tv_usec=0;
+        t.tv_sec=t.tv_usec=0;
 
-	FD_ZERO(&serr);
-	FD_SET(errfd,&serr);
-	n = select(errfd+1,NULL,&serr,NULL,&t);
-	if(n <= 0)
-	    return;
+        FD_ZERO(&serr);
+        FD_SET(errfd,&serr);
+        n = select(errfd+1,NULL,&serr,NULL,&t);
+        if(n <= 0)
+            return;
     }
 #endif
 
@@ -669,17 +669,17 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     tpf = compute_tpf(fr);
 
     if(buffsize > 0 && ai && ai->rate > 0 && ai->channels > 0) {
-	dt = (double) buffsize / ai->rate / ai->channels;
-	if( (ai->format & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
-	    dt *= 0.5;
+        dt = (double) buffsize / ai->rate / ai->channels;
+        if( (ai->format & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
+            dt *= 0.5;
     }
 
     rno = 0;
     sno = no;
     if(rd->filelen >= 0) {
-	long t = rd->tell(rd);
-	rno = (int)((double)(rd->filelen-t)/bpf);
-	sno = (int)((double)t/bpf);
+        long t = rd->tell(rd);
+        rno = (int)((double)(rd->filelen-t)/bpf);
+        sno = (int)((double)t/bpf);
     }
 
     sprintf(outbuf+strlen(outbuf),"\rFrame# %5d [%5d], ",sno,rno);
@@ -692,15 +692,15 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     tim2 = tim2 < 0 ? 0.0 : tim2;
 
     sprintf(outbuf+strlen(outbuf),"Time: %02u:%02u.%02u [%02u:%02u.%02u], ",
-	    (unsigned int)tim1/60,
-	    (unsigned int)tim1%60,
-	    (unsigned int)(tim1*100)%100,
-	    (unsigned int)tim2/60,
-	    (unsigned int)tim2%60,
-	    (unsigned int)(tim2*100)%100);
+            (unsigned int)tim1/60,
+            (unsigned int)tim1%60,
+            (unsigned int)(tim1*100)%100,
+            (unsigned int)tim2/60,
+            (unsigned int)tim2%60,
+            (unsigned int)(tim2*100)%100);
 
     if(param.usebuffer)
-	sprintf(outbuf+strlen(outbuf),"[%8ld] ",(long)buffsize);
+        sprintf(outbuf+strlen(outbuf),"[%8ld] ",(long)buffsize);
     write(fileno(stderr),outbuf,strlen(outbuf));
 #if 0
     fflush(out); /* hmm not really nec. */
@@ -710,14 +710,14 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
 int get_songlen(struct frame *fr,int no)
 {
     double tpf;
-	
+
     if(!fr)
-	return 0;
-	
+        return 0;
+
     if(no < 0) {
-	if(!rd || rd->filelen < 0)
-	    return 0;
-	no = (double) rd->filelen / compute_bpf(fr);
+        if(!rd || rd->filelen < 0)
+            return 0;
+        no = (double) rd->filelen / compute_bpf(fr);
     }
 
     tpf = compute_tpf(fr);

+ 1 - 1
panda/src/mpg123/decode.c

@@ -125,7 +125,7 @@ int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
   int bo1;
 
   if(param.enable_equalizer)
-	do_equalizer(bandPtr,channel);
+        do_equalizer(bandPtr,channel);
 
   if(!channel) {
     bo--;

+ 14 - 14
panda/src/mpg123/decode_ntom.c

@@ -25,23 +25,23 @@ static unsigned long ntom_step = NTOM_MUL;
 
 void synth_ntom_set_step(long m,long n)
 {
-	if(param.verbose > 1)
-		fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
+        if(param.verbose > 1)
+                fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
 
-	if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
-		fprintf(stderr,"NtoM converter: illegal rates\n");
-		exit(1);
-	}
+        if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
+                fprintf(stderr,"NtoM converter: illegal rates\n");
+                exit(1);
+        }
 
-	n *= NTOM_MUL;
-	ntom_step = n / m;
+        n *= NTOM_MUL;
+        ntom_step = n / m;
 
-	if(ntom_step > 8*NTOM_MUL) {
-		fprintf(stderr,"max. 1:8 conversion allowed!\n");
-		exit(1);
-	}
+        if(ntom_step > 8*NTOM_MUL) {
+                fprintf(stderr,"max. 1:8 conversion allowed!\n");
+                exit(1);
+        }
 
-	ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
+        ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
 }
 
 int synth_ntom_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
@@ -154,7 +154,7 @@ int synth_ntom(real *bandPtr,int channel,unsigned char *out,int *pnt)
   int ntom;
 
   if(param.enable_equalizer)
-	do_equalizer(bandPtr,channel);
+        do_equalizer(bandPtr,channel);
 
   if(!channel) {
     bo--;

+ 12 - 12
panda/src/mpg123/equalizer.c

@@ -9,18 +9,18 @@ real equalizerband[2][SBLIMIT*SSLIMIT];
 
 void do_equalizer(real *bandPtr,int channel) 
 {
-	int i;
-
-	if(param.enable_equalizer) {
-		for(i=0;i<32;i++)
-			bandPtr[i] *= equalizer[channel][i];
-	}
-
-/*	if(param.equalizer & 0x2) {
-		
-		for(i=0;i<32;i++)
-			equalizer_sum[channel][i] += bandPtr[i];
-	}
+        int i;
+
+        if(param.enable_equalizer) {
+                for(i=0;i<32;i++)
+                        bandPtr[i] *= equalizer[channel][i];
+        }
+
+/*      if(param.equalizer & 0x2) {
+
+                for(i=0;i<32;i++)
+                        equalizer_sum[channel][i] += bandPtr[i];
+        }
 */
 }
 

+ 4 - 4
panda/src/mpg123/getbits.c

@@ -4,11 +4,11 @@
 #if 0
 static void check_buffer_range(int size)
 {
-	int pos = (bsi->wordpointer-bsbuf) + (size>>3);
+        int pos = (bsi->wordpointer-bsbuf) + (size>>3);
 
-	if( pos >= fsizeold) {
-		fprintf(stderr,"Pointer out of range (%d,%d)!\n",pos,fsizeold);
-	}
+        if( pos >= fsizeold) {
+                fprintf(stderr,"Pointer out of range (%d,%d)!\n",pos,fsizeold);
+        }
 }
 #endif
 

+ 268 - 268
panda/src/mpg123/httpget.c

@@ -31,51 +31,51 @@ extern int errno;
 
 void writestring (int fd, char *string)
 {
-	int result, bytes = strlen(string);
-
-	while (bytes) {
-		if ((result = write(fd, string, bytes)) < 0 && errno != EINTR) {
-			perror ("write");
-			exit (1);
-		}
-		else if (result == 0) {
-			fprintf (stderr, "write: %s\n",
-				"socket closed unexpectedly");
-			exit (1);
-		}
-		string += result;
-		bytes -= result;
-	}
+        int result, bytes = strlen(string);
+
+        while (bytes) {
+                if ((result = write(fd, string, bytes)) < 0 && errno != EINTR) {
+                        perror ("write");
+                        exit (1);
+                }
+                else if (result == 0) {
+                        fprintf (stderr, "write: %s\n",
+                                "socket closed unexpectedly");
+                        exit (1);
+                }
+                string += result;
+                bytes -= result;
+        }
 }
 
 void readstring (char *string, int maxlen, FILE *f)
 {
 #if 0
-	char *result;
+        char *result;
 #endif
-	int pos = 0;
-
-	while(1) {
-		if( read(fileno(f),string+pos,1) == 1) {
-			pos++;
-			if(string[pos-1] == '\n') {
-				string[pos] = 0;
-				break;
-			}
-		}
-		else if(errno != EINTR) {
-			fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
-			exit(1);
-		}
-	}
+        int pos = 0;
+
+        while(1) {
+                if( read(fileno(f),string+pos,1) == 1) {
+                        pos++;
+                        if(string[pos-1] == '\n') {
+                                string[pos] = 0;
+                                break;
+                        }
+                }
+                else if(errno != EINTR) {
+                        fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
+                        exit(1);
+                }
+        }
 #if 0
-	do {
-		result = fgets(string, maxlen, f);
-	} while (!result  && errno == EINTR);
-	if (!result) {
-		fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
-		exit (1);
-	}
+        do {
+                result = fgets(string, maxlen, f);
+        } while (!result  && errno == EINTR);
+        if (!result) {
+                fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
+                exit (1);
+        }
 #endif
 
 }
@@ -138,73 +138,73 @@ static char *defaultportstr = "80";
 
 char *url2hostport (char *url, char **hname, unsigned long *hip, unsigned char **port)
 {
-	char *h, *p;
-	char *hostptr;
-	char *r_hostptr;
-	char *pathptr;
-	char *portptr;
-	char *p0;
-	size_t stringlength;
-
-	p = url;
-	if (strncmp(p, "http://", 7) == 0)
-		p += 7;
-	hostptr = p;
-	while (*p && *p != '/')
-		p++;
-	pathptr = p;
-
-	r_hostptr = --p;
-	while (*p && hostptr < p && *p != ':' && *p != ']')
-		p--;
-
-	if (!*p || p < hostptr || *p != ':') {
-		portptr = NULL;
-	}
-	else{
-		portptr = p + 1;
-		r_hostptr = p - 1;
-	}
-	if (*hostptr == '[' && *r_hostptr == ']') {
-		hostptr++;
-		r_hostptr--;
-	}
-
-	stringlength = r_hostptr - hostptr + 1;
-	h = malloc(stringlength + 1); /* removed the strndup for better portability */
-	if (h == NULL) {
-		*hname = NULL;
-		*port = NULL;
-		return NULL;
-	}
-	strncpy(h, hostptr, stringlength);
-	*(h+stringlength) = '\0';
-	*hname = h;
-
-	if (portptr) {
-		stringlength = (pathptr - portptr);
-		if(!stringlength) portptr = NULL;
-	}
-	if (portptr == NULL) {
-		portptr = defaultportstr;
-		stringlength = strlen(defaultportstr);
-	}
-	p0 = malloc(stringlength + 1);
-	if (p0 == NULL) {
-		free(h);
-		*hname = NULL;
-		*port = NULL;
-		return NULL;
-	}
-	strncpy(p0, portptr, stringlength);
-	*(p0 + stringlength) = '\0';
-
-	for (p = p0; *p && isdigit((unsigned char) *p); p++) ;
-
-	*p = '\0';
-	*port = (unsigned char *) p0;
-
-	return pathptr;
+        char *h, *p;
+        char *hostptr;
+        char *r_hostptr;
+        char *pathptr;
+        char *portptr;
+        char *p0;
+        size_t stringlength;
+
+        p = url;
+        if (strncmp(p, "http://", 7) == 0)
+                p += 7;
+        hostptr = p;
+        while (*p && *p != '/')
+                p++;
+        pathptr = p;
+
+        r_hostptr = --p;
+        while (*p && hostptr < p && *p != ':' && *p != ']')
+                p--;
+
+        if (!*p || p < hostptr || *p != ':') {
+                portptr = NULL;
+        }
+        else{
+                portptr = p + 1;
+                r_hostptr = p - 1;
+        }
+        if (*hostptr == '[' && *r_hostptr == ']') {
+                hostptr++;
+                r_hostptr--;
+        }
+
+        stringlength = r_hostptr - hostptr + 1;
+        h = malloc(stringlength + 1); /* removed the strndup for better portability */
+        if (h == NULL) {
+                *hname = NULL;
+                *port = NULL;
+                return NULL;
+        }
+        strncpy(h, hostptr, stringlength);
+        *(h+stringlength) = '\0';
+        *hname = h;
+
+        if (portptr) {
+                stringlength = (pathptr - portptr);
+                if(!stringlength) portptr = NULL;
+        }
+        if (portptr == NULL) {
+                portptr = defaultportstr;
+                stringlength = strlen(defaultportstr);
+        }
+        p0 = malloc(stringlength + 1);
+        if (p0 == NULL) {
+                free(h);
+                *hname = NULL;
+                *port = NULL;
+                return NULL;
+        }
+        strncpy(p0, portptr, stringlength);
+        *(p0 + stringlength) = '\0';
+
+        for (p = p0; *p && isdigit((unsigned char) *p); p++) ;
+
+        *p = '\0';
+        *port = (unsigned char *) p0;
+
+        return pathptr;
 }
 
 char *proxyurl = NULL;
@@ -218,190 +218,190 @@ char httpauth1[256];
 
 int http_open (char *url)
 {
-	char *purl, *host, *request, *sptr;
-	int linelength;
-	unsigned long myip;
-	unsigned char *myport;
-	int sock;
-	int relocate, numrelocs = 0;
-	FILE *myfile;
+        char *purl, *host, *request, *sptr;
+        int linelength;
+        unsigned long myip;
+        unsigned char *myport;
+        int sock;
+        int relocate, numrelocs = 0;
+        FILE *myfile;
 #ifdef INET6
-	struct addrinfo hints, *res, *res0;
-	int error;
+        struct addrinfo hints, *res, *res0;
+        int error;
 #else
-	struct hostent *hp;
-	struct sockaddr_in sin;
+        struct hostent *hp;
+        struct sockaddr_in sin;
 #endif
 
-	host = NULL;
-	proxyport = NULL;
-	myport = NULL;
-	if (!proxyip) {
-		if (!proxyurl)
-			if (!(proxyurl = getenv("MP3_HTTP_PROXY")))
-				if (!(proxyurl = getenv("http_proxy")))
-					proxyurl = getenv("HTTP_PROXY");
-		if (proxyurl && proxyurl[0] && strcmp(proxyurl, "none")) {
-			if (!(url2hostport(proxyurl, &host, &proxyip, &proxyport))) {
-				fprintf (stderr, "Unknown proxy host \"%s\".\n",
-					host ? host : "");
-				exit (1);
-			}
+        host = NULL;
+        proxyport = NULL;
+        myport = NULL;
+        if (!proxyip) {
+                if (!proxyurl)
+                        if (!(proxyurl = getenv("MP3_HTTP_PROXY")))
+                                if (!(proxyurl = getenv("http_proxy")))
+                                        proxyurl = getenv("HTTP_PROXY");
+                if (proxyurl && proxyurl[0] && strcmp(proxyurl, "none")) {
+                        if (!(url2hostport(proxyurl, &host, &proxyip, &proxyport))) {
+                                fprintf (stderr, "Unknown proxy host \"%s\".\n",
+                                        host ? host : "");
+                                exit (1);
+                        }
 #if 0
-			if (host)
-				free (host);
+                        if (host)
+                                free (host);
 #endif
-		}
-		else
-			proxyip = INADDR_NONE;
-	}
-	
-	if ((linelength = strlen(url)+200) < 1024)
-		linelength = 1024;
-	if (!(request = malloc(linelength)) || !(purl = malloc(1024))) {
-		fprintf (stderr, "malloc() failed, out of memory.\n");
-		exit (1);
-	}
-	strncpy (purl, url, 1023);
-	purl[1023] = '\0';
+                }
+                else
+                        proxyip = INADDR_NONE;
+        }
+
+        if ((linelength = strlen(url)+200) < 1024)
+                linelength = 1024;
+        if (!(request = malloc(linelength)) || !(purl = malloc(1024))) {
+                fprintf (stderr, "malloc() failed, out of memory.\n");
+                exit (1);
+        }
+        strncpy (purl, url, 1023);
+        purl[1023] = '\0';
 
         getauthfromURL(purl,httpauth1);
 
-	do {
-		strcpy (request, "GET ");
-		if (proxyip != INADDR_NONE) {
-			if (strncmp(url, "http://", 7))
-				strcat (request, "http://");
-			strcat (request, purl);
-			myport = proxyport;
-			myip = proxyip;
-		}
-		else {
-			if (host) {
-				free(host);
-				host=NULL;
-			}
-			if (proxyport) {
-				free(proxyport);
-				proxyport=NULL;
-			}
-			if (!(sptr = url2hostport(purl, &host, &myip, &myport))) {
-				fprintf (stderr, "Unknown host \"%s\".\n",
-					host ? host : "");
-				exit (1);
-			}
-			strcat (request, sptr);
-		}
-		sprintf (request + strlen(request),
-			" HTTP/1.0\r\nUser-Agent: %s/%s\r\n",
-			prgName, prgVersion);
-		if (host) {
-			sprintf(request + strlen(request),
-				"Host: %s:%s\r\n", host, myport);
+        do {
+                strcpy (request, "GET ");
+                if (proxyip != INADDR_NONE) {
+                        if (strncmp(url, "http://", 7))
+                                strcat (request, "http://");
+                        strcat (request, purl);
+                        myport = proxyport;
+                        myip = proxyip;
+                }
+                else {
+                        if (host) {
+                                free(host);
+                                host=NULL;
+                        }
+                        if (proxyport) {
+                                free(proxyport);
+                                proxyport=NULL;
+                        }
+                        if (!(sptr = url2hostport(purl, &host, &myip, &myport))) {
+                                fprintf (stderr, "Unknown host \"%s\".\n",
+                                        host ? host : "");
+                                exit (1);
+                        }
+                        strcat (request, sptr);
+                }
+                sprintf (request + strlen(request),
+                        " HTTP/1.0\r\nUser-Agent: %s/%s\r\n",
+                        prgName, prgVersion);
+                if (host) {
+                        sprintf(request + strlen(request),
+                                "Host: %s:%s\r\n", host, myport);
 #if 0
-			free (host);
+                        free (host);
 #endif
-		}
-		strcat (request, ACCEPT_HEAD);
+                }
+                strcat (request, ACCEPT_HEAD);
 
 #ifdef INET6
-		memset(&hints, 0, sizeof(hints));
-		hints.ai_socktype = SOCK_STREAM;
-		error = getaddrinfo(host, (char *)myport, &hints, &res0);
-		if (error) {
-			fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
-			exit(1);
-		}
-
-		sock = -1;
-		for (res = res0; res; res = res->ai_next) {
-			if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
-				continue;
-			}
-			if (connect(sock, res->ai_addr, res->ai_addrlen)) {
-				close(sock);
-				sock = -1;
-				continue;
-			}
-			break;
-		}
-
-		freeaddrinfo(res0);
+                memset(&hints, 0, sizeof(hints));
+                hints.ai_socktype = SOCK_STREAM;
+                error = getaddrinfo(host, (char *)myport, &hints, &res0);
+                if (error) {
+                        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
+                        exit(1);
+                }
+
+                sock = -1;
+                for (res = res0; res; res = res->ai_next) {
+                        if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
+                                continue;
+                        }
+                        if (connect(sock, res->ai_addr, res->ai_addrlen)) {
+                                close(sock);
+                                sock = -1;
+                                continue;
+                        }
+                        break;
+                }
+
+                freeaddrinfo(res0);
 #else
-		sock = -1;
-		hp = gethostbyname(host);
-		if (!hp)
-			goto fail;
-		if (hp->h_length != sizeof(sin.sin_addr))
-			goto fail;
-		sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-		if (sock < 0)
-			goto fail;
-		memset(&sin, 0, sizeof(sin));
-		sin.sin_family = AF_INET;
-		/* sin.sin_len = sizeof(struct sockaddr_in); */
-		memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
-		if (connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) ) < 0) {
-			close(sock);
-			sock = -1;
-		}
+                sock = -1;
+                hp = gethostbyname(host);
+                if (!hp)
+                        goto fail;
+                if (hp->h_length != sizeof(sin.sin_addr))
+                        goto fail;
+                sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+                if (sock < 0)
+                        goto fail;
+                memset(&sin, 0, sizeof(sin));
+                sin.sin_family = AF_INET;
+                /* sin.sin_len = sizeof(struct sockaddr_in); */
+                memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
+                if (connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) ) < 0) {
+                        close(sock);
+                        sock = -1;
+                }
 fail:
 #endif
 
-		if (sock < 0) {
-			perror("socket");
-			exit(1);
-		}
+                if (sock < 0) {
+                        perror("socket");
+                        exit(1);
+                }
 
-		if (strlen(httpauth1) || httpauth) {
-			char buf[1023];
-			strcat (request,"Authorization: Basic ");
+                if (strlen(httpauth1) || httpauth) {
+                        char buf[1023];
+                        strcat (request,"Authorization: Basic ");
                         if(strlen(httpauth1))
                           encode64(httpauth1,buf);
                         else
-			  encode64(httpauth,buf);
-			strcat (request,buf);
-			strcat (request,"\r\n");
-		}
-		strcat (request, "\r\n");
-
-		writestring (sock, request);
-		if (!(myfile = fdopen(sock, "rb"))) {
-			perror ("fdopen");
-			exit (1);
-		};
-		relocate = FALSE;
-		purl[0] = '\0';
-		readstring (request, linelength-1, myfile);
-		if ((sptr = strchr(request, ' '))) {
-			switch (sptr[1]) {
-				case '3':
-					relocate = TRUE;
-				case '2':
-					break;
-				default:
-					fprintf (stderr, "HTTP request failed: %s",
-						sptr+1); /* '\n' is included */
-					exit (1);
-			}
-		}
-		do {
-			readstring (request, linelength-1, myfile);
-			if (!strncmp(request, "Location:", 9))
-				strncpy (purl, request+10, 1023);
-		} while (request[0] != '\r' && request[0] != '\n');
-	} while (relocate && purl[0] && numrelocs++ < 5);
-	if (relocate) {
-		fprintf (stderr, "Too many HTTP relocations.\n");
-		exit (1);
-	}
-	free (purl);
-	free (request);
-	free(host);
-	free(proxyport);
-	free(myport);
-
-	return sock;
+                          encode64(httpauth,buf);
+                        strcat (request,buf);
+                        strcat (request,"\r\n");
+                }
+                strcat (request, "\r\n");
+
+                writestring (sock, request);
+                if (!(myfile = fdopen(sock, "rb"))) {
+                        perror ("fdopen");
+                        exit (1);
+                };
+                relocate = FALSE;
+                purl[0] = '\0';
+                readstring (request, linelength-1, myfile);
+                if ((sptr = strchr(request, ' '))) {
+                        switch (sptr[1]) {
+                                case '3':
+                                        relocate = TRUE;
+                                case '2':
+                                        break;
+                                default:
+                                        fprintf (stderr, "HTTP request failed: %s",
+                                                sptr+1); /* '\n' is included */
+                                        exit (1);
+                        }
+                }
+                do {
+                        readstring (request, linelength-1, myfile);
+                        if (!strncmp(request, "Location:", 9))
+                                strncpy (purl, request+10, 1023);
+                } while (request[0] != '\r' && request[0] != '\n');
+        } while (relocate && purl[0] && numrelocs++ < 5);
+        if (relocate) {
+                fprintf (stderr, "Too many HTTP relocations.\n");
+                exit (1);
+        }
+        free (purl);
+        free (request);
+        free(host);
+        free(proxyport);
+        free(myport);
+
+        return sock;
 }
 
 #else

+ 1 - 1
panda/src/mpg123/layer1.c

@@ -53,7 +53,7 @@ void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],stru
 }
 
 void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
-	unsigned int scale_index[2][SBLIMIT],struct frame *fr)
+        unsigned int scale_index[2][SBLIMIT],struct frame *fr)
 {
   int i,n;
   int smpb[2*SBLIMIT]; /* values: 0-65535 */

+ 3 - 3
panda/src/mpg123/layer2.c

@@ -14,7 +14,7 @@ static int grp_3tab[32 * 3] = { 0, };   /* used: 27 */
 static int grp_5tab[128 * 3] = { 0, };  /* used: 125 */
 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
 
-real muls[27][64];	/* also used by layer 1 */
+real muls[27][64];      /* also used by layer 1 */
 
 void init_layer2(void)
 {
@@ -55,7 +55,7 @@ void init_layer2(void)
 #ifdef USE_MMX
     if(!param.down_sample) 
         for(j=3,i=0;i<63;i++,j--)
-	  *table++ = 16384 * m * pow(2.0,(double) j / 3.0);
+          *table++ = 16384 * m * pow(2.0,(double) j / 3.0);
     else
 #endif
     for(j=3,i=0;i<63;i++,j--)
@@ -183,7 +183,7 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
     for (i=jsbound;i<sblimit;i++,alloc1+=(1<<step))
     {
       step = alloc1->bits;
-      bita++;	/* channel 1 and channel 2 bitalloc are the same */
+      bita++;   /* channel 1 and channel 2 bitalloc are the same */
       if ( (ba=*bita++) )
       {
         k=(alloc2 = alloc1+ba)->bits;

+ 19 - 19
panda/src/mpg123/layer3.c

@@ -713,8 +713,8 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
         mask <<= 1;
       }
       if(part2remain+num <= 0) {
-	num -= part2remain+num;
-	break;
+        num -= part2remain+num;
+        break;
       }
 
       for(i=0;i<4;i++) {
@@ -826,7 +826,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
 
         if (x == 15 && h->linbits) {
           max = cb;
-	  REFRESH_MASK;
+          REFRESH_MASK;
           x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           num -= h->linbits+1;
           mask <<= h->linbits;
@@ -850,7 +850,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
 
         if (y == 15 && h->linbits) {
           max = cb;
-	  REFRESH_MASK;
+          REFRESH_MASK;
           y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           num -= h->linbits+1;
           mask <<= h->linbits;
@@ -889,7 +889,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
         mask <<= 1;
       }
       if(part2remain+num <= 0) {
-	num -= part2remain+num;
+        num -= part2remain+num;
         break;
       }
 
@@ -972,7 +972,7 @@ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
 #if 0
       if(lsf) {
         int p = gr_info->scalefac_compress & 0x1;
-	if(ms_stereo) {
+        if(ms_stereo) {
           tab1 = pow1_2[p]; tab2 = pow2_2[p];
         }
         else {
@@ -1376,21 +1376,21 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
     ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
     ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; 
 #define MACRO1(v) { \
-	real sum0,sum1; \
+        real sum0,sum1; \
     sum0 = tmp1a + tmp2a; \
-	sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
-	MACRO0(v); }
+        sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
+        MACRO0(v); }
 #define MACRO2(v) { \
     real sum0,sum1; \
     sum0 = tmp2a - tmp1a; \
     sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
-	MACRO0(v); }
+        MACRO0(v); }
 
     register const real *c = COS9;
     register real *out2 = o2;
-	register real *w = wintab;
-	register real *out1 = o1;
-	register real *ts = tsbuf;
+        register real *w = wintab;
+        register real *out1 = o1;
+        register real *ts = tsbuf;
 
     real ta33,ta66,tb33,tb66;
 
@@ -1443,12 +1443,12 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
       MACRO2(5);
     }
 
-	{
-		real sum0,sum1;
-    	sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
-    	sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
-		MACRO0(4);
-	}
+        {
+                real sum0,sum1;
+        sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
+        sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
+                MACRO0(4);
+        }
   }
 #endif
 

+ 156 - 156
panda/src/mpg123/mpgbuffer.c

@@ -24,12 +24,12 @@ static int usr1flag = FALSE;
 
 static void catch_interrupt (void)
 {
-	intflag = TRUE;
+        intflag = TRUE;
 }
 
 static void catch_usr1 (void)
 {
-	usr1flag = TRUE;
+        usr1flag = TRUE;
 }
 
 /* Interfaces to writer process */
@@ -39,197 +39,197 @@ extern void buffer_sig(int signal, int block);
 void buffer_ignore_lowmem(void)
 {
 #ifndef NOXFERMEM
-	if(buffermem->wakeme[XF_READER])
-		xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_WAKEUP);
+        if(buffermem->wakeme[XF_READER])
+                xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_WAKEUP);
 #endif
 }
 
 void buffer_end(void)
 {
 #ifndef NOXFERMEM
-	xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_TERMINATE);
+        xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_TERMINATE);
 #endif
 }
 
 void buffer_resync(void)
 {
-	buffer_sig(SIGINT, TRUE);
+        buffer_sig(SIGINT, TRUE);
 }
 
 void buffer_reset(void)
 {
-	buffer_sig(SIGUSR1, TRUE);
+        buffer_sig(SIGUSR1, TRUE);
 }
 
 void buffer_start(void)
 {
-	buffer_sig(SIGCONT, FALSE);
+        buffer_sig(SIGCONT, FALSE);
 }
 
 void buffer_stop(void)
 {
-	buffer_sig(SIGSTOP, FALSE);
+        buffer_sig(SIGSTOP, FALSE);
 }
 
 extern int buffer_pid;
 
 void buffer_sig(int signal, int block)
 {
-	
+
 #ifndef NOXFERMEM
-	
-	kill(buffer_pid, signal);
-	
-	if (!buffermem || !block)
-		return;
-
-	if(xfermem_block(XF_WRITER, buffermem) != XF_CMD_WAKEUP) 
-		perror("Could not resync/reset buffers");
+
+        kill(buffer_pid, signal);
+
+        if (!buffermem || !block)
+                return;
+
+        if(xfermem_block(XF_WRITER, buffermem) != XF_CMD_WAKEUP) 
+                perror("Could not resync/reset buffers");
 #endif
-	
-	return;
+
+        return;
 }
 
 #ifndef NOXFERMEM
 
 void buffer_loop(struct audio_info_struct *ai, sigset_t *oldsigset)
 {
-	int bytes;
-	int my_fd = buffermem->fd[XF_READER];
-	txfermem *xf = buffermem;
-	int done = FALSE;
-
-	catchsignal (SIGINT, catch_interrupt);
-	catchsignal (SIGUSR1, catch_usr1);
-	sigprocmask (SIG_SETMASK, oldsigset, NULL);
-	if (param.outmode == DECODE_AUDIO) {
-		if (audio_open(ai) < 0) {
-			perror("audio");
-			exit(1);
-		}
-	}
-
-	for (;;) {
-		if (intflag) {
-			intflag = FALSE;
-			if (param.outmode == DECODE_AUDIO)
-				audio_queueflush (ai);
-			xf->readindex = xf->freeindex;
-			if (xf->wakeme[XF_WRITER])
-				xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
-		}
-		if (usr1flag) {
-			usr1flag = FALSE;
-			/*   close and re-open in order to flush
-			 *   the device's internal buffer before
-			 *   changing the sample rate.   [OF]
-			 */
-			/* writer must block when sending SIGUSR1
-			 * or we will lose all data processed 
-			 * in the meantime! [dk]
-			 */
-			xf->readindex = xf->freeindex;
-			/* We've nailed down the new starting location -
-			 * writer is now safe to go on. [dk]
-			 */
-			if (xf->wakeme[XF_WRITER])
-				xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
-			if (param.outmode == DECODE_AUDIO) {
-				audio_close (ai);
-				ai->rate = xf->buf[0]; 
-				ai->channels = xf->buf[1]; 
-				ai->format = xf->buf[2];
-				if (audio_open(ai) < 0) {
-					perror("audio");
-					exit(1);
-				}
-			}
-		}
-		if ( (bytes = xfermem_get_usedspace(xf)) < outburst ) {
-			/* if we got a buffer underrun we first
-			 * fill 1/8 of the buffer before continue/start
-			 * playing */
-			preload = xf->size>>3;
-			if(preload < outburst)
-				preload = outburst;
-		}
-		if(bytes < preload) {
-			int cmd;
-			if (done && !bytes) { 
-				break;
-			}
-
-			if(!done) {
-
-				cmd = xfermem_block(XF_READER, xf);
-
-				switch(cmd) {
-
-					/* More input pending. */
-					case XF_CMD_WAKEUP_INFO:
-						continue;
-					/* Yes, we know buffer is low but
-					 * know we don't care.
-					 */
-					case XF_CMD_WAKEUP:
-						break;	/* Proceed playing. */
-					case XF_CMD_TERMINATE:
-						/* Proceed playing without 
-						 * blocking any further.
-						 */
-						done=TRUE;
-						break;
-					case -1:
-						if(errno==EINTR)
-							continue;
-						perror("Yuck! Error in buffer handling...");
-						done = TRUE;
-						xf->readindex = xf->freeindex;
-						xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
-						break;
-					default:
-						fprintf(stderr, "\nEh!? Received unknown command 0x%x in buffer process. Tell Daniel!\n", cmd);
-				}
-			}
-		}
-		preload = outburst; /* set preload to lower mark */
-		if (bytes > xf->size - xf->readindex)
-			bytes = xf->size - xf->readindex;
-		if (bytes > outburst)
-			bytes = outburst;
-
-		if (param.outmode == DECODE_FILE)
-			bytes = write(OutputDescriptor, xf->data + xf->readindex, bytes);
-		else if (param.outmode == DECODE_AUDIO)
-			bytes = audio_play_samples(ai,
-				(unsigned char *) (xf->data + xf->readindex), bytes);
-
-		if(bytes < 0) {
-			bytes = 0;
-			if(errno != EINTR) {
-				perror("Ouch ... error while writing audio data: ");
-				/*
-				 * done==TRUE tells writer process to stop
-				 * sending data. There might be some latency
-				 * involved when resetting readindex to 
-				 * freeindex so we might need more than one
-				 * cycle to terminate. (The number of cycles
-				 * should be finite unless I managed to mess
-				 * up something. ;-) [dk]
-				 */
-				done = TRUE;	
-				xf->readindex = xf->freeindex;
-				xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
-			}
-		}
-
-		xf->readindex = (xf->readindex + bytes) % xf->size;
-		if (xf->wakeme[XF_WRITER])
-			xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
-	}
-
-	if (param.outmode == DECODE_AUDIO)
-		audio_close (ai);
+        int bytes;
+        int my_fd = buffermem->fd[XF_READER];
+        txfermem *xf = buffermem;
+        int done = FALSE;
+
+        catchsignal (SIGINT, catch_interrupt);
+        catchsignal (SIGUSR1, catch_usr1);
+        sigprocmask (SIG_SETMASK, oldsigset, NULL);
+        if (param.outmode == DECODE_AUDIO) {
+                if (audio_open(ai) < 0) {
+                        perror("audio");
+                        exit(1);
+                }
+        }
+
+        for (;;) {
+                if (intflag) {
+                        intflag = FALSE;
+                        if (param.outmode == DECODE_AUDIO)
+                                audio_queueflush (ai);
+                        xf->readindex = xf->freeindex;
+                        if (xf->wakeme[XF_WRITER])
+                                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+                }
+                if (usr1flag) {
+                        usr1flag = FALSE;
+                        /*   close and re-open in order to flush
+                         *   the device's internal buffer before
+                         *   changing the sample rate.   [OF]
+                         */
+                        /* writer must block when sending SIGUSR1
+                         * or we will lose all data processed 
+                         * in the meantime! [dk]
+                         */
+                        xf->readindex = xf->freeindex;
+                        /* We've nailed down the new starting location -
+                         * writer is now safe to go on. [dk]
+                         */
+                        if (xf->wakeme[XF_WRITER])
+                                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+                        if (param.outmode == DECODE_AUDIO) {
+                                audio_close (ai);
+                                ai->rate = xf->buf[0]; 
+                                ai->channels = xf->buf[1]; 
+                                ai->format = xf->buf[2];
+                                if (audio_open(ai) < 0) {
+                                        perror("audio");
+                                        exit(1);
+                                }
+                        }
+                }
+                if ( (bytes = xfermem_get_usedspace(xf)) < outburst ) {
+                        /* if we got a buffer underrun we first
+                         * fill 1/8 of the buffer before continue/start
+                         * playing */
+                        preload = xf->size>>3;
+                        if(preload < outburst)
+                                preload = outburst;
+                }
+                if(bytes < preload) {
+                        int cmd;
+                        if (done && !bytes) { 
+                                break;
+                        }
+
+                        if(!done) {
+
+                                cmd = xfermem_block(XF_READER, xf);
+
+                                switch(cmd) {
+
+                                        /* More input pending. */
+                                        case XF_CMD_WAKEUP_INFO:
+                                                continue;
+                                        /* Yes, we know buffer is low but
+                                         * know we don't care.
+                                         */
+                                        case XF_CMD_WAKEUP:
+                                                break;  /* Proceed playing. */
+                                        case XF_CMD_TERMINATE:
+                                                /* Proceed playing without 
+                                                 * blocking any further.
+                                                 */
+                                                done=TRUE;
+                                                break;
+                                        case -1:
+                                                if(errno==EINTR)
+                                                        continue;
+                                                perror("Yuck! Error in buffer handling...");
+                                                done = TRUE;
+                                                xf->readindex = xf->freeindex;
+                                                xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
+                                                break;
+                                        default:
+                                                fprintf(stderr, "\nEh!? Received unknown command 0x%x in buffer process. Tell Daniel!\n", cmd);
+                                }
+                        }
+                }
+                preload = outburst; /* set preload to lower mark */
+                if (bytes > xf->size - xf->readindex)
+                        bytes = xf->size - xf->readindex;
+                if (bytes > outburst)
+                        bytes = outburst;
+
+                if (param.outmode == DECODE_FILE)
+                        bytes = write(OutputDescriptor, xf->data + xf->readindex, bytes);
+                else if (param.outmode == DECODE_AUDIO)
+                        bytes = audio_play_samples(ai,
+                                (unsigned char *) (xf->data + xf->readindex), bytes);
+
+                if(bytes < 0) {
+                        bytes = 0;
+                        if(errno != EINTR) {
+                                perror("Ouch ... error while writing audio data: ");
+                                /*
+                                 * done==TRUE tells writer process to stop
+                                 * sending data. There might be some latency
+                                 * involved when resetting readindex to 
+                                 * freeindex so we might need more than one
+                                 * cycle to terminate. (The number of cycles
+                                 * should be finite unless I managed to mess
+                                 * up something. ;-) [dk]
+                                 */
+                                done = TRUE;
+                                xf->readindex = xf->freeindex;
+                                xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
+                        }
+                }
+
+                xf->readindex = (xf->readindex + bytes) % xf->size;
+                if (xf->wakeme[XF_WRITER])
+                        xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+        }
+
+        if (param.outmode == DECODE_AUDIO)
+                audio_close (ai);
 }
 
 #endif

+ 102 - 102
panda/src/mpg123/readers.c

@@ -27,12 +27,12 @@ static int fullread(int fd,unsigned char *buf,int count)
 {
     int ret,cnt=0;
     while(cnt < count) {
-	ret = read(fd,buf+cnt,count-cnt);
-	if(ret < 0)
-	    return ret;
-	if(ret == 0)
-	    break;
-	cnt += ret;
+        ret = read(fd,buf+cnt,count-cnt);
+        if(ret < 0)
+            return ret;
+        if(ret == 0)
+            break;
+        cnt += ret;
     } 
 
     return cnt;
@@ -46,10 +46,10 @@ static int default_init(struct reader *rds)
     rds->filelen = get_fileinfo(rds,buf);
   
     if(rds->filelen > 0) {
-	if(!strncmp(buf,"TAG",3)) {
-	    rds->flags |= READER_ID3TAG;
-	    memcpy(rds->id3buf,buf,128);
-	}
+        if(!strncmp(buf,"TAG",3)) {
+            rds->flags |= READER_ID3TAG;
+            memcpy(rds->id3buf,buf,128);
+        }
     }
     return 0;
 }
@@ -67,9 +67,9 @@ void stream_close(struct reader *rds)
 static int stream_back_bytes(struct reader *rds,int bytes)
 {
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
-	return -1;
+        return -1;
     if(param.usebuffer)
-	buffer_resync();
+        buffer_resync();
     return 0;
 }
 
@@ -80,7 +80,7 @@ static int stream_back_frame(struct reader *rds,struct frame *fr,int num)
     unsigned long newhead;
 
     if(!firsthead)
-	return 0;
+        return 0;
 
     bytes = (fr->framesize+8)*(num+2);
 
@@ -88,43 +88,43 @@ static int stream_back_frame(struct reader *rds,struct frame *fr,int num)
      * See mapped_back_frame(). 
      */
     if(param.usebuffer)
-	bytes += (long)(xfermem_get_usedspace(buffermem) /
-			(buffermem->buf[0] * buffermem->buf[1]
-			 * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
-			    16.0 : 8.0 ))
-			* (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
+        bytes += (long)(xfermem_get_usedspace(buffermem) /
+                        (buffermem->buf[0] * buffermem->buf[1]
+                         * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
+                            16.0 : 8.0 ))
+                        * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
     /*
       bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
-    */	
+    */
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
-	return -1;
+        return -1;
 
     if(fullread(rds->filept,buf,4) != 4)
-	return -1;
+        return -1;
 
     newhead = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + buf[3];
-	
+
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
-	if(fullread(rds->filept,buf,1) != 1)
-	    return -1;
-	newhead <<= 8;
-	newhead |= buf[0];
-	newhead &= 0xffffffff;
+        if(fullread(rds->filept,buf,1) != 1)
+            return -1;
+        newhead <<= 8;
+        newhead |= buf[0];
+        newhead &= 0xffffffff;
     }
 
     if( lseek(rds->filept,-4,SEEK_CUR) < 0)
-	return -1;
-	
+        return -1;
+
     read_frame(fr);
     read_frame(fr);
 
     if(fr->lay == 3) {
-	set_pointer(512);
+        set_pointer(512);
     }
 
     if(param.usebuffer)
-	buffer_resync();
-	
+        buffer_resync();
+
     return 0;
 }
 
@@ -133,12 +133,12 @@ static int stream_head_read(struct reader *rds,unsigned long *newhead)
     unsigned char hbuf[4];
 
     if(fullread(rds->filept,hbuf,4) != 4)
-	return FALSE;
+        return FALSE;
   
     *newhead = ((unsigned long) hbuf[0] << 24) |
-	((unsigned long) hbuf[1] << 16) |
-	((unsigned long) hbuf[2] << 8)  |
-	(unsigned long) hbuf[3];
+        ((unsigned long) hbuf[1] << 16) |
+        ((unsigned long) hbuf[2] << 8)  |
+        (unsigned long) hbuf[3];
   
     return TRUE;
 }
@@ -148,7 +148,7 @@ static int stream_head_shift(struct reader *rds,unsigned long *head)
     unsigned char hbuf;
 
     if(fullread(rds->filept,&hbuf,1) != 1)
-	return 0;
+        return 0;
     *head <<= 8;
     *head |= hbuf;
     *head &= 0xffffffff;
@@ -158,28 +158,28 @@ static int stream_head_shift(struct reader *rds,unsigned long *head)
 static int stream_skip_bytes(struct reader *rds,int len)
 {
     if (!param.usebuffer)
-  	return lseek(rds->filept,len,SEEK_CUR);
+        return lseek(rds->filept,len,SEEK_CUR);
 
     else {
 
-	int ret = lseek(rds->filept,len,SEEK_CUR);
-	buffer_resync();
-	return ret;
+        int ret = lseek(rds->filept,len,SEEK_CUR);
+        buffer_resync();
+        return ret;
 
     }
 }
 
 static int stream_read_frame_body(struct reader *rds,unsigned char *buf,
-				  int size)
+                                  int size)
 {
     long l;
 
     if( (l=fullread(rds->filept,buf,size)) != size)
-	{
-	    if(l <= 0)
-		return 0;
-	    memset(buf+l,0,size-l);
-	}
+        {
+            if(l <= 0)
+                return 0;
+            memset(buf+l,0,size-l);
+        }
 
     return 1;
 }
@@ -193,7 +193,7 @@ static void stream_rewind(struct reader *rds)
 {
     lseek(rds->filept,0,SEEK_SET);
     if(param.usebuffer) 
-	buffer_resync();
+        buffer_resync();
 }
 
 /*
@@ -205,20 +205,20 @@ static int get_fileinfo(struct reader *rds,char *buf)
     int len;
 
     if((len=lseek(rds->filept,0,SEEK_END)) < 0) {
-	return -1;
+        return -1;
     }
     if(lseek(rds->filept,-128,SEEK_END) < 0)
-	return -1;
+        return -1;
     if(fullread(rds->filept,(unsigned char *)buf,128) != 128) {
-	return -1;
+        return -1;
     }
     if(!strncmp(buf,"TAG",3)) {
-	len -= 128;
+        len -= 128;
     }
     if(lseek(rds->filept,0,SEEK_SET) < 0)
-	return -1;
+        return -1;
     if(len <= 0)
-	return -1;
+        return -1;
     return len;
 }
 
@@ -239,22 +239,22 @@ static int mapped_init(struct reader *rds)
 
     len = get_fileinfo(rds,buf);
     if(len < 0)
-	return -1;
+        return -1;
 
     if(!strncmp(buf,"TAG",3)) {
-	rds->flags |= READER_ID3TAG;
-	memcpy(rds->id3buf,buf,128);
+        rds->flags |= READER_ID3TAG;
+        memcpy(rds->id3buf,buf,128);
     }
 
     mappnt = mapbuf = (unsigned char *)
-	mmap(NULL, len, PROT_READ, MAP_SHARED , rds->filept, 0);
+        mmap(NULL, len, PROT_READ, MAP_SHARED , rds->filept, 0);
     if(!mapbuf || mapbuf == MAP_FAILED)
-	return -1;
+        return -1;
 
     mapend = mapbuf + len;
-	
+
     if(param.verbose > 1)
-	fprintf(stderr,"Using memory mapped IO for this stream.\n");
+        fprintf(stderr,"Using memory mapped IO for this stream.\n");
 
     rds->filelen = len;
     return 0;
@@ -264,14 +264,14 @@ static void mapped_rewind(struct reader *rds)
 {
     mappnt = mapbuf;
     if (param.usebuffer) 
-	buffer_resync();	
+        buffer_resync();
 }
 
 static void mapped_close(struct reader *rds)
 {
     munmap((void *)mapbuf,mapend-mapbuf);
     if (rds->flags & READER_FD_OPENED)
-	close(rds->filept);
+        close(rds->filept);
 }
 
 static int mapped_head_read(struct reader *rds,unsigned long *newhead) 
@@ -279,7 +279,7 @@ static int mapped_head_read(struct reader *rds,unsigned long *newhead)
     unsigned long nh;
 
     if(mappnt + 4 > mapend)
-	return FALSE;
+        return FALSE;
 
     nh = (*mappnt++)  << 24;
     nh |= (*mappnt++) << 16;
@@ -293,7 +293,7 @@ static int mapped_head_read(struct reader *rds,unsigned long *newhead)
 static int mapped_head_shift(struct reader *rds,unsigned long *head)
 {
     if(mappnt + 1 > mapend)
-	return FALSE;
+        return FALSE;
     *head <<= 8;
     *head |= *mappnt++;
     *head &= 0xffffffff;
@@ -303,22 +303,22 @@ static int mapped_head_shift(struct reader *rds,unsigned long *head)
 static int mapped_skip_bytes(struct reader *rds,int len)
 {
     if(mappnt + len > mapend)
-	return FALSE;
+        return FALSE;
     mappnt += len;
     if (param.usebuffer)
-	buffer_resync();
+        buffer_resync();
     return TRUE;
 }
 
 static int mapped_read_frame_body(struct reader *rds,unsigned char *buf,
-				  int size)
+                                  int size)
 {
     if(size <= 0) {
-	fprintf(stderr,"Ouch. Read_frame called with size <= 0\n");
-	return FALSE;
+        fprintf(stderr,"Ouch. Read_frame called with size <= 0\n");
+        return FALSE;
     }
     if(mappnt + size > mapend)
-	return FALSE;
+        return FALSE;
     memcpy(buf,mappnt,size);
     mappnt += size;
 
@@ -331,7 +331,7 @@ static int mapped_back_bytes(struct reader *rds,int bytes)
         return -1;
     mappnt -= bytes;
     if(param.usebuffer)
-	buffer_resync();
+        buffer_resync();
     return 0;
 }
 
@@ -351,11 +351,11 @@ static int mapped_back_frame(struct reader *rds,struct frame *fr,int num)
      * this corresponds to.
      */
     if(param.usebuffer) 
-	bytes += (long)(xfermem_get_usedspace(buffermem) /
-			(buffermem->buf[0] * buffermem->buf[1] 
-			 * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
-			    16.0 : 8.0 )) 
-			* (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
+        bytes += (long)(xfermem_get_usedspace(buffermem) /
+                        (buffermem->buf[0] * buffermem->buf[1] 
+                         * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
+                            16.0 : 8.0 )) 
+                        * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
     /*
       bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));  
     */
@@ -383,7 +383,7 @@ static int mapped_back_frame(struct reader *rds,struct frame *fr,int num)
         set_pointer(512);
 
     if(param.usebuffer)
-	buffer_resync();
+        buffer_resync();
     
     return 0;
 }
@@ -403,7 +403,7 @@ struct reader *rd;
 struct reader readers[] = {
 #ifdef READ_SYSTEM
     { system_init,
-      NULL,	/* filled in by system_init() */
+      NULL,     /* filled in by system_init() */
       NULL,
       NULL,
       NULL,
@@ -447,42 +447,42 @@ struct reader *open_stream(char *bs_filenam,int fd)
     int filept;
 
     if (!bs_filenam) {
-	if(fd < 0) {
-	    filept = 0;
-	    filept_opened = 0;
-	}
-	else
-	    filept = fd;
+        if(fd < 0) {
+            filept = 0;
+            filept_opened = 0;
+        }
+        else
+            filept = fd;
     }
     else if (!strncmp(bs_filenam, "http://", 7)) 
-	filept = http_open(bs_filenam);
+        filept = http_open(bs_filenam);
 #ifndef O_BINARY
 #define O_BINARY (0)
 #endif
     else if ( (filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) {
-	perror (bs_filenam);
-	return NULL;
+        perror (bs_filenam);
+        return NULL;
     }
 
     rd = NULL;
     for(i=0;;i++) {
-	readers[i].filelen = -1;
-	readers[i].filept  = filept;
-	readers[i].flags = 0;
-	if(filept_opened)
-	    readers[i].flags |= READER_FD_OPENED;
-	if(!readers[i].init) {
-	    fprintf(stderr,"Fatal error!\n");
-	    exit(1);
-	}
-	if(readers[i].init(readers+i) >= 0) {
-	    rd = &readers[i];
-	    break;
-	}
+        readers[i].filelen = -1;
+        readers[i].filept  = filept;
+        readers[i].flags = 0;
+        if(filept_opened)
+            readers[i].flags |= READER_FD_OPENED;
+        if(!readers[i].init) {
+            fprintf(stderr,"Fatal error!\n");
+            exit(1);
+        }
+        if(readers[i].init(readers+i) >= 0) {
+            rd = &readers[i];
+            break;
+        }
     }
 
     if(rd && rd->flags & READER_ID3TAG) {
-	print_id3_tag(rd->id3buf);
+        print_id3_tag(rd->id3buf);
     }
 
     return rd;

+ 1 - 1
panda/src/mpg123/tabinit.c

@@ -113,7 +113,7 @@ void make_conv16to8_table(int mode)
       else
         c1 = 255 - (int) (log( 1.0 + 255.0 * (double) i*mul / 32768.0 ) * m);
       if(c1 < 0 || c1 > 255) 
-	fprintf(stderr,"Converror %d %d\n",i,c1);
+        fprintf(stderr,"Converror %d %d\n",i,c1);
       if(c1 == 0)
         c1 = 2;
       conv16to8[i] = (unsigned char) c1;

+ 15 - 15
panda/src/mpg123/vbrhead.c

@@ -8,9 +8,9 @@ static unsigned long get32bits(unsigned char *buf) {
     unsigned long ret = 0;
 
     ret = (((unsigned long) buf[0]) << 24) |
-	(((unsigned long) buf[1]) << 16) |
-	(((unsigned long) buf[2]) << 8) |
-	((unsigned long) buf[3]) ;
+        (((unsigned long) buf[1]) << 16) |
+        (((unsigned long) buf[2]) << 8) |
+        ((unsigned long) buf[3]) ;
 
     return ret;
 }
@@ -20,42 +20,42 @@ int getVBRHeader(struct vbrHeader *head,unsigned char *buf, struct frame *fr)
     int ssize;
 
     if(fr->lay != 3)
-	return 0;
+        return 0;
 
     if(fr->lsf)
-	ssize = (fr->stereo == 1) ? 9 : 17;
+        ssize = (fr->stereo == 1) ? 9 : 17;
     else
-	ssize = (fr->stereo == 1) ? 17 : 32;
+        ssize = (fr->stereo == 1) ? 17 : 32;
 
 
     buf += ssize;
 
     if(( buf[0] != 'X' ) || ( buf[1] != 'i' ) ||
        ( buf[2] != 'n' ) || ( buf[3] != 'g' ) ) 
-	return 0;
+        return 0;
     buf+=4;
     
     head->flags = get32bits(buf);
     buf+=4;
     
     if(head->flags & VBR_FRAMES_FLAG) {
-	head->frames = get32bits(buf);
-	buf += 4;
+        head->frames = get32bits(buf);
+        buf += 4;
     }
 
     if(head->flags & VBR_BYTES_FLAG) {
-	head->bytes  = get32bits(buf); 
-	buf += 4;
+        head->bytes  = get32bits(buf); 
+        buf += 4;
     }
 
     if(head->flags & VBR_TOC_FLAG) {
-	memcpy(head->toc,buf,100);
-	buf += 100;
+        memcpy(head->toc,buf,100);
+        buf += 100;
     }
 
     if(head->flags & VBR_SCALE_FLAG) {
-	head->scale = get32bits(buf);
-	buf += 4;
+        head->scale = get32bits(buf);
+        buf += 4;
     }
 
     /* fprintf(stderr,"Found XING %04lx\n",head->flags); */

+ 131 - 131
panda/src/mpg123/xfermem.c

@@ -44,189 +44,189 @@ extern int errno;
 
 void xfermem_init (txfermem **xf, int bufsize, int msize, int skipbuf)
 {
-	int regsize = bufsize + msize + skipbuf + sizeof(txfermem);
-	extern int preload;
+        int regsize = bufsize + msize + skipbuf + sizeof(txfermem);
+        extern int preload;
 
 #ifdef USE_MMAP
 #  ifdef MAP_ANON
-	if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
-			MAP_ANON | MAP_SHARED, -1, 0)) == (txfermem *) -1) {
-		perror ("mmap()");
-		exit (1);
-	}
+        if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
+                        MAP_ANON | MAP_SHARED, -1, 0)) == (txfermem *) -1) {
+                perror ("mmap()");
+                exit (1);
+        }
 #  else
-	int devzero;
-	if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) {
-		perror ("open(/dev/zero)");
-		exit (1);
-	}
-	if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
-			MAP_SHARED, devzero, 0)) == (txfermem *) -1) {
-		perror ("mmap()");
-		exit (1);
-	}
-	close (devzero);
+        int devzero;
+        if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) {
+                perror ("open(/dev/zero)");
+                exit (1);
+        }
+        if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
+                        MAP_SHARED, devzero, 0)) == (txfermem *) -1) {
+                perror ("mmap()");
+                exit (1);
+        }
+        close (devzero);
 #  endif
 #else
-	struct shmid_ds shmemds;
-	int shmemid;
-	if ((shmemid = shmget(IPC_PRIVATE, regsize, IPC_CREAT | 0600)) == -1) {
-		perror ("shmget()");
-		exit (1);
-	}
-	if ((*xf = (txfermem *) shmat(shmemid, 0, 0)) == (txfermem *) -1) {
-		perror ("shmat()");
-		shmctl (shmemid, IPC_RMID, &shmemds);
-		exit (1);
-	}
-	if (shmctl(shmemid, IPC_RMID, &shmemds) == -1) {
-		perror ("shmctl()");
-		xfermem_done (*xf);
-		exit (1);
-	}
+        struct shmid_ds shmemds;
+        int shmemid;
+        if ((shmemid = shmget(IPC_PRIVATE, regsize, IPC_CREAT | 0600)) == -1) {
+                perror ("shmget()");
+                exit (1);
+        }
+        if ((*xf = (txfermem *) shmat(shmemid, 0, 0)) == (txfermem *) -1) {
+                perror ("shmat()");
+                shmctl (shmemid, IPC_RMID, &shmemds);
+                exit (1);
+        }
+        if (shmctl(shmemid, IPC_RMID, &shmemds) == -1) {
+                perror ("shmctl()");
+                xfermem_done (*xf);
+                exit (1);
+        }
 #endif
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, (*xf)->fd) < 0) {
-		perror ("socketpair()");
-		xfermem_done (*xf);
-		exit (1);
-	}
-	(*xf)->freeindex = (*xf)->readindex = 0;
-	(*xf)->wakeme[0] = (*xf)->wakeme[1] = FALSE;
-	(*xf)->data = ((byte *) *xf) + sizeof(txfermem) + msize;
-	(*xf)->metadata = ((byte *) *xf) + sizeof(txfermem);
-	(*xf)->size = bufsize;
-	(*xf)->metasize = msize + skipbuf;
-	preload = bufsize>>3;
+        if (socketpair(AF_UNIX, SOCK_STREAM, 0, (*xf)->fd) < 0) {
+                perror ("socketpair()");
+                xfermem_done (*xf);
+                exit (1);
+        }
+        (*xf)->freeindex = (*xf)->readindex = 0;
+        (*xf)->wakeme[0] = (*xf)->wakeme[1] = FALSE;
+        (*xf)->data = ((byte *) *xf) + sizeof(txfermem) + msize;
+        (*xf)->metadata = ((byte *) *xf) + sizeof(txfermem);
+        (*xf)->size = bufsize;
+        (*xf)->metasize = msize + skipbuf;
+        preload = bufsize>>3;
 }
 
 void xfermem_done (txfermem *xf)
 {
-	if(!xf)
-		return;
+        if(!xf)
+                return;
 #ifdef USE_MMAP
-	munmap ((caddr_t) xf, xf->size + xf->metasize + sizeof(txfermem));
+        munmap ((caddr_t) xf, xf->size + xf->metasize + sizeof(txfermem));
 #else
-	if (shmdt((void *) xf) == -1) {
-		perror ("shmdt()");
-		exit (1);
-	}
+        if (shmdt((void *) xf) == -1) {
+                perror ("shmdt()");
+                exit (1);
+        }
 #endif
 }
 
 void xfermem_init_writer (txfermem *xf)
 {
-	if(xf)
-		close (xf->fd[XF_READER]);
+        if(xf)
+                close (xf->fd[XF_READER]);
 }
 
 void xfermem_init_reader (txfermem *xf)
 {
-	if(xf)
-		close (xf->fd[XF_WRITER]);
+        if(xf)
+                close (xf->fd[XF_WRITER]);
 }
 
 int xfermem_get_freespace (txfermem *xf)
 {
-	int freeindex, readindex;
+        int freeindex, readindex;
 
-	if(!xf)
-		return 0;
+        if(!xf)
+                return 0;
 
-	if ((freeindex = xf->freeindex) < 0
-			|| (readindex = xf->readindex) < 0)
-		return (0);
-	if (readindex > freeindex)
-		return ((readindex - freeindex) - 1);
-	else
-		return ((xf->size - (freeindex - readindex)) - 1);
+        if ((freeindex = xf->freeindex) < 0
+                        || (readindex = xf->readindex) < 0)
+                return (0);
+        if (readindex > freeindex)
+                return ((readindex - freeindex) - 1);
+        else
+                return ((xf->size - (freeindex - readindex)) - 1);
 }
 
 int xfermem_get_usedspace (txfermem *xf)
 {
-	int freeindex, readindex;
+        int freeindex, readindex;
 
-	if(!xf)
-		return 0;
+        if(!xf)
+                return 0;
 
-	if ((freeindex = xf->freeindex) < 0
-			|| (readindex = xf->readindex) < 0)
-		return (0);
-	if (freeindex >= readindex)
-		return (freeindex - readindex);
-	else
-		return (xf->size - (readindex - freeindex));
+        if ((freeindex = xf->freeindex) < 0
+                        || (readindex = xf->readindex) < 0)
+                return (0);
+        if (freeindex >= readindex)
+                return (freeindex - readindex);
+        else
+                return (xf->size - (readindex - freeindex));
 }
 
 int xfermem_getcmd (int fd, int block)
 {
-	fd_set selfds;
-	byte cmd;
+        fd_set selfds;
+        byte cmd;
 
-	for (;;) {
-		struct timeval selto = {0, 0};
+        for (;;) {
+                struct timeval selto = {0, 0};
 
-		FD_ZERO (&selfds);
-		FD_SET (fd, &selfds);
-		/* #ifdef HPUX */ /* seems to trigger performance problems? strange */
+                FD_ZERO (&selfds);
+                FD_SET (fd, &selfds);
+                /* #ifdef HPUX */ /* seems to trigger performance problems? strange */
 #if 0
-		switch (select(FD_SETSIZE, (int *) &selfds, NULL, NULL, block ? NULL : &selto)) {
+                switch (select(FD_SETSIZE, (int *) &selfds, NULL, NULL, block ? NULL : &selto)) {
 #else
-		switch (select(FD_SETSIZE, &selfds, NULL, NULL, block ? NULL : &selto)) {
+                switch (select(FD_SETSIZE, &selfds, NULL, NULL, block ? NULL : &selto)) {
 #endif
-			case 0:
-				if (!block)
-					return (0);
-				continue;
-			case -1:
-				if (errno == EINTR)
-					continue;
-				return (-2);
-			case 1:
-				if (FD_ISSET(fd, &selfds))
-					switch (read(fd, &cmd, 1)) {
-						case 0: /* EOF */
-							return (-1);
-						case -1:
-							if (errno == EINTR)
-								continue;
-							return (-3);
-						case 1:
-							return (cmd);
-						default: /* ?!? */
-							return (-4);
-					}
-				else /* ?!? */
-					return (-5);
-			default: /* ?!? */
-				return (-6);
-		}
-	}
+                        case 0:
+                                if (!block)
+                                        return (0);
+                                continue;
+                        case -1:
+                                if (errno == EINTR)
+                                        continue;
+                                return (-2);
+                        case 1:
+                                if (FD_ISSET(fd, &selfds))
+                                        switch (read(fd, &cmd, 1)) {
+                                                case 0: /* EOF */
+                                                        return (-1);
+                                                case -1:
+                                                        if (errno == EINTR)
+                                                                continue;
+                                                        return (-3);
+                                                case 1:
+                                                        return (cmd);
+                                                default: /* ?!? */
+                                                        return (-4);
+                                        }
+                                else /* ?!? */
+                                        return (-5);
+                        default: /* ?!? */
+                                return (-6);
+                }
+        }
 }
 
 int xfermem_putcmd (int fd, byte cmd)
 {
-	for (;;) {
-		switch (write(fd, &cmd, 1)) {
-			case 1:
-				return (1);
-			case -1:
-				if (errno != EINTR)
-					return (-1);
-		}
-	}
+        for (;;) {
+                switch (write(fd, &cmd, 1)) {
+                        case 1:
+                                return (1);
+                        case -1:
+                                if (errno != EINTR)
+                                        return (-1);
+                }
+        }
 }
 
 int xfermem_block (int readwrite, txfermem *xf)
 {
-	int myfd = xf->fd[readwrite];
-	int result;
+        int myfd = xf->fd[readwrite];
+        int result;
 
-	xf->wakeme[readwrite] = TRUE;
-	if (xf->wakeme[1 - readwrite])
-		xfermem_putcmd (myfd, XF_CMD_WAKEUP);
-	result = xfermem_getcmd(myfd, TRUE);
-	xf->wakeme[readwrite] = FALSE;
-	return ((result <= 0) ? -1 : result);
+        xf->wakeme[readwrite] = TRUE;
+        if (xf->wakeme[1 - readwrite])
+                xfermem_putcmd (myfd, XF_CMD_WAKEUP);
+        result = xfermem_getcmd(myfd, TRUE);
+        xf->wakeme[readwrite] = FALSE;
+        return ((result <= 0) ? -1 : result);
 }
 
 #elif defined(WIN32)

+ 94 - 91
panda/src/pnm/bitio.c

@@ -15,8 +15,11 @@
  * without express or implied warranty.
  *
  * $Log$
- * Revision 1.1  2000/10/04 01:14:42  drose
- * Initial revision
+ * Revision 1.2  2001/05/25 16:13:01  drose
+ * *** empty log message ***
+ *
+ * Revision 1.1.1.1  2000/10/04 01:14:42  drose
+ *
  *
  * Revision 1.5  1992/11/24  19:36:46  dws
  * Added copyright.
@@ -39,23 +42,23 @@
 
 struct bitstream
 {
-	FILE *
-		f;		/* bytestream */
-	unsigned long
-		bitbuf;		/* bit buffer */
-	int
-		nbitbuf;	/* number of bits in 'bitbuf' */
-	char
-		mode;
+        FILE *
+                f;              /* bytestream */
+        unsigned long
+                bitbuf;         /* bit buffer */
+        int
+                nbitbuf;        /* number of bits in 'bitbuf' */
+        char
+                mode;
 };
 
-#define Mask(n)		((1<<(n))-1)
+#define Mask(n)         ((1<<(n))-1)
 
-#define BitPut(b,ul,n)	((b)->bitbuf = (((b)->bitbuf<<(n))	\
-					|((ul)&Mask(n))),	\
-			(b)->nbitbuf += (n))
+#define BitPut(b,ul,n)  ((b)->bitbuf = (((b)->bitbuf<<(n))      \
+                                        |((ul)&Mask(n))),       \
+                        (b)->nbitbuf += (n))
 
-#define BitGet(b,n)	(((b)->bitbuf>>((b)->nbitbuf-=(n))) & Mask(n))
+#define BitGet(b,n)     (((b)->bitbuf>>((b)->nbitbuf-=(n))) & Mask(n))
 
 /*
  * pm_bitinit() - allocate and return a struct bitstream * for the
@@ -70,21 +73,21 @@ struct bitstream
 EXPCL_PANDA struct bitstream *
 pm_bitinit(FILE *f, char *mode)
 {
-	struct bitstream *ans = (struct bitstream *)0;
+        struct bitstream *ans = (struct bitstream *)0;
 
-	if(!f || !mode || !*mode)
-		return ans;
-	if(strcmp(mode, "r") && strcmp(mode, "w"))
-		return ans;
+        if(!f || !mode || !*mode)
+                return ans;
+        if(strcmp(mode, "r") && strcmp(mode, "w"))
+                return ans;
 
-	ans = (struct bitstream *)calloc(1, sizeof(struct bitstream));
-	if(ans)
-	{
-		ans->f = f;
-		ans->mode = *mode;
-	}
+        ans = (struct bitstream *)calloc(1, sizeof(struct bitstream));
+        if(ans)
+        {
+                ans->f = f;
+                ans->mode = *mode;
+        }
 
-	return ans;
+        return ans;
 }
 
 /*
@@ -100,40 +103,40 @@ pm_bitinit(FILE *f, char *mode)
 EXPCL_PANDA int
 pm_bitfini(struct bitstream *b)
 {
-	int		nbyte = 0;
-
-	if(!b)
-		return -1;
-
-	/* flush the output */
-	if(b->mode == 'w')
-	{
-		/* flush the bits */
-		if (b->nbitbuf < 0 || b->nbitbuf >= 8)
-		{
-			/* pm_bitwrite() didn't work */
-			return -1;
-		}
-
-		/*
-		 * If we get to here, nbitbuf is 0..7
-		 */
-		if(b->nbitbuf)
-		{
-			char	c;
-
-			BitPut(b, 0, (long)8-(b->nbitbuf));
-			c = (char) BitGet(b, (long)8);
-			if(putc(c, b->f) == EOF)
-			{
-				return -1;
-			}
-			nbyte++;
-		}
-	}
-
-	free(b);
-	return nbyte;
+        int             nbyte = 0;
+
+        if(!b)
+                return -1;
+
+        /* flush the output */
+        if(b->mode == 'w')
+        {
+                /* flush the bits */
+                if (b->nbitbuf < 0 || b->nbitbuf >= 8)
+                {
+                        /* pm_bitwrite() didn't work */
+                        return -1;
+                }
+
+                /*
+                 * If we get to here, nbitbuf is 0..7
+                 */
+                if(b->nbitbuf)
+                {
+                        char    c;
+
+                        BitPut(b, 0, (long)8-(b->nbitbuf));
+                        c = (char) BitGet(b, (long)8);
+                        if(putc(c, b->f) == EOF)
+                        {
+                                return -1;
+                        }
+                        nbyte++;
+                }
+        }
+
+        free(b);
+        return nbyte;
 }
 
 /*
@@ -147,25 +150,25 @@ pm_bitfini(struct bitstream *b)
 EXPCL_PANDA int
 pm_bitread(struct bitstream *b, unsigned long nbits, unsigned long *val)
 {
-	int		nbyte = 0;
-	int		c;
+        int             nbyte = 0;
+        int             c;
 
-	if(!b)
-		return -1;
+        if(!b)
+                return -1;
 
-	while (b->nbitbuf < nbits)
-	{
-		if((c = getc(b->f)) == EOF)
-		{
-			return -1;
-		}
-		nbyte++;
+        while (b->nbitbuf < nbits)
+        {
+                if((c = getc(b->f)) == EOF)
+                {
+                        return -1;
+                }
+                nbyte++;
 
-		BitPut(b, c, (long) 8);
-	}
+                BitPut(b, c, (long) 8);
+        }
 
-	*val = BitGet(b, nbits);
-	return nbyte;
+        *val = BitGet(b, nbits);
+        return nbyte;
 }
 
 /*
@@ -179,24 +182,24 @@ pm_bitread(struct bitstream *b, unsigned long nbits, unsigned long *val)
 EXPCL_PANDA int
 pm_bitwrite(struct bitstream *b, unsigned long nbits, unsigned long val)
 {
-	int		nbyte = 0;
-	char		c;
+        int             nbyte = 0;
+        char            c;
 
-	if(!b)
-		return -1;
+        if(!b)
+                return -1;
 
-	BitPut(b, val, nbits);
+        BitPut(b, val, nbits);
 
-	while (b->nbitbuf >= 8)
-	{
-		c = (char) BitGet(b, (long)8);
+        while (b->nbitbuf >= 8)
+        {
+                c = (char) BitGet(b, (long)8);
 
-		if(putc(c, b->f) == EOF)
-		{
-			return -1;
-		}
-		nbyte++;
-	}
+                if(putc(c, b->f) == EOF)
+                {
+                        return -1;
+                }
+                nbyte++;
+        }
 
-	return nbyte;
+        return nbyte;
 }

+ 381 - 381
panda/src/pnm/libpbm1.c

@@ -248,17 +248,17 @@ pm_init( argcP, argv )
             {
             pm_message( "Version: %s", PBMPLUS_VERSION );
 #if defined(COMPILE_TIME) && defined(COMPILED_BY)
-	    pm_message( "Compiled %s by user \"%s\"",
-		       COMPILE_TIME, COMPILED_BY );
+            pm_message( "Compiled %s by user \"%s\"",
+                       COMPILE_TIME, COMPILED_BY );
 #endif
 #ifdef BSD
             pm_message( "BSD defined" );
 #endif /*BSD*/
 #ifdef SYSV
 #ifdef VMS
-	    pm_message( "VMS & SYSV defined" );
+            pm_message( "VMS & SYSV defined" );
 #else
-  	    pm_message( "SYSV defined" );
+            pm_message( "SYSV defined" );
 #endif
 #endif /*SYSV*/
 #ifdef MSDOS
@@ -597,9 +597,9 @@ pm_openr( name )
     else
         {
 #ifndef VMS
-  	f = fopen( name, "rb" );
+        f = fopen( name, "rb" );
 #else
-	f = fopen ( name, "r", "ctx=stm" );
+        f = fopen ( name, "r", "ctx=stm" );
 #endif
         if ( f == NULL )
             {
@@ -820,14 +820,14 @@ char *pm_read_unknown_size( file, nread )
 
 #ifdef VMS
 /*
- * @(#)argproc.c 1.0 89/02/01		Mark Pizzolato ([email protected])	
+ * @(#)argproc.c 1.0 89/02/01           Mark Pizzolato ([email protected])
  */
 
 #ifndef lint
 char argproc_version[] = "@(#)argproc.c VMS uucp Version infopiz-1.0";
 #endif
 
-#include "includes.h"		/* System include files, system dependent */
+#include "includes.h"           /* System include files, system dependent */
 
 
 /*
@@ -839,7 +839,7 @@ char argproc_version[] = "@(#)argproc.c VMS uucp Version infopiz-1.0";
  * of program.  With suitable modification, it may useful for other
  * portability problems as well.
  *
- * Author:  Mark Pizzolato	[email protected]
+ * Author:  Mark Pizzolato      [email protected]
  */
 struct list_item
     {
@@ -849,8 +849,8 @@ struct list_item
 
 int
 getredirection(ac, av)
-int		*ac;
-char		***av;
+int             *ac;
+char            ***av;
 /*
  * Process vms redirection arg's.  Exit if any error is seen.
  * If getredirection() processes an argument, it is erased
@@ -864,29 +864,29 @@ char		***av;
  *
  * Normal usage is as follows:
  *
- *	main(argc, argv)
- *	int		argc;
- *    	char		*argv[];
- *	{
- *		getredirection(&argc, &argv);
- *	}
+ *      main(argc, argv)
+ *      int             argc;
+ *      char            *argv[];
+ *      {
+ *              getredirection(&argc, &argv);
+ *      }
  */
 {
-    int			argc = *ac;	/* Argument Count	  */
-    char		**argv = *av;	/* Argument Vector	  */
-    char		*ap;   		/* Argument pointer	  */
-    int	       		j;		/* argv[] index		  */
-    extern int		errno;		/* Last vms i/o error 	  */
-    int			item_count = 0;	/* Count of Items in List */
-    int			new_file;	/* flag, true if '>' used */
-    struct list_item 	*list_head = 0;	/* First Item in List	    */
-    struct list_item	*list_tail;	/* Last Item in List	    */
-    char 		*in = NULL;	/* Input File Name	    */
-    char 		*out = NULL;	/* Output File Name	    */
-    char 		*outmode = "w";	/* Mode to Open Output File */
-    int			cmargc = 0;    	/* Piped Command Arg Count  */
-    char		**cmargv = NULL;/* Piped Command Arg Vector */
-    stat_t		statbuf;	/* fstat buffer		    */
+    int                 argc = *ac;     /* Argument Count         */
+    char                **argv = *av;   /* Argument Vector        */
+    char                *ap;            /* Argument pointer       */
+    int                 j;              /* argv[] index           */
+    extern int          errno;          /* Last vms i/o error     */
+    int                 item_count = 0; /* Count of Items in List */
+    int                 new_file;       /* flag, true if '>' used */
+    struct list_item    *list_head = 0; /* First Item in List       */
+    struct list_item    *list_tail;     /* Last Item in List        */
+    char                *in = NULL;     /* Input File Name          */
+    char                *out = NULL;    /* Output File Name         */
+    char                *outmode = "w"; /* Mode to Open Output File */
+    int                 cmargc = 0;     /* Piped Command Arg Count  */
+    char                **cmargv = NULL;/* Piped Command Arg Vector */
+    stat_t              statbuf;        /* fstat buffer             */
 
     /*
      * First handle the case where the last thing on the line ends with
@@ -895,136 +895,136 @@ char		***av;
      */
     ap = argv[argc-1];
     if (0 == strcmp("&", ap))
-	exit(background_process(--argc, argv));
+        exit(background_process(--argc, argv));
     if ('&' == ap[strlen(ap)-1])
-	{
-	ap[strlen(ap)-1] = '\0';
-	exit(background_process(argc, argv));
-	}
+        {
+        ap[strlen(ap)-1] = '\0';
+        exit(background_process(argc, argv));
+        }
     /*
      * Now we handle the general redirection cases that involve '>', '>>',
      * '<', and pipes '|'.
      */
     for (new_file = 0, j = 0; j < argc; ++j)
-	{
-	if (0 == strcmp("<", argv[j]))
-	    {
-	    if (j+1 >= argc)
-		{
-		errno = EINVAL;
-		perror("No input file");
-		exit(EXIT_ERR);
-		}
-	    in = argv[++j];
-	    continue;
-	    }
-	if ('<' == *(ap = argv[j]))
-	    {
-	    in = 1 + ap;
-	    continue;
-	    }
-	if (0 == strcmp(">", ap))
-	    {
-	    if (j+1 >= argc)
-		{
-		errno = EINVAL;
-		perror("No output file");
-		exit(EXIT_ERR);
-		}
-	    out = argv[++j];
-	    new_file = 1;
-	    continue;
-	    }
-	if ('>' == *ap)
-	    {
-	    if ('>' == ap[1])
-		{
-		outmode = "a";
-		if ('\0' == ap[2])
-		    out = argv[++j];
-		else
-		    out = 2 + ap;
-		}
-	    else
-		{ out = 1 + ap;  new_file = 1; }
-	    continue;
-	    }
-	if (0 == strcmp("|", argv[j]))
-	    {
-	    if (j+1 >= argc)
-		{
-		errno = EPIPE;
-		perror("No command to Pipe to");
-		exit(EXIT_ERR);
-		}
-	    cmargc = argc-(j+1);
-	    cmargv = &argv[j+1];
-	    argc = j;
-	    outmode = "wb";	/* pipes are binary mode devices */
-	    continue;
-	    }
-	if ('|' == *(ap = argv[j]))
-	    {
-	    ++argv[j];
-	    cmargc = argc-j;
-	    cmargv = &argv[j];
-	    argc = j;
-	    outmode = "wb";	/* pipes are binary mode devices */
-	    continue;
-	    }
-	expand_wild_cards(ap, &list_head, &list_tail, &item_count);
-	}
+        {
+        if (0 == strcmp("<", argv[j]))
+            {
+            if (j+1 >= argc)
+                {
+                errno = EINVAL;
+                perror("No input file");
+                exit(EXIT_ERR);
+                }
+            in = argv[++j];
+            continue;
+            }
+        if ('<' == *(ap = argv[j]))
+            {
+            in = 1 + ap;
+            continue;
+            }
+        if (0 == strcmp(">", ap))
+            {
+            if (j+1 >= argc)
+                {
+                errno = EINVAL;
+                perror("No output file");
+                exit(EXIT_ERR);
+                }
+            out = argv[++j];
+            new_file = 1;
+            continue;
+            }
+        if ('>' == *ap)
+            {
+            if ('>' == ap[1])
+                {
+                outmode = "a";
+                if ('\0' == ap[2])
+                    out = argv[++j];
+                else
+                    out = 2 + ap;
+                }
+            else
+                { out = 1 + ap;  new_file = 1; }
+            continue;
+            }
+        if (0 == strcmp("|", argv[j]))
+            {
+            if (j+1 >= argc)
+                {
+                errno = EPIPE;
+                perror("No command to Pipe to");
+                exit(EXIT_ERR);
+                }
+            cmargc = argc-(j+1);
+            cmargv = &argv[j+1];
+            argc = j;
+            outmode = "wb";     /* pipes are binary mode devices */
+            continue;
+            }
+        if ('|' == *(ap = argv[j]))
+            {
+            ++argv[j];
+            cmargc = argc-j;
+            cmargv = &argv[j];
+            argc = j;
+            outmode = "wb";     /* pipes are binary mode devices */
+            continue;
+            }
+        expand_wild_cards(ap, &list_head, &list_tail, &item_count);
+        }
     /*
      * Allocate and fill in the new argument vector, Some Unix's terminate
      * the list with an extra null pointer.
      */
     argv = *av = calloc(item_count+1, sizeof(char *));
     for (j = 0; j < item_count; ++j, list_head = list_head->next)
-	argv[j] = list_head->value;
+        argv[j] = list_head->value;
     *ac = item_count;
     if (cmargv != NULL)
-	{
-	char subcmd[1024];
-	static char *pipe_and_fork();
-
-	if (out != NULL)
-	    {
-	    errno = EINVAL;
-	    perror("Invalid '|' and '>' specified");
-	    exit(EXIT_ERR);
-	    }
-	strcpy(subcmd, cmargv[0]);
-	for (j = 1; j < cmargc; ++j)
-	    {
-	    strcat(subcmd, " \"");
-	    strcat(subcmd, cmargv[j]);
-	    strcat(subcmd, "\"");
-	    }
-	out = pipe_and_fork(subcmd);
-	outmode = "wb";
-	}
-	
+        {
+        char subcmd[1024];
+        static char *pipe_and_fork();
+
+        if (out != NULL)
+            {
+            errno = EINVAL;
+            perror("Invalid '|' and '>' specified");
+            exit(EXIT_ERR);
+            }
+        strcpy(subcmd, cmargv[0]);
+        for (j = 1; j < cmargc; ++j)
+            {
+            strcat(subcmd, " \"");
+            strcat(subcmd, cmargv[j]);
+            strcat(subcmd, "\"");
+            }
+        out = pipe_and_fork(subcmd);
+        outmode = "wb";
+        }
+
     /* Check for input from a pipe (mailbox) */
 
     if(fstat(0, &statbuf) == 0){
-	if(strncmp(statbuf.st_dev, "MB", 2) == 0 || 
-	    strncmp(statbuf.st_dev, "_MB", 3) == 0){
-
-	    /* Input from a pipe, reopen it in binary mode to disable	*/
-	    /* carriage control processing.				*/
-
-	    if (in != NULL){
-		errno = EINVAL;
-		perror("Invalid '|' and '<' specified");
-		exit(EXIT_ERR);
-		}
-	    freopen(statbuf.st_dev, "rb", stdin);
-	    }
-	}
+        if(strncmp(statbuf.st_dev, "MB", 2) == 0 || 
+            strncmp(statbuf.st_dev, "_MB", 3) == 0){
+
+            /* Input from a pipe, reopen it in binary mode to disable   */
+            /* carriage control processing.                             */
+
+            if (in != NULL){
+                errno = EINVAL;
+                perror("Invalid '|' and '<' specified");
+                exit(EXIT_ERR);
+                }
+            freopen(statbuf.st_dev, "rb", stdin);
+            }
+        }
     else {
-	perror("fstat failed");
-	exit(EXIT_ERR);
-	}
+        perror("fstat failed");
+        exit(EXIT_ERR);
+        }
 
 #ifdef __ALPHA
         /*, "mbc=32", "mbf=2"))) blows up on the ALPHA cbm 11/08/92 */
@@ -1032,53 +1032,53 @@ char		***av;
         {
 #else
     if ((in != NULL) && (NULL == freopen(in, "r", stdin, "mbc=32", "mbf=2")))
-	{
+        {
 #endif
-	perror(in);    	       	/* Can't find file		*/
-	exit(EXIT_ERR);		/* Is a fatal error		*/
-	}
+        perror(in);             /* Can't find file              */
+        exit(EXIT_ERR);         /* Is a fatal error             */
+        }
 #ifdef __ALPHA
     if ((out != NULL) && (NULL == freopen(out, outmode, stdout)))
         {
 #else
     if ((out != NULL) && (NULL == freopen(out, outmode, stdout, "mbc=32", "mbf=2")))
-	{	
+        {
 #endif
-	perror(ap);		/* Error, can't write or append	*/
-	exit(EXIT_ERR);		/* Is a fatal error		*/
-	}
+        perror(ap);             /* Error, can't write or append */
+        exit(EXIT_ERR);         /* Is a fatal error             */
+        }
 
      if ( new_file ) {
-	/*
-	 * We are making an explicit output file, fstat the file and
+        /*
+         * We are making an explicit output file, fstat the file and
          * declare exit handler to be able change the file to fixed length
-	 * records if necessary. 
-	 */
-	char fname[256];
-	static int outfile_rundown(), check_outfile_filetype();
-	static stat_t ofile_stat;
-	static struct exit_control_block {
-    	    struct exit_control_block *flink;
-    	    int	(*exit_routine)();
-	    int arg_count;
-	    int *status_address;	/* arg 1 */
-	    stat_t *stat;		/* arg 2 */
-	    int exit_status;
-	    int skew[128];
-	} exit_block = 
-	    { 0, outfile_rundown, 2, &exit_block.exit_status, &ofile_stat, 0 };
-
-	if ( fstat ( fileno(stdout), &ofile_stat ) == 0 )
-	     sys$dclexh ( &exit_block );
-	else fprintf(stderr,"Error fstating stdout - %s\n",
-		strerror(errno,vaxc$errno) );
-
-	if ( fgetname ( stdout, fname, 0 ) ) check_outfile_filetype ( fname );
+         * records if necessary. 
+         */
+        char fname[256];
+        static int outfile_rundown(), check_outfile_filetype();
+        static stat_t ofile_stat;
+        static struct exit_control_block {
+            struct exit_control_block *flink;
+            int (*exit_routine)();
+            int arg_count;
+            int *status_address;        /* arg 1 */
+            stat_t *stat;               /* arg 2 */
+            int exit_status;
+            int skew[128];
+        } exit_block = 
+            { 0, outfile_rundown, 2, &exit_block.exit_status, &ofile_stat, 0 };
+
+        if ( fstat ( fileno(stdout), &ofile_stat ) == 0 )
+             sys$dclexh ( &exit_block );
+        else fprintf(stderr,"Error fstating stdout - %s\n",
+                strerror(errno,vaxc$errno) );
+
+        if ( fgetname ( stdout, fname, 0 ) ) check_outfile_filetype ( fname );
      }
 #ifdef DEBUG
     fprintf(stderr, "Arglist:\n");
     for (j = 0; j < *ac;  ++j)
-	fprintf(stderr, "argv[%d] = '%s'\n", j, argv[j]);
+        fprintf(stderr, "argv[%d] = '%s'\n", j, argv[j]);
 #endif
 }
 
@@ -1101,15 +1101,15 @@ static int check_outfile_filetype ( name )
     t = strrchr ( name, '.' );   if ( t != NULL ) *t = '\0';
 
     for ( p = binary_filetypes; *p != '\0'; p++ ) {
-	for ( t = p;
-	      (*p != '\0' ) && (strchr ( ", 	", *p ) == NULL); 
-	     p++ ) *p = toupper(*p);
-	*p = '\0';
-
-	if ( strcmp ( t, ext ) == 0 ) {
-	    binary_outfile = 1;
-	    break;
-	}
+        for ( t = p;
+              (*p != '\0' ) && (strchr ( ",     ", *p ) == NULL); 
+             p++ ) *p = toupper(*p);
+        *p = '\0';
+
+        if ( strcmp ( t, ext ) == 0 ) {
+            binary_outfile = 1;
+            break;
+        }
     }
     return binary_outfile;
 }
@@ -1126,7 +1126,7 @@ static int outfile_rundown ( reason, statbuf )
     long int fib_desc[2], devchar;
     short int iosb[4];
     $DESCRIPTOR(device, statbuf->st_dev);
-    struct fibdef fib;		/* File information block (XQP) */
+    struct fibdef fib;          /* File information block (XQP) */
     struct atrdef atr[2];
     struct fat {
       unsigned char rtype, ratattrib;
@@ -1134,7 +1134,7 @@ static int outfile_rundown ( reason, statbuf )
       unsigned short int reserved[4], versions;
     } rat;
 
-    if ( !binary_outfile ) return 1;	/* leave file alone */
+    if ( !binary_outfile ) return 1;    /* leave file alone */
     /*
      * Assign channel to device listed in stat block and test if it is
      * a directory structured device, returning if not.
@@ -1142,12 +1142,12 @@ static int outfile_rundown ( reason, statbuf )
     device.dsc$w_length = strlen ( statbuf->st_dev );
     status = sys$assign ( &device, &channel, 0, 0 );
     if ((status & 1) == 0) { fprintf(stderr, 
-	"assign error to %s (%d)\n", device.dsc$a_pointer, status);
-		return status; }
+        "assign error to %s (%d)\n", device.dsc$a_pointer, status);
+                return status; }
     code = DVI$_DEVCHAR;
     status = LIB$GETDVI ( &code, &channel, 0, &devchar );
     if ((status & 1) == 0) { fprintf(stderr, "getdvi error: %d\n", status);
-		return status; }
+                return status; }
     if ( (devchar & DEV$M_DIR) == 0 ) return 1;
     /*
      * Build File Information Block and Atrribute block.
@@ -1177,23 +1177,23 @@ static int outfile_rundown ( reason, statbuf )
     fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_WRITE;
 #endif
     status = sys$qiow ( 0, channel, IO$_ACCESS|IO$M_ACCESS,
-		 &iosb, 0, 0, &fib_desc, 0, 0, 0, &atr, 0 );
+                 &iosb, 0, 0, &fib_desc, 0, 0, 0, &atr, 0 );
     /*
      * If status successful, update record byte and perform a MODIFY.
      */
     if ( (status&1) == 1 ) status = iosb[0];
     if ( (status&1) == 1 ) {
-      rat.rtype = 1;		/* fixed length records */
-      rat.rsize = 512;  	/* 512 byte block recrods */
+      rat.rtype = 1;            /* fixed length records */
+      rat.rsize = 512;          /* 512 byte block recrods */
       rat.ratattrib = 0;        /* Record attributes: none */
 
      status = sys$qiow
-	( 0, channel, IO$_MODIFY, &iosb, 0, 0, &fib_desc, 0, 0, 0, &atr, 0 );
+        ( 0, channel, IO$_MODIFY, &iosb, 0, 0, &fib_desc, 0, 0, 0, &atr, 0 );
        if ( (status&1) == 1 ) status = iosb[0];
    }
    sys$dassgn ( channel );
    if ( (status & 1) == 0 ) fprintf ( stderr,
-	"Failed to convert output file to binary format, status: %d\n", status);
+        "Failed to convert output file to binary format, status: %d\n", status);
    return status;
 }
 
@@ -1205,24 +1205,24 @@ char *value;
 int *count;
 {
     if (*head == 0)
-	{
-	if (NULL == (*head = calloc(1, sizeof(**head))))
-	    {
-	    errno = ENOMEM;
-	    perror("");
-	    exit(EXIT_ERR);
-	    }
-	*tail = *head;
-	}
+        {
+        if (NULL == (*head = calloc(1, sizeof(**head))))
+            {
+            errno = ENOMEM;
+            perror("");
+            exit(EXIT_ERR);
+            }
+        *tail = *head;
+        }
     else
-	if (NULL == ((*tail)->next = calloc(1, sizeof(**head))))
-	    {
-	    errno = ENOMEM;
-	    perror("");
-	    exit(EXIT_ERR);
-	    }
-	else
-	    *tail = (*tail)->next;
+        if (NULL == ((*tail)->next = calloc(1, sizeof(**head))))
+            {
+            errno = ENOMEM;
+            perror("");
+            exit(EXIT_ERR);
+            }
+        else
+            *tail = (*tail)->next;
     (*tail)->value = value;
     ++(*count);
 }
@@ -1243,10 +1243,10 @@ $DESCRIPTOR(defaultspec, "SYS$DISK:[]*.*;");
 $DESCRIPTOR(resultspec, "");
 
     if (strcspn(item, "*%") == strlen(item))
-	{
-	add_item(head, tail, item, count);
-	return;
-	}
+        {
+        add_item(head, tail, item, count);
+        return;
+        }
     resultspec.dsc$b_dtype = DSC$K_DTYPE_T;
     resultspec.dsc$b_class = DSC$K_CLASS_D;
     resultspec.dsc$a_pointer = NULL;
@@ -1256,40 +1256,40 @@ $DESCRIPTOR(resultspec, "");
      */
     had_version = strchr(item, ';');
     while (1 == (1&lib$find_file(&filespec, &resultspec, &context,
-    				 &defaultspec, 0, &status_value, &0)))
-	{
-	char *string;
-	char *c;
-
-	if (NULL == (string = calloc(1, resultspec.dsc$w_length+1)))
-	    {
-	    errno = ENOMEM;
-	    perror("");
-	    exit(EXIT_ERR);
-	    }
-	strncpy(string, resultspec.dsc$a_pointer, resultspec.dsc$w_length);
-	string[resultspec.dsc$w_length] = '\0';
-	if (NULL == had_version)
-	    *((char *)strrchr(string, ';')) = '\0';
-	/*
-	 * Be consistent with what the C RTL has already done to the rest of
-	 * the argv items and lowercase all of these names.
-	 */
-	for (c = string; *c; ++c)
-	    if (isupper(*c))
-		*c = tolower(*c);
-	add_item(head, tail, string, count);
-	++expcount;
-	}
+                                 &defaultspec, 0, &status_value, &0)))
+        {
+        char *string;
+        char *c;
+
+        if (NULL == (string = calloc(1, resultspec.dsc$w_length+1)))
+            {
+            errno = ENOMEM;
+            perror("");
+            exit(EXIT_ERR);
+            }
+        strncpy(string, resultspec.dsc$a_pointer, resultspec.dsc$w_length);
+        string[resultspec.dsc$w_length] = '\0';
+        if (NULL == had_version)
+            *((char *)strrchr(string, ';')) = '\0';
+        /*
+         * Be consistent with what the C RTL has already done to the rest of
+         * the argv items and lowercase all of these names.
+         */
+        for (c = string; *c; ++c)
+            if (isupper(*c))
+                *c = tolower(*c);
+        add_item(head, tail, string, count);
+        ++expcount;
+        }
     if (expcount == 0)
-	add_item(head, tail, item, count);
+        add_item(head, tail, item, count);
     lib$sfree1_dd(&resultspec);
     lib$find_file_end(&context);
 }
 
-static int child_st[2];	/* Event Flag set when child process completes	*/
+static int child_st[2]; /* Event Flag set when child process completes  */
 
-static short child_chan;/* I/O Channel for Pipe Mailbox			*/
+static short child_chan;/* I/O Channel for Pipe Mailbox                 */
 
 static exit_handler(status)
 int *status;
@@ -1297,32 +1297,32 @@ int *status;
 short iosb[4];
 
     if (0 == child_st[0])
-	{
+        {
 #ifdef DEBUG
-	fprintf(stderr, "Waiting for Child Process to Finnish . . .\n");
+        fprintf(stderr, "Waiting for Child Process to Finnish . . .\n");
 #endif
-	fflush(stdout);	    /* Have to flush pipe for binary data to	*/
-			    /* terminate properly -- <[email protected]>	*/
+        fflush(stdout);     /* Have to flush pipe for binary data to    */
+                            /* terminate properly -- <[email protected]>    */
 #ifdef DEBUG
-	fprintf(stderr, "    stdout flushed. . .\n");
+        fprintf(stderr, "    stdout flushed. . .\n");
 #endif
-	sys$qio(0, child_chan, IO$_WRITEOF, iosb, 0, 0, 0, 0, 0, 0, 0, 0);
+        sys$qio(0, child_chan, IO$_WRITEOF, iosb, 0, 0, 0, 0, 0, 0, 0, 0);
 #ifdef DEBUG
-	fprintf(stderr, "    Pipe terminated. . .\n");
+        fprintf(stderr, "    Pipe terminated. . .\n");
 #endif
-	fclose(stdout);
+        fclose(stdout);
 #ifdef DEBUG
-	fprintf(stderr, "    stdout closed. . .\n");
+        fprintf(stderr, "    stdout closed. . .\n");
 #endif
-	sys$synch(0, child_st);
-	sys$dassgn(child_chan);
-	}
+        sys$synch(0, child_st);
+        sys$dassgn(child_chan);
+        }
 #ifdef DEBUG
-	fprintf(stderr, "    sync done. . .\n");
+        fprintf(stderr, "    sync done. . .\n");
 #endif
 }
 
-#include <syidef>		/* System Information Definitions	*/
+#include <syidef>               /* System Information Definitions       */
 
 static sig_child(chan)
 int chan;
@@ -1331,14 +1331,14 @@ int chan;
     fprintf(stderr, "Child Completion AST, st: %x\n", child_st[0] );
 #endif
     if (child_st[0] == 0)
-	{ child_st[0] = 1; }
+        { child_st[0] = 1; }
     sys$setef ( 0 );
 }
 
 static struct exit_control_block
     {
     struct exit_control_block *flink;
-    int	(*exit_routine)();
+    int (*exit_routine)();
     int arg_count;
     int *status_address;
     int exit_status;
@@ -1361,36 +1361,36 @@ char *cmd;
     int status;
     int pid;
     struct
-	{
-	short dna_buflen;
-	short dna_itmcod;
-	char *dna_buffer;
-	short *dna_retlen;
-	int listend;
-	} itmlst =
-	{
-	sizeof(mbxname),
-	DVI$_DEVNAM,
-	mbxname,
-	&mbxdsc.dsc$w_length,
-	0
-	};
+        {
+        short dna_buflen;
+        short dna_itmcod;
+        char *dna_buffer;
+        short *dna_retlen;
+        int listend;
+        } itmlst =
+        {
+        sizeof(mbxname),
+        DVI$_DEVNAM,
+        mbxname,
+        &mbxdsc.dsc$w_length,
+        0
+        };
     int mbxsize;
     struct
-	{
-	short mbf_buflen;
-	short mbf_itmcod;
-	int *mbf_maxbuf;
-	short *mbf_retlen;
-	int listend;
-	} syiitmlst =
-	{
-	sizeof(mbxsize),
-	SYI$_MAXBUF,
-	&mbxsize,
-	0,
-	0
-	};
+        {
+        short mbf_buflen;
+        short mbf_itmcod;
+        int *mbf_maxbuf;
+        short *mbf_retlen;
+        int listend;
+        } syiitmlst =
+        {
+        sizeof(mbxsize),
+        SYI$_MAXBUF,
+        &mbxsize,
+        0,
+        0
+        };
 
     cmddsc.dsc$w_length = strlen(cmd);
     /*
@@ -1398,42 +1398,42 @@ char *cmd;
      * the size of the 'pipe' mailbox.
      */
     if (1 == (1&(vaxc$errno = sys$getsyiw(0, 0, 0, &syiitmlst, iosb, 0, 0, 0))))
-	vaxc$errno = iosb[0];
+        vaxc$errno = iosb[0];
     if (0 == (1&vaxc$errno))
-	{
- 	errno = EVMSERR;
-	perror("Can't get SYSGEN parameter value for MAXBUF");
-	exit(EXIT_ERR);
-	}
+        {
+        errno = EVMSERR;
+        perror("Can't get SYSGEN parameter value for MAXBUF");
+        exit(EXIT_ERR);
+        }
     if (mbxsize > 2048)
-	mbxsize = 2048;
+        mbxsize = 2048;
     if (0 == (1&(vaxc$errno = sys$crembx(0, &child_chan, mbxsize, mbxsize, 0, 0, 0))))
-	{
-	errno = EVMSERR;
-	perror("Can't create pipe mailbox");
-	exit(EXIT_ERR);
-	}
+        {
+        errno = EVMSERR;
+        perror("Can't create pipe mailbox");
+        exit(EXIT_ERR);
+        }
     if (1 == (1&(vaxc$errno = sys$getdviw(0, child_chan, 0, &itmlst, iosb,
-    					  0, 0, 0))))
-	vaxc$errno = iosb[0];
+                                          0, 0, 0))))
+        vaxc$errno = iosb[0];
     if (0 == (1&vaxc$errno))
-	{
- 	errno = EVMSERR;
-	perror("Can't get pipe mailbox device name");
-	exit(EXIT_ERR);
-	}
+        {
+        errno = EVMSERR;
+        perror("Can't get pipe mailbox device name");
+        exit(EXIT_ERR);
+        }
     mbxname[mbxdsc.dsc$w_length] = '\0';
 #ifdef DEBUG
     fprintf(stderr, "Pipe Mailbox Name = '%s'\n", mbxname);
 #endif
     if (0 == (1&(vaxc$errno = lib$spawn(&cmddsc, &mbxdsc, 0, &1,
-    					0, &pid, child_st, &ef, sig_child,
-    					&child_chan))))
-	{
-	errno = EVMSERR;
-	perror("Can't spawn subprocess");
-	exit(EXIT_ERR);
-	}
+                                        0, &pid, child_st, &ef, sig_child,
+                                        &child_chan))))
+        {
+        errno = EVMSERR;
+        perror("Can't spawn subprocess");
+        exit(EXIT_ERR);
+        }
 #ifdef DEBUG
     fprintf(stderr, "Subprocess's Pid = %08X\n", pid);
 #endif
@@ -1453,24 +1453,24 @@ int pid;
 
     strcat(command, argv[0]);
     while (--argc)
-	{
-	strcat(command, " \"");
-	strcat(command, *(++argv));
-	strcat(command, "\"");
-	}
+        {
+        strcat(command, " \"");
+        strcat(command, *(++argv));
+        strcat(command, "\"");
+        }
     value.dsc$w_length = strlen(command);
     if (0 == (1&(vaxc$errno = lib$set_symbol(&cmd, &value))))
-	{
-	errno = EVMSERR;
-	perror("Can't create symbol for subprocess command");
-	exit(EXIT_ERR);
-	}
+        {
+        errno = EVMSERR;
+        perror("Can't create symbol for subprocess command");
+        exit(EXIT_ERR);
+        }
     if (0 == (1&(vaxc$errno = lib$spawn(&cmd, &null, 0, &17, 0, &pid))))
-	{
-	errno = EVMSERR;
-	perror("Can't spawn subprocess");
-	exit(EXIT_ERR);
-	}
+        {
+        errno = EVMSERR;
+        perror("Can't spawn subprocess");
+        exit(EXIT_ERR);
+        }
 #ifdef DEBUG
     fprintf(stderr, "%s\n", command);
 #endif
@@ -1480,70 +1480,70 @@ int pid;
 
 /* got this off net.sources */
 
-#ifdef	VMS
-#define	index	strchr
-#endif	/*VMS*/
+#ifdef  VMS
+#define index   strchr
+#endif  /*VMS*/
 
 /*
  * get option letter from argument vector
  */
-int	opterr = 1,		/* useless, never set or used */
-	optind = 1,		/* index into parent argv vector */
-	optopt;			/* character checked for validity */
-char	*optarg;		/* argument associated with option */
+int     opterr = 1,             /* useless, never set or used */
+        optind = 1,             /* index into parent argv vector */
+        optopt;                 /* character checked for validity */
+char    *optarg;                /* argument associated with option */
 
-#define BADCH	(int)'?'
-#define EMSG	""
-#define tell(s)	fputs(progname,stderr);fputs(s,stderr); \
-		fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);
+#define BADCH   (int)'?'
+#define EMSG    ""
+#define tell(s) fputs(progname,stderr);fputs(s,stderr); \
+                fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);
 
 getopt(nargc,nargv,ostr)
-int	nargc;
-char	**nargv,
-	*ostr;
+int     nargc;
+char    **nargv,
+        *ostr;
 {
-	static char	*place = EMSG;	/* option letter processing */
-	register char	*oli;		/* option letter list index */
-	char	*index();
-	char *progname;
-
-	if(!*place) {			/* update scanning pointer */
-		if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF);
-		if (*place == '-') {	/* found "--" */
-			++optind;
-			return(EOF);
-		}
-	}				/* option letter okay? */
-	if ((optopt = (int)*place++) == (int)':' || !(oli = index(ostr,optopt))) {
-		if(!*place) ++optind;
+        static char     *place = EMSG;  /* option letter processing */
+        register char   *oli;           /* option letter list index */
+        char    *index();
+        char *progname;
+
+        if(!*place) {                   /* update scanning pointer */
+                if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF);
+                if (*place == '-') {    /* found "--" */
+                        ++optind;
+                        return(EOF);
+                }
+        }                               /* option letter okay? */
+        if ((optopt = (int)*place++) == (int)':' || !(oli = index(ostr,optopt))) {
+                if(!*place) ++optind;
 #ifdef VMS
-		progname = strrchr(nargv[0],']');
+                progname = strrchr(nargv[0],']');
 #else
-		progname = rindex(nargv[0],'/');
+                progname = rindex(nargv[0],'/');
 #endif
-		if (!progname) progname = nargv[0]; else progname++;
-		tell(": illegal option -- ");
-	}
-	if (*++oli != ':') {		/* don't need argument */
-		optarg = NULL;
-		if (!*place) ++optind;
-	}
-	else {				/* need an argument */
-		if (*place) optarg = place;	/* no white space */
-		else if (nargc <= ++optind) {	/* no arg */
-			place = EMSG;
+                if (!progname) progname = nargv[0]; else progname++;
+                tell(": illegal option -- ");
+        }
+        if (*++oli != ':') {            /* don't need argument */
+                optarg = NULL;
+                if (!*place) ++optind;
+        }
+        else {                          /* need an argument */
+                if (*place) optarg = place;     /* no white space */
+                else if (nargc <= ++optind) {   /* no arg */
+                        place = EMSG;
 #ifdef VMS
-			progname = strrchr(nargv[0],']');
+                        progname = strrchr(nargv[0],']');
 #else
-			progname = rindex(nargv[0],'/');
+                        progname = rindex(nargv[0],'/');
 #endif
-			if (!progname) progname = nargv[0]; else progname++;
-			tell(": option requires an argument -- ");
-		}
-	 	else optarg = nargv[optind];	/* white space */
-		place = EMSG;
-		++optind;
-	}
-	return(optopt);			/* dump back option letter */
+                        if (!progname) progname = nargv[0]; else progname++;
+                        tell(": option requires an argument -- ");
+                }
+                else optarg = nargv[optind];    /* white space */
+                place = EMSG;
+                ++optind;
+        }
+        return(optopt);                 /* dump back option letter */
 }
 #endif /* VMS */

+ 36 - 36
panda/src/pnm/libpbm2.c

@@ -21,13 +21,13 @@ pbm_getbit( file )
     register char ch;
 
     do
-	{
-	ch = pbm_getc( file );
-	}
+        {
+        ch = pbm_getc( file );
+        }
     while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
 
     if ( ch != '0' && ch != '1' )
-	pm_error( "junk in file where bits should be" );
+        pm_error( "junk in file where bits should be" );
 
     return ( ch == '1' ) ? 1 : 0;
     }
@@ -40,10 +40,10 @@ pbm_readmagicnumber( file )
 
     ich1 = getc( file );
     if ( ich1 == EOF )
-	pm_error( "EOF / read error reading magic number" );
+        pm_error( "EOF / read error reading magic number" );
     ich2 = getc( file );
     if ( ich2 == EOF )
-	pm_error( "EOF / read error reading magic number" );
+        pm_error( "EOF / read error reading magic number" );
     return ich1 * 256 + ich2;
     }
 
@@ -68,14 +68,14 @@ pbm_readpbminit( file, colsP, rowsP, formatP )
     /* Check magic number. */
     *formatP = pbm_readmagicnumber( file );
     switch ( PBM_FORMAT_TYPE(*formatP) )
-	{
+        {
         case PBM_TYPE:
-	pbm_readpbminitrest( file, colsP, rowsP );
-	break;
+        pbm_readpbminitrest( file, colsP, rowsP );
+        break;
 
-	default:
-	pm_error( "bad magic number - not a pbm file" );
-	}
+        default:
+        pm_error( "bad magic number - not a pbm file" );
+        }
     }
 
 void
@@ -89,29 +89,29 @@ pbm_readpbmrow( file, bitrow, cols, format )
     register bit* bP;
 
     switch ( format )
-	{
-	case PBM_FORMAT:
-	for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
-	    *bP = pbm_getbit( file );
-	break;
-
-	case RPBM_FORMAT:
-	bitshift = -1;
-	for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
-	    {
-	    if ( bitshift == -1 )
-		{
-		item = pbm_getrawbyte( file );
-		bitshift = 7;
-		}
-	    *bP = ( item >> bitshift ) & 1;
-	    --bitshift;
-	    }
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PBM_FORMAT:
+        for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
+            *bP = pbm_getbit( file );
+        break;
+
+        case RPBM_FORMAT:
+        bitshift = -1;
+        for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
+            {
+            if ( bitshift == -1 )
+                {
+                item = pbm_getrawbyte( file );
+                bitshift = 7;
+                }
+            *bP = ( item >> bitshift ) & 1;
+            --bitshift;
+            }
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 bit**
@@ -128,7 +128,7 @@ pbm_readpbm( file, colsP, rowsP )
     bits = pbm_allocarray( *colsP, *rowsP );
 
     for ( row = 0; row < *rowsP; ++row )
-	pbm_readpbmrow( file, bits[row], *colsP, format );
+        pbm_readpbmrow( file, bits[row], *colsP, format );
 
     return bits;
     }

+ 26 - 26
panda/src/pnm/libpbm3.c

@@ -25,13 +25,13 @@ pbm_writepbminit( file, cols, rows, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( ! forceplain ) {
-	fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, RPBM_MAGIC2, cols, rows );
+        fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, RPBM_MAGIC2, cols, rows );
 #ifdef VMS
         set_outfile_binary();
 #endif
         }
     else
-	fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
+        fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
 #else /*PBMPLUS_RAWBITS*/
     fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
 #endif /*PBMPLUS_RAWBITS*/
@@ -51,19 +51,19 @@ pbm_writepbmrowraw( file, bitrow, cols )
     bitshift = 7;
     item = 0;
     for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
-	{
-	if ( *bP )
-	    item += 1 << bitshift;
-	--bitshift;
-	if ( bitshift == -1 )
-	    {
-	    (void) putc( item, file );
-	    bitshift = 7;
-	    item = 0;
-	    }
-	}
+        {
+        if ( *bP )
+            item += 1 << bitshift;
+        --bitshift;
+        if ( bitshift == -1 )
+            {
+            (void) putc( item, file );
+            bitshift = 7;
+            item = 0;
+            }
+        }
     if ( bitshift != 7 )
-	(void) putc( item, file );
+        (void) putc( item, file );
     }
 #endif /*PBMPLUS_RAWBITS*/
 
@@ -78,15 +78,15 @@ pbm_writepbmrowplain( file, bitrow, cols )
 
     charcount = 0;
     for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
-	{
-	if ( charcount >= 70 )
-	    {
-	    (void) putc( '\n', file );
-	    charcount = 0;
-	    }
-	(void) putc( *bP ? '1' : '0', file );
-	++charcount;
-	}
+        {
+        if ( charcount >= 70 )
+            {
+            (void) putc( '\n', file );
+            charcount = 0;
+            }
+        (void) putc( *bP ? '1' : '0', file );
+        ++charcount;
+        }
     (void) putc( '\n', file );
     }
 
@@ -99,9 +99,9 @@ pbm_writepbmrow( file, bitrow, cols, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( ! forceplain )
-	pbm_writepbmrowraw( file, bitrow, cols );
+        pbm_writepbmrowraw( file, bitrow, cols );
     else
-	pbm_writepbmrowplain( file, bitrow, cols );
+        pbm_writepbmrowplain( file, bitrow, cols );
 #else /*PBMPLUS_RAWBITS*/
     pbm_writepbmrowplain( file, bitrow, cols );
 #endif /*PBMPLUS_RAWBITS*/
@@ -119,5 +119,5 @@ pbm_writepbm( file, bits, cols, rows, forceplain )
     pbm_writepbminit( file, cols, rows, forceplain );
 
     for ( row = 0; row < rows; ++row )
-	pbm_writepbmrow( file, bits[row], cols, forceplain );
+        pbm_writepbmrow( file, bits[row], cols, forceplain );
     }

+ 19 - 19
panda/src/pnm/libpbm4.c

@@ -22,20 +22,20 @@ pbm_getc( file )
 
     ich = getc( file );
     if ( ich == EOF )
-	pm_error( "EOF / read error" );
+        pm_error( "EOF / read error" );
     ch = (char) ich;
     
     if ( ch == '#' )
-	{
-	do
-	    {
-	    ich = getc( file );
-	    if ( ich == EOF )
-		pm_error( "EOF / read error" );
-	    ch = (char) ich;
-	    }
-	while ( ch != '\n' && ch != '\r' );
-	}
+        {
+        do
+            {
+            ich = getc( file );
+            if ( ich == EOF )
+                pm_error( "EOF / read error" );
+            ch = (char) ich;
+            }
+        while ( ch != '\n' && ch != '\r' );
+        }
 
     return ch;
     }
@@ -48,7 +48,7 @@ pbm_getrawbyte( file )
 
     iby = getc( file );
     if ( iby == EOF )
-	pm_error( "EOF / read error" );
+        pm_error( "EOF / read error" );
     return (unsigned char) iby;
     }
 
@@ -60,19 +60,19 @@ pbm_getint( file )
     register int i;
 
     do
-	{
-	ch = pbm_getc( file );
-	}
+        {
+        ch = pbm_getc( file );
+        }
     while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
 
     if ( ch < '0' || ch > '9' )
-	pm_error( "junk in file where an integer should be" );
+        pm_error( "junk in file where an integer should be" );
 
     i = 0;
     do
-	{
-	i = i * 10 + ch - '0';
-	ch = pbm_getc( file );
+        {
+        i = i * 10 + ch - '0';
+        ch = pbm_getc( file );
         }
     while ( ch >= '0' && ch <= '9' );
 

+ 267 - 267
panda/src/pnm/libpbm5.c

@@ -642,37 +642,37 @@ static struct font default_bdffont = { 14, 15, -1, -3, {
 
 struct font*
 pbm_defaultfont( name )
-	char* name;
+        char* name;
     {
     bit** defaultfont;
     int row, col, scol;
     unsigned long l;
 
     if (!strcmp(name, "bdf"))
-	return &default_bdffont;
+        return &default_bdffont;
 
     if (strcmp(name, "fixed"))
-	pm_error( "built-in font name unknown, try 'bdf' or 'fixed'" );
+        pm_error( "built-in font name unknown, try 'bdf' or 'fixed'" );
 
     defaultfont = pbm_allocarray( DEFAULTFONT_COLS, DEFAULTFONT_ROWS );
     for ( row = 0; row < DEFAULTFONT_ROWS; ++row )
-	{
-	for ( col = 0; col < DEFAULTFONT_COLS; col += 32 )
-	    {
-	    l = defaultfont_bits[row][col / 32];
-	    for ( scol = min( col + 32, DEFAULTFONT_COLS ) - 1;
-		  scol >= col; --scol )
-		{
-		if ( l & 1 )
-		    defaultfont[row][scol] = 1;
-		else
-		    defaultfont[row][scol] = 0;
-		l >>= 1;
-		}
-	    }
-	}
-
-	return pbm_dissectfont( defaultfont, DEFAULTFONT_ROWS, DEFAULTFONT_COLS );
+        {
+        for ( col = 0; col < DEFAULTFONT_COLS; col += 32 )
+            {
+            l = defaultfont_bits[row][col / 32];
+            for ( scol = min( col + 32, DEFAULTFONT_COLS ) - 1;
+                  scol >= col; --scol )
+                {
+                if ( l & 1 )
+                    defaultfont[row][scol] = 1;
+                else
+                    defaultfont[row][scol] = 0;
+                l >>= 1;
+                }
+            }
+        }
+
+        return pbm_dissectfont( defaultfont, DEFAULTFONT_ROWS, DEFAULTFONT_COLS );
     }
 
 struct font*
@@ -719,27 +719,27 @@ pbm_dissectfont( font, frows, fcols )
 
     /* Find first blank row. */
     for ( brow = 0; brow < frows / 6; ++brow )
-	{
-	b = font[brow][0];
-	for ( col = 1; col < fcols; ++col )
-	    if ( font[brow][col] != b )
-		goto nextrow;
-	goto gotblankrow;
+        {
+        b = font[brow][0];
+        for ( col = 1; col < fcols; ++col )
+            if ( font[brow][col] != b )
+                goto nextrow;
+        goto gotblankrow;
     nextrow: ;
-	}
+        }
     pm_error( "couldn't find blank row in font" );
 
 gotblankrow:
     /* Find first blank col. */
     for ( bcol = 0; bcol < fcols / 8; ++bcol )
-	{
-	b = font[0][bcol];
-	for ( row = 1; row < frows; ++row )
-	    if ( font[row][bcol] != b )
-		goto nextcol;
-	goto gotblankcol;
+        {
+        b = font[0][bcol];
+        for ( row = 1; row < frows; ++row )
+            if ( font[row][bcol] != b )
+                goto nextcol;
+        goto gotblankcol;
     nextcol: ;
-	}
+        }
     pm_error( "couldn't find blank col in font" );
 
 gotblankcol:
@@ -747,11 +747,11 @@ gotblankcol:
     d = frows - brow;
     char_height = d / 11;
     if ( char_height * 11 != d )
-	pm_error( "problem computing character cell height" );
+        pm_error( "problem computing character cell height" );
     d = fcols - bcol;
     char_width = d / 15;
     if ( char_width * 15 != d )
-	pm_error( "problem computing character cell width" );
+        pm_error( "problem computing character cell width" );
     char_aheight = brow;
     char_awidth = bcol;
 
@@ -759,51 +759,51 @@ gotblankcol:
 
     fn = (struct font*) malloc( sizeof(struct font) );
     if ( fn == (struct font*) 0 )
-	pm_error( "out of memory allocating font structure" );
+        pm_error( "out of memory allocating font structure" );
 
     fn->maxwidth = char_awidth;
     fn->maxheight = char_height;
     fn->x = fn->y = 0;
     for (i = 0; i < 256; i++)
-	fn->glyph[i] = 0;
+        fn->glyph[i] = 0;
     fn->oldfont = font;
     fn->frows = frows;
     fn->fcols = fcols;
     
     glyph = (struct glyph*) malloc( sizeof(struct glyph) * 95 );
     if ( glyph == (struct glyph*) 0 )
-	pm_error( "out of memory allocating glyphs" );
+        pm_error( "out of memory allocating glyphs" );
     
     bmap = (char*) malloc( fn->maxwidth * fn->maxheight * 95 );
     if ( bmap == (char*) 0)
-	pm_error( "out of memory allocating glyph data" );
+        pm_error( "out of memory allocating glyph data" );
 
     /* Now fill in the 0,0 coords. */
     row = char_height * 2;
     col = char_width * 2;
     for ( ch = 0; ch < 95; ++ch )
-	{
-	glyph[ch].width = fn->maxwidth;
-	glyph[ch].height = fn->maxheight;
-	glyph[ch].x = glyph[ch].y = 0;
-	glyph[ch].xadd = char_width;
-
-	for ( r = 0; r < glyph[ch].height; ++r )
-	    for ( c = 0; c < glyph[ch].width; ++c )
-		bmap[r * glyph[ch].width + c] = font[row + r][col + c];
-	
-	glyph[ch].bmap = bmap;
-	bmap += glyph[ch].width * glyph[ch].height;
-
-	fn->glyph[ch + 32] = glyph + ch;
-
-	col += char_width;
-	if ( col >= char_width * 14 )
-	    {
-	    col = char_width * 2;
-	    row += char_height;
-	    }
-	}
+        {
+        glyph[ch].width = fn->maxwidth;
+        glyph[ch].height = fn->maxheight;
+        glyph[ch].x = glyph[ch].y = 0;
+        glyph[ch].xadd = char_width;
+
+        for ( r = 0; r < glyph[ch].height; ++r )
+            for ( c = 0; c < glyph[ch].width; ++c )
+                bmap[r * glyph[ch].width + c] = font[row + r][col + c];
+
+        glyph[ch].bmap = bmap;
+        bmap += glyph[ch].width * glyph[ch].height;
+
+        fn->glyph[ch + 32] = glyph + ch;
+
+        col += char_width;
+        if ( col >= char_width * 14 )
+            {
+            col = char_width * 2;
+            row += char_height;
+            }
+        }
     
     return fn;
     }
@@ -821,17 +821,17 @@ char* filename;
     pm_close( fp );
 
     if (line[0] == PBM_MAGIC1 && 
-	(line[1] == PBM_MAGIC2 || line[1] == RPBM_MAGIC2))
+        (line[1] == PBM_MAGIC2 || line[1] == RPBM_MAGIC2))
     {
-	return pbm_loadpbmfont( filename );
+        return pbm_loadpbmfont( filename );
     }
     else if (!strncmp(line, "STARTFONT", 9)) {
-	if (!(fn = pbm_loadbdffont( filename )))
-	    pm_error( "could not load BDF font file" );
-	return fn;
+        if (!(fn = pbm_loadbdffont( filename )))
+            pm_error( "could not load BDF font file" );
+        return fn;
     }
     else
-	pm_error( "font file not in a recognized format ");
+        pm_error( "font file not in a recognized format ");
     return NULL; /* to make compiler happy; can't get here. */
 }
 
@@ -857,80 +857,80 @@ pbm_dumpfont( fn )
     unsigned long l;
 
     if (fn->oldfont) {
-	printf( "#define DEFAULTFONT_ROWS %d\n", fn->frows );
-	printf( "#define DEFAULTFONT_COLS %d\n", fn->fcols );
-	printf( "static unsigned long defaultfont_bits[DEFAULTFONT_ROWS][(DEFAULTFONT_COLS+31)/32] = {\n" );
-	for ( row = 0; row < fn->frows; ++row )
-	    {
-	    lperrow = 0;
-	    for ( col = 0; col < fn->fcols; col += 32 )
-		{
-		if ( lperrow == 0 )
-		    printf( "    {" );
-		else if ( lperrow % 6 == 0 )
-		    {
-		    printf( ",\n     " );
-		    lperrow = 0;
-		    }
-		else
-		    printf( "," );
-		l = 0;
-		for ( scol = col; scol < min( col + 32, fn->fcols ); ++scol )
-		    {
-		    l <<= 1;
-		    if ( fn->oldfont[row][scol] )
-			l |= 1;
-		    }
-		printf( "0x%08lxL", l );
-		++lperrow;
-		}
-	    printf( "}%s\n", row == fn->frows - 1 ? "" : "," );
-	    }
-	printf( "    };\n" );
+        printf( "#define DEFAULTFONT_ROWS %d\n", fn->frows );
+        printf( "#define DEFAULTFONT_COLS %d\n", fn->fcols );
+        printf( "static unsigned long defaultfont_bits[DEFAULTFONT_ROWS][(DEFAULTFONT_COLS+31)/32] = {\n" );
+        for ( row = 0; row < fn->frows; ++row )
+            {
+            lperrow = 0;
+            for ( col = 0; col < fn->fcols; col += 32 )
+                {
+                if ( lperrow == 0 )
+                    printf( "    {" );
+                else if ( lperrow % 6 == 0 )
+                    {
+                    printf( ",\n     " );
+                    lperrow = 0;
+                    }
+                else
+                    printf( "," );
+                l = 0;
+                for ( scol = col; scol < min( col + 32, fn->fcols ); ++scol )
+                    {
+                    l <<= 1;
+                    if ( fn->oldfont[row][scol] )
+                        l |= 1;
+                    }
+                printf( "0x%08lxL", l );
+                ++lperrow;
+                }
+            printf( "}%s\n", row == fn->frows - 1 ? "" : "," );
+            }
+        printf( "    };\n" );
     }
     else {
-	struct glyph* glyph;
-	int i, j, ng;
-
-	ng = 0;
-	for (i = 0; i < 256; i++)
-		if (fn->glyph[i])
-			ng++;
-
-	printf("static struct glyph _g[%d] = {\n", ng);
-	for (i = 0; i < 256; i++) {
-		if (!(glyph = fn->glyph[i]))
-			continue;
-
-		printf(" { %d, %d, %d, %d, %d, \"", glyph->width, glyph->height,
-			glyph->x, glyph->y, glyph->xadd);
-
-		for (j = 0; j < glyph->width * glyph->height; j++)
-			if (glyph->bmap[j])
-				printf("\\1");
-			else
-				printf("\\0");
-		
-		ng--;
-		printf("\" }%s\n", ng ? "," : "");
-	}
-	printf("};\n");
-
-	printf("static struct font default_bdffont = { %d, %d, %d, %d, {\n",
-		fn->maxwidth, fn->maxheight, fn->x, fn->y);
-
-	for (i = 0; i < 256; i++) {
-		if (fn->glyph[i])
-			printf(" _g + %d", ng++);
-		else
-			printf(" 0");
-		
-		if (i != 255) printf(",");
-		printf("\n");
-	}
-
-	printf(" }\n};\n");
-	exit(0);
+        struct glyph* glyph;
+        int i, j, ng;
+
+        ng = 0;
+        for (i = 0; i < 256; i++)
+                if (fn->glyph[i])
+                        ng++;
+
+        printf("static struct glyph _g[%d] = {\n", ng);
+        for (i = 0; i < 256; i++) {
+                if (!(glyph = fn->glyph[i]))
+                        continue;
+
+                printf(" { %d, %d, %d, %d, %d, \"", glyph->width, glyph->height,
+                        glyph->x, glyph->y, glyph->xadd);
+
+                for (j = 0; j < glyph->width * glyph->height; j++)
+                        if (glyph->bmap[j])
+                                printf("\\1");
+                        else
+                                printf("\\0");
+
+                ng--;
+                printf("\" }%s\n", ng ? "," : "");
+        }
+        printf("};\n");
+
+        printf("static struct font default_bdffont = { %d, %d, %d, %d, {\n",
+                fn->maxwidth, fn->maxheight, fn->x, fn->y);
+
+        for (i = 0; i < 256; i++) {
+                if (fn->glyph[i])
+                        printf(" _g + %d", ng++);
+                else
+                        printf(" 0");
+
+                if (i != 255) printf(",");
+                printf("\n");
+        }
+
+        printf(" }\n};\n");
+        exit(0);
 
     }
 
@@ -942,117 +942,117 @@ pbm_dumpfont( fn )
 static int readline ARGS((FILE* fp, char* buf, char* arg[]));
 
 #define expect(str) if (readline(fp, line, arg) < 0 || strcmp(arg[0], (str))) \
-	{ fclose(fp); return 0; }
+        { fclose(fp); return 0; }
 
 struct font* pbm_loadbdffont(name)
 char* name;
 {
-	FILE* fp;
-	char line[1024], *arg[32], *b, *hex;
-	int i, n, numchar, hdig, encoding;
-	struct font* font;
-	struct glyph* glyph;
-
-	if (!(fp = fopen(name, "r")))
-		return 0;
-
-	expect("STARTFONT");
-
-	if (!(font = (struct font*)malloc(sizeof(struct font))))
-		pm_error("no memory for font");
-	font->oldfont = 0;
-	for (i = 0; i < 256; i++)
-		font->glyph[i] = 0;
-
-	while (readline(fp, line, arg) >= 0) {
-		if (!strcmp(arg[0], "COMMENT"))
-			continue;
-		if (!strcmp(arg[0], "SIZE"))
-			continue;
-		
-		if (!strcmp(arg[0], "STARTPROPERTIES")) {
-			n = atoi(arg[1]);
-			for (; n > 0 && readline(fp, line, arg) >= 0; n--)
-				;
-		}
-		else if (!strcmp(arg[0], "FONTBOUNDINGBOX")) {
-			font->maxwidth = atoi(arg[1]);
-			font->maxheight = atoi(arg[2]);
-			font->x = atoi(arg[3]);
-			font->y = atoi(arg[4]);
-		}
-		else if (!strcmp(arg[0], "ENDFONT")) {
-			fclose(fp);
-			return font;
-		}
-		else if (!strcmp(arg[0], "CHARS")) {
-			numchar = atoi(arg[1]);
-			while (numchar > 0) {
-				if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
-				if (!strcmp(arg[0], "COMMENT"))
-					continue;
-				if (strcmp(arg[0], "STARTCHAR")) { fclose(fp); return 0; }
-				if (!(glyph = (struct glyph*)malloc(sizeof(struct glyph))))
-					pm_error("no memory for font glyph");
-
-				expect("ENCODING");
-				if ((encoding = atoi(arg[1])) < 0) {
-					if (arg[2])
-						encoding = atoi(arg[2]);
-					else {
-						while (readline(fp, line, arg) >= 0)
-							if (!strcmp(arg[0], "ENDCHAR"))
-								break;
-						
-						numchar--;
-						continue;
-					}
-				}
-				expect("SWIDTH");
-				expect("DWIDTH");
-				glyph->xadd = atoi(arg[1]);
-				expect("BBX");
-				glyph->width = atoi(arg[1]);
-				glyph->height = atoi(arg[2]);
-				glyph->x = atoi(arg[3]);
-				glyph->y = atoi(arg[4]);
-
-				if (!(glyph->bmap = (char*)malloc(glyph->width * glyph->height)))
-					pm_error("no memory for font glyph byte map");
-
-				if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
-				if (!strcmp(arg[0], "ATTRIBUTES"))
-					if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
-				
-				b = glyph->bmap;
-				for (n = glyph->height; n > 0; n--) {
-					if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
-					hex = line;
-					for (i = glyph->width; i > 0; i -= 4) {
-						hdig = *hex++;
-						if (hdig >= '0' && hdig <= '9')
-							hdig -= '0';
-						else if (hdig >= 'a' && hdig <= 'f')
-							hdig -= 'a' - 10;
-						else if (hdig >= 'A' && hdig <= 'F')
-							hdig -= 'A' - 10;
-						
-						*b++ = hdig & 8 ? 1 : 0;
-						if (i > 1) *b++ = hdig & 4 ? 1 : 0;
-						if (i > 2) *b++ = hdig & 2 ? 1 : 0;
-						if (i > 3) *b++ = hdig & 1;
-					}
-				}
-
-				expect("ENDCHAR");
-
-				font->glyph[encoding] = glyph;
-
-				numchar--;
-			}
-		}
-	}
-	return font;
+        FILE* fp;
+        char line[1024], *arg[32], *b, *hex;
+        int i, n, numchar, hdig, encoding;
+        struct font* font;
+        struct glyph* glyph;
+
+        if (!(fp = fopen(name, "r")))
+                return 0;
+
+        expect("STARTFONT");
+
+        if (!(font = (struct font*)malloc(sizeof(struct font))))
+                pm_error("no memory for font");
+        font->oldfont = 0;
+        for (i = 0; i < 256; i++)
+                font->glyph[i] = 0;
+
+        while (readline(fp, line, arg) >= 0) {
+                if (!strcmp(arg[0], "COMMENT"))
+                        continue;
+                if (!strcmp(arg[0], "SIZE"))
+                        continue;
+
+                if (!strcmp(arg[0], "STARTPROPERTIES")) {
+                        n = atoi(arg[1]);
+                        for (; n > 0 && readline(fp, line, arg) >= 0; n--)
+                                ;
+                }
+                else if (!strcmp(arg[0], "FONTBOUNDINGBOX")) {
+                        font->maxwidth = atoi(arg[1]);
+                        font->maxheight = atoi(arg[2]);
+                        font->x = atoi(arg[3]);
+                        font->y = atoi(arg[4]);
+                }
+                else if (!strcmp(arg[0], "ENDFONT")) {
+                        fclose(fp);
+                        return font;
+                }
+                else if (!strcmp(arg[0], "CHARS")) {
+                        numchar = atoi(arg[1]);
+                        while (numchar > 0) {
+                                if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
+                                if (!strcmp(arg[0], "COMMENT"))
+                                        continue;
+                                if (strcmp(arg[0], "STARTCHAR")) { fclose(fp); return 0; }
+                                if (!(glyph = (struct glyph*)malloc(sizeof(struct glyph))))
+                                        pm_error("no memory for font glyph");
+
+                                expect("ENCODING");
+                                if ((encoding = atoi(arg[1])) < 0) {
+                                        if (arg[2])
+                                                encoding = atoi(arg[2]);
+                                        else {
+                                                while (readline(fp, line, arg) >= 0)
+                                                        if (!strcmp(arg[0], "ENDCHAR"))
+                                                                break;
+
+                                                numchar--;
+                                                continue;
+                                        }
+                                }
+                                expect("SWIDTH");
+                                expect("DWIDTH");
+                                glyph->xadd = atoi(arg[1]);
+                                expect("BBX");
+                                glyph->width = atoi(arg[1]);
+                                glyph->height = atoi(arg[2]);
+                                glyph->x = atoi(arg[3]);
+                                glyph->y = atoi(arg[4]);
+
+                                if (!(glyph->bmap = (char*)malloc(glyph->width * glyph->height)))
+                                        pm_error("no memory for font glyph byte map");
+
+                                if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
+                                if (!strcmp(arg[0], "ATTRIBUTES"))
+                                        if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
+
+                                b = glyph->bmap;
+                                for (n = glyph->height; n > 0; n--) {
+                                        if (readline(fp, line, arg) < 0) { fclose(fp); return 0; }
+                                        hex = line;
+                                        for (i = glyph->width; i > 0; i -= 4) {
+                                                hdig = *hex++;
+                                                if (hdig >= '0' && hdig <= '9')
+                                                        hdig -= '0';
+                                                else if (hdig >= 'a' && hdig <= 'f')
+                                                        hdig -= 'a' - 10;
+                                                else if (hdig >= 'A' && hdig <= 'F')
+                                                        hdig -= 'A' - 10;
+
+                                                *b++ = hdig & 8 ? 1 : 0;
+                                                if (i > 1) *b++ = hdig & 4 ? 1 : 0;
+                                                if (i > 2) *b++ = hdig & 2 ? 1 : 0;
+                                                if (i > 3) *b++ = hdig & 1;
+                                        }
+                                }
+
+                                expect("ENDCHAR");
+
+                                font->glyph[encoding] = glyph;
+
+                                numchar--;
+                        }
+                }
+        }
+        return font;
 }
 
 static int readline(fp, buf, arg)
@@ -1060,10 +1060,10 @@ FILE* fp;
 char* buf;
 char* arg[];
 {
-	if (!fgets(buf, 1024, fp))
-		return -1;
-	
-	return mk_argvn(buf, arg, 32);
+        if (!fgets(buf, 1024, fp))
+                return -1;
+
+        return mk_argvn(buf, arg, 32);
 }
 
 int mk_argvn(s, vec, mk_max)
@@ -1071,20 +1071,20 @@ char* s;
 char* vec[];
 int mk_max;
 {
-	int	n;
-
-	n = 0;
-	while (*s) {
-		if (isspace(*s)) {
-			*s++ = '\0';
-			continue;
-		}
-		vec[n++] = s;
-		if (n >= mk_max)
-			break;
-		while (*s && !isspace(*s))
-			s++;
-	}
-	vec[n] = 0;
-	return n;
+        int     n;
+
+        n = 0;
+        while (*s) {
+                if (isspace(*s)) {
+                        *s++ = '\0';
+                        continue;
+                }
+                vec[n++] = s;
+                if (n >= mk_max)
+                        break;
+                while (*s && !isspace(*s))
+                        s++;
+        }
+        vec[n] = 0;
+        return n;
 }

+ 42 - 42
panda/src/pnm/libpgm1.c

@@ -39,7 +39,7 @@ pgm_readpgminitrest( file, colsP, rowsP, maxvalP )
     /* Read maxval. */
     maxval = pbm_getint( file );
     if ( maxval > PGM_MAXMAXVAL )
-	pm_error( "maxval is too large - try reconfiguring with PGM_BIGGRAYS" );
+        pm_error( "maxval is too large - try reconfiguring with PGM_BIGGRAYS" );
     *maxvalP = maxval;
     }
 
@@ -56,19 +56,19 @@ pgm_readpgminit( file, colsP, rowsP, maxvalP, formatP )
     /* Check magic number. */
     *formatP = pbm_readmagicnumber( file );
     switch ( PGM_FORMAT_TYPE(*formatP) )
-	{
+        {
         case PGM_TYPE:
-	pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
-	break;
+        pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
+        break;
 
         case PBM_TYPE:
-	pbm_readpbminitrest( file, colsP, rowsP );
-	*maxvalP = pgm_pbmmaxval;
-	break;
+        pbm_readpbminitrest( file, colsP, rowsP );
+        *maxvalP = pgm_pbmmaxval;
+        break;
 
-	default:
-	pm_error( "bad magic number - not a pgm or pbm file" );
-	}
+        default:
+        pm_error( "bad magic number - not a pgm or pbm file" );
+        }
     }
 
 #if __STDC__
@@ -90,41 +90,41 @@ pgm_readpgmrow( file, grayrow, cols, maxval, format )
     register bit* bP;
 
     switch ( format )
-	{
-	case PGM_FORMAT:
-	for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
-	    {
-	    *gP = pbm_getint( file );
+        {
+        case PGM_FORMAT:
+        for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
+            {
+            *gP = pbm_getint( file );
 #ifdef DEBUG
-	    if ( *gP > maxval )
-		pm_error( "value out of bounds (%u > %u)", *gP, maxval );
+            if ( *gP > maxval )
+                pm_error( "value out of bounds (%u > %u)", *gP, maxval );
 #endif /*DEBUG*/
-	    }
-	break;
-	
-	case RPGM_FORMAT:
-	for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
-	    {
-	    *gP = pbm_getrawbyte( file );
+            }
+        break;
+
+        case RPGM_FORMAT:
+        for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
+            {
+            *gP = pbm_getrawbyte( file );
 #ifdef DEBUG
-	    if ( *gP > maxval )
-		pm_error( "value out of bounds (%u > %u)", *gP, maxval );
+            if ( *gP > maxval )
+                pm_error( "value out of bounds (%u > %u)", *gP, maxval );
 #endif /*DEBUG*/
-	    }
-	break;
-	
-	case PBM_FORMAT:
-	case RPBM_FORMAT:
-	bitrow = pbm_allocrow( cols );
-	pbm_readpbmrow( file, bitrow, cols, format );
-	for ( col = 0, gP = grayrow, bP = bitrow; col < cols; ++col, ++gP, ++bP )
-	    *gP = ( *bP == PBM_WHITE ) ? maxval : 0;
-	pbm_freerow( bitrow );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+            }
+        break;
+
+        case PBM_FORMAT:
+        case RPBM_FORMAT:
+        bitrow = pbm_allocrow( cols );
+        pbm_readpbmrow( file, bitrow, cols, format );
+        for ( col = 0, gP = grayrow, bP = bitrow; col < cols; ++col, ++gP, ++bP )
+            *gP = ( *bP == PBM_WHITE ) ? maxval : 0;
+        pbm_freerow( bitrow );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 gray**
@@ -143,7 +143,7 @@ pgm_readpgm( file, colsP, rowsP, maxvalP )
     grays = pgm_allocarray( *colsP, *rowsP );
 
     for ( row = 0; row < *rowsP; ++row )
-	pgm_readpgmrow( file, grays[row], *colsP, *maxvalP, format );
+        pgm_readpgmrow( file, grays[row], *colsP, *maxvalP, format );
 
     return grays;
     }

+ 34 - 34
panda/src/pnm/libpgm2.c

@@ -32,21 +32,21 @@ pgm_writepgminit( file, cols, rows, maxval, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( maxval <= 255 && ! forceplain ) {
-	fprintf(
-	    file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, RPGM_MAGIC2,
-	    cols, rows, maxval );
+        fprintf(
+            file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, RPGM_MAGIC2,
+            cols, rows, maxval );
 #ifdef VMS
         set_outfile_binary();
 #endif
         }
     else
-	fprintf(
-	    file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
-	    cols, rows, maxval );
+        fprintf(
+            file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
+            cols, rows, maxval );
 #else /*PBMPLUS_RAWBITS*/
     fprintf(
-	file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
-	cols, rows, maxval );
+        file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
+        cols, rows, maxval );
 #endif /*PBMPLUS_RAWBITS*/
     }
 
@@ -56,7 +56,7 @@ putus( n, file )
     FILE* file;
     {
     if ( n >= 10 )
-	putus( n / 10, file );
+        putus( n / 10, file );
     (void) putc( n % 10 + '0', file );
     }
 
@@ -68,13 +68,13 @@ pgm_writepgmrowraw(FILE* file,gray* grayrow,int cols,gray maxval)
     register gray* gP;
 
     for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
-	{
+        {
 #ifdef DEBUG
-	if ( *gP > maxval )
-	    pm_error( "value out of bounds (%u > %u)", *gP, maxval );
+        if ( *gP > maxval )
+            pm_error( "value out of bounds (%u > %u)", *gP, maxval );
 #endif /*DEBUG*/
-	(void) putc( *gP, file );
-	}
+        (void) putc( *gP, file );
+        }
     }
 #endif /*PBMPLUS_RAWBITS*/
 
@@ -86,26 +86,26 @@ pgm_writepgmrowplain(FILE* file,gray* grayrow,int cols,gray maxval)
 
     charcount = 0;
     for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
-	{
-	if ( charcount >= 65 )
-	    {
-	    (void) putc( '\n', file );
-	    charcount = 0;
-	    }
-	else if ( charcount > 0 )
-	    {
-	    (void) putc( ' ', file );
-	    ++charcount;
-	    }
+        {
+        if ( charcount >= 65 )
+            {
+            (void) putc( '\n', file );
+            charcount = 0;
+            }
+        else if ( charcount > 0 )
+            {
+            (void) putc( ' ', file );
+            ++charcount;
+            }
 #ifdef DEBUG
-	if ( *gP > maxval )
-	    pm_error( "value out of bounds (%u > %u)", *gP, maxval );
+        if ( *gP > maxval )
+            pm_error( "value out of bounds (%u > %u)", *gP, maxval );
 #endif /*DEBUG*/
-	putus( (unsigned long) *gP, file );
-	charcount += 3;
-	}
+        putus( (unsigned long) *gP, file );
+        charcount += 3;
+        }
     if ( charcount > 0 )
-	(void) putc( '\n', file );
+        (void) putc( '\n', file );
     }
 
 #if __STDC__
@@ -123,9 +123,9 @@ pgm_writepgmrow( file, grayrow, cols, maxval, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( maxval <= 255 && ! forceplain )
-	pgm_writepgmrowraw( file, grayrow, cols, maxval );
+        pgm_writepgmrowraw( file, grayrow, cols, maxval );
     else
-	pgm_writepgmrowplain( file, grayrow, cols, maxval );
+        pgm_writepgmrowplain( file, grayrow, cols, maxval );
 #else /*PBMPLUS_RAWBITS*/
     pgm_writepgmrowplain( file, grayrow, cols, maxval );
 #endif /*PBMPLUS_RAWBITS*/
@@ -149,5 +149,5 @@ pgm_writepgm( file, grays, cols, rows, maxval, forceplain )
     pgm_writepgminit( file, cols, rows, maxval, forceplain );
 
     for ( row = 0; row < rows; ++row )
-	 pgm_writepgmrow( file, grays[row], cols, maxval, forceplain );
+         pgm_writepgmrow( file, grays[row], cols, maxval, forceplain );
     }

+ 43 - 43
panda/src/pnm/libpnm1.c

@@ -44,24 +44,24 @@ pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP )
     /* Check magic number. */
     *formatP = pbm_readmagicnumber( file );
     switch ( PNM_FORMAT_TYPE(*formatP) )
-	{
-	case PPM_TYPE:
-	ppm_readppminitrest( file, colsP, rowsP, (pixval*) maxvalP );
-	break;
-
-	case PGM_TYPE:
-	pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
-	*maxvalP = (xelval) gmaxval;
-	break;
-
-	case PBM_TYPE:
-	pbm_readpbminitrest( file, colsP, rowsP );
-	*maxvalP = pnm_pbmmaxval;
-	break;
-
-	default:
-	pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
-	}
+        {
+        case PPM_TYPE:
+        ppm_readppminitrest( file, colsP, rowsP, (pixval*) maxvalP );
+        break;
+
+        case PGM_TYPE:
+        pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
+        *maxvalP = (xelval) gmaxval;
+        break;
+
+        case PBM_TYPE:
+        pbm_readpbminitrest( file, colsP, rowsP );
+        *maxvalP = pnm_pbmmaxval;
+        break;
+
+        default:
+        pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
+        }
     }
 
 #if defined(__STDC__) || defined(WIN32_VC)
@@ -83,30 +83,30 @@ void pnm_readpnmrow( file, xelrow, cols, maxval, format )
     register bit* bP;
 
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	ppm_readppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, format );
-	break;
-
-	case PGM_TYPE:
-	grayrow = pgm_allocrow( cols );
-	pgm_readpgmrow( file, grayrow, cols, (gray) maxval, format );
-	for ( col = 0, xP = xelrow, gP = grayrow; col < cols; ++col, ++xP, ++gP )
-	    PNM_ASSIGN1( *xP, *gP );
-	pgm_freerow( grayrow );
-	break;
-
-	case PBM_TYPE:
-	bitrow = pbm_allocrow( cols );
-	pbm_readpbmrow( file, bitrow, cols, format );
-	for ( col = 0, xP = xelrow, bP = bitrow; col < cols; ++col, ++xP, ++bP )
-	    PNM_ASSIGN1( *xP, *bP == PBM_BLACK ? 0: pnm_pbmmaxval );
-	pbm_freerow( bitrow );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PPM_TYPE:
+        ppm_readppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, format );
+        break;
+
+        case PGM_TYPE:
+        grayrow = pgm_allocrow( cols );
+        pgm_readpgmrow( file, grayrow, cols, (gray) maxval, format );
+        for ( col = 0, xP = xelrow, gP = grayrow; col < cols; ++col, ++xP, ++gP )
+            PNM_ASSIGN1( *xP, *gP );
+        pgm_freerow( grayrow );
+        break;
+
+        case PBM_TYPE:
+        bitrow = pbm_allocrow( cols );
+        pbm_readpbmrow( file, bitrow, cols, format );
+        for ( col = 0, xP = xelrow, bP = bitrow; col < cols; ++col, ++xP, ++bP )
+            PNM_ASSIGN1( *xP, *bP == PBM_BLACK ? 0: pnm_pbmmaxval );
+        pbm_freerow( bitrow );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 xel**
@@ -125,7 +125,7 @@ pnm_readpnm( file, colsP, rowsP, maxvalP, formatP )
     xels = pnm_allocarray( *colsP, *rowsP );
 
     for ( row = 0; row < *rowsP; ++row )
-	pnm_readpnmrow( file, xels[row], *colsP, *maxvalP, *formatP );
+        pnm_readpnmrow( file, xels[row], *colsP, *maxvalP, *formatP );
 
     return xels;
     }

+ 41 - 41
panda/src/pnm/libpnm2.c

@@ -34,22 +34,22 @@ pnm_writepnminit( file, cols, rows, maxval, format, forceplain )
 #endif /*__STDC__*/
     {
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
-	break;
-
-	case PGM_TYPE:
-	pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
-	break;
-
-	case PBM_TYPE:
-	pbm_writepbminit( file, cols, rows, forceplain );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PPM_TYPE:
+        ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
+        break;
+
+        case PGM_TYPE:
+        pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
+        break;
+
+        case PBM_TYPE:
+        pbm_writepbminit( file, cols, rows, forceplain );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 #if defined(__STDC__) || defined(WIN32_VC)
@@ -72,30 +72,30 @@ pnm_writepnmrow( file, xelrow, cols, maxval, format, forceplain )
     register bit* bP;
 
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
-	break;
-
-	case PGM_TYPE:
-	grayrow = pgm_allocrow( cols );
-	for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
-	    *gP = PNM_GET1( *xP );
-	pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
-	pgm_freerow( grayrow );
-	break;
-
-	case PBM_TYPE:
-	bitrow = pbm_allocrow( cols );
-	for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
-	    *bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
-	pbm_writepbmrow( file, bitrow, cols, forceplain );
-	pbm_freerow( bitrow );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PPM_TYPE:
+        ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
+        break;
+
+        case PGM_TYPE:
+        grayrow = pgm_allocrow( cols );
+        for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
+            *gP = PNM_GET1( *xP );
+        pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
+        pgm_freerow( grayrow );
+        break;
+
+        case PBM_TYPE:
+        bitrow = pbm_allocrow( cols );
+        for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
+            *bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
+        pbm_writepbmrow( file, bitrow, cols, forceplain );
+        pbm_freerow( bitrow );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 #if __STDC__
@@ -116,5 +116,5 @@ pnm_writepnm( file, xels, cols, rows, maxval, format, forceplain )
     pnm_writepnminit( file, cols, rows, maxval, format, forceplain );
 
     for ( row = 0; row < rows; ++row )
-	pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
+        pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
     }

+ 214 - 214
panda/src/pnm/libpnm3.c

@@ -42,53 +42,53 @@ pnm_backgroundxel( xels, cols, rows, maxval, format )
 
     /* First check for three corners equal. */
     if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, ll ) )
-	bgxel = ul;
+        bgxel = ul;
     else if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, lr ) )
-	bgxel = ul;
+        bgxel = ul;
     else if ( PNM_EQUAL( ul, ll ) && PNM_EQUAL( ll, lr ) )
-	bgxel = ul;
+        bgxel = ul;
     else if ( PNM_EQUAL( ur, ll ) && PNM_EQUAL( ll, lr ) )
-	bgxel = ur;
+        bgxel = ur;
     /* Nope, check for two corners equal. */
     else if ( PNM_EQUAL( ul, ur ) || PNM_EQUAL( ul, ll ) ||
-	      PNM_EQUAL( ul, lr ) )
-	bgxel = ul;
+              PNM_EQUAL( ul, lr ) )
+        bgxel = ul;
     else if ( PNM_EQUAL( ur, ll ) || PNM_EQUAL( ur, lr ) )
-	bgxel = ur;
+        bgxel = ur;
     else if ( PNM_EQUAL( ll, lr ) )
-	bgxel = ll;
+        bgxel = ll;
     else
-	{
-	/* Nope, we have to average the four corners.  This breaks the
-	** rules of pnm, but oh well.  Let's try to do it portably. */
-	switch ( PNM_FORMAT_TYPE(format) )
-	    {
-	    case PPM_TYPE:
-	    PPM_ASSIGN( bgxel,
-		PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr) / 4,
-		PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr) / 4,
-		PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr) / 4 );
-	    break;
-
-	    case PGM_TYPE:
-	    {
-	    gray gul, gur, gll, glr;
-	    gul = (gray) PNM_GET1( ul );
-	    gur = (gray) PNM_GET1( ur );
-	    gll = (gray) PNM_GET1( ll );
-	    glr = (gray) PNM_GET1( lr );
-	    PNM_ASSIGN1( bgxel, ( ( gul + gur + gll + glr ) / 4 ) );
-	    break;
-	    }
-
-	    case PBM_TYPE:
-	    pm_error(
-	    "pnm_backgroundxel: four bits no two of which equal each other??" );
-
-	    default:
-	    pm_error( "can't happen" );
-	    }
-	}
+        {
+        /* Nope, we have to average the four corners.  This breaks the
+        ** rules of pnm, but oh well.  Let's try to do it portably. */
+        switch ( PNM_FORMAT_TYPE(format) )
+            {
+            case PPM_TYPE:
+            PPM_ASSIGN( bgxel,
+                PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr) / 4,
+                PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr) / 4,
+                PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr) / 4 );
+            break;
+
+            case PGM_TYPE:
+            {
+            gray gul, gur, gll, glr;
+            gul = (gray) PNM_GET1( ul );
+            gur = (gray) PNM_GET1( ur );
+            gll = (gray) PNM_GET1( ll );
+            glr = (gray) PNM_GET1( lr );
+            PNM_ASSIGN1( bgxel, ( ( gul + gur + gll + glr ) / 4 ) );
+            break;
+            }
+
+            case PBM_TYPE:
+            pm_error(
+            "pnm_backgroundxel: four bits no two of which equal each other??" );
+
+            default:
+            pm_error( "can't happen" );
+            }
+        }
 
     return bgxel;
     }
@@ -112,48 +112,48 @@ pnm_backgroundxelrow( xelrow, cols, maxval, format )
 
     /* First check for both corners equal. */
     if ( PNM_EQUAL( l, r ) )
-	bgxel = l;
+        bgxel = l;
     else
-	{
-	/* Nope, we have to average the two corners.  This breaks the
-	** rules of pnm, but oh well.  Let's try to do it portably. */
-	switch ( PNM_FORMAT_TYPE(format) )
-	    {
-	    case PPM_TYPE:
-	    PPM_ASSIGN( bgxel, PPM_GETR(l) + PPM_GETR(r) / 2,
-		PPM_GETG(l) + PPM_GETG(r) / 2, PPM_GETB(l) + PPM_GETB(r) / 2 );
-	    break;
-
-	    case PGM_TYPE:
-	    {
-	    gray gl, gr;
-	    gl = (gray) PNM_GET1( l );
-	    gr = (gray) PNM_GET1( r );
-	    PNM_ASSIGN1( bgxel, ( ( gl + gr ) / 2 ) );
-	    break;
-	    }
-
-	    case PBM_TYPE:
-	    {
-	    int col, blacks;
-
-	    /* One black, one white.  Gotta count. */
-	    for ( col = 0, blacks = 0; col < cols; ++col )
-		{
-		if ( PNM_GET1( xelrow[col] ) == 0 )
-		    ++blacks;
-		}
-	    if ( blacks >= cols / 2 )
-		PNM_ASSIGN1( bgxel, 0 );
-	    else
-		PNM_ASSIGN1( bgxel, pnm_pbmmaxval );
-	    break;
-	    }
-
-	    default:
-	    pm_error( "can't happen" );
-	    }
-	}
+        {
+        /* Nope, we have to average the two corners.  This breaks the
+        ** rules of pnm, but oh well.  Let's try to do it portably. */
+        switch ( PNM_FORMAT_TYPE(format) )
+            {
+            case PPM_TYPE:
+            PPM_ASSIGN( bgxel, PPM_GETR(l) + PPM_GETR(r) / 2,
+                PPM_GETG(l) + PPM_GETG(r) / 2, PPM_GETB(l) + PPM_GETB(r) / 2 );
+            break;
+
+            case PGM_TYPE:
+            {
+            gray gl, gr;
+            gl = (gray) PNM_GET1( l );
+            gr = (gray) PNM_GET1( r );
+            PNM_ASSIGN1( bgxel, ( ( gl + gr ) / 2 ) );
+            break;
+            }
+
+            case PBM_TYPE:
+            {
+            int col, blacks;
+
+            /* One black, one white.  Gotta count. */
+            for ( col = 0, blacks = 0; col < cols; ++col )
+                {
+                if ( PNM_GET1( xelrow[col] ) == 0 )
+                    ++blacks;
+                }
+            if ( blacks >= cols / 2 )
+                PNM_ASSIGN1( bgxel, 0 );
+            else
+                PNM_ASSIGN1( bgxel, pnm_pbmmaxval );
+            break;
+            }
+
+            default:
+            pm_error( "can't happen" );
+            }
+        }
 
     return bgxel;
     }
@@ -171,22 +171,22 @@ pnm_whitexel( maxval, format )
     xel x;
 
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	PPM_ASSIGN( x, maxval, maxval, maxval );
-	break;
+        {
+        case PPM_TYPE:
+        PPM_ASSIGN( x, maxval, maxval, maxval );
+        break;
 
-	case PGM_TYPE:
-	PNM_ASSIGN1( x, maxval );
-	break;
+        case PGM_TYPE:
+        PNM_ASSIGN1( x, maxval );
+        break;
 
-	case PBM_TYPE:
-	PNM_ASSIGN1( x, pnm_pbmmaxval );
-	break;
+        case PBM_TYPE:
+        PNM_ASSIGN1( x, pnm_pbmmaxval );
+        break;
 
-	default:
-	pm_error( "can't happen" );
-	}
+        default:
+        pm_error( "can't happen" );
+        }
 
     return x;
     }
@@ -204,22 +204,22 @@ pnm_blackxel( maxval, format )
     xel x;
 
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	PPM_ASSIGN( x, 0, 0, 0 );
-	break;
+        {
+        case PPM_TYPE:
+        PPM_ASSIGN( x, 0, 0, 0 );
+        break;
 
-	case PGM_TYPE:
-	PNM_ASSIGN1( x, (xelval) 0 );
-	break;
+        case PGM_TYPE:
+        PNM_ASSIGN1( x, (xelval) 0 );
+        break;
 
-	case PBM_TYPE:
-	PNM_ASSIGN1( x, (xelval) 0 );
-	break;
+        case PBM_TYPE:
+        PNM_ASSIGN1( x, (xelval) 0 );
+        break;
 
-	default:
-	pm_error( "can't happen" );
-	}
+        default:
+        pm_error( "can't happen" );
+        }
 
     return x;
     }
@@ -236,24 +236,24 @@ pnm_invertxel( xP, maxval, format )
 #endif /*__STDC__*/
     {
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PPM_TYPE:
-	PPM_ASSIGN(
-	    *xP, maxval - PPM_GETR( *xP ),
-	    maxval - PPM_GETG( *xP ), maxval - PPM_GETB( *xP ) );
-	break;
-
-	case PGM_TYPE:
-	PNM_ASSIGN1( *xP, (gray) maxval - (gray) PNM_GET1( *xP ) );
-	break;
-
-	case PBM_TYPE:
-	PNM_ASSIGN1( *xP, ( PNM_GET1( *xP ) == 0 ) ? pnm_pbmmaxval : 0 );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PPM_TYPE:
+        PPM_ASSIGN(
+            *xP, maxval - PPM_GETR( *xP ),
+            maxval - PPM_GETG( *xP ), maxval - PPM_GETB( *xP ) );
+        break;
+
+        case PGM_TYPE:
+        PNM_ASSIGN1( *xP, (gray) maxval - (gray) PNM_GET1( *xP ) );
+        break;
+
+        case PBM_TYPE:
+        PNM_ASSIGN1( *xP, ( PNM_GET1( *xP ) == 0 ) ? pnm_pbmmaxval : 0 );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 #if __STDC__
@@ -270,8 +270,8 @@ pnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat )
     int row;
 
     for ( row = 0; row < rows; ++row )
-	pnm_promoteformatrow(
-	    xels[row], cols, maxval, format, newmaxval, newformat );
+        pnm_promoteformatrow(
+            xels[row], cols, maxval, format, newmaxval, newformat );
     }
 
 #if __STDC__
@@ -289,98 +289,98 @@ pnm_promoteformatrow( xelrow, cols, maxval, format, newmaxval, newformat )
     register xel* xP;
 
     if ( ( PNM_FORMAT_TYPE(format) == PPM_TYPE &&
-	   ( PNM_FORMAT_TYPE(newformat) == PGM_TYPE ||
-	     PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) ) ||
-	 ( PNM_FORMAT_TYPE(format) == PGM_TYPE &&
-	   PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) )
-	pm_error( "pnm_promoteformatrow: can't promote downwards!" );
+           ( PNM_FORMAT_TYPE(newformat) == PGM_TYPE ||
+             PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) ) ||
+         ( PNM_FORMAT_TYPE(format) == PGM_TYPE &&
+           PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) )
+        pm_error( "pnm_promoteformatrow: can't promote downwards!" );
 
     /* Are we promoting to the same type? */
     if ( PNM_FORMAT_TYPE(format) == PNM_FORMAT_TYPE(newformat) )
-	{
-	if ( PNM_FORMAT_TYPE(format) == PBM_TYPE )
-	    return;
-	if ( newmaxval < maxval )
-	    pm_error(
-	   "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
-	if ( newmaxval == maxval )
-	    return;
-	/* Increase maxval. */
-	switch ( PNM_FORMAT_TYPE(format) )
-	    {
-	    case PGM_TYPE:
-	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		PNM_ASSIGN1(
-		    *xP, (int) PNM_GET1(*xP) * newmaxval / maxval );
-	    break;
-
-	    case PPM_TYPE:
-	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		PPM_DEPTH( *xP, *xP, maxval, newmaxval );
-	    break;
-
-	    default:
-	    pm_error( "shouldn't happen" );
-	    }
-	return;
-	}
+        {
+        if ( PNM_FORMAT_TYPE(format) == PBM_TYPE )
+            return;
+        if ( newmaxval < maxval )
+            pm_error(
+           "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
+        if ( newmaxval == maxval )
+            return;
+        /* Increase maxval. */
+        switch ( PNM_FORMAT_TYPE(format) )
+            {
+            case PGM_TYPE:
+            for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                PNM_ASSIGN1(
+                    *xP, (int) PNM_GET1(*xP) * newmaxval / maxval );
+            break;
+
+            case PPM_TYPE:
+            for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                PPM_DEPTH( *xP, *xP, maxval, newmaxval );
+            break;
+
+            default:
+            pm_error( "shouldn't happen" );
+            }
+        return;
+        }
 
     /* We must be promoting to a higher type. */
     switch ( PNM_FORMAT_TYPE(format) )
-	{
-	case PBM_TYPE:
-	switch ( PNM_FORMAT_TYPE(newformat) )
-	    {
-	    case PGM_TYPE:
-	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		if ( PNM_GET1(*xP) == 0 )
-		    PNM_ASSIGN1( *xP, 0 );
-		else
-		    PNM_ASSIGN1( *xP, newmaxval );
-	    break;
-
-	    case PPM_TYPE:
-	    for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		if ( PNM_GET1(*xP) == 0 )
-		    PPM_ASSIGN( *xP, 0, 0, 0 );
-		else
-		    PPM_ASSIGN( *xP, newmaxval, newmaxval, newmaxval );
-	    break;
-
-	    default:
-	    pm_error( "can't happen" );
-	    }
-	break;
-
-	case PGM_TYPE:
-	switch ( PNM_FORMAT_TYPE(newformat) )
-	    {
-	    case PPM_TYPE:
-	    if ( newmaxval < maxval )
-		pm_error(
-	   "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
-	    if ( newmaxval == maxval )
-		{
-		for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		    PPM_ASSIGN(
-			*xP, PNM_GET1(*xP), PNM_GET1(*xP), PNM_GET1(*xP) );
-		}
-	    else
-		{ /* Increase maxval. */
-		for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
-		    PPM_ASSIGN(
-			*xP, (int) PNM_GET1(*xP) * newmaxval / maxval,
-			(int) PNM_GET1(*xP) * newmaxval / maxval,
-			(int) PNM_GET1(*xP) * newmaxval / maxval );
-		}
-	    break;
-
-	    default:
-	    pm_error( "can't happen" );
-	    }
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+        {
+        case PBM_TYPE:
+        switch ( PNM_FORMAT_TYPE(newformat) )
+            {
+            case PGM_TYPE:
+            for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                if ( PNM_GET1(*xP) == 0 )
+                    PNM_ASSIGN1( *xP, 0 );
+                else
+                    PNM_ASSIGN1( *xP, newmaxval );
+            break;
+
+            case PPM_TYPE:
+            for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                if ( PNM_GET1(*xP) == 0 )
+                    PPM_ASSIGN( *xP, 0, 0, 0 );
+                else
+                    PPM_ASSIGN( *xP, newmaxval, newmaxval, newmaxval );
+            break;
+
+            default:
+            pm_error( "can't happen" );
+            }
+        break;
+
+        case PGM_TYPE:
+        switch ( PNM_FORMAT_TYPE(newformat) )
+            {
+            case PPM_TYPE:
+            if ( newmaxval < maxval )
+                pm_error(
+           "pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
+            if ( newmaxval == maxval )
+                {
+                for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                    PPM_ASSIGN(
+                        *xP, PNM_GET1(*xP), PNM_GET1(*xP), PNM_GET1(*xP) );
+                }
+            else
+                { /* Increase maxval. */
+                for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
+                    PPM_ASSIGN(
+                        *xP, (int) PNM_GET1(*xP) * newmaxval / maxval,
+                        (int) PNM_GET1(*xP) * newmaxval / maxval,
+                        (int) PNM_GET1(*xP) * newmaxval / maxval );
+                }
+            break;
+
+            default:
+            pm_error( "can't happen" );
+            }
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }

+ 303 - 303
panda/src/pnm/libpnm4.c

@@ -27,17 +27,17 @@ mem_create( w, h, depth )
 
     p = (struct pixrect*) malloc( sizeof(struct pixrect) );
     if ( p == NULL )
-	return NULL;
+        return NULL;
     p->pr_ops = NULL;
     p->pr_size.x = w;
     p->pr_size.y = h;
     p->pr_depth = depth;
     m = p->pr_data = (struct mpr_data*) malloc( sizeof(struct mpr_data) );
     if ( m == NULL )
-	{
-	free( p );
-	return NULL;
-	}
+        {
+        free( p );
+        return NULL;
+        }
     /* According to the documentation, linebytes is supposed to be rounded
     ** up to a longword (except on 386 boxes).  However, this turns out
     ** not to be the case.  In reality, all of Sun's code rounds up to
@@ -49,11 +49,11 @@ mem_create( w, h, depth )
     m->md_flags = 0;
     m->md_image = (unsigned char*) malloc( m->md_linebytes * h );
     if ( m->md_image == NULL )
-	{
-	free( m );
-	free( p );
-	return NULL;
-	}
+        {
+        free( m );
+        free( p );
+        return NULL;
+        }
 
     return p;
     }
@@ -88,179 +88,179 @@ pr_dump( p, out, colormap, type, copy_flag )
 
     h.ras_type = type;
     switch ( type )
-	{
-	case RT_OLD:
-	pm_error( "old rasterfile type is not supported" );
-
-	case RT_FORMAT_TIFF:
-	pm_error( "tiff rasterfile type is not supported" );
-
-	case RT_FORMAT_IFF:
-	pm_error( "iff rasterfile type is not supported" );
-
-	case RT_EXPERIMENTAL:
-	pm_error( "experimental rasterfile type is not supported" );
-
-	case RT_STANDARD:
-	case RT_FORMAT_RGB:
-	/* Ignore hP->ras_length. */
-	h.ras_length = p->pr_size.y * p->pr_data->md_linebytes;
-	break;
-
-	case RT_BYTE_ENCODED:
-	size = p->pr_size.y * p->pr_data->md_linebytes;
-	bp = p->pr_data->md_image;
-	beimage = (unsigned char*) malloc( size * 3 / 2 );	/* worst case */
-	if ( beimage == NULL )
-	    return PIX_ERR;
-	besize = 0;
-	count = 0;
-	for ( i = 0; i < size; ++i )
-	    {
-	    c = *bp++;
-	    if ( count > 0 )
-		{
-		if ( pc != c )
-		    {
-		    if ( count == 1 && pc == 128 )
-			{
-			beimage[besize++] = 128;
-			beimage[besize++] = 0;
-			count = 0;
-			}
-		    else if ( count > 2 || pc == 128 )
-			{
-			beimage[besize++] = 128;
-			beimage[besize++] = count - 1;
-			beimage[besize++] = pc;
-			count = 0;
-			}
-		    else
-			{
-			for ( j = 0; j < count; ++j )
-			    beimage[besize++] = pc;
-			count = 0;
-			}
-		    }
-		}
-	    pc = c;
-	    ++count;
-	    if ( count == 256 )
-		{
-		beimage[besize++] = 128;
-		beimage[besize++] = count - 1;
-		beimage[besize++] = c;
-		count = 0;
-		}
-	    }
-	if ( count > 0 )
-	    {
-	    if ( count == 1 && c == 128 )
-		{
-		beimage[besize++] = 128;
-		beimage[besize++] = 0;
-		}
-	    if ( count > 2 || c == 128 )
-		{
-		beimage[besize++] = 128;
-		beimage[besize++] = count - 1;
-		beimage[besize++] = c;
-		}
-	    else
-		{
-		for ( j = 0; j < count; ++j )
-		    beimage[besize++] = c;
-		}
-	    }
-	h.ras_length = besize;
-	break;
-
-	default:
-	pm_error( "unknown rasterfile type" );
-	}
+        {
+        case RT_OLD:
+        pm_error( "old rasterfile type is not supported" );
+
+        case RT_FORMAT_TIFF:
+        pm_error( "tiff rasterfile type is not supported" );
+
+        case RT_FORMAT_IFF:
+        pm_error( "iff rasterfile type is not supported" );
+
+        case RT_EXPERIMENTAL:
+        pm_error( "experimental rasterfile type is not supported" );
+
+        case RT_STANDARD:
+        case RT_FORMAT_RGB:
+        /* Ignore hP->ras_length. */
+        h.ras_length = p->pr_size.y * p->pr_data->md_linebytes;
+        break;
+
+        case RT_BYTE_ENCODED:
+        size = p->pr_size.y * p->pr_data->md_linebytes;
+        bp = p->pr_data->md_image;
+        beimage = (unsigned char*) malloc( size * 3 / 2 );      /* worst case */
+        if ( beimage == NULL )
+            return PIX_ERR;
+        besize = 0;
+        count = 0;
+        for ( i = 0; i < size; ++i )
+            {
+            c = *bp++;
+            if ( count > 0 )
+                {
+                if ( pc != c )
+                    {
+                    if ( count == 1 && pc == 128 )
+                        {
+                        beimage[besize++] = 128;
+                        beimage[besize++] = 0;
+                        count = 0;
+                        }
+                    else if ( count > 2 || pc == 128 )
+                        {
+                        beimage[besize++] = 128;
+                        beimage[besize++] = count - 1;
+                        beimage[besize++] = pc;
+                        count = 0;
+                        }
+                    else
+                        {
+                        for ( j = 0; j < count; ++j )
+                            beimage[besize++] = pc;
+                        count = 0;
+                        }
+                    }
+                }
+            pc = c;
+            ++count;
+            if ( count == 256 )
+                {
+                beimage[besize++] = 128;
+                beimage[besize++] = count - 1;
+                beimage[besize++] = c;
+                count = 0;
+                }
+            }
+        if ( count > 0 )
+            {
+            if ( count == 1 && c == 128 )
+                {
+                beimage[besize++] = 128;
+                beimage[besize++] = 0;
+                }
+            if ( count > 2 || c == 128 )
+                {
+                beimage[besize++] = 128;
+                beimage[besize++] = count - 1;
+                beimage[besize++] = c;
+                }
+            else
+                {
+                for ( j = 0; j < count; ++j )
+                    beimage[besize++] = c;
+                }
+            }
+        h.ras_length = besize;
+        break;
+
+        default:
+        pm_error( "unknown rasterfile type" );
+        }
 
     if ( colormap == NULL )
-	{
-	h.ras_maptype = RMT_NONE;
-	h.ras_maplength = 0;
-	}
+        {
+        h.ras_maptype = RMT_NONE;
+        h.ras_maplength = 0;
+        }
     else
-	{
-	h.ras_maptype = colormap->type;
-	switch ( colormap->type )
-	    {
-	    case RMT_EQUAL_RGB:
-	    h.ras_maplength = colormap->length * 3;
-	    break;
-
-	    case RMT_RAW:
-	    h.ras_maplength = colormap->length;
-	    break;
-
-	    default:
-	    pm_error( "unknown colormap type" );
-	    }
-	}
+        {
+        h.ras_maptype = colormap->type;
+        switch ( colormap->type )
+            {
+            case RMT_EQUAL_RGB:
+            h.ras_maplength = colormap->length * 3;
+            break;
+
+            case RMT_RAW:
+            h.ras_maplength = colormap->length;
+            break;
+
+            default:
+            pm_error( "unknown colormap type" );
+            }
+        }
 
     if ( pm_writebiglong( out, h.ras_magic ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_width ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_height ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_depth ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_length ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_type ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_maptype ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_writebiglong( out, h.ras_maplength ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
 
     if ( colormap != NULL )
-	{
-	switch ( colormap->type )
-	    {
-	    case RMT_EQUAL_RGB:
-	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
-		 colormap->length )
-		return PIX_ERR;
-	    if ( fwrite( colormap->map[1], 1, colormap->length, out ) !=
-		 colormap->length )
-		return PIX_ERR;
-	    if ( fwrite( colormap->map[2], 1, colormap->length, out ) !=
-		 colormap->length )
-		return PIX_ERR;
-	    break;
-
-	    case RMT_RAW:
-	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
-		 colormap->length )
-		return PIX_ERR;
-	    break;
-	    }
-	}
+        {
+        switch ( colormap->type )
+            {
+            case RMT_EQUAL_RGB:
+            if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
+                 colormap->length )
+                return PIX_ERR;
+            if ( fwrite( colormap->map[1], 1, colormap->length, out ) !=
+                 colormap->length )
+                return PIX_ERR;
+            if ( fwrite( colormap->map[2], 1, colormap->length, out ) !=
+                 colormap->length )
+                return PIX_ERR;
+            break;
+
+            case RMT_RAW:
+            if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
+                 colormap->length )
+                return PIX_ERR;
+            break;
+            }
+        }
 
     switch ( type )
-	{
-	case RT_STANDARD:
-	case RT_FORMAT_RGB:
-	if ( fwrite( p->pr_data->md_image, 1, h.ras_length, out ) !=
-	     h.ras_length )
-	    return PIX_ERR;
-	break;
-
-	case RT_BYTE_ENCODED:
-	if ( fwrite( beimage, 1, besize, out ) != besize )
-	    {
-	    free( beimage );
-	    return PIX_ERR;
-	    }
-	free( beimage );
-	break;
-	}
+        {
+        case RT_STANDARD:
+        case RT_FORMAT_RGB:
+        if ( fwrite( p->pr_data->md_image, 1, h.ras_length, out ) !=
+             h.ras_length )
+            return PIX_ERR;
+        break;
+
+        case RT_BYTE_ENCODED:
+        if ( fwrite( beimage, 1, besize, out ) != besize )
+            {
+            free( beimage );
+            return PIX_ERR;
+            }
+        free( beimage );
+        break;
+        }
 
     return 0;
     }
@@ -271,23 +271,23 @@ pr_load_header( in, hP )
     struct rasterfile* hP;
     {
     if ( pm_readbiglong( in, &(hP->ras_magic) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( hP->ras_magic != RAS_MAGIC )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_width) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_height) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_depth) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_length) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_type) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_maptype) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     if ( pm_readbiglong( in, &(hP->ras_maplength) ) == -1 )
-	return PIX_ERR;
+        return PIX_ERR;
     return 0;
     }
 
@@ -298,64 +298,64 @@ pr_load_colormap( in, hP, colormap )
     colormap_t* colormap;
     {
     if ( colormap == NULL || hP->ras_maptype == RMT_NONE )
-	{
-	int i;
+        {
+        int i;
 
-	for ( i = 0; i < hP->ras_maplength; ++i )
-	    if ( getc( in ) == EOF )
-		return PIX_ERR;
-	}
+        for ( i = 0; i < hP->ras_maplength; ++i )
+            if ( getc( in ) == EOF )
+                return PIX_ERR;
+        }
     else
-	{
-	colormap->type = hP->ras_maptype;
-	switch ( hP->ras_maptype )
-	    {
-	    case RMT_EQUAL_RGB:
-	    colormap->length = hP->ras_maplength / 3;
-	    colormap->map[0] = (unsigned char*) malloc( colormap->length );
-	    if ( colormap->map[0] == NULL )
-		return PIX_ERR;
-	    colormap->map[1] = (unsigned char*) malloc( colormap->length );
-	    if ( colormap->map[1] == NULL )
-		{
-		free( colormap->map[0] );
-		return PIX_ERR;
-		}
-	    colormap->map[2] = (unsigned char*) malloc( colormap->length );
-	    if ( colormap->map[2] == NULL )
-		{
-		free( colormap->map[0] );
-		free( colormap->map[1] );
-		return PIX_ERR;
-		}
-	    if ( fread( colormap->map[0], 1, colormap->length, in ) != colormap->length ||
-	         fread( colormap->map[1], 1, colormap->length, in ) != colormap->length ||
-	         fread( colormap->map[2], 1, colormap->length, in ) != colormap->length )
-		{
-		free( colormap->map[0] );
-		free( colormap->map[1] );
-		free( colormap->map[2] );
-		return PIX_ERR;
-		}
-	    break;
-
-	    case RMT_RAW:
-	    colormap->length = hP->ras_maplength;
-	    colormap->map[0] = (unsigned char*) malloc( colormap->length );
-	    if ( colormap->map[0] == NULL )
-		return PIX_ERR;
-	    colormap->map[2] = colormap->map[1] = colormap->map[0];
-	    if ( fread( colormap->map[0], 1, hP->ras_maplength, in ) != hP->ras_maplength )
-		{
-		free( colormap->map[0] );
-		return PIX_ERR;
-		}
-	    break;
-
-	    default:
-	    pm_error( "unknown colormap type" );
-	    }
-	}
+        {
+        colormap->type = hP->ras_maptype;
+        switch ( hP->ras_maptype )
+            {
+            case RMT_EQUAL_RGB:
+            colormap->length = hP->ras_maplength / 3;
+            colormap->map[0] = (unsigned char*) malloc( colormap->length );
+            if ( colormap->map[0] == NULL )
+                return PIX_ERR;
+            colormap->map[1] = (unsigned char*) malloc( colormap->length );
+            if ( colormap->map[1] == NULL )
+                {
+                free( colormap->map[0] );
+                return PIX_ERR;
+                }
+            colormap->map[2] = (unsigned char*) malloc( colormap->length );
+            if ( colormap->map[2] == NULL )
+                {
+                free( colormap->map[0] );
+                free( colormap->map[1] );
+                return PIX_ERR;
+                }
+            if ( fread( colormap->map[0], 1, colormap->length, in ) != colormap->length ||
+                 fread( colormap->map[1], 1, colormap->length, in ) != colormap->length ||
+                 fread( colormap->map[2], 1, colormap->length, in ) != colormap->length )
+                {
+                free( colormap->map[0] );
+                free( colormap->map[1] );
+                free( colormap->map[2] );
+                return PIX_ERR;
+                }
+            break;
+
+            case RMT_RAW:
+            colormap->length = hP->ras_maplength;
+            colormap->map[0] = (unsigned char*) malloc( colormap->length );
+            if ( colormap->map[0] == NULL )
+                return PIX_ERR;
+            colormap->map[2] = colormap->map[1] = colormap->map[0];
+            if ( fread( colormap->map[0], 1, hP->ras_maplength, in ) != hP->ras_maplength )
+                {
+                free( colormap->map[0] );
+                return PIX_ERR;
+                }
+            break;
+
+            default:
+            pm_error( "unknown colormap type" );
+            }
+        }
     return 0;
     }
 
@@ -375,79 +375,79 @@ pr_load_image( in, hP, colormap )
 
     p = mem_create( hP->ras_width, hP->ras_height, hP->ras_depth );
     if ( p == NULL )
-	return NULL;
+        return NULL;
 
     switch ( hP->ras_type )
-	{
-	case RT_OLD:
-	pm_error( "old rasterfile type is not supported" );
-
-	case RT_FORMAT_TIFF:
-	pm_error( "tiff rasterfile type is not supported" );
-
-	case RT_FORMAT_IFF:
-	pm_error( "iff rasterfile type is not supported" );
-
-	case RT_EXPERIMENTAL:
-	pm_error( "experimental rasterfile type is not supported" );
-
-	case RT_STANDARD:
-	case RT_FORMAT_RGB:
-	/* Ignore hP->ras_length. */
-	i = p->pr_size.y * p->pr_data->md_linebytes;
-	if ( fread( p->pr_data->md_image, 1, i, in ) != i )
-	    {
-	    mem_free( p );
-	    return NULL;
-	    }
-	break;
-
-	case RT_BYTE_ENCODED:
-	beimage = (unsigned char*) malloc( hP->ras_length );
-	if ( beimage == NULL )
-	    {
-	    mem_free( p );
-	    return NULL;
-	    }
-	if ( fread( beimage, 1, hP->ras_length, in ) != hP->ras_length )
-	    {
-	    mem_free( p );
-	    free( beimage );
-	    return NULL;
-	    }
-	bep = beimage;
-	bp = p->pr_data->md_image;
-	for ( i = 0; i < hP->ras_length; )
-	    {
-	    c = *bep++;
-	    if ( c == 128 )
-		{
-		count = ( *bep++ ) + 1;
-		if ( count == 1 )
-		    {
-		    *bp++ = 128;
-		    i += 2;
-		    }
-		else
-		    {
-		    c = *bep++;
-		    for ( j = 0; j < count; ++j )
-			*bp++ = c;
-		    i += 3;
-		    }
-		}
-	    else
-		{
-		*bp++ = c;
-		++i;
-		}
-	    }
-	free( beimage );
-	break;
-
-	default:
-	pm_error( "unknown rasterfile type" );
-	}
+        {
+        case RT_OLD:
+        pm_error( "old rasterfile type is not supported" );
+
+        case RT_FORMAT_TIFF:
+        pm_error( "tiff rasterfile type is not supported" );
+
+        case RT_FORMAT_IFF:
+        pm_error( "iff rasterfile type is not supported" );
+
+        case RT_EXPERIMENTAL:
+        pm_error( "experimental rasterfile type is not supported" );
+
+        case RT_STANDARD:
+        case RT_FORMAT_RGB:
+        /* Ignore hP->ras_length. */
+        i = p->pr_size.y * p->pr_data->md_linebytes;
+        if ( fread( p->pr_data->md_image, 1, i, in ) != i )
+            {
+            mem_free( p );
+            return NULL;
+            }
+        break;
+
+        case RT_BYTE_ENCODED:
+        beimage = (unsigned char*) malloc( hP->ras_length );
+        if ( beimage == NULL )
+            {
+            mem_free( p );
+            return NULL;
+            }
+        if ( fread( beimage, 1, hP->ras_length, in ) != hP->ras_length )
+            {
+            mem_free( p );
+            free( beimage );
+            return NULL;
+            }
+        bep = beimage;
+        bp = p->pr_data->md_image;
+        for ( i = 0; i < hP->ras_length; )
+            {
+            c = *bep++;
+            if ( c == 128 )
+                {
+                count = ( *bep++ ) + 1;
+                if ( count == 1 )
+                    {
+                    *bp++ = 128;
+                    i += 2;
+                    }
+                else
+                    {
+                    c = *bep++;
+                    for ( j = 0; j < count; ++j )
+                        *bp++ = c;
+                    i += 3;
+                    }
+                }
+            else
+                {
+                *bp++ = c;
+                ++i;
+                }
+            }
+        free( beimage );
+        break;
+
+        default:
+        pm_error( "unknown rasterfile type" );
+        }
 
     return p;
     }

+ 79 - 79
panda/src/pnm/libppm1.c

@@ -41,7 +41,7 @@ ppm_readppminitrest( file, colsP, rowsP, maxvalP )
     /* Read maxval. */
     maxval = pbm_getint( file );
     if ( maxval > PPM_MAXMAXVAL )
-	pm_error(
+        pm_error(
 "maxval is too large - try reconfiguring with PGM_BIGGRAYS\n    or without PPM_PACKCOLORS" );
     *maxvalP = maxval;
     }
@@ -59,23 +59,23 @@ ppm_readppminit( file, colsP, rowsP, maxvalP, formatP )
     /* Check magic number. */
     *formatP = pbm_readmagicnumber( file );
     switch ( PPM_FORMAT_TYPE(*formatP) )
-	{
-	case PPM_TYPE:
-	ppm_readppminitrest( file, colsP, rowsP, maxvalP );
-	break;
-
-	case PGM_TYPE:
-	pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
-	break;
-
-	case PBM_TYPE:
-	pbm_readpbminitrest( file, colsP, rowsP );
-	*maxvalP = ppm_pbmmaxval;
-	break;
-
-	default:
-	pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
-	}
+        {
+        case PPM_TYPE:
+        ppm_readppminitrest( file, colsP, rowsP, maxvalP );
+        break;
+
+        case PGM_TYPE:
+        pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
+        break;
+
+        case PBM_TYPE:
+        pbm_readpbminitrest( file, colsP, rowsP );
+        *maxvalP = ppm_pbmmaxval;
+        break;
+
+        default:
+        pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
+        }
     }
 
 #if __STDC__
@@ -99,78 +99,78 @@ ppm_readppmrow( file, pixelrow, cols, maxval, format )
     register bit* bP;
 
     switch ( format )
-	{
-	case PPM_FORMAT:
-	for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
-	    {
-	    r = pbm_getint( file );
+        {
+        case PPM_FORMAT:
+        for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
+            {
+            r = pbm_getint( file );
 #ifdef DEBUG
-	    if ( r > maxval )
-		pm_error( "r value out of bounds (%u > %u)", r, maxval );
+            if ( r > maxval )
+                pm_error( "r value out of bounds (%u > %u)", r, maxval );
 #endif /*DEBUG*/
-	    g = pbm_getint( file );
+            g = pbm_getint( file );
 #ifdef DEBUG
-	    if ( g > maxval )
-		pm_error( "g value out of bounds (%u > %u)", g, maxval );
+            if ( g > maxval )
+                pm_error( "g value out of bounds (%u > %u)", g, maxval );
 #endif /*DEBUG*/
-	    b = pbm_getint( file );
+            b = pbm_getint( file );
 #ifdef DEBUG
-	    if ( b > maxval )
-		pm_error( "b value out of bounds (%u > %u)", b, maxval );
+            if ( b > maxval )
+                pm_error( "b value out of bounds (%u > %u)", b, maxval );
 #endif /*DEBUG*/
-	    PPM_ASSIGN( *pP, r, g, b );
-	    }
-	break;
-
-	case RPPM_FORMAT:
-	for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
-	    {
-	    r = pbm_getrawbyte( file );
+            PPM_ASSIGN( *pP, r, g, b );
+            }
+        break;
+
+        case RPPM_FORMAT:
+        for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
+            {
+            r = pbm_getrawbyte( file );
 #ifdef DEBUG
-	    if ( r > maxval )
-		pm_error( "r value out of bounds (%u > %u)", r, maxval );
+            if ( r > maxval )
+                pm_error( "r value out of bounds (%u > %u)", r, maxval );
 #endif /*DEBUG*/
-	    g = pbm_getrawbyte( file );
+            g = pbm_getrawbyte( file );
 #ifdef DEBUG
-	    if ( g > maxval )
-		pm_error( "g value out of bounds (%u > %u)", g, maxval );
+            if ( g > maxval )
+                pm_error( "g value out of bounds (%u > %u)", g, maxval );
 #endif /*DEBUG*/
-	    b = pbm_getrawbyte( file );
+            b = pbm_getrawbyte( file );
 #ifdef DEBUG
-	    if ( b > maxval )
-		pm_error( "b value out of bounds (%u > %u)", b, maxval );
+            if ( b > maxval )
+                pm_error( "b value out of bounds (%u > %u)", b, maxval );
 #endif /*DEBUG*/
-	    PPM_ASSIGN( *pP, r, g, b );
-	    }
-	break;
-
-	case PGM_FORMAT:
-	case RPGM_FORMAT:
-	grayrow = pgm_allocrow( cols );
-	pgm_readpgmrow( file, grayrow, cols, maxval, format );
-	for ( col = 0, gP = grayrow, pP = pixelrow; col < cols; ++col, ++gP, ++pP )
-	    {
-	    r = *gP;
-	    PPM_ASSIGN( *pP, r, r, r );
-	    }
-	pgm_freerow( grayrow );
-	break;
-
-	case PBM_FORMAT:
-	case RPBM_FORMAT:
-	bitrow = pbm_allocrow( cols );
-	pbm_readpbmrow( file, bitrow, cols, format );
-	for ( col = 0, bP = bitrow, pP = pixelrow; col < cols; ++col, ++bP, ++pP )
-	    {
-	    r = ( *bP == PBM_WHITE ) ? maxval : 0;
-	    PPM_ASSIGN( *pP, r, r, r );
-	    }
-	pbm_freerow( bitrow );
-	break;
-
-	default:
-	pm_error( "can't happen" );
-	}
+            PPM_ASSIGN( *pP, r, g, b );
+            }
+        break;
+
+        case PGM_FORMAT:
+        case RPGM_FORMAT:
+        grayrow = pgm_allocrow( cols );
+        pgm_readpgmrow( file, grayrow, cols, maxval, format );
+        for ( col = 0, gP = grayrow, pP = pixelrow; col < cols; ++col, ++gP, ++pP )
+            {
+            r = *gP;
+            PPM_ASSIGN( *pP, r, r, r );
+            }
+        pgm_freerow( grayrow );
+        break;
+
+        case PBM_FORMAT:
+        case RPBM_FORMAT:
+        bitrow = pbm_allocrow( cols );
+        pbm_readpbmrow( file, bitrow, cols, format );
+        for ( col = 0, bP = bitrow, pP = pixelrow; col < cols; ++col, ++bP, ++pP )
+            {
+            r = ( *bP == PBM_WHITE ) ? maxval : 0;
+            PPM_ASSIGN( *pP, r, r, r );
+            }
+        pbm_freerow( bitrow );
+        break;
+
+        default:
+        pm_error( "can't happen" );
+        }
     }
 
 pixel**
@@ -189,7 +189,7 @@ ppm_readppm( file, colsP, rowsP, maxvalP )
     pixels = ppm_allocarray( *colsP, *rowsP );
 
     for ( row = 0; row < *rowsP; ++row )
-	ppm_readppmrow( file, pixels[row], *colsP, *maxvalP, format );
+        ppm_readppmrow( file, pixels[row], *colsP, *maxvalP, format );
 
     return pixels;
     }

+ 54 - 54
panda/src/pnm/libppm2.c

@@ -35,21 +35,21 @@ ppm_writeppminit( file, cols, rows, maxval, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( maxval <= 255 && ! forceplain ) {
-	fprintf(
-	    file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, RPPM_MAGIC2,
-	    cols, rows, maxval );
+        fprintf(
+            file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, RPPM_MAGIC2,
+            cols, rows, maxval );
 #ifdef VMS
         set_outfile_binary();
 #endif
         }
     else
-	fprintf(
-	    file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
-	    cols, rows, maxval );
+        fprintf(
+            file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
+            cols, rows, maxval );
 #else /*PBMPLUS_RAWBITS*/
     fprintf(
-	file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
-	cols, rows, maxval );
+        file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
+        cols, rows, maxval );
 #endif /*PBMPLUS_RAWBITS*/
     }
 
@@ -57,7 +57,7 @@ static void
 putus(unsigned short n, FILE* file)
     {
     if ( n >= 10 )
-	putus( n / 10, file );
+        putus( n / 10, file );
     (void) putc( n % 10 + '0', file );
     }
 
@@ -70,25 +70,25 @@ ppm_writeppmrowraw (FILE* file,pixel* pixelrow,int cols,pixval maxval)
     register pixval val;
 
     for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
-	{
-	val = PPM_GETR( *pP );
+        {
+        val = PPM_GETR( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "r value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "r value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	(void) putc( val, file );
-	val = PPM_GETG( *pP );
+        (void) putc( val, file );
+        val = PPM_GETG( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "g value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "g value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	(void) putc( val, file );
-	val = PPM_GETB( *pP );
+        (void) putc( val, file );
+        val = PPM_GETB( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "b value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "b value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	(void) putc( val, file );
+        (void) putc( val, file );
         }
     }
 #endif /*PBMPLUS_RAWBITS*/
@@ -102,42 +102,42 @@ ppm_writeppmrowplain(FILE* file,pixel* pixelrow,int cols,pixval maxval)
 
     charcount = 0;
     for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
-	{
-	if ( charcount >= 65 )
-	    {
-	    (void) putc( '\n', file );
-	    charcount = 0;
-	    }
-	else if ( charcount > 0 )
-	    {
-	    (void) putc( ' ', file );
-	    (void) putc( ' ', file );
-	    charcount += 2;
-	    }
-	val = PPM_GETR( *pP );
+        {
+        if ( charcount >= 65 )
+            {
+            (void) putc( '\n', file );
+            charcount = 0;
+            }
+        else if ( charcount > 0 )
+            {
+            (void) putc( ' ', file );
+            (void) putc( ' ', file );
+            charcount += 2;
+            }
+        val = PPM_GETR( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "r value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "r value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	putus( val, file );
-	(void) putc( ' ', file );
-	val = PPM_GETG( *pP );
+        putus( val, file );
+        (void) putc( ' ', file );
+        val = PPM_GETG( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "g value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "g value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	putus( val, file );
-	(void) putc( ' ', file );
-	val = PPM_GETB( *pP );
+        putus( val, file );
+        (void) putc( ' ', file );
+        val = PPM_GETB( *pP );
 #ifdef DEBUG
-	if ( val > maxval )
-	    pm_error( "b value out of bounds (%u > %u)", val, maxval );
+        if ( val > maxval )
+            pm_error( "b value out of bounds (%u > %u)", val, maxval );
 #endif /*DEBUG*/
-	putus( val, file );
-	charcount += 11;
-	}
+        putus( val, file );
+        charcount += 11;
+        }
     if ( charcount > 0 )
-	(void) putc( '\n', file );
+        (void) putc( '\n', file );
     }
 
 #if __STDC__
@@ -155,9 +155,9 @@ ppm_writeppmrow( file, pixelrow, cols, maxval, forceplain )
     {
 #ifdef PBMPLUS_RAWBITS
     if ( maxval <= 255 && ! forceplain )
-	ppm_writeppmrowraw( file, pixelrow, cols, maxval );
+        ppm_writeppmrowraw( file, pixelrow, cols, maxval );
     else
-	ppm_writeppmrowplain( file, pixelrow, cols, maxval );
+        ppm_writeppmrowplain( file, pixelrow, cols, maxval );
 #else /*PBMPLUS_RAWBITS*/
     ppm_writeppmrowplain( file, pixelrow, cols, maxval );
 #endif /*PBMPLUS_RAWBITS*/
@@ -181,5 +181,5 @@ ppm_writeppm( file, pixels, cols, rows, maxval, forceplain )
     ppm_writeppminit( file, cols, rows, maxval, forceplain );
 
     for ( row = 0; row < rows; ++row )
-	ppm_writeppmrow( file, pixels[row], cols, maxval, forceplain );
+        ppm_writeppmrow( file, pixels[row], cols, maxval, forceplain );
     }

+ 83 - 83
panda/src/pnm/libppm3.c

@@ -35,7 +35,7 @@ ppm_computecolorhist( pixels, cols, rows, maxcolors, colorsP )
 
     cht = ppm_computecolorhash( pixels, cols, rows, maxcolors, colorsP );
     if ( cht == (colorhash_table) 0 )
-	return (colorhist_vector) 0;
+        return (colorhist_vector) 0;
     chv = ppm_colorhashtocolorhist( cht, maxcolors );
     ppm_freecolorhash( cht );
     return chv;
@@ -52,32 +52,32 @@ ppm_addtocolorhist( chv, colorsP, maxcolors, colorP, value, position )
 
     /* Search colorhist for the color. */
     for ( i = 0; i < *colorsP; ++i )
-	if ( PPM_EQUAL( chv[i].color, *colorP ) )
-	    {
-	    /* Found it - move to new slot. */
-	    if ( position > i )
-		{
-		for ( j = i; j < position; ++j )
-		    chv[j] = chv[j + 1];
-		}
-	    else if ( position < i )
-		{
-		for ( j = i; j > position; --j )
-		    chv[j] = chv[j - 1];
-		}
-	    chv[position].color = *colorP;
-	    chv[position].value = value;
-	    return;
-	    }
+        if ( PPM_EQUAL( chv[i].color, *colorP ) )
+            {
+            /* Found it - move to new slot. */
+            if ( position > i )
+                {
+                for ( j = i; j < position; ++j )
+                    chv[j] = chv[j + 1];
+                }
+            else if ( position < i )
+                {
+                for ( j = i; j > position; --j )
+                    chv[j] = chv[j - 1];
+                }
+            chv[position].color = *colorP;
+            chv[position].value = value;
+            return;
+            }
     if ( *colorsP < maxcolors )
-	{
-	/* Didn't find it, but there's room to add it; so do so. */
-	for ( i = *colorsP; i > position; --i )
-	    chv[i] = chv[i - 1];
-	chv[position].color = *colorP;
-	chv[position].value = value;
-	++(*colorsP);
-	}
+        {
+        /* Didn't find it, but there's room to add it; so do so. */
+        for ( i = *colorsP; i > position; --i )
+            chv[i] = chv[i - 1];
+        chv[position].color = *colorP;
+        chv[position].value = value;
+        ++(*colorsP);
+        }
     }
 
 colorhash_table
@@ -96,30 +96,30 @@ ppm_computecolorhash( pixels, cols, rows, maxcolors, colorsP )
 
     /* Go through the entire image, building a hash table of colors. */
     for ( row = 0; row < rows; ++row )
-	for ( col = 0, pP = pixels[row]; col < cols; ++col, ++pP )
-	    {
-	    hash = ppm_hashpixel( *pP );
-	    for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next )
-		if ( PPM_EQUAL( chl->ch.color, *pP ) )
-		    break;
-	    if ( chl != (colorhist_list) 0 )
-		++(chl->ch.value);
-	    else
-		{
-		if ( ++(*colorsP) > maxcolors )
-		    {
-		    ppm_freecolorhash( cht );
-		    return (colorhash_table) 0;
-		    }
-		chl = (colorhist_list) malloc( sizeof(struct colorhist_list_item) );
-		if ( chl == 0 )
-		    pm_error( "out of memory computing hash table" );
-		chl->ch.color = *pP;
-		chl->ch.value = 1;
-		chl->next = cht[hash];
-		cht[hash] = chl;
-		}
-	    }
+        for ( col = 0, pP = pixels[row]; col < cols; ++col, ++pP )
+            {
+            hash = ppm_hashpixel( *pP );
+            for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next )
+                if ( PPM_EQUAL( chl->ch.color, *pP ) )
+                    break;
+            if ( chl != (colorhist_list) 0 )
+                ++(chl->ch.value);
+            else
+                {
+                if ( ++(*colorsP) > maxcolors )
+                    {
+                    ppm_freecolorhash( cht );
+                    return (colorhash_table) 0;
+                    }
+                chl = (colorhist_list) malloc( sizeof(struct colorhist_list_item) );
+                if ( chl == 0 )
+                    pm_error( "out of memory computing hash table" );
+                chl->ch.color = *pP;
+                chl->ch.value = 1;
+                chl->next = cht[hash];
+                cht[hash] = chl;
+                }
+            }
     
     return cht;
     }
@@ -132,10 +132,10 @@ ppm_alloccolorhash( )
 
     cht = (colorhash_table) malloc( HASH_SIZE * sizeof(colorhist_list) );
     if ( cht == 0 )
-	pm_error( "out of memory allocating hash table" );
+        pm_error( "out of memory allocating hash table" );
 
     for ( i = 0; i < HASH_SIZE; ++i )
-	cht[i] = (colorhist_list) 0;
+        cht[i] = (colorhist_list) 0;
 
     return cht;
     }
@@ -151,7 +151,7 @@ ppm_addtocolorhash( cht, colorP, value )
 
     chl = (colorhist_list) malloc( sizeof(struct colorhist_list_item) );
     if ( chl == 0 )
-	return -1;
+        return -1;
     hash = ppm_hashpixel( *colorP );
     chl->ch.color = *colorP;
     chl->ch.value = value;
@@ -173,17 +173,17 @@ ppm_colorhashtocolorhist( cht, maxcolors )
     chv = (colorhist_vector) malloc( maxcolors * sizeof(struct colorhist_item) );
     /* (Leave room for expansion by caller.) */
     if ( chv == (colorhist_vector) 0 )
-	pm_error( "out of memory generating histogram" );
+        pm_error( "out of memory generating histogram" );
 
     /* Loop through the hash table. */
     j = 0;
     for ( i = 0; i < HASH_SIZE; ++i )
-	for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chl->next )
-	    {
-	    /* Add the new entry. */
-	    chv[j] = chl->ch;
-	    ++j;
-	    }
+        for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chl->next )
+            {
+            /* Add the new entry. */
+            chv[j] = chl->ch;
+            ++j;
+            }
 
     /* All done. */
     return chv;
@@ -202,22 +202,22 @@ ppm_colorhisttocolorhash( chv, colors )
     cht = ppm_alloccolorhash( );
 
     for ( i = 0; i < colors; ++i )
-	{
-	color = chv[i].color;
-	hash = ppm_hashpixel( color );
-	for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next )
-	    if ( PPM_EQUAL( chl->ch.color, color ) )
-		pm_error(
-		    "same color found twice - %d %d %d", PPM_GETR(color),
-		    PPM_GETG(color), PPM_GETB(color) );
-	chl = (colorhist_list) malloc( sizeof(struct colorhist_list_item) );
-	if ( chl == (colorhist_list) 0 )
-	    pm_error( "out of memory" );
-	chl->ch.color = color;
-	chl->ch.value = i;
-	chl->next = cht[hash];
-	cht[hash] = chl;
-	}
+        {
+        color = chv[i].color;
+        hash = ppm_hashpixel( color );
+        for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next )
+            if ( PPM_EQUAL( chl->ch.color, color ) )
+                pm_error(
+                    "same color found twice - %d %d %d", PPM_GETR(color),
+                    PPM_GETG(color), PPM_GETB(color) );
+        chl = (colorhist_list) malloc( sizeof(struct colorhist_list_item) );
+        if ( chl == (colorhist_list) 0 )
+            pm_error( "out of memory" );
+        chl->ch.color = color;
+        chl->ch.value = i;
+        chl->next = cht[hash];
+        cht[hash] = chl;
+        }
 
     return cht;
     }
@@ -232,8 +232,8 @@ ppm_lookupcolor( cht, colorP )
 
     hash = ppm_hashpixel( *colorP );
     for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next )
-	if ( PPM_EQUAL( chl->ch.color, *colorP ) )
-	    return chl->ch.value;
+        if ( PPM_EQUAL( chl->ch.color, *colorP ) )
+            return chl->ch.value;
 
     return -1;
     }
@@ -253,10 +253,10 @@ ppm_freecolorhash( cht )
     colorhist_list chl, chlnext;
 
     for ( i = 0; i < HASH_SIZE; ++i )
-	for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chlnext )
-	    {
-	    chlnext = chl->next;
-	    free( (char*) chl );
-	    }
+        for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chlnext )
+            {
+            chlnext = chl->next;
+            free( (char*) chl );
+            }
     free( (char*) cht );
     }

+ 354 - 354
panda/src/pnm/libppm5.c

@@ -32,7 +32,7 @@ ppmd_point_drawproc( pixels, cols, rows, maxval, x, y, clientdata )
 #endif /*__STDC__*/
     {
     if ( x >= 0 && x < cols && y >= 0 && y < rows )
-	pixels[y][x] = *( (pixel*) clientdata );
+        pixels[y][x] = *( (pixel*) clientdata );
     }
 
 
@@ -59,28 +59,28 @@ ppmd_filledrectangle( pixels, cols, rows, maxval, x, y, width, height, drawprocP
     cwidth = width;
     cheight = height;
     if ( cx < 0 )
-	{
-	cx = 0;
-	cwidth += x;
-	}
+        {
+        cx = 0;
+        cwidth += x;
+        }
     if ( cy < 0 )
-	{
-	cy = 0;
-	cheight += y;
-	}
+        {
+        cy = 0;
+        cheight += y;
+        }
     if ( cx + cwidth > cols )
-	cwidth = cols - cx;
+        cwidth = cols - cx;
     if ( cy + cheight > rows )
-	cheight = rows - cy;
+        cheight = rows - cy;
 
     /* Draw. */
     for ( row = cy; row < cy + cheight; ++row )
-	for ( col = cx; col < cx + cwidth; ++col )
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		pixels[row][col] = *( (pixel*) clientdata );
-	    else
-		(*drawprocP)(
-		    pixels, cols, rows, maxval, col, row, clientdata );
+        for ( col = cx; col < cx + cwidth; ++col )
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                pixels[row][col] = *( (pixel*) clientdata );
+            else
+                (*drawprocP)(
+                    pixels, cols, rows, maxval, col, row, clientdata );
     }
 
 
@@ -129,16 +129,16 @@ ppmd_line( pixels, cols, rows, maxval, x0, y0, x1, y1, drawprocP, clientdata )
 
     /* Special case zero-length lines. */
     if ( x0 == x1 && y0 == y1 )
-	{
-	if ( ( ! ppmd_lineclip ) ||
-	     ( x0 >= 0 && x0 < cols && y0 >= 0 && y0 < rows ) )
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		ppmd_point_drawproc(
-		    pixels, cols, rows, maxval, x0, y0, clientdata );
-	    else
-		(*drawprocP)( pixels, cols, rows, maxval, x0, y0, clientdata );
-	return;
-	}
+        {
+        if ( ( ! ppmd_lineclip ) ||
+             ( x0 >= 0 && x0 < cols && y0 >= 0 && y0 < rows ) )
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                ppmd_point_drawproc(
+                    pixels, cols, rows, maxval, x0, y0, clientdata );
+            else
+                (*drawprocP)( pixels, cols, rows, maxval, x0, y0, clientdata );
+        return;
+        }
 
     /* Clip. */
     cx0 = x0;
@@ -146,138 +146,138 @@ ppmd_line( pixels, cols, rows, maxval, x0, y0, x1, y1, drawprocP, clientdata )
     cx1 = x1;
     cy1 = y1;
     if ( ppmd_lineclip )
-	{
-	if ( cx0 < 0 )
-	    {
-	    if ( cx1 < 0 ) return;
-	    cy0 = cy0 + ( cy1 - cy0 ) * ( -cx0 ) / ( cx1 - cx0 );
-	    cx0 = 0;
-	    }
-	else if ( cx0 >= cols )
-	    {
-	    if ( cx1 >= cols ) return;
-	    cy0 = cy0 + ( cy1 - cy0 ) * ( cols - 1 - cx0 ) / ( cx1 - cx0 );
-	    cx0 = cols - 1;
-	    }
-	if ( cy0 < 0 )
-	    {
-	    if ( cy1 < 0 ) return;
-	    cx0 = cx0 + ( cx1 - cx0 ) * ( -cy0 ) / ( cy1 - cy0 );
-	    cy0 = 0;
-	    }
-	else if ( cy0 >= rows )
-	    {
-	    if ( cy1 >= rows ) return;
-	    cx0 = cx0 + ( cx1 - cx0 ) * ( rows - 1 - cy0 ) / ( cy1 - cy0 );
-	    cy0 = rows - 1;
-	    }
-	if ( cx1 < 0 )
-	    {
-	    cy1 = cy1 + ( cy0 - cy1 ) * ( -cx1 ) / ( cx0 - cx1 );
-	    cx1 = 0;
-	    }
-	else if ( cx1 >= cols )
-	    {
-	    cy1 = cy1 + ( cy0 - cy1 ) * ( cols - 1 - cx1 ) / ( cx0 - cx1 );
-	    cx1 = cols - 1;
-	    }
-	if ( cy1 < 0 )
-	    {
-	    cx1 = cx1 + ( cx0 - cx1 ) * ( -cy1 ) / ( cy0 - cy1 );
-	    cy1 = 0;
-	    }
-	else if ( cy1 >= rows )
-	    {
-	    cx1 = cx1 + ( cx0 - cx1 ) * ( rows - 1 - cy1 ) / ( cy0 - cy1 );
-	    cy1 = rows - 1;
-	    }
-
-	/* Check again for zero-length lines. */
-	if ( cx0 == cx1 && cy0 == cy1 )
-	    {
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		ppmd_point_drawproc(
-		    pixels, cols, rows, maxval, cx0, cy0, clientdata );
-	    else
-		(*drawprocP)(
-		    pixels, cols, rows, maxval, cx0, cy0, clientdata );
-	    return;
-	    }
-	}
+        {
+        if ( cx0 < 0 )
+            {
+            if ( cx1 < 0 ) return;
+            cy0 = cy0 + ( cy1 - cy0 ) * ( -cx0 ) / ( cx1 - cx0 );
+            cx0 = 0;
+            }
+        else if ( cx0 >= cols )
+            {
+            if ( cx1 >= cols ) return;
+            cy0 = cy0 + ( cy1 - cy0 ) * ( cols - 1 - cx0 ) / ( cx1 - cx0 );
+            cx0 = cols - 1;
+            }
+        if ( cy0 < 0 )
+            {
+            if ( cy1 < 0 ) return;
+            cx0 = cx0 + ( cx1 - cx0 ) * ( -cy0 ) / ( cy1 - cy0 );
+            cy0 = 0;
+            }
+        else if ( cy0 >= rows )
+            {
+            if ( cy1 >= rows ) return;
+            cx0 = cx0 + ( cx1 - cx0 ) * ( rows - 1 - cy0 ) / ( cy1 - cy0 );
+            cy0 = rows - 1;
+            }
+        if ( cx1 < 0 )
+            {
+            cy1 = cy1 + ( cy0 - cy1 ) * ( -cx1 ) / ( cx0 - cx1 );
+            cx1 = 0;
+            }
+        else if ( cx1 >= cols )
+            {
+            cy1 = cy1 + ( cy0 - cy1 ) * ( cols - 1 - cx1 ) / ( cx0 - cx1 );
+            cx1 = cols - 1;
+            }
+        if ( cy1 < 0 )
+            {
+            cx1 = cx1 + ( cx0 - cx1 ) * ( -cy1 ) / ( cy0 - cy1 );
+            cy1 = 0;
+            }
+        else if ( cy1 >= rows )
+            {
+            cx1 = cx1 + ( cx0 - cx1 ) * ( rows - 1 - cy1 ) / ( cy0 - cy1 );
+            cy1 = rows - 1;
+            }
+
+        /* Check again for zero-length lines. */
+        if ( cx0 == cx1 && cy0 == cy1 )
+            {
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                ppmd_point_drawproc(
+                    pixels, cols, rows, maxval, cx0, cy0, clientdata );
+            else
+                (*drawprocP)(
+                    pixels, cols, rows, maxval, cx0, cy0, clientdata );
+            return;
+            }
+        }
 
     /* Draw, using a simple DDA. */
     if ( abs( cx1 - cx0 ) > abs( cy1 - cy0 ) )
-	{ /* Loop over X domain. */
-	register long dy, srow;
-	register int dx, col, row, prevrow;
-
-	if ( cx1 > cx0 )
-	    dx = 1;
-	else
-	    dx = -1;
-	dy = ( cy1 - cy0 ) * DDA_SCALE / abs( cx1 - cx0 );
-	prevrow = row = cy0;
-	srow = row * DDA_SCALE + DDA_SCALE / 2;
-	col = cx0;
-	for ( ; ; )
-	    {
-	    if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && row != prevrow )
-		{
-		if ( drawprocP == PPMD_NULLDRAWPROC )
-		    pixels[prevrow][col] = *( (pixel*) clientdata );
-		else
-		    (*drawprocP)(
-		        pixels, cols, rows, maxval, col, prevrow, clientdata );
-		prevrow = row;
-		}
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		pixels[row][col] = *( (pixel*) clientdata );
-	    else
-		(*drawprocP)(
-		    pixels, cols, rows, maxval, col, row, clientdata );
-	    if ( col == cx1 )
-		break;
-	    srow += dy;
-	    row = srow / DDA_SCALE;
-	    col += dx;
-	    }
-	}
+        { /* Loop over X domain. */
+        register long dy, srow;
+        register int dx, col, row, prevrow;
+
+        if ( cx1 > cx0 )
+            dx = 1;
+        else
+            dx = -1;
+        dy = ( cy1 - cy0 ) * DDA_SCALE / abs( cx1 - cx0 );
+        prevrow = row = cy0;
+        srow = row * DDA_SCALE + DDA_SCALE / 2;
+        col = cx0;
+        for ( ; ; )
+            {
+            if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && row != prevrow )
+                {
+                if ( drawprocP == PPMD_NULLDRAWPROC )
+                    pixels[prevrow][col] = *( (pixel*) clientdata );
+                else
+                    (*drawprocP)(
+                        pixels, cols, rows, maxval, col, prevrow, clientdata );
+                prevrow = row;
+                }
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                pixels[row][col] = *( (pixel*) clientdata );
+            else
+                (*drawprocP)(
+                    pixels, cols, rows, maxval, col, row, clientdata );
+            if ( col == cx1 )
+                break;
+            srow += dy;
+            row = srow / DDA_SCALE;
+            col += dx;
+            }
+        }
     else
-	{ /* Loop over Y domain. */
-	register long dx, scol;
-	register int dy, col, row, prevcol;
-
-	if ( cy1 > cy0 )
-	    dy = 1;
-	else
-	    dy = -1;
-	dx = ( cx1 - cx0 ) * DDA_SCALE / abs( cy1 - cy0 );
-	row = cy0;
-	prevcol = col = cx0;
-	scol = col * DDA_SCALE + DDA_SCALE / 2;
-	for ( ; ; )
-	    {
-	    if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && col != prevcol )
-		{
-		if ( drawprocP == PPMD_NULLDRAWPROC )
-		    pixels[row][prevcol] = *( (pixel*) clientdata );
-		else
-		    (*drawprocP)(
-			pixels, cols, rows, maxval, prevcol, row, clientdata );
-		prevcol = col;
-		}
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		pixels[row][col] = *( (pixel*) clientdata );
-	    else
-		(*drawprocP)(
-		    pixels, cols, rows, maxval, col, row, clientdata );
-	    if ( row == cy1 )
-		break;
-	    row += dy;
-	    scol += dx;
-	    col = scol / DDA_SCALE;
-	    }
-	}
+        { /* Loop over Y domain. */
+        register long dx, scol;
+        register int dy, col, row, prevcol;
+
+        if ( cy1 > cy0 )
+            dy = 1;
+        else
+            dy = -1;
+        dx = ( cx1 - cx0 ) * DDA_SCALE / abs( cy1 - cy0 );
+        row = cy0;
+        prevcol = col = cx0;
+        scol = col * DDA_SCALE + DDA_SCALE / 2;
+        for ( ; ; )
+            {
+            if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && col != prevcol )
+                {
+                if ( drawprocP == PPMD_NULLDRAWPROC )
+                    pixels[row][prevcol] = *( (pixel*) clientdata );
+                else
+                    (*drawprocP)(
+                        pixels, cols, rows, maxval, prevcol, row, clientdata );
+                prevcol = col;
+                }
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                pixels[row][col] = *( (pixel*) clientdata );
+            else
+                (*drawprocP)(
+                    pixels, cols, rows, maxval, col, row, clientdata );
+            if ( row == cy1 )
+                break;
+            row += dy;
+            scol += dx;
+            col = scol / DDA_SCALE;
+            }
+        }
     }
 
 #define SPLINE_THRESH 3
@@ -306,22 +306,22 @@ ppmd_spline3( pixels, cols, rows, maxval, x0, y0, x1, y1, x2, y2, drawprocP, cli
     xp = ( x0 + xb ) / 2;
     yp = ( y0 + yb ) / 2;
     if ( abs( xa - xp ) + abs( ya - yp ) > SPLINE_THRESH )
-	ppmd_spline3(
-	    pixels, cols, rows, maxval, x0, y0, xa, ya, xb, yb, drawprocP,
-	    clientdata );
+        ppmd_spline3(
+            pixels, cols, rows, maxval, x0, y0, xa, ya, xb, yb, drawprocP,
+            clientdata );
     else
-	ppmd_line(
-	    pixels, cols, rows, maxval, x0, y0, xb, yb, drawprocP, clientdata );
+        ppmd_line(
+            pixels, cols, rows, maxval, x0, y0, xb, yb, drawprocP, clientdata );
 
     xp = ( x2 + xb ) / 2;
     yp = ( y2 + yb ) / 2;
     if ( abs( xc - xp ) + abs( yc - yp ) > SPLINE_THRESH )
-	ppmd_spline3(
-	    pixels, cols, rows, maxval, xb, yb, xc, yc, x2, y2, drawprocP,
-	    clientdata );
+        ppmd_spline3(
+            pixels, cols, rows, maxval, xb, yb, xc, yc, x2, y2, drawprocP,
+            clientdata );
     else
-	ppmd_line(
-	    pixels, cols, rows, maxval, xb, yb, x2, y2, drawprocP, clientdata );
+        ppmd_line(
+            pixels, cols, rows, maxval, xb, yb, x2, y2, drawprocP, clientdata );
     }
 
 #if __STDC__
@@ -344,18 +344,18 @@ ppmd_polyspline( pixels, cols, rows, maxval, x0, y0, nc, xc, yc, x1, y1, drawpro
     x = x0;
     y = y0;
     for ( i = 0; i < nc - 1; ++i )
-	{
-	xn = ( xc[i] + xc[i + 1] ) / 2;
-	yn = ( yc[i] + yc[i + 1] ) / 2;
-	ppmd_spline3(
-	    pixels, cols, rows, maxval, x, y, xc[i], yc[i], xn, yn, drawprocP,
-	    clientdata );
-	x = xn;
-	y = yn;
-	}
+        {
+        xn = ( xc[i] + xc[i + 1] ) / 2;
+        yn = ( yc[i] + yc[i + 1] ) / 2;
+        ppmd_spline3(
+            pixels, cols, rows, maxval, x, y, xc[i], yc[i], xn, yn, drawprocP,
+            clientdata );
+        x = xn;
+        y = yn;
+        }
     ppmd_spline3(
-	pixels, cols, rows, maxval, x, y, xc[nc - 1], yc[nc - 1], x1, y1,
-	drawprocP, clientdata );
+        pixels, cols, rows, maxval, x, y, xc[nc - 1], yc[nc - 1], x1, y1,
+        drawprocP, clientdata );
     }
 
 #if __STDC__
@@ -380,28 +380,28 @@ ppmd_circle( pixels, cols, rows, maxval, cx, cy, radius, drawprocP, clientdata )
     sy = y * DDA_SCALE + DDA_SCALE / 2;
     e = DDA_SCALE / radius;
     if ( drawprocP == PPMD_NULLDRAWPROC )
-	pixels[y + cy][x + cx] = *( (pixel*) clientdata );
+        pixels[y + cy][x + cx] = *( (pixel*) clientdata );
     else
-	(*drawprocP)( pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
+        (*drawprocP)( pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
     nopointsyet = 1;
     do
-	{
-	prevx = x;
-	prevy = y;
-	sx += e * sy / DDA_SCALE;
-	sy -= e * sx / DDA_SCALE;
-	x = sx / DDA_SCALE;
-	y = sy / DDA_SCALE;
-	if ( x != prevx || y != prevy )
-	    {
-	    nopointsyet = 0;
-	    if ( drawprocP == PPMD_NULLDRAWPROC )
-		pixels[y + cy][x + cx] = *( (pixel*) clientdata );
-	    else
-		(*drawprocP)(
-		    pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
-	    }
-	}
+        {
+        prevx = x;
+        prevy = y;
+        sx += e * sy / DDA_SCALE;
+        sy -= e * sx / DDA_SCALE;
+        x = sx / DDA_SCALE;
+        y = sy / DDA_SCALE;
+        if ( x != prevx || y != prevy )
+            {
+            nopointsyet = 0;
+            if ( drawprocP == PPMD_NULLDRAWPROC )
+                pixels[y + cy][x + cx] = *( (pixel*) clientdata );
+            else
+                (*drawprocP)(
+                    pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
+            }
+        }
     while ( nopointsyet || x != x0 || y != y0 );
     }
 
@@ -436,11 +436,11 @@ ppmd_fill_init( )
 
     fh = (fillobj*) malloc( sizeof(fillobj) );
     if ( fh == 0 )
-	pm_error( "out of memory allocating a fillhandle" );
+        pm_error( "out of memory allocating a fillhandle" );
     fh->n = 0;
     fh->coords = (coord*) malloc( SOME * sizeof(coord) );
     if ( fh->coords == 0 )
-	pm_error( "out of memory allocating a fillhandle" );
+        pm_error( "out of memory allocating a fillhandle" );
     fh->size = SOME;
     fh->curedge = 0;
 
@@ -469,76 +469,76 @@ ppmd_fill_drawproc( pixels, cols, rows, maxval, x, y, clientdata )
     fh = (fillobj*) clientdata;
 
     if ( fh->n > 0 )
-	{
-	/* If these are the same coords we saved last time, don't bother. */
-	ocp = &(fh->coords[fh->n - 1]);
-	if ( x == ocp->x && y == ocp->y )
-	    return;
-	}
+        {
+        /* If these are the same coords we saved last time, don't bother. */
+        ocp = &(fh->coords[fh->n - 1]);
+        if ( x == ocp->x && y == ocp->y )
+            return;
+        }
 
     /* Ok, these are new; check if there's room for two more coords. */
     if ( fh->n + 1 >= fh->size )
-	{
-	fh->size += SOME;
-	fh->coords = (coord*) realloc(
-	    (char*) fh->coords, fh->size * sizeof(coord) );
-	if ( fh->coords == 0 )
-	    pm_error( "out of memory enlarging a fillhandle" );
-	}
+        {
+        fh->size += SOME;
+        fh->coords = (coord*) realloc(
+            (char*) fh->coords, fh->size * sizeof(coord) );
+        if ( fh->coords == 0 )
+            pm_error( "out of memory enlarging a fillhandle" );
+        }
 
     /* Check for extremum and set the edge number. */
     if ( fh->n == 0 )
-	{ /* Start first segment. */
-	fh->segstart = fh->n;
-	fh->ydir = 0;
-	fh->startydir = 0;
-	}
+        { /* Start first segment. */
+        fh->segstart = fh->n;
+        fh->ydir = 0;
+        fh->startydir = 0;
+        }
     else
-	{
-	register int dx, dy;
-
-	dx = x - ocp->x;
-	dy = y - ocp->y;
-	if ( dx < -1 || dx > 1 || dy < -1 || dy > 1 )
-	    { /* Segment break.  Close off old one. */
-	    if ( fh->startydir != 0 && fh->ydir != 0 )
-		if ( fh->startydir == fh->ydir )
-		    { /* Oops, first edge and last edge are the same.
-		      ** Renumber the first edge in the old segment. */
-		    register coord* fcp;
-		    int oldedge;
-
-		    fcp = &(fh->coords[fh->segstart]);
-		    oldedge = fcp->edge;
-		    for ( ; fcp->edge == oldedge; ++fcp )
-			fcp->edge = ocp->edge;
-		    }
-	    /* And start new segment. */
-	    ++(fh->curedge);
-	    fh->segstart = fh->n;
-	    fh->ydir = 0;
-	    fh->startydir = 0;
-	    }
-	else
-	    { /* Segment continues. */
-	    if ( dy != 0 )
-		{
-		if ( fh->ydir != 0 && fh->ydir != dy )
-		    { /* Direction changed.  Insert a fake coord, old
-		      ** position but new edge number. */
-		    ++(fh->curedge);
-		    cp = &(fh->coords[fh->n]);
-		    cp->x = ocp->x;
-		    cp->y = ocp->y;
-		    cp->edge = fh->curedge;
-		    ++(fh->n);
-		    }
-		fh->ydir = dy;
-		if ( fh->startydir == 0 )
-		    fh->startydir = dy;
-		}
-	    }
-	}
+        {
+        register int dx, dy;
+
+        dx = x - ocp->x;
+        dy = y - ocp->y;
+        if ( dx < -1 || dx > 1 || dy < -1 || dy > 1 )
+            { /* Segment break.  Close off old one. */
+            if ( fh->startydir != 0 && fh->ydir != 0 )
+                if ( fh->startydir == fh->ydir )
+                    { /* Oops, first edge and last edge are the same.
+                      ** Renumber the first edge in the old segment. */
+                    register coord* fcp;
+                    int oldedge;
+
+                    fcp = &(fh->coords[fh->segstart]);
+                    oldedge = fcp->edge;
+                    for ( ; fcp->edge == oldedge; ++fcp )
+                        fcp->edge = ocp->edge;
+                    }
+            /* And start new segment. */
+            ++(fh->curedge);
+            fh->segstart = fh->n;
+            fh->ydir = 0;
+            fh->startydir = 0;
+            }
+        else
+            { /* Segment continues. */
+            if ( dy != 0 )
+                {
+                if ( fh->ydir != 0 && fh->ydir != dy )
+                    { /* Direction changed.  Insert a fake coord, old
+                      ** position but new edge number. */
+                    ++(fh->curedge);
+                    cp = &(fh->coords[fh->n]);
+                    cp->x = ocp->x;
+                    cp->y = ocp->y;
+                    cp->edge = fh->curedge;
+                    ++(fh->n);
+                    }
+                fh->ydir = dy;
+                if ( fh->startydir == 0 )
+                    fh->startydir = dy;
+                }
+            }
+        }
 
     /* Save this coord. */
     cp = &(fh->coords[fh->n]);
@@ -554,13 +554,13 @@ yx_compare(const void* v1,const void* v2) {
  coord* c2 = (coord *)v2;
 
     if ( c1->y > c2->y )
-	return 1;
+        return 1;
     if ( c1->y < c2->y )
-	return -1;
+        return -1;
     if ( c1->x > c2->x )
-	return 1;
+        return 1;
     if ( c1->x < c2->x )
-	return -1;
+        return -1;
     return 0;
     }
 
@@ -587,17 +587,17 @@ ppmd_fill( pixels, cols, rows, maxval, fillhandle, drawprocP, clientdata )
 
     /* Close off final segment. */
     if ( fh->n > 0 && fh->startydir != 0 && fh->ydir != 0 )
-	if ( fh->startydir == fh->ydir )
-	    { /* Oops, first edge and last edge are the same. */
-	    register coord* fcp;
-	    int lastedge, oldedge;
-
-	    lastedge = fh->coords[fh->n - 1].edge;
-	    fcp = &(fh->coords[fh->segstart]);
-	    oldedge = fcp->edge;
-	    for ( ; fcp->edge == oldedge; ++fcp )
-		fcp->edge = lastedge;
-	    }
+        if ( fh->startydir == fh->ydir )
+            { /* Oops, first edge and last edge are the same. */
+            register coord* fcp;
+            int lastedge, oldedge;
+
+            lastedge = fh->coords[fh->n - 1].edge;
+            fcp = &(fh->coords[fh->segstart]);
+            oldedge = fcp->edge;
+            for ( ; fcp->edge == oldedge; ++fcp )
+                fcp->edge = lastedge;
+            }
 
     /* Restore clipping now. */
     (void) ppmd_setlineclip( oldclip );
@@ -608,88 +608,88 @@ ppmd_fill( pixels, cols, rows, maxval, fillhandle, drawprocP, clientdata )
     /* Find equal coords with different edge numbers, and swap if necessary. */
     edge = -1;
     for ( i = 0; i < fh->n; ++i )
-	{
-	cp = &(fh->coords[i]);
-	if ( i > 1 && eq && cp->edge != edge && cp->edge == pedge )
-	    { /* Swap .-1 and .-2. */
-	    coord t;
-
-	    t = fh->coords[i-1];
-	    fh->coords[i-1] = fh->coords[i-2];
-	    fh->coords[i-2] = t;
-	    }
-	if ( i > 0 )
-	    {
-	    if ( cp->x == lx && cp->y == py )
-		{
-		eq = 1;
-		if ( cp->edge != edge && cp->edge == pedge )
-		    { /* Swap . and .-1. */
-		    coord t;
-
-		    t = *cp;
-		    *cp = fh->coords[i-1];
-		    fh->coords[i-1] = t;
-		    }
-		}
-	    else
-		eq = 0;
-	    }
-	lx = cp->x;
-	py = cp->y;
-	pedge = edge;
-	edge = cp->edge;
-	}
+        {
+        cp = &(fh->coords[i]);
+        if ( i > 1 && eq && cp->edge != edge && cp->edge == pedge )
+            { /* Swap .-1 and .-2. */
+            coord t;
+
+            t = fh->coords[i-1];
+            fh->coords[i-1] = fh->coords[i-2];
+            fh->coords[i-2] = t;
+            }
+        if ( i > 0 )
+            {
+            if ( cp->x == lx && cp->y == py )
+                {
+                eq = 1;
+                if ( cp->edge != edge && cp->edge == pedge )
+                    { /* Swap . and .-1. */
+                    coord t;
+
+                    t = *cp;
+                    *cp = fh->coords[i-1];
+                    fh->coords[i-1] = t;
+                    }
+                }
+            else
+                eq = 0;
+            }
+        lx = cp->x;
+        py = cp->y;
+        pedge = edge;
+        edge = cp->edge;
+        }
 
     /* Ok, now run through the coords filling spans. */
     for ( i = 0; i < fh->n; ++i )
-	{
-	cp = &(fh->coords[i]);
-	if ( i == 0 )
-	    {
-	    lx = rx = cp->x;
-	    py = cp->y;
-	    edge = cp->edge;
-	    leftside = 1;
-	    }
-	else
-	    {
-	    if ( cp->y != py )
-		{ /* Row changed.  Emit old span and start a new one. */
-		ppmd_filledrectangle(
-		    pixels, cols, rows, maxval, lx, py, rx - lx + 1, 1,
-		    drawprocP, clientdata);
-		lx = rx = cp->x;
-		py = cp->y;
-		edge = cp->edge;
-		leftside = 1;
-		}
-	    else
-		{
-		if ( cp->edge == edge )
-		    { /* Continuation of side. */
-		    rx = cp->x;
-		    }
-		else
-		    { /* Edge changed.  Is it a span? */
-		    if ( leftside )
-			{
-			rx = cp->x;
-			leftside = 0;
-			}
-		    else
-			{ /* Got a span to fill. */
-			ppmd_filledrectangle(
-			    pixels, cols, rows, maxval, lx, py, rx - lx + 1,
-			    1, drawprocP, clientdata);
-			lx = rx = cp->x;
-			leftside = 1;
-			}
-		    edge = cp->edge;
-		    }
-		}
-	    }
-	}
+        {
+        cp = &(fh->coords[i]);
+        if ( i == 0 )
+            {
+            lx = rx = cp->x;
+            py = cp->y;
+            edge = cp->edge;
+            leftside = 1;
+            }
+        else
+            {
+            if ( cp->y != py )
+                { /* Row changed.  Emit old span and start a new one. */
+                ppmd_filledrectangle(
+                    pixels, cols, rows, maxval, lx, py, rx - lx + 1, 1,
+                    drawprocP, clientdata);
+                lx = rx = cp->x;
+                py = cp->y;
+                edge = cp->edge;
+                leftside = 1;
+                }
+            else
+                {
+                if ( cp->edge == edge )
+                    { /* Continuation of side. */
+                    rx = cp->x;
+                    }
+                else
+                    { /* Edge changed.  Is it a span? */
+                    if ( leftside )
+                        {
+                        rx = cp->x;
+                        leftside = 0;
+                        }
+                    else
+                        { /* Got a span to fill. */
+                        ppmd_filledrectangle(
+                            pixels, cols, rows, maxval, lx, py, rx - lx + 1,
+                            1, drawprocP, clientdata);
+                        lx = rx = cp->x;
+                        leftside = 1;
+                        }
+                    edge = cp->edge;
+                    }
+                }
+            }
+        }
 
     /* All done.  Free up the fillhandle and leave. */
     free( fh->coords );

+ 204 - 204
panda/src/pnmimagetypes/color.c

@@ -16,261 +16,261 @@
 #include <malloc.h>
 #endif
 
-#define  MINELEN	8	/* minimum scanline length for encoding */
-#define  MAXELEN	0x7fff	/* maximum scanline length for encoding */
-#define  MINRUN		4	/* minimum run length */
+#define  MINELEN        8       /* minimum scanline length for encoding */
+#define  MAXELEN        0x7fff  /* maximum scanline length for encoding */
+#define  MINRUN         4       /* minimum run length */
 
 void setcolr(register COLR, double, double, double);
 void colr_color(register COLOR, register COLR);
 
 
 char *
-tempbuffer(unsigned len)		/* get a temporary buffer */
+tempbuffer(unsigned len)                /* get a temporary buffer */
 {
 #ifndef WIN32VC
-	extern char  *malloc(size_t), *realloc(void *, size_t);
+        extern char  *malloc(size_t), *realloc(void *, size_t);
 #endif
-	static char  *tempbuf = NULL;
-	static unsigned  tempbuflen = 0;
-
-	if (len > tempbuflen) {
-		if (tempbuflen > 0)
-			tempbuf = (char *)realloc(tempbuf, len);
-		else
-			tempbuf = (char *)malloc(len);
-		tempbuflen = tempbuf==NULL ? 0 : len;
-	}
-	return(tempbuf);
+        static char  *tempbuf = NULL;
+        static unsigned  tempbuflen = 0;
+
+        if (len > tempbuflen) {
+                if (tempbuflen > 0)
+                        tempbuf = (char *)realloc(tempbuf, len);
+                else
+                        tempbuf = (char *)malloc(len);
+                tempbuflen = tempbuf==NULL ? 0 : len;
+        }
+        return(tempbuf);
 }
 
 
 int fwritecolrs(register COLR *scanline, unsigned len, register FILE *fp)
-		/* write out a colr scanline */
+                /* write out a colr scanline */
 {
-	register int  i, j, beg, cnt;
-	int  c2;
-	
-	if (len < MINELEN || len > MAXELEN)	/* OOBs, write out flat */
-		return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len);
-					/* put magic header */
-	putc(2, fp);
-	putc(2, fp);
-	putc(len>>8, fp);
-	putc(len&255, fp);
-					/* put components seperately */
-	for (i = 0; i < 4; i++) {
-	    for (j = 0; j < len; j += cnt) {	/* find next run */
-		for (beg = j; beg < len; beg += cnt) {
-		    for (cnt = 1; cnt < 127 && beg+cnt < len &&
-			    scanline[beg+cnt][i] == scanline[beg][i]; cnt++)
-			;
-		    if (cnt >= MINRUN)
-			break;			/* long enough */
-		}
-		if (beg-j > 1 && beg-j < MINRUN) {
-		    c2 = j+1;
-		    while (scanline[c2++][i] == scanline[j][i])
-			if (c2 == beg) {	/* short run */
-			    putc(128+beg-j, fp);
-			    putc(scanline[j][i], fp);
-			    j = beg;
-			    break;
-			}
-		}
-		while (j < beg) {		/* write out non-run */
-		    if ((c2 = beg-j) > 128) c2 = 128;
-		    putc(c2, fp);
-		    while (c2--)
-			putc(scanline[j++][i], fp);
-		}
-		if (cnt >= MINRUN) {		/* write out run */
-		    putc(128+cnt, fp);
-		    putc(scanline[beg][i], fp);
-		} else
-		    cnt = 0;
-	    }
-	}
-	return(ferror(fp) ? -1 : 0);
+        register int  i, j, beg, cnt;
+        int  c2;
+
+        if (len < MINELEN || len > MAXELEN)     /* OOBs, write out flat */
+                return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len);
+                                        /* put magic header */
+        putc(2, fp);
+        putc(2, fp);
+        putc(len>>8, fp);
+        putc(len&255, fp);
+                                        /* put components seperately */
+        for (i = 0; i < 4; i++) {
+            for (j = 0; j < len; j += cnt) {    /* find next run */
+                for (beg = j; beg < len; beg += cnt) {
+                    for (cnt = 1; cnt < 127 && beg+cnt < len &&
+                            scanline[beg+cnt][i] == scanline[beg][i]; cnt++)
+                        ;
+                    if (cnt >= MINRUN)
+                        break;                  /* long enough */
+                }
+                if (beg-j > 1 && beg-j < MINRUN) {
+                    c2 = j+1;
+                    while (scanline[c2++][i] == scanline[j][i])
+                        if (c2 == beg) {        /* short run */
+                            putc(128+beg-j, fp);
+                            putc(scanline[j][i], fp);
+                            j = beg;
+                            break;
+                        }
+                }
+                while (j < beg) {               /* write out non-run */
+                    if ((c2 = beg-j) > 128) c2 = 128;
+                    putc(c2, fp);
+                    while (c2--)
+                        putc(scanline[j++][i], fp);
+                }
+                if (cnt >= MINRUN) {            /* write out run */
+                    putc(128+cnt, fp);
+                    putc(scanline[beg][i], fp);
+                } else
+                    cnt = 0;
+            }
+        }
+        return(ferror(fp) ? -1 : 0);
 }
 
 int oldreadcolrs(register COLR *scanline, int len, register FILE *fp);
 
 int freadcolrs(register COLR *scanline, int len, register FILE *fp)
-		/* read in an encoded colr scanline */
+                /* read in an encoded colr scanline */
 {
-	register int  i, j;
-	int  code, val;
-					/* determine scanline type */
-	if (len < MINELEN || len > MAXELEN)
-		return(oldreadcolrs(scanline, len, fp));
-	if ((i = getc(fp)) == EOF)
-		return(-1);
-	if (i != 2) {
-		ungetc(i, fp);
-		return(oldreadcolrs(scanline, len, fp));
-	}
-	scanline[0][GRN] = getc(fp);
-	scanline[0][BLU] = getc(fp);
-	if ((i = getc(fp)) == EOF)
-		return(-1);
-	if (scanline[0][GRN] != 2 || scanline[0][BLU] & 128) {
-		scanline[0][RED] = 2;
-		scanline[0][EXP] = i;
-		return(oldreadcolrs(scanline+1, len-1, fp));
-	}
-	if ((scanline[0][BLU]<<8 | i) != len)
-		return(-1);		/* length mismatch! */
-					/* read each component */
-	for (i = 0; i < 4; i++)
-	    for (j = 0; j < len; ) {
-		if ((code = getc(fp)) == EOF)
-		    return(-1);
-		if (code > 128) {	/* run */
-		    code &= 127;
-		    val = getc(fp);
-		    while (code--)
-			scanline[j++][i] = val;
-		} else			/* non-run */
-		    while (code--)
-			scanline[j++][i] = getc(fp);
-	    }
-	return(feof(fp) ? -1 : 0);
+        register int  i, j;
+        int  code, val;
+                                        /* determine scanline type */
+        if (len < MINELEN || len > MAXELEN)
+                return(oldreadcolrs(scanline, len, fp));
+        if ((i = getc(fp)) == EOF)
+                return(-1);
+        if (i != 2) {
+                ungetc(i, fp);
+                return(oldreadcolrs(scanline, len, fp));
+        }
+        scanline[0][GRN] = getc(fp);
+        scanline[0][BLU] = getc(fp);
+        if ((i = getc(fp)) == EOF)
+                return(-1);
+        if (scanline[0][GRN] != 2 || scanline[0][BLU] & 128) {
+                scanline[0][RED] = 2;
+                scanline[0][EXP] = i;
+                return(oldreadcolrs(scanline+1, len-1, fp));
+        }
+        if ((scanline[0][BLU]<<8 | i) != len)
+                return(-1);             /* length mismatch! */
+                                        /* read each component */
+        for (i = 0; i < 4; i++)
+            for (j = 0; j < len; ) {
+                if ((code = getc(fp)) == EOF)
+                    return(-1);
+                if (code > 128) {       /* run */
+                    code &= 127;
+                    val = getc(fp);
+                    while (code--)
+                        scanline[j++][i] = val;
+                } else                  /* non-run */
+                    while (code--)
+                        scanline[j++][i] = getc(fp);
+            }
+        return(feof(fp) ? -1 : 0);
 }
 
 
-		/* read in an old colr scanline */
+                /* read in an old colr scanline */
 int oldreadcolrs(register COLR *scanline, int len, register FILE *fp)
 {
-	int  rshift;
-	register int  i;
-	
-	rshift = 0;
-	
-	while (len > 0) {
-		scanline[0][RED] = getc(fp);
-		scanline[0][GRN] = getc(fp);
-		scanline[0][BLU] = getc(fp);
-		scanline[0][EXP] = getc(fp);
-		if (feof(fp) || ferror(fp))
-			return(-1);
-		if (scanline[0][RED] == 1 &&
-				scanline[0][GRN] == 1 &&
-				scanline[0][BLU] == 1) {
-			for (i = scanline[0][EXP] << rshift; i > 0; i--) {
-				copycolr(scanline[0], scanline[-1]);
-				scanline++;
-				len--;
-			}
-			rshift += 8;
-		} else {
-			scanline++;
-			len--;
-			rshift = 0;
-		}
-	}
-	return(0);
+        int  rshift;
+        register int  i;
+
+        rshift = 0;
+
+        while (len > 0) {
+                scanline[0][RED] = getc(fp);
+                scanline[0][GRN] = getc(fp);
+                scanline[0][BLU] = getc(fp);
+                scanline[0][EXP] = getc(fp);
+                if (feof(fp) || ferror(fp))
+                        return(-1);
+                if (scanline[0][RED] == 1 &&
+                                scanline[0][GRN] == 1 &&
+                                scanline[0][BLU] == 1) {
+                        for (i = scanline[0][EXP] << rshift; i > 0; i--) {
+                                copycolr(scanline[0], scanline[-1]);
+                                scanline++;
+                                len--;
+                        }
+                        rshift += 8;
+                } else {
+                        scanline++;
+                        len--;
+                        rshift = 0;
+                }
+        }
+        return(0);
 }
 
 
-	/* write out a scanline */
-int fwritescan(register COLOR *scanline, int len, FILE *fp)	
+        /* write out a scanline */
+int fwritescan(register COLOR *scanline, int len, FILE *fp)
 {
-	COLR  *clrscan;
-	int  n;
-	register COLR  *sp;
-					/* get scanline buffer */
-	if ((sp = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
-		return(-1);
-	clrscan = sp;
-					/* convert scanline */
-	n = len;
-	while (n-- > 0) {
-		setcolr(sp[0], scanline[0][RED],
-				  scanline[0][GRN],
-				  scanline[0][BLU]);
-		scanline++;
-		sp++;
-	}
-	return(fwritecolrs(clrscan, len, fp));
+        COLR  *clrscan;
+        int  n;
+        register COLR  *sp;
+                                        /* get scanline buffer */
+        if ((sp = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
+                return(-1);
+        clrscan = sp;
+                                        /* convert scanline */
+        n = len;
+        while (n-- > 0) {
+                setcolr(sp[0], scanline[0][RED],
+                                  scanline[0][GRN],
+                                  scanline[0][BLU]);
+                scanline++;
+                sp++;
+        }
+        return(fwritecolrs(clrscan, len, fp));
 }
 
 
 int freadscan(register COLOR *scanline, int len, FILE *fp)
-			/* read in a scanline */
+                        /* read in a scanline */
 {
-	register COLR  *clrscan;
-
-	if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
-		return(-1);
-	if (freadcolrs(clrscan, len, fp) < 0)
-		return(-1);
-					/* convert scanline */
-	colr_color(scanline[0], clrscan[0]);
-	while (--len > 0) {
-		scanline++; clrscan++;
-		if (clrscan[0][RED] == clrscan[-1][RED] &&
-			    clrscan[0][GRN] == clrscan[-1][GRN] &&
-			    clrscan[0][BLU] == clrscan[-1][BLU] &&
-			    clrscan[0][EXP] == clrscan[-1][EXP])
-			copycolor(scanline[0], scanline[-1]);
-		else
-			colr_color(scanline[0], clrscan[0]);
-	}
-	return(0);
+        register COLR  *clrscan;
+
+        if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
+                return(-1);
+        if (freadcolrs(clrscan, len, fp) < 0)
+                return(-1);
+                                        /* convert scanline */
+        colr_color(scanline[0], clrscan[0]);
+        while (--len > 0) {
+                scanline++; clrscan++;
+                if (clrscan[0][RED] == clrscan[-1][RED] &&
+                            clrscan[0][GRN] == clrscan[-1][GRN] &&
+                            clrscan[0][BLU] == clrscan[-1][BLU] &&
+                            clrscan[0][EXP] == clrscan[-1][EXP])
+                        copycolor(scanline[0], scanline[-1]);
+                else
+                        colr_color(scanline[0], clrscan[0]);
+        }
+        return(0);
 }
 
 
 void
 setcolr(register COLR clr, double r, double g, double b)
-			/* assign a short color value */
+                        /* assign a short color value */
 {
-	double  d;
-	int  e;
-	
-	d = r > g ? r : g;
-	if (b > d) d = b;
-
-	if (d <= 1e-32) {
-		clr[RED] = clr[GRN] = clr[BLU] = 0;
-		clr[EXP] = 0;
-		return;
-	}
-
-	d = frexp(d, &e) * 255.9999 / d;
-
-	clr[RED] = r * d;
-	clr[GRN] = g * d;
-	clr[BLU] = b * d;
-	clr[EXP] = e + COLXS;
+        double  d;
+        int  e;
+
+        d = r > g ? r : g;
+        if (b > d) d = b;
+
+        if (d <= 1e-32) {
+                clr[RED] = clr[GRN] = clr[BLU] = 0;
+                clr[EXP] = 0;
+                return;
+        }
+
+        d = frexp(d, &e) * 255.9999 / d;
+
+        clr[RED] = r * d;
+        clr[GRN] = g * d;
+        clr[BLU] = b * d;
+        clr[EXP] = e + COLXS;
 }
 
 
 void
 colr_color(register COLOR col, register COLR clr)
-			/* convert short to float color */
+                        /* convert short to float color */
 {
-	double  f;
-	
-	if (clr[EXP] == 0)
-		col[RED] = col[GRN] = col[BLU] = 0.0;
-	else {
-		f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
-		col[RED] = (clr[RED] + 0.5)*f;
-		col[GRN] = (clr[GRN] + 0.5)*f;
-		col[BLU] = (clr[BLU] + 0.5)*f;
-	}
+        double  f;
+
+        if (clr[EXP] == 0)
+                col[RED] = col[GRN] = col[BLU] = 0.0;
+        else {
+                f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
+                col[RED] = (clr[RED] + 0.5)*f;
+                col[GRN] = (clr[GRN] + 0.5)*f;
+                col[BLU] = (clr[BLU] + 0.5)*f;
+        }
 }
 
 
 int
 bigdiff(register COLOR c1, register COLOR c2, double md)
-			/* c1 delta c2 > md? */
+                        /* c1 delta c2 > md? */
 {
-	register int  i;
+        register int  i;
 
-	for (i = 0; i < 3; i++)
-		if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) ||
-			colval(c2,i)-colval(c1,i) > md*colval(c1,i))
-			return(1);
-	return(0);
+        for (i = 0; i < 3; i++)
+                if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) ||
+                        colval(c2,i)-colval(c1,i) > md*colval(c1,i))
+                        return(1);
+        return(0);
 }

+ 168 - 168
panda/src/pnmimagetypes/colrops.c

@@ -6,222 +6,222 @@
 
 #include "color.h"
 
-#define NULL		0
+#define NULL            0
 
 #define bmalloc malloc
 #ifndef WIN32VC
-extern char	*bmalloc(int);
+extern char     *bmalloc(int);
 #else
 #include <malloc.h>
 #include <math.h>
 #endif
 
-#define MAXGSHIFT	31		/* maximum shift for gamma table */
+#define MAXGSHIFT       31              /* maximum shift for gamma table */
 
-static BYTE	*g_mant = NULL, *g_nexp = NULL;
+static BYTE     *g_mant = NULL, *g_nexp = NULL;
 
-static BYTE	(*g_bval)[256] = NULL;
+static BYTE     (*g_bval)[256] = NULL;
 
 #ifndef pow
 #ifndef WIN32VC
-extern double	pow(double, double);
+extern double   pow(double, double);
 #endif
 #endif
 
 
 int setcolrcor(double (*f)(double, double), double a2)
-		/* set brightness correction */
+                /* set brightness correction */
 {
-	double	mult;
-	register int	i, j;
-					/* allocate tables */
-	if (g_bval == NULL && (g_bval =
-			(BYTE (*)[256])bmalloc((MAXGSHIFT+1)*256)) == NULL)
-		return(-1);
-					/* compute colr -> gamb mapping */
-	mult = 1.0/256.0;
-	for (i = 0; i <= MAXGSHIFT; i++) {
-		for (j = 0; j < 256; j++)
-			g_bval[i][j] = 256.0 * (*f)((j+.5)*mult, a2);
-		mult *= 0.5;
-	}
-	return(0);
+        double  mult;
+        register int    i, j;
+                                        /* allocate tables */
+        if (g_bval == NULL && (g_bval =
+                        (BYTE (*)[256])bmalloc((MAXGSHIFT+1)*256)) == NULL)
+                return(-1);
+                                        /* compute colr -> gamb mapping */
+        mult = 1.0/256.0;
+        for (i = 0; i <= MAXGSHIFT; i++) {
+                for (j = 0; j < 256; j++)
+                        g_bval[i][j] = 256.0 * (*f)((j+.5)*mult, a2);
+                mult *= 0.5;
+        }
+        return(0);
 }
 
 
 int setcolrinv(double (*f)(double, double), double a2)
-		/* set inverse brightness correction */
+                /* set inverse brightness correction */
 {
-	double	mult;
-	register int	i, j;
-					/* allocate tables */
-	if (g_mant == NULL && (g_mant = (BYTE *)bmalloc(256)) == NULL)
-		return(-1);
-	if (g_nexp == NULL && (g_nexp = (BYTE *)bmalloc(256)) == NULL)
-		return(-1);
-					/* compute gamb -> colr mapping */
-	i = 0;
-	mult = 256.0;
-	for (j = 255; j > 0; j--) {
-		while ((g_mant[j] = mult * (*f)(j/256.0, a2)) < 128) {
-			i++;
-			mult *= 2.0;
-		}
-		g_nexp[j] = i;
-	}
-	g_mant[0] = 0;
-	g_nexp[0] = COLXS;
-	return(0);
+        double  mult;
+        register int    i, j;
+                                        /* allocate tables */
+        if (g_mant == NULL && (g_mant = (BYTE *)bmalloc(256)) == NULL)
+                return(-1);
+        if (g_nexp == NULL && (g_nexp = (BYTE *)bmalloc(256)) == NULL)
+                return(-1);
+                                        /* compute gamb -> colr mapping */
+        i = 0;
+        mult = 256.0;
+        for (j = 255; j > 0; j--) {
+                while ((g_mant[j] = mult * (*f)(j/256.0, a2)) < 128) {
+                        i++;
+                        mult *= 2.0;
+                }
+                g_nexp[j] = i;
+        }
+        g_mant[0] = 0;
+        g_nexp[0] = COLXS;
+        return(0);
 }
 
 
-int setcolrgam(double g)			/* set gamma conversion */
+int setcolrgam(double g)                        /* set gamma conversion */
 {
-	if (setcolrcor(pow, 1.0/g) < 0)
-		return(-1);
-	return(setcolrinv(pow, g));
+        if (setcolrcor(pow, 1.0/g) < 0)
+                return(-1);
+        return(setcolrinv(pow, g));
 }
 
 
 int colrs_gambs(register COLR *scan, int len)
-		/* convert scanline of colrs to gamma bytes */
+                /* convert scanline of colrs to gamma bytes */
 {
-	register int	i, expo;
-
-	if (g_bval == NULL)
-		return(-1);
-	while (len-- > 0) {
-		expo = scan[0][EXP] - COLXS;
-		if (expo < -MAXGSHIFT) {
-			if (expo < -MAXGSHIFT-8) {
-				scan[0][RED] =
-				scan[0][GRN] =
-				scan[0][BLU] = 0;
-			} else {
-				i = (-MAXGSHIFT-1) - expo;
-				scan[0][RED] = 
-				g_bval[MAXGSHIFT][((scan[0][RED]>>i)+1)>>1];
-				scan[0][GRN] =
-				g_bval[MAXGSHIFT][((scan[0][GRN]>>i)+1)>>1];
-				scan[0][BLU] =
-				g_bval[MAXGSHIFT][((scan[0][BLU]>>i)+1)>>1];
-			}
-		} else if (expo > 0) {
-			if (expo > 8) {
-				scan[0][RED] =
-				scan[0][GRN] =
-				scan[0][BLU] = 255;
-			} else {
-				i = (scan[0][RED]<<1 | 1) << (expo-1);
-				scan[0][RED] = i > 255 ? 255 : g_bval[0][i];
-				i = (scan[0][GRN]<<1 | 1) << (expo-1);
-				scan[0][GRN] = i > 255 ? 255 : g_bval[0][i];
-				i = (scan[0][BLU]<<1 | 1) << (expo-1);
-				scan[0][BLU] = i > 255 ? 255 : g_bval[0][i];
-			}
-		} else {
-			scan[0][RED] = g_bval[-expo][scan[0][RED]];
-			scan[0][GRN] = g_bval[-expo][scan[0][GRN]];
-			scan[0][BLU] = g_bval[-expo][scan[0][BLU]];
-		}
-		scan[0][EXP] = COLXS;
-		scan++;
-	}
-	return(0);
+        register int    i, expo;
+
+        if (g_bval == NULL)
+                return(-1);
+        while (len-- > 0) {
+                expo = scan[0][EXP] - COLXS;
+                if (expo < -MAXGSHIFT) {
+                        if (expo < -MAXGSHIFT-8) {
+                                scan[0][RED] =
+                                scan[0][GRN] =
+                                scan[0][BLU] = 0;
+                        } else {
+                                i = (-MAXGSHIFT-1) - expo;
+                                scan[0][RED] = 
+                                g_bval[MAXGSHIFT][((scan[0][RED]>>i)+1)>>1];
+                                scan[0][GRN] =
+                                g_bval[MAXGSHIFT][((scan[0][GRN]>>i)+1)>>1];
+                                scan[0][BLU] =
+                                g_bval[MAXGSHIFT][((scan[0][BLU]>>i)+1)>>1];
+                        }
+                } else if (expo > 0) {
+                        if (expo > 8) {
+                                scan[0][RED] =
+                                scan[0][GRN] =
+                                scan[0][BLU] = 255;
+                        } else {
+                                i = (scan[0][RED]<<1 | 1) << (expo-1);
+                                scan[0][RED] = i > 255 ? 255 : g_bval[0][i];
+                                i = (scan[0][GRN]<<1 | 1) << (expo-1);
+                                scan[0][GRN] = i > 255 ? 255 : g_bval[0][i];
+                                i = (scan[0][BLU]<<1 | 1) << (expo-1);
+                                scan[0][BLU] = i > 255 ? 255 : g_bval[0][i];
+                        }
+                } else {
+                        scan[0][RED] = g_bval[-expo][scan[0][RED]];
+                        scan[0][GRN] = g_bval[-expo][scan[0][GRN]];
+                        scan[0][BLU] = g_bval[-expo][scan[0][BLU]];
+                }
+                scan[0][EXP] = COLXS;
+                scan++;
+        }
+        return(0);
 }
 
 
 int gambs_colrs(register COLR *scan, int len)
-	/* convert gamma bytes to colr scanline */
+        /* convert gamma bytes to colr scanline */
 {
-	register int	nexpo;
-
-	if (g_mant == NULL || g_nexp == NULL)
-		return(-1);
-	while (len-- > 0) {
-		nexpo = g_nexp[scan[0][RED]];
-		if (g_nexp[scan[0][GRN]] < nexpo)
-			nexpo = g_nexp[scan[0][GRN]];
-		if (g_nexp[scan[0][BLU]] < nexpo)
-			nexpo = g_nexp[scan[0][BLU]];
-		if (nexpo < g_nexp[scan[0][RED]])
-			scan[0][RED] = g_mant[scan[0][RED]]
-					>> (g_nexp[scan[0][RED]]-nexpo);
-		else
-			scan[0][RED] = g_mant[scan[0][RED]];
-		if (nexpo < g_nexp[scan[0][GRN]])
-			scan[0][GRN] = g_mant[scan[0][GRN]]
-					>> (g_nexp[scan[0][GRN]]-nexpo);
-		else
-			scan[0][GRN] = g_mant[scan[0][GRN]];
-		if (nexpo < g_nexp[scan[0][BLU]])
-			scan[0][BLU] = g_mant[scan[0][BLU]]
-					>> (g_nexp[scan[0][BLU]]-nexpo);
-		else
-			scan[0][BLU] = g_mant[scan[0][BLU]];
-		scan[0][EXP] = COLXS - nexpo;
-		scan++;
-	}
-	return(0);
+        register int    nexpo;
+
+        if (g_mant == NULL || g_nexp == NULL)
+                return(-1);
+        while (len-- > 0) {
+                nexpo = g_nexp[scan[0][RED]];
+                if (g_nexp[scan[0][GRN]] < nexpo)
+                        nexpo = g_nexp[scan[0][GRN]];
+                if (g_nexp[scan[0][BLU]] < nexpo)
+                        nexpo = g_nexp[scan[0][BLU]];
+                if (nexpo < g_nexp[scan[0][RED]])
+                        scan[0][RED] = g_mant[scan[0][RED]]
+                                        >> (g_nexp[scan[0][RED]]-nexpo);
+                else
+                        scan[0][RED] = g_mant[scan[0][RED]];
+                if (nexpo < g_nexp[scan[0][GRN]])
+                        scan[0][GRN] = g_mant[scan[0][GRN]]
+                                        >> (g_nexp[scan[0][GRN]]-nexpo);
+                else
+                        scan[0][GRN] = g_mant[scan[0][GRN]];
+                if (nexpo < g_nexp[scan[0][BLU]])
+                        scan[0][BLU] = g_mant[scan[0][BLU]]
+                                        >> (g_nexp[scan[0][BLU]]-nexpo);
+                else
+                        scan[0][BLU] = g_mant[scan[0][BLU]];
+                scan[0][EXP] = COLXS - nexpo;
+                scan++;
+        }
+        return(0);
 }
 
 
 void
 shiftcolrs(register COLR *scan, register int len, register int adjust)
-	/* shift a scanline of colors by 2^adjust */
+        /* shift a scanline of colors by 2^adjust */
 {
-	int	minexp;
-
-	if (adjust == 0)
-		return;
-	minexp = adjust < 0 ? -adjust : 0;
-	while (len-- > 0) {
-		if (scan[0][EXP] <= minexp)
-			scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
-			scan[0][EXP] = 0;
-		else
-			scan[0][EXP] += adjust;
-		scan++;
-	}
+        int     minexp;
+
+        if (adjust == 0)
+                return;
+        minexp = adjust < 0 ? -adjust : 0;
+        while (len-- > 0) {
+                if (scan[0][EXP] <= minexp)
+                        scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
+                        scan[0][EXP] = 0;
+                else
+                        scan[0][EXP] += adjust;
+                scan++;
+        }
 }
 
 
 void
-normcolrs(register COLR *scan, int len, int adjust)	
+normcolrs(register COLR *scan, int len, int adjust)
 /* normalize a scanline of colrs */
 {
-	register int  c;
-	register int  shift;
-
-	while (len-- > 0) {
-		shift = scan[0][EXP] + adjust - COLXS;
-		if (shift > 0) {
-			if (shift > 8) {
-				scan[0][RED] =
-				scan[0][GRN] =
-				scan[0][BLU] = 255;
-			} else {
-				shift--;
-				c = (scan[0][RED]<<1 | 1) << shift;
-				scan[0][RED] = c > 255 ? 255 : c;
-				c = (scan[0][GRN]<<1 | 1) << shift;
-				scan[0][GRN] = c > 255 ? 255 : c;
-				c = (scan[0][BLU]<<1 | 1) << shift;
-				scan[0][BLU] = c > 255 ? 255 : c;
-			}
-		} else if (shift < 0) {
-			if (shift < -8) {
-				scan[0][RED] =
-				scan[0][GRN] =
-				scan[0][BLU] = 0;
-			} else {
-				shift = -1-shift;
-				scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
-				scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
-				scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
-			}
-		}
-		scan[0][EXP] = COLXS - adjust;
-		scan++;
-	}
+        register int  c;
+        register int  shift;
+
+        while (len-- > 0) {
+                shift = scan[0][EXP] + adjust - COLXS;
+                if (shift > 0) {
+                        if (shift > 8) {
+                                scan[0][RED] =
+                                scan[0][GRN] =
+                                scan[0][BLU] = 255;
+                        } else {
+                                shift--;
+                                c = (scan[0][RED]<<1 | 1) << shift;
+                                scan[0][RED] = c > 255 ? 255 : c;
+                                c = (scan[0][GRN]<<1 | 1) << shift;
+                                scan[0][GRN] = c > 255 ? 255 : c;
+                                c = (scan[0][BLU]<<1 | 1) << shift;
+                                scan[0][BLU] = c > 255 ? 255 : c;
+                        }
+                } else if (shift < 0) {
+                        if (shift < -8) {
+                                scan[0][RED] =
+                                scan[0][GRN] =
+                                scan[0][BLU] = 0;
+                        } else {
+                                shift = -1-shift;
+                                scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
+                                scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
+                                scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
+                        }
+                }
+                scan[0][EXP] = COLXS - adjust;
+                scan++;
+        }
 }

+ 125 - 125
panda/src/pnmimagetypes/header.c

@@ -3,17 +3,17 @@
 /*
  *  header.c - routines for reading and writing information headers.
  *
- *	8/19/88
+ *      8/19/88
  *
- *  newheader(t,fp)	start new information header identified by string t
- *  isheadid(s)		returns true if s is a header id line
- *  headidval(r,s)	copy header identifier value in s to r
+ *  newheader(t,fp)     start new information header identified by string t
+ *  isheadid(s)         returns true if s is a header id line
+ *  headidval(r,s)      copy header identifier value in s to r
  *  printargs(ac,av,fp) print an argument list to fp, followed by '\n'
- *  isformat(s)		returns true if s is of the form "FORMAT=*"
- *  formatval(r,s)	copy the format value in s to r
- *  fputformat(s,fp)	write "FORMAT=%s" to fp
- *  getheader(fp,f,p)	read header from fp, calling f(s,p) on each line
- *  checkheader(i,p,o)	check header format from i against p and copy to o
+ *  isformat(s)         returns true if s is of the form "FORMAT=*"
+ *  formatval(r,s)      copy the format value in s to r
+ *  fputformat(s,fp)    write "FORMAT=%s" to fp
+ *  getheader(fp,f,p)   read header from fp, calling f(s,p) on each line
+ *  checkheader(i,p,o)  check header format from i against p and copy to o
  *
  *  To copy header from input to output, use getheader(fin, fputs, fout)
  */
@@ -22,132 +22,132 @@
 #include  <ctype.h>
 #include <string.h>
 
-#define	 MAXLINE	512
+#define  MAXLINE        512
 
-char  HDRSTR[] = "#?";		/* information header magic number */
+char  HDRSTR[] = "#?";          /* information header magic number */
 
-char  FMTSTR[] = "FORMAT=";	/* format identifier */
+char  FMTSTR[] = "FORMAT=";     /* format identifier */
 
 
 void
-newheader(char *s, register FILE *fp)		/* identifying line of information header */
+newheader(char *s, register FILE *fp)           /* identifying line of information header */
 {
-	fputs(HDRSTR, fp);
-	fputs(s, fp);
-	putc('\n', fp);
+        fputs(HDRSTR, fp);
+        fputs(s, fp);
+        putc('\n', fp);
 }
 
 
 int 
-headidval(register char *r, register char *s)			/* get header id (return true if is id) */
+headidval(register char *r, register char *s)                   /* get header id (return true if is id) */
 {
-	register char  *cp = HDRSTR;
+        register char  *cp = HDRSTR;
 
-	while (*cp) if (*cp++ != *s++) return(0);
-	if (r == NULL) return(1);
-	while (*s) *r++ = *s++;
-	*r = '\0';
-	return(1);
+        while (*cp) if (*cp++ != *s++) return(0);
+        if (r == NULL) return(1);
+        while (*s) *r++ = *s++;
+        *r = '\0';
+        return(1);
 }
 
 
 int
-isheadid(char *s)			/* check to see if line is header id */
+isheadid(char *s)                       /* check to see if line is header id */
 {
-	return(headidval(NULL, s));
+        return(headidval(NULL, s));
 }
 
 
 void
-printargs(int ac, char **av, register FILE *fp)		/* print arguments to a file */
+printargs(int ac, char **av, register FILE *fp)         /* print arguments to a file */
 {
-	int  quote;
-
-	while (ac-- > 0) {
-		if (strchr(*av, ' ') != NULL) {		/* quote it */
-			if (strchr(*av, '\'') != NULL)
-				quote = '"';
-			else
-				quote = '\'';
-			putc(quote, fp);
-			fputs(*av++, fp);
-			putc(quote, fp);
-		} else
-			fputs(*av++, fp);
-		putc(' ', fp);
-	}
-	putc('\n', fp);
+        int  quote;
+
+        while (ac-- > 0) {
+                if (strchr(*av, ' ') != NULL) {         /* quote it */
+                        if (strchr(*av, '\'') != NULL)
+                                quote = '"';
+                        else
+                                quote = '\'';
+                        putc(quote, fp);
+                        fputs(*av++, fp);
+                        putc(quote, fp);
+                } else
+                        fputs(*av++, fp);
+                putc(' ', fp);
+        }
+        putc('\n', fp);
 }
 
 
 int
-formatval(register char *r, register char *s)			/* get format value (return true if format) */
+formatval(register char *r, register char *s)                   /* get format value (return true if format) */
 {
-	register char  *cp = FMTSTR;
-
-	while (*cp) if (*cp++ != *s++) return(0);
-	while (isspace(*s)) s++;
-	if (!*s) return(0);
-	if (r == NULL) return(1);
-	while(*s) *r++ = *s++;
-	while (isspace(r[-1])) r--;
-	*r = '\0';
-	return(1);
+        register char  *cp = FMTSTR;
+
+        while (*cp) if (*cp++ != *s++) return(0);
+        while (isspace(*s)) s++;
+        if (!*s) return(0);
+        if (r == NULL) return(1);
+        while(*s) *r++ = *s++;
+        while (isspace(r[-1])) r--;
+        *r = '\0';
+        return(1);
 }
 
 
 int
-isformat(char *s)			/* is line a format line? */
+isformat(char *s)                       /* is line a format line? */
 {
-	return(formatval(NULL, s));
+        return(formatval(NULL, s));
 }
 
 
 void
-fputformat(char *s, FILE *fp)		/* put out a format value */
+fputformat(char *s, FILE *fp)           /* put out a format value */
 {
-	fputs(FMTSTR, fp);
-	fputs(s, fp);
-	putc('\n', fp);
+        fputs(FMTSTR, fp);
+        fputs(s, fp);
+        putc('\n', fp);
 }
 
 
 int
-getheader(FILE *fp, int (*f)(char *, char *), char *p)		/* get header from file */
+getheader(FILE *fp, int (*f)(char *, char *), char *p)          /* get header from file */
 {
-	char  buf[MAXLINE];
-
-	for ( ; ; ) {
-		buf[MAXLINE-2] = '\n';
-		if (fgets(buf, MAXLINE, fp) == NULL)
-			return(-1);
-		if (buf[0] == '\n')
-			return(0);
+        char  buf[MAXLINE];
+
+        for ( ; ; ) {
+                buf[MAXLINE-2] = '\n';
+                if (fgets(buf, MAXLINE, fp) == NULL)
+                        return(-1);
+                if (buf[0] == '\n')
+                        return(0);
 #ifdef MSDOS
-		if (buf[0] == '\r' && buf[1] == '\n')
-			return(0);
+                if (buf[0] == '\r' && buf[1] == '\n')
+                        return(0);
 #endif
-		if (buf[MAXLINE-2] != '\n') {
-			ungetc(buf[MAXLINE-2], fp);	/* prevent false end */
-			buf[MAXLINE-2] = '\0';
-		}
-		if (f != NULL)
-			(*f)(buf, p);
-	}
+                if (buf[MAXLINE-2] != '\n') {
+                        ungetc(buf[MAXLINE-2], fp);     /* prevent false end */
+                        buf[MAXLINE-2] = '\0';
+                }
+                if (f != NULL)
+                        (*f)(buf, p);
+        }
 }
 
 
 struct check {
-	FILE	*fp;
-	char	fs[64];
+        FILE    *fp;
+        char    fs[64];
 };
 
 
 static void
-mycheck(char *s, register struct check *cp)			/* check a header line for format info. */
+mycheck(char *s, register struct check *cp)                     /* check a header line for format info. */
 {
-	if (!formatval(cp->fs, s) && cp->fp != NULL)
-		fputs(s, cp->fp);
+        if (!formatval(cp->fs, s) && cp->fp != NULL)
+                fputs(s, cp->fp);
 }
 
 
@@ -159,42 +159,42 @@ mycheck(char *s, register struct check *cp)			/* check a header line for format
 #ifdef COPYMATCH
 copymatch(char *pat, char *str)
 {
-	int	docopy = 0;
-	register char	*p = pat, *s = str;
-
-	do {
-		switch (*p) {
-		case '?':			/* match any character */
-			if (!*s++)
-				return(0);
-			docopy++;
-			break;
-		case '*':			/* match any string */
-			while (p[1] == '*') p++;
-			do
-				if ( (p[1]=='?' || p[1]==*s)
-						&& copymatch(p+1,s) ) {
-					strcpy(pat, str);
-					return(1);
-				}
-			while (*s++);
-			return(0);
-		case '\\':			/* literal next */
-			p++;
-		/* fall through */
-		default:			/* normal character */
-			if (*p != *s)
-				return(0);
-			s++;
-			break;
-		}
-	} while (*p++);
-	if (docopy)
-		strcpy(pat, str);
-	return(1);
+        int     docopy = 0;
+        register char   *p = pat, *s = str;
+
+        do {
+                switch (*p) {
+                case '?':                       /* match any character */
+                        if (!*s++)
+                                return(0);
+                        docopy++;
+                        break;
+                case '*':                       /* match any string */
+                        while (p[1] == '*') p++;
+                        do
+                                if ( (p[1]=='?' || p[1]==*s)
+                                                && copymatch(p+1,s) ) {
+                                        strcpy(pat, str);
+                                        return(1);
+                                }
+                        while (*s++);
+                        return(0);
+                case '\\':                      /* literal next */
+                        p++;
+                /* fall through */
+                default:                        /* normal character */
+                        if (*p != *s)
+                                return(0);
+                        s++;
+                        break;
+                }
+        } while (*p++);
+        if (docopy)
+                strcpy(pat, str);
+        return(1);
 }
 #else
-#define copymatch(pat, s)	(!strcmp(pat, s))
+#define copymatch(pat, s)       (!strcmp(pat, s))
 #endif
 
 
@@ -214,13 +214,13 @@ copymatch(char *pat, char *str)
 int
 checkheader(FILE *fin, char *fmt, FILE *fout)
 {
-	struct check	cdat;
-
-	cdat.fp = fout;
-	cdat.fs[0] = '\0';
-	if (getheader(fin, (int (*)(char *, char *))mycheck, (char *)&cdat) < 0)
-		return(-1);
-	if (cdat.fs[0] != '\0')
-		return(copymatch(fmt, cdat.fs) ? 1 : -1);
-	return(0);
+        struct check    cdat;
+
+        cdat.fp = fout;
+        cdat.fs[0] = '\0';
+        if (getheader(fin, (int (*)(char *, char *))mycheck, (char *)&cdat) < 0)
+                return(-1);
+        if (cdat.fs[0] != '\0')
+                return(copymatch(fmt, cdat.fs) ? 1 : -1);
+        return(0);
 }

+ 58 - 58
panda/src/pnmimagetypes/resolu.c

@@ -10,82 +10,82 @@
 #include "resolu.h"
 
 
-char  resolu_buf[RESOLU_BUFLEN];	/* resolution line buffer */
+char  resolu_buf[RESOLU_BUFLEN];        /* resolution line buffer */
 
 int str2resolu(register RESOLU *, char *);
 char *resolu2str(char *, register RESOLU *);
 
 void
-fputresolu(int ord, int sl, int ns, FILE *fp)		/* put out picture dimensions */
+fputresolu(int ord, int sl, int ns, FILE *fp)           /* put out picture dimensions */
 {
-	RESOLU  rs;
-
-	if ((rs.or = ord) & YMAJOR) {
-		rs.xr = sl;
-		rs.yr = ns;
-	} else {
-		rs.xr = ns;
-		rs.yr = sl;
-	}
-	fputsresolu(&rs, fp);
+        RESOLU  rs;
+
+        if ((rs.or = ord) & YMAJOR) {
+                rs.xr = sl;
+                rs.yr = ns;
+        } else {
+                rs.xr = ns;
+                rs.yr = sl;
+        }
+        fputsresolu(&rs, fp);
 }
 
 
 int
-fgetresolu(int *sl, int *ns, FILE *fp)			/* get picture dimensions */
+fgetresolu(int *sl, int *ns, FILE *fp)                  /* get picture dimensions */
 {
-	RESOLU  rs;
-
-	if (!fgetsresolu(&rs, fp))
-		return(-1);
-	if (rs.or & YMAJOR) {
-		*sl = rs.xr;
-		*ns = rs.yr;
-	} else {
-		*sl = rs.yr;
-		*ns = rs.xr;
-	}
-	return(rs.or);
+        RESOLU  rs;
+
+        if (!fgetsresolu(&rs, fp))
+                return(-1);
+        if (rs.or & YMAJOR) {
+                *sl = rs.xr;
+                *ns = rs.yr;
+        } else {
+                *sl = rs.yr;
+                *ns = rs.xr;
+        }
+        return(rs.or);
 }
 
 
 char *
-resolu2str(char *buf, register RESOLU *rp)		/* convert resolution struct to line */
+resolu2str(char *buf, register RESOLU *rp)              /* convert resolution struct to line */
 {
-	if (rp->or&YMAJOR)
-		sprintf(buf, "%cY %d %cX %d\n",
-				rp->or&YDECR ? '-' : '+', rp->yr,
-				rp->or&XDECR ? '-' : '+', rp->xr);
-	else
-		sprintf(buf, "%cX %d %cY %d\n",
-				rp->or&XDECR ? '-' : '+', rp->xr,
-				rp->or&YDECR ? '-' : '+', rp->yr);
-	return(buf);
+        if (rp->or&YMAJOR)
+                sprintf(buf, "%cY %d %cX %d\n",
+                                rp->or&YDECR ? '-' : '+', rp->yr,
+                                rp->or&XDECR ? '-' : '+', rp->xr);
+        else
+                sprintf(buf, "%cX %d %cY %d\n",
+                                rp->or&XDECR ? '-' : '+', rp->xr,
+                                rp->or&YDECR ? '-' : '+', rp->yr);
+        return(buf);
 }
 
 
-int str2resolu(register RESOLU *rp, char *buf)		/* convert resolution line to struct */
+int str2resolu(register RESOLU *rp, char *buf)          /* convert resolution line to struct */
 {
-	register char  *xndx, *yndx;
-	register char  *cp;
-
-	if (buf == NULL)
-		return(0);
-	xndx = yndx = NULL;
-	for (cp = buf; *cp; cp++)
-		if (*cp == 'X')
-			xndx = cp;
-		else if (*cp == 'Y')
-			yndx = cp;
-	if (xndx == NULL || yndx == NULL)
-		return(0);
-	rp->or = 0;
-	if (xndx > yndx) rp->or |= YMAJOR;
-	if (xndx[-1] == '-') rp->or |= XDECR;
-	if (yndx[-1] == '-') rp->or |= YDECR;
-	if ((rp->xr = atoi(xndx+1)) <= 0)
-		return(0);
-	if ((rp->yr = atoi(yndx+1)) <= 0)
-		return(0);
-	return(1);
+        register char  *xndx, *yndx;
+        register char  *cp;
+
+        if (buf == NULL)
+                return(0);
+        xndx = yndx = NULL;
+        for (cp = buf; *cp; cp++)
+                if (*cp == 'X')
+                        xndx = cp;
+                else if (*cp == 'Y')
+                        yndx = cp;
+        if (xndx == NULL || yndx == NULL)
+                return(0);
+        rp->or = 0;
+        if (xndx > yndx) rp->or |= YMAJOR;
+        if (xndx[-1] == '-') rp->or |= XDECR;
+        if (yndx[-1] == '-') rp->or |= YDECR;
+        if ((rp->xr = atoi(xndx+1)) <= 0)
+                return(0);
+        if ((rp->yr = atoi(yndx+1)) <= 0)
+                return(0);
+        return(1);
 }

+ 407 - 407
panda/src/tiff/mkg3states.c

@@ -36,34 +36,34 @@ static char rcsid[] = "$Header$";
  *
  * BEGIN (from the original source)
  LEGAL
- *	Copyright 1989, 1990 Michael P. Marking, Post Office Box 8039,
- *	Scottsdale, Arizona 85252-8039. All rights reserved.
+ *      Copyright 1989, 1990 Michael P. Marking, Post Office Box 8039,
+ *      Scottsdale, Arizona 85252-8039. All rights reserved.
  *
- *	License is granted by the copyright holder to distribute and use this
- *	code without payment of royalties or the necessity of notification as
- *	long as this notice (all the text under "LEGAL") is included.
+ *      License is granted by the copyright holder to distribute and use this
+ *      code without payment of royalties or the necessity of notification as
+ *      long as this notice (all the text under "LEGAL") is included.
  *
- *	Reference: $Id$
+ *      Reference: $Id$
  *
- *	This program is offered without any warranty of any kind. It includes
- *	no warranty of merchantability or fitness for any purpose. Testing and
- *	suitability for any use are the sole responsibility of the user.
+ *      This program is offered without any warranty of any kind. It includes
+ *      no warranty of merchantability or fitness for any purpose. Testing and
+ *      suitability for any use are the sole responsibility of the user.
  *
  INFORMATION
- *	Although there is no support offered with this program, the author will
- *	endeavor to correct errors. Updates will also be made available from
- *	time to time.
+ *      Although there is no support offered with this program, the author will
+ *      endeavor to correct errors. Updates will also be made available from
+ *      time to time.
  *
- *	Contact: Michael P. Marking, Post Office Box 8039, Scottsdale, Arizona
- *	85252-8039 USA. Replies are not guaranteed to be swift. Beginning
- *	July 1990, e-mail may be sent to uunet!ipel!marking.
+ *      Contact: Michael P. Marking, Post Office Box 8039, Scottsdale, Arizona
+ *      85252-8039 USA. Replies are not guaranteed to be swift. Beginning
+ *      July 1990, e-mail may be sent to uunet!ipel!marking.
  *
- *	Also beginning in July 1990, this code will be archived at the
- *	ipel!phoenix BBS in file g3g4.zoo. The 24-hour telephone number
- *	for 300/1200/2400 is (602)274-0462. When logging in, specify user
- *	"public", system "bbs", and password "public".
+ *      Also beginning in July 1990, this code will be archived at the
+ *      ipel!phoenix BBS in file g3g4.zoo. The 24-hour telephone number
+ *      for 300/1200/2400 is (602)274-0462. When logging in, specify user
+ *      "public", system "bbs", and password "public".
  *
- *	This code is also available from the C Users Group in volume 317.
+ *      This code is also available from the C Users Group in volume 317.
  *
  * END (from the original source)
  */
@@ -72,12 +72,12 @@ static char rcsid[] = "$Header$";
 #include "tiffcomp.h"
 
 #ifndef TRUE
-#define	TRUE	1
-#define	FALSE	0
+#define TRUE    1
+#define FALSE   0
 #endif
 
-#define WHITE	0
-#define BLACK	1
+#define WHITE   0
+#define BLACK   1
 
 /*
  * G3 2D and G4 decoding modes.  Note that
@@ -85,19 +85,19 @@ static char rcsid[] = "$Header$";
  * (mode - MODE_VERT_V0) gives the vertical
  * adjustment for the b1 parameter.
  */
-#define MODE_NULL	0
-#define MODE_PASS	1
-#define MODE_HORIZ	2
-#define MODE_VERT_VL3	3
-#define MODE_VERT_VL2	4
-#define MODE_VERT_VL1	5
-#define MODE_VERT_V0	6
-#define MODE_VERT_VR1	7
-#define MODE_VERT_VR2	8
-#define MODE_VERT_VR3	9
-#define MODE_UNCOMP	10
-#define MODE_ERROR	11
-#define MODE_ERROR_1	12
+#define MODE_NULL       0
+#define MODE_PASS       1
+#define MODE_HORIZ      2
+#define MODE_VERT_VL3   3
+#define MODE_VERT_VL2   4
+#define MODE_VERT_VL1   5
+#define MODE_VERT_V0    6
+#define MODE_VERT_VR1   7
+#define MODE_VERT_VR2   8
+#define MODE_VERT_VR3   9
+#define MODE_UNCOMP     10
+#define MODE_ERROR      11
+#define MODE_ERROR_1    12
 
 unsigned long
 append_0(unsigned long prefix)
@@ -109,16 +109,16 @@ unsigned long
 append_1(unsigned long prefix)
 {
     static unsigned short prefix_bit[16] = {
-	0x8000, 0x4000, 0x2000, 0x1000,
-	0x0800, 0x0400, 0x0200, 0x0100,
-	0x0080, 0x0040, 0x0020, 0x0010,
-	0x0008, 0x0004, 0x0002, 0x0001
+        0x8000, 0x4000, 0x2000, 0x1000,
+        0x0800, 0x0400, 0x0200, 0x0100,
+        0x0080, 0x0040, 0x0020, 0x0010,
+        0x0008, 0x0004, 0x0002, 0x0001
     };
     unsigned char len = (prefix >> 16) & 0xf;
     return (append_0(prefix) + prefix_bit[len]);
 }
 
-#define	G3CODES
+#define G3CODES
 #include "t4.h"
 
 short
@@ -128,14 +128,14 @@ search_table(unsigned long prefix, const tableentry* tab, int n)
     unsigned short code = (prefix & 0xffff) >> (16 - len);
 
     while (n-- > 0) {
-	if (tab->length == len && tab->code == code)
-	    return ((short) tab->runlen);
-	tab++;
+        if (tab->length == len && tab->code == code)
+            return ((short) tab->runlen);
+        tab++;
     }
     return (G3CODE_INCOMP);
 }
 
-#define	NCODES(a)	(sizeof (a) / sizeof (a[0]))
+#define NCODES(a)       (sizeof (a) / sizeof (a[0]))
 short
 white_run_length(unsigned long prefix)
 {
@@ -149,17 +149,17 @@ black_run_length(unsigned long prefix)
 }
 #undef NCODES
 
-#define MAX_NULLPREFIX	200	/* max # of null-mode prefixes */
-typedef	unsigned char NullModeTable[MAX_NULLPREFIX][256];
-#define MAX_HORIZPREFIX	250	/* max # of incomplete 1-D prefixes */
-typedef	unsigned char HorizModeTable[MAX_HORIZPREFIX][256];
+#define MAX_NULLPREFIX  200     /* max # of null-mode prefixes */
+typedef unsigned char NullModeTable[MAX_NULLPREFIX][256];
+#define MAX_HORIZPREFIX 250     /* max # of incomplete 1-D prefixes */
+typedef unsigned char HorizModeTable[MAX_HORIZPREFIX][256];
 
   /* the bit string corresponding to this row of the decoding table */
-long	null_mode_prefix[MAX_NULLPREFIX];
-NullModeTable null_mode;		/* MODE_*, indexed by bit and byte */
-NullModeTable null_mode_next_state;	/* next row of decoding tables to use */
+long    null_mode_prefix[MAX_NULLPREFIX];
+NullModeTable null_mode;                /* MODE_*, indexed by bit and byte */
+NullModeTable null_mode_next_state;     /* next row of decoding tables to use */
   /* number of prefixes or rows in the G4 decoding tables */
-short	null_mode_prefix_count = 0;
+short   null_mode_prefix_count = 0;
 
 /*
  * 2D uncompressed mode codes.  Note
@@ -168,41 +168,41 @@ short	null_mode_prefix_count = 0;
  * length of the run by subtracting the
  * code from a known base value.
  */
-#define	UNCOMP_INCOMP	0
+#define UNCOMP_INCOMP   0
 /* runs of [0]*1 */
-#define	UNCOMP_RUN0	1
-#define	UNCOMP_RUN1	2
-#define	UNCOMP_RUN2	3
-#define	UNCOMP_RUN3	4
-#define	UNCOMP_RUN4	5
-#define	UNCOMP_RUN5	6
-#define	UNCOMP_RUN6	7
+#define UNCOMP_RUN0     1
+#define UNCOMP_RUN1     2
+#define UNCOMP_RUN2     3
+#define UNCOMP_RUN3     4
+#define UNCOMP_RUN4     5
+#define UNCOMP_RUN5     6
+#define UNCOMP_RUN6     7
 /* runs of [0]* w/ terminating color */
-#define	UNCOMP_TRUN0	8
-#define	UNCOMP_TRUN1	9
-#define	UNCOMP_TRUN2	10
-#define	UNCOMP_TRUN3	11
-#define	UNCOMP_TRUN4	12
+#define UNCOMP_TRUN0    8
+#define UNCOMP_TRUN1    9
+#define UNCOMP_TRUN2    10
+#define UNCOMP_TRUN3    11
+#define UNCOMP_TRUN4    12
 /* special code for unexpected EOF */
-#define	UNCOMP_EOF	13
+#define UNCOMP_EOF      13
 /* invalid code encountered */
-#define	UNCOMP_INVALID	14
+#define UNCOMP_INVALID  14
 
-long	uncomp_mode_prefix[MAX_NULLPREFIX];
+long    uncomp_mode_prefix[MAX_NULLPREFIX];
 NullModeTable uncomp_mode;
 NullModeTable uncomp_mode_next_state;
-short	uncomp_mode_prefix_count = 0;
+short   uncomp_mode_prefix_count = 0;
 
 /*
  * Decoding action values for horiz_mode.
  */
-#define ACT_INCOMP	0		/* incompletely decoded code */
-#define ACT_INVALID	1		/* invalide code */
-#define	ACT_WRUNT	2		/* terminating white run code */
-#define	ACT_WRUN	65		/* non-terminating white run code */
-#define	ACT_BRUNT	106		/* terminating black run code */
-#define	ACT_BRUN	169		/* non-terminating black run code */
-#define ACT_EOL		210		/* end-of-line code */
+#define ACT_INCOMP      0               /* incompletely decoded code */
+#define ACT_INVALID     1               /* invalide code */
+#define ACT_WRUNT       2               /* terminating white run code */
+#define ACT_WRUN        65              /* non-terminating white run code */
+#define ACT_BRUNT       106             /* terminating black run code */
+#define ACT_BRUN        169             /* non-terminating black run code */
+#define ACT_EOL         210             /* end-of-line code */
 HorizModeTable horiz_mode;
 
 short
@@ -224,60 +224,60 @@ horiz_mode_code_white(short runlen)
  * decoding the next codeword.
  */
 HorizModeTable horiz_mode_next_state;
-		/* prefixes corresponding to the rows of the decoding table */
-long	horiz_mode_prefix[MAX_HORIZPREFIX];
-		/* color of next run, BLACK or WHITE */
-char	horiz_mode_color[MAX_HORIZPREFIX];
-short	horiz_mode_prefix_count = 0;
+                /* prefixes corresponding to the rows of the decoding table */
+long    horiz_mode_prefix[MAX_HORIZPREFIX];
+                /* color of next run, BLACK or WHITE */
+char    horiz_mode_color[MAX_HORIZPREFIX];
+short   horiz_mode_prefix_count = 0;
 
-static	unsigned char bit_mask[8] =
+static  unsigned char bit_mask[8] =
     { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
 
-void	build_null_mode_tables(void);
-short	find_horiz_mode_prefix(long, char);
-short	find_null_mode_prefix(long);
-short	null_mode_type(long);
-void	build_horiz_mode_tables(void);
-short	horiz_mode_code_black(short);
-short	horiz_mode_code_white(short);
-void	build_uncomp_mode_tables(void);
-void	write_tables(FILE*);
+void    build_null_mode_tables(void);
+short   find_horiz_mode_prefix(long, char);
+short   find_null_mode_prefix(long);
+short   null_mode_type(long);
+void    build_horiz_mode_tables(void);
+short   horiz_mode_code_black(short);
+short   horiz_mode_code_white(short);
+void    build_uncomp_mode_tables(void);
+void    write_tables(FILE*);
 
-int	verbose = FALSE;
-char	*storage_class = "";
-int	packoutput = TRUE;
+int     verbose = FALSE;
+char    *storage_class = "";
+int     packoutput = TRUE;
 
 void
 main(int argc, char** argv)
 {
     while (argc > 1 && argv[1][0] == '-') {
-	if (strcmp(argv[1], "-v") == 0) {
-	    verbose = TRUE;
-	    argc--, argv++;
-	} else if (strcmp(argv[1], "-c") == 0) {
-	    storage_class = "const ";
-	    argc--, argv++;
-	} else if (strcmp(argv[1], "-p") == 0) {
-	    packoutput = FALSE;
-	    argc--, argv++;
-	}
+        if (strcmp(argv[1], "-v") == 0) {
+            verbose = TRUE;
+            argc--, argv++;
+        } else if (strcmp(argv[1], "-c") == 0) {
+            storage_class = "const ";
+            argc--, argv++;
+        } else if (strcmp(argv[1], "-p") == 0) {
+            packoutput = FALSE;
+            argc--, argv++;
+        }
     }
-    build_null_mode_tables();		/* null mode decoding tables */
+    build_null_mode_tables();           /* null mode decoding tables */
     if (verbose) {
-	fprintf(stderr, "%d null mode prefixes defined\n",
-	    (int) null_mode_prefix_count);
-	fprintf(stderr, "building uncompressed mode scripts...\n");
+        fprintf(stderr, "%d null mode prefixes defined\n",
+            (int) null_mode_prefix_count);
+        fprintf(stderr, "building uncompressed mode scripts...\n");
     }
-    build_uncomp_mode_tables();		/* uncompressed mode decoding tables */
+    build_uncomp_mode_tables();         /* uncompressed mode decoding tables */
     if (verbose) {
-	fprintf(stderr, "%d uncompressed mode prefixes defined\n",
-	    (int) uncomp_mode_prefix_count);
-	fprintf(stderr, "building 1D scripts...\n");
+        fprintf(stderr, "%d uncompressed mode prefixes defined\n",
+            (int) uncomp_mode_prefix_count);
+        fprintf(stderr, "building 1D scripts...\n");
     }
-    build_horiz_mode_tables();		/* 1D decoding tables */
+    build_horiz_mode_tables();          /* 1D decoding tables */
     if (verbose)
-	fprintf(stderr, "%d incomplete prefixes defined\n",
-	    (int) horiz_mode_prefix_count);
+        fprintf(stderr, "%d incomplete prefixes defined\n",
+            (int) horiz_mode_prefix_count);
     write_tables(stdout);
     exit(0);
 }
@@ -290,40 +290,40 @@ write_null_mode_table(FILE* fd, NullModeTable table, char* name)
     char* sep;
 
     fprintf(fd, "%su_char\t%s[%d][256] = {", storage_class,
-	name, (int) null_mode_prefix_count);
+        name, (int) null_mode_prefix_count);
     outersep = "";
     if (!packoutput) {
-	for (i = 0; i < null_mode_prefix_count; i++) {
-	    fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i);
-	    sep = "    ";
-	    for (j = 0; j < 256; j++) {
-		fprintf(fd, "%s%2d", sep, (int) table[i][j]);
-		if (((j+1) % 16) == 0) {
-		    fprintf(fd, ", /* %3d-%3d */\n", j-15, j);
-		    sep = "    ";
-		} else
-		    sep = ",";
-	    }
-	    fprintf(fd, "}");
-	    outersep = ",";
-	}
+        for (i = 0; i < null_mode_prefix_count; i++) {
+            fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i);
+            sep = "    ";
+            for (j = 0; j < 256; j++) {
+                fprintf(fd, "%s%2d", sep, (int) table[i][j]);
+                if (((j+1) % 16) == 0) {
+                    fprintf(fd, ", /* %3d-%3d */\n", j-15, j);
+                    sep = "    ";
+                } else
+                    sep = ",";
+            }
+            fprintf(fd, "}");
+            outersep = ",";
+        }
     } else {
-	for (i = 0; i < null_mode_prefix_count; i++) {
-	    fprintf(fd, "%s{\n", outersep);
-	    for (j = 255; j > 0; j--)
-		if (table[i][j] != 0)
-		    break;
-	    sep = "";
-	    lastNonZero = j;
-	    for (j = 0; j <= lastNonZero; j++) {
-		fprintf(fd, "%s%d", sep, (int) table[i][j]);
-		if (((j+1) % 24) == 0)
-		    putc('\n', fd);
-		sep = ",";
-	    }
-	    fprintf(fd, "}");
-	    outersep = ",";
-	}
+        for (i = 0; i < null_mode_prefix_count; i++) {
+            fprintf(fd, "%s{\n", outersep);
+            for (j = 255; j > 0; j--)
+                if (table[i][j] != 0)
+                    break;
+            sep = "";
+            lastNonZero = j;
+            for (j = 0; j <= lastNonZero; j++) {
+                fprintf(fd, "%s%d", sep, (int) table[i][j]);
+                if (((j+1) % 24) == 0)
+                    putc('\n', fd);
+                sep = ",";
+            }
+            fprintf(fd, "}");
+            outersep = ",";
+        }
     }
     fprintf(fd, "\n};\n");
 }
@@ -336,41 +336,41 @@ write_horiz_mode_table(FILE* fd, HorizModeTable table, char* name)
     char* sep;
 
     fprintf(fd, "%s u_char\t%s[%d][256] = {", storage_class,
-	name, (int) horiz_mode_prefix_count);
+        name, (int) horiz_mode_prefix_count);
     outersep = "";
     if (!packoutput) {
-	for (i = 0; i < horiz_mode_prefix_count; i++) {
-	    fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i);
-	    sep = "    ";
-	    for (j = 0; j < 256; j++) {
-		fprintf(fd, "%s%3d", sep, (int) table[i][j]);
-		if (((j+1) % 14) == 0) {
-		    fprintf(fd, ", /* %3d-%3d */\n", j-13, j);
-		    sep = "    ";
-		} else
-		    sep = ",";
-	    }
-	    fprintf(fd, "\n}");
-	    outersep = ",";
-	}
+        for (i = 0; i < horiz_mode_prefix_count; i++) {
+            fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i);
+            sep = "    ";
+            for (j = 0; j < 256; j++) {
+                fprintf(fd, "%s%3d", sep, (int) table[i][j]);
+                if (((j+1) % 14) == 0) {
+                    fprintf(fd, ", /* %3d-%3d */\n", j-13, j);
+                    sep = "    ";
+                } else
+                    sep = ",";
+            }
+            fprintf(fd, "\n}");
+            outersep = ",";
+        }
     } else {
-	outersep = "";
-	for (i = 0; i < horiz_mode_prefix_count; i++) {
-	    fprintf(fd, "%s{\n", outersep);
-	    for (j = 255; j > 0; j--)
-		if (table[i][j] != 0)
-		    break;
-	    sep = "";
-	    lastNonZero = j;
-	    for (j = 0; j <= lastNonZero; j++) {
-		fprintf(fd, "%s%d", sep, (int) table[i][j]);
-		if (((j+1) % 24) == 0)
-		    putc('\n', fd);
-		sep = ",";
-	    }
-	    fprintf(fd, "}");
-	    outersep = ",";
-	}
+        outersep = "";
+        for (i = 0; i < horiz_mode_prefix_count; i++) {
+            fprintf(fd, "%s{\n", outersep);
+            for (j = 255; j > 0; j--)
+                if (table[i][j] != 0)
+                    break;
+            sep = "";
+            lastNonZero = j;
+            for (j = 0; j <= lastNonZero; j++) {
+                fprintf(fd, "%s%d", sep, (int) table[i][j]);
+                if (((j+1) % 24) == 0)
+                    putc('\n', fd);
+                sep = ",";
+            }
+            fprintf(fd, "}");
+            outersep = ",";
+        }
     }
     fprintf(fd, "\n};\n");
 }
@@ -380,7 +380,7 @@ write_define(FILE* fd, char* name, int value, char* comment)
 {
     fprintf(fd, "#define\t%s\t%d", name, value);
     if (!packoutput && comment)
-	fprintf(fd, "\t/* %s */", comment);
+        fprintf(fd, "\t/* %s */", comment);
     fprintf(fd, "\n");
 }
 
@@ -412,7 +412,7 @@ write_preamble(FILE* fd)
     write_define(fd, "MODE_ERROR", MODE_ERROR, NULL);
     write_define(fd, "MODE_ERROR_1", MODE_ERROR_1, NULL);
     fprintf(fd, "\n");
-    fprintf(fd, "#define\tRUNLENGTH(ix)	(TIFFFaxWhiteCodes[ix].runlen)\n");
+    fprintf(fd, "#define\tRUNLENGTH(ix) (TIFFFaxWhiteCodes[ix].runlen)\n");
     fprintf(fd, "\n");
     write_define(fd, "UNCOMP_INCOMP", UNCOMP_INCOMP, NULL);
     fprintf(fd, "/* runs of [0]*1 */\n");
@@ -434,7 +434,7 @@ write_preamble(FILE* fd)
     fprintf(fd, "/* invalid code encountered */\n");
     write_define(fd, "UNCOMP_INVALID", UNCOMP_INVALID, NULL);
     fprintf(fd, "/* codes >= terminate uncompress mode */\n");
-    fprintf(fd, "#define\tUNCOMP_EXIT	UNCOMP_TRUN0\n");
+    fprintf(fd, "#define\tUNCOMP_EXIT   UNCOMP_TRUN0\n");
     fprintf(fd, "\n");
 }
 
@@ -471,17 +471,17 @@ find_null_mode_prefix(long prefix)
     short j1;
 
     if (prefix == 0L)
-	return (0);
+        return (0);
     for (j1 = 8; j1 < null_mode_prefix_count; j1++)
-	if (prefix == null_mode_prefix[j1])
-		return (j1);
+        if (prefix == null_mode_prefix[j1])
+                return (j1);
     if (null_mode_prefix_count == MAX_NULLPREFIX) {
-	fprintf(stderr, "ERROR: null mode prefix table overflow\n");
-	exit(1);
+        fprintf(stderr, "ERROR: null mode prefix table overflow\n");
+        exit(1);
     }
     if (verbose)
-	fprintf(stderr, "adding null mode prefix[%d] 0x%lx\n",
-	    (int) null_mode_prefix_count, prefix);
+        fprintf(stderr, "adding null mode prefix[%d] 0x%lx\n",
+            (int) null_mode_prefix_count, prefix);
     null_mode_prefix[null_mode_prefix_count++] = prefix;
     return (null_mode_prefix_count-1);
 }
@@ -492,19 +492,19 @@ find_horiz_mode_prefix(long prefix, char color)
     short j1;
 
     for (j1 = 0; j1 < horiz_mode_prefix_count; j1++)
-	if (prefix == horiz_mode_prefix[j1] && horiz_mode_color[j1] == color)
-	    return (j1);
+        if (prefix == horiz_mode_prefix[j1] && horiz_mode_color[j1] == color)
+            return (j1);
     /*
      * It wasn't found, so add it to the tables, but first, is there room?
      */
     if (horiz_mode_prefix_count == MAX_HORIZPREFIX) {
-	fprintf(stderr, "ERROR: 1D prefix table overflow\n");
-	exit(1);
+        fprintf(stderr, "ERROR: 1D prefix table overflow\n");
+        exit(1);
     }
     /* OK, there's room... */
     if (verbose)
-	fprintf(stderr, "\nhoriz mode prefix %d, color %c = 0x%lx ",
-	    (int) horiz_mode_prefix_count, "WB"[color], prefix);
+        fprintf(stderr, "\nhoriz mode prefix %d, color %c = 0x%lx ",
+            (int) horiz_mode_prefix_count, "WB"[color], prefix);
     horiz_mode_prefix[horiz_mode_prefix_count] = prefix;
     horiz_mode_color[horiz_mode_prefix_count] = color;
     horiz_mode_prefix_count++;
@@ -517,17 +517,17 @@ find_uncomp_mode_prefix(long prefix)
     short j1;
 
     if (prefix == 0L)
-	return (0);
+        return (0);
     for (j1 = 8; j1 < uncomp_mode_prefix_count; j1++)
-	if (prefix == uncomp_mode_prefix[j1])
-		return (j1);
+        if (prefix == uncomp_mode_prefix[j1])
+                return (j1);
     if (uncomp_mode_prefix_count == MAX_NULLPREFIX) {
-	fprintf(stderr, "ERROR: uncomp mode prefix table overflow\n");
-	exit(1);
+        fprintf(stderr, "ERROR: uncomp mode prefix table overflow\n");
+        exit(1);
     }
     if (verbose)
-	fprintf(stderr, "adding uncomp mode prefix[%d] 0x%lx\n",
-	    (int) uncomp_mode_prefix_count, prefix);
+        fprintf(stderr, "adding uncomp mode prefix[%d] 0x%lx\n",
+            (int) uncomp_mode_prefix_count, prefix);
     uncomp_mode_prefix[uncomp_mode_prefix_count++] = prefix;
     return (uncomp_mode_prefix_count-1);
 }
@@ -536,25 +536,25 @@ short
 null_mode_type(long prefix)
 {
     switch (prefix) {
-    case 0x18000L: return (MODE_VERT_V0);	/* 1 */
-    case 0x36000L: return (MODE_VERT_VR1);	/* 011 */
-    case 0x34000L: return (MODE_VERT_VL1);	/* 010 */
-    case 0x32000L: return (MODE_HORIZ);		/* 001 */
-    case 0x41000L: return (MODE_PASS);		/* 0001 */
-    case 0x60C00L: return (MODE_VERT_VR2);	/* 0000 11 */
-    case 0x60800L: return (MODE_VERT_VL2);	/* 0000 10 */
-    case 0x70600L: return (MODE_VERT_VR3);	/* 0000 011 */
-    case 0x70400L: return (MODE_VERT_VL3);	/* 0000 010 */
-    case 0x80200L: return (MODE_ERROR);		/* 0000 0010 */
-    case 0x90300L: return (MODE_ERROR);		/* 0000 0011 0 */
-    case 0xA0380L: return (MODE_ERROR);		/* 0000 0011 10 */
-    case 0xA03C0L: return (MODE_UNCOMP);	/* 0000 0011 11 */
+    case 0x18000L: return (MODE_VERT_V0);       /* 1 */
+    case 0x36000L: return (MODE_VERT_VR1);      /* 011 */
+    case 0x34000L: return (MODE_VERT_VL1);      /* 010 */
+    case 0x32000L: return (MODE_HORIZ);         /* 001 */
+    case 0x41000L: return (MODE_PASS);          /* 0001 */
+    case 0x60C00L: return (MODE_VERT_VR2);      /* 0000 11 */
+    case 0x60800L: return (MODE_VERT_VL2);      /* 0000 10 */
+    case 0x70600L: return (MODE_VERT_VR3);      /* 0000 011 */
+    case 0x70400L: return (MODE_VERT_VL3);      /* 0000 010 */
+    case 0x80200L: return (MODE_ERROR);         /* 0000 0010 */
+    case 0x90300L: return (MODE_ERROR);         /* 0000 0011 0 */
+    case 0xA0380L: return (MODE_ERROR);         /* 0000 0011 10 */
+    case 0xA03C0L: return (MODE_UNCOMP);        /* 0000 0011 11 */
     /*
      * Under the assumption that there are no
      * errors in the file, then this bit string
      * can only be the beginning of an EOL code.
      */
-    case 0x70000L: return (MODE_ERROR_1);	/* 0000 000 */
+    case 0x70000L: return (MODE_ERROR_1);       /* 0000 000 */
     }
     return (-1);
 }
@@ -565,24 +565,24 @@ uncomp_mode_type(long prefix)
     short code;
     short len;
     switch (prefix) {
-    case 0x18000L: return (UNCOMP_RUN1);	/* 1 */
-    case 0x24000L: return (UNCOMP_RUN2);	/* 01 */
-    case 0x32000L: return (UNCOMP_RUN3);	/* 001 */
-    case 0x41000L: return (UNCOMP_RUN4);	/* 0001 */
-    case 0x50800L: return (UNCOMP_RUN5);	/* 0000 1 */
-    case 0x60400L: return (UNCOMP_RUN6);	/* 0000 01 */
-    case 0x70200L: return (UNCOMP_TRUN0);	/* 0000 001 */
-    case 0x80100L: return (UNCOMP_TRUN1);	/* 0000 0001 */
-    case 0x90080L: return (UNCOMP_TRUN2);	/* 0000 0000 1 */
-    case 0xA0040L: return (UNCOMP_TRUN3);	/* 0000 0000 01 */
-    case 0xB0020L: return (UNCOMP_TRUN4);	/* 0000 0000 001 */
+    case 0x18000L: return (UNCOMP_RUN1);        /* 1 */
+    case 0x24000L: return (UNCOMP_RUN2);        /* 01 */
+    case 0x32000L: return (UNCOMP_RUN3);        /* 001 */
+    case 0x41000L: return (UNCOMP_RUN4);        /* 0001 */
+    case 0x50800L: return (UNCOMP_RUN5);        /* 0000 1 */
+    case 0x60400L: return (UNCOMP_RUN6);        /* 0000 01 */
+    case 0x70200L: return (UNCOMP_TRUN0);       /* 0000 001 */
+    case 0x80100L: return (UNCOMP_TRUN1);       /* 0000 0001 */
+    case 0x90080L: return (UNCOMP_TRUN2);       /* 0000 0000 1 */
+    case 0xA0040L: return (UNCOMP_TRUN3);       /* 0000 0000 01 */
+    case 0xB0020L: return (UNCOMP_TRUN4);       /* 0000 0000 001 */
     }
     code = prefix & 0xffffL;
     len = (prefix >> 16) & 0xf;
     return ((code || len > 10) ? UNCOMP_INVALID : -1);
 }
 
-#define	BASESTATE(b)	((unsigned char) ((b) & 0x7))
+#define BASESTATE(b)    ((unsigned char) ((b) & 0x7))
 
 void
 build_null_mode_tables(void)
@@ -595,61 +595,61 @@ build_null_mode_tables(void)
      */
     null_mode_prefix_count = 8;
     for (prefix = 0; prefix < null_mode_prefix_count; prefix++) {
-	short byte;
-	for (byte = 0; byte < 256; byte++) {
-	    short firstbit;
-	    short bit;
-	    long curprefix;
-	    char found_code = FALSE;
-
-	    if (prefix < 8) {
-		curprefix = 0L;
-		firstbit = prefix;
-	    } else {
-		curprefix = null_mode_prefix[prefix];
-		firstbit = 0;
-	    }
-	    for (bit = firstbit; bit < 8 && !found_code; bit++) {
-		short mode;
-
-		if (bit_mask[bit] & byte)
-		    curprefix = append_1(curprefix);
-		else
-		    curprefix = append_0(curprefix);
-		switch (mode = null_mode_type(curprefix)) {
-		case MODE_PASS:
-		case MODE_HORIZ:
-		case MODE_VERT_V0:
-		case MODE_VERT_VR1:
-		case MODE_VERT_VR2:
-		case MODE_VERT_VR3:
-		case MODE_VERT_VL1:
-		case MODE_VERT_VL2:
-		case MODE_VERT_VL3:
-		case MODE_UNCOMP:
-		case MODE_ERROR:
-		case MODE_ERROR_1:
-		    /*
-		     * NOTE: if the bit number is 8, then the table
-		     * entry will be zero, which indicates a new byte
-		     * is to be fetched during the decoding process
-		     */
-		    found_code = TRUE;
-		    null_mode[prefix][byte] = (unsigned char) mode;
-		    null_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-		    break;
-		}
-	    }
-	    if (!found_code) {
-		null_mode_next_state[prefix][byte] = (unsigned char)
-		    find_null_mode_prefix(curprefix);
-		/*
-		 * This indicates to the decoder that
-		 * no valid code has yet been identified.
-		 */
-		null_mode[prefix][byte] = MODE_NULL;
-	    }
-	}
+        short byte;
+        for (byte = 0; byte < 256; byte++) {
+            short firstbit;
+            short bit;
+            long curprefix;
+            char found_code = FALSE;
+
+            if (prefix < 8) {
+                curprefix = 0L;
+                firstbit = prefix;
+            } else {
+                curprefix = null_mode_prefix[prefix];
+                firstbit = 0;
+            }
+            for (bit = firstbit; bit < 8 && !found_code; bit++) {
+                short mode;
+
+                if (bit_mask[bit] & byte)
+                    curprefix = append_1(curprefix);
+                else
+                    curprefix = append_0(curprefix);
+                switch (mode = null_mode_type(curprefix)) {
+                case MODE_PASS:
+                case MODE_HORIZ:
+                case MODE_VERT_V0:
+                case MODE_VERT_VR1:
+                case MODE_VERT_VR2:
+                case MODE_VERT_VR3:
+                case MODE_VERT_VL1:
+                case MODE_VERT_VL2:
+                case MODE_VERT_VL3:
+                case MODE_UNCOMP:
+                case MODE_ERROR:
+                case MODE_ERROR_1:
+                    /*
+                     * NOTE: if the bit number is 8, then the table
+                     * entry will be zero, which indicates a new byte
+                     * is to be fetched during the decoding process
+                     */
+                    found_code = TRUE;
+                    null_mode[prefix][byte] = (unsigned char) mode;
+                    null_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                    break;
+                }
+            }
+            if (!found_code) {
+                null_mode_next_state[prefix][byte] = (unsigned char)
+                    find_null_mode_prefix(curprefix);
+                /*
+                 * This indicates to the decoder that
+                 * no valid code has yet been identified.
+                 */
+                null_mode[prefix][byte] = MODE_NULL;
+            }
+        }
     }
 }
 
@@ -666,85 +666,85 @@ build_horiz_mode_tables(void)
      */
     horiz_mode_prefix_count = 16;
     for (prefix = 0; prefix < horiz_mode_prefix_count; prefix++)
-	for (byte = 0; byte < 256; byte++) {
-	    short bits_digested = 0;
-	    short bit;
-	    short firstbit;
-	    char color;
-	    unsigned long curprefix;
-
-	    if (prefix < 8) {
-		color = WHITE;
-		curprefix = 0L;
-		firstbit = prefix;
-	    } else if (prefix < 16) {
-		color = BLACK;
-		curprefix = 0L;
-		firstbit = prefix - 8;
-	    } else {
-		color = horiz_mode_color[prefix];
-		curprefix = horiz_mode_prefix[prefix];
-		firstbit = 0;
-	    }
-	    for (bit = firstbit; bit < 8 && !bits_digested; bit++) {
-		if (bit_mask[bit] & byte)
-		    curprefix = append_1(curprefix);
-		else
-		    curprefix = append_0(curprefix);
-		/*
-		 * The following conversion allows for arbitrary strings of
-		 * zeroes to precede the end-of-line code 0000 0000 0001.
-		 * It assumes no errors in the data, and is based on
-		 * the assumption that the code replaced (12 consecutive
-		 * zeroes) can only be "legally" encountered before the
-		 * end-of-line code.  This assumption is valid only for
-		 * a Group 3 image; the combination will never occur
-		 * in horizontal mode in a proper Group 4 image.
-		 */
-		if (curprefix == 0xC0000L)
-		    curprefix = 0xB0000L;
-		if (color == WHITE) {
-		    short runlength = white_run_length(curprefix);
-
-		    if (runlength == G3CODE_INVALID) {
-			horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID;
-			horiz_mode_next_state[prefix][byte] = (unsigned char) bit;
-			bits_digested = bit + 1;
-		    } else if (runlength == G3CODE_EOL) { /* Group 3 only */
-			horiz_mode[prefix][byte] = (unsigned char) ACT_EOL;
-			horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-			bits_digested = bit + 1;
-		    } else if (runlength != G3CODE_INCOMP) {
-			horiz_mode[prefix][byte] = (unsigned char)
-			    horiz_mode_code_white(runlength);
-			horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-			bits_digested = bit + 1;
-		    }
-		} else {		/* color == BLACK */
-		    short runlength = black_run_length(curprefix);
-
-		    if (runlength == G3CODE_INVALID) {
-			horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID;
-			horiz_mode_next_state[prefix][byte] = (unsigned char) (bit+8);
-			bits_digested = bit + 1;
-		    } else if (runlength == G3CODE_EOL) { /* Group 3 only */
-			horiz_mode[prefix][byte] = (unsigned char) ACT_EOL;
-			horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-			bits_digested = bit + 1;
-		    } else if (runlength != G3CODE_INCOMP) {
-			horiz_mode[prefix][byte] = (unsigned char)
-			    horiz_mode_code_black(runlength);
-			horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-			bits_digested = bit + 1;
-		    }
-		}
-	    }
-	    if (!bits_digested) {	/* no codewords after examining byte */
-		horiz_mode[prefix][byte] = (unsigned char) ACT_INCOMP;
-		horiz_mode_next_state[prefix][byte] = (unsigned char)
-		    find_horiz_mode_prefix(curprefix, color);
-	    }
-	}
+        for (byte = 0; byte < 256; byte++) {
+            short bits_digested = 0;
+            short bit;
+            short firstbit;
+            char color;
+            unsigned long curprefix;
+
+            if (prefix < 8) {
+                color = WHITE;
+                curprefix = 0L;
+                firstbit = prefix;
+            } else if (prefix < 16) {
+                color = BLACK;
+                curprefix = 0L;
+                firstbit = prefix - 8;
+            } else {
+                color = horiz_mode_color[prefix];
+                curprefix = horiz_mode_prefix[prefix];
+                firstbit = 0;
+            }
+            for (bit = firstbit; bit < 8 && !bits_digested; bit++) {
+                if (bit_mask[bit] & byte)
+                    curprefix = append_1(curprefix);
+                else
+                    curprefix = append_0(curprefix);
+                /*
+                 * The following conversion allows for arbitrary strings of
+                 * zeroes to precede the end-of-line code 0000 0000 0001.
+                 * It assumes no errors in the data, and is based on
+                 * the assumption that the code replaced (12 consecutive
+                 * zeroes) can only be "legally" encountered before the
+                 * end-of-line code.  This assumption is valid only for
+                 * a Group 3 image; the combination will never occur
+                 * in horizontal mode in a proper Group 4 image.
+                 */
+                if (curprefix == 0xC0000L)
+                    curprefix = 0xB0000L;
+                if (color == WHITE) {
+                    short runlength = white_run_length(curprefix);
+
+                    if (runlength == G3CODE_INVALID) {
+                        horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID;
+                        horiz_mode_next_state[prefix][byte] = (unsigned char) bit;
+                        bits_digested = bit + 1;
+                    } else if (runlength == G3CODE_EOL) { /* Group 3 only */
+                        horiz_mode[prefix][byte] = (unsigned char) ACT_EOL;
+                        horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                        bits_digested = bit + 1;
+                    } else if (runlength != G3CODE_INCOMP) {
+                        horiz_mode[prefix][byte] = (unsigned char)
+                            horiz_mode_code_white(runlength);
+                        horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                        bits_digested = bit + 1;
+                    }
+                } else {                /* color == BLACK */
+                    short runlength = black_run_length(curprefix);
+
+                    if (runlength == G3CODE_INVALID) {
+                        horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID;
+                        horiz_mode_next_state[prefix][byte] = (unsigned char) (bit+8);
+                        bits_digested = bit + 1;
+                    } else if (runlength == G3CODE_EOL) { /* Group 3 only */
+                        horiz_mode[prefix][byte] = (unsigned char) ACT_EOL;
+                        horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                        bits_digested = bit + 1;
+                    } else if (runlength != G3CODE_INCOMP) {
+                        horiz_mode[prefix][byte] = (unsigned char)
+                            horiz_mode_code_black(runlength);
+                        horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                        bits_digested = bit + 1;
+                    }
+                }
+            }
+            if (!bits_digested) {       /* no codewords after examining byte */
+                horiz_mode[prefix][byte] = (unsigned char) ACT_INCOMP;
+                horiz_mode_next_state[prefix][byte] = (unsigned char)
+                    find_horiz_mode_prefix(curprefix, color);
+            }
+        }
 }
 
 void
@@ -758,49 +758,49 @@ build_uncomp_mode_tables(void)
      */
     uncomp_mode_prefix_count = 8;
     for (prefix = 0; prefix < uncomp_mode_prefix_count; prefix++) {
-	short byte;
-	for (byte = 0; byte < 256; byte++) {
-	    short firstbit;
-	    short bit;
-	    long curprefix;
-	    char found_code = FALSE;
-
-	    if (prefix < 8) {
-		curprefix = 0L;
-		firstbit = prefix;
-	    } else {
-		curprefix = uncomp_mode_prefix[prefix];
-		firstbit = 0;
-	    }
-	    for (bit = firstbit; bit < 8 && !found_code; bit++) {
-		short mode;
-
-		if (bit_mask[bit] & byte)
-		    curprefix = append_1(curprefix);
-		else
-		    curprefix = append_0(curprefix);
-		mode = uncomp_mode_type(curprefix);
-		if (mode != -1) {
-		    /*
-		     * NOTE: if the bit number is 8, then the table
-		     * entry will be zero, which indicates a new byte
-		     * is to be fetched during the decoding process
-		     */
-		    found_code = TRUE;
-		    uncomp_mode[prefix][byte] = (unsigned char) mode;
-		    uncomp_mode_next_state[prefix][byte] = BASESTATE(bit+1);
-		    break;
-		}
-	    }
-	    if (!found_code) {
-		uncomp_mode_next_state[prefix][byte] = (unsigned char)
-		    find_uncomp_mode_prefix(curprefix);
-		/*
-		 * This indicates to the decoder that
-		 * no valid code has yet been identified.
-		 */
-		uncomp_mode[prefix][byte] = UNCOMP_INCOMP;
-	    }
-	}
+        short byte;
+        for (byte = 0; byte < 256; byte++) {
+            short firstbit;
+            short bit;
+            long curprefix;
+            char found_code = FALSE;
+
+            if (prefix < 8) {
+                curprefix = 0L;
+                firstbit = prefix;
+            } else {
+                curprefix = uncomp_mode_prefix[prefix];
+                firstbit = 0;
+            }
+            for (bit = firstbit; bit < 8 && !found_code; bit++) {
+                short mode;
+
+                if (bit_mask[bit] & byte)
+                    curprefix = append_1(curprefix);
+                else
+                    curprefix = append_0(curprefix);
+                mode = uncomp_mode_type(curprefix);
+                if (mode != -1) {
+                    /*
+                     * NOTE: if the bit number is 8, then the table
+                     * entry will be zero, which indicates a new byte
+                     * is to be fetched during the decoding process
+                     */
+                    found_code = TRUE;
+                    uncomp_mode[prefix][byte] = (unsigned char) mode;
+                    uncomp_mode_next_state[prefix][byte] = BASESTATE(bit+1);
+                    break;
+                }
+            }
+            if (!found_code) {
+                uncomp_mode_next_state[prefix][byte] = (unsigned char)
+                    find_uncomp_mode_prefix(curprefix);
+                /*
+                 * This indicates to the decoder that
+                 * no valid code has yet been identified.
+                 */
+                uncomp_mode[prefix][byte] = UNCOMP_INCOMP;
+            }
+        }
     }
 }

+ 31 - 31
panda/src/tiff/mkspans.c

@@ -10,41 +10,41 @@ static char rcsid[] = "$Header$";
  */
 
 dumparray(name, runs)
-	char *name;
-	unsigned char runs[256];
+        char *name;
+        unsigned char runs[256];
 {
-	register int i;
-	register char *sep;
-	printf("static u_char %s[256] = {\n", name);
-	sep = "    ";
-	for (i = 0; i < 256; i++) {
-		printf("%s%d", sep, runs[i]);
-		if (((i + 1) % 16) == 0) {
-			printf(",	/* 0x%02x - 0x%02x */\n", i-15, i);
-			sep = "    ";
-		} else
-			sep = ", ";
-	}
-	printf("\n};\n");
+        register int i;
+        register char *sep;
+        printf("static u_char %s[256] = {\n", name);
+        sep = "    ";
+        for (i = 0; i < 256; i++) {
+                printf("%s%d", sep, runs[i]);
+                if (((i + 1) % 16) == 0) {
+                        printf(",       /* 0x%02x - 0x%02x */\n", i-15, i);
+                        sep = "    ";
+                } else
+                        sep = ", ";
+        }
+        printf("\n};\n");
 }
 
 main()
 {
-	unsigned char runs[2][256];
+        unsigned char runs[2][256];
 
-	memset(runs[0], 0, 256*sizeof (char));
-	memset(runs[1], 0, 256*sizeof (char));
-	{ register int run, runlen, i;
-	  runlen = 1;
-	  for (run = 0x80; run != 0xff; run = (run>>1)|0x80) {
-		for (i = run-1; i >= 0; i--) {
-			runs[1][run|i] = runlen;
-			runs[0][(~(run|i)) & 0xff] = runlen;
-		}
-		runlen++;
-	  }
-	  runs[1][0xff] = runs[0][0] = 8;
-	}
-	dumparray("bruns", runs[0]);
-	dumparray("wruns", runs[1]);
+        memset(runs[0], 0, 256*sizeof (char));
+        memset(runs[1], 0, 256*sizeof (char));
+        { register int run, runlen, i;
+          runlen = 1;
+          for (run = 0x80; run != 0xff; run = (run>>1)|0x80) {
+                for (i = run-1; i >= 0; i--) {
+                        runs[1][run|i] = runlen;
+                        runs[0][(~(run|i)) & 0xff] = runlen;
+                }
+                runlen++;
+          }
+          runs[1][0xff] = runs[0][0] = 8;
+        }
+        dumparray("bruns", runs[0]);
+        dumparray("wruns", runs[1]);
 }

+ 98 - 98
panda/src/tiff/tif_apple.c

@@ -49,60 +49,60 @@ static char rcsid[] = "$Header$";
 #include <Memory.h>
 
 #ifdef applec
-#define	CtoPstr	c2pstr
+#define CtoPstr c2pstr
 #endif
 
 static tsize_t
 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (FSRead((short) fd, (long*) &size, (char*) buf) == noErr ?
-	    size : (tsize_t) -1);
+        return (FSRead((short) fd, (long*) &size, (char*) buf) == noErr ?
+            size : (tsize_t) -1);
 }
 
 static tsize_t
 _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (FSWrite((short) fd, (long*) &size, (char*) buf) == noErr ?
-	    size : (tsize_t) -1);
+        return (FSWrite((short) fd, (long*) &size, (char*) buf) == noErr ?
+            size : (tsize_t) -1);
 }
 
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
-	long fpos, size;
-
-	if (GetEOF((short) fd, &size) != noErr)
-		return EOF;
-	(void) GetFPos((short) fd, &fpos);
-
-	switch (whence) {
-	case SEEK_CUR:
-		if (off + fpos > size)
-			SetEOF((short) fd, off + fpos);
-		if (SetFPos((short) fd, fsFromMark, off) != noErr)
-			return EOF;
-		break;
-	case SEEK_END:
-		if (off > 0)
-			SetEOF((short) fd, off + size);
-		if (SetFPos((short) fd, fsFromStart, off + size) != noErr)
-			return EOF;
-		break;
-	case SEEK_SET:
-		if (off > size)
-			SetEOF((short) fd, off);
-		if (SetFPos((short) fd, fsFromStart, off) != noErr)
-			return EOF;
-		break;
-	}
-
-	return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF);
+        long fpos, size;
+
+        if (GetEOF((short) fd, &size) != noErr)
+                return EOF;
+        (void) GetFPos((short) fd, &fpos);
+
+        switch (whence) {
+        case SEEK_CUR:
+                if (off + fpos > size)
+                        SetEOF((short) fd, off + fpos);
+                if (SetFPos((short) fd, fsFromMark, off) != noErr)
+                        return EOF;
+                break;
+        case SEEK_END:
+                if (off > 0)
+                        SetEOF((short) fd, off + size);
+                if (SetFPos((short) fd, fsFromStart, off + size) != noErr)
+                        return EOF;
+                break;
+        case SEEK_SET:
+                if (off > size)
+                        SetEOF((short) fd, off);
+                if (SetFPos((short) fd, fsFromStart, off) != noErr)
+                        return EOF;
+                break;
+        }
+
+        return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF);
 }
 
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	return (0);
+        return (0);
 }
 
 static void
@@ -113,44 +113,44 @@ _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 static int
 _tiffCloseProc(thandle_t fd)
 {
-	return (FSClose((short) fd));
+        return (FSClose((short) fd));
 }
 
 static toff_t
 _tiffSizeProc(thandle_t fd)
 {
-	long size;
+        long size;
 
-	if (GetEOF((short) fd, &size) != noErr) {
-		TIFFError("_tiffSizeProc", "%s: Cannot get file size");
-		return (-1L);
-	}
-	return ((toff_t) size);
+        if (GetEOF((short) fd, &size) != noErr) {
+                TIFFError("_tiffSizeProc", "%s: Cannot get file size");
+                return (-1L);
+        }
+        return ((toff_t) size);
 }
 
 void *
 _TIFFmalloc(size_t s)
 {
-	return (NewPtr(s));
+        return (NewPtr(s));
 }
 
 void
 _TIFFfree(void* p)
 {
-	DisposePtr(p);
+        DisposePtr(p);
 }
 
 void *
 _TIFFrealloc(void* p, size_t s)
 {
-	Ptr n = p;
-
-	SetPtrSize(p, s);
-	if (MemError() && (n = NewPtr(s)) != NULL) {
-		BlockMove(p, n, GetPtrSize(p));
-		DisposePtr(p);
-	}
-	return (n);
+        Ptr n = p;
+
+        SetPtrSize(p, s);
+        if (MemError() && (n = NewPtr(s)) != NULL) {
+                BlockMove(p, n, GetPtrSize(p));
+                DisposePtr(p);
+        }
+        return (n);
 }
 
 /*
@@ -159,14 +159,14 @@ _TIFFrealloc(void* p, size_t s)
 TIFF*
 TIFFFdOpen(int fd, const char* name, const char* mode)
 {
-	TIFF* tif;
-
-	tif = TIFFClientOpen(name, mode, (thandle_t) fd,
-	    _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
-	    _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
-	if (tif)
-		tif->tif_fd = fd;
-	return (tif);
+        TIFF* tif;
+
+        tif = TIFFClientOpen(name, mode, (thandle_t) fd,
+            _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
+            _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
+        if (tif)
+                tif->tif_fd = fd;
+        return (tif);
 }
 
 /*
@@ -175,45 +175,45 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
 TIFF*
 TIFFOpen(const char* name, const char* mode)
 {
-	static const char module[] = "TIFFOpen";
-	Str255 pname;
-	FInfo finfo;
-	short fref;
-	OSErr err;
-
-	strcpy((char*) pname, name);
-	CtoPstr((char*) pname);
-
-	switch (_TIFFgetMode(mode, module)) {
-	default:
-		return ((TIFF*) 0);
-	case O_RDWR | O_CREAT | O_TRUNC:
-		if (GetFInfo(pname, 0, &finfo) == noErr)
-			FSDelete(pname, 0);
-		/* fall through */
-	case O_RDWR | O_CREAT:
-		if ((err = GetFInfo(pname, 0, &finfo)) == fnfErr) {
-			if (Create(pname, 0, '    ', 'TIFF') != noErr)
-				goto badCreate;
-			if (FSOpen(pname, 0, &fref) != noErr)
-				goto badOpen;
-		} else if (err == noErr) {
-			if (FSOpen(pname, 0, &fref) != noErr)
-				goto badOpen;
-		} else
-			goto badOpen;
-		break;
-	case O_RDONLY:
-	case O_RDWR:
-		if (FSOpen(pname, 0, &fref) != noErr)
-			goto badOpen;
-		break;
-	}
-	return (TIFFFdOpen((int) fref, name, mode));
+        static const char module[] = "TIFFOpen";
+        Str255 pname;
+        FInfo finfo;
+        short fref;
+        OSErr err;
+
+        strcpy((char*) pname, name);
+        CtoPstr((char*) pname);
+
+        switch (_TIFFgetMode(mode, module)) {
+        default:
+                return ((TIFF*) 0);
+        case O_RDWR | O_CREAT | O_TRUNC:
+                if (GetFInfo(pname, 0, &finfo) == noErr)
+                        FSDelete(pname, 0);
+                /* fall through */
+        case O_RDWR | O_CREAT:
+                if ((err = GetFInfo(pname, 0, &finfo)) == fnfErr) {
+                        if (Create(pname, 0, '    ', 'TIFF') != noErr)
+                                goto badCreate;
+                        if (FSOpen(pname, 0, &fref) != noErr)
+                                goto badOpen;
+                } else if (err == noErr) {
+                        if (FSOpen(pname, 0, &fref) != noErr)
+                                goto badOpen;
+                } else
+                        goto badOpen;
+                break;
+        case O_RDONLY:
+        case O_RDWR:
+                if (FSOpen(pname, 0, &fref) != noErr)
+                        goto badOpen;
+                break;
+        }
+        return (TIFFFdOpen((int) fref, name, mode));
 badCreate:
-	TIFFError(module, "%s: Cannot create", name);
-	return ((TIFF*) 0);
+        TIFFError(module, "%s: Cannot create", name);
+        return ((TIFF*) 0);
 badOpen:
-	TIFFError(module, "%s: Cannot open", name);
-	return ((TIFF*) 0);
+        TIFFError(module, "%s: Cannot open", name);
+        return ((TIFF*) 0);
 }

+ 129 - 129
panda/src/tiff/tif_aux.c

@@ -39,31 +39,31 @@ static char rcsid[] = "$Header$";
 static void
 TIFFDefaultTransferFunction(TIFFDirectory* td)
 {
-	uint16 **tf = td->td_transferfunction;
-	long i, n = 1<<td->td_bitspersample;
+        uint16 **tf = td->td_transferfunction;
+        long i, n = 1<<td->td_bitspersample;
 
-	tf[0] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
-	tf[0][0] = 0;
-	for (i = 1; i < n; i++)
-		tf[0][i] = (uint16)floor(65535.*pow(i/(n-1.), 2.2) + .5);
-	if (td->td_samplesperpixel - td->td_extrasamples > 1) {
-		tf[1] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
-		memcpy(tf[1], tf[0], n * sizeof (uint16));
-		tf[2] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
-		memcpy(tf[2], tf[0], n * sizeof (uint16));
-	}
+        tf[0] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
+        tf[0][0] = 0;
+        for (i = 1; i < n; i++)
+                tf[0][i] = (uint16)floor(65535.*pow(i/(n-1.), 2.2) + .5);
+        if (td->td_samplesperpixel - td->td_extrasamples > 1) {
+                tf[1] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
+                memcpy(tf[1], tf[0], n * sizeof (uint16));
+                tf[2] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
+                memcpy(tf[2], tf[0], n * sizeof (uint16));
+        }
 }
 
 static void
 TIFFDefaultRefBlackWhite(TIFFDirectory* td)
 {
-	int i;
+        int i;
 
-	td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
-	for (i = 0; i < 3; i++) {
-	    td->td_refblackwhite[2*i+0] = 0;
-	    td->td_refblackwhite[2*i+1] = 1L<<td->td_bitspersample;
-	}
+        td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
+        for (i = 0; i < 3; i++) {
+            td->td_refblackwhite[2*i+0] = 0;
+            td->td_refblackwhite[2*i+1] = 1L<<td->td_bitspersample;
+        }
 }
 #endif
 
@@ -71,121 +71,121 @@ TIFFDefaultRefBlackWhite(TIFFDirectory* td)
  * Like TIFFGetField, but return any default
  * value if the tag is not present in the directory.
  *
- * NB:	We use the value in the directory, rather than
- *	explcit values so that defaults exist only one
- *	place in the library -- in TIFFDefaultDirectory.
+ * NB:  We use the value in the directory, rather than
+ *      explcit values so that defaults exist only one
+ *      place in the library -- in TIFFDefaultDirectory.
  */
 TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
 {
-	TIFFDirectory *td = &tif->tif_dir;
+        TIFFDirectory *td = &tif->tif_dir;
 
-	if (TIFFVGetField(tif, tag, ap))
-		return (1);
-	switch (tag) {
-	case TIFFTAG_SUBFILETYPE:
-		*va_arg(ap, uint16 *) = td->td_subfiletype;
-		return (1);
-	case TIFFTAG_BITSPERSAMPLE:
-		*va_arg(ap, uint16 *) = td->td_bitspersample;
-		return (1);
-	case TIFFTAG_THRESHHOLDING:
-		*va_arg(ap, uint16 *) = td->td_threshholding;
-		return (1);
-	case TIFFTAG_FILLORDER:
-		*va_arg(ap, uint16 *) = td->td_fillorder;
-		return (1);
-	case TIFFTAG_ORIENTATION:
-		*va_arg(ap, uint16 *) = td->td_orientation;
-		return (1);
-	case TIFFTAG_SAMPLESPERPIXEL:
-		*va_arg(ap, uint16 *) = td->td_samplesperpixel;
-		return (1);
-	case TIFFTAG_ROWSPERSTRIP:
-		*va_arg(ap, uint32 *) = td->td_rowsperstrip;
-		return (1);
-	case TIFFTAG_MINSAMPLEVALUE:
-		*va_arg(ap, uint16 *) = td->td_minsamplevalue;
-		return (1);
-	case TIFFTAG_MAXSAMPLEVALUE:
-		*va_arg(ap, uint16 *) = td->td_maxsamplevalue;
-		return (1);
-	case TIFFTAG_PLANARCONFIG:
-		*va_arg(ap, uint16 *) = td->td_planarconfig;
-		return (1);
-	case TIFFTAG_GROUP4OPTIONS:
-		*va_arg(ap, uint32 *) = td->td_group4options;
-		return (1);
-	case TIFFTAG_RESOLUTIONUNIT:
-		*va_arg(ap, uint16 *) = td->td_resolutionunit;
-		return (1);
-	case TIFFTAG_PREDICTOR:
-		*va_arg(ap, uint16 *) = td->td_predictor;
-		return (1);
+        if (TIFFVGetField(tif, tag, ap))
+                return (1);
+        switch (tag) {
+        case TIFFTAG_SUBFILETYPE:
+                *va_arg(ap, uint16 *) = td->td_subfiletype;
+                return (1);
+        case TIFFTAG_BITSPERSAMPLE:
+                *va_arg(ap, uint16 *) = td->td_bitspersample;
+                return (1);
+        case TIFFTAG_THRESHHOLDING:
+                *va_arg(ap, uint16 *) = td->td_threshholding;
+                return (1);
+        case TIFFTAG_FILLORDER:
+                *va_arg(ap, uint16 *) = td->td_fillorder;
+                return (1);
+        case TIFFTAG_ORIENTATION:
+                *va_arg(ap, uint16 *) = td->td_orientation;
+                return (1);
+        case TIFFTAG_SAMPLESPERPIXEL:
+                *va_arg(ap, uint16 *) = td->td_samplesperpixel;
+                return (1);
+        case TIFFTAG_ROWSPERSTRIP:
+                *va_arg(ap, uint32 *) = td->td_rowsperstrip;
+                return (1);
+        case TIFFTAG_MINSAMPLEVALUE:
+                *va_arg(ap, uint16 *) = td->td_minsamplevalue;
+                return (1);
+        case TIFFTAG_MAXSAMPLEVALUE:
+                *va_arg(ap, uint16 *) = td->td_maxsamplevalue;
+                return (1);
+        case TIFFTAG_PLANARCONFIG:
+                *va_arg(ap, uint16 *) = td->td_planarconfig;
+                return (1);
+        case TIFFTAG_GROUP4OPTIONS:
+                *va_arg(ap, uint32 *) = td->td_group4options;
+                return (1);
+        case TIFFTAG_RESOLUTIONUNIT:
+                *va_arg(ap, uint16 *) = td->td_resolutionunit;
+                return (1);
+        case TIFFTAG_PREDICTOR:
+                *va_arg(ap, uint16 *) = td->td_predictor;
+                return (1);
 #ifdef CMYK_SUPPORT
-	case TIFFTAG_DOTRANGE:
-		*va_arg(ap, uint16 *) = 0;
-		*va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
-		return (1);
-	case TIFFTAG_INKSET:
-		*va_arg(ap, uint16 *) = td->td_inkset;
-		return (1);
+        case TIFFTAG_DOTRANGE:
+                *va_arg(ap, uint16 *) = 0;
+                *va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
+                return (1);
+        case TIFFTAG_INKSET:
+                *va_arg(ap, uint16 *) = td->td_inkset;
+                return (1);
 #endif
-	case TIFFTAG_EXTRASAMPLES:
-		*va_arg(ap, uint16 *) = td->td_extrasamples;
-		*va_arg(ap, uint16 **) = td->td_sampleinfo;
-		return (1);
-	case TIFFTAG_MATTEING:
-		*va_arg(ap, uint16 *) =
-		    (td->td_extrasamples == 1 &&
-		     td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
-		return (1);
-	case TIFFTAG_TILEDEPTH:
-		*va_arg(ap, uint32 *) = td->td_tiledepth;
-		return (1);
-	case TIFFTAG_DATATYPE:
-		*va_arg(ap, uint16 *) = td->td_sampleformat-1;
-		return (1);
-	case TIFFTAG_IMAGEDEPTH:
-		*va_arg(ap, uint16 *) = td->td_imagedepth;
-		return (1);
+        case TIFFTAG_EXTRASAMPLES:
+                *va_arg(ap, uint16 *) = td->td_extrasamples;
+                *va_arg(ap, uint16 **) = td->td_sampleinfo;
+                return (1);
+        case TIFFTAG_MATTEING:
+                *va_arg(ap, uint16 *) =
+                    (td->td_extrasamples == 1 &&
+                     td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
+                return (1);
+        case TIFFTAG_TILEDEPTH:
+                *va_arg(ap, uint32 *) = td->td_tiledepth;
+                return (1);
+        case TIFFTAG_DATATYPE:
+                *va_arg(ap, uint16 *) = td->td_sampleformat-1;
+                return (1);
+        case TIFFTAG_IMAGEDEPTH:
+                *va_arg(ap, uint16 *) = td->td_imagedepth;
+                return (1);
 #ifdef YCBCR_SUPPORT
-	case TIFFTAG_YCBCRCOEFFICIENTS:
-		if (!td->td_ycbcrcoeffs) {
-			td->td_ycbcrcoeffs = (float *)
-			    _TIFFmalloc(3*sizeof (float));
-			/* defaults are from CCIR Recommendation 601-1 */
-			td->td_ycbcrcoeffs[0] = .299;
-			td->td_ycbcrcoeffs[1] = .587;
-			td->td_ycbcrcoeffs[2] = .114;
-		}
-		*va_arg(ap, float **) = td->td_ycbcrcoeffs;
-		return (1);
-	case TIFFTAG_YCBCRSUBSAMPLING:
-		*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0];
-		*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1];
-		return (1);
-	case TIFFTAG_YCBCRPOSITIONING:
-		*va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
-		return (1);
+        case TIFFTAG_YCBCRCOEFFICIENTS:
+                if (!td->td_ycbcrcoeffs) {
+                        td->td_ycbcrcoeffs = (float *)
+                            _TIFFmalloc(3*sizeof (float));
+                        /* defaults are from CCIR Recommendation 601-1 */
+                        td->td_ycbcrcoeffs[0] = .299;
+                        td->td_ycbcrcoeffs[1] = .587;
+                        td->td_ycbcrcoeffs[2] = .114;
+                }
+                *va_arg(ap, float **) = td->td_ycbcrcoeffs;
+                return (1);
+        case TIFFTAG_YCBCRSUBSAMPLING:
+                *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0];
+                *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1];
+                return (1);
+        case TIFFTAG_YCBCRPOSITIONING:
+                *va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
+                return (1);
 #endif
 #ifdef COLORIMETRY_SUPPORT
-	case TIFFTAG_TRANSFERFUNCTION:
-		if (!td->td_transferfunction[0])
-			TIFFDefaultTransferFunction(td);
-		*va_arg(ap, uint16 **) = td->td_transferfunction[0];
-		if (td->td_samplesperpixel - td->td_extrasamples > 1) {
-			*va_arg(ap, uint16 **) = td->td_transferfunction[1];
-			*va_arg(ap, uint16 **) = td->td_transferfunction[2];
-		}
-		return (1);
-	case TIFFTAG_REFERENCEBLACKWHITE:
-		if (!td->td_refblackwhite)
-			TIFFDefaultRefBlackWhite(td);
-		*va_arg(ap, float **) = td->td_refblackwhite;
-		return (1);
+        case TIFFTAG_TRANSFERFUNCTION:
+                if (!td->td_transferfunction[0])
+                        TIFFDefaultTransferFunction(td);
+                *va_arg(ap, uint16 **) = td->td_transferfunction[0];
+                if (td->td_samplesperpixel - td->td_extrasamples > 1) {
+                        *va_arg(ap, uint16 **) = td->td_transferfunction[1];
+                        *va_arg(ap, uint16 **) = td->td_transferfunction[2];
+                }
+                return (1);
+        case TIFFTAG_REFERENCEBLACKWHITE:
+                if (!td->td_refblackwhite)
+                        TIFFDefaultRefBlackWhite(td);
+                *va_arg(ap, float **) = td->td_refblackwhite;
+                return (1);
 #endif
-	}
-	return (0);
+        }
+        return (0);
 }
 
 /*
@@ -194,11 +194,11 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
  */
 TIFFGetFieldDefaulted(TIFF* tif, ttag_t tag, ...)
 {
-	int ok;
-	va_list ap;
+        int ok;
+        va_list ap;
 
-	va_start(ap, tag);
-	ok =  TIFFVGetFieldDefaulted(tif, tag, ap);
-	va_end(ap);
-	return (ok);
+        va_start(ap, tag);
+        ok =  TIFFVGetFieldDefaulted(tif, tag, ap);
+        va_end(ap);
+        return (ok);
 }

+ 30 - 30
panda/src/tiff/tif_ccittrle.c

@@ -37,39 +37,39 @@ static char rcsid[] = "$Header$";
 
 TIFFInitCCITTRLE(TIFF* tif)
 {
-	TIFFInitCCITTFax3(tif);		/* reuse G3 compression */
-	tif->tif_preencode = NULL;
-	tif->tif_postencode = NULL;
-	tif->tif_encoderow = TIFFNoRowEncode;
-	tif->tif_encodestrip = TIFFNoStripEncode;
-	tif->tif_encodetile = TIFFNoTileEncode;
-	tif->tif_close = NULL;
-	/*
-	 * This magic causes the regular G3 decompression
-	 * code to not skip to the EOL mark at the end of
-	 * a row, and to flush input data to a byte boundary
-	 * at the end of each row.
-	 */
-	tif->tif_options |= FAX3_NOEOL|FAX3_BYTEALIGN;
-	return (1);
+        TIFFInitCCITTFax3(tif);         /* reuse G3 compression */
+        tif->tif_preencode = NULL;
+        tif->tif_postencode = NULL;
+        tif->tif_encoderow = TIFFNoRowEncode;
+        tif->tif_encodestrip = TIFFNoStripEncode;
+        tif->tif_encodetile = TIFFNoTileEncode;
+        tif->tif_close = NULL;
+        /*
+         * This magic causes the regular G3 decompression
+         * code to not skip to the EOL mark at the end of
+         * a row, and to flush input data to a byte boundary
+         * at the end of each row.
+         */
+        tif->tif_options |= FAX3_NOEOL|FAX3_BYTEALIGN;
+        return (1);
 }
 
 int
 TIFFInitCCITTRLEW(TIFF* tif)
 {
-	TIFFInitCCITTFax3(tif);		/* reuse G3 compression */
-	tif->tif_preencode = NULL;
-	tif->tif_postencode = NULL;
-	tif->tif_encoderow = TIFFNoRowEncode;
-	tif->tif_encodestrip = TIFFNoStripEncode;
-	tif->tif_encodetile = TIFFNoTileEncode;
-	tif->tif_close = NULL;
-	/*
-	 * This magic causes the regular G3 decompression
-	 * code to not skip to the EOL mark at the end of
-	 * a row, and to flush input data to a byte boundary
-	 * at the end of each row.
-	 */
-	tif->tif_options |= FAX3_NOEOL|FAX3_WORDALIGN;
-	return (1);
+        TIFFInitCCITTFax3(tif);         /* reuse G3 compression */
+        tif->tif_preencode = NULL;
+        tif->tif_postencode = NULL;
+        tif->tif_encoderow = TIFFNoRowEncode;
+        tif->tif_encodestrip = TIFFNoStripEncode;
+        tif->tif_encodetile = TIFFNoTileEncode;
+        tif->tif_close = NULL;
+        /*
+         * This magic causes the regular G3 decompression
+         * code to not skip to the EOL mark at the end of
+         * a row, and to flush input data to a byte boundary
+         * at the end of each row.
+         */
+        tif->tif_options |= FAX3_NOEOL|FAX3_WORDALIGN;
+        return (1);
 }

+ 14 - 14
panda/src/tiff/tif_close.c

@@ -34,18 +34,18 @@ static char rcsid[] = "$Header$";
 void
 TIFFClose(TIFF* tif)
 {
-	if (tif->tif_mode != O_RDONLY)
-		/*
-		 * Flush buffered data and directory (if dirty).
-		 */
-		TIFFFlush(tif);
-	if (tif->tif_cleanup)
-		(*tif->tif_cleanup)(tif);
-	TIFFFreeDirectory(tif);
-	if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
-		_TIFFfree(tif->tif_rawdata);
-	if (isMapped(tif))
-		TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
-	(void) TIFFCloseFile(tif);
-	_TIFFfree((char *)tif);
+        if (tif->tif_mode != O_RDONLY)
+                /*
+                 * Flush buffered data and directory (if dirty).
+                 */
+                TIFFFlush(tif);
+        if (tif->tif_cleanup)
+                (*tif->tif_cleanup)(tif);
+        TIFFFreeDirectory(tif);
+        if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
+                _TIFFfree(tif->tif_rawdata);
+        if (isMapped(tif))
+                TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
+        (void) TIFFCloseFile(tif);
+        _TIFFfree((char *)tif);
 }

+ 55 - 55
panda/src/tiff/tif_compress.c

@@ -34,125 +34,125 @@ static char rcsid[] = "$Header$";
 #include "tiffiop.h"
 
 typedef struct {
-	char*	name;
-	int	scheme;
-	TIFFBoolMethod	init;
+        char*   name;
+        int     scheme;
+        TIFFBoolMethod  init;
 } cscheme_t;
 static const cscheme_t CompressionSchemes[] = {
-    { "Null",		COMPRESSION_NONE,	TIFFInitDumpMode },
+    { "Null",           COMPRESSION_NONE,       TIFFInitDumpMode },
 #ifdef LZW_SUPPORT
-    { "LZW",		COMPRESSION_LZW,	TIFFInitLZW },
+    { "LZW",            COMPRESSION_LZW,        TIFFInitLZW },
 #endif
 #ifdef PACKBITS_SUPPORT
-    { "PackBits",	COMPRESSION_PACKBITS,	TIFFInitPackBits },
+    { "PackBits",       COMPRESSION_PACKBITS,   TIFFInitPackBits },
 #endif
 #ifdef THUNDER_SUPPORT
-    { "ThunderScan",	COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
+    { "ThunderScan",    COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
 #endif
 #ifdef NEXT_SUPPORT
-    { "NeXT",		COMPRESSION_NEXT,	TIFFInitNeXT },
+    { "NeXT",           COMPRESSION_NEXT,       TIFFInitNeXT },
 #endif
 #ifdef JPEG_SUPPORT
-    { "JPEG",		COMPRESSION_JPEG,	TIFFInitJPEG },
+    { "JPEG",           COMPRESSION_JPEG,       TIFFInitJPEG },
 #endif
 #ifdef CCITT_SUPPORT
-    { "CCITT RLE",	COMPRESSION_CCITTRLE,	TIFFInitCCITTRLE },
-    { "CCITT RLE/W",	COMPRESSION_CCITTRLEW,	TIFFInitCCITTRLEW },
-    { "CCITT Group3",	COMPRESSION_CCITTFAX3,	TIFFInitCCITTFax3 },
-    { "CCITT Group4",	COMPRESSION_CCITTFAX4,	TIFFInitCCITTFax4 },
+    { "CCITT RLE",      COMPRESSION_CCITTRLE,   TIFFInitCCITTRLE },
+    { "CCITT RLE/W",    COMPRESSION_CCITTRLEW,  TIFFInitCCITTRLEW },
+    { "CCITT Group3",   COMPRESSION_CCITTFAX3,  TIFFInitCCITTFax3 },
+    { "CCITT Group4",   COMPRESSION_CCITTFAX4,  TIFFInitCCITTFax4 },
 #endif
 };
-#define	NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
+#define NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
 
 static const cscheme_t *
 findScheme(int scheme)
 {
-	register const cscheme_t *c;
+        register const cscheme_t *c;
 
-	for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
-		if (c->scheme == scheme)
-			return (c);
-	return ((const cscheme_t *)0);
+        for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
+                if (c->scheme == scheme)
+                        return (c);
+        return ((const cscheme_t *)0);
 }
 
 static int
 TIFFNoEncode(TIFF* tif, char* method)
 {
-	const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
-	TIFFError(tif->tif_name,
-	    "%s %s encoding is not implemented", c->name, method);
-	return (-1);
+        const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
+        TIFFError(tif->tif_name,
+            "%s %s encoding is not implemented", c->name, method);
+        return (-1);
 }
 
 int
 TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoEncode(tif, "scanline"));
+        return (TIFFNoEncode(tif, "scanline"));
 }
 
 int
 TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoEncode(tif, "strip"));
+        return (TIFFNoEncode(tif, "strip"));
 }
 
 int
 TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoEncode(tif, "tile"));
+        return (TIFFNoEncode(tif, "tile"));
 }
 
 static int
 TIFFNoDecode(TIFF* tif, char* method)
 {
-	const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
-	TIFFError(tif->tif_name,
-	    "%s %s decoding is not implemented", c->name, method);
-	return (-1);
+        const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
+        TIFFError(tif->tif_name,
+            "%s %s decoding is not implemented", c->name, method);
+        return (-1);
 }
 
 int
 TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoDecode(tif, "scanline"));
+        return (TIFFNoDecode(tif, "scanline"));
 }
 
 int
 TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoDecode(tif, "strip"));
+        return (TIFFNoDecode(tif, "strip"));
 }
 
 int
 TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	return (TIFFNoDecode(tif, "tile"));
+        return (TIFFNoDecode(tif, "tile"));
 }
 
 int
 TIFFSetCompressionScheme(TIFF* tif, int scheme)
 {
-	const cscheme_t *c = findScheme(scheme);
+        const cscheme_t *c = findScheme(scheme);
 
-	if (!c) {
-		TIFFError(tif->tif_name,
-		    "Unknown data compression algorithm %u (0x%x)",
-		    scheme, scheme);
-		return (0);
-	}
-	tif->tif_predecode = NULL;
-	tif->tif_decoderow = TIFFNoRowDecode;
-	tif->tif_decodestrip = TIFFNoStripDecode;
-	tif->tif_decodetile = TIFFNoTileDecode;
-	tif->tif_preencode = NULL;
-	tif->tif_postencode = NULL;
-	tif->tif_encoderow = TIFFNoRowEncode;
-	tif->tif_encodestrip = TIFFNoStripEncode;
-	tif->tif_encodetile = TIFFNoTileEncode;
-	tif->tif_close = NULL;
-	tif->tif_seek = NULL;
-	tif->tif_cleanup = NULL;
-	tif->tif_flags &= ~TIFF_NOBITREV;
-	tif->tif_options = 0;
-	return ((*c->init)(tif));
+        if (!c) {
+                TIFFError(tif->tif_name,
+                    "Unknown data compression algorithm %u (0x%x)",
+                    scheme, scheme);
+                return (0);
+        }
+        tif->tif_predecode = NULL;
+        tif->tif_decoderow = TIFFNoRowDecode;
+        tif->tif_decodestrip = TIFFNoStripDecode;
+        tif->tif_decodetile = TIFFNoTileDecode;
+        tif->tif_preencode = NULL;
+        tif->tif_postencode = NULL;
+        tif->tif_encoderow = TIFFNoRowEncode;
+        tif->tif_encodestrip = TIFFNoStripEncode;
+        tif->tif_encodetile = TIFFNoTileEncode;
+        tif->tif_close = NULL;
+        tif->tif_seek = NULL;
+        tif->tif_cleanup = NULL;
+        tif->tif_flags &= ~TIFF_NOBITREV;
+        tif->tif_options = 0;
+        return ((*c->init)(tif));
 }

File diff suppressed because it is too large
+ 642 - 642
panda/src/tiff/tif_dir.c


+ 219 - 219
panda/src/tiff/tif_dirinfo.c

@@ -34,8 +34,8 @@ static char rcsid[] = "$Header$";
 #include "tiffiop.h"
 
 #ifndef TRUE
-#define	TRUE	1
-#define	FALSE	0
+#define TRUE    1
+#define FALSE   0
 #endif
 
 /*
@@ -45,245 +45,245 @@ static char rcsid[] = "$Header$";
  *     writing to work properly.
  */
 const TIFFFieldInfo tiffFieldInfo[] = {
-    { TIFFTAG_SUBFILETYPE,	 1, 1, TIFF_LONG,	FIELD_SUBFILETYPE,
-      TRUE,	"SubfileType" },
+    { TIFFTAG_SUBFILETYPE,       1, 1, TIFF_LONG,       FIELD_SUBFILETYPE,
+      TRUE,     "SubfileType" },
 /* XXX SHORT for compatibility w/ old versions of the library */
-    { TIFFTAG_SUBFILETYPE,	 1, 1, TIFF_SHORT,	FIELD_SUBFILETYPE,
-      TRUE,	"SubfileType" },
-    { TIFFTAG_OSUBFILETYPE,	 1, 1, TIFF_SHORT,	FIELD_SUBFILETYPE,
-      TRUE,	"OldSubfileType" },
-    { TIFFTAG_IMAGEWIDTH,	 1, 1, TIFF_LONG,	FIELD_IMAGEDIMENSIONS,
-      FALSE,	"ImageWidth" },
-    { TIFFTAG_IMAGEWIDTH,	 1, 1, TIFF_SHORT,	FIELD_IMAGEDIMENSIONS,
-      FALSE,	"ImageWidth" },
-    { TIFFTAG_IMAGELENGTH,	 1, 1, TIFF_LONG,	FIELD_IMAGEDIMENSIONS,
-      TRUE,	"ImageLength" },
-    { TIFFTAG_IMAGELENGTH,	 1, 1, TIFF_SHORT,	FIELD_IMAGEDIMENSIONS,
-      TRUE,	"ImageLength" },
-    { TIFFTAG_BITSPERSAMPLE,	-1,-1, TIFF_SHORT,	FIELD_BITSPERSAMPLE,
-      FALSE,	"BitsPerSample" },
-    { TIFFTAG_COMPRESSION,	-1, 1, TIFF_SHORT,	FIELD_COMPRESSION,
-      FALSE,	"Compression" },
-    { TIFFTAG_PHOTOMETRIC,	 1, 1, TIFF_SHORT,	FIELD_PHOTOMETRIC,
-      FALSE,	"PhotometricInterpretation" },
-    { TIFFTAG_THRESHHOLDING,	 1, 1, TIFF_SHORT,	FIELD_THRESHHOLDING,
-      TRUE,	"Threshholding" },
-    { TIFFTAG_CELLWIDTH,	 1, 1, TIFF_SHORT,	FIELD_IGNORE,
-      TRUE,	"CellWidth" },
-    { TIFFTAG_CELLLENGTH,	 1, 1, TIFF_SHORT,	FIELD_IGNORE,
-      TRUE,	"CellLength" },
-    { TIFFTAG_FILLORDER,	 1, 1, TIFF_SHORT,	FIELD_FILLORDER,
-      FALSE,	"FillOrder" },
-    { TIFFTAG_DOCUMENTNAME,	-1,-1, TIFF_ASCII,	FIELD_DOCUMENTNAME,
-      TRUE,	"DocumentName" },
-    { TIFFTAG_IMAGEDESCRIPTION,	-1,-1, TIFF_ASCII,	FIELD_IMAGEDESCRIPTION,
-      TRUE,	"ImageDescription" },
-    { TIFFTAG_MAKE,		-1,-1, TIFF_ASCII,	FIELD_MAKE,
-      TRUE,	"Make" },
-    { TIFFTAG_MODEL,		-1,-1, TIFF_ASCII,	FIELD_MODEL,
-      TRUE,	"Model" },
-    { TIFFTAG_STRIPOFFSETS,	-1,-1, TIFF_LONG,	FIELD_STRIPOFFSETS,
-      FALSE,	"StripOffsets" },
-    { TIFFTAG_STRIPOFFSETS,	-1,-1, TIFF_SHORT,	FIELD_STRIPOFFSETS,
-      FALSE,	"StripOffsets" },
-    { TIFFTAG_ORIENTATION,	 1, 1, TIFF_SHORT,	FIELD_ORIENTATION,
-      FALSE,	"Orientation" },
-    { TIFFTAG_SAMPLESPERPIXEL,	 1, 1, TIFF_SHORT,	FIELD_SAMPLESPERPIXEL,
-      FALSE,	"SamplesPerPixel" },
-    { TIFFTAG_ROWSPERSTRIP,	 1, 1, TIFF_LONG,	FIELD_ROWSPERSTRIP,
-      FALSE,	"RowsPerStrip" },
-    { TIFFTAG_ROWSPERSTRIP,	 1, 1, TIFF_SHORT,	FIELD_ROWSPERSTRIP,
-      FALSE,	"RowsPerStrip" },
-    { TIFFTAG_STRIPBYTECOUNTS,	-1,-1, TIFF_LONG,	FIELD_STRIPBYTECOUNTS,
-      FALSE,	"StripByteCounts" },
-    { TIFFTAG_STRIPBYTECOUNTS,	-1,-1, TIFF_SHORT,	FIELD_STRIPBYTECOUNTS,
-      FALSE,	"StripByteCounts" },
-    { TIFFTAG_MINSAMPLEVALUE,	-2,-1, TIFF_SHORT,	FIELD_MINSAMPLEVALUE,
-      TRUE,	"MinSampleValue" },
-    { TIFFTAG_MAXSAMPLEVALUE,	-2,-1, TIFF_SHORT,	FIELD_MAXSAMPLEVALUE,
-      TRUE,	"MaxSampleValue" },
-    { TIFFTAG_XRESOLUTION,	 1, 1, TIFF_RATIONAL,	FIELD_RESOLUTION,
-      FALSE,	"XResolution" },
-    { TIFFTAG_YRESOLUTION,	 1, 1, TIFF_RATIONAL,	FIELD_RESOLUTION,
-      FALSE,	"YResolution" },
-    { TIFFTAG_PLANARCONFIG,	 1, 1, TIFF_SHORT,	FIELD_PLANARCONFIG,
-      FALSE,	"PlanarConfiguration" },
-    { TIFFTAG_PAGENAME,		-1,-1, TIFF_ASCII,	FIELD_PAGENAME,
-      TRUE,	"PageName" },
-    { TIFFTAG_XPOSITION,	 1, 1, TIFF_RATIONAL,	FIELD_POSITION,
-      TRUE,	"XPosition" },
-    { TIFFTAG_YPOSITION,	 1, 1, TIFF_RATIONAL,	FIELD_POSITION,
-      TRUE,	"YPosition" },
-    { TIFFTAG_FREEOFFSETS,	-1,-1, TIFF_LONG,	FIELD_IGNORE,
-      FALSE,	"FreeOffsets" },
-    { TIFFTAG_FREEBYTECOUNTS,	-1,-1, TIFF_LONG,	FIELD_IGNORE,
-      FALSE,	"FreeByteCounts" },
-    { TIFFTAG_GRAYRESPONSEUNIT,	 1, 1, TIFF_SHORT,	FIELD_IGNORE,
-      TRUE,	"GrayResponseUnit" },
-    { TIFFTAG_GRAYRESPONSECURVE,-1,-1, TIFF_SHORT,	FIELD_IGNORE,
-      TRUE,	"GrayResponseCurve" },
-    { TIFFTAG_GROUP3OPTIONS,	 1, 1, TIFF_LONG,	FIELD_GROUP3OPTIONS,
-      FALSE,	"Group3Options" },
-    { TIFFTAG_GROUP4OPTIONS,	 1, 1, TIFF_LONG,	FIELD_GROUP4OPTIONS,
-      FALSE,	"Group4Options" },
-    { TIFFTAG_RESOLUTIONUNIT,	 1, 1, TIFF_SHORT,	FIELD_RESOLUTIONUNIT,
-      FALSE,	"ResolutionUnit" },
-    { TIFFTAG_PAGENUMBER,	 2, 2, TIFF_SHORT,	FIELD_PAGENUMBER,
-      TRUE,	"PageNumber" },
-    { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT,	FIELD_IGNORE,
-      TRUE,	"ColorResponseUnit" },
+    { TIFFTAG_SUBFILETYPE,       1, 1, TIFF_SHORT,      FIELD_SUBFILETYPE,
+      TRUE,     "SubfileType" },
+    { TIFFTAG_OSUBFILETYPE,      1, 1, TIFF_SHORT,      FIELD_SUBFILETYPE,
+      TRUE,     "OldSubfileType" },
+    { TIFFTAG_IMAGEWIDTH,        1, 1, TIFF_LONG,       FIELD_IMAGEDIMENSIONS,
+      FALSE,    "ImageWidth" },
+    { TIFFTAG_IMAGEWIDTH,        1, 1, TIFF_SHORT,      FIELD_IMAGEDIMENSIONS,
+      FALSE,    "ImageWidth" },
+    { TIFFTAG_IMAGELENGTH,       1, 1, TIFF_LONG,       FIELD_IMAGEDIMENSIONS,
+      TRUE,     "ImageLength" },
+    { TIFFTAG_IMAGELENGTH,       1, 1, TIFF_SHORT,      FIELD_IMAGEDIMENSIONS,
+      TRUE,     "ImageLength" },
+    { TIFFTAG_BITSPERSAMPLE,    -1,-1, TIFF_SHORT,      FIELD_BITSPERSAMPLE,
+      FALSE,    "BitsPerSample" },
+    { TIFFTAG_COMPRESSION,      -1, 1, TIFF_SHORT,      FIELD_COMPRESSION,
+      FALSE,    "Compression" },
+    { TIFFTAG_PHOTOMETRIC,       1, 1, TIFF_SHORT,      FIELD_PHOTOMETRIC,
+      FALSE,    "PhotometricInterpretation" },
+    { TIFFTAG_THRESHHOLDING,     1, 1, TIFF_SHORT,      FIELD_THRESHHOLDING,
+      TRUE,     "Threshholding" },
+    { TIFFTAG_CELLWIDTH,         1, 1, TIFF_SHORT,      FIELD_IGNORE,
+      TRUE,     "CellWidth" },
+    { TIFFTAG_CELLLENGTH,        1, 1, TIFF_SHORT,      FIELD_IGNORE,
+      TRUE,     "CellLength" },
+    { TIFFTAG_FILLORDER,         1, 1, TIFF_SHORT,      FIELD_FILLORDER,
+      FALSE,    "FillOrder" },
+    { TIFFTAG_DOCUMENTNAME,     -1,-1, TIFF_ASCII,      FIELD_DOCUMENTNAME,
+      TRUE,     "DocumentName" },
+    { TIFFTAG_IMAGEDESCRIPTION, -1,-1, TIFF_ASCII,      FIELD_IMAGEDESCRIPTION,
+      TRUE,     "ImageDescription" },
+    { TIFFTAG_MAKE,             -1,-1, TIFF_ASCII,      FIELD_MAKE,
+      TRUE,     "Make" },
+    { TIFFTAG_MODEL,            -1,-1, TIFF_ASCII,      FIELD_MODEL,
+      TRUE,     "Model" },
+    { TIFFTAG_STRIPOFFSETS,     -1,-1, TIFF_LONG,       FIELD_STRIPOFFSETS,
+      FALSE,    "StripOffsets" },
+    { TIFFTAG_STRIPOFFSETS,     -1,-1, TIFF_SHORT,      FIELD_STRIPOFFSETS,
+      FALSE,    "StripOffsets" },
+    { TIFFTAG_ORIENTATION,       1, 1, TIFF_SHORT,      FIELD_ORIENTATION,
+      FALSE,    "Orientation" },
+    { TIFFTAG_SAMPLESPERPIXEL,   1, 1, TIFF_SHORT,      FIELD_SAMPLESPERPIXEL,
+      FALSE,    "SamplesPerPixel" },
+    { TIFFTAG_ROWSPERSTRIP,      1, 1, TIFF_LONG,       FIELD_ROWSPERSTRIP,
+      FALSE,    "RowsPerStrip" },
+    { TIFFTAG_ROWSPERSTRIP,      1, 1, TIFF_SHORT,      FIELD_ROWSPERSTRIP,
+      FALSE,    "RowsPerStrip" },
+    { TIFFTAG_STRIPBYTECOUNTS,  -1,-1, TIFF_LONG,       FIELD_STRIPBYTECOUNTS,
+      FALSE,    "StripByteCounts" },
+    { TIFFTAG_STRIPBYTECOUNTS,  -1,-1, TIFF_SHORT,      FIELD_STRIPBYTECOUNTS,
+      FALSE,    "StripByteCounts" },
+    { TIFFTAG_MINSAMPLEVALUE,   -2,-1, TIFF_SHORT,      FIELD_MINSAMPLEVALUE,
+      TRUE,     "MinSampleValue" },
+    { TIFFTAG_MAXSAMPLEVALUE,   -2,-1, TIFF_SHORT,      FIELD_MAXSAMPLEVALUE,
+      TRUE,     "MaxSampleValue" },
+    { TIFFTAG_XRESOLUTION,       1, 1, TIFF_RATIONAL,   FIELD_RESOLUTION,
+      FALSE,    "XResolution" },
+    { TIFFTAG_YRESOLUTION,       1, 1, TIFF_RATIONAL,   FIELD_RESOLUTION,
+      FALSE,    "YResolution" },
+    { TIFFTAG_PLANARCONFIG,      1, 1, TIFF_SHORT,      FIELD_PLANARCONFIG,
+      FALSE,    "PlanarConfiguration" },
+    { TIFFTAG_PAGENAME,         -1,-1, TIFF_ASCII,      FIELD_PAGENAME,
+      TRUE,     "PageName" },
+    { TIFFTAG_XPOSITION,         1, 1, TIFF_RATIONAL,   FIELD_POSITION,
+      TRUE,     "XPosition" },
+    { TIFFTAG_YPOSITION,         1, 1, TIFF_RATIONAL,   FIELD_POSITION,
+      TRUE,     "YPosition" },
+    { TIFFTAG_FREEOFFSETS,      -1,-1, TIFF_LONG,       FIELD_IGNORE,
+      FALSE,    "FreeOffsets" },
+    { TIFFTAG_FREEBYTECOUNTS,   -1,-1, TIFF_LONG,       FIELD_IGNORE,
+      FALSE,    "FreeByteCounts" },
+    { TIFFTAG_GRAYRESPONSEUNIT,  1, 1, TIFF_SHORT,      FIELD_IGNORE,
+      TRUE,     "GrayResponseUnit" },
+    { TIFFTAG_GRAYRESPONSECURVE,-1,-1, TIFF_SHORT,      FIELD_IGNORE,
+      TRUE,     "GrayResponseCurve" },
+    { TIFFTAG_GROUP3OPTIONS,     1, 1, TIFF_LONG,       FIELD_GROUP3OPTIONS,
+      FALSE,    "Group3Options" },
+    { TIFFTAG_GROUP4OPTIONS,     1, 1, TIFF_LONG,       FIELD_GROUP4OPTIONS,
+      FALSE,    "Group4Options" },
+    { TIFFTAG_RESOLUTIONUNIT,    1, 1, TIFF_SHORT,      FIELD_RESOLUTIONUNIT,
+      FALSE,    "ResolutionUnit" },
+    { TIFFTAG_PAGENUMBER,        2, 2, TIFF_SHORT,      FIELD_PAGENUMBER,
+      TRUE,     "PageNumber" },
+    { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT,      FIELD_IGNORE,
+      TRUE,     "ColorResponseUnit" },
 #ifdef COLORIMETRY_SUPPORT
-    { TIFFTAG_TRANSFERFUNCTION,	-1,-1, TIFF_SHORT,	FIELD_TRANSFERFUNCTION,
-      TRUE,	"TransferFunction" },
+    { TIFFTAG_TRANSFERFUNCTION, -1,-1, TIFF_SHORT,      FIELD_TRANSFERFUNCTION,
+      TRUE,     "TransferFunction" },
 #endif
-    { TIFFTAG_SOFTWARE,		-1,-1, TIFF_ASCII,	FIELD_SOFTWARE,
-      TRUE,	"Software" },
-    { TIFFTAG_DATETIME,		20,20, TIFF_ASCII,	FIELD_DATETIME,
-      TRUE,	"DateTime" },
-    { TIFFTAG_ARTIST,		-1,-1, TIFF_ASCII,	FIELD_ARTIST,
-      TRUE,	"Artist" },
-    { TIFFTAG_HOSTCOMPUTER,	-1,-1, TIFF_ASCII,	FIELD_HOSTCOMPUTER,
-      TRUE,	"HostComputer" },
-    { TIFFTAG_PREDICTOR,	 1, 1, TIFF_SHORT,	FIELD_PREDICTOR,
-      FALSE,	"Predictor" },
+    { TIFFTAG_SOFTWARE,         -1,-1, TIFF_ASCII,      FIELD_SOFTWARE,
+      TRUE,     "Software" },
+    { TIFFTAG_DATETIME,         20,20, TIFF_ASCII,      FIELD_DATETIME,
+      TRUE,     "DateTime" },
+    { TIFFTAG_ARTIST,           -1,-1, TIFF_ASCII,      FIELD_ARTIST,
+      TRUE,     "Artist" },
+    { TIFFTAG_HOSTCOMPUTER,     -1,-1, TIFF_ASCII,      FIELD_HOSTCOMPUTER,
+      TRUE,     "HostComputer" },
+    { TIFFTAG_PREDICTOR,         1, 1, TIFF_SHORT,      FIELD_PREDICTOR,
+      FALSE,    "Predictor" },
 #ifdef COLORIMETRY_SUPPORT
-    { TIFFTAG_WHITEPOINT,	 2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT,
-      TRUE,	"WhitePoint" },
+    { TIFFTAG_WHITEPOINT,        2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT,
+      TRUE,     "WhitePoint" },
     { TIFFTAG_PRIMARYCHROMATICITIES,6,6,TIFF_RATIONAL,FIELD_PRIMARYCHROMAS,
-      TRUE,	"PrimaryChromaticities" },
+      TRUE,     "PrimaryChromaticities" },
 #endif
-    { TIFFTAG_COLORMAP,		-1,-1, TIFF_SHORT,	FIELD_COLORMAP,
-      TRUE,	"ColorMap" },
-    { TIFFTAG_HALFTONEHINTS,	 2, 2, TIFF_SHORT,	FIELD_HALFTONEHINTS,
-      TRUE,	"HalftoneHints" },
-    { TIFFTAG_TILEWIDTH,	 1, 1, TIFF_LONG,	FIELD_TILEDIMENSIONS,
-      FALSE,	"TileWidth" },
-    { TIFFTAG_TILEWIDTH,	 1, 1, TIFF_SHORT,	FIELD_TILEDIMENSIONS,
-      FALSE,	"TileWidth" },
-    { TIFFTAG_TILELENGTH,	 1, 1, TIFF_LONG,	FIELD_TILEDIMENSIONS,
-      FALSE,	"TileLength" },
-    { TIFFTAG_TILELENGTH,	 1, 1, TIFF_SHORT,	FIELD_TILEDIMENSIONS,
-      FALSE,	"TileLength" },
-    { TIFFTAG_TILEOFFSETS,	-1, 1, TIFF_LONG,	FIELD_STRIPOFFSETS,
-      FALSE,	"TileOffsets" },
-    { TIFFTAG_TILEBYTECOUNTS,	-1, 1, TIFF_LONG,	FIELD_STRIPBYTECOUNTS,
-      FALSE,	"TileByteCounts" },
-    { TIFFTAG_TILEBYTECOUNTS,	-1, 1, TIFF_SHORT,	FIELD_STRIPBYTECOUNTS,
-      FALSE,	"TileByteCounts" },
-    { TIFFTAG_BADFAXLINES,	 1, 1, TIFF_LONG,	FIELD_BADFAXLINES,
-      TRUE,	"BadFaxLines" },
-    { TIFFTAG_BADFAXLINES,	 1, 1, TIFF_SHORT,	FIELD_BADFAXLINES,
-      TRUE,	"BadFaxLines" },
-    { TIFFTAG_CLEANFAXDATA,	 1, 1, TIFF_SHORT,	FIELD_CLEANFAXDATA,
-      TRUE,	"CleanFaxData" },
+    { TIFFTAG_COLORMAP,         -1,-1, TIFF_SHORT,      FIELD_COLORMAP,
+      TRUE,     "ColorMap" },
+    { TIFFTAG_HALFTONEHINTS,     2, 2, TIFF_SHORT,      FIELD_HALFTONEHINTS,
+      TRUE,     "HalftoneHints" },
+    { TIFFTAG_TILEWIDTH,         1, 1, TIFF_LONG,       FIELD_TILEDIMENSIONS,
+      FALSE,    "TileWidth" },
+    { TIFFTAG_TILEWIDTH,         1, 1, TIFF_SHORT,      FIELD_TILEDIMENSIONS,
+      FALSE,    "TileWidth" },
+    { TIFFTAG_TILELENGTH,        1, 1, TIFF_LONG,       FIELD_TILEDIMENSIONS,
+      FALSE,    "TileLength" },
+    { TIFFTAG_TILELENGTH,        1, 1, TIFF_SHORT,      FIELD_TILEDIMENSIONS,
+      FALSE,    "TileLength" },
+    { TIFFTAG_TILEOFFSETS,      -1, 1, TIFF_LONG,       FIELD_STRIPOFFSETS,
+      FALSE,    "TileOffsets" },
+    { TIFFTAG_TILEBYTECOUNTS,   -1, 1, TIFF_LONG,       FIELD_STRIPBYTECOUNTS,
+      FALSE,    "TileByteCounts" },
+    { TIFFTAG_TILEBYTECOUNTS,   -1, 1, TIFF_SHORT,      FIELD_STRIPBYTECOUNTS,
+      FALSE,    "TileByteCounts" },
+    { TIFFTAG_BADFAXLINES,       1, 1, TIFF_LONG,       FIELD_BADFAXLINES,
+      TRUE,     "BadFaxLines" },
+    { TIFFTAG_BADFAXLINES,       1, 1, TIFF_SHORT,      FIELD_BADFAXLINES,
+      TRUE,     "BadFaxLines" },
+    { TIFFTAG_CLEANFAXDATA,      1, 1, TIFF_SHORT,      FIELD_CLEANFAXDATA,
+      TRUE,     "CleanFaxData" },
     { TIFFTAG_CONSECUTIVEBADFAXLINES,1,1, TIFF_LONG,FIELD_BADFAXRUN,
-      TRUE,	"ConsecutiveBadFaxLines" },
+      TRUE,     "ConsecutiveBadFaxLines" },
     { TIFFTAG_CONSECUTIVEBADFAXLINES,1,1, TIFF_SHORT,FIELD_BADFAXRUN,
-      TRUE,	"ConsecutiveBadFaxLines" },
-#ifdef CMYK_SUPPORT		/* 6.0 CMYK tags */
-    { TIFFTAG_INKSET,		 1, 1, TIFF_SHORT,	FIELD_INKSET,
-      FALSE,	"InkSet" },
-    { TIFFTAG_INKNAMES,		-1,-1, TIFF_ASCII,	FIELD_INKNAMES,
-      TRUE,	"InkNames" },
-    { TIFFTAG_DOTRANGE,		 2, 2, TIFF_SHORT,	FIELD_DOTRANGE,
-      FALSE,	"DotRange" },
-    { TIFFTAG_DOTRANGE,		 2, 2, TIFF_BYTE,	FIELD_DOTRANGE,
-      FALSE,	"DotRange" },
-    { TIFFTAG_TARGETPRINTER,	-1,-1, TIFF_ASCII,	FIELD_TARGETPRINTER,
-      TRUE,	"TargetPrinter" },
+      TRUE,     "ConsecutiveBadFaxLines" },
+#ifdef CMYK_SUPPORT             /* 6.0 CMYK tags */
+    { TIFFTAG_INKSET,            1, 1, TIFF_SHORT,      FIELD_INKSET,
+      FALSE,    "InkSet" },
+    { TIFFTAG_INKNAMES,         -1,-1, TIFF_ASCII,      FIELD_INKNAMES,
+      TRUE,     "InkNames" },
+    { TIFFTAG_DOTRANGE,          2, 2, TIFF_SHORT,      FIELD_DOTRANGE,
+      FALSE,    "DotRange" },
+    { TIFFTAG_DOTRANGE,          2, 2, TIFF_BYTE,       FIELD_DOTRANGE,
+      FALSE,    "DotRange" },
+    { TIFFTAG_TARGETPRINTER,    -1,-1, TIFF_ASCII,      FIELD_TARGETPRINTER,
+      TRUE,     "TargetPrinter" },
 #endif
-    { TIFFTAG_EXTRASAMPLES,	-1,-1, TIFF_SHORT,	FIELD_EXTRASAMPLES,
-      FALSE,	"ExtraSamples" },
+    { TIFFTAG_EXTRASAMPLES,     -1,-1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
+      FALSE,    "ExtraSamples" },
 /* XXX for bogus Adobe Photoshop v2.5 files */
-    { TIFFTAG_EXTRASAMPLES,	-1,-1, TIFF_BYTE,	FIELD_EXTRASAMPLES,
-      FALSE,	"ExtraSamples" },
-    { TIFFTAG_SAMPLEFORMAT,	-1,-1, TIFF_SHORT,	FIELD_SAMPLEFORMAT,
-      FALSE,	"SampleFormat" },
+    { TIFFTAG_EXTRASAMPLES,     -1,-1, TIFF_BYTE,       FIELD_EXTRASAMPLES,
+      FALSE,    "ExtraSamples" },
+    { TIFFTAG_SAMPLEFORMAT,     -1,-1, TIFF_SHORT,      FIELD_SAMPLEFORMAT,
+      FALSE,    "SampleFormat" },
 #ifdef notdef
-    { TIFFTAG_SMINSAMPLEVALUE,	-2,-1, TIFF_ANY,	FIELD_SMINSAMPLEVALUE,
-      TRUE,	"SMinSampleValue" },
-    { TIFFTAG_SMAXSAMPLEVALUE,	-2,-1, TIFF_ANY,	FIELD_SMAXSAMPLEVALUE,
-      TRUE,	"SMaxSampleValue" },
+    { TIFFTAG_SMINSAMPLEVALUE,  -2,-1, TIFF_ANY,        FIELD_SMINSAMPLEVALUE,
+      TRUE,     "SMinSampleValue" },
+    { TIFFTAG_SMAXSAMPLEVALUE,  -2,-1, TIFF_ANY,        FIELD_SMAXSAMPLEVALUE,
+      TRUE,     "SMaxSampleValue" },
 #endif
-#ifdef JPEG_SUPPORT		/* 6.0 JPEG tags */
-    { TIFFTAG_JPEGPROC,		 1, 1, TIFF_SHORT,	FIELD_JPEGPROC,
-      FALSE,	"JPEGProc" },
-    { TIFFTAG_JPEGIFOFFSET,	 1, 1, TIFF_LONG,	FIELD_IGNORE,
-      FALSE,	"JPEGInterchangeFormat" },
-    { TIFFTAG_JPEGIFBYTECOUNT,	 1, 1, TIFF_LONG,	FIELD_IGNORE,
-      FALSE,	"JPEGInterchangeFormatLength" },
+#ifdef JPEG_SUPPORT             /* 6.0 JPEG tags */
+    { TIFFTAG_JPEGPROC,          1, 1, TIFF_SHORT,      FIELD_JPEGPROC,
+      FALSE,    "JPEGProc" },
+    { TIFFTAG_JPEGIFOFFSET,      1, 1, TIFF_LONG,       FIELD_IGNORE,
+      FALSE,    "JPEGInterchangeFormat" },
+    { TIFFTAG_JPEGIFBYTECOUNT,   1, 1, TIFF_LONG,       FIELD_IGNORE,
+      FALSE,    "JPEGInterchangeFormatLength" },
     { TIFFTAG_JPEGRESTARTINTERVAL,1,1, TIFF_SHORT,FIELD_JPEGRESTARTINTERVAL,
-      FALSE,	"JPEGRestartInterval" },
-    { TIFFTAG_JPEGQTABLES,	-2,-1, TIFF_LONG,	FIELD_JPEGQTABLES,
-      FALSE,	"JPEGQTables" },
-    { TIFFTAG_JPEGDCTABLES,	-2,-1, TIFF_LONG,	FIELD_JPEGDCTABLES,
-      FALSE,	"JPEGDCTables" },
-    { TIFFTAG_JPEGACTABLES,	-2,-1, TIFF_LONG,	FIELD_JPEGACTABLES,
-      FALSE,	"JPEGACTables" },
+      FALSE,    "JPEGRestartInterval" },
+    { TIFFTAG_JPEGQTABLES,      -2,-1, TIFF_LONG,       FIELD_JPEGQTABLES,
+      FALSE,    "JPEGQTables" },
+    { TIFFTAG_JPEGDCTABLES,     -2,-1, TIFF_LONG,       FIELD_JPEGDCTABLES,
+      FALSE,    "JPEGDCTables" },
+    { TIFFTAG_JPEGACTABLES,     -2,-1, TIFF_LONG,       FIELD_JPEGACTABLES,
+      FALSE,    "JPEGACTables" },
 #endif
-#ifdef YCBCR_SUPPORT		/* 6.0 YCbCr tags */
-    { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL,	FIELD_YCBCRCOEFFICIENTS,
-      FALSE,	"YCbCrCoefficients" },
-    { TIFFTAG_YCBCRSUBSAMPLING,	 2, 2, TIFF_SHORT,	FIELD_YCBCRSUBSAMPLING,
-      FALSE,	"YCbCrSubsampling" },
-    { TIFFTAG_YCBCRPOSITIONING,	 1, 1, TIFF_SHORT,	FIELD_YCBCRPOSITIONING,
-      FALSE,	"YCbCrPositioning" },
+#ifdef YCBCR_SUPPORT            /* 6.0 YCbCr tags */
+    { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL,   FIELD_YCBCRCOEFFICIENTS,
+      FALSE,    "YCbCrCoefficients" },
+    { TIFFTAG_YCBCRSUBSAMPLING,  2, 2, TIFF_SHORT,      FIELD_YCBCRSUBSAMPLING,
+      FALSE,    "YCbCrSubsampling" },
+    { TIFFTAG_YCBCRPOSITIONING,  1, 1, TIFF_SHORT,      FIELD_YCBCRPOSITIONING,
+      FALSE,    "YCbCrPositioning" },
 #endif
 #ifdef COLORIMETRY_SUPPORT
-    { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL,	FIELD_REFBLACKWHITE,
-      FALSE,	"ReferenceBlackWhite" },
+    { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL,    FIELD_REFBLACKWHITE,
+      FALSE,    "ReferenceBlackWhite" },
 /* XXX temporarily accept LONG for backwards compatibility */
-    { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG,	FIELD_REFBLACKWHITE,
-      FALSE,	"ReferenceBlackWhite" },
+    { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG,        FIELD_REFBLACKWHITE,
+      FALSE,    "ReferenceBlackWhite" },
 #endif
 /* begin SGI tags */
-    { TIFFTAG_MATTEING,		 1, 1, TIFF_SHORT,	FIELD_EXTRASAMPLES,
-      FALSE,	"Matteing" },
-    { TIFFTAG_DATATYPE,		-2,-1, TIFF_SHORT,	FIELD_SAMPLEFORMAT,
-      FALSE,	"DataType" },
-    { TIFFTAG_IMAGEDEPTH,	 1, 1, TIFF_LONG,	FIELD_IMAGEDEPTH,
-      FALSE,	"ImageDepth" },
-    { TIFFTAG_IMAGEDEPTH,	 1, 1, TIFF_SHORT,	FIELD_IMAGEDEPTH,
-      FALSE,	"ImageDepth" },
-    { TIFFTAG_TILEDEPTH,	 1, 1, TIFF_LONG,	FIELD_TILEDEPTH,
-      FALSE,	"TileDepth" },
-    { TIFFTAG_TILEDEPTH,	 1, 1, TIFF_SHORT,	FIELD_TILEDEPTH,
-      FALSE,	"TileDepth" },
+    { TIFFTAG_MATTEING,          1, 1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
+      FALSE,    "Matteing" },
+    { TIFFTAG_DATATYPE,         -2,-1, TIFF_SHORT,      FIELD_SAMPLEFORMAT,
+      FALSE,    "DataType" },
+    { TIFFTAG_IMAGEDEPTH,        1, 1, TIFF_LONG,       FIELD_IMAGEDEPTH,
+      FALSE,    "ImageDepth" },
+    { TIFFTAG_IMAGEDEPTH,        1, 1, TIFF_SHORT,      FIELD_IMAGEDEPTH,
+      FALSE,    "ImageDepth" },
+    { TIFFTAG_TILEDEPTH,         1, 1, TIFF_LONG,       FIELD_TILEDEPTH,
+      FALSE,    "TileDepth" },
+    { TIFFTAG_TILEDEPTH,         1, 1, TIFF_SHORT,      FIELD_TILEDEPTH,
+      FALSE,    "TileDepth" },
 /* end SGI tags */
     { 0 }
 };
 
 const int tiffDataWidth[] = {
-    1,	/* nothing */
-    1,	/* TIFF_BYTE */
-    1,	/* TIFF_ASCII */
-    2,	/* TIFF_SHORT */
-    4,	/* TIFF_LONG */
-    8,	/* TIFF_RATIONAL */
-    1,	/* TIFF_SBYTE */
-    1,	/* TIFF_UNDEFINED */
-    2,	/* TIFF_SSHORT */
-    4,	/* TIFF_SLONG */
-    8,	/* TIFF_SRATIONAL */
-    4,	/* TIFF_FLOAT */
-    8,	/* TIFF_DOUBLE */
+    1,  /* nothing */
+    1,  /* TIFF_BYTE */
+    1,  /* TIFF_ASCII */
+    2,  /* TIFF_SHORT */
+    4,  /* TIFF_LONG */
+    8,  /* TIFF_RATIONAL */
+    1,  /* TIFF_SBYTE */
+    1,  /* TIFF_UNDEFINED */
+    2,  /* TIFF_SSHORT */
+    4,  /* TIFF_SLONG */
+    8,  /* TIFF_SRATIONAL */
+    4,  /* TIFF_FLOAT */
+    8,  /* TIFF_DOUBLE */
 };
 
 const TIFFFieldInfo *
 TIFFFindFieldInfo(ttag_t tag, TIFFDataType dt)
 {
-	static const TIFFFieldInfo *last = NULL;
-	register const TIFFFieldInfo *fip;
+        static const TIFFFieldInfo *last = NULL;
+        register const TIFFFieldInfo *fip;
 
-	if (last && last->field_tag == tag &&
-	    (dt == TIFF_ANY || dt == last->field_type))
-		return (last);
-	/* NB: if table gets big, use sorted search (e.g. binary search) */
-	for (fip = tiffFieldInfo; fip->field_tag; fip++)
-		if (fip->field_tag == tag &&
-		    (dt == TIFF_ANY || fip->field_type == dt))
-			return (last = fip);
-	return ((const TIFFFieldInfo *)0);
+        if (last && last->field_tag == tag &&
+            (dt == TIFF_ANY || dt == last->field_type))
+                return (last);
+        /* NB: if table gets big, use sorted search (e.g. binary search) */
+        for (fip = tiffFieldInfo; fip->field_tag; fip++)
+                if (fip->field_tag == tag &&
+                    (dt == TIFF_ANY || fip->field_type == dt))
+                        return (last = fip);
+        return ((const TIFFFieldInfo *)0);
 }
 
 #include <assert.h>
@@ -292,12 +292,12 @@ TIFFFindFieldInfo(ttag_t tag, TIFFDataType dt)
 const TIFFFieldInfo *
 TIFFFieldWithTag(ttag_t tag)
 {
-	const TIFFFieldInfo *fip = TIFFFindFieldInfo(tag, TIFF_ANY);
-	if (!fip) {
-		TIFFError("TIFFFieldWithTag",
-		    "Internal error, unknown tag 0x%x", (u_int) tag);
-		assert(fip != NULL);
-		/*NOTREACHED*/
-	}
-	return (fip);
+        const TIFFFieldInfo *fip = TIFFFindFieldInfo(tag, TIFF_ANY);
+        if (!fip) {
+                TIFFError("TIFFFieldWithTag",
+                    "Internal error, unknown tag 0x%x", (u_int) tag);
+                assert(fip != NULL);
+                /*NOTREACHED*/
+        }
+        return (fip);
 }

File diff suppressed because it is too large
+ 473 - 473
panda/src/tiff/tif_dirread.c


File diff suppressed because it is too large
+ 459 - 459
panda/src/tiff/tif_dirwrite.c


+ 46 - 46
panda/src/tiff/tif_dumpmode.c

@@ -39,27 +39,27 @@ static char rcsid[] = "$Header$";
 static int
 DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
-	while (cc > 0) {
-		tsize_t n;
+        while (cc > 0) {
+                tsize_t n;
 
-		n = cc;
-		if (tif->tif_rawcc + n > tif->tif_rawdatasize)
-			n = tif->tif_rawdatasize - tif->tif_rawcc;
-		/*
-		 * Avoid copy if client has setup raw
-		 * data buffer to avoid extra copy.
-		 */
-		if (tif->tif_rawcp != pp)
-			memcpy(tif->tif_rawcp, pp, n);
-		tif->tif_rawcp += n;
-		tif->tif_rawcc += n;
-		pp += n;
-		cc -= n;
-		if (tif->tif_rawcc >= tif->tif_rawdatasize &&
-		    !TIFFFlushData1(tif))
-			return (-1);
-	}
-	return (1);
+                n = cc;
+                if (tif->tif_rawcc + n > tif->tif_rawdatasize)
+                        n = tif->tif_rawdatasize - tif->tif_rawcc;
+                /*
+                 * Avoid copy if client has setup raw
+                 * data buffer to avoid extra copy.
+                 */
+                if (tif->tif_rawcp != pp)
+                        memcpy(tif->tif_rawcp, pp, n);
+                tif->tif_rawcp += n;
+                tif->tif_rawcc += n;
+                pp += n;
+                cc -= n;
+                if (tif->tif_rawcc >= tif->tif_rawdatasize &&
+                    !TIFFFlushData1(tif))
+                        return (-1);
+        }
+        return (1);
 }
 
 /*
@@ -68,21 +68,21 @@ DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 static int
 DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
-	if (tif->tif_rawcc < cc) {
-		TIFFError(tif->tif_name,
-		    "DumpModeDecode: Not enough data for scanline %d",
-		    tif->tif_row);
-		return (0);
-	}
-	/*
-	 * Avoid copy if client has setup raw
-	 * data buffer to avoid extra copy.
-	 */
-	if (tif->tif_rawcp != buf)
-		memcpy(buf, tif->tif_rawcp, cc);
-	tif->tif_rawcp += cc;
-	tif->tif_rawcc -= cc;
-	return (1);
+        if (tif->tif_rawcc < cc) {
+                TIFFError(tif->tif_name,
+                    "DumpModeDecode: Not enough data for scanline %d",
+                    tif->tif_row);
+                return (0);
+        }
+        /*
+         * Avoid copy if client has setup raw
+         * data buffer to avoid extra copy.
+         */
+        if (tif->tif_rawcp != buf)
+                memcpy(buf, tif->tif_rawcp, cc);
+        tif->tif_rawcp += cc;
+        tif->tif_rawcc -= cc;
+        return (1);
 }
 
 /*
@@ -91,9 +91,9 @@ DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 static int
 DumpModeSeek(TIFF* tif, uint32 nrows)
 {
-	tif->tif_rawcp += nrows * tif->tif_scanlinesize;
-	tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
-	return (1);
+        tif->tif_rawcp += nrows * tif->tif_scanlinesize;
+        tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
+        return (1);
 }
 
 /*
@@ -102,12 +102,12 @@ DumpModeSeek(TIFF* tif, uint32 nrows)
 int
 TIFFInitDumpMode(TIFF* tif)
 {
-	tif->tif_decoderow = DumpModeDecode;
-	tif->tif_decodestrip = DumpModeDecode;
-	tif->tif_decodetile = DumpModeDecode;
-	tif->tif_encoderow = DumpModeEncode;
-	tif->tif_encodestrip = DumpModeEncode;
-	tif->tif_encodetile = DumpModeEncode;
-	tif->tif_seek = DumpModeSeek;
-	return (1);
+        tif->tif_decoderow = DumpModeDecode;
+        tif->tif_decodestrip = DumpModeDecode;
+        tif->tif_decodetile = DumpModeDecode;
+        tif->tif_encoderow = DumpModeEncode;
+        tif->tif_encodestrip = DumpModeEncode;
+        tif->tif_encodetile = DumpModeEncode;
+        tif->tif_seek = DumpModeSeek;
+        return (1);
 }

+ 13 - 13
panda/src/tiff/tif_error.c

@@ -35,10 +35,10 @@ static char rcsid[] = "$Header$";
 static void
 defaultHandler(const char* module, const char* fmt, va_list ap)
 {
-	if (module != NULL)
-		fprintf(stderr, "%s: ", module);
-	vfprintf(stderr, fmt, ap);
-	fprintf(stderr, ".\n");
+        if (module != NULL)
+                fprintf(stderr, "%s: ", module);
+        vfprintf(stderr, fmt, ap);
+        fprintf(stderr, ".\n");
 }
 
 static TIFFErrorHandler _errorHandler = defaultHandler;
@@ -46,18 +46,18 @@ static TIFFErrorHandler _errorHandler = defaultHandler;
 TIFFErrorHandler
 TIFFSetErrorHandler(TIFFErrorHandler handler)
 {
-	TIFFErrorHandler prev = _errorHandler;
-	_errorHandler = handler;
-	return (prev);
+        TIFFErrorHandler prev = _errorHandler;
+        _errorHandler = handler;
+        return (prev);
 }
 
 void
 TIFFError(const char* module, const char* fmt, ...)
 {
-	if (_errorHandler) {
-		va_list ap;
-		va_start(ap, fmt);
-		(*_errorHandler)(module, fmt, ap);
-		va_end(ap);
-	}
+        if (_errorHandler) {
+                va_list ap;
+                va_start(ap, fmt);
+                (*_errorHandler)(module, fmt, ap);
+                va_end(ap);
+        }
 }

File diff suppressed because it is too large
+ 482 - 482
panda/src/tiff/tif_fax3.c


+ 48 - 48
panda/src/tiff/tif_fax4.c

@@ -42,21 +42,21 @@ static char rcsid[] = "$Header$";
 static int
 Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
-	Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
-	int status;
+        Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
+        int status;
 
-	memset(buf, 0, occ);		/* decoding only sets non-zero bits */
-	while ((long)occ > 0) {
-		status = Fax3Decode2DRow(tif, buf, sp->rowpixels);
-		if (status < 0)
-			return (status == G3CODE_EOF);
-		memcpy(sp->refline, buf, sp->rowbytes);
-		buf += sp->rowbytes;
-		occ -= sp->rowbytes;
-		if (occ != 0)
-			tif->tif_row++;
-	}
-	return (1);
+        memset(buf, 0, occ);            /* decoding only sets non-zero bits */
+        while ((long)occ > 0) {
+                status = Fax3Decode2DRow(tif, buf, sp->rowpixels);
+                if (status < 0)
+                        return (status == G3CODE_EOF);
+                memcpy(sp->refline, buf, sp->rowbytes);
+                buf += sp->rowbytes;
+                occ -= sp->rowbytes;
+                if (occ != 0)
+                        tif->tif_row++;
+        }
+        return (1);
 }
 
 /*
@@ -65,50 +65,50 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 static int
 Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
-	Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
+        Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
 
-	while ((long)cc > 0) {
-		if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->rowpixels))
-			return (0);
-		memcpy(sp->refline, bp, sp->rowbytes);
-		bp += sp->rowbytes;
-		cc -= sp->rowbytes;
-		if (cc != 0)
-			tif->tif_row++;
-	}
-	return (1);
+        while ((long)cc > 0) {
+                if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->rowpixels))
+                        return (0);
+                memcpy(sp->refline, bp, sp->rowbytes);
+                bp += sp->rowbytes;
+                cc -= sp->rowbytes;
+                if (cc != 0)
+                        tif->tif_row++;
+        }
+        return (1);
 }
 
 static
 Fax4PostEncode(TIFF* tif)
 {
-	Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
+        Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
 
-	/* terminate strip w/ EOFB */
-	Fax3PutBits(tif, EOL, 12);
-	Fax3PutBits(tif, EOL, 12);
-	if (sp->bit != 8)
-		Fax3FlushBits(tif, sp);
-	return (1);
+        /* terminate strip w/ EOFB */
+        Fax3PutBits(tif, EOL, 12);
+        Fax3PutBits(tif, EOL, 12);
+        if (sp->bit != 8)
+                Fax3FlushBits(tif, sp);
+        return (1);
 }
 
 int
 TIFFInitCCITTFax4(TIFF* tif)
 {
-	TIFFInitCCITTFax3(tif);		/* reuse G3 compression */
-	tif->tif_decoderow = Fax4Decode;
-	tif->tif_decodestrip = Fax4Decode;
-	tif->tif_decodetile = Fax4Decode;
-	tif->tif_encoderow = Fax4Encode;
-	tif->tif_encodestrip = Fax4Encode;
-	tif->tif_encodetile = Fax4Encode;
-	tif->tif_postencode = Fax4PostEncode;
-	/*
-	 * FAX3_NOEOL causes the regular G3 decompression
-	 * code to not skip to the EOL mark at the end of
-	 * a row (during normal decoding).  FAX3_CLASSF
-	 * suppresses RTC generation at the end of an image.
-	 */
-	tif->tif_options = FAX3_NOEOL|FAX3_CLASSF;
-	return (1);
+        TIFFInitCCITTFax3(tif);         /* reuse G3 compression */
+        tif->tif_decoderow = Fax4Decode;
+        tif->tif_decodestrip = Fax4Decode;
+        tif->tif_decodetile = Fax4Decode;
+        tif->tif_encoderow = Fax4Encode;
+        tif->tif_encodestrip = Fax4Encode;
+        tif->tif_encodetile = Fax4Encode;
+        tif->tif_postencode = Fax4PostEncode;
+        /*
+         * FAX3_NOEOL causes the regular G3 decompression
+         * code to not skip to the EOL mark at the end of
+         * a row (during normal decoding).  FAX3_CLASSF
+         * suppresses RTC generation at the end of an image.
+         */
+        tif->tif_options = FAX3_NOEOL|FAX3_CLASSF;
+        return (1);
 }

+ 16 - 16
panda/src/tiff/tif_flush.c

@@ -35,14 +35,14 @@ int
 TIFFFlush(TIFF* tif)
 {
 
-	if (tif->tif_mode != O_RDONLY) {
-		if (!TIFFFlushData(tif))
-			return (0);
-		if ((tif->tif_flags & TIFF_DIRTYDIRECT) &&
-		    !TIFFWriteDirectory(tif))
-			return (0);
-	}
-	return (1);
+        if (tif->tif_mode != O_RDONLY) {
+                if (!TIFFFlushData(tif))
+                        return (0);
+                if ((tif->tif_flags & TIFF_DIRTYDIRECT) &&
+                    !TIFFWriteDirectory(tif))
+                        return (0);
+        }
+        return (1);
 }
 
 /*
@@ -51,12 +51,12 @@ TIFFFlush(TIFF* tif)
 int
 TIFFFlushData(TIFF* tif)
 {
-	if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
-		return (0);
-	if (tif->tif_flags & TIFF_POSTENCODE) {
-		tif->tif_flags &= ~TIFF_POSTENCODE;
-		if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
-			return (0);
-	}
-	return (TIFFFlushData1(tif));
+        if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
+                return (0);
+        if (tif->tif_flags & TIFF_POSTENCODE) {
+                tif->tif_flags &= ~TIFF_POSTENCODE;
+                if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
+                        return (0);
+        }
+        return (TIFFFlushData1(tif));
 }

File diff suppressed because it is too large
+ 475 - 475
panda/src/tiff/tif_getimage.c


+ 1 - 1
panda/src/tiff/tif_jpeg.c

@@ -35,5 +35,5 @@ static char rcsid[] = "$Header$";
 
 TIFFInitJPEG(TIFF* tif)
 {
-	return (1);
+        return (1);
 }

File diff suppressed because it is too large
+ 592 - 592
panda/src/tiff/tif_lzw.c


+ 72 - 72
panda/src/tiff/tif_machdep.c

@@ -32,102 +32,102 @@ static char rcsid[] = "$Header$";
 #include "tiffiop.h"
 
 #ifdef tahoe
-typedef	struct ieeedouble {
-	u_long	sign	: 1,
-		exp	: 11,
-		mant	: 20;
-	u_long	mant2;
+typedef struct ieeedouble {
+        u_long  sign    : 1,
+                exp     : 11,
+                mant    : 20;
+        u_long  mant2;
 } ieeedouble;
-typedef	struct ieeefloat {
-	u_long	sign	: 1,
-		exp	: 8,
-		mant	: 23;
+typedef struct ieeefloat {
+        u_long  sign    : 1,
+                exp     : 8,
+                mant    : 23;
 } ieeefloat;
 
-typedef	struct {
-	u_long	sign	: 1,
-		exp	: 8,
-		mant	: 23;
-	u_long	mant2;
+typedef struct {
+        u_long  sign    : 1,
+                exp     : 8,
+                mant    : 23;
+        u_long  mant2;
 } nativedouble;
-typedef	struct {
-	u_long	sign	: 1,
-		exp	: 8,
-		mant	: 23;
+typedef struct {
+        u_long  sign    : 1,
+                exp     : 8,
+                mant    : 23;
 } nativefloat;
 /*
  * Beware, over/under-flow in conversions will
  * result in garbage values -- handling it would
  * require a subroutine call or lots more code.
  */
-#define	NATIVE2IEEEFLOAT(fp) { \
+#define NATIVE2IEEEFLOAT(fp) { \
     if ((fp)->native.exp) \
-        (fp)->ieee.exp = (fp)->native.exp - 129 + 127;	/* alter bias */\
+        (fp)->ieee.exp = (fp)->native.exp - 129 + 127;  /* alter bias */\
 }
-#define	IEEEFLOAT2NATIVE(fp) { \
+#define IEEEFLOAT2NATIVE(fp) { \
     if ((fp)->ieee.exp) \
-        (fp)->native.exp = (fp)->ieee.exp - 127 + 129; 	/* alter bias */\
+        (fp)->native.exp = (fp)->ieee.exp - 127 + 129;  /* alter bias */\
 }
-#define	IEEEDOUBLE2NATIVE(dp) { \
+#define IEEEDOUBLE2NATIVE(dp) { \
     if ((dp)->native.exp = (dp)->ieee.exp) \
-	(dp)->native.exp += -1023 + 129; \
+        (dp)->native.exp += -1023 + 129; \
     (dp)->native.mant = ((dp)->ieee.mant<<3)|((dp)->native.mant2>>29); \
     (dp)->native.mant2 <<= 3; \
 }
 #endif /* tahoe */
 
 #ifdef vax
-typedef	struct ieeedouble {
-	u_long	mant	: 20,
-		exp	: 11,
-		sign	: 1;
-	u_long	mant2;
+typedef struct ieeedouble {
+        u_long  mant    : 20,
+                exp     : 11,
+                sign    : 1;
+        u_long  mant2;
 } ieeedouble;
-typedef	struct ieeefloat {
-	u_long	mant	: 23,
-		exp	: 8,
-		sign	: 1;
+typedef struct ieeefloat {
+        u_long  mant    : 23,
+                exp     : 8,
+                sign    : 1;
 } ieeefloat;
 
-typedef	struct {
-	u_long	mant1	: 7,
-		exp	: 8,
-		sign	: 1,
-		mant2	: 16;
-	u_long	mant3;
+typedef struct {
+        u_long  mant1   : 7,
+                exp     : 8,
+                sign    : 1,
+                mant2   : 16;
+        u_long  mant3;
 } nativedouble;
-typedef	struct {
-	u_long	mant1	: 7,
-		exp	: 8,
-		sign	: 1,
-		mant2	: 16;
+typedef struct {
+        u_long  mant1   : 7,
+                exp     : 8,
+                sign    : 1,
+                mant2   : 16;
 } nativefloat;
 /*
  * Beware, these do not handle over/under-flow
  * during conversion from ieee to native format.
  */
-#define	NATIVE2IEEEFLOAT(fp) { \
+#define NATIVE2IEEEFLOAT(fp) { \
     float_t t; \
     if (t.ieee.exp = (fp)->native.exp) \
-	t.ieee.exp += -129 + 127; \
+        t.ieee.exp += -129 + 127; \
     t.ieee.sign = (fp)->native.sign; \
     t.ieee.mant = ((fp)->native.mant1<<16)|(fp)->native.mant2; \
     *(fp) = t; \
 }
-#define	IEEEFLOAT2NATIVE(fp) { \
+#define IEEEFLOAT2NATIVE(fp) { \
     float_t t; int v = (fp)->ieee.exp; \
-    if (v) v += -127 + 129;		/* alter bias of exponent */\
-    t.native.exp = v;			/* implicit truncation of exponent */\
+    if (v) v += -127 + 129;             /* alter bias of exponent */\
+    t.native.exp = v;                   /* implicit truncation of exponent */\
     t.native.sign = (fp)->ieee.sign; \
     v = (fp)->ieee.mant; \
     t.native.mant1 = v >> 16; \
     t.native.mant2 = v;\
     *(fp) = t; \
 }
-#define	IEEEDOUBLE2NATIVE(dp) { \
+#define IEEEDOUBLE2NATIVE(dp) { \
     double_t t; int v = (dp)->ieee.exp; \
-    if (v) v += -1023 + 1025; 		/* if can alter bias of exponent */\
-    t.native.exp = v;			/* implicit truncation of exponent */\
+    if (v) v += -1023 + 1025;           /* if can alter bias of exponent */\
+    t.native.exp = v;                   /* implicit truncation of exponent */\
     v = (dp)->ieee.mant; \
     t.native.sign = (dp)->ieee.sign; \
     t.native.mant1 = v >> 16; \
@@ -148,39 +148,39 @@ but not defined how to convert between IEEE and native formats!"
  * conversions.  The above macros define the
  * conversion operations.
  */
-typedef	union {
-	ieeedouble	ieee;
-	nativedouble	native;
-	char		b[8];
-	double		d;
+typedef union {
+        ieeedouble      ieee;
+        nativedouble    native;
+        char            b[8];
+        double          d;
 } double_t;
 
-typedef	union {
-	ieeefloat	ieee;
-	nativefloat	native;
-	char		b[4];
-	float		f;
+typedef union {
+        ieeefloat       ieee;
+        nativefloat     native;
+        char            b[4];
+        float           f;
 } float_t;
 
 void
 TIFFCvtIEEEFloatToNative(TIFF* tif, u_int n, float* f)
 {
-	float_t *fp = (float_t *)f;
+        float_t *fp = (float_t *)f;
 
-	while (n-- > 0) {
-		IEEEFLOAT2NATIVE(fp);
-		fp++;
-	}
+        while (n-- > 0) {
+                IEEEFLOAT2NATIVE(fp);
+                fp++;
+        }
 }
 
 void
 TIFFCvtNativeToIEEEFloat(TIFF* tif, u_int n, float* f)
 {
-	float_t *fp = (float_t *)f;
+        float_t *fp = (float_t *)f;
 
-	while (n-- > 0) {
-		NATIVE2IEEEFLOAT(fp);
-		fp++;
-	}
+        while (n-- > 0) {
+                NATIVE2IEEEFLOAT(fp);
+                fp++;
+        }
 }
 #endif

+ 34 - 34
panda/src/tiff/tif_msdos.c

@@ -31,31 +31,31 @@ static char rcsid[] = "$Header$";
  */
 #include "tiffiop.h"
 #if defined(__WATCOMC__) || defined(__BORLANDC__)
-#include <io.h>		/* for open, close, etc. function prototypes */
+#include <io.h>         /* for open, close, etc. function prototypes */
 #endif
 
 static tsize_t 
 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (read((int) fd, buf, size));
+        return (read((int) fd, buf, size));
 }
 
 static tsize_t
 _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (write((int) fd, buf, size));
+        return (write((int) fd, buf, size));
 }
 
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
-	return (lseek((int) fd, (off_t) off, whence));
+        return (lseek((int) fd, (off_t) off, whence));
 }
 
 static int
 _tiffCloseProc(thandle_t fd)
 {
-	return (close((int) fd));
+        return (close((int) fd));
 }
 
 #include <sys/stat.h>
@@ -63,14 +63,14 @@ _tiffCloseProc(thandle_t fd)
 static toff_t
 _tiffSizeProc(thandle_t fd)
 {
-	struct stat sb;
-	return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
+        struct stat sb;
+        return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
 }
 
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	return (0);
+        return (0);
 }
 
 static void
@@ -84,15 +84,15 @@ _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 TIFF*
 TIFFFdOpen(int fd, const char* name, const char* mode)
 {
-	TIFF* tif;
-
-	tif = TIFFClientOpen(name, mode,
-	    (void*) fd,
-	    _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
-	    _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
-	if (tif)
-		tif->tif_fd = fd;
-	return (tif);
+        TIFF* tif;
+
+        tif = TIFFClientOpen(name, mode,
+            (void*) fd,
+            _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
+            _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
+        if (tif)
+                tif->tif_fd = fd;
+        return (tif);
 }
 
 /*
@@ -101,23 +101,23 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
 TIFF*
 TIFFOpen(const char* name, const char* mode)
 {
-	static const char module[] = "TIFFOpen";
-	int m, fd;
-
-	m = _TIFFgetMode(mode, module);
-	if (m == -1)
-		return ((TIFF*)0);
-	fd = open(name, m|O_BINARY, 0666);
-	if (fd < 0) {
-		TIFFError(module, "%s: Cannot open", name);
-		return ((TIFF*)0);
-	}
-	return (TIFFFdOpen(fd, name, mode));
+        static const char module[] = "TIFFOpen";
+        int m, fd;
+
+        m = _TIFFgetMode(mode, module);
+        if (m == -1)
+                return ((TIFF*)0);
+        fd = open(name, m|O_BINARY, 0666);
+        if (fd < 0) {
+                TIFFError(module, "%s: Cannot open", name);
+                return ((TIFF*)0);
+        }
+        return (TIFFFdOpen(fd, name, mode));
 }
 
 #ifdef __GNUC__
-extern	char *malloc();
-extern	char *realloc();
+extern  char *malloc();
+extern  char *realloc();
 #else
 #include <malloc.h>
 #endif
@@ -125,17 +125,17 @@ extern	char *realloc();
 void *
 _TIFFmalloc(size_t s)
 {
-	return (malloc(s));
+        return (malloc(s));
 }
 
 void
 _TIFFfree(void* p)
 {
-	free(p);
+        free(p);
 }
 
 void *
 _TIFFrealloc(void* p, size_t s)
 {
-	return (realloc(p, s));
+        return (realloc(p, s));
 }

+ 89 - 89
panda/src/tiff/tif_next.c

@@ -33,108 +33,108 @@ static char rcsid[] = "$Header$";
  */
 #include "tiffiop.h"
 
-#define SETPIXEL(op, v) {			\
-	switch (npixels++ & 3) {		\
-	case 0:	op[0]  = (v) << 6; break;	\
-	case 1:	op[0] |= (v) << 4; break;	\
-	case 2:	op[0] |= (v) << 2; break;	\
-	case 3:	*op++ |= (v);	   break;	\
-	}					\
+#define SETPIXEL(op, v) {                       \
+        switch (npixels++ & 3) {                \
+        case 0: op[0]  = (v) << 6; break;       \
+        case 1: op[0] |= (v) << 4; break;       \
+        case 2: op[0] |= (v) << 2; break;       \
+        case 3: *op++ |= (v);      break;       \
+        }                                       \
 }
 
-#define LITERALROW	0x00
-#define LITERALSPAN	0x40
-#define WHITE   	((1<<2)-1)
+#define LITERALROW      0x00
+#define LITERALSPAN     0x40
+#define WHITE           ((1<<2)-1)
 
 static int
 NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
-	register u_char *bp, *op;
-	register tsize_t cc;
-	register int n;
-	tidata_t row;
-	tsize_t scanline;
+        register u_char *bp, *op;
+        register tsize_t cc;
+        register int n;
+        tidata_t row;
+        tsize_t scanline;
 
-	/*
-	 * Each scanline is assumed to start off as all
-	 * white (we assume a PhotometricInterpretation
-	 * of ``min-is-black'').
-	 */
-	for (op = buf, cc = occ; cc-- > 0;)
-		*op++ = 0xff;
+        /*
+         * Each scanline is assumed to start off as all
+         * white (we assume a PhotometricInterpretation
+         * of ``min-is-black'').
+         */
+        for (op = buf, cc = occ; cc-- > 0;)
+                *op++ = 0xff;
 
-	bp = (u_char *)tif->tif_rawcp;
-	cc = tif->tif_rawcc;
-	scanline = tif->tif_scanlinesize;
-	for (row = buf; (long)occ > 0; occ -= scanline, row += scanline) {
-		n = *bp++, cc--;
-		switch (n) {
-		case LITERALROW:
-			/*
-			 * The entire scanline is given as literal values.
-			 */
-			if (cc < scanline)
-				goto bad;
-			memcpy(row, bp, scanline);
-			bp += scanline;
-			cc -= scanline;
-			break;
-		case LITERALSPAN: {
-			int off;
-			/*
-			 * The scanline has a literal span
-			 * that begins at some offset.
-			 */
-			off = (bp[0] * 256) + bp[1];
-			n = (bp[2] * 256) + bp[3];
-			if (cc < 4+n)
-				goto bad;
-			memcpy(row+off, bp+4, n);
-			bp += 4+n;
-			cc -= 4+n;
-			break;
-		}
-		default: {
-			register int npixels = 0, grey;
-			u_long imagewidth = tif->tif_dir.td_imagewidth;
+        bp = (u_char *)tif->tif_rawcp;
+        cc = tif->tif_rawcc;
+        scanline = tif->tif_scanlinesize;
+        for (row = buf; (long)occ > 0; occ -= scanline, row += scanline) {
+                n = *bp++, cc--;
+                switch (n) {
+                case LITERALROW:
+                        /*
+                         * The entire scanline is given as literal values.
+                         */
+                        if (cc < scanline)
+                                goto bad;
+                        memcpy(row, bp, scanline);
+                        bp += scanline;
+                        cc -= scanline;
+                        break;
+                case LITERALSPAN: {
+                        int off;
+                        /*
+                         * The scanline has a literal span
+                         * that begins at some offset.
+                         */
+                        off = (bp[0] * 256) + bp[1];
+                        n = (bp[2] * 256) + bp[3];
+                        if (cc < 4+n)
+                                goto bad;
+                        memcpy(row+off, bp+4, n);
+                        bp += 4+n;
+                        cc -= 4+n;
+                        break;
+                }
+                default: {
+                        register int npixels = 0, grey;
+                        u_long imagewidth = tif->tif_dir.td_imagewidth;
 
-			/*
-			 * The scanline is composed of a sequence
-			 * of constant color ``runs''.  We shift
-			 * into ``run mode'' and interpret bytes
-			 * as codes of the form <color><npixels>
-			 * until we've filled the scanline.
-			 */
-			op = row;
-			for (;;) {
-				grey = (n>>6) & 0x3;
-				n &= 0x3f;
-				while (n-- > 0)
-					SETPIXEL(op, grey);
-				if (npixels >= imagewidth)
-					break;
-				if (cc == 0)
-					goto bad;
-				n = *bp++, cc--;
-			}
-			break;
-		}
-		}
-	}
-	tif->tif_rawcp = (tidata_t) bp;
-	tif->tif_rawcc = cc;
-	return (1);
+                        /*
+                         * The scanline is composed of a sequence
+                         * of constant color ``runs''.  We shift
+                         * into ``run mode'' and interpret bytes
+                         * as codes of the form <color><npixels>
+                         * until we've filled the scanline.
+                         */
+                        op = row;
+                        for (;;) {
+                                grey = (n>>6) & 0x3;
+                                n &= 0x3f;
+                                while (n-- > 0)
+                                        SETPIXEL(op, grey);
+                                if (npixels >= imagewidth)
+                                        break;
+                                if (cc == 0)
+                                        goto bad;
+                                n = *bp++, cc--;
+                        }
+                        break;
+                }
+                }
+        }
+        tif->tif_rawcp = (tidata_t) bp;
+        tif->tif_rawcc = cc;
+        return (1);
 bad:
-	TIFFError(tif->tif_name, "NeXTDecode: Not enough data for scanline %ld",
-	    (long) tif->tif_row);
-	return (0);
+        TIFFError(tif->tif_name, "NeXTDecode: Not enough data for scanline %ld",
+            (long) tif->tif_row);
+        return (0);
 }
 
 int
 TIFFInitNeXT(TIFF* tif)
 {
-	tif->tif_decoderow = NeXTDecode;
-	tif->tif_decodestrip = NeXTDecode;
-	tif->tif_decodetile = NeXTDecode;
-	return (1);
+        tif->tif_decoderow = NeXTDecode;
+        tif->tif_decodestrip = NeXTDecode;
+        tif->tif_decodetile = NeXTDecode;
+        return (1);
 }

+ 225 - 225
panda/src/tiff/tif_open.c

@@ -32,49 +32,49 @@ static char rcsid[] = "$Header$";
 #include "tiffiop.h"
 
 static const long typemask[13] = {
-	0L,		/* TIFF_NOTYPE */
-	0x000000ffL,	/* TIFF_BYTE */
-	0xffffffffL,	/* TIFF_ASCII */
-	0x0000ffffL,	/* TIFF_SHORT */
-	0xffffffffL,	/* TIFF_LONG */
-	0xffffffffL,	/* TIFF_RATIONAL */
-	0x000000ffL,	/* TIFF_SBYTE */
-	0x000000ffL,	/* TIFF_UNDEFINED */
-	0x0000ffffL,	/* TIFF_SSHORT */
-	0xffffffffL,	/* TIFF_SLONG */
-	0xffffffffL,	/* TIFF_SRATIONAL */
-	0xffffffffL,	/* TIFF_FLOAT */
-	0xffffffffL,	/* TIFF_DOUBLE */
+        0L,             /* TIFF_NOTYPE */
+        0x000000ffL,    /* TIFF_BYTE */
+        0xffffffffL,    /* TIFF_ASCII */
+        0x0000ffffL,    /* TIFF_SHORT */
+        0xffffffffL,    /* TIFF_LONG */
+        0xffffffffL,    /* TIFF_RATIONAL */
+        0x000000ffL,    /* TIFF_SBYTE */
+        0x000000ffL,    /* TIFF_UNDEFINED */
+        0x0000ffffL,    /* TIFF_SSHORT */
+        0xffffffffL,    /* TIFF_SLONG */
+        0xffffffffL,    /* TIFF_SRATIONAL */
+        0xffffffffL,    /* TIFF_FLOAT */
+        0xffffffffL,    /* TIFF_DOUBLE */
 };
 static const int bigTypeshift[13] = {
-	0,		/* TIFF_NOTYPE */
-	24,		/* TIFF_BYTE */
-	0,		/* TIFF_ASCII */
-	16,		/* TIFF_SHORT */
-	0,		/* TIFF_LONG */
-	0,		/* TIFF_RATIONAL */
-	16,		/* TIFF_SBYTE */
-	16,		/* TIFF_UNDEFINED */
-	24,		/* TIFF_SSHORT */
-	0,		/* TIFF_SLONG */
-	0,		/* TIFF_SRATIONAL */
-	0,		/* TIFF_FLOAT */
-	0,		/* TIFF_DOUBLE */
+        0,              /* TIFF_NOTYPE */
+        24,             /* TIFF_BYTE */
+        0,              /* TIFF_ASCII */
+        16,             /* TIFF_SHORT */
+        0,              /* TIFF_LONG */
+        0,              /* TIFF_RATIONAL */
+        16,             /* TIFF_SBYTE */
+        16,             /* TIFF_UNDEFINED */
+        24,             /* TIFF_SSHORT */
+        0,              /* TIFF_SLONG */
+        0,              /* TIFF_SRATIONAL */
+        0,              /* TIFF_FLOAT */
+        0,              /* TIFF_DOUBLE */
 };
 static const int litTypeshift[13] = {
-	0,		/* TIFF_NOTYPE */
-	0,		/* TIFF_BYTE */
-	0,		/* TIFF_ASCII */
-	0,		/* TIFF_SHORT */
-	0,		/* TIFF_LONG */
-	0,		/* TIFF_RATIONAL */
-	0,		/* TIFF_SBYTE */
-	0,		/* TIFF_UNDEFINED */
-	0,		/* TIFF_SSHORT */
-	0,		/* TIFF_SLONG */
-	0,		/* TIFF_SRATIONAL */
-	0,		/* TIFF_FLOAT */
-	0,		/* TIFF_DOUBLE */
+        0,              /* TIFF_NOTYPE */
+        0,              /* TIFF_BYTE */
+        0,              /* TIFF_ASCII */
+        0,              /* TIFF_SHORT */
+        0,              /* TIFF_LONG */
+        0,              /* TIFF_RATIONAL */
+        0,              /* TIFF_SBYTE */
+        0,              /* TIFF_UNDEFINED */
+        0,              /* TIFF_SSHORT */
+        0,              /* TIFF_SLONG */
+        0,              /* TIFF_SRATIONAL */
+        0,              /* TIFF_FLOAT */
+        0,              /* TIFF_DOUBLE */
 };
 
 /*
@@ -86,205 +86,205 @@ static const int litTypeshift[13] = {
 static void
 TIFFInitOrder(register TIFF* tif, int magic, int bigendian)
 {
-	/* XXX how can we deduce this dynamically? */
-	tif->tif_fillorder = FILLORDER_MSB2LSB;
+        /* XXX how can we deduce this dynamically? */
+        tif->tif_fillorder = FILLORDER_MSB2LSB;
 
-	tif->tif_typemask = typemask;
-	if (magic == TIFF_BIGENDIAN) {
-		tif->tif_typeshift = bigTypeshift;
-		if (!bigendian)
-			tif->tif_flags |= TIFF_SWAB;
-	} else {
-		tif->tif_typeshift = litTypeshift;
-		if (bigendian)
-			tif->tif_flags |= TIFF_SWAB;
-	}
+        tif->tif_typemask = typemask;
+        if (magic == TIFF_BIGENDIAN) {
+                tif->tif_typeshift = bigTypeshift;
+                if (!bigendian)
+                        tif->tif_flags |= TIFF_SWAB;
+        } else {
+                tif->tif_typeshift = litTypeshift;
+                if (bigendian)
+                        tif->tif_flags |= TIFF_SWAB;
+        }
 }
 
 int
 _TIFFgetMode(const char* mode, const char* module)
 {
-	int m = -1;
+        int m = -1;
 
-	switch (mode[0]) {
-	case 'r':
-		m = O_RDONLY;
-		if (mode[1] == '+')
-			m = O_RDWR;
-		break;
-	case 'w':
-	case 'a':
-		m = O_RDWR|O_CREAT;
-		if (mode[0] == 'w')
-			m |= O_TRUNC;
-		break;
-	default:
-		TIFFError(module, "\"%s\": Bad mode", mode);
-		break;
-	}
-	return (m);
+        switch (mode[0]) {
+        case 'r':
+                m = O_RDONLY;
+                if (mode[1] == '+')
+                        m = O_RDWR;
+                break;
+        case 'w':
+        case 'a':
+                m = O_RDWR|O_CREAT;
+                if (mode[0] == 'w')
+                        m |= O_TRUNC;
+                break;
+        default:
+                TIFFError(module, "\"%s\": Bad mode", mode);
+                break;
+        }
+        return (m);
 }
 
 TIFF*
 TIFFClientOpen(
-	const char* name, const char* mode,
-	thandle_t clientdata,
-	TIFFReadWriteProc readproc,
-	TIFFReadWriteProc writeproc,
-	TIFFSeekProc seekproc,
-	TIFFCloseProc closeproc,
-	TIFFSizeProc sizeproc,
-	TIFFMapFileProc mapproc,
-	TIFFUnmapFileProc unmapproc
+        const char* name, const char* mode,
+        thandle_t clientdata,
+        TIFFReadWriteProc readproc,
+        TIFFReadWriteProc writeproc,
+        TIFFSeekProc seekproc,
+        TIFFCloseProc closeproc,
+        TIFFSizeProc sizeproc,
+        TIFFMapFileProc mapproc,
+        TIFFUnmapFileProc unmapproc
 )
 {
-	static const char module[] = "TIFFClientOpen";
-	TIFF *tif;
-	int m, bigendian;
+        static const char module[] = "TIFFClientOpen";
+        TIFF *tif;
+        int m, bigendian;
 
-	m = _TIFFgetMode(mode, module);
-	if (m == -1)
-		goto bad2;
-	tif = (TIFF *)_TIFFmalloc(sizeof (TIFF) + strlen(name) + 1);
-	if (tif == NULL) {
-		TIFFError(module, "%s: Out of memory (TIFF structure)", name);
-		goto bad2;
-	}
-	memset(tif, 0, sizeof (*tif));
-	tif->tif_name = (char *)tif + sizeof (TIFF);
-	strcpy(tif->tif_name, name);
-	tif->tif_mode = m &~ (O_CREAT|O_TRUNC);
-	tif->tif_curdir = -1;		/* non-existent directory */
-	tif->tif_curoff = 0;
-	tif->tif_curstrip = -1;		/* invalid strip */
-	tif->tif_row = -1;		/* read/write pre-increment */
-	tif->tif_clientdata = clientdata;
-	tif->tif_readproc = readproc;
-	tif->tif_writeproc = writeproc;
-	tif->tif_seekproc = seekproc;
-	tif->tif_closeproc = closeproc;
-	tif->tif_sizeproc = sizeproc;
-	tif->tif_mapproc = mapproc;
-	tif->tif_unmapproc = unmapproc;
+        m = _TIFFgetMode(mode, module);
+        if (m == -1)
+                goto bad2;
+        tif = (TIFF *)_TIFFmalloc(sizeof (TIFF) + strlen(name) + 1);
+        if (tif == NULL) {
+                TIFFError(module, "%s: Out of memory (TIFF structure)", name);
+                goto bad2;
+        }
+        memset(tif, 0, sizeof (*tif));
+        tif->tif_name = (char *)tif + sizeof (TIFF);
+        strcpy(tif->tif_name, name);
+        tif->tif_mode = m &~ (O_CREAT|O_TRUNC);
+        tif->tif_curdir = -1;           /* non-existent directory */
+        tif->tif_curoff = 0;
+        tif->tif_curstrip = -1;         /* invalid strip */
+        tif->tif_row = -1;              /* read/write pre-increment */
+        tif->tif_clientdata = clientdata;
+        tif->tif_readproc = readproc;
+        tif->tif_writeproc = writeproc;
+        tif->tif_seekproc = seekproc;
+        tif->tif_closeproc = closeproc;
+        tif->tif_sizeproc = sizeproc;
+        tif->tif_mapproc = mapproc;
+        tif->tif_unmapproc = unmapproc;
 
-	{ int one = 1; char* cp = (char*)&one; bigendian = (*cp == 0); }
-	/*
-	 * Read in TIFF header.
-	 */
-	if (!ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
-		if (tif->tif_mode == O_RDONLY) {
-			TIFFError(name, "Cannot read TIFF header");
-			goto bad;
-		}
-		/*
-		 * Setup header and write.
-		 */
-		tif->tif_header.tiff_magic =  bigendian ?
-		    TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
-		tif->tif_header.tiff_version = TIFF_VERSION;
-		tif->tif_header.tiff_diroff = 0;	/* filled in later */
-		if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
-			TIFFError(name, "Error writing TIFF header");
-			goto bad;
-		}
-		/*
-		 * Setup the byte order handling.
-		 */
-		TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
-		/*
-		 * Setup default directory.
-		 */
-		if (!TIFFDefaultDirectory(tif))
-			goto bad;
-		tif->tif_diroff = 0;
-		return (tif);
-	}
-	/*
-	 * Setup the byte order handling.
-	 */
-	if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
-	    tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN) {
-		TIFFError(name,  "Not a TIFF file, bad magic number %d (0x%x)",
-		    tif->tif_header.tiff_magic,
-		    tif->tif_header.tiff_magic);
-		goto bad;
-	}
-	TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
-	/*
-	 * Swap header if required.
-	 */
-	if (tif->tif_flags & TIFF_SWAB) {
-		TIFFSwabShort(&tif->tif_header.tiff_version);
-		TIFFSwabLong(&tif->tif_header.tiff_diroff);
-	}
-	/*
-	 * Now check version (if needed, it's been byte-swapped).
-	 * Note that this isn't actually a version number, it's a
-	 * magic number that doesn't change (stupid).
-	 */
-	if (tif->tif_header.tiff_version != TIFF_VERSION) {
-		TIFFError(name,
-		    "Not a TIFF file, bad version number %d (0x%x)",
-		    tif->tif_header.tiff_version,
-		    tif->tif_header.tiff_version); 
-		goto bad;
-	}
-	tif->tif_flags |= TIFF_MYBUFFER;
-	tif->tif_rawcp = tif->tif_rawdata = 0;
-	tif->tif_rawdatasize = 0;
-	/*
-	 * Setup initial directory.
-	 */
-	switch (mode[0]) {
-	case 'r':
-		tif->tif_nextdiroff = tif->tif_header.tiff_diroff;
-		if (TIFFMapFileContents(tif, (tdata_t*) &tif->tif_base, &tif->tif_size))
-			tif->tif_flags |= TIFF_MAPPED;
-		if (TIFFReadDirectory(tif)) {
-			tif->tif_rawcc = -1;
-			tif->tif_flags |= TIFF_BUFFERSETUP;
-			return (tif);
-		}
-		break;
-	case 'a':
-		/*
-		 * Don't append to file that has information
-		 * byte swapped -- we will write data that is
-		 * in the opposite order.
-		 */
-		if (tif->tif_flags & TIFF_SWAB) {
-			TIFFError(name,
-		"Cannot append to file that has opposite byte ordering");
-			goto bad;
-		}
-		/*
-		 * New directories are automatically append
-		 * to the end of the directory chain when they
-		 * are written out (see TIFFWriteDirectory).
-		 */
-		if (!TIFFDefaultDirectory(tif))
-			goto bad;
-		return (tif);
-	}
+        { int one = 1; char* cp = (char*)&one; bigendian = (*cp == 0); }
+        /*
+         * Read in TIFF header.
+         */
+        if (!ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
+                if (tif->tif_mode == O_RDONLY) {
+                        TIFFError(name, "Cannot read TIFF header");
+                        goto bad;
+                }
+                /*
+                 * Setup header and write.
+                 */
+                tif->tif_header.tiff_magic =  bigendian ?
+                    TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
+                tif->tif_header.tiff_version = TIFF_VERSION;
+                tif->tif_header.tiff_diroff = 0;        /* filled in later */
+                if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
+                        TIFFError(name, "Error writing TIFF header");
+                        goto bad;
+                }
+                /*
+                 * Setup the byte order handling.
+                 */
+                TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
+                /*
+                 * Setup default directory.
+                 */
+                if (!TIFFDefaultDirectory(tif))
+                        goto bad;
+                tif->tif_diroff = 0;
+                return (tif);
+        }
+        /*
+         * Setup the byte order handling.
+         */
+        if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
+            tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN) {
+                TIFFError(name,  "Not a TIFF file, bad magic number %d (0x%x)",
+                    tif->tif_header.tiff_magic,
+                    tif->tif_header.tiff_magic);
+                goto bad;
+        }
+        TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
+        /*
+         * Swap header if required.
+         */
+        if (tif->tif_flags & TIFF_SWAB) {
+                TIFFSwabShort(&tif->tif_header.tiff_version);
+                TIFFSwabLong(&tif->tif_header.tiff_diroff);
+        }
+        /*
+         * Now check version (if needed, it's been byte-swapped).
+         * Note that this isn't actually a version number, it's a
+         * magic number that doesn't change (stupid).
+         */
+        if (tif->tif_header.tiff_version != TIFF_VERSION) {
+                TIFFError(name,
+                    "Not a TIFF file, bad version number %d (0x%x)",
+                    tif->tif_header.tiff_version,
+                    tif->tif_header.tiff_version); 
+                goto bad;
+        }
+        tif->tif_flags |= TIFF_MYBUFFER;
+        tif->tif_rawcp = tif->tif_rawdata = 0;
+        tif->tif_rawdatasize = 0;
+        /*
+         * Setup initial directory.
+         */
+        switch (mode[0]) {
+        case 'r':
+                tif->tif_nextdiroff = tif->tif_header.tiff_diroff;
+                if (TIFFMapFileContents(tif, (tdata_t*) &tif->tif_base, &tif->tif_size))
+                        tif->tif_flags |= TIFF_MAPPED;
+                if (TIFFReadDirectory(tif)) {
+                        tif->tif_rawcc = -1;
+                        tif->tif_flags |= TIFF_BUFFERSETUP;
+                        return (tif);
+                }
+                break;
+        case 'a':
+                /*
+                 * Don't append to file that has information
+                 * byte swapped -- we will write data that is
+                 * in the opposite order.
+                 */
+                if (tif->tif_flags & TIFF_SWAB) {
+                        TIFFError(name,
+                "Cannot append to file that has opposite byte ordering");
+                        goto bad;
+                }
+                /*
+                 * New directories are automatically append
+                 * to the end of the directory chain when they
+                 * are written out (see TIFFWriteDirectory).
+                 */
+                if (!TIFFDefaultDirectory(tif))
+                        goto bad;
+                return (tif);
+        }
 bad:
-	tif->tif_mode = O_RDONLY;	/* XXX avoid flush */
-	TIFFClose(tif);
-	return ((TIFF*)0);
+        tif->tif_mode = O_RDONLY;       /* XXX avoid flush */
+        TIFFClose(tif);
+        return ((TIFF*)0);
 bad2:
-	(void) (*closeproc)(clientdata);
-	return ((TIFF*)0);
+        (void) (*closeproc)(clientdata);
+        return ((TIFF*)0);
 }
 
 tsize_t
 TIFFScanlineSize(TIFF* tif)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t scanline;
-	
-	scanline = td->td_bitspersample * td->td_imagewidth;
-	if (td->td_planarconfig == PLANARCONFIG_CONTIG)
-		scanline *= td->td_samplesperpixel;
-	return (howmany(scanline, 8));
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t scanline;
+
+        scanline = td->td_bitspersample * td->td_imagewidth;
+        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
+                scanline *= td->td_samplesperpixel;
+        return (howmany(scanline, 8));
 }
 
 /*
@@ -297,7 +297,7 @@ TIFFScanlineSize(TIFF* tif)
 const char *
 TIFFFileName(TIFF* tif)
 {
-	return (tif->tif_name);
+        return (tif->tif_name);
 }
 
 /*
@@ -306,7 +306,7 @@ TIFFFileName(TIFF* tif)
 int
 TIFFFileno(TIFF* tif)
 {
-	return (tif->tif_fd);
+        return (tif->tif_fd);
 }
 
 /*
@@ -315,7 +315,7 @@ TIFFFileno(TIFF* tif)
 int
 TIFFGetMode(TIFF* tif)
 {
-	return (tif->tif_mode);
+        return (tif->tif_mode);
 }
 
 /*
@@ -325,7 +325,7 @@ TIFFGetMode(TIFF* tif)
 int
 TIFFIsTiled(TIFF* tif)
 {
-	return (isTiled(tif));
+        return (isTiled(tif));
 }
 
 /*
@@ -334,7 +334,7 @@ TIFFIsTiled(TIFF* tif)
 uint32
 TIFFCurrentRow(TIFF* tif)
 {
-	return (tif->tif_row);
+        return (tif->tif_row);
 }
 
 /*
@@ -343,7 +343,7 @@ TIFFCurrentRow(TIFF* tif)
 tdir_t
 TIFFCurrentDirectory(TIFF* tif)
 {
-	return (tif->tif_curdir);
+        return (tif->tif_curdir);
 }
 
 /*
@@ -352,7 +352,7 @@ TIFFCurrentDirectory(TIFF* tif)
 tstrip_t
 TIFFCurrentStrip(TIFF* tif)
 {
-	return (tif->tif_curstrip);
+        return (tif->tif_curstrip);
 }
 
 /*
@@ -361,7 +361,7 @@ TIFFCurrentStrip(TIFF* tif)
 ttile_t
 TIFFCurrentTile(TIFF* tif)
 {
-	return (tif->tif_curtile);
+        return (tif->tif_curtile);
 }
 
 /*
@@ -370,5 +370,5 @@ TIFFCurrentTile(TIFF* tif)
 int
 TIFFIsByteSwapped(TIFF* tif)
 {
-	return ((tif->tif_flags & TIFF_SWAB) != 0);
+        return ((tif->tif_flags & TIFF_SWAB) != 0);
 }

+ 174 - 174
panda/src/tiff/tif_packbits.c

@@ -39,14 +39,14 @@ static char rcsid[] = "$Header$";
 static int
 PackBitsPreEncode(TIFF* tif)
 {
-	/*
-	 * Calculate the scanline/tile-width size in bytes.
-	 */
-	if (isTiled(tif))
-		tif->tif_data = (tidata_t) TIFFTileRowSize(tif);
-	else
-		tif->tif_data = (tidata_t) TIFFScanlineSize(tif);
-	return (1);
+        /*
+         * Calculate the scanline/tile-width size in bytes.
+         */
+        if (isTiled(tif))
+                tif->tif_data = (tidata_t) TIFFTileRowSize(tif);
+        else
+                tif->tif_data = (tidata_t) TIFFScanlineSize(tif);
+        return (1);
 }
 
 /*
@@ -55,119 +55,119 @@ PackBitsPreEncode(TIFF* tif)
 static int
 PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
-	u_char* bp = (u_char*) buf;
-	tidata_t op, ep, lastliteral;
-	long n, slop;
-	int b;
-	enum { BASE, LITERAL, RUN, LITERAL_RUN } state;
+        u_char* bp = (u_char*) buf;
+        tidata_t op, ep, lastliteral;
+        long n, slop;
+        int b;
+        enum { BASE, LITERAL, RUN, LITERAL_RUN } state;
 
-	op = tif->tif_rawcp;
-	ep = tif->tif_rawdata + tif->tif_rawdatasize;
-	state = BASE;
-	lastliteral = 0;
-	while (cc > 0) {
-		/*
-		 * Find the longest string of identical bytes.
-		 */
-		b = *bp++, cc--, n = 1;
-		for (; cc > 0 && b == *bp; cc--, bp++)
-			n++;
-	again:
-		if (op + 2 >= ep) {		/* insure space for new data */
-			/*
-			 * Be careful about writing the last
-			 * literal.  Must write up to that point
-			 * and then copy the remainder to the
-			 * front of the buffer.
-			 */
-			if (state == LITERAL || state == LITERAL_RUN) {
-				slop = op - lastliteral;
-				tif->tif_rawcc += lastliteral - tif->tif_rawcp;
-				if (!TIFFFlushData1(tif))
-					return (-1);
-				op = tif->tif_rawcp;
-				while (slop-- > 0)
-					*op++ = *lastliteral++;
-				lastliteral = tif->tif_rawcp;
-			} else {
-				tif->tif_rawcc += op - tif->tif_rawcp;
-				if (!TIFFFlushData1(tif))
-					return (-1);
-				op = tif->tif_rawcp;
-			}
-		}
-		switch (state) {
-		case BASE:		/* initial state, set run/literal */
-			if (n > 1) {
-				state = RUN;
-				if (n > 128) {
-					*op++ = -127;
-					*op++ = b;
-					n -= 128;
-					goto again;
-				}
-				*op++ = -(n-1);
-				*op++ = b;
-			} else {
-				lastliteral = op;
-				*op++ = 0;
-				*op++ = b;
-				state = LITERAL;
-			}
-			break;
-		case LITERAL:		/* last object was literal string */
-			if (n > 1) {
-				state = LITERAL_RUN;
-				if (n > 128) {
-					*op++ = -127;
-					*op++ = b;
-					n -= 128;
-					goto again;
-				}
-				*op++ = -(n-1);		/* encode run */
-				*op++ = b;
-			} else {			/* extend literal */
-				if (++(*lastliteral) == 127)
-					state = BASE;
-				*op++ = b;
-			}
-			break;
-		case RUN:		/* last object was run */
-			if (n > 1) {
-				if (n > 128) {
-					*op++ = -127;
-					*op++ = b;
-					n -= 128;
-					goto again;
-				}
-				*op++ = -(n-1);
-				*op++ = b;
-			} else {
-				lastliteral = op;
-				*op++ = 0;
-				*op++ = b;
-				state = LITERAL;
-			}
-			break;
-		case LITERAL_RUN:	/* literal followed by a run */
-			/*
-			 * Check to see if previous run should
-			 * be converted to a literal, in which
-			 * case we convert literal-run-literal
-			 * to a single literal.
-			 */
-			if (n == 1 && -op[-2] == 1 && *lastliteral < 126) {
-				state = (((*lastliteral) += 2) == 127 ?
-				    BASE : LITERAL);
-				op[-2] = op[-1];	/* replicate */
-			} else
-				state = RUN;
-			goto again;
-		}
-	}
-	tif->tif_rawcc += op - tif->tif_rawcp;
-	tif->tif_rawcp = op;
-	return (1);
+        op = tif->tif_rawcp;
+        ep = tif->tif_rawdata + tif->tif_rawdatasize;
+        state = BASE;
+        lastliteral = 0;
+        while (cc > 0) {
+                /*
+                 * Find the longest string of identical bytes.
+                 */
+                b = *bp++, cc--, n = 1;
+                for (; cc > 0 && b == *bp; cc--, bp++)
+                        n++;
+        again:
+                if (op + 2 >= ep) {             /* insure space for new data */
+                        /*
+                         * Be careful about writing the last
+                         * literal.  Must write up to that point
+                         * and then copy the remainder to the
+                         * front of the buffer.
+                         */
+                        if (state == LITERAL || state == LITERAL_RUN) {
+                                slop = op - lastliteral;
+                                tif->tif_rawcc += lastliteral - tif->tif_rawcp;
+                                if (!TIFFFlushData1(tif))
+                                        return (-1);
+                                op = tif->tif_rawcp;
+                                while (slop-- > 0)
+                                        *op++ = *lastliteral++;
+                                lastliteral = tif->tif_rawcp;
+                        } else {
+                                tif->tif_rawcc += op - tif->tif_rawcp;
+                                if (!TIFFFlushData1(tif))
+                                        return (-1);
+                                op = tif->tif_rawcp;
+                        }
+                }
+                switch (state) {
+                case BASE:              /* initial state, set run/literal */
+                        if (n > 1) {
+                                state = RUN;
+                                if (n > 128) {
+                                        *op++ = -127;
+                                        *op++ = b;
+                                        n -= 128;
+                                        goto again;
+                                }
+                                *op++ = -(n-1);
+                                *op++ = b;
+                        } else {
+                                lastliteral = op;
+                                *op++ = 0;
+                                *op++ = b;
+                                state = LITERAL;
+                        }
+                        break;
+                case LITERAL:           /* last object was literal string */
+                        if (n > 1) {
+                                state = LITERAL_RUN;
+                                if (n > 128) {
+                                        *op++ = -127;
+                                        *op++ = b;
+                                        n -= 128;
+                                        goto again;
+                                }
+                                *op++ = -(n-1);         /* encode run */
+                                *op++ = b;
+                        } else {                        /* extend literal */
+                                if (++(*lastliteral) == 127)
+                                        state = BASE;
+                                *op++ = b;
+                        }
+                        break;
+                case RUN:               /* last object was run */
+                        if (n > 1) {
+                                if (n > 128) {
+                                        *op++ = -127;
+                                        *op++ = b;
+                                        n -= 128;
+                                        goto again;
+                                }
+                                *op++ = -(n-1);
+                                *op++ = b;
+                        } else {
+                                lastliteral = op;
+                                *op++ = 0;
+                                *op++ = b;
+                                state = LITERAL;
+                        }
+                        break;
+                case LITERAL_RUN:       /* literal followed by a run */
+                        /*
+                         * Check to see if previous run should
+                         * be converted to a literal, in which
+                         * case we convert literal-run-literal
+                         * to a single literal.
+                         */
+                        if (n == 1 && -op[-2] == 1 && *lastliteral < 126) {
+                                state = (((*lastliteral) += 2) == 127 ?
+                                    BASE : LITERAL);
+                                op[-2] = op[-1];        /* replicate */
+                        } else
+                                state = RUN;
+                        goto again;
+                }
+        }
+        tif->tif_rawcc += op - tif->tif_rawcp;
+        tif->tif_rawcp = op;
+        return (1);
 }
 
 /*
@@ -180,70 +180,70 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 static int
 PackBitsEncodeChunk(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
-	tsize_t rowsize = (tsize_t) tif->tif_data;
+        tsize_t rowsize = (tsize_t) tif->tif_data;
 
-	assert(rowsize > 0);
-	while ((long)cc > 0) {
-		if (PackBitsEncode(tif, bp, rowsize, s) < 0)
-			return (-1);
-		bp += rowsize;
-		cc -= rowsize;
-	}
-	return (1);
+        assert(rowsize > 0);
+        while ((long)cc > 0) {
+                if (PackBitsEncode(tif, bp, rowsize, s) < 0)
+                        return (-1);
+                bp += rowsize;
+                cc -= rowsize;
+        }
+        return (1);
 }
 
 static int
 PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
-	char *bp;
-	tsize_t cc;
+        char *bp;
+        tsize_t cc;
 
-	bp = (char*) tif->tif_rawcp;
-	cc = tif->tif_rawcc;
-	while (cc > 0 && (long)occ > 0) {
-		long n = (long) *bp++;
-		int b;
-		/*
-		 * Watch out for compilers that
-		 * don't sign extend chars...
-		 */
-		if (n >= 128)
-			n -= 256;
-		if (n < 0) {		/* replicate next byte -n+1 times */
-			cc--;
-			if (n == -128)	/* nop */
-				continue;
-			n = -n + 1;
-			occ -= n;
-			for (b = *bp++; n-- > 0;)
-				*op++ = b;
-		} else {		/* copy next n+1 bytes literally */
-			memcpy(op, bp, ++n);
-			op += n; occ -= n;
-			bp += n; cc -= n;
-		}
-	}
-	tif->tif_rawcp = (tidata_t) bp;
-	tif->tif_rawcc = cc;
-	if (occ > 0) {
-		TIFFError(tif->tif_name,
-		    "PackBitsDecode: Not enough data for scanline %ld",
-		    (long) tif->tif_row);
-		return (0);
-	}
-	/* check for buffer overruns? */
-	return (1);
+        bp = (char*) tif->tif_rawcp;
+        cc = tif->tif_rawcc;
+        while (cc > 0 && (long)occ > 0) {
+                long n = (long) *bp++;
+                int b;
+                /*
+                 * Watch out for compilers that
+                 * don't sign extend chars...
+                 */
+                if (n >= 128)
+                        n -= 256;
+                if (n < 0) {            /* replicate next byte -n+1 times */
+                        cc--;
+                        if (n == -128)  /* nop */
+                                continue;
+                        n = -n + 1;
+                        occ -= n;
+                        for (b = *bp++; n-- > 0;)
+                                *op++ = b;
+                } else {                /* copy next n+1 bytes literally */
+                        memcpy(op, bp, ++n);
+                        op += n; occ -= n;
+                        bp += n; cc -= n;
+                }
+        }
+        tif->tif_rawcp = (tidata_t) bp;
+        tif->tif_rawcc = cc;
+        if (occ > 0) {
+                TIFFError(tif->tif_name,
+                    "PackBitsDecode: Not enough data for scanline %ld",
+                    (long) tif->tif_row);
+                return (0);
+        }
+        /* check for buffer overruns? */
+        return (1);
 }
 
 int
 TIFFInitPackBits(TIFF* tif)
 {
-	tif->tif_decoderow = PackBitsDecode;
-	tif->tif_decodestrip = PackBitsDecode;
-	tif->tif_decodetile = PackBitsDecode;
-	tif->tif_preencode = PackBitsPreEncode;
-	tif->tif_encoderow = PackBitsEncode;
-	tif->tif_encodestrip = PackBitsEncodeChunk;
-	tif->tif_encodetile = PackBitsEncodeChunk;
-	return (1);
+        tif->tif_decoderow = PackBitsDecode;
+        tif->tif_decodestrip = PackBitsDecode;
+        tif->tif_decodetile = PackBitsDecode;
+        tif->tif_preencode = PackBitsPreEncode;
+        tif->tif_encoderow = PackBitsEncode;
+        tif->tif_encodestrip = PackBitsEncodeChunk;
+        tif->tif_encodetile = PackBitsEncodeChunk;
+        return (1);
 }

+ 514 - 514
panda/src/tiff/tif_print.c

@@ -38,73 +38,73 @@ static char rcsid[] = "$Header$";
 static void
 JPEGPrintQTable(FILE* fd, u_char* tab)
 {
-	int i, j;
-	char *sep;
+        int i, j;
+        char *sep;
 
-	fputc('\n', fd);
-	for (i = 0; i < 8; i++) {
-		sep = "    ";
-		for (j = 0; j < 8; j++) {
-			fprintf(fd, "%s%2u", sep, tab[8*i+j]);
-			sep = ", ";
-		}
-		fputc('\n', fd);
-	}
+        fputc('\n', fd);
+        for (i = 0; i < 8; i++) {
+                sep = "    ";
+                for (j = 0; j < 8; j++) {
+                        fprintf(fd, "%s%2u", sep, tab[8*i+j]);
+                        sep = ", ";
+                }
+                fputc('\n', fd);
+        }
 }
 
 static void
 JPEGPrintCTable(FILE* fd, u_char* tab)
 {
-	int i, n, count;
-	char *sep;
+        int i, n, count;
+        char *sep;
 
-	fprintf(fd, "\n    Bits:");
-	count = 0;
-	for (i = 0; i < 16; i++) {
-		fprintf(fd, " %u", tab[i]);
-		count += tab[i];
-	}
-	n = 0;
-	for (; count > 0; count--) {
-		if ((n % 8) == 0) {
-			fputc('\n', fd);
-			sep = "    ";
-		}
-		fprintf(fd, "%s0x%02x", sep, tab[i++]);
-		sep = ", ";
-		n++;
+        fprintf(fd, "\n    Bits:");
+        count = 0;
+        for (i = 0; i < 16; i++) {
+                fprintf(fd, " %u", tab[i]);
+                count += tab[i];
+        }
+        n = 0;
+        for (; count > 0; count--) {
+                if ((n % 8) == 0) {
+                        fputc('\n', fd);
+                        sep = "    ";
+                }
+                fprintf(fd, "%s0x%02x", sep, tab[i++]);
+                sep = ", ";
+                n++;
 
-	}
-	if (n % 8)
-		fputc('\n', fd);
+        }
+        if (n % 8)
+                fputc('\n', fd);
 }
 #endif
 
 static const char *photoNames[] = {
-    "min-is-white",				/* PHOTOMETRIC_MINISWHITE */
-    "min-is-black",				/* PHOTOMETRIC_MINISBLACK */
-    "RGB color",				/* PHOTOMETRIC_RGB */
-    "palette color (RGB from colormap)",	/* PHOTOMETRIC_PALETTE */
-    "transparency mask",			/* PHOTOMETRIC_MASK */
-    "separated",				/* PHOTOMETRIC_SEPARATED */
-    "YCbCr",					/* PHOTOMETRIC_YCBCR */
+    "min-is-white",                             /* PHOTOMETRIC_MINISWHITE */
+    "min-is-black",                             /* PHOTOMETRIC_MINISBLACK */
+    "RGB color",                                /* PHOTOMETRIC_RGB */
+    "palette color (RGB from colormap)",        /* PHOTOMETRIC_PALETTE */
+    "transparency mask",                        /* PHOTOMETRIC_MASK */
+    "separated",                                /* PHOTOMETRIC_SEPARATED */
+    "YCbCr",                                    /* PHOTOMETRIC_YCBCR */
     "7 (0x7)",
-    "CIE L*a*b*",				/* PHOTOMETRIC_CIELAB */
+    "CIE L*a*b*",                               /* PHOTOMETRIC_CIELAB */
 };
-#define	NPHOTONAMES	(sizeof (photoNames) / sizeof (photoNames[0]))
+#define NPHOTONAMES     (sizeof (photoNames) / sizeof (photoNames[0]))
 
 static const char *orientNames[] = {
     "0 (0x0)",
-    "row 0 top, col 0 lhs",			/* ORIENTATION_TOPLEFT */
-    "row 0 top, col 0 rhs",			/* ORIENTATION_TOPRIGHT */
-    "row 0 bottom, col 0 rhs",			/* ORIENTATION_BOTRIGHT */
-    "row 0 bottom, col 0 lhs",			/* ORIENTATION_BOTLEFT */
-    "row 0 lhs, col 0 top",			/* ORIENTATION_LEFTTOP */
-    "row 0 rhs, col 0 top",			/* ORIENTATION_RIGHTTOP */
-    "row 0 rhs, col 0 bottom",			/* ORIENTATION_RIGHTBOT */
-    "row 0 lhs, col 0 bottom",			/* ORIENTATION_LEFTBOT */
+    "row 0 top, col 0 lhs",                     /* ORIENTATION_TOPLEFT */
+    "row 0 top, col 0 rhs",                     /* ORIENTATION_TOPRIGHT */
+    "row 0 bottom, col 0 rhs",                  /* ORIENTATION_BOTRIGHT */
+    "row 0 bottom, col 0 lhs",                  /* ORIENTATION_BOTLEFT */
+    "row 0 lhs, col 0 top",                     /* ORIENTATION_LEFTTOP */
+    "row 0 rhs, col 0 top",                     /* ORIENTATION_RIGHTTOP */
+    "row 0 rhs, col 0 bottom",                  /* ORIENTATION_RIGHTBOT */
+    "row 0 lhs, col 0 bottom",                  /* ORIENTATION_LEFTBOT */
 };
-#define	NORIENTNAMES	(sizeof (orientNames) / sizeof (orientNames[0]))
+#define NORIENTNAMES    (sizeof (orientNames) / sizeof (orientNames[0]))
 
 /*
  * Print the contents of the current directory
@@ -113,478 +113,478 @@ static const char *orientNames[] = {
 void
 TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
 {
-	register TIFFDirectory *td;
-	char *sep;
-	int i, j;
-	long n;
+        register TIFFDirectory *td;
+        char *sep;
+        int i, j;
+        long n;
 
-	fprintf(fd, "TIFF Directory at offset 0x%x\n", tif->tif_diroff);
-	td = &tif->tif_dir;
-	if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
-		fprintf(fd, "  Subfile Type:");
-		sep = " ";
-		if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
-			fprintf(fd, "%sreduced-resolution image", sep);
-			sep = "/";
-		}
-		if (td->td_subfiletype & FILETYPE_PAGE) {
-			fprintf(fd, "%smulti-page document", sep);
-			sep = "/";
-		}
-		if (td->td_subfiletype & FILETYPE_MASK)
-			fprintf(fd, "%stransparency mask", sep);
-		fprintf(fd, " (%u = 0x%x)\n",
-		    td->td_subfiletype, td->td_subfiletype);
-	}
-	if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
-		fprintf(fd, "  Image Width: %lu Image Length: %lu",
-		    (u_long) td->td_imagewidth, (u_long) td->td_imagelength);
-		if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
-			fprintf(fd, " Image Depth: %lu",
-			    (u_long) td->td_imagedepth);
-		fprintf(fd, "\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
-		fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
-		    (u_long) td->td_tilewidth, (u_long) td->td_tilelength);
-		if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
-			fprintf(fd, " Tile Depth: %lu",
-			    (u_long) td->td_tiledepth);
-		fprintf(fd, "\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
-		fprintf(fd, "  Resolution: %g, %g",
-		    td->td_xresolution, td->td_yresolution);
-		if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
-			switch (td->td_resolutionunit) {
-			case RESUNIT_NONE:
-				fprintf(fd, " (unitless)");
-				break;
-			case RESUNIT_INCH:
-				fprintf(fd, " pixels/inch");
-				break;
-			case RESUNIT_CENTIMETER:
-				fprintf(fd, " pixels/cm");
-				break;
-			default:
-				fprintf(fd, " (unit %u = 0x%x)",
-				    td->td_resolutionunit,
-				    td->td_resolutionunit);
-				break;
-			}
-		}
-		fprintf(fd, "\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_POSITION))
-		fprintf(fd, "  Position: %g, %g\n",
-		    td->td_xposition, td->td_yposition);
-	if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
-		fprintf(fd, "  Bits/Sample: %u\n", td->td_bitspersample);
-	if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
-		fprintf(fd, "  Sample Format: ");
-		switch (td->td_sampleformat) {
-		case SAMPLEFORMAT_VOID:
-			fprintf(fd, "void\n");
-			break;
-		case SAMPLEFORMAT_INT:
-			fprintf(fd, "signed integer\n");
-			break;
-		case SAMPLEFORMAT_UINT:
-			fprintf(fd, "unsigned integer\n");
-			break;
-		case SAMPLEFORMAT_IEEEFP:
-			fprintf(fd, "IEEE floating point\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_sampleformat, td->td_sampleformat);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
-		fprintf(fd, "  Compression Scheme: ");
-		switch (td->td_compression) {
-		case COMPRESSION_NONE:
-			fprintf(fd, "none\n");
-			break;
-		case COMPRESSION_CCITTRLE:
-			fprintf(fd, "CCITT modified Huffman encoding\n");
-			break;
-		case COMPRESSION_CCITTFAX3:
-			fprintf(fd, "CCITT Group 3 facsimile encoding\n");
-			break;
-		case COMPRESSION_CCITTFAX4:
-			fprintf(fd, "CCITT Group 4 facsimile encoding\n");
-			break;
-		case COMPRESSION_CCITTRLEW:
-			fprintf(fd, "CCITT modified Huffman encoding %s\n",
-			    "w/ word alignment");
-			break;
-		case COMPRESSION_PACKBITS:
-			fprintf(fd, "Macintosh PackBits encoding\n");
-			break;
-		case COMPRESSION_THUNDERSCAN:
-			fprintf(fd, "ThunderScan 4-bit encoding\n");
-			break;
-		case COMPRESSION_LZW:
-			fprintf(fd, "Lempel-Ziv & Welch encoding\n");
-			break;
-		case COMPRESSION_NEXT:
-			fprintf(fd, "NeXT 2-bit encoding\n");
-			break;
-		case COMPRESSION_JPEG:
-			fprintf(fd, "JPEG encoding\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_compression, td->td_compression);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
-		fprintf(fd, "  Photometric Interpretation: ");
-		if (td->td_photometric < NPHOTONAMES)
-			fprintf(fd, "%s\n", photoNames[td->td_photometric]);
-		else
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_photometric, td->td_photometric);
-	}
-	if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
-		fprintf(fd, "  Extra Samples: %u<", td->td_extrasamples);
-		sep = "";
-		for (i = 0; i < td->td_extrasamples; i++) {
-			switch (td->td_sampleinfo[i]) {
-			case EXTRASAMPLE_UNSPECIFIED:
-				fprintf(fd, "%sunspecified", sep);
-				break;
-			case EXTRASAMPLE_ASSOCALPHA:
-				fprintf(fd, "%sassoc-alpha", sep);
-				break;
-			case EXTRASAMPLE_UNASSALPHA:
-				fprintf(fd, "%sunassoc-alpha", sep);
-				break;
-			default:
-				fprintf(fd, "%s%u (0x%x)", sep,
-				    td->td_sampleinfo[i], td->td_sampleinfo[i]);
-				break;
-			}
-			sep = ", ";
-		}
-		fprintf(fd, ">\n");
-	}
+        fprintf(fd, "TIFF Directory at offset 0x%x\n", tif->tif_diroff);
+        td = &tif->tif_dir;
+        if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
+                fprintf(fd, "  Subfile Type:");
+                sep = " ";
+                if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
+                        fprintf(fd, "%sreduced-resolution image", sep);
+                        sep = "/";
+                }
+                if (td->td_subfiletype & FILETYPE_PAGE) {
+                        fprintf(fd, "%smulti-page document", sep);
+                        sep = "/";
+                }
+                if (td->td_subfiletype & FILETYPE_MASK)
+                        fprintf(fd, "%stransparency mask", sep);
+                fprintf(fd, " (%u = 0x%x)\n",
+                    td->td_subfiletype, td->td_subfiletype);
+        }
+        if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
+                fprintf(fd, "  Image Width: %lu Image Length: %lu",
+                    (u_long) td->td_imagewidth, (u_long) td->td_imagelength);
+                if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
+                        fprintf(fd, " Image Depth: %lu",
+                            (u_long) td->td_imagedepth);
+                fprintf(fd, "\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
+                fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
+                    (u_long) td->td_tilewidth, (u_long) td->td_tilelength);
+                if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
+                        fprintf(fd, " Tile Depth: %lu",
+                            (u_long) td->td_tiledepth);
+                fprintf(fd, "\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
+                fprintf(fd, "  Resolution: %g, %g",
+                    td->td_xresolution, td->td_yresolution);
+                if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
+                        switch (td->td_resolutionunit) {
+                        case RESUNIT_NONE:
+                                fprintf(fd, " (unitless)");
+                                break;
+                        case RESUNIT_INCH:
+                                fprintf(fd, " pixels/inch");
+                                break;
+                        case RESUNIT_CENTIMETER:
+                                fprintf(fd, " pixels/cm");
+                                break;
+                        default:
+                                fprintf(fd, " (unit %u = 0x%x)",
+                                    td->td_resolutionunit,
+                                    td->td_resolutionunit);
+                                break;
+                        }
+                }
+                fprintf(fd, "\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_POSITION))
+                fprintf(fd, "  Position: %g, %g\n",
+                    td->td_xposition, td->td_yposition);
+        if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
+                fprintf(fd, "  Bits/Sample: %u\n", td->td_bitspersample);
+        if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
+                fprintf(fd, "  Sample Format: ");
+                switch (td->td_sampleformat) {
+                case SAMPLEFORMAT_VOID:
+                        fprintf(fd, "void\n");
+                        break;
+                case SAMPLEFORMAT_INT:
+                        fprintf(fd, "signed integer\n");
+                        break;
+                case SAMPLEFORMAT_UINT:
+                        fprintf(fd, "unsigned integer\n");
+                        break;
+                case SAMPLEFORMAT_IEEEFP:
+                        fprintf(fd, "IEEE floating point\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_sampleformat, td->td_sampleformat);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
+                fprintf(fd, "  Compression Scheme: ");
+                switch (td->td_compression) {
+                case COMPRESSION_NONE:
+                        fprintf(fd, "none\n");
+                        break;
+                case COMPRESSION_CCITTRLE:
+                        fprintf(fd, "CCITT modified Huffman encoding\n");
+                        break;
+                case COMPRESSION_CCITTFAX3:
+                        fprintf(fd, "CCITT Group 3 facsimile encoding\n");
+                        break;
+                case COMPRESSION_CCITTFAX4:
+                        fprintf(fd, "CCITT Group 4 facsimile encoding\n");
+                        break;
+                case COMPRESSION_CCITTRLEW:
+                        fprintf(fd, "CCITT modified Huffman encoding %s\n",
+                            "w/ word alignment");
+                        break;
+                case COMPRESSION_PACKBITS:
+                        fprintf(fd, "Macintosh PackBits encoding\n");
+                        break;
+                case COMPRESSION_THUNDERSCAN:
+                        fprintf(fd, "ThunderScan 4-bit encoding\n");
+                        break;
+                case COMPRESSION_LZW:
+                        fprintf(fd, "Lempel-Ziv & Welch encoding\n");
+                        break;
+                case COMPRESSION_NEXT:
+                        fprintf(fd, "NeXT 2-bit encoding\n");
+                        break;
+                case COMPRESSION_JPEG:
+                        fprintf(fd, "JPEG encoding\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_compression, td->td_compression);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
+                fprintf(fd, "  Photometric Interpretation: ");
+                if (td->td_photometric < NPHOTONAMES)
+                        fprintf(fd, "%s\n", photoNames[td->td_photometric]);
+                else
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_photometric, td->td_photometric);
+        }
+        if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
+                fprintf(fd, "  Extra Samples: %u<", td->td_extrasamples);
+                sep = "";
+                for (i = 0; i < td->td_extrasamples; i++) {
+                        switch (td->td_sampleinfo[i]) {
+                        case EXTRASAMPLE_UNSPECIFIED:
+                                fprintf(fd, "%sunspecified", sep);
+                                break;
+                        case EXTRASAMPLE_ASSOCALPHA:
+                                fprintf(fd, "%sassoc-alpha", sep);
+                                break;
+                        case EXTRASAMPLE_UNASSALPHA:
+                                fprintf(fd, "%sunassoc-alpha", sep);
+                                break;
+                        default:
+                                fprintf(fd, "%s%u (0x%x)", sep,
+                                    td->td_sampleinfo[i], td->td_sampleinfo[i]);
+                                break;
+                        }
+                        sep = ", ";
+                }
+                fprintf(fd, ">\n");
+        }
 #ifdef CMYK_SUPPORT
-	if (TIFFFieldSet(tif,FIELD_INKSET)) {
-		fprintf(fd, "  Ink Set: ");
-		switch (td->td_inkset) {
-		case INKSET_CMYK:
-			fprintf(fd, "CMYK\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_inkset, td->td_inkset);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
-		char *cp;
-		fprintf(fd, "  Ink Names: ");
-		i = td->td_samplesperpixel;
-		sep = "";
-		for (cp = td->td_inknames; i > 0; cp = strchr(cp, '\0')) {
-			fprintf(fd, "%s%s", sep, cp);
-			sep = ", ";
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_DOTRANGE))
-		fprintf(fd, "  Dot Range: %u-%u\n",
-		    td->td_dotrange[0], td->td_dotrange[1]);
-	if (TIFFFieldSet(tif,FIELD_TARGETPRINTER))
-		fprintf(fd, "  Target Printer: %s\n", td->td_targetprinter);
+        if (TIFFFieldSet(tif,FIELD_INKSET)) {
+                fprintf(fd, "  Ink Set: ");
+                switch (td->td_inkset) {
+                case INKSET_CMYK:
+                        fprintf(fd, "CMYK\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_inkset, td->td_inkset);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
+                char *cp;
+                fprintf(fd, "  Ink Names: ");
+                i = td->td_samplesperpixel;
+                sep = "";
+                for (cp = td->td_inknames; i > 0; cp = strchr(cp, '\0')) {
+                        fprintf(fd, "%s%s", sep, cp);
+                        sep = ", ";
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_DOTRANGE))
+                fprintf(fd, "  Dot Range: %u-%u\n",
+                    td->td_dotrange[0], td->td_dotrange[1]);
+        if (TIFFFieldSet(tif,FIELD_TARGETPRINTER))
+                fprintf(fd, "  Target Printer: %s\n", td->td_targetprinter);
 #endif
-	if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
-		fprintf(fd, "  Thresholding: ");
-		switch (td->td_threshholding) {
-		case THRESHHOLD_BILEVEL:
-			fprintf(fd, "bilevel art scan\n");
-			break;
-		case THRESHHOLD_HALFTONE:
-			fprintf(fd, "halftone or dithered scan\n");
-			break;
-		case THRESHHOLD_ERRORDIFFUSE:
-			fprintf(fd, "error diffused\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_threshholding, td->td_threshholding);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
-		fprintf(fd, "  FillOrder: ");
-		switch (td->td_fillorder) {
-		case FILLORDER_MSB2LSB:
-			fprintf(fd, "msb-to-lsb\n");
-			break;
-		case FILLORDER_LSB2MSB:
-			fprintf(fd, "lsb-to-msb\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_fillorder, td->td_fillorder);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_PREDICTOR)) {
-		fprintf(fd, "  Predictor: ");
-		switch (td->td_predictor) {
-		case 1:
-			fprintf(fd, "none\n");
-			break;
-		case 2:
-			fprintf(fd, "horizontal differencing\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_predictor, td->td_predictor);
-			break;
-		}
-	}
+        if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
+                fprintf(fd, "  Thresholding: ");
+                switch (td->td_threshholding) {
+                case THRESHHOLD_BILEVEL:
+                        fprintf(fd, "bilevel art scan\n");
+                        break;
+                case THRESHHOLD_HALFTONE:
+                        fprintf(fd, "halftone or dithered scan\n");
+                        break;
+                case THRESHHOLD_ERRORDIFFUSE:
+                        fprintf(fd, "error diffused\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_threshholding, td->td_threshholding);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
+                fprintf(fd, "  FillOrder: ");
+                switch (td->td_fillorder) {
+                case FILLORDER_MSB2LSB:
+                        fprintf(fd, "msb-to-lsb\n");
+                        break;
+                case FILLORDER_LSB2MSB:
+                        fprintf(fd, "lsb-to-msb\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_fillorder, td->td_fillorder);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_PREDICTOR)) {
+                fprintf(fd, "  Predictor: ");
+                switch (td->td_predictor) {
+                case 1:
+                        fprintf(fd, "none\n");
+                        break;
+                case 2:
+                        fprintf(fd, "horizontal differencing\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_predictor, td->td_predictor);
+                        break;
+                }
+        }
 #ifdef YCBCR_SUPPORT
-	if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
-		fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
-		    td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
-	if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
-		fprintf(fd, "  YCbCr Positioning: ");
-		switch (td->td_ycbcrpositioning) {
-		case YCBCRPOSITION_CENTERED:
-			fprintf(fd, "centered\n");
-			break;
-		case YCBCRPOSITION_COSITED:
-			fprintf(fd, "cosited\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_ycbcrpositioning, td->td_ycbcrpositioning);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_YCBCRCOEFFICIENTS))
-		fprintf(fd, "  YCbCr Coefficients: %g, %g, %g\n",
-		    td->td_ycbcrcoeffs[0],
-		    td->td_ycbcrcoeffs[1],
-		    td->td_ycbcrcoeffs[2]);
+        if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
+                fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
+                    td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
+        if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
+                fprintf(fd, "  YCbCr Positioning: ");
+                switch (td->td_ycbcrpositioning) {
+                case YCBCRPOSITION_CENTERED:
+                        fprintf(fd, "centered\n");
+                        break;
+                case YCBCRPOSITION_COSITED:
+                        fprintf(fd, "cosited\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_ycbcrpositioning, td->td_ycbcrpositioning);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_YCBCRCOEFFICIENTS))
+                fprintf(fd, "  YCbCr Coefficients: %g, %g, %g\n",
+                    td->td_ycbcrcoeffs[0],
+                    td->td_ycbcrcoeffs[1],
+                    td->td_ycbcrcoeffs[2]);
 #endif
 #ifdef JPEG_SUPPORT
-	if (TIFFFieldSet(tif,FIELD_JPEGPROC)) {
-		fprintf(fd, "  JPEG Processing Mode: ");
-		switch (td->td_jpegproc) {
-		case JPEGPROC_BASELINE:
-			fprintf(fd, "baseline sequential algorithm\n");
-			break;
-		case JPEGPROC_LOSSLESS:
-			fprintf(fd, "lossless algorithm with Huffman coding\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_jpegproc, td->td_jpegproc);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_JPEGRESTARTINTERVAL)) {
-		fprintf(fd, "  JPEG Restart Interval: ");
-		if (td->td_jpegrestartinterval)
-			fprintf(fd, "%u\n", td->td_jpegrestartinterval);
-		else
-			fprintf(fd, "(no restart markers)\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_JPEGQTABLES)) {
-		fprintf(fd, "  JPEG Quantization Tables: ");
-		if (flags & TIFFPRINT_JPEGQTABLES) {
-			for (i = 0; i < td->td_samplesperpixel; i++)
-				JPEGPrintQTable(fd, td->td_qtab[i]);
-		} else
-			fprintf(fd, "(present)\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_JPEGDCTABLES)) {
-		fprintf(fd, "  JPEG DC Tables: ");
-		if (flags & TIFFPRINT_JPEGDCTABLES) {
-			for (i = 0; i < td->td_samplesperpixel; i++)
-				JPEGPrintCTable(fd, td->td_dctab[i]);
-		} else
-			fprintf(fd, "(present)\n");
-	}
-	if (TIFFFieldSet(tif,FIELD_JPEGACTABLES)) {
-		fprintf(fd, "  JPEG AC Tables: ");
-		if (flags & TIFFPRINT_JPEGACTABLES) {
-			for (i = 0; i < td->td_samplesperpixel; i++)
-				JPEGPrintCTable(fd, td->td_actab[i]);
-		} else
-			fprintf(fd, "(present)\n");
-	}
+        if (TIFFFieldSet(tif,FIELD_JPEGPROC)) {
+                fprintf(fd, "  JPEG Processing Mode: ");
+                switch (td->td_jpegproc) {
+                case JPEGPROC_BASELINE:
+                        fprintf(fd, "baseline sequential algorithm\n");
+                        break;
+                case JPEGPROC_LOSSLESS:
+                        fprintf(fd, "lossless algorithm with Huffman coding\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_jpegproc, td->td_jpegproc);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_JPEGRESTARTINTERVAL)) {
+                fprintf(fd, "  JPEG Restart Interval: ");
+                if (td->td_jpegrestartinterval)
+                        fprintf(fd, "%u\n", td->td_jpegrestartinterval);
+                else
+                        fprintf(fd, "(no restart markers)\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_JPEGQTABLES)) {
+                fprintf(fd, "  JPEG Quantization Tables: ");
+                if (flags & TIFFPRINT_JPEGQTABLES) {
+                        for (i = 0; i < td->td_samplesperpixel; i++)
+                                JPEGPrintQTable(fd, td->td_qtab[i]);
+                } else
+                        fprintf(fd, "(present)\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_JPEGDCTABLES)) {
+                fprintf(fd, "  JPEG DC Tables: ");
+                if (flags & TIFFPRINT_JPEGDCTABLES) {
+                        for (i = 0; i < td->td_samplesperpixel; i++)
+                                JPEGPrintCTable(fd, td->td_dctab[i]);
+                } else
+                        fprintf(fd, "(present)\n");
+        }
+        if (TIFFFieldSet(tif,FIELD_JPEGACTABLES)) {
+                fprintf(fd, "  JPEG AC Tables: ");
+                if (flags & TIFFPRINT_JPEGACTABLES) {
+                        for (i = 0; i < td->td_samplesperpixel; i++)
+                                JPEGPrintCTable(fd, td->td_actab[i]);
+                } else
+                        fprintf(fd, "(present)\n");
+        }
 #endif
-	if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
-		fprintf(fd, "  Halftone Hints: light %u dark %u\n",
-		    td->td_halftonehints[0], td->td_halftonehints[1]);
-	if (TIFFFieldSet(tif,FIELD_ARTIST))
-		fprintf(fd, "  Artist: \"%s\"\n", td->td_artist);
-	if (TIFFFieldSet(tif,FIELD_DATETIME))
-		fprintf(fd, "  Date & Time: \"%s\"\n", td->td_datetime);
-	if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
-		fprintf(fd, "  Host Computer: \"%s\"\n", td->td_hostcomputer);
-	if (TIFFFieldSet(tif,FIELD_SOFTWARE))
-		fprintf(fd, "  Software: \"%s\"\n", td->td_software);
-	if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
-		fprintf(fd, "  Document Name: \"%s\"\n", td->td_documentname);
-	if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
-		fprintf(fd, "  Image Description: \"%s\"\n",
-		    td->td_imagedescription);
-	if (TIFFFieldSet(tif,FIELD_MAKE))
-		fprintf(fd, "  Make: \"%s\"\n", td->td_make);
-	if (TIFFFieldSet(tif,FIELD_MODEL))
-		fprintf(fd, "  Model: \"%s\"\n", td->td_model);
-	if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
-		fprintf(fd, "  Orientation: ");
-		if (td->td_orientation < NORIENTNAMES)
-			fprintf(fd, "%s\n", orientNames[td->td_orientation]);
-		else
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_orientation, td->td_orientation);
-	}
-	if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
-		fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
-	if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
-		fprintf(fd, "  Rows/Strip: ");
-		if (td->td_rowsperstrip == 0xffffffffL)
-			fprintf(fd, "(infinite)\n");
-		else
-			fprintf(fd, "%lu\n", (u_long) td->td_rowsperstrip);
-	}
-	if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
-		fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);
-	if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
-		fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
-	if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
-		fprintf(fd, "  Planar Configuration: ");
-		switch (td->td_planarconfig) {
-		case PLANARCONFIG_CONTIG:
-			fprintf(fd, "single image plane\n");
-			break;
-		case PLANARCONFIG_SEPARATE:
-			fprintf(fd, "separate image planes\n");
-			break;
-		default:
-			fprintf(fd, "%u (0x%x)\n",
-			    td->td_planarconfig, td->td_planarconfig);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_PAGENAME))
-		fprintf(fd, "  Page Name: \"%s\"\n", td->td_pagename);
-	if (TIFFFieldSet(tif,FIELD_GROUP3OPTIONS)) {
-		fprintf(fd, "  Group 3 Options:");
-		sep = " ";
-		if (td->td_group3options & GROUP3OPT_2DENCODING)
-			fprintf(fd, "%s2-d encoding", sep), sep = "+";
-		if (td->td_group3options & GROUP3OPT_FILLBITS)
-			fprintf(fd, "%sEOL padding", sep), sep = "+";
-		if (td->td_group3options & GROUP3OPT_UNCOMPRESSED)
-			fprintf(fd, "%suncompressed data", sep);
-		fprintf(fd, " (%lu = 0x%lx)\n",
-		    (u_long) td->td_group3options,
-		    (u_long) td->td_group3options);
-	}
-	if (TIFFFieldSet(tif,FIELD_CLEANFAXDATA)) {
-		fprintf(fd, "  Fax Data: ");
-		switch (td->td_cleanfaxdata) {
-		case CLEANFAXDATA_CLEAN:
-			fprintf(fd, "clean\n");
-			break;
-		case CLEANFAXDATA_REGENERATED:
-			fprintf(fd, "receiver regenerated\n");
-			break;
-		case CLEANFAXDATA_UNCLEAN:
-			fprintf(fd, "uncorrected errors\n");
-			break;
-		default:
-			fprintf(fd, "(%u = 0x%x)\n",
-			    td->td_cleanfaxdata, td->td_cleanfaxdata);
-			break;
-		}
-	}
-	if (TIFFFieldSet(tif,FIELD_BADFAXLINES))
-		fprintf(fd, "  Bad Fax Lines: %lu\n",
-		    (u_long) td->td_badfaxlines);
-	if (TIFFFieldSet(tif,FIELD_BADFAXRUN))
-		fprintf(fd, "  Consecutive Bad Fax Lines: %u\n",
-		    td->td_badfaxrun);
-	if (TIFFFieldSet(tif,FIELD_GROUP4OPTIONS)) {
-		fprintf(fd, "  Group 4 Options:");
-		if (td->td_group4options & GROUP4OPT_UNCOMPRESSED)
-			fprintf(fd, "uncompressed data");
-		fprintf(fd, " (%lu = 0x%lx)\n",
-		    (u_long) td->td_group4options,
-		    (u_long) td->td_group4options);
-	}
-	if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
-		fprintf(fd, "  Page Number: %u-%u\n",
-		    td->td_pagenumber[0], td->td_pagenumber[1]);
-	if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
-		fprintf(fd, "  Color Map: ");
-		if (flags & TIFFPRINT_COLORMAP) {
-			fprintf(fd, "\n");
-			n = 1L<<td->td_bitspersample;
-			for (i = 0; i < n; i++)
-				fprintf(fd, "   %5d: %5u %5u %5u\n",
-				    i,
-				    td->td_colormap[0][i],
-				    td->td_colormap[1][i],
-				    td->td_colormap[2][i]);
-		} else
-			fprintf(fd, "(present)\n");
-	}
+        if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
+                fprintf(fd, "  Halftone Hints: light %u dark %u\n",
+                    td->td_halftonehints[0], td->td_halftonehints[1]);
+        if (TIFFFieldSet(tif,FIELD_ARTIST))
+                fprintf(fd, "  Artist: \"%s\"\n", td->td_artist);
+        if (TIFFFieldSet(tif,FIELD_DATETIME))
+                fprintf(fd, "  Date & Time: \"%s\"\n", td->td_datetime);
+        if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
+                fprintf(fd, "  Host Computer: \"%s\"\n", td->td_hostcomputer);
+        if (TIFFFieldSet(tif,FIELD_SOFTWARE))
+                fprintf(fd, "  Software: \"%s\"\n", td->td_software);
+        if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
+                fprintf(fd, "  Document Name: \"%s\"\n", td->td_documentname);
+        if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
+                fprintf(fd, "  Image Description: \"%s\"\n",
+                    td->td_imagedescription);
+        if (TIFFFieldSet(tif,FIELD_MAKE))
+                fprintf(fd, "  Make: \"%s\"\n", td->td_make);
+        if (TIFFFieldSet(tif,FIELD_MODEL))
+                fprintf(fd, "  Model: \"%s\"\n", td->td_model);
+        if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
+                fprintf(fd, "  Orientation: ");
+                if (td->td_orientation < NORIENTNAMES)
+                        fprintf(fd, "%s\n", orientNames[td->td_orientation]);
+                else
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_orientation, td->td_orientation);
+        }
+        if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
+                fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
+        if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
+                fprintf(fd, "  Rows/Strip: ");
+                if (td->td_rowsperstrip == 0xffffffffL)
+                        fprintf(fd, "(infinite)\n");
+                else
+                        fprintf(fd, "%lu\n", (u_long) td->td_rowsperstrip);
+        }
+        if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
+                fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);
+        if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
+                fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
+        if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
+                fprintf(fd, "  Planar Configuration: ");
+                switch (td->td_planarconfig) {
+                case PLANARCONFIG_CONTIG:
+                        fprintf(fd, "single image plane\n");
+                        break;
+                case PLANARCONFIG_SEPARATE:
+                        fprintf(fd, "separate image planes\n");
+                        break;
+                default:
+                        fprintf(fd, "%u (0x%x)\n",
+                            td->td_planarconfig, td->td_planarconfig);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_PAGENAME))
+                fprintf(fd, "  Page Name: \"%s\"\n", td->td_pagename);
+        if (TIFFFieldSet(tif,FIELD_GROUP3OPTIONS)) {
+                fprintf(fd, "  Group 3 Options:");
+                sep = " ";
+                if (td->td_group3options & GROUP3OPT_2DENCODING)
+                        fprintf(fd, "%s2-d encoding", sep), sep = "+";
+                if (td->td_group3options & GROUP3OPT_FILLBITS)
+                        fprintf(fd, "%sEOL padding", sep), sep = "+";
+                if (td->td_group3options & GROUP3OPT_UNCOMPRESSED)
+                        fprintf(fd, "%suncompressed data", sep);
+                fprintf(fd, " (%lu = 0x%lx)\n",
+                    (u_long) td->td_group3options,
+                    (u_long) td->td_group3options);
+        }
+        if (TIFFFieldSet(tif,FIELD_CLEANFAXDATA)) {
+                fprintf(fd, "  Fax Data: ");
+                switch (td->td_cleanfaxdata) {
+                case CLEANFAXDATA_CLEAN:
+                        fprintf(fd, "clean\n");
+                        break;
+                case CLEANFAXDATA_REGENERATED:
+                        fprintf(fd, "receiver regenerated\n");
+                        break;
+                case CLEANFAXDATA_UNCLEAN:
+                        fprintf(fd, "uncorrected errors\n");
+                        break;
+                default:
+                        fprintf(fd, "(%u = 0x%x)\n",
+                            td->td_cleanfaxdata, td->td_cleanfaxdata);
+                        break;
+                }
+        }
+        if (TIFFFieldSet(tif,FIELD_BADFAXLINES))
+                fprintf(fd, "  Bad Fax Lines: %lu\n",
+                    (u_long) td->td_badfaxlines);
+        if (TIFFFieldSet(tif,FIELD_BADFAXRUN))
+                fprintf(fd, "  Consecutive Bad Fax Lines: %u\n",
+                    td->td_badfaxrun);
+        if (TIFFFieldSet(tif,FIELD_GROUP4OPTIONS)) {
+                fprintf(fd, "  Group 4 Options:");
+                if (td->td_group4options & GROUP4OPT_UNCOMPRESSED)
+                        fprintf(fd, "uncompressed data");
+                fprintf(fd, " (%lu = 0x%lx)\n",
+                    (u_long) td->td_group4options,
+                    (u_long) td->td_group4options);
+        }
+        if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
+                fprintf(fd, "  Page Number: %u-%u\n",
+                    td->td_pagenumber[0], td->td_pagenumber[1]);
+        if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
+                fprintf(fd, "  Color Map: ");
+                if (flags & TIFFPRINT_COLORMAP) {
+                        fprintf(fd, "\n");
+                        n = 1L<<td->td_bitspersample;
+                        for (i = 0; i < n; i++)
+                                fprintf(fd, "   %5d: %5u %5u %5u\n",
+                                    i,
+                                    td->td_colormap[0][i],
+                                    td->td_colormap[1][i],
+                                    td->td_colormap[2][i]);
+                } else
+                        fprintf(fd, "(present)\n");
+        }
 #ifdef COLORIMETRY_SUPPORT
-	if (TIFFFieldSet(tif,FIELD_WHITEPOINT))
-		fprintf(fd, "  White Point: %g-%g\n",
-		    td->td_whitepoint[0], td->td_whitepoint[1]);
-	if (TIFFFieldSet(tif,FIELD_PRIMARYCHROMAS))
-		fprintf(fd, "  Primary Chromaticities: %g,%g %g,%g %g,%g\n",
-		    td->td_primarychromas[0], td->td_primarychromas[1],
-		    td->td_primarychromas[2], td->td_primarychromas[3],
-		    td->td_primarychromas[4], td->td_primarychromas[5]);
-	if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
-		fprintf(fd, "  Reference Black/White:\n");
-		for (i = 0; i < td->td_samplesperpixel; i++)
-			fprintf(fd, "    %2d: %5g %5g\n",
-			    i,
-			    td->td_refblackwhite[2*i+0],
-			    td->td_refblackwhite[2*i+1]);
-	}
-	if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
-		fprintf(fd, "  Transfer Function: ");
-		if (flags & TIFFPRINT_CURVES) {
-			fprintf(fd, "\n");
-			n = 1L<<td->td_bitspersample;
-			for (i = 0; i < n; i++) {
-				fprintf(fd, "    %2d: %5u",
-				    i, td->td_transferfunction[0][i]);
-				for (j = 1; j < td->td_samplesperpixel; j++)
-					fprintf(fd, " %5u",
-					    td->td_transferfunction[j][i]);
-				putc('\n', fd);
-			}
-		} else
-			fprintf(fd, "(present)\n");
-	}
+        if (TIFFFieldSet(tif,FIELD_WHITEPOINT))
+                fprintf(fd, "  White Point: %g-%g\n",
+                    td->td_whitepoint[0], td->td_whitepoint[1]);
+        if (TIFFFieldSet(tif,FIELD_PRIMARYCHROMAS))
+                fprintf(fd, "  Primary Chromaticities: %g,%g %g,%g %g,%g\n",
+                    td->td_primarychromas[0], td->td_primarychromas[1],
+                    td->td_primarychromas[2], td->td_primarychromas[3],
+                    td->td_primarychromas[4], td->td_primarychromas[5]);
+        if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
+                fprintf(fd, "  Reference Black/White:\n");
+                for (i = 0; i < td->td_samplesperpixel; i++)
+                        fprintf(fd, "    %2d: %5g %5g\n",
+                            i,
+                            td->td_refblackwhite[2*i+0],
+                            td->td_refblackwhite[2*i+1]);
+        }
+        if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
+                fprintf(fd, "  Transfer Function: ");
+                if (flags & TIFFPRINT_CURVES) {
+                        fprintf(fd, "\n");
+                        n = 1L<<td->td_bitspersample;
+                        for (i = 0; i < n; i++) {
+                                fprintf(fd, "    %2d: %5u",
+                                    i, td->td_transferfunction[0][i]);
+                                for (j = 1; j < td->td_samplesperpixel; j++)
+                                        fprintf(fd, " %5u",
+                                            td->td_transferfunction[j][i]);
+                                putc('\n', fd);
+                        }
+                } else
+                        fprintf(fd, "(present)\n");
+        }
 #endif
-	if ((flags & TIFFPRINT_STRIPS) &&
-	    TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
-		fprintf(fd, "  %u %s:\n",
-		    td->td_nstrips,
-		    isTiled(tif) ? "Tiles" : "Strips");
-		for (i = 0; i < td->td_nstrips; i++)
-			fprintf(fd, "    %3d: [%8lu, %8lu]\n",
-			    i,
-			    (u_long) td->td_stripoffset[i],
-			    (u_long) td->td_stripbytecount[i]);
-	}
+        if ((flags & TIFFPRINT_STRIPS) &&
+            TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
+                fprintf(fd, "  %u %s:\n",
+                    td->td_nstrips,
+                    isTiled(tif) ? "Tiles" : "Strips");
+                for (i = 0; i < td->td_nstrips; i++)
+                        fprintf(fd, "    %3d: [%8lu, %8lu]\n",
+                            i,
+                            (u_long) td->td_stripoffset[i],
+                            (u_long) td->td_stripbytecount[i]);
+        }
 }

+ 375 - 375
panda/src/tiff/tif_read.c

@@ -34,11 +34,11 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include <assert.h>
 
-static	int TIFFFillStrip(TIFF*, tstrip_t);
-static	int TIFFFillTile(TIFF*, ttile_t);
-static	int TIFFStartStrip(TIFF*, tstrip_t);
-static	int TIFFStartTile(TIFF*, ttile_t);
-static	int TIFFCheckRead(TIFF*, int);
+static  int TIFFFillStrip(TIFF*, tstrip_t);
+static  int TIFFFillTile(TIFF*, ttile_t);
+static  int TIFFStartStrip(TIFF*, tstrip_t);
+static  int TIFFStartTile(TIFF*, ttile_t);
+static  int TIFFCheckRead(TIFF*, int);
 
 /*
  * Seek to a random row+sample in a file.
@@ -46,74 +46,74 @@ static	int TIFFCheckRead(TIFF*, int);
 static int
 TIFFSeek(TIFF* tif, uint32 row, tsample_t sample)
 {
-	register TIFFDirectory *td = &tif->tif_dir;
-	tstrip_t strip;
-
-	if (row >= td->td_imagelength) {	/* out of range */
-		TIFFError(tif->tif_name, "%lu: Row out of range, max %lu",
-		    (u_long) row, (u_long) td->td_imagelength);
-		return (0);
-	}
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
-		if (sample >= td->td_samplesperpixel) {
-			TIFFError(tif->tif_name,
-			    "%lu: Sample out of range, max %lu",
-			    (u_long) sample, (u_long) td->td_samplesperpixel);
-			return (0);
-		}
-		strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
-	} else
-		strip = row / td->td_rowsperstrip;
-	if (strip != tif->tif_curstrip) { 	/* different strip, refill */
-		if (!TIFFFillStrip(tif, strip))
-			return (0);
-	} else if (row < tif->tif_row) {
-		/*
-		 * Moving backwards within the same strip: backup
-		 * to the start and then decode forward (below).
-		 *
-		 * NB: If you're planning on lots of random access within a
-		 * strip, it's better to just read and decode the entire
-		 * strip, and then access the decoded data in a random fashion.
-		 */
-		if (!TIFFStartStrip(tif, strip))
-			return (0);
-	}
-	if (row != tif->tif_row) {
-		if (tif->tif_seek) {
-			/*
-			 * Seek forward to the desired row.
-			 */
-			if (!(*tif->tif_seek)(tif, row - tif->tif_row))
-				return (0);
-			tif->tif_row = row;
-		} else {
-			TIFFError(tif->tif_name,
-		    "Compression algorithm does not support random access");
-			return (0);
-		}
-	}
-	return (1);
+        register TIFFDirectory *td = &tif->tif_dir;
+        tstrip_t strip;
+
+        if (row >= td->td_imagelength) {        /* out of range */
+                TIFFError(tif->tif_name, "%lu: Row out of range, max %lu",
+                    (u_long) row, (u_long) td->td_imagelength);
+                return (0);
+        }
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
+                if (sample >= td->td_samplesperpixel) {
+                        TIFFError(tif->tif_name,
+                            "%lu: Sample out of range, max %lu",
+                            (u_long) sample, (u_long) td->td_samplesperpixel);
+                        return (0);
+                }
+                strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
+        } else
+                strip = row / td->td_rowsperstrip;
+        if (strip != tif->tif_curstrip) {       /* different strip, refill */
+                if (!TIFFFillStrip(tif, strip))
+                        return (0);
+        } else if (row < tif->tif_row) {
+                /*
+                 * Moving backwards within the same strip: backup
+                 * to the start and then decode forward (below).
+                 *
+                 * NB: If you're planning on lots of random access within a
+                 * strip, it's better to just read and decode the entire
+                 * strip, and then access the decoded data in a random fashion.
+                 */
+                if (!TIFFStartStrip(tif, strip))
+                        return (0);
+        }
+        if (row != tif->tif_row) {
+                if (tif->tif_seek) {
+                        /*
+                         * Seek forward to the desired row.
+                         */
+                        if (!(*tif->tif_seek)(tif, row - tif->tif_row))
+                                return (0);
+                        tif->tif_row = row;
+                } else {
+                        TIFFError(tif->tif_name,
+                    "Compression algorithm does not support random access");
+                        return (0);
+                }
+        }
+        return (1);
 }
 
 int
 TIFFReadScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
 {
-	int e;
-
-	if (!TIFFCheckRead(tif, 0))
-		return (-1);
-	if (e = TIFFSeek(tif, row, sample)) {
-		/*
-		 * Decompress desired row into user buffer.
-		 */
-		e = (*tif->tif_decoderow)
-		    (tif, buf, tif->tif_scanlinesize, sample);
-		tif->tif_row++;
-		if (e)
-			(*tif->tif_postdecode)(tif, buf, tif->tif_scanlinesize);
-	}
-	return (e ? 1 : -1);
+        int e;
+
+        if (!TIFFCheckRead(tif, 0))
+                return (-1);
+        if (e = TIFFSeek(tif, row, sample)) {
+                /*
+                 * Decompress desired row into user buffer.
+                 */
+                e = (*tif->tif_decoderow)
+                    (tif, buf, tif->tif_scanlinesize, sample);
+                tif->tif_row++;
+                if (e)
+                        (*tif->tif_postdecode)(tif, buf, tif->tif_scanlinesize);
+        }
+        return (e ? 1 : -1);
 }
 
 /*
@@ -123,67 +123,67 @@ TIFFReadScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
 tsize_t
 TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	uint32 nrows;
-	tsize_t stripsize;
-
-	if (!TIFFCheckRead(tif, 0))
-		return (-1);
-	if (strip >= td->td_nstrips) {
-		TIFFError(tif->tif_name, "%ld: Strip out of range, max %ld",
-		    (long) strip, (long) td->td_nstrips);
-		return (-1);
-	}
-	/*
-	 * Calculate the strip size according to the number of
-	 * rows in the strip (check for truncated last strip).
-	 */
-	if (strip != td->td_nstrips-1 ||
-	    (nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
-		nrows = td->td_rowsperstrip;
-	stripsize = TIFFVStripSize(tif, nrows);
-	if (size == (tsize_t) -1)
-		size = stripsize;
-	else if (size > stripsize)
-		size = stripsize;
-	if (TIFFFillStrip(tif, strip) &&
+        TIFFDirectory *td = &tif->tif_dir;
+        uint32 nrows;
+        tsize_t stripsize;
+
+        if (!TIFFCheckRead(tif, 0))
+                return (-1);
+        if (strip >= td->td_nstrips) {
+                TIFFError(tif->tif_name, "%ld: Strip out of range, max %ld",
+                    (long) strip, (long) td->td_nstrips);
+                return (-1);
+        }
+        /*
+         * Calculate the strip size according to the number of
+         * rows in the strip (check for truncated last strip).
+         */
+        if (strip != td->td_nstrips-1 ||
+            (nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
+                nrows = td->td_rowsperstrip;
+        stripsize = TIFFVStripSize(tif, nrows);
+        if (size == (tsize_t) -1)
+                size = stripsize;
+        else if (size > stripsize)
+                size = stripsize;
+        if (TIFFFillStrip(tif, strip) &&
     (*tif->tif_decodestrip)(tif, buf, size, strip / td->td_stripsperimage)) {
-		(*tif->tif_postdecode)(tif, buf, size);
-		return (size);
-	} else
-		return ((tsize_t) -1);
+                (*tif->tif_postdecode)(tif, buf, size);
+                return (size);
+        } else
+                return ((tsize_t) -1);
 }
 
 static tsize_t
 TIFFReadRawStrip1(TIFF* tif,
     tstrip_t strip, tdata_t buf, tsize_t size, const char* module)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-
-	if (!isMapped(tif)) {
-		if (!SeekOK(tif, td->td_stripoffset[strip])) {
-			TIFFError(module,
-			    "%s: Seek error at scanline %lu, strip %lu",
-			    tif->tif_name,
-			    (u_long) tif->tif_row, (u_long) strip);
-			return (-1);
-		}
-		if (!ReadOK(tif, buf, size)) {
-			TIFFError(module, "%s: Read error at scanline %lu",
-			    tif->tif_name, (u_long) tif->tif_row);
-			return (-1);
-		}
-	} else {
-		if (td->td_stripoffset[strip] + size > tif->tif_size) {
-			TIFFError(module,
-			    "%s: Seek error at scanline %lu, strip %lu",
-			    tif->tif_name,
-			    (u_long) tif->tif_row, (u_long) strip);
-			return (-1);
-		}
-		memcpy(buf, tif->tif_base + td->td_stripoffset[strip], size);
-	}
-	return (size);
+        TIFFDirectory *td = &tif->tif_dir;
+
+        if (!isMapped(tif)) {
+                if (!SeekOK(tif, td->td_stripoffset[strip])) {
+                        TIFFError(module,
+                            "%s: Seek error at scanline %lu, strip %lu",
+                            tif->tif_name,
+                            (u_long) tif->tif_row, (u_long) strip);
+                        return (-1);
+                }
+                if (!ReadOK(tif, buf, size)) {
+                        TIFFError(module, "%s: Read error at scanline %lu",
+                            tif->tif_name, (u_long) tif->tif_row);
+                        return (-1);
+                }
+        } else {
+                if (td->td_stripoffset[strip] + size > tif->tif_size) {
+                        TIFFError(module,
+                            "%s: Seek error at scanline %lu, strip %lu",
+                            tif->tif_name,
+                            (u_long) tif->tif_row, (u_long) strip);
+                        return (-1);
+                }
+                memcpy(buf, tif->tif_base + td->td_stripoffset[strip], size);
+        }
+        return (size);
 }
 
 /*
@@ -192,21 +192,21 @@ TIFFReadRawStrip1(TIFF* tif,
 tsize_t
 TIFFReadRawStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
 {
-	static const char module[] = "TIFFReadRawStrip";
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t bytecount;
-
-	if (!TIFFCheckRead(tif, 0))
-		return (-1);
-	if (strip >= td->td_nstrips) {
-		TIFFError(tif->tif_name, "%lu: Strip out of range, max %lu",
-		    (u_long) strip, (u_long) td->td_nstrips);
-		return (-1);
-	}
-	bytecount = td->td_stripbytecount[strip];
-	if (size != (tsize_t)-1 && size < bytecount)
-		bytecount = size;
-	return (TIFFReadRawStrip1(tif, strip, buf, bytecount, module));
+        static const char module[] = "TIFFReadRawStrip";
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t bytecount;
+
+        if (!TIFFCheckRead(tif, 0))
+                return (-1);
+        if (strip >= td->td_nstrips) {
+                TIFFError(tif->tif_name, "%lu: Strip out of range, max %lu",
+                    (u_long) strip, (u_long) td->td_nstrips);
+                return (-1);
+        }
+        bytecount = td->td_stripbytecount[strip];
+        if (size != (tsize_t)-1 && size < bytecount)
+                bytecount = size;
+        return (TIFFReadRawStrip1(tif, strip, buf, bytecount, module));
 }
 
 /*
@@ -217,66 +217,66 @@ TIFFReadRawStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
 static int
 TIFFFillStrip(TIFF* tif, tstrip_t strip)
 {
-	static const char module[] = "TIFFFillStrip";
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t bytecount;
-
-	bytecount = td->td_stripbytecount[strip];
-	if (isMapped(tif) &&
-	    (td->td_fillorder == tif->tif_fillorder || (tif->tif_flags & TIFF_NOBITREV))) {
-		/*
-		 * The image is mapped into memory and we either don't
-		 * need to flip bits or the compression routine is going
-		 * to handle this operation itself.  In this case, avoid
-		 * copying the raw data and instead just reference the
-		 * data from the memory mapped file image.  This assumes
-		 * that the decompression routines do not modify the
-		 * contents of the raw data buffer (if they try to,
-		 * the application will get a fault since the file is
-		 * mapped read-only).
-		 */
-		if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
-			_TIFFfree(tif->tif_rawdata);
-		tif->tif_flags &= ~TIFF_MYBUFFER;
-		if (td->td_stripoffset[strip] + bytecount > tif->tif_size) {
-			/*
-			 * This error message might seem strange, but it's
-			 * what would happen if a read were done instead.
-			 */
-			TIFFError(module, "%s: Read error on strip %lu",
-			    tif->tif_name, (u_long) strip);
-			tif->tif_curstrip = -1;		/* unknown state */
-			return (0);
-		}
-		tif->tif_rawdatasize = bytecount;
-		tif->tif_rawdata = tif->tif_base + td->td_stripoffset[strip];
-	} else {
-		/*
-		 * Expand raw data buffer, if needed, to
-		 * hold data strip coming from file
-		 * (perhaps should set upper bound on
-		 *  the size of a buffer we'll use?).
-		 */
-		if (bytecount > tif->tif_rawdatasize) {
-			tif->tif_curstrip = -1;		/* unknown state */
-			if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
-				TIFFError(module,
-				"%s: Data buffer too small to hold strip %lu",
-				    tif->tif_name, (u_long) strip);
-				return (0);
-			}
-			if (!TIFFReadBufferSetup(tif, 0,
-			    roundup(bytecount, 1024)))
-				return (0);
-		}
-		if (TIFFReadRawStrip1(tif, strip, (u_char *)tif->tif_rawdata,
-		    bytecount, module) != bytecount)
-			return (0);
-		if (td->td_fillorder != tif->tif_fillorder &&
-		    (tif->tif_flags & TIFF_NOBITREV) == 0)
-			TIFFReverseBits(tif->tif_rawdata, bytecount);
-	}
-	return (TIFFStartStrip(tif, strip));
+        static const char module[] = "TIFFFillStrip";
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t bytecount;
+
+        bytecount = td->td_stripbytecount[strip];
+        if (isMapped(tif) &&
+            (td->td_fillorder == tif->tif_fillorder || (tif->tif_flags & TIFF_NOBITREV))) {
+                /*
+                 * The image is mapped into memory and we either don't
+                 * need to flip bits or the compression routine is going
+                 * to handle this operation itself.  In this case, avoid
+                 * copying the raw data and instead just reference the
+                 * data from the memory mapped file image.  This assumes
+                 * that the decompression routines do not modify the
+                 * contents of the raw data buffer (if they try to,
+                 * the application will get a fault since the file is
+                 * mapped read-only).
+                 */
+                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
+                        _TIFFfree(tif->tif_rawdata);
+                tif->tif_flags &= ~TIFF_MYBUFFER;
+                if (td->td_stripoffset[strip] + bytecount > tif->tif_size) {
+                        /*
+                         * This error message might seem strange, but it's
+                         * what would happen if a read were done instead.
+                         */
+                        TIFFError(module, "%s: Read error on strip %lu",
+                            tif->tif_name, (u_long) strip);
+                        tif->tif_curstrip = -1;         /* unknown state */
+                        return (0);
+                }
+                tif->tif_rawdatasize = bytecount;
+                tif->tif_rawdata = tif->tif_base + td->td_stripoffset[strip];
+        } else {
+                /*
+                 * Expand raw data buffer, if needed, to
+                 * hold data strip coming from file
+                 * (perhaps should set upper bound on
+                 *  the size of a buffer we'll use?).
+                 */
+                if (bytecount > tif->tif_rawdatasize) {
+                        tif->tif_curstrip = -1;         /* unknown state */
+                        if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
+                                TIFFError(module,
+                                "%s: Data buffer too small to hold strip %lu",
+                                    tif->tif_name, (u_long) strip);
+                                return (0);
+                        }
+                        if (!TIFFReadBufferSetup(tif, 0,
+                            roundup(bytecount, 1024)))
+                                return (0);
+                }
+                if (TIFFReadRawStrip1(tif, strip, (u_char *)tif->tif_rawdata,
+                    bytecount, module) != bytecount)
+                        return (0);
+                if (td->td_fillorder != tif->tif_fillorder &&
+                    (tif->tif_flags & TIFF_NOBITREV) == 0)
+                        TIFFReverseBits(tif->tif_rawdata, bytecount);
+        }
+        return (TIFFStartStrip(tif, strip));
 }
 
 /*
@@ -292,10 +292,10 @@ tsize_t
 TIFFReadTile(TIFF* tif,
     tdata_t buf, uint32 x, uint32 y, uint32 z, tsample_t s)
 {
-	if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))
-		return (-1);
-	return (TIFFReadEncodedTile(tif,
-	    TIFFComputeTile(tif, x, y, z, s), buf, (tsize_t) -1));
+        if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))
+                return (-1);
+        return (TIFFReadEncodedTile(tif,
+            TIFFComputeTile(tif, x, y, z, s), buf, (tsize_t) -1));
 }
 
 /*
@@ -305,64 +305,64 @@ TIFFReadTile(TIFF* tif,
 tsize_t
 TIFFReadEncodedTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t tilesize = tif->tif_tilesize;
-
-	if (!TIFFCheckRead(tif, 1))
-		return (-1);
-	if (tile >= td->td_nstrips) {
-		TIFFError(tif->tif_name, "%ld: Tile out of range, max %ld",
-		    (long) tile, (u_long) td->td_nstrips);
-		return (-1);
-	}
-	if (size == (tsize_t) -1)
-		size = tilesize;
-	else if (size > tilesize)
-		size = tilesize;
-	if (TIFFFillTile(tif, tile) && 
-	    (*tif->tif_decodetile)(tif, buf, size, tile/td->td_stripsperimage)) {
-		(*tif->tif_postdecode)(tif, buf, size);
-		return (size);
-	} else
-		return (-1);
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t tilesize = tif->tif_tilesize;
+
+        if (!TIFFCheckRead(tif, 1))
+                return (-1);
+        if (tile >= td->td_nstrips) {
+                TIFFError(tif->tif_name, "%ld: Tile out of range, max %ld",
+                    (long) tile, (u_long) td->td_nstrips);
+                return (-1);
+        }
+        if (size == (tsize_t) -1)
+                size = tilesize;
+        else if (size > tilesize)
+                size = tilesize;
+        if (TIFFFillTile(tif, tile) && 
+            (*tif->tif_decodetile)(tif, buf, size, tile/td->td_stripsperimage)) {
+                (*tif->tif_postdecode)(tif, buf, size);
+                return (size);
+        } else
+                return (-1);
 }
 
 static tsize_t
 TIFFReadRawTile1(TIFF* tif,
     ttile_t tile, tdata_t buf, tsize_t size, const char* module)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-
-	if (!isMapped(tif)) {
-		if (!SeekOK(tif, td->td_stripoffset[tile])) {
-			TIFFError(module,
-			    "%s: Seek error at row %ld, col %ld, tile %ld",
-			    tif->tif_name,
-			    (long) tif->tif_row,
-			    (long) tif->tif_col,
-			    (long) tile);
-			return ((tsize_t) -1);
-		}
-		if (!ReadOK(tif, buf, size)) {
-			TIFFError(module, "%s: Read error at row %ld, col %ld",
-			    tif->tif_name,
-			    (long) tif->tif_row,
-			    (long) tif->tif_col);
-			return ((tsize_t) -1);
-		}
-	} else {
-		if (td->td_stripoffset[tile] + size > tif->tif_size) {
-			TIFFError(module,
-			    "%s: Seek error at row %ld, col %ld, tile %ld",
-			    tif->tif_name,
-			    (long) tif->tif_row,
-			    (long) tif->tif_col,
-			    (long) tile);
-			return ((tsize_t) -1);
-		}
-		memcpy(buf, tif->tif_base + td->td_stripoffset[tile], size);
-	}
-	return (size);
+        TIFFDirectory *td = &tif->tif_dir;
+
+        if (!isMapped(tif)) {
+                if (!SeekOK(tif, td->td_stripoffset[tile])) {
+                        TIFFError(module,
+                            "%s: Seek error at row %ld, col %ld, tile %ld",
+                            tif->tif_name,
+                            (long) tif->tif_row,
+                            (long) tif->tif_col,
+                            (long) tile);
+                        return ((tsize_t) -1);
+                }
+                if (!ReadOK(tif, buf, size)) {
+                        TIFFError(module, "%s: Read error at row %ld, col %ld",
+                            tif->tif_name,
+                            (long) tif->tif_row,
+                            (long) tif->tif_col);
+                        return ((tsize_t) -1);
+                }
+        } else {
+                if (td->td_stripoffset[tile] + size > tif->tif_size) {
+                        TIFFError(module,
+                            "%s: Seek error at row %ld, col %ld, tile %ld",
+                            tif->tif_name,
+                            (long) tif->tif_row,
+                            (long) tif->tif_col,
+                            (long) tile);
+                        return ((tsize_t) -1);
+                }
+                memcpy(buf, tif->tif_base + td->td_stripoffset[tile], size);
+        }
+        return (size);
 }
 
 /*
@@ -371,21 +371,21 @@ TIFFReadRawTile1(TIFF* tif,
 tsize_t
 TIFFReadRawTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
 {
-	static const char module[] = "TIFFReadRawTile";
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t bytecount;
-
-	if (!TIFFCheckRead(tif, 1))
-		return ((tsize_t) -1);
-	if (tile >= td->td_nstrips) {
-		TIFFError(tif->tif_name, "%lu: Tile out of range, max %lu",
-		    (u_long) tile, (u_long) td->td_nstrips);
-		return ((tsize_t) -1);
-	}
-	bytecount = td->td_stripbytecount[tile];
-	if (size != (tsize_t) -1 && size < bytecount)
-		bytecount = size;
-	return (TIFFReadRawTile1(tif, tile, buf, bytecount, module));
+        static const char module[] = "TIFFReadRawTile";
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t bytecount;
+
+        if (!TIFFCheckRead(tif, 1))
+                return ((tsize_t) -1);
+        if (tile >= td->td_nstrips) {
+                TIFFError(tif->tif_name, "%lu: Tile out of range, max %lu",
+                    (u_long) tile, (u_long) td->td_nstrips);
+                return ((tsize_t) -1);
+        }
+        bytecount = td->td_stripbytecount[tile];
+        if (size != (tsize_t) -1 && size < bytecount)
+                bytecount = size;
+        return (TIFFReadRawTile1(tif, tile, buf, bytecount, module));
 }
 
 /*
@@ -396,60 +396,60 @@ TIFFReadRawTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
 static int
 TIFFFillTile(TIFF* tif, ttile_t tile)
 {
-	static const char module[] = "TIFFFillTile";
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t bytecount;
-
-	bytecount = td->td_stripbytecount[tile];
-	if (isMapped(tif) &&
-	    (td->td_fillorder == tif->tif_fillorder || (tif->tif_flags & TIFF_NOBITREV))) {
-		/*
-		 * The image is mapped into memory and we either don't
-		 * need to flip bits or the compression routine is going
-		 * to handle this operation itself.  In this case, avoid
-		 * copying the raw data and instead just reference the
-		 * data from the memory mapped file image.  This assumes
-		 * that the decompression routines do not modify the
-		 * contents of the raw data buffer (if they try to,
-		 * the application will get a fault since the file is
-		 * mapped read-only).
-		 */
-		if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
-			_TIFFfree(tif->tif_rawdata);
-		tif->tif_flags &= ~TIFF_MYBUFFER;
-		if (td->td_stripoffset[tile] + bytecount > tif->tif_size) {
-			tif->tif_curtile = -1;		/* unknown state */
-			return (0);
-		}
-		tif->tif_rawdatasize = bytecount;
-		tif->tif_rawdata = tif->tif_base + td->td_stripoffset[tile];
-	} else {
-		/*
-		 * Expand raw data buffer, if needed, to
-		 * hold data tile coming from file
-		 * (perhaps should set upper bound on
-		 *  the size of a buffer we'll use?).
-		 */
-		if (bytecount > tif->tif_rawdatasize) {
-			tif->tif_curtile = -1;		/* unknown state */
-			if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
-				TIFFError(module,
-				"%s: Data buffer too small to hold tile %ld",
-				    tif->tif_name, (long) tile);
-				return (0);
-			}
-			if (!TIFFReadBufferSetup(tif, 0,
-			    roundup(bytecount, 1024)))
-				return (0);
-		}
-		if (TIFFReadRawTile1(tif, tile, (u_char *)tif->tif_rawdata,
-		    bytecount, module) != bytecount)
-			return (0);
-		if (td->td_fillorder != tif->tif_fillorder &&
-		    (tif->tif_flags & TIFF_NOBITREV) == 0)
-			TIFFReverseBits(tif->tif_rawdata, bytecount);
-	}
-	return (TIFFStartTile(tif, tile));
+        static const char module[] = "TIFFFillTile";
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t bytecount;
+
+        bytecount = td->td_stripbytecount[tile];
+        if (isMapped(tif) &&
+            (td->td_fillorder == tif->tif_fillorder || (tif->tif_flags & TIFF_NOBITREV))) {
+                /*
+                 * The image is mapped into memory and we either don't
+                 * need to flip bits or the compression routine is going
+                 * to handle this operation itself.  In this case, avoid
+                 * copying the raw data and instead just reference the
+                 * data from the memory mapped file image.  This assumes
+                 * that the decompression routines do not modify the
+                 * contents of the raw data buffer (if they try to,
+                 * the application will get a fault since the file is
+                 * mapped read-only).
+                 */
+                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
+                        _TIFFfree(tif->tif_rawdata);
+                tif->tif_flags &= ~TIFF_MYBUFFER;
+                if (td->td_stripoffset[tile] + bytecount > tif->tif_size) {
+                        tif->tif_curtile = -1;          /* unknown state */
+                        return (0);
+                }
+                tif->tif_rawdatasize = bytecount;
+                tif->tif_rawdata = tif->tif_base + td->td_stripoffset[tile];
+        } else {
+                /*
+                 * Expand raw data buffer, if needed, to
+                 * hold data tile coming from file
+                 * (perhaps should set upper bound on
+                 *  the size of a buffer we'll use?).
+                 */
+                if (bytecount > tif->tif_rawdatasize) {
+                        tif->tif_curtile = -1;          /* unknown state */
+                        if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
+                                TIFFError(module,
+                                "%s: Data buffer too small to hold tile %ld",
+                                    tif->tif_name, (long) tile);
+                                return (0);
+                        }
+                        if (!TIFFReadBufferSetup(tif, 0,
+                            roundup(bytecount, 1024)))
+                                return (0);
+                }
+                if (TIFFReadRawTile1(tif, tile, (u_char *)tif->tif_rawdata,
+                    bytecount, module) != bytecount)
+                        return (0);
+                if (td->td_fillorder != tif->tif_fillorder &&
+                    (tif->tif_flags & TIFF_NOBITREV) == 0)
+                        TIFFReverseBits(tif->tif_rawdata, bytecount);
+        }
+        return (TIFFStartTile(tif, tile));
 }
 
 /*
@@ -464,30 +464,30 @@ TIFFFillTile(TIFF* tif, ttile_t tile)
 int
 TIFFReadBufferSetup(TIFF* tif, tdata_t bp, tsize_t size)
 {
-	static const char module[] = "TIFFReadBufferSetup";
-
-	if (tif->tif_rawdata) {
-		if (tif->tif_flags & TIFF_MYBUFFER)
-			_TIFFfree(tif->tif_rawdata);
-		tif->tif_rawdata = NULL;
-	}
-	if (bp) {
-		tif->tif_rawdatasize = size;
-		tif->tif_rawdata = (tidata_t) bp;
-		tif->tif_flags &= ~TIFF_MYBUFFER;
-	} else {
-		tif->tif_rawdatasize = roundup(size, 1024);
-		tif->tif_rawdata = (tdata_t) _TIFFmalloc(tif->tif_rawdatasize);
-		tif->tif_flags |= TIFF_MYBUFFER;
-	}
-	if (tif->tif_rawdata == NULL) {
-		TIFFError(module,
-		    "%s: No space for data buffer at scanline %ld",
-		    tif->tif_name, (long) tif->tif_row);
-		tif->tif_rawdatasize = 0;
-		return (0);
-	}
-	return (1);
+        static const char module[] = "TIFFReadBufferSetup";
+
+        if (tif->tif_rawdata) {
+                if (tif->tif_flags & TIFF_MYBUFFER)
+                        _TIFFfree(tif->tif_rawdata);
+                tif->tif_rawdata = NULL;
+        }
+        if (bp) {
+                tif->tif_rawdatasize = size;
+                tif->tif_rawdata = (tidata_t) bp;
+                tif->tif_flags &= ~TIFF_MYBUFFER;
+        } else {
+                tif->tif_rawdatasize = roundup(size, 1024);
+                tif->tif_rawdata = (tdata_t) _TIFFmalloc(tif->tif_rawdatasize);
+                tif->tif_flags |= TIFF_MYBUFFER;
+        }
+        if (tif->tif_rawdata == NULL) {
+                TIFFError(module,
+                    "%s: No space for data buffer at scanline %ld",
+                    tif->tif_name, (long) tif->tif_row);
+                tif->tif_rawdatasize = 0;
+                return (0);
+        }
+        return (1);
 }
 
 /*
@@ -497,13 +497,13 @@ TIFFReadBufferSetup(TIFF* tif, tdata_t bp, tsize_t size)
 static int
 TIFFStartStrip(TIFF* tif, tstrip_t strip)
 {
-	TIFFDirectory *td = &tif->tif_dir;
+        TIFFDirectory *td = &tif->tif_dir;
 
-	tif->tif_curstrip = strip;
-	tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
-	tif->tif_rawcp = tif->tif_rawdata;
-	tif->tif_rawcc = td->td_stripbytecount[strip];
-	return (tif->tif_predecode == NULL || (*tif->tif_predecode)(tif));
+        tif->tif_curstrip = strip;
+        tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
+        tif->tif_rawcp = tif->tif_rawdata;
+        tif->tif_rawcc = td->td_stripbytecount[strip];
+        return (tif->tif_predecode == NULL || (*tif->tif_predecode)(tif));
 }
 
 /*
@@ -513,34 +513,34 @@ TIFFStartStrip(TIFF* tif, tstrip_t strip)
 static int
 TIFFStartTile(TIFF* tif, ttile_t tile)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-
-	tif->tif_curtile = tile;
-	tif->tif_row =
-	    (tile % howmany(td->td_imagewidth, td->td_tilewidth)) *
-		td->td_tilelength;
-	tif->tif_col =
-	    (tile % howmany(td->td_imagelength, td->td_tilelength)) *
-		td->td_tilewidth;
-	tif->tif_rawcp = tif->tif_rawdata;
-	tif->tif_rawcc = td->td_stripbytecount[tile];
-	return (tif->tif_predecode == NULL || (*tif->tif_predecode)(tif));
+        TIFFDirectory *td = &tif->tif_dir;
+
+        tif->tif_curtile = tile;
+        tif->tif_row =
+            (tile % howmany(td->td_imagewidth, td->td_tilewidth)) *
+                td->td_tilelength;
+        tif->tif_col =
+            (tile % howmany(td->td_imagelength, td->td_tilelength)) *
+                td->td_tilewidth;
+        tif->tif_rawcp = tif->tif_rawdata;
+        tif->tif_rawcc = td->td_stripbytecount[tile];
+        return (tif->tif_predecode == NULL || (*tif->tif_predecode)(tif));
 }
 
 static int
 TIFFCheckRead(TIFF* tif, int tiles)
 {
-	if (tif->tif_mode == O_WRONLY) {
-		TIFFError(tif->tif_name, "File not open for reading");
-		return (0);
-	}
-	if (tiles ^ isTiled(tif)) {
-		TIFFError(tif->tif_name, tiles ?
-		    "Can not read tiles from a stripped image" :
-		    "Can not read scanlines from a tiled image");
-		return (0);
-	}
-	return (1);
+        if (tif->tif_mode == O_WRONLY) {
+                TIFFError(tif->tif_name, "File not open for reading");
+                return (0);
+        }
+        if (tiles ^ isTiled(tif)) {
+                TIFFError(tif->tif_name, tiles ?
+                    "Can not read tiles from a stripped image" :
+                    "Can not read scanlines from a tiled image");
+                return (0);
+        }
+        return (1);
 }
 
 void

+ 45 - 45
panda/src/tiff/tif_strip.c

@@ -39,20 +39,20 @@ static char rcsid[] = "$Header$";
 tstrip_t
 TIFFComputeStrip(TIFF* tif, uint32 row, tsample_t sample)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tstrip_t strip;
+        TIFFDirectory *td = &tif->tif_dir;
+        tstrip_t strip;
 
-	strip = row / td->td_rowsperstrip;
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
-		if (sample >= td->td_samplesperpixel) {
-			TIFFError(tif->tif_name,
-			    "%u: Sample out of range, max %u",
-			    sample, td->td_samplesperpixel);
-			return ((tstrip_t) 0);
-		}
-		strip += sample*td->td_stripsperimage;
-	}
-	return (strip);
+        strip = row / td->td_rowsperstrip;
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
+                if (sample >= td->td_samplesperpixel) {
+                        TIFFError(tif->tif_name,
+                            "%u: Sample out of range, max %u",
+                            sample, td->td_samplesperpixel);
+                        return ((tstrip_t) 0);
+                }
+                strip += sample*td->td_stripsperimage;
+        }
+        return (strip);
 }
 
 /*
@@ -61,15 +61,15 @@ TIFFComputeStrip(TIFF* tif, uint32 row, tsample_t sample)
 tstrip_t
 TIFFNumberOfStrips(TIFF* tif)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tstrip_t nstrips;
+        TIFFDirectory *td = &tif->tif_dir;
+        tstrip_t nstrips;
 
-	nstrips = (td->td_rowsperstrip == 0xffffffff ?
-	     (td->td_imagelength != 0 ? 1 : 0) :
-	     howmany(td->td_imagelength, td->td_rowsperstrip));
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
-		nstrips *= td->td_samplesperpixel;
-	return (nstrips);
+        nstrips = (td->td_rowsperstrip == 0xffffffff ?
+             (td->td_imagelength != 0 ? 1 : 0) :
+             howmany(td->td_imagelength, td->td_rowsperstrip));
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
+                nstrips *= td->td_samplesperpixel;
+        return (nstrips);
 }
 
 /*
@@ -78,32 +78,32 @@ TIFFNumberOfStrips(TIFF* tif)
 tsize_t
 TIFFVStripSize(TIFF* tif, uint32 nrows)
 {
-	TIFFDirectory *td = &tif->tif_dir;
+        TIFFDirectory *td = &tif->tif_dir;
 
-	if (nrows == (uint32) -1)
-		nrows = td->td_imagelength;
+        if (nrows == (uint32) -1)
+                nrows = td->td_imagelength;
 #ifdef YCBCR_SUPPORT
-	if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
-	    td->td_photometric == PHOTOMETRIC_YCBCR) {
-		/*
-		 * Packed YCbCr data contain one Cb+Cr for every
-		 * HorizontalSampling*VerticalSampling Y values.
-		 * Must also roundup width and height when calculating
-		 * since images that are not a multiple of the
-		 * horizontal/vertical subsampling area include
-		 * YCbCr data for the extended image.
-		 */
-		tsize_t w =
-		    roundup(td->td_imagewidth, td->td_ycbcrsubsampling[0]);
-		tsize_t scanline = howmany(w*td->td_bitspersample, 8);
-		tsize_t samplingarea =
-		    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
-		nrows = roundup(nrows, td->td_ycbcrsubsampling[1]);
-		/* NB: don't need howmany here 'cuz everything is rounded */
-		return (nrows*scanline + 2*(nrows*scanline / samplingarea));
-	} else
+        if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
+            td->td_photometric == PHOTOMETRIC_YCBCR) {
+                /*
+                 * Packed YCbCr data contain one Cb+Cr for every
+                 * HorizontalSampling*VerticalSampling Y values.
+                 * Must also roundup width and height when calculating
+                 * since images that are not a multiple of the
+                 * horizontal/vertical subsampling area include
+                 * YCbCr data for the extended image.
+                 */
+                tsize_t w =
+                    roundup(td->td_imagewidth, td->td_ycbcrsubsampling[0]);
+                tsize_t scanline = howmany(w*td->td_bitspersample, 8);
+                tsize_t samplingarea =
+                    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
+                nrows = roundup(nrows, td->td_ycbcrsubsampling[1]);
+                /* NB: don't need howmany here 'cuz everything is rounded */
+                return (nrows*scanline + 2*(nrows*scanline / samplingarea));
+        } else
 #endif
-		return (nrows * TIFFScanlineSize(tif));
+                return (nrows * TIFFScanlineSize(tif));
 }
 
 /*
@@ -112,5 +112,5 @@ TIFFVStripSize(TIFF* tif, uint32 nrows)
 tsize_t
 TIFFStripSize(TIFF* tif)
 {
-	return (TIFFVStripSize(tif, tif->tif_dir.td_rowsperstrip));
+        return (TIFFVStripSize(tif, tif->tif_dir.td_rowsperstrip));
 }

+ 38 - 38
panda/src/tiff/tif_swab.c

@@ -37,10 +37,10 @@ static char rcsid[] = "$Header$";
 void
 TIFFSwabShort(uint16* wp)
 {
-	register u_char *cp = (u_char *)wp;
-	int t;
+        register u_char *cp = (u_char *)wp;
+        int t;
 
-	t = cp[1]; cp[1] = cp[0]; cp[0] = t;
+        t = cp[1]; cp[1] = cp[0]; cp[0] = t;
 }
 #endif
 
@@ -48,11 +48,11 @@ TIFFSwabShort(uint16* wp)
 void
 TIFFSwabLong(uint32* lp)
 {
-	register u_char *cp = (u_char *)lp;
-	int t;
+        register u_char *cp = (u_char *)lp;
+        int t;
 
-	t = cp[3]; cp[3] = cp[0]; cp[0] = t;
-	t = cp[2]; cp[2] = cp[1]; cp[1] = t;
+        t = cp[3]; cp[3] = cp[0]; cp[0] = t;
+        t = cp[2]; cp[2] = cp[1]; cp[1] = t;
 }
 #endif
 
@@ -60,15 +60,15 @@ TIFFSwabLong(uint32* lp)
 void
 TIFFSwabArrayOfShort(uint16* wp, register u_long n)
 {
-	register u_char *cp;
-	register int t;
+        register u_char *cp;
+        register int t;
 
-	/* XXX unroll loop some */
-	while (n-- > 0) {
-		cp = (unsigned char *)wp;
-		t = cp[1]; cp[1] = cp[0]; cp[0] = t;
-		wp++;
-	}
+        /* XXX unroll loop some */
+        while (n-- > 0) {
+                cp = (unsigned char *)wp;
+                t = cp[1]; cp[1] = cp[0]; cp[0] = t;
+                wp++;
+        }
 }
 #endif
 
@@ -76,16 +76,16 @@ TIFFSwabArrayOfShort(uint16* wp, register u_long n)
 void
 TIFFSwabArrayOfLong(register uint32* lp, register u_long n)
 {
-	register unsigned char *cp;
-	register int t;
+        register unsigned char *cp;
+        register int t;
 
-	/* XXX unroll loop some */
-	while (n-- > 0) {
-		cp = (unsigned char *)lp;
-		t = cp[3]; cp[3] = cp[0]; cp[0] = t;
-		t = cp[2]; cp[2] = cp[1]; cp[1] = t;
-		lp++;
-	}
+        /* XXX unroll loop some */
+        while (n-- > 0) {
+                cp = (unsigned char *)lp;
+                t = cp[3]; cp[3] = cp[0]; cp[0] = t;
+                t = cp[2]; cp[2] = cp[1]; cp[1] = t;
+                lp++;
+        }
 }
 #endif
 
@@ -170,23 +170,23 @@ static const unsigned char TIFFNoBitRevTable[256] = {
 const unsigned char*
 TIFFGetBitRevTable(int reversed)
 {
-	return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable);
+        return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable);
 }
 
 void
 TIFFReverseBits(register u_char* cp, register u_long n)
 {
-	for (; n > 8; n -= 8) {
-		cp[0] = TIFFBitRevTable[cp[0]];
-		cp[1] = TIFFBitRevTable[cp[1]];
-		cp[2] = TIFFBitRevTable[cp[2]];
-		cp[3] = TIFFBitRevTable[cp[3]];
-		cp[4] = TIFFBitRevTable[cp[4]];
-		cp[5] = TIFFBitRevTable[cp[5]];
-		cp[6] = TIFFBitRevTable[cp[6]];
-		cp[7] = TIFFBitRevTable[cp[7]];
-		cp += 8;
-	}
-	while (n-- > 0)
-		*cp = TIFFBitRevTable[*cp], cp++;
+        for (; n > 8; n -= 8) {
+                cp[0] = TIFFBitRevTable[cp[0]];
+                cp[1] = TIFFBitRevTable[cp[1]];
+                cp[2] = TIFFBitRevTable[cp[2]];
+                cp[3] = TIFFBitRevTable[cp[3]];
+                cp[4] = TIFFBitRevTable[cp[4]];
+                cp[5] = TIFFBitRevTable[cp[5]];
+                cp[6] = TIFFBitRevTable[cp[6]];
+                cp[7] = TIFFBitRevTable[cp[7]];
+                cp += 8;
+        }
+        while (n-- > 0)
+                *cp = TIFFBitRevTable[*cp], cp++;
 }

+ 84 - 84
panda/src/tiff/tif_thunder.c

@@ -43,110 +43,110 @@ static char rcsid[] = "$Header$";
  * or 3-bit delta values are used, with the deltas packed
  * into a single byte.
  */
-#define	THUNDER_DATA		0x3f	/* mask for 6-bit data */
-#define	THUNDER_CODE		0xc0	/* mask for 2-bit code word */
+#define THUNDER_DATA            0x3f    /* mask for 6-bit data */
+#define THUNDER_CODE            0xc0    /* mask for 2-bit code word */
 /* code values */
-#define	THUNDER_RUN		0x00	/* run of pixels w/ encoded count */
-#define	THUNDER_2BITDELTAS	0x40	/* 3 pixels w/ encoded 2-bit deltas */
-#define	    DELTA2_SKIP		2	/* skip code for 2-bit deltas */
-#define	THUNDER_3BITDELTAS	0x80	/* 2 pixels w/ encoded 3-bit deltas */
-#define	    DELTA3_SKIP		4	/* skip code for 3-bit deltas */
-#define	THUNDER_RAW		0xc0	/* raw data encoded */
+#define THUNDER_RUN             0x00    /* run of pixels w/ encoded count */
+#define THUNDER_2BITDELTAS      0x40    /* 3 pixels w/ encoded 2-bit deltas */
+#define     DELTA2_SKIP         2       /* skip code for 2-bit deltas */
+#define THUNDER_3BITDELTAS      0x80    /* 2 pixels w/ encoded 3-bit deltas */
+#define     DELTA3_SKIP         4       /* skip code for 3-bit deltas */
+#define THUNDER_RAW             0xc0    /* raw data encoded */
 
 static const int twobitdeltas[4] = { 0, 1, 0, -1 };
 static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
 
-#define	SETPIXEL(op, v) { \
-	lastpixel = (v) & 0xf; \
-	if (npixels++ & 1) \
-	    *op++ |= lastpixel; \
-	else \
-	    op[0] = lastpixel << 4; \
+#define SETPIXEL(op, v) { \
+        lastpixel = (v) & 0xf; \
+        if (npixels++ & 1) \
+            *op++ |= lastpixel; \
+        else \
+            op[0] = lastpixel << 4; \
 }
 
 static int
 ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
 {
-	register u_char *bp;
-	register tsize_t cc;
-	u_int lastpixel;
-	tsize_t npixels;
+        register u_char *bp;
+        register tsize_t cc;
+        u_int lastpixel;
+        tsize_t npixels;
 
-	bp = (u_char *)tif->tif_rawcp;
-	cc = tif->tif_rawcc;
-	lastpixel = 0;
-	npixels = 0;
-	while (cc > 0 && npixels < maxpixels) {
-		int n, delta;
+        bp = (u_char *)tif->tif_rawcp;
+        cc = tif->tif_rawcc;
+        lastpixel = 0;
+        npixels = 0;
+        while (cc > 0 && npixels < maxpixels) {
+                int n, delta;
 
-		n = *bp++, cc--;
-		switch (n & THUNDER_CODE) {
-		case THUNDER_RUN:		/* pixel run */
-			/*
-			 * Replicate the last pixel n times,
-			 * where n is the lower-order 6 bits.
-			 */
-			if (npixels & 1) {
-				op[0] |= lastpixel;
-				lastpixel = *op++; npixels++; n--;
-			} else
-				lastpixel |= lastpixel << 4;
-			npixels += n;
-			for (; n > 0; n -= 2)
-				*op++ = lastpixel;
-			if (n == -1)
-				*--op &= 0xf0;
-			lastpixel &= 0xf;
-			break;
-		case THUNDER_2BITDELTAS:	/* 2-bit deltas */
-			if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP)
-				SETPIXEL(op, lastpixel + twobitdeltas[delta]);
-			if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP)
-				SETPIXEL(op, lastpixel + twobitdeltas[delta]);
-			if ((delta = (n & 3)) != DELTA2_SKIP)
-				SETPIXEL(op, lastpixel + twobitdeltas[delta]);
-			break;
-		case THUNDER_3BITDELTAS:	/* 3-bit deltas */
-			if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP)
-				SETPIXEL(op, lastpixel + threebitdeltas[delta]);
-			if ((delta = (n & 7)) != DELTA3_SKIP)
-				SETPIXEL(op, lastpixel + threebitdeltas[delta]);
-			break;
-		case THUNDER_RAW:		/* raw data */
-			SETPIXEL(op, n);
-			break;
-		}
-	}
-	tif->tif_rawcp = (tidata_t) bp;
-	tif->tif_rawcc = cc;
-	if (npixels != maxpixels) {
-		TIFFError(tif->tif_name,
-		    "ThunderDecode: %s data at scanline %ld (%lu != %lu)",
-		    npixels < maxpixels ? "Not enough" : "Too much",
-		    (long) tif->tif_row, (long) npixels, (long) maxpixels);
-		return (0);
-	}
-	return (1);
+                n = *bp++, cc--;
+                switch (n & THUNDER_CODE) {
+                case THUNDER_RUN:               /* pixel run */
+                        /*
+                         * Replicate the last pixel n times,
+                         * where n is the lower-order 6 bits.
+                         */
+                        if (npixels & 1) {
+                                op[0] |= lastpixel;
+                                lastpixel = *op++; npixels++; n--;
+                        } else
+                                lastpixel |= lastpixel << 4;
+                        npixels += n;
+                        for (; n > 0; n -= 2)
+                                *op++ = lastpixel;
+                        if (n == -1)
+                                *--op &= 0xf0;
+                        lastpixel &= 0xf;
+                        break;
+                case THUNDER_2BITDELTAS:        /* 2-bit deltas */
+                        if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP)
+                                SETPIXEL(op, lastpixel + twobitdeltas[delta]);
+                        if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP)
+                                SETPIXEL(op, lastpixel + twobitdeltas[delta]);
+                        if ((delta = (n & 3)) != DELTA2_SKIP)
+                                SETPIXEL(op, lastpixel + twobitdeltas[delta]);
+                        break;
+                case THUNDER_3BITDELTAS:        /* 3-bit deltas */
+                        if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP)
+                                SETPIXEL(op, lastpixel + threebitdeltas[delta]);
+                        if ((delta = (n & 7)) != DELTA3_SKIP)
+                                SETPIXEL(op, lastpixel + threebitdeltas[delta]);
+                        break;
+                case THUNDER_RAW:               /* raw data */
+                        SETPIXEL(op, n);
+                        break;
+                }
+        }
+        tif->tif_rawcp = (tidata_t) bp;
+        tif->tif_rawcc = cc;
+        if (npixels != maxpixels) {
+                TIFFError(tif->tif_name,
+                    "ThunderDecode: %s data at scanline %ld (%lu != %lu)",
+                    npixels < maxpixels ? "Not enough" : "Too much",
+                    (long) tif->tif_row, (long) npixels, (long) maxpixels);
+                return (0);
+        }
+        return (1);
 }
 
 static int
 ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
-	tidata_t row = buf;
-	
-	while ((long)occ > 0) {
-		if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth))
-			return (0);
-		occ -= tif->tif_scanlinesize;
-		row += tif->tif_scanlinesize;
-	}
-	return (1);
+        tidata_t row = buf;
+
+        while ((long)occ > 0) {
+                if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth))
+                        return (0);
+                occ -= tif->tif_scanlinesize;
+                row += tif->tif_scanlinesize;
+        }
+        return (1);
 }
 
 int
 TIFFInitThunderScan(TIFF* tif)
 {
-	tif->tif_decoderow = ThunderDecodeRow;
-	tif->tif_decodestrip = ThunderDecodeRow;
-	return (1);
+        tif->tif_decoderow = ThunderDecodeRow;
+        tif->tif_decodestrip = ThunderDecodeRow;
+        return (1);
 }

+ 103 - 103
panda/src/tiff/tif_tile.c

@@ -39,34 +39,34 @@ static char rcsid[] = "$Header$";
 ttile_t
 TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	u_long dx = td->td_tilewidth;
-	u_long dy = td->td_tilelength;
-	u_long dz = td->td_tiledepth;
-	ttile_t tile = 1;
+        TIFFDirectory *td = &tif->tif_dir;
+        u_long dx = td->td_tilewidth;
+        u_long dy = td->td_tilelength;
+        u_long dz = td->td_tiledepth;
+        ttile_t tile = 1;
 
-	if (td->td_imagedepth == 1)
-		z = 0;
-	if (dx == (u_long) -1)
-		dx = td->td_imagewidth;
-	if (dy == (u_long) -1)
-		dy = td->td_imagelength;
-	if (dz == (u_long) -1)
-		dz = td->td_imagedepth;
-	if (dx != 0 && dy != 0 && dz != 0) {
-		u_long xpt = howmany(td->td_imagewidth, dx); 
-		u_long ypt = howmany(td->td_imagelength, dy); 
-		u_long zpt = howmany(td->td_imagedepth, dz); 
+        if (td->td_imagedepth == 1)
+                z = 0;
+        if (dx == (u_long) -1)
+                dx = td->td_imagewidth;
+        if (dy == (u_long) -1)
+                dy = td->td_imagelength;
+        if (dz == (u_long) -1)
+                dz = td->td_imagedepth;
+        if (dx != 0 && dy != 0 && dz != 0) {
+                u_long xpt = howmany(td->td_imagewidth, dx); 
+                u_long ypt = howmany(td->td_imagelength, dy); 
+                u_long zpt = howmany(td->td_imagedepth, dz); 
 
-		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) 
-			tile = (xpt*ypt*zpt)*s +
-			     (xpt*ypt)*(z/dz) +
-			     xpt*(y/dy) +
-			     x/dx;
-		else
-			tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx + s;
-	}
-	return (tile);
+                if (td->td_planarconfig == PLANARCONFIG_SEPARATE) 
+                        tile = (xpt*ypt*zpt)*s +
+                             (xpt*ypt)*(z/dz) +
+                             xpt*(y/dy) +
+                             x/dx;
+                else
+                        tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx + s;
+        }
+        return (tile);
 }
 
 /*
@@ -75,30 +75,30 @@ TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
  */
 TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
 {
-	TIFFDirectory *td = &tif->tif_dir;
+        TIFFDirectory *td = &tif->tif_dir;
 
-	if (x >= td->td_imagewidth) {
-		TIFFError(tif->tif_name, "Col %ld out of range, max %lu",
-		    (long) x, (u_long) td->td_imagewidth);
-		return (0);
-	}
-	if (y >= td->td_imagelength) {
-		TIFFError(tif->tif_name, "Row %ld out of range, max %lu",
-		    (long) y, (u_long) td->td_imagelength);
-		return (0);
-	}
-	if (z >= td->td_imagedepth) {
-		TIFFError(tif->tif_name, "Depth %ld out of range, max %lu",
-		    (long) z, (u_long) td->td_imagedepth);
-		return (0);
-	}
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE &&
-	    s >= td->td_samplesperpixel) {
-		TIFFError(tif->tif_name, "Sample %d out of range, max %u",
-		    (int) s, td->td_samplesperpixel);
-		return (0);
-	}
-	return (1);
+        if (x >= td->td_imagewidth) {
+                TIFFError(tif->tif_name, "Col %ld out of range, max %lu",
+                    (long) x, (u_long) td->td_imagewidth);
+                return (0);
+        }
+        if (y >= td->td_imagelength) {
+                TIFFError(tif->tif_name, "Row %ld out of range, max %lu",
+                    (long) y, (u_long) td->td_imagelength);
+                return (0);
+        }
+        if (z >= td->td_imagedepth) {
+                TIFFError(tif->tif_name, "Depth %ld out of range, max %lu",
+                    (long) z, (u_long) td->td_imagedepth);
+                return (0);
+        }
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE &&
+            s >= td->td_samplesperpixel) {
+                TIFFError(tif->tif_name, "Sample %d out of range, max %u",
+                    (int) s, td->td_samplesperpixel);
+                return (0);
+        }
+        return (1);
 }
 
 /*
@@ -107,25 +107,25 @@ TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
 ttile_t
 TIFFNumberOfTiles(TIFF* tif)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	u_long dx = td->td_tilewidth;
-	u_long dy = td->td_tilelength;
-	u_long dz = td->td_tiledepth;
-	ttile_t ntiles;
+        TIFFDirectory *td = &tif->tif_dir;
+        u_long dx = td->td_tilewidth;
+        u_long dy = td->td_tilelength;
+        u_long dz = td->td_tiledepth;
+        ttile_t ntiles;
 
-	if (dx == (u_long) -1)
-		dx = td->td_imagewidth;
-	if (dy == (u_long) -1)
-		dy = td->td_imagelength;
-	if (dz == (u_long) -1)
-		dz = td->td_imagedepth;
-	ntiles = (dx != 0 && dy != 0 && dz != 0) ?
-	    (howmany(td->td_imagewidth, dx) * howmany(td->td_imagelength, dy) *
-		howmany(td->td_imagedepth, dz)) :
-	    0;
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
-		ntiles *= td->td_samplesperpixel;
-	return (ntiles);
+        if (dx == (u_long) -1)
+                dx = td->td_imagewidth;
+        if (dy == (u_long) -1)
+                dy = td->td_imagelength;
+        if (dz == (u_long) -1)
+                dz = td->td_imagedepth;
+        ntiles = (dx != 0 && dy != 0 && dz != 0) ?
+            (howmany(td->td_imagewidth, dx) * howmany(td->td_imagelength, dy) *
+                howmany(td->td_imagedepth, dz)) :
+            0;
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
+                ntiles *= td->td_samplesperpixel;
+        return (ntiles);
 }
 
 /*
@@ -134,15 +134,15 @@ TIFFNumberOfTiles(TIFF* tif)
 tsize_t
 TIFFTileRowSize(TIFF* tif)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t rowsize;
-	
-	if (td->td_tilelength == 0 || td->td_tilewidth == 0)
-		return ((tsize_t) 0);
-	rowsize = td->td_bitspersample * td->td_tilewidth;
-	if (td->td_planarconfig == PLANARCONFIG_CONTIG)
-		rowsize *= td->td_samplesperpixel;
-	return (howmany(rowsize, 8));
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t rowsize;
+
+        if (td->td_tilelength == 0 || td->td_tilewidth == 0)
+                return ((tsize_t) 0);
+        rowsize = td->td_bitspersample * td->td_tilewidth;
+        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
+                rowsize *= td->td_samplesperpixel;
+        return (howmany(rowsize, 8));
 }
 
 /*
@@ -151,35 +151,35 @@ TIFFTileRowSize(TIFF* tif)
 tsize_t
 TIFFVTileSize(TIFF* tif, uint32 nrows)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	tsize_t tilesize;
+        TIFFDirectory *td = &tif->tif_dir;
+        tsize_t tilesize;
 
-	if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
-	    td->td_tiledepth == 0)
-		return ((tsize_t) 0);
+        if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
+            td->td_tiledepth == 0)
+                return ((tsize_t) 0);
 #ifdef YCBCR_SUPPORT
-	if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
-	    td->td_photometric == PHOTOMETRIC_YCBCR) {
-		/*
-		 * Packed YCbCr data contain one Cb+Cr for every
-		 * HorizontalSampling*VerticalSampling Y values.
-		 * Must also roundup width and height when calculating
-		 * since images that are not a multiple of the
-		 * horizontal/vertical subsampling area include
-		 * YCbCr data for the extended image.
-		 */
-		tsize_t w =
-		    roundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]);
-		tsize_t rowsize = howmany(w*td->td_bitspersample, 8);
-		tsize_t samplingarea =
-		    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
-		nrows = roundup(nrows, td->td_ycbcrsubsampling[1]);
-		/* NB: don't need howmany here 'cuz everything is rounded */
-		tilesize = nrows*rowsize + 2*(nrows*rowsize / samplingarea);
-	} else
+        if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
+            td->td_photometric == PHOTOMETRIC_YCBCR) {
+                /*
+                 * Packed YCbCr data contain one Cb+Cr for every
+                 * HorizontalSampling*VerticalSampling Y values.
+                 * Must also roundup width and height when calculating
+                 * since images that are not a multiple of the
+                 * horizontal/vertical subsampling area include
+                 * YCbCr data for the extended image.
+                 */
+                tsize_t w =
+                    roundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]);
+                tsize_t rowsize = howmany(w*td->td_bitspersample, 8);
+                tsize_t samplingarea =
+                    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
+                nrows = roundup(nrows, td->td_ycbcrsubsampling[1]);
+                /* NB: don't need howmany here 'cuz everything is rounded */
+                tilesize = nrows*rowsize + 2*(nrows*rowsize / samplingarea);
+        } else
 #endif
-		tilesize = nrows * TIFFTileRowSize(tif);
-	return (tilesize * td->td_tiledepth);
+                tilesize = nrows * TIFFTileRowSize(tif);
+        return (tilesize * td->td_tiledepth);
 }
 
 /*
@@ -188,5 +188,5 @@ TIFFVTileSize(TIFF* tif, uint32 nrows)
 tsize_t
 TIFFTileSize(TIFF* tif)
 {
-	return (TIFFVTileSize(tif, tif->tif_dir.td_tilelength));
+        return (TIFFVTileSize(tif, tif->tif_dir.td_tilelength));
 }

+ 45 - 45
panda/src/tiff/tif_unix.c

@@ -35,25 +35,25 @@ static char rcsid[] = "$Header$";
 static tsize_t
 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (read((int) fd, buf, (size_t) size));
+        return (read((int) fd, buf, (size_t) size));
 }
 
 static tsize_t
 _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (write((int) fd, buf, (size_t) size));
+        return (write((int) fd, buf, (size_t) size));
 }
 
 static toff_t
 _tiffSeekProc(thandle_t fd, off_t off, int whence)
 {
-	return ((toff_t) lseek((int) fd, (off_t) off, whence));
+        return ((toff_t) lseek((int) fd, (off_t) off, whence));
 }
 
 static int
 _tiffCloseProc(thandle_t fd)
 {
-	return (close((int) fd));
+        return (close((int) fd));
 }
 
 #include <sys/stat.h>
@@ -62,11 +62,11 @@ static toff_t
 _tiffSizeProc(thandle_t fd)
 {
 #ifdef _AM29K
-	long fsize;
-	return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize);
+        long fsize;
+        return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize);
 #else
-	struct stat sb;
-	return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
+        struct stat sb;
+        return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
 #endif
 }
 
@@ -76,28 +76,28 @@ _tiffSizeProc(thandle_t fd)
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	toff_t size = _tiffSizeProc(fd);
-	if (size != (toff_t) -1) {
-		*pbase = (tdata_t)
-		    mmap(0, size, PROT_READ, MAP_SHARED, (int) fd, 0);
-		if (*pbase != (tdata_t) -1) {
-			*psize = size;
-			return (1);
-		}
-	}
-	return (0);
+        toff_t size = _tiffSizeProc(fd);
+        if (size != (toff_t) -1) {
+                *pbase = (tdata_t)
+                    mmap(0, size, PROT_READ, MAP_SHARED, (int) fd, 0);
+                if (*pbase != (tdata_t) -1) {
+                        *psize = size;
+                        return (1);
+                }
+        }
+        return (0);
 }
 
 static void
 _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 {
-	(void) munmap(base, (off_t) size);
+        (void) munmap(base, (off_t) size);
 }
 #else /* !MMAP_SUPPORT */
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	return (0);
+        return (0);
 }
 
 static void
@@ -112,16 +112,16 @@ _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 TIFF*
 TIFFFdOpen(int fd, const char* name, const char* mode)
 {
-	TIFF* tif;
-
-	tif = TIFFClientOpen(name, mode,
-	    (thandle_t) fd,
-	    _tiffReadProc, _tiffWriteProc,
-	    _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
-	    _tiffMapProc, _tiffUnmapProc);
-	if (tif)
-		tif->tif_fd = fd;
-	return (tif);
+        TIFF* tif;
+
+        tif = TIFFClientOpen(name, mode,
+            (thandle_t) fd,
+            _tiffReadProc, _tiffWriteProc,
+            _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
+            _tiffMapProc, _tiffUnmapProc);
+        if (tif)
+                tif->tif_fd = fd;
+        return (tif);
 }
 
 /*
@@ -130,38 +130,38 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
 TIFF*
 TIFFOpen(const char* name, const char* mode)
 {
-	static const char module[] = "TIFFOpen";
-	int m, fd;
+        static const char module[] = "TIFFOpen";
+        int m, fd;
 
-	m = _TIFFgetMode(mode, module);
-	if (m == -1)
-		return ((TIFF*)0);
+        m = _TIFFgetMode(mode, module);
+        if (m == -1)
+                return ((TIFF*)0);
 #ifdef _AM29K
-	fd = open(name, m);
+        fd = open(name, m);
 #else
-	fd = open(name, m, 0666);
+        fd = open(name, m, 0666);
 #endif
-	if (fd < 0) {
-		TIFFError(module, "%s: Cannot open", name);
-		return ((TIFF *)0);
-	}
-	return (TIFFFdOpen(fd, name, mode));
+        if (fd < 0) {
+                TIFFError(module, "%s: Cannot open", name);
+                return ((TIFF *)0);
+        }
+        return (TIFFFdOpen(fd, name, mode));
 }
 
 void*
 _TIFFmalloc(size_t s)
 {
-	return (malloc(s));
+        return (malloc(s));
 }
 
 void
 _TIFFfree(void* p)
 {
-	free(p);
+        free(p);
 }
 
 void*
 _TIFFrealloc(void* p, size_t s)
 {
-	return (realloc(p, s));
+        return (realloc(p, s));
 }

+ 1 - 1
panda/src/tiff/tif_version.c

@@ -32,5 +32,5 @@ Copyright (c) 1991, 1992 Silicon Graphics, Inc.\
 const char*
 TIFFGetVersion(void)
 {
-	return (TIFFVersion);
+        return (TIFFVersion);
 }

+ 109 - 109
panda/src/tiff/tif_vms.c

@@ -34,25 +34,25 @@ static char rcsid[] = "$Header$";
 static tsize_t
 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
 {
-	return (read((int) fd, buf, size));
+        return (read((int) fd, buf, size));
 }
 
 static tsize_t
 _tiffWriteProc(thandle_t fd, tdata_t buf, u_long size)
 {
-	return (write((int) fd, buf, size));
+        return (write((int) fd, buf, size));
 }
 
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
-	return ((toff_t) lseek((int) fd, (off_t) off, whence));
+        return ((toff_t) lseek((int) fd, (off_t) off, whence));
 }
 
 static int
 _tiffCloseProc(thandle_t fd)
 {
-	return (close((int) fd));
+        return (close((int) fd));
 }
 
 #include <sys/stat.h>
@@ -60,8 +60,8 @@ _tiffCloseProc(thandle_t fd)
 static toff_t
 _tiffSizeProc(thandle_t fd)
 {
-	struct stat sb;
-	return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
+        struct stat sb;
+        return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
 }
 
 #ifdef MMAP_SUPPORT
@@ -75,9 +75,9 @@ _tiffSizeProc(thandle_t fd)
 #define MAX_MAPPED 100
 static int no_mapped = 0;
 static struct {
-	char *base;
-	char *top;
-	unsigned short channel;
+        char *base;
+        char *top;
+        unsigned short channel;
 } map_table[MAX_MAPPED];
 
 /* 
@@ -96,55 +96,55 @@ static struct {
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	char name[256];
-	struct FAB fab;
-	unsigned short channel;
-	char *inadr[2], *retadr[2];
-	unsigned long status;
-	long size;
-	
-	if (no_mapped >= MAX_MAPPED)
-		return(0);
-	/*
-	 * We cannot use a file descriptor, we
-	 * must open the file once more.
-	 */
-	if (getname(fd, name, 1) == NULL)
-		return(0);
-	/* prepare the FAB for a user file open */
-	fab = cc$rms_fab;
-	fab.fab$v_ufo = 1;
-	fab.fab$b_fac = FAB$M_GET;
-	fab.fab$b_shr = FAB$M_SHRGET;
-	fab.fab$l_fna = name;
-	fab.fab$b_fns = strlen(name);
-	status = sys$open(&fab);	/* open file & get channel number */
-	if ((status&1) == 0)
-		return(0);
-	channel = (unsigned short)fab.fab$l_stv;
-	inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */
-	/*
-	 * Map the blocks of the file up to
-	 * the EOF block into virtual memory.
-	 */
-	size = _tiffSizeProc(fd);
-	status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel,
-		howmany(size,512), 0,0,0);
-	if ((status&1) == 0){
-		sys$dassgn(channel);
-		return(0);
-	}
-	*pbase = (tdata_t) retadr[0];	/* starting virtual address */
-	/*
-	 * Use the size of the file up to the
-	 * EOF mark for UNIX compatibility.
-	 */
-	*psize = (toff_t) size;
-	/* Record the section in the table */
-	map_table[no_mapped].base = retadr[0];
-	map_table[no_mapped].top = retadr[1];
-	map_table[no_mapped].channel = channel;
-	no_mapped++;
+        char name[256];
+        struct FAB fab;
+        unsigned short channel;
+        char *inadr[2], *retadr[2];
+        unsigned long status;
+        long size;
+
+        if (no_mapped >= MAX_MAPPED)
+                return(0);
+        /*
+         * We cannot use a file descriptor, we
+         * must open the file once more.
+         */
+        if (getname(fd, name, 1) == NULL)
+                return(0);
+        /* prepare the FAB for a user file open */
+        fab = cc$rms_fab;
+        fab.fab$v_ufo = 1;
+        fab.fab$b_fac = FAB$M_GET;
+        fab.fab$b_shr = FAB$M_SHRGET;
+        fab.fab$l_fna = name;
+        fab.fab$b_fns = strlen(name);
+        status = sys$open(&fab);        /* open file & get channel number */
+        if ((status&1) == 0)
+                return(0);
+        channel = (unsigned short)fab.fab$l_stv;
+        inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */
+        /*
+         * Map the blocks of the file up to
+         * the EOF block into virtual memory.
+         */
+        size = _tiffSizeProc(fd);
+        status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel,
+                howmany(size,512), 0,0,0);
+        if ((status&1) == 0){
+                sys$dassgn(channel);
+                return(0);
+        }
+        *pbase = (tdata_t) retadr[0];   /* starting virtual address */
+        /*
+         * Use the size of the file up to the
+         * EOF mark for UNIX compatibility.
+         */
+        *psize = (toff_t) size;
+        /* Record the section in the table */
+        map_table[no_mapped].base = retadr[0];
+        map_table[no_mapped].top = retadr[1];
+        map_table[no_mapped].channel = channel;
+        no_mapped++;
 
         return(1);
 }
@@ -157,30 +157,30 @@ _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 static void
 _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 {
-	char *inadr[2];
-	int i, j;
-	
-	/* Find the section in the table */
-	for (i = 0;i < no_mapped; i++) {
-		if (map_table[i].base == (char *) base) {
-			/* Unmap the section */
-			inadr[0] = (char *) base;
-			inadr[1] = map_table[i].top;
-			sys$deltva(inadr, 0, 0);
-			sys$dassgn(map_table[i].channel);
-			/* Remove this section from the list */
-			for (j = i+1; j < no_mapped; j++)
-				map_table[j-1] = map_table[j];
-			no_mapped--;
-			return;
-		}
-	}
+        char *inadr[2];
+        int i, j;
+
+        /* Find the section in the table */
+        for (i = 0;i < no_mapped; i++) {
+                if (map_table[i].base == (char *) base) {
+                        /* Unmap the section */
+                        inadr[0] = (char *) base;
+                        inadr[1] = map_table[i].top;
+                        sys$deltva(inadr, 0, 0);
+                        sys$dassgn(map_table[i].channel);
+                        /* Remove this section from the list */
+                        for (j = i+1; j < no_mapped; j++)
+                                map_table[j-1] = map_table[j];
+                        no_mapped--;
+                        return;
+                }
+        }
 }
 #else /* !MMAP_SUPPORT */
 static int
 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
-	return (0);
+        return (0);
 }
 
 static void
@@ -195,15 +195,15 @@ _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 TIFF*
 TIFFFdOpen(int fd, const char* name, const char* mode)
 {
-	TIFF* tif;
+        TIFF* tif;
 
-	tif = TIFFClientOpen(name, mode,
-	    (thandle_t) fd,
-	    _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
-	    _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
-	if (tif)
-		tif->tif_fd = fd;
-	return (tif);
+        tif = TIFFClientOpen(name, mode,
+            (thandle_t) fd,
+            _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
+            _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
+        if (tif)
+                tif->tif_fd = fd;
+        return (tif);
 }
 
 /*
@@ -212,48 +212,48 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
 TIFF*
 TIFFOpen(const char* name, const char* mode)
 {
-	static const char module[] = "TIFFOpen";
-	int m, fd;
+        static const char module[] = "TIFFOpen";
+        int m, fd;
 
-	m = _TIFFgetMode(mode, module);
-	if (m == -1)
-		return ((TIFF*)0);
+        m = _TIFFgetMode(mode, module);
+        if (m == -1)
+                return ((TIFF*)0);
         if (m&O_TRUNC){
                 /*
-		 * There is a bug in open in VAXC. If you use
-		 * open w/ m=O_RDWR|O_CREAT|O_TRUNC the
-		 * wrong thing happens.  On the other hand
-		 * creat does the right thing.
+                 * There is a bug in open in VAXC. If you use
+                 * open w/ m=O_RDWR|O_CREAT|O_TRUNC the
+                 * wrong thing happens.  On the other hand
+                 * creat does the right thing.
                  */
                 fd = creat(name, 0666,
-		    "alq = 128", "deq = 64", "mbc = 32",
-		    "fop = tef", "ctx = stm");
-	} else if (m&O_RDWR) {
-		fd = open(name, m, 0666,
-		    "deq = 64", "mbc = 32", "fop = tef", "ctx = stm");
-	} else
-		fd = open(name, m, 0666, "mbc = 32");
-	if (fd < 0) {
-		TIFFError(module, "%s: Cannot open", name);
-		return ((TIFF*)0);
-	}
-	return (TIFFFdOpen(fd, name, mode));
+                    "alq = 128", "deq = 64", "mbc = 32",
+                    "fop = tef", "ctx = stm");
+        } else if (m&O_RDWR) {
+                fd = open(name, m, 0666,
+                    "deq = 64", "mbc = 32", "fop = tef", "ctx = stm");
+        } else
+                fd = open(name, m, 0666, "mbc = 32");
+        if (fd < 0) {
+                TIFFError(module, "%s: Cannot open", name);
+                return ((TIFF*)0);
+        }
+        return (TIFFFdOpen(fd, name, mode));
 }
 
 void*
 _TIFFmalloc(size_t s)
 {
-	return (malloc(s));
+        return (malloc(s));
 }
 
 void
 _TIFFfree(void* p)
 {
-	free(p);
+        free(p);
 }
 
 void*
 _TIFFrealloc(void* p, size_t s)
 {
-	return (realloc(p, s));
+        return (realloc(p, s));
 }

+ 14 - 14
panda/src/tiff/tif_warning.c

@@ -35,11 +35,11 @@ static char rcsid[] = "$Header$";
 static void
 defaultHandler(const char* module, const char* fmt, va_list ap)
 {
-	if (module != NULL)
-		fprintf(stderr, "%s: ", module);
-	fprintf(stderr, "Warning, ");
-	vfprintf(stderr, fmt, ap);
-	fprintf(stderr, ".\n");
+        if (module != NULL)
+                fprintf(stderr, "%s: ", module);
+        fprintf(stderr, "Warning, ");
+        vfprintf(stderr, fmt, ap);
+        fprintf(stderr, ".\n");
 }
 
 static TIFFErrorHandler _warningHandler = defaultHandler;
@@ -47,18 +47,18 @@ static TIFFErrorHandler _warningHandler = defaultHandler;
 TIFFErrorHandler
 TIFFSetWarningHandler(TIFFErrorHandler handler)
 {
-	TIFFErrorHandler prev = _warningHandler;
-	_warningHandler = handler;
-	return (prev);
+        TIFFErrorHandler prev = _warningHandler;
+        _warningHandler = handler;
+        return (prev);
 }
 
 void
 TIFFWarning(const char* module, const char* fmt, ...)
 {
-	if (_warningHandler) {
-		va_list ap;
-		va_start(ap, fmt);
-		(*_warningHandler)(module, fmt, ap);
-		va_end(ap);
-	}
+        if (_warningHandler) {
+                va_list ap;
+                va_start(ap, fmt);
+                (*_warningHandler)(module, fmt, ap);
+                va_end(ap);
+        }
 }

+ 379 - 379
panda/src/tiff/tif_write.c

@@ -35,125 +35,125 @@ static char rcsid[] = "$Header$";
 #include <assert.h>
 #include <stdio.h>
 
-#define	STRIPINCR	20		/* expansion factor on strip array */
+#define STRIPINCR       20              /* expansion factor on strip array */
 
-static	int TIFFWriteCheck(TIFF*, int, const char*);
-static	int TIFFBufferSetup(TIFF*, const char*);
-static	int TIFFGrowStrips(TIFF*, int, const char*);
-static	int TIFFAppendToStrip(TIFF*, tstrip_t, tidata_t, tsize_t);
-static	int TIFFSetupStrips(TIFF*);
+static  int TIFFWriteCheck(TIFF*, int, const char*);
+static  int TIFFBufferSetup(TIFF*, const char*);
+static  int TIFFGrowStrips(TIFF*, int, const char*);
+static  int TIFFAppendToStrip(TIFF*, tstrip_t, tidata_t, tsize_t);
+static  int TIFFSetupStrips(TIFF*);
 
 int
 TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
 {
-	static const char module[] = "TIFFWriteScanline";
-	register TIFFDirectory *td;
-	int status, imagegrew = 0;
-	tstrip_t strip;
+        static const char module[] = "TIFFWriteScanline";
+        register TIFFDirectory *td;
+        int status, imagegrew = 0;
+        tstrip_t strip;
 
-	if (!TIFFWriteCheck(tif, 0, module))
-		return (-1);
-	/*
-	 * Handle delayed allocation of data buffer.  This
-	 * permits it to be sized more intelligently (using
-	 * directory information).
-	 */
-	if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
-		if (!TIFFBufferSetup(tif, module))
-			return (-1);
-		tif->tif_flags |= TIFF_BUFFERSETUP;
-	}
-	td = &tif->tif_dir;
-	/*
-	 * Extend image length if needed
-	 * (but only for PlanarConfig=1).
-	 */
-	if (row >= td->td_imagelength) {	/* extend image */
-		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
-			TIFFError(tif->tif_name,
-		"Can not change \"ImageLength\" when using separate planes");
-			return (-1);
-		}
-		td->td_imagelength = row+1;
-		imagegrew = 1;
-	}
-	/*
-	 * Calculate strip and check for crossings.
-	 */
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
-		if (sample >= td->td_samplesperpixel) {
-			TIFFError(tif->tif_name,
-			    "%d: Sample out of range, max %d",
-			    sample, td->td_samplesperpixel);
-			return (-1);
-		}
-		strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
-	} else
-		strip = row / td->td_rowsperstrip;
-	if (strip != tif->tif_curstrip) {
-		/*
-		 * Changing strips -- flush any data present.
-		 */
-		if (!TIFFFlushData(tif))
-			return (-1);
-		tif->tif_curstrip = strip;
-		/*
-		 * Watch out for a growing image.  The value of
-		 * strips/image will initially be 1 (since it
-		 * can't be deduced until the imagelength is known).
-		 */
-		if (strip >= td->td_stripsperimage && imagegrew)
-			td->td_stripsperimage =
-			    howmany(td->td_imagelength, td->td_rowsperstrip);
-		tif->tif_row =
-		    (strip % td->td_stripsperimage) * td->td_rowsperstrip;
-		if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
-			return (-1);
-		tif->tif_flags |= TIFF_POSTENCODE;
-	}
-	/*
-	 * Check strip array to make sure there's space.
-	 * We don't support dynamically growing files that
-	 * have data organized in separate bitplanes because
-	 * it's too painful.  In that case we require that
-	 * the imagelength be set properly before the first
-	 * write (so that the strips array will be fully
-	 * allocated above).
-	 */
-	if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))
-		return (-1);
-	/*
-	 * Ensure the write is either sequential or at the
-	 * beginning of a strip (or that we can randomly
-	 * access the data -- i.e. no encoding).
-	 */
-	if (row != tif->tif_row) {
-		if (tif->tif_seek) {
-			if (row < tif->tif_row) {
-				/*
-				 * Moving backwards within the same strip:
-				 * backup to the start and then decode
-				 * forward (below).
-				 */
-				tif->tif_row = (strip % td->td_stripsperimage) *
-				    td->td_rowsperstrip;
-				tif->tif_rawcp = tif->tif_rawdata;
-			}
-			/*
-			 * Seek forward to the desired row.
-			 */
-			if (!(*tif->tif_seek)(tif, row - tif->tif_row))
-				return (-1);
-			tif->tif_row = row;
-		} else {
-			TIFFError(tif->tif_name,
-		    "Compression algorithm does not support random access");
-			return (-1);
-		}
-	}
-	status = (*tif->tif_encoderow)(tif, buf, tif->tif_scanlinesize, sample);
-	tif->tif_row++;
-	return (status);
+        if (!TIFFWriteCheck(tif, 0, module))
+                return (-1);
+        /*
+         * Handle delayed allocation of data buffer.  This
+         * permits it to be sized more intelligently (using
+         * directory information).
+         */
+        if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
+                if (!TIFFBufferSetup(tif, module))
+                        return (-1);
+                tif->tif_flags |= TIFF_BUFFERSETUP;
+        }
+        td = &tif->tif_dir;
+        /*
+         * Extend image length if needed
+         * (but only for PlanarConfig=1).
+         */
+        if (row >= td->td_imagelength) {        /* extend image */
+                if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
+                        TIFFError(tif->tif_name,
+                "Can not change \"ImageLength\" when using separate planes");
+                        return (-1);
+                }
+                td->td_imagelength = row+1;
+                imagegrew = 1;
+        }
+        /*
+         * Calculate strip and check for crossings.
+         */
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
+                if (sample >= td->td_samplesperpixel) {
+                        TIFFError(tif->tif_name,
+                            "%d: Sample out of range, max %d",
+                            sample, td->td_samplesperpixel);
+                        return (-1);
+                }
+                strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
+        } else
+                strip = row / td->td_rowsperstrip;
+        if (strip != tif->tif_curstrip) {
+                /*
+                 * Changing strips -- flush any data present.
+                 */
+                if (!TIFFFlushData(tif))
+                        return (-1);
+                tif->tif_curstrip = strip;
+                /*
+                 * Watch out for a growing image.  The value of
+                 * strips/image will initially be 1 (since it
+                 * can't be deduced until the imagelength is known).
+                 */
+                if (strip >= td->td_stripsperimage && imagegrew)
+                        td->td_stripsperimage =
+                            howmany(td->td_imagelength, td->td_rowsperstrip);
+                tif->tif_row =
+                    (strip % td->td_stripsperimage) * td->td_rowsperstrip;
+                if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
+                        return (-1);
+                tif->tif_flags |= TIFF_POSTENCODE;
+        }
+        /*
+         * Check strip array to make sure there's space.
+         * We don't support dynamically growing files that
+         * have data organized in separate bitplanes because
+         * it's too painful.  In that case we require that
+         * the imagelength be set properly before the first
+         * write (so that the strips array will be fully
+         * allocated above).
+         */
+        if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))
+                return (-1);
+        /*
+         * Ensure the write is either sequential or at the
+         * beginning of a strip (or that we can randomly
+         * access the data -- i.e. no encoding).
+         */
+        if (row != tif->tif_row) {
+                if (tif->tif_seek) {
+                        if (row < tif->tif_row) {
+                                /*
+                                 * Moving backwards within the same strip:
+                                 * backup to the start and then decode
+                                 * forward (below).
+                                 */
+                                tif->tif_row = (strip % td->td_stripsperimage) *
+                                    td->td_rowsperstrip;
+                                tif->tif_rawcp = tif->tif_rawdata;
+                        }
+                        /*
+                         * Seek forward to the desired row.
+                         */
+                        if (!(*tif->tif_seek)(tif, row - tif->tif_row))
+                                return (-1);
+                        tif->tif_row = row;
+                } else {
+                        TIFFError(tif->tif_name,
+                    "Compression algorithm does not support random access");
+                        return (-1);
+                }
+        }
+        status = (*tif->tif_encoderow)(tif, buf, tif->tif_scanlinesize, sample);
+        tif->tif_row++;
+        return (status);
 }
 
 /*
@@ -168,44 +168,44 @@ TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
 tsize_t
 TIFFWriteEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc)
 {
-	static const char module[] = "TIFFWriteEncodedStrip";
-	TIFFDirectory *td = &tif->tif_dir;
+        static const char module[] = "TIFFWriteEncodedStrip";
+        TIFFDirectory *td = &tif->tif_dir;
 
-	if (!TIFFWriteCheck(tif, 0, module))
-		return ((tsize_t) -1);
-	if (strip >= td->td_nstrips) {
-		TIFFError(module, "%s: Strip %lu out of range, max %lu",
-		    tif->tif_name, (u_long) strip, (u_long) td->td_nstrips);
-		return ((tsize_t) -1);
-	}
-	/*
-	 * Handle delayed allocation of data buffer.  This
-	 * permits it to be sized according to the directory
-	 * info.
-	 */
-	if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
-		if (!TIFFBufferSetup(tif, module))
-			return ((tsize_t) -1);
-		tif->tif_flags |= TIFF_BUFFERSETUP;
-	}
-	tif->tif_curstrip = strip;
-	tif->tif_flags &= ~TIFF_POSTENCODE;
-	if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
-		return ((tsize_t) -1);
-	if (!(*tif->tif_encodestrip)(tif,
-	    data, cc, strip / td->td_stripsperimage))
-		return ((tsize_t) 0);
-	if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
-		return (-1);
-	if (td->td_fillorder != tif->tif_fillorder &&
-	    (tif->tif_flags & TIFF_NOBITREV) == 0)
-		TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
-	if (tif->tif_rawcc > 0 &&
-	    !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
-		return (-1);
-	tif->tif_rawcc = 0;
-	tif->tif_rawcp = tif->tif_rawdata;
-	return (cc);
+        if (!TIFFWriteCheck(tif, 0, module))
+                return ((tsize_t) -1);
+        if (strip >= td->td_nstrips) {
+                TIFFError(module, "%s: Strip %lu out of range, max %lu",
+                    tif->tif_name, (u_long) strip, (u_long) td->td_nstrips);
+                return ((tsize_t) -1);
+        }
+        /*
+         * Handle delayed allocation of data buffer.  This
+         * permits it to be sized according to the directory
+         * info.
+         */
+        if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
+                if (!TIFFBufferSetup(tif, module))
+                        return ((tsize_t) -1);
+                tif->tif_flags |= TIFF_BUFFERSETUP;
+        }
+        tif->tif_curstrip = strip;
+        tif->tif_flags &= ~TIFF_POSTENCODE;
+        if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
+                return ((tsize_t) -1);
+        if (!(*tif->tif_encodestrip)(tif,
+            data, cc, strip / td->td_stripsperimage))
+                return ((tsize_t) 0);
+        if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
+                return (-1);
+        if (td->td_fillorder != tif->tif_fillorder &&
+            (tif->tif_flags & TIFF_NOBITREV) == 0)
+                TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
+        if (tif->tif_rawcc > 0 &&
+            !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
+                return (-1);
+        tif->tif_rawcc = 0;
+        tif->tif_rawcp = tif->tif_rawdata;
+        return (cc);
 }
 
 /*
@@ -220,17 +220,17 @@ TIFFWriteEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc)
 tsize_t
 TIFFWriteRawStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc)
 {
-	static const char module[] = "TIFFWriteRawStrip";
+        static const char module[] = "TIFFWriteRawStrip";
 
-	if (!TIFFWriteCheck(tif, 0, module))
-		return ((tsize_t) -1);
-	if (strip >= tif->tif_dir.td_nstrips) {
-		TIFFError(module, "%s: Strip %lu out of range, max %lu",
-		    tif->tif_name, (u_long) strip,
-		    (u_long) tif->tif_dir.td_nstrips);
-		return ((tsize_t) -1);
-	}
-	return (TIFFAppendToStrip(tif, strip, data, cc) ? cc : (tsize_t) -1);
+        if (!TIFFWriteCheck(tif, 0, module))
+                return ((tsize_t) -1);
+        if (strip >= tif->tif_dir.td_nstrips) {
+                TIFFError(module, "%s: Strip %lu out of range, max %lu",
+                    tif->tif_name, (u_long) strip,
+                    (u_long) tif->tif_dir.td_nstrips);
+                return ((tsize_t) -1);
+        }
+        return (TIFFAppendToStrip(tif, strip, data, cc) ? cc : (tsize_t) -1);
 }
 
 /*
@@ -241,16 +241,16 @@ tsize_t
 TIFFWriteTile(TIFF* tif,
     tdata_t buf, uint32 x, uint32 y, uint32 z, tsample_t s)
 {
-	if (!TIFFCheckTile(tif, x, y, z, s))
-		return (-1);
-	/*
-	 * NB: A tile size of -1 is used instead of tif_tilesize knowing
-	 *     that TIFFWriteEncodedTile will clamp this to the tile size.
-	 *     This is done because the tile size may not be defined until
-	 *     after the output buffer is setup in TIFFBufferSetup.
-	 */
-	return (TIFFWriteEncodedTile(tif,
-	    TIFFComputeTile(tif, x, y, z, s), buf, (tsize_t) -1));
+        if (!TIFFCheckTile(tif, x, y, z, s))
+                return (-1);
+        /*
+         * NB: A tile size of -1 is used instead of tif_tilesize knowing
+         *     that TIFFWriteEncodedTile will clamp this to the tile size.
+         *     This is done because the tile size may not be defined until
+         *     after the output buffer is setup in TIFFBufferSetup.
+         */
+        return (TIFFWriteEncodedTile(tif,
+            TIFFComputeTile(tif, x, y, z, s), buf, (tsize_t) -1));
 }
 
 /*
@@ -268,60 +268,60 @@ TIFFWriteTile(TIFF* tif,
 tsize_t
 TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
 {
-	static const char module[] = "TIFFWriteEncodedTile";
-	TIFFDirectory *td;
+        static const char module[] = "TIFFWriteEncodedTile";
+        TIFFDirectory *td;
 
-	if (!TIFFWriteCheck(tif, 1, module))
-		return ((tsize_t) -1);
-	td = &tif->tif_dir;
-	if (tile >= td->td_nstrips) {
-		TIFFError(module, "%s: Tile %lu out of range, max %lu",
-		    tif->tif_name, (u_long) tile, (u_long) td->td_nstrips);
-		return ((tsize_t) -1);
-	}
-	/*
-	 * Handle delayed allocation of data buffer.  This
-	 * permits it to be sized more intelligently (using
-	 * directory information).
-	 */
-	if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
-		if (!TIFFBufferSetup(tif, module))
-			return ((tsize_t) -1);
-		tif->tif_flags |= TIFF_BUFFERSETUP;
-	}
-	tif->tif_curtile = tile;
-	/* 
-	 * Compute tiles per row & per column to compute
-	 * current row and column
-	 */
-	tif->tif_row = (tile % howmany(td->td_imagelength, td->td_tilelength))
-		* td->td_tilelength;
-	tif->tif_col = (tile % howmany(td->td_imagewidth, td->td_tilewidth))
-		* td->td_tilewidth;
+        if (!TIFFWriteCheck(tif, 1, module))
+                return ((tsize_t) -1);
+        td = &tif->tif_dir;
+        if (tile >= td->td_nstrips) {
+                TIFFError(module, "%s: Tile %lu out of range, max %lu",
+                    tif->tif_name, (u_long) tile, (u_long) td->td_nstrips);
+                return ((tsize_t) -1);
+        }
+        /*
+         * Handle delayed allocation of data buffer.  This
+         * permits it to be sized more intelligently (using
+         * directory information).
+         */
+        if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
+                if (!TIFFBufferSetup(tif, module))
+                        return ((tsize_t) -1);
+                tif->tif_flags |= TIFF_BUFFERSETUP;
+        }
+        tif->tif_curtile = tile;
+        /* 
+         * Compute tiles per row & per column to compute
+         * current row and column
+         */
+        tif->tif_row = (tile % howmany(td->td_imagelength, td->td_tilelength))
+                * td->td_tilelength;
+        tif->tif_col = (tile % howmany(td->td_imagewidth, td->td_tilewidth))
+                * td->td_tilewidth;
 
-	tif->tif_flags &= ~TIFF_POSTENCODE;
-	if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
-		return ((tsize_t) -1);
-	/*
-	 * Clamp write amount to the tile size.  This is mostly
-	 * done so that callers can pass in some large number
-	 * (e.g. -1) and have the tile size used instead.
-	 */
-	if (cc > tif->tif_tilesize)
-		cc = tif->tif_tilesize;
-	if (!(*tif->tif_encodetile)(tif, data, cc, tile/td->td_stripsperimage))
-		return ((tsize_t) 0);
-	if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
-		return ((tsize_t) -1);
-	if (td->td_fillorder != tif->tif_fillorder &&
-	    (tif->tif_flags & TIFF_NOBITREV) == 0)
-		TIFFReverseBits((u_char *)tif->tif_rawdata, tif->tif_rawcc);
-	if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,
-	    tif->tif_rawdata, tif->tif_rawcc))
-		return ((tsize_t) -1);
-	tif->tif_rawcc = 0;
-	tif->tif_rawcp = tif->tif_rawdata;
-	return (cc);
+        tif->tif_flags &= ~TIFF_POSTENCODE;
+        if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
+                return ((tsize_t) -1);
+        /*
+         * Clamp write amount to the tile size.  This is mostly
+         * done so that callers can pass in some large number
+         * (e.g. -1) and have the tile size used instead.
+         */
+        if (cc > tif->tif_tilesize)
+                cc = tif->tif_tilesize;
+        if (!(*tif->tif_encodetile)(tif, data, cc, tile/td->td_stripsperimage))
+                return ((tsize_t) 0);
+        if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
+                return ((tsize_t) -1);
+        if (td->td_fillorder != tif->tif_fillorder &&
+            (tif->tif_flags & TIFF_NOBITREV) == 0)
+                TIFFReverseBits((u_char *)tif->tif_rawdata, tif->tif_rawcc);
+        if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,
+            tif->tif_rawdata, tif->tif_rawcc))
+                return ((tsize_t) -1);
+        tif->tif_rawcc = 0;
+        tif->tif_rawcp = tif->tif_rawdata;
+        return (cc);
 }
 
 /*
@@ -336,50 +336,50 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
 tsize_t
 TIFFWriteRawTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
 {
-	static const char module[] = "TIFFWriteRawTile";
+        static const char module[] = "TIFFWriteRawTile";
 
-	if (!TIFFWriteCheck(tif, 1, module))
-		return ((tsize_t) -1);
-	if (tile >= tif->tif_dir.td_nstrips) {
-		TIFFError(module, "%s: Tile %lu out of range, max %lu",
-		    tif->tif_name, (u_long) tile,
-		    (u_long) tif->tif_dir.td_nstrips);
-		return ((tsize_t) -1);
-	}
-	return (TIFFAppendToStrip(tif, tile, data, cc) ? cc : (tsize_t) -1);
+        if (!TIFFWriteCheck(tif, 1, module))
+                return ((tsize_t) -1);
+        if (tile >= tif->tif_dir.td_nstrips) {
+                TIFFError(module, "%s: Tile %lu out of range, max %lu",
+                    tif->tif_name, (u_long) tile,
+                    (u_long) tif->tif_dir.td_nstrips);
+                return ((tsize_t) -1);
+        }
+        return (TIFFAppendToStrip(tif, tile, data, cc) ? cc : (tsize_t) -1);
 }
 
 static int
 TIFFSetupStrips(TIFF* tif)
 {
-#define	isUnspecified(td, v) \
+#define isUnspecified(td, v) \
     (td->v == 0xffffffff || (td)->td_imagelength == 0)
-	register TIFFDirectory *td = &tif->tif_dir;
+        register TIFFDirectory *td = &tif->tif_dir;
 
-	if (!isTiled(tif))
-		td->td_stripsperimage = isUnspecified(td, td_rowsperstrip) ?
-		    1 : howmany(td->td_imagelength, td->td_rowsperstrip);
-	else
-		td->td_stripsperimage = isUnspecified(td, td_tilelength) ?
-		    1 : TIFFNumberOfTiles(tif);
-	td->td_nstrips = td->td_stripsperimage;
-	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
-		td->td_nstrips *= td->td_samplesperpixel;
-	td->td_stripoffset = (uint32 *)
-	    _TIFFmalloc(td->td_nstrips * sizeof (uint32));
-	td->td_stripbytecount = (uint32 *)
-	    _TIFFmalloc(td->td_nstrips * sizeof (uint32));
-	if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
-		return (0);
-	/*
-	 * Place data at the end-of-file
-	 * (by setting offsets to zero).
-	 */
-	memset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint32));
-	memset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint32));
-	TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
-	TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
-	return (1);
+        if (!isTiled(tif))
+                td->td_stripsperimage = isUnspecified(td, td_rowsperstrip) ?
+                    1 : howmany(td->td_imagelength, td->td_rowsperstrip);
+        else
+                td->td_stripsperimage = isUnspecified(td, td_tilelength) ?
+                    1 : TIFFNumberOfTiles(tif);
+        td->td_nstrips = td->td_stripsperimage;
+        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
+                td->td_nstrips *= td->td_samplesperpixel;
+        td->td_stripoffset = (uint32 *)
+            _TIFFmalloc(td->td_nstrips * sizeof (uint32));
+        td->td_stripbytecount = (uint32 *)
+            _TIFFmalloc(td->td_nstrips * sizeof (uint32));
+        if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
+                return (0);
+        /*
+         * Place data at the end-of-file
+         * (by setting offsets to zero).
+         */
+        memset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint32));
+        memset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint32));
+        TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
+        TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
+        return (1);
 #undef isUnspecified
 }
 
@@ -392,50 +392,50 @@ TIFFSetupStrips(TIFF* tif)
 static int
 TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
 {
-	if (tif->tif_mode == O_RDONLY) {
-		TIFFError(module, "%s: File not open for writing",
-		    tif->tif_name);
-		return (0);
-	}
-	if (tiles ^ isTiled(tif)) {
-		TIFFError(tif->tif_name, tiles ?
-		    "Can not write tiles to a stripped image" :
-		    "Can not write scanlines to a tiled image");
-		return (0);
-	}
-	/*
-	 * On the first write verify all the required information
-	 * has been setup and initialize any data structures that
-	 * had to wait until directory information was set.
-	 * Note that a lot of our work is assumed to remain valid
-	 * because we disallow any of the important parameters
-	 * from changing after we start writing (i.e. once
-	 * TIFF_BEENWRITING is set, TIFFSetField will only allow
-	 * the image's length to be changed).
-	 */
-	if ((tif->tif_flags & TIFF_BEENWRITING) == 0) {
-		if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {
-			TIFFError(module,
-			    "%s: Must set \"ImageWidth\" before writing data",
-			    tif->tif_name);
-			return (0);
-		}
-		if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {
-			TIFFError(module,
-		    "%s: Must set \"PlanarConfiguration\" before writing data",
-			    tif->tif_name);
-			return (0);
-		}
-		if (tif->tif_dir.td_stripoffset == NULL &&
-		    !TIFFSetupStrips(tif)) {
-			tif->tif_dir.td_nstrips = 0;
-			TIFFError(module, "%s: No space for %s arrays",
-			    tif->tif_name, isTiled(tif) ? "tile" : "strip");
-			return (0);
-		}
-		tif->tif_flags |= TIFF_BEENWRITING;
-	}
-	return (1);
+        if (tif->tif_mode == O_RDONLY) {
+                TIFFError(module, "%s: File not open for writing",
+                    tif->tif_name);
+                return (0);
+        }
+        if (tiles ^ isTiled(tif)) {
+                TIFFError(tif->tif_name, tiles ?
+                    "Can not write tiles to a stripped image" :
+                    "Can not write scanlines to a tiled image");
+                return (0);
+        }
+        /*
+         * On the first write verify all the required information
+         * has been setup and initialize any data structures that
+         * had to wait until directory information was set.
+         * Note that a lot of our work is assumed to remain valid
+         * because we disallow any of the important parameters
+         * from changing after we start writing (i.e. once
+         * TIFF_BEENWRITING is set, TIFFSetField will only allow
+         * the image's length to be changed).
+         */
+        if ((tif->tif_flags & TIFF_BEENWRITING) == 0) {
+                if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {
+                        TIFFError(module,
+                            "%s: Must set \"ImageWidth\" before writing data",
+                            tif->tif_name);
+                        return (0);
+                }
+                if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {
+                        TIFFError(module,
+                    "%s: Must set \"PlanarConfiguration\" before writing data",
+                            tif->tif_name);
+                        return (0);
+                }
+                if (tif->tif_dir.td_stripoffset == NULL &&
+                    !TIFFSetupStrips(tif)) {
+                        tif->tif_dir.td_nstrips = 0;
+                        TIFFError(module, "%s: No space for %s arrays",
+                            tif->tif_name, isTiled(tif) ? "tile" : "strip");
+                        return (0);
+                }
+                tif->tif_flags |= TIFF_BEENWRITING;
+        }
+        return (1);
 }
 
 /*
@@ -444,28 +444,28 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
 static int
 TIFFBufferSetup(TIFF* tif, const char* module)
 {
-	tsize_t size;
+        tsize_t size;
 
-	if (isTiled(tif))
-		tif->tif_tilesize = size = TIFFTileSize(tif);
-	else
-		tif->tif_scanlinesize = size = TIFFScanlineSize(tif);
-	/*
-	 * Make raw data buffer at least 8K
-	 */
-	if (size < 8*1024)
-		size = 8*1024;
-	tif->tif_rawdata = _TIFFmalloc(size);
-	if (tif->tif_rawdata == NULL) {
-		TIFFError(module, "%s: No space for output buffer",
-		    tif->tif_name);
-		return (0);
-	}
-	tif->tif_flags |= TIFF_MYBUFFER;
-	tif->tif_rawdatasize = size;
-	tif->tif_rawcc = 0;
-	tif->tif_rawcp = tif->tif_rawdata;
-	return (1);
+        if (isTiled(tif))
+                tif->tif_tilesize = size = TIFFTileSize(tif);
+        else
+                tif->tif_scanlinesize = size = TIFFScanlineSize(tif);
+        /*
+         * Make raw data buffer at least 8K
+         */
+        if (size < 8*1024)
+                size = 8*1024;
+        tif->tif_rawdata = _TIFFmalloc(size);
+        if (tif->tif_rawdata == NULL) {
+                TIFFError(module, "%s: No space for output buffer",
+                    tif->tif_name);
+                return (0);
+        }
+        tif->tif_flags |= TIFF_MYBUFFER;
+        tif->tif_rawdatasize = size;
+        tif->tif_rawcc = 0;
+        tif->tif_rawcp = tif->tif_rawdata;
+        return (1);
 }
 
 /*
@@ -474,23 +474,23 @@ TIFFBufferSetup(TIFF* tif, const char* module)
 static int
 TIFFGrowStrips(TIFF* tif, int delta, const char* module)
 {
-	TIFFDirectory *td = &tif->tif_dir;
+        TIFFDirectory *td = &tif->tif_dir;
 
-	assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
-	td->td_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
-	    (td->td_nstrips + delta) * sizeof (uint32));
-	td->td_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
-	    (td->td_nstrips + delta) * sizeof (uint32));
-	if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) {
-		td->td_nstrips = 0;
-		TIFFError(module, "%s: No space to expand strip arrays",
-		    tif->tif_name);
-		return (0);
-	}
-	memset(td->td_stripoffset+td->td_nstrips, 0, delta*sizeof (uint32));
-	memset(td->td_stripbytecount+td->td_nstrips, 0, delta*sizeof (uint32));
-	td->td_nstrips += delta;
-	return (1);
+        assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
+        td->td_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
+            (td->td_nstrips + delta) * sizeof (uint32));
+        td->td_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
+            (td->td_nstrips + delta) * sizeof (uint32));
+        if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) {
+                td->td_nstrips = 0;
+                TIFFError(module, "%s: No space to expand strip arrays",
+                    tif->tif_name);
+                return (0);
+        }
+        memset(td->td_stripoffset+td->td_nstrips, 0, delta*sizeof (uint32));
+        memset(td->td_stripbytecount+td->td_nstrips, 0, delta*sizeof (uint32));
+        td->td_nstrips += delta;
+        return (1);
 }
 
 /*
@@ -502,33 +502,33 @@ TIFFGrowStrips(TIFF* tif, int delta, const char* module)
 static int
 TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc)
 {
-	TIFFDirectory *td = &tif->tif_dir;
-	static const char module[] = "TIFFAppendToStrip";
+        TIFFDirectory *td = &tif->tif_dir;
+        static const char module[] = "TIFFAppendToStrip";
 
-	if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
-		/*
-		 * No current offset, set the current strip.
-		 */
-		if (td->td_stripoffset[strip] != 0) {
-			if (!SeekOK(tif, td->td_stripoffset[strip])) {
-				TIFFError(module,
-				    "%s: Seek error at scanline %lu",
-				    tif->tif_name, (u_long) tif->tif_row);
-				return (0);
-			}
-		} else
-			td->td_stripoffset[strip] =
-			    TIFFSeekFile(tif, 0L, L_XTND);
-		tif->tif_curoff = td->td_stripoffset[strip];
-	}
-	if (!WriteOK(tif, data, cc)) {
-		TIFFError(module, "%s: Write error at scanline %lu",
-		    tif->tif_name, (u_long) tif->tif_row);
-		return (0);
-	}
-	tif->tif_curoff += cc;
-	td->td_stripbytecount[strip] += cc;
-	return (1);
+        if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
+                /*
+                 * No current offset, set the current strip.
+                 */
+                if (td->td_stripoffset[strip] != 0) {
+                        if (!SeekOK(tif, td->td_stripoffset[strip])) {
+                                TIFFError(module,
+                                    "%s: Seek error at scanline %lu",
+                                    tif->tif_name, (u_long) tif->tif_row);
+                                return (0);
+                        }
+                } else
+                        td->td_stripoffset[strip] =
+                            TIFFSeekFile(tif, 0L, L_XTND);
+                tif->tif_curoff = td->td_stripoffset[strip];
+        }
+        if (!WriteOK(tif, data, cc)) {
+                TIFFError(module, "%s: Write error at scanline %lu",
+                    tif->tif_name, (u_long) tif->tif_row);
+                return (0);
+        }
+        tif->tif_curoff += cc;
+        td->td_stripbytecount[strip] += cc;
+        return (1);
 }
 
 /*
@@ -539,19 +539,19 @@ TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc)
 int
 TIFFFlushData1(TIFF* tif)
 {
-	if (tif->tif_rawcc > 0) {
-		if (tif->tif_dir.td_fillorder != tif->tif_fillorder &&
-		    (tif->tif_flags & TIFF_NOBITREV) == 0)
-			TIFFReverseBits((u_char *)tif->tif_rawdata,
-			    tif->tif_rawcc);
-		if (!TIFFAppendToStrip(tif,
-		    isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,
-		    tif->tif_rawdata, tif->tif_rawcc))
-			return (0);
-		tif->tif_rawcc = 0;
-		tif->tif_rawcp = tif->tif_rawdata;
-	}
-	return (1);
+        if (tif->tif_rawcc > 0) {
+                if (tif->tif_dir.td_fillorder != tif->tif_fillorder &&
+                    (tif->tif_flags & TIFF_NOBITREV) == 0)
+                        TIFFReverseBits((u_char *)tif->tif_rawdata,
+                            tif->tif_rawcc);
+                if (!TIFFAppendToStrip(tif,
+                    isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,
+                    tif->tif_rawdata, tif->tif_rawcc))
+                        return (0);
+                tif->tif_rawcc = 0;
+                tif->tif_rawcp = tif->tif_rawdata;
+        }
+        return (1);
 }
 
 /*
@@ -563,5 +563,5 @@ TIFFFlushData1(TIFF* tif)
 void
 TIFFSetWriteOffset(TIFF* tif, toff_t off)
 {
-	tif->tif_curoff = off;
+        tif->tif_curoff = off;
 }

Some files were not shown because too many files changed in this diff