home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib2 / libpgm1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-18  |  1.9 KB  |  83 lines

  1. /* libpgm1.c - pgm utility library part 1 - reading
  2. *
  3. * Copyright (C) 1989 by Jef Poskanzer.
  4. *
  5. * Permission to use, copy, modify, and distribute this software and its
  6. * documentation for any purpose and without fee is hereby granted, provided
  7. * that the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation. This software is provided "as is" without express or
  10. * implied warranty.
  11. */
  12.  
  13. #include "pgm.h"
  14. #include "libpgm.h"
  15. #include "libpbm.h"
  16.  
  17. pgm_readpgminitrest(fileP, colsP, rowsP, maxvalP)
  18. FILE*    fileP;
  19. int    *colsP, *rowsP;
  20. gray*    maxvalP;
  21. {
  22. int maxval;
  23.  
  24.     /* Read size. */
  25.     *colsP = pbm_getint(fileP);
  26.     *rowsP = pbm_getint(fileP);
  27.  
  28.     /* Read maxval. */
  29.     maxval = pbm_getint(fileP);
  30.     if (maxval > PGM_MAXMAXVAL)
  31.     return    prgmerr(0, "maxval too large: %d > %d", maxval, PGM_MAXMAXVAL);
  32.     else    *maxvalP = maxval;
  33. return    0;
  34. }
  35.  
  36.  
  37. #ifdef __STDC__
  38. pgm_readpgmrow(FILE* fileP, gray* grayrow, int cols, gray maxval, int format)
  39. #else
  40. pgm_readpgmrow(fileP, grayrow, cols, maxval, format)
  41. FILE*    fileP;
  42. gray*    grayrow;
  43. int    cols, maxval, format;
  44. #endif    __STDC__
  45. {
  46. register int    col;
  47. register gray*    gP;
  48. register bit*    bP, *bitrow;
  49.  
  50. switch (format)
  51. {
  52. case PGM_FORMAT:
  53.     for (col=0, gP=grayrow; col < cols; ++col, ++gP)
  54.     {
  55.         *gP = pbm_getint(fileP);
  56. #ifdef _DEBUG_
  57.         if (*gP > maxval)
  58.         message("value out of bounds (%u > %u)", *gP, maxval);
  59. #endif
  60.     }
  61.     break;
  62. case RPGM_FORMAT:
  63.     for (col=0, gP=grayrow; col < cols; ++col, ++gP)
  64.     {
  65.         *gP = pbm_getrawbyte(fileP);
  66. #ifdef _DEBUG_
  67.         if (*gP > maxval)
  68.         message("value out of bounds (%u > %u)", *gP, maxval);
  69. #endif
  70.     }
  71.     break;
  72. case PBM_FORMAT:
  73. case RPBM_FORMAT:
  74.     pbm_readpbmrow(fileP, bitrow, cols, format);
  75.     for (col=0, gP=grayrow, bP=bitrow; col < cols; ++col, ++gP, ++bP)
  76.         *gP = (*bP == PBM_WHITE) ? maxval : 0;
  77.     break;
  78. default:    col = prgmerr(0, "can't happen");
  79. }
  80. return    col;
  81. }
  82.  
  83.