diff --git a/pkgs/images-pkgs/images-doc/images/scribblings/flomap.scrbl b/pkgs/images-pkgs/images-doc/images/scribblings/flomap.scrbl index 8c07362d81..f1c13428b2 100644 --- a/pkgs/images-pkgs/images-doc/images/scribblings/flomap.scrbl +++ b/pkgs/images-pkgs/images-doc/images/scribblings/flomap.scrbl @@ -327,7 +327,7 @@ Like @racket[unsafe-flomap-ref], but returns an flvector containing all the comp @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%]. 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. } -@defproc[(bitmap->flomap [bm Any]) flomap]{ -Given a @racket[bitmap%] instance, returns an ARGB flomap with alpha-multiplied color components. +@defproc[(bitmap->flomap [bm Any] [#:unscaled? unscaled? Any]) flomap]{ +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. +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. } diff --git a/pkgs/images-pkgs/images-lib/images/private/flomap-convert.rkt b/pkgs/images-pkgs/images-lib/images/private/flomap-convert.rkt index b92d61f60e..ac38bc7ec9 100644 --- a/pkgs/images-pkgs/images-lib/images/private/flomap-convert.rkt +++ b/pkgs/images-pkgs/images-lib/images/private/flomap-convert.rkt @@ -8,14 +8,19 @@ (provide bitmap->flomap flomap->bitmap draw-flomap) -(define (bitmap->flomap bm) +(define (bitmap->flomap bm #:unscaled? [unscaled? #f]) (unless (is-a? bm bitmap%) (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))) - (send bm get-argb-pixels 0 0 w h bs #t #t) - (send bm get-argb-pixels 0 0 w h bs #f #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 #:unscaled? unscaled?) (define argb-fm (make-flomap 4 w h)) (define argb-vs (flomap-values argb-fm)) diff --git a/pkgs/images-pkgs/images-lib/images/private/flomap.rkt b/pkgs/images-pkgs/images-lib/images/private/flomap.rkt index e3378bc12a..117e89ec40 100644 --- a/pkgs/images-pkgs/images-lib/images/private/flomap.rkt +++ b/pkgs/images-pkgs/images-lib/images/private/flomap.rkt @@ -29,7 +29,7 @@ (require/typed "flomap-convert.rkt" - [bitmap->flomap ((Instance Bitmap%) -> flomap)] + [bitmap->flomap ((Instance Bitmap%) [#:unscaled? Any] -> flomap)] [flomap->bitmap (flomap [#:backing-scale Positive-Real] -> (Instance Bitmap%))] [draw-flomap ((Any -> Any) Integer Integer -> flomap)])