Skip to content

Commit

Permalink
add the ability to save the data from the file that was loaded
Browse files Browse the repository at this point in the history
into a bitmap% object

related to racket/htdp#105
  • Loading branch information
rfindler committed Sep 7, 2020
1 parent 36ba573 commit 51faf19
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 162 deletions.
37 changes: 33 additions & 4 deletions draw-doc/scribblings/draw/bitmap-class.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ A bitmap is convertible to @racket['png-bytes] through the
'unknown]
[bg-color (or/c (is-a?/c color%) #f) #f]
[complain-on-failure? any/c #f]
[backing-scale (>/c 0.0) 1.0])
[backing-scale (>/c 0.0) 1.0]
[save-data-from-file? any/c #f])
([bits bytes?]
[width exact-positive-integer?]
[height exact-positive-integer?]))]{
Expand Down Expand Up @@ -78,8 +79,11 @@ When a @racket[bits] byte string is provided: Creates a monochrome
@racket[height] is larger than 8 times the length of @racket[bits],
@|MismatchExn|.

See @method[bitmap% get-data-from-file] for information on @racket[save-data-from-file?]

@history[#:changed "1.1" @elem{Added the @racket[backing-scale]
optional arguments.}]}
optional arguments.}
#:changed "1.17" @elem{Added @racket[save-data-from-file?]}]}

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

@history[#:added "1.1"]}

@defmethod[(get-data-from-file)
(or/c (vector/c (or/c 'unknown 'unknown/mask 'unknown/alpha
'gif 'gif/mask 'gif/alpha
'jpeg 'jpeg/alpha
'png 'png/mask 'png/alpha
'xbm 'xbm/alpha 'xpm 'xpm/alpha
'bmp 'bmp/alpha)
(or/c (is-a?/c color%) #f)
(and/c bytes? immutable?)
#:immutable? #t)
#f)]{
If the bitmap data in this bitmap was read from a file
and the @racket[_save-data-from-file?] was passed with
a true value when it was read (either in the constructor
or in @method[bitmap% load-file]), then this method
returns the contents of the loaded file as bytes. Otherwise,
it returns @racket[#f].

@history[#:added "1.17"]
}

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

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

After a bitmap is created, @method[bitmap% load-file] can be used
only if the bitmap's @tech{backing scale} is @racket[1.0].}
only if the bitmap's @tech{backing scale} is @racket[1.0].

See @method[bitmap% get-data-from-file] for information on @racket[save-data-from-file?]

@history[#:changed "1.17" @elem{Added @racket[save-data-from-file?]}]}


@defmethod[(make-dc)
Expand Down
9 changes: 8 additions & 1 deletion draw-doc/scribblings/draw/draw-funcs.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ optional argument.}]}
'unknown/alpha]
[bg-color (or/c (is-a?/c color%) #f) #f]
[complain-on-failure? any/c #t]
[#:get-data-from-file? get-data-from-file? any/c #f]
[#:backing-scale backing-scale (>/c 0.0) 1.0]
[#:try-@2x? try-@2x? any/c #f])
(is-a?/c bitmap%)]{
Expand All @@ -207,8 +208,14 @@ but with @filepath{@"@"2x} added to the name (before the file suffix,
if any). If the @filepath{@"@"2x} path exists, it is used instead of
@racket[in], and @racket[backing-scale] is multiplied by @racket[2].

If @racket[get-data-from-file?] is not @racket[#f], then the resulting
bitmap's @method[bitmap% get-data-from-file] method will return
the bytes from the file.

@history[#:changed "1.1" @elem{Added the @racket[#:backing-scale]
and @racket[#:try-@2x?] optional arguments.}]}
and @racket[#:try-@2x?] optional arguments.}
#:changed "1.17" @elem{Added the @racket[#:get-data-from-file?]
argument.}]}


@defproc[(recorded-datum->procedure [datum any/c]) ((is-a?/c dc<%>) . -> . void?)]{
Expand Down
2 changes: 1 addition & 1 deletion draw-lib/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

(define pkg-authors '(mflatt))

(define version "1.16")
(define version "1.17")
1 change: 1 addition & 0 deletions draw-lib/racket/draw.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'bmp 'bmp/alpha)
(or/c (is-a?/c color%) #f)
any/c
#:save-data-from-file? any/c
#:backing-scale (>/c 0.0)
#:try-@2x? any/c)
. ->* . (instanceof/c bitmap%/c))])
Expand Down
Loading

0 comments on commit 51faf19

Please sign in to comment.