home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprocs / imagedim.icn < prev    next >
Text File  |  2001-05-02  |  2KB  |  65 lines

  1. ############################################################################
  2. #
  3. #    File:     imagedim.icn
  4. #
  5. #    Subject:  Procedures for getting image dimensions
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 2, 2001
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  imagedim(s) returns a record that contains the type and dimensions of an 
  18. #  image named s.
  19. #
  20. #  The assumptions about image formats are naive.
  21. #
  22. ############################################################################
  23. #
  24. #  Requires:  Version 9 graphics
  25. #
  26. ############################################################################
  27.  
  28. record idim(type, w, h)
  29.  
  30. procedure imagedim(s)
  31.    local Image, line, dim
  32.  
  33.    Image := open(s) | stop("*** cannot open ", s)
  34.  
  35.    line := read(Image) | idim_bad()
  36.    line ? {
  37.       if tab(find("width") + 6) then {
  38.          dim := idim("xbm")
  39.          dim.w := integer(tab(0)) | idim_bad()
  40.          read(Image) ? {
  41.             tab(find("height") + 7) | idim_bad()
  42.             dim.h := integer(tab(0)) | idim_bad()
  43.             } | idim_bad()
  44.          }
  45.       else if find("XPM") then {
  46.          dim := idim("xpm")
  47.          read(Image) | idim_bad()
  48.  
  49.          read(Image) ? {
  50.             ="\"" & dim.w := integer(tab(many(&digits))) &
  51.               =" " & dim.h := integer(tab(many(&digits)))
  52.             } | idim_bad()
  53.          }
  54.       }
  55.  
  56. #  close(Image)
  57.  
  58.    return dim
  59.  
  60. end
  61.  
  62. procedure idim_bad()
  63.    stop("*** bad image data")
  64. end
  65.