Skip to content

Commit 51faf19

Browse files
committed
add the ability to save the data from the file that was loaded
into a bitmap% object related to racket/htdp#105
1 parent 36ba573 commit 51faf19

File tree

8 files changed

+305
-162
lines changed

8 files changed

+305
-162
lines changed

draw-doc/scribblings/draw/bitmap-class.scrbl

+33-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ A bitmap is convertible to @racket['png-bytes] through the
3939
'unknown]
4040
[bg-color (or/c (is-a?/c color%) #f) #f]
4141
[complain-on-failure? any/c #f]
42-
[backing-scale (>/c 0.0) 1.0])
42+
[backing-scale (>/c 0.0) 1.0]
43+
[save-data-from-file? any/c #f])
4344
([bits bytes?]
4445
[width exact-positive-integer?]
4546
[height exact-positive-integer?]))]{
@@ -78,8 +79,11 @@ When a @racket[bits] byte string is provided: Creates a monochrome
7879
@racket[height] is larger than 8 times the length of @racket[bits],
7980
@|MismatchExn|.
8081

82+
See @method[bitmap% get-data-from-file] for information on @racket[save-data-from-file?]
83+
8184
@history[#:changed "1.1" @elem{Added the @racket[backing-scale]
82-
optional arguments.}]}
85+
optional arguments.}
86+
#:changed "1.17" @elem{Added @racket[save-data-from-file?]}]}
8387

8488
@defmethod[(get-argb-pixels [x exact-nonnegative-integer?]
8589
[y exact-nonnegative-integer?]
@@ -113,6 +117,26 @@ Returns the bitmap's @tech{backing scale}.
113117

114118
@history[#:added "1.1"]}
115119

120+
@defmethod[(get-data-from-file)
121+
(or/c (vector/c (or/c 'unknown 'unknown/mask 'unknown/alpha
122+
'gif 'gif/mask 'gif/alpha
123+
'jpeg 'jpeg/alpha
124+
'png 'png/mask 'png/alpha
125+
'xbm 'xbm/alpha 'xpm 'xpm/alpha
126+
'bmp 'bmp/alpha)
127+
(or/c (is-a?/c color%) #f)
128+
(and/c bytes? immutable?)
129+
#:immutable? #t)
130+
#f)]{
131+
If the bitmap data in this bitmap was read from a file
132+
and the @racket[_save-data-from-file?] was passed with
133+
a true value when it was read (either in the constructor
134+
or in @method[bitmap% load-file]), then this method
135+
returns the contents of the loaded file as bytes. Otherwise,
136+
it returns @racket[#f].
137+
138+
@history[#:added "1.17"]
139+
}
116140

117141
@defmethod[(get-depth)
118142
exact-nonnegative-integer?]{
@@ -206,7 +230,8 @@ Returns @racket[#f] if the bitmap is monochrome, @racket[#t] otherwise.
206230
'bmp 'bmp/alpha)
207231
'unknown]
208232
[bg-color (or/c (is-a?/c color%) #f) #f]
209-
[complain-on-failure? any/c #f])
233+
[complain-on-failure? any/c #f]
234+
[#:save-data-from-file? save-data-from-file? any/c #f])
210235
boolean?]{
211236

212237
Loads a bitmap from a file format that read from @racket[in], unless
@@ -278,7 +303,11 @@ For PNG and BMP loading, if @racket[bg-color] is not @racket[#f], then it is
278303
are both undefined, a platform-specific default is used.
279304

280305
After a bitmap is created, @method[bitmap% load-file] can be used
281-
only if the bitmap's @tech{backing scale} is @racket[1.0].}
306+
only if the bitmap's @tech{backing scale} is @racket[1.0].
307+
308+
See @method[bitmap% get-data-from-file] for information on @racket[save-data-from-file?]
309+
310+
@history[#:changed "1.17" @elem{Added @racket[save-data-from-file?]}]}
282311

283312

284313
@defmethod[(make-dc)

draw-doc/scribblings/draw/draw-funcs.scrbl

+8-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ optional argument.}]}
191191
'unknown/alpha]
192192
[bg-color (or/c (is-a?/c color%) #f) #f]
193193
[complain-on-failure? any/c #t]
194+
[#:get-data-from-file? get-data-from-file? any/c #f]
194195
[#:backing-scale backing-scale (>/c 0.0) 1.0]
195196
[#:try-@2x? try-@2x? any/c #f])
196197
(is-a?/c bitmap%)]{
@@ -207,8 +208,14 @@ but with @filepath{@"@"2x} added to the name (before the file suffix,
207208
if any). If the @filepath{@"@"2x} path exists, it is used instead of
208209
@racket[in], and @racket[backing-scale] is multiplied by @racket[2].
209210

211+
If @racket[get-data-from-file?] is not @racket[#f], then the resulting
212+
bitmap's @method[bitmap% get-data-from-file] method will return
213+
the bytes from the file.
214+
210215
@history[#:changed "1.1" @elem{Added the @racket[#:backing-scale]
211-
and @racket[#:try-@2x?] optional arguments.}]}
216+
and @racket[#:try-@2x?] optional arguments.}
217+
#:changed "1.17" @elem{Added the @racket[#:get-data-from-file?]
218+
argument.}]}
212219

213220

214221
@defproc[(recorded-datum->procedure [datum any/c]) ((is-a?/c dc<%>) . -> . void?)]{

draw-lib/info.rkt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
(define pkg-authors '(mflatt))
1919

20-
(define version "1.16")
20+
(define version "1.17")

draw-lib/racket/draw.rkt

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
'bmp 'bmp/alpha)
6060
(or/c (is-a?/c color%) #f)
6161
any/c
62+
#:save-data-from-file? any/c
6263
#:backing-scale (>/c 0.0)
6364
#:try-@2x? any/c)
6465
. ->* . (instanceof/c bitmap%/c))])

0 commit comments

Comments
 (0)