home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C6TIFF.ZIP / SWAB.C < prev    next >
Encoding:
Text File  |  1989-12-30  |  1.4 KB  |  74 lines

  1. /*
  2.  * Copyright (c) 1988 by Sam Leffler.
  3.  * All rights reserved.
  4.  *
  5.  * This file is provided for unrestricted use provided that this
  6.  * legend is included on all tape media and as a part of the
  7.  * software program in whole or part.  Users may copy, modify or
  8.  * distribute this file at will.
  9.  */
  10.  
  11. /*
  12. TIFF Library Byte Swapping Routines.
  13. We assume int, short and unsigned = 16-bits and long = 32-bits
  14. */
  15.  
  16. void TIFFSwabShort(unsigned *wp)
  17. {
  18.    register unsigned char *cp = (unsigned char *)wp;
  19.    register unsigned t;
  20.  
  21.    t = cp[1];
  22.    cp[1] = cp[0];
  23.    cp[0] = t;
  24. }
  25.  
  26.  
  27. void TIFFSwabLong(unsigned long *lp)
  28. {
  29.    register unsigned char *cp = (unsigned char *)lp;
  30.    unsigned t;
  31.  
  32.    t = cp[3];
  33.    cp[3] = cp[0];
  34.    cp[0] = t;
  35.    t = cp[2];
  36.    cp[2] = cp[1];
  37.    cp[1] = t;
  38. }
  39.  
  40.  
  41. void TIFFSwabArrayOfShort(unsigned *wp, unsigned n)
  42. {
  43.    register unsigned char *cp;
  44.    register unsigned t;
  45.  
  46.    while (n-- > 0)
  47.    {
  48.       cp = (unsigned char *)wp;
  49.       t = cp[1];
  50.       cp[1] = cp[0];
  51.       cp[0] = t;
  52.       wp++;
  53.    }
  54. }
  55.  
  56.  
  57. void TIFFSwabArrayOfLong(unsigned long *lp, unsigned n)
  58. {
  59.    register unsigned char *cp;
  60.    register unsigned t;
  61.  
  62.    while (n-- > 0)
  63.    {
  64.       cp = (unsigned char *)lp;
  65.       t = cp[3];
  66.       cp[3] = cp[0];
  67.       cp[0] = t;
  68.       t = cp[2];
  69.       cp[2] = cp[1];
  70.       cp[1] = t;
  71.       lp++;
  72.    }
  73. }
  74.