home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / deltac / part01 / deltac.c next >
C/C++ Source or Header  |  1990-06-15  |  2KB  |  97 lines

  1. /* 
  2.  * Delta modulation uncompress
  3.  *
  4.  * (C) Copyright 1989, 1990 Diomidis Spinellis.  All rights reserved.
  5.  * 
  6.  * $Header: deltac.c,v 1.1 90/06/08 22:13:42 dds Rel $
  7.  *
  8.  * Permission to use, copy, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation.
  13.  * 
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  15.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  16.  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  *
  18.  */
  19.  
  20.  
  21. #include <stdio.h>
  22.  
  23. #ifndef lint
  24. static char RCSid[] = "$Header: deltac.c,v 1.1 90/06/08 22:13:42 dds Rel $";
  25. #endif
  26.  
  27. static prev, stored;
  28.  
  29. #ifdef SLOW
  30. void
  31. putnib(x)
  32.     int x;
  33. {
  34.  
  35.     if (stored) {
  36.         if (putchar(prev | (x & 0xf)) == EOF) {
  37.             perror("<stdout>");
  38.             exit(1);
  39.         }
  40.         stored = 0;
  41.     } else {
  42.         prev = x << 4;
  43.         stored = 1;
  44.     }
  45. }
  46. #else
  47. #define putnib(x) \
  48. do { \
  49.     if (stored) { \
  50.         if (putchar(prev | (x & 0xf)) == EOF) { \
  51.             perror("<stdout>"); \
  52.             exit(1); \
  53.         } \
  54.         stored = 0; \
  55.     } else { \
  56.         prev = (x) << 4; \
  57.         stored = 1; \
  58.     } \
  59. } while(0)
  60. #endif
  61.  
  62. void
  63. flushnib()
  64. {
  65.     if (stored)
  66.         if (putchar(prev | 8) == EOF) {
  67.             perror("<stdout>");
  68.             exit(1);
  69.         }
  70. }
  71.  
  72.  
  73. main(argc, argv)
  74.     int argc;
  75.     char *argv[];
  76. {
  77.     register c, cp = 256, delta;
  78.  
  79.     if (argc != 1) {
  80.         fprintf(stderr, "%s: usage %s\n", argv[1]);
  81.         exit(1);
  82.     }
  83.     while((c = getchar()) != EOF) {
  84.         delta = c - cp;
  85.         if (delta > 7 || delta < -7) {
  86.             putnib(8);
  87.             putnib(c >> 4);
  88.             putnib(c);
  89.         } else if (delta >= 0)
  90.             putnib(delta);
  91.         else
  92.             putnib(8 | -delta);
  93.         cp = c;
  94.     }
  95.     flushnib();
  96. }
  97.