Added #:unscaled? keyword argument to `bitmap->flomap'
This commit is contained in:
parent
d202f415d9
commit
2cd8064bdd
|
@ -327,7 +327,7 @@ Like @racket[unsafe-flomap-ref], but returns an flvector containing all the comp
|
||||||
|
|
||||||
@section{Conversion and Construction}
|
@section{Conversion and Construction}
|
||||||
|
|
||||||
@defproc[(flomap->bitmap [fm flomap] [#:backing-scale backing-scale (>/c 0.0)]) Any]{
|
@defproc[(flomap->bitmap [fm flomap] [#:backing-scale backing-scale Positive-Real]) Any]{
|
||||||
Converts a flomap to a @racket[bitmap%].
|
Converts a flomap to a @racket[bitmap%].
|
||||||
|
|
||||||
The return type is imprecise because Typed Racket does not support the object system well yet.
|
The return type is imprecise because Typed Racket does not support the object system well yet.
|
||||||
|
@ -350,10 +350,13 @@ For example, if @racket[fm] is size 0×1, the result of @racket[(flomap->bitmap
|
||||||
Values are clamped to between @racket[0.0] and @racket[1.0] before conversion.
|
Values are clamped to between @racket[0.0] and @racket[1.0] before conversion.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(bitmap->flomap [bm Any]) flomap]{
|
@defproc[(bitmap->flomap [bm Any] [#:unscaled? unscaled? Any]) flomap]{
|
||||||
Given a @racket[bitmap%] instance, returns an ARGB flomap with alpha-multiplied color components.
|
Given a @racket[bitmap%] instance @racket[bm], returns an ARGB flomap with alpha-multiplied color components.
|
||||||
See @secref{flomap:opacity} for a discussion of opacity (alpha) representation.
|
See @secref{flomap:opacity} for a discussion of opacity (alpha) representation.
|
||||||
|
|
||||||
|
If @racket[unscaled?] is true, the flomap is converted from the actual bitmap backing @racket[bm] rather than a scaled version.
|
||||||
|
See the @racket[#:unscaled?] keyword parameter of @method[bitmap% get-argb-pixels] for more information.
|
||||||
|
|
||||||
The argument type is imprecise because Typed Racket does not support the object system well yet.
|
The argument type is imprecise because Typed Racket does not support the object system well yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,19 @@
|
||||||
|
|
||||||
(provide bitmap->flomap flomap->bitmap draw-flomap)
|
(provide bitmap->flomap flomap->bitmap draw-flomap)
|
||||||
|
|
||||||
(define (bitmap->flomap bm)
|
(define (bitmap->flomap bm #:unscaled? [unscaled? #f])
|
||||||
(unless (is-a? bm bitmap%)
|
(unless (is-a? bm bitmap%)
|
||||||
(raise-type-error 'bitmap->flomap "bitmap% instance" bm))
|
(raise-type-error 'bitmap->flomap "bitmap% instance" bm))
|
||||||
(define w (send bm get-width))
|
|
||||||
(define h (send bm get-height))
|
(define backing-scale (send bm get-backing-scale))
|
||||||
|
(define (scale d)
|
||||||
|
(if unscaled? (inexact->exact (ceiling (* d backing-scale))) d))
|
||||||
|
|
||||||
|
(define w (scale (send bm get-width)))
|
||||||
|
(define h (scale (send bm get-height)))
|
||||||
(define bs (make-bytes (* 4 w h)))
|
(define bs (make-bytes (* 4 w h)))
|
||||||
(send bm get-argb-pixels 0 0 w h bs #t #t)
|
(send bm get-argb-pixels 0 0 w h bs #t #t #:unscaled? unscaled?)
|
||||||
(send bm get-argb-pixels 0 0 w h bs #f #t)
|
(send bm get-argb-pixels 0 0 w h bs #f #t #:unscaled? unscaled?)
|
||||||
|
|
||||||
(define argb-fm (make-flomap 4 w h))
|
(define argb-fm (make-flomap 4 w h))
|
||||||
(define argb-vs (flomap-values argb-fm))
|
(define argb-vs (flomap-values argb-fm))
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
(require/typed
|
(require/typed
|
||||||
"flomap-convert.rkt"
|
"flomap-convert.rkt"
|
||||||
[bitmap->flomap ((Instance Bitmap%) -> flomap)]
|
[bitmap->flomap ((Instance Bitmap%) [#:unscaled? Any] -> flomap)]
|
||||||
[flomap->bitmap (flomap [#:backing-scale Positive-Real] -> (Instance Bitmap%))]
|
[flomap->bitmap (flomap [#:backing-scale Positive-Real] -> (Instance Bitmap%))]
|
||||||
[draw-flomap ((Any -> Any) Integer Integer -> flomap)])
|
[draw-flomap ((Any -> Any) Integer Integer -> flomap)])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user