summaryrefslogtreecommitdiff
path: root/ipl/gprocs/imagedim.icn
blob: 3b5a7186f59740671ee944d537b6d0eeff56fd59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
############################################################################
#
#	File:     imagedim.icn
#
#	Subject:  Procedures for getting image dimensions
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  imagedim(s) returns a record that contains the type and dimensions of an 
#  image named s.
#
#  The assumptions about image formats are naive.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################

record idim(type, w, h)

procedure imagedim(s)
   local Image, line, dim

   Image := open(s) | stop("*** cannot open ", s)

   line := read(Image) | idim_bad()
   line ? {
      if tab(find("width") + 6) then {
         dim := idim("xbm")
         dim.w := integer(tab(0)) | idim_bad()
         read(Image) ? {
            tab(find("height") + 7) | idim_bad()
            dim.h := integer(tab(0)) | idim_bad()
            } | idim_bad()
         }
      else if find("XPM") then {
         dim := idim("xpm")
         read(Image) | idim_bad()

         read(Image) ? {
            ="\"" & dim.w := integer(tab(many(&digits))) &
              =" " & dim.h := integer(tab(many(&digits)))
            } | idim_bad()
         }
      }

#  close(Image)

   return dim

end

procedure idim_bad()
   stop("*** bad image data")
end