home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / iofunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-29  |  654 b   |  42 lines

  1. #include  <stdio.h>
  2. #include  <libc.h>
  3. #include  <objc/objc.h>
  4. #include  "common.h"
  5.  
  6. int get_short(FILE *fp)
  7. {
  8.     int c = getc(fp);
  9.     return ((getc(fp) << 8) | c);
  10. }
  11.  
  12. long get_long(FILE *fp)
  13. {
  14.     long c = get_short(fp);
  15.     return ((get_short(fp) << 16) | c);
  16. }
  17.  
  18. void put_short(int k, FILE *fp)
  19. {
  20.     putc(k & 0xff, fp);
  21.     putc((k >> 8) & 0xff, fp);
  22. }
  23.  
  24. void put_long(long k, FILE *fp)
  25. {
  26.     put_short(k & 0xffff, fp);
  27.     put_short((k >> 16) & 0xffff, fp);
  28. }
  29.  
  30. int byte_length(int bits, int width)
  31. {
  32.     switch (bits) {
  33.     case 1: return ((width + 7) >> 3);
  34.     case 2: return ((width + 3) >> 2);
  35.     case 4: return ((width + 1) >> 1);
  36.     case 8:
  37.     default:
  38.         break;
  39.     }
  40.     return width;
  41. }
  42.