~ubuntu-branches/ubuntu/intrepid/mit-scheme/intrepid-updates

« back to all changes in this revision

Viewing changes to src/6001/pic-reco.scm

  • Committer: Bazaar Package Importer
  • Author(s): Chris Hanson
  • Date: 2005-01-18 00:33:57 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050118003357-pv3i8iqlm5m80tl5
Tags: 7.7.90-5
* Add "libx11-dev" to build-depends.  (closes: Bug#290845)
* Fix debian/control and debian/menu to eliminate some lintian errors
  and warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#| -*-Scheme-*-
2
2
 
3
 
$Id: pic-reco.scm,v 1.8 2001/12/20 03:24:33 cph Exp $
4
 
 
5
 
Copyright (c) 1993, 1999, 2001 Massachusetts Institute of Technology
6
 
 
7
 
This program is free software; you can redistribute it and/or modify
 
3
$Id: pic-reco.scm,v 1.11 2003/03/07 19:19:24 cph Exp $
 
4
 
 
5
Copyright 1991,1992,1993,2001,2003 Massachusetts Institute of Technology
 
6
 
 
7
This file is part of MIT/GNU Scheme.
 
8
 
 
9
MIT/GNU Scheme is free software; you can redistribute it and/or modify
8
10
it under the terms of the GNU General Public License as published by
9
11
the Free Software Foundation; either version 2 of the License, or (at
10
12
your option) any later version.
11
13
 
12
 
This program is distributed in the hope that it will be useful, but
 
14
MIT/GNU Scheme is distributed in the hope that it will be useful, but
13
15
WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
17
General Public License for more details.
16
18
 
17
19
You should have received a copy of the GNU General Public License
18
 
along with this program; if not, write to the Free Software
19
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
 
02111-1307, USA.
 
20
along with MIT/GNU Scheme; if not, write to the Free Software
 
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
22
USA.
 
23
 
21
24
|#
22
 
 
 
25
 
23
26
;;; Representation of pictures using records
24
27
 
25
28
(declare (usual-integrations))
26
 
 
27
 
(define picture-type (make-record-type 
28
 
                      'picture 
29
 
                      '(width
30
 
                        height
31
 
                        data
32
 
                        min
33
 
                        max 
34
 
                        image)))
35
 
 
36
 
(define %make-picture (record-constructor picture-type '(width height)))
37
 
 
38
 
(define %picture-min (record-accessor picture-type 'min))
39
 
(define %picture-max (record-accessor picture-type 'max))
40
 
(define %picture-set-data! (record-updater picture-type 'data))
41
 
(define %picture-set-image! (record-updater picture-type 'image))
42
 
(define %picture-set-min! (record-updater picture-type 'min))
43
 
(define %picture-set-max! (record-updater picture-type 'max))
 
29
 
 
30
(define-record-type <picture>
 
31
    (%make-picture width height)
 
32
    picture?
 
33
  (width picture-width)
 
34
  (height picture-height)
 
35
  (data picture-data %picture-set-data!)
 
36
  (min %picture-min %picture-set-min!)
 
37
  (max %picture-max %picture-set-max!)
 
38
  (image picture-image %picture-set-image!))
44
39
 
45
40
(define (make-picture width height #!optional initial-val)
46
41
  (let ((pic (%make-picture width height))
47
 
        (initial-val (if (default-object? initial-val)
48
 
                         0.
49
 
                         (exact->inexact initial-val))))
 
42
        (initial-val
 
43
         (if (default-object? initial-val)
 
44
             0.
 
45
             (exact->inexact initial-val))))
50
46
    (%picture-set-min! pic initial-val)
51
47
    (%picture-set-max! pic initial-val)
52
48
    (%picture-set-data! pic 
53
 
                        (make-initialized-vector
54
 
                         height
55
 
                         (lambda (n)
56
 
                           n    ; ignored
57
 
                           (flo:make-vector width initial-val))))
 
49
                        (make-initialized-vector height
 
50
                          (lambda (n)
 
51
                            n
 
52
                            (flo:make-vector width initial-val))))
58
53
    (%picture-set-image! pic #f)
59
54
    pic))
60
55
 
61
 
(define picture? (record-predicate picture-type))
62
 
 
63
 
(define picture-width
64
 
  (record-accessor picture-type 'width))
65
 
 
66
 
(define picture-height
67
 
  (record-accessor picture-type 'height))
68
 
 
69
 
(define picture-data
70
 
  (record-accessor picture-type 'data))
71
 
 
72
 
(define picture-image
73
 
  (record-accessor picture-type 'image))
 
56
(define (picture-set-data! picture data)
 
57
  (%picture-set-data! picture data)
 
58
  (invalidate-cached-values picture))
 
59
 
 
60
(define (picture-min picture)
 
61
  (or (%picture-min picture)
 
62
      (begin
 
63
        (find-min-max picture)
 
64
        (%picture-min picture))))
 
65
 
 
66
(define (picture-max picture)
 
67
  (or (%picture-max picture)
 
68
      (begin
 
69
        (find-min-max picture)
 
70
        (%picture-max picture))))
74
71
 
75
72
(define (picture-set-image! picture image)
76
73
  (let ((img (picture-image picture)))
77
74
    (if (image? img)
78
75
        (image/destroy img))
79
76
    (%picture-set-image! picture image)))
80
 
 
81
 
(define (picture-min picture)
82
 
  (let ((pic-min (%picture-min picture)))
83
 
    (if (not pic-min) 
84
 
        (begin (find-min-max picture)
85
 
               (%picture-min picture))
86
 
        pic-min)))
87
 
 
88
 
(define (picture-max picture)
89
 
  (let ((pic-max (%picture-max picture)))
90
 
    (if (not pic-max) 
91
 
        (begin (find-min-max picture)
92
 
               (%picture-max picture))
93
 
        pic-max)))
94
 
 
 
77
 
95
78
(define (make-picture-referencer bad-type-predicate bad-range-signal)
96
79
  (lambda (picture x y)
97
80
    (cond ((bad-type-predicate x)
122
105
           (bad-range-signal y 'PICTURE-SET!))
123
106
          (else
124
107
           (flo:vector-set! (vector-ref (picture-data picture) y)
125
 
                        x (exact->inexact value))
 
108
                            x (exact->inexact value))
126
109
           (invalidate-cached-values picture)))))
127
110
 
128
 
(define picture-ref (make-picture-referencer
129
 
                     (lambda (var)
130
 
                       (declare (integrate var))
131
 
                       (not (fix:fixnum? var)))
132
 
                     error:bad-range-argument))
133
 
 
134
 
(define no-error-picture-ref (make-picture-referencer
135
 
                          (lambda (var)
136
 
                            (declare (integrate var))
137
 
                            var  ;ignored
138
 
                            false)
139
 
                          (lambda (var proc-name)
140
 
                            var proc-name   ;ignored
141
 
                            false)))
142
 
 
143
 
(define picture-set! (make-picture-setter
144
 
                      (lambda (var)
145
 
                        (declare (integrate var))
146
 
                        (not (fix:fixnum? var)))
147
 
                      error:bad-range-argument))
148
 
 
149
 
(define no-error-picture-set! (make-picture-setter
150
 
                           (lambda (var)
151
 
                             (declare (integrate var))
152
 
                             var  ;ignored
153
 
                             false)
154
 
                           (lambda (var proc-name)
155
 
                             var proc-name  ;ignored 
156
 
                             false)))
157
 
 
 
111
(define picture-ref
 
112
  (make-picture-referencer (lambda (var) (not (fix:fixnum? var)))
 
113
                           error:bad-range-argument))
 
114
 
 
115
(define no-error-picture-ref
 
116
  (make-picture-referencer (lambda (var) var #f)
 
117
                           (lambda (var caller) var caller #f)))
 
118
 
 
119
(define picture-set!
 
120
  (make-picture-setter (lambda (var) (not (fix:fixnum? var)))
 
121
                       error:bad-range-argument))
 
122
 
 
123
(define no-error-picture-set!
 
124
  (make-picture-setter (lambda (var) var #f)
 
125
                       (lambda (var caller) var caller #f)))
 
126
 
158
127
(define (picture-map! picture fn)
159
128
  (let ((picdata (picture-data picture))
160
129
        (width (picture-width picture))
170
139
                  (y-loop (1+ y))))))
171
140
      (invalidate-cached-values picture))))
172
141
 
173
 
(define (picture-set-data! picture data)
174
 
  (%picture-set-data! picture data)
175
 
  (invalidate-cached-values picture))
176
 
 
177
142
;;; Note that picture-data and picture-set-data! are both unsafe operations
178
143
;;; in the sense that both of them do not ensure that only floating point 
179
144
;;; numbers are ever stored in the picture array.
180
145
 
181
 
 
182
146
(define (invalidate-cached-values picture)
183
147
  (%picture-set-min! picture #f)
184
148
  (%picture-set-max! picture #f)
204
168
                    (x-loop (1+ x)))
205
169
                  (y-loop (1+ y)))))))
206
170
    (%picture-set-min! picture current-min)
207
 
    (%picture-set-max! picture current-max)))
 
171
    (%picture-set-max! picture current-max)))
 
 
b'\\ No newline at end of file'