4.8 Resizing

► |  | Images

1 | Icons
2 | Logos
3 | Embedding Bitmaps in Compiled Files
4 | Floating-Point Bitmaps

▼ | 4 | Floating-Point Bitmaps

4.1 | Overview
4.2 | Struct Type and Accessors
4.3 | Conversion and Construction
4.4 | Component Operations
4.5 | Pointwise Operations
4.6 | Gradients and Normals
4.7 | Blur
4.8 | Resizing
4.9 | Compositing
4.10 | Spatial Transformations
4.11 | Effects

On this page:

flomap-copy
subflomap
flomap-trim
flomap-inset
flomap-crop
flomap-lt-crop
flomap-lc-crop
flomap-lb-crop
flomap-ct-crop
flomap-cc-crop
flomap-cb-crop
flomap-rt-crop
flomap-rc-crop
flomap-rb-crop
flomap-scale
flomap-resize

top ← prev up next →

#### 4.8`` Resizing

> procedure (flomap-copy fm x-start y-start x-end y-end) → flomap
> fm : flomap
> x-start : Integer
> y-start : Integer
> x-end : Integer
> y-end : Integer

Returns the part of fm for which the x coordinate is x-start ≤ x < x-end and the y coordinate is y-start ≤ y < y-end. If x-start ≥ x-end, the result is width 0, and if y-start ≥ y-end, the result is height 0.

The interval arguments may identify a rectangle with points outside the bounds of fm. In this case, the points’ values in the returned flomap are 0.0, as per the Conceptual Model.

This function is guaranteed to return a copy.

> procedure (subflomap fm x-start y-start x-end y-end) → flomap
> fm : flomap
> x-start : Integer
> y-start : Integer
> x-end : Integer
> y-end : Integer

Like flomap-copy, but returns fm when x-start and y-start are 0, and x-end and y-end are respectively the width and height of fm.

Use subflomap instead of flomap-copy when programming functionally. Every library function that returns parts of a flomap (such as flomap-trim and flomap-inset) is defined using subflomap.

> procedure (flomap-trim fm [alpha?]) → flomap
> fm : flomap
> alpha? : Boolean = #t

Shrinks fm to its largest nonzero rectangle. If alpha? is #t, it uses only component 0 to determine the largest nonzero rectangle; otherwise, it uses every component.

This function cannot return a larger flomap.

Examples:
> > (define small-circle-fm
> (draw-flomap (λ (fm-dc)
> (send fm-dc draw-ellipse 20 20 10 10))
> 100 100))
> > (flomap->bitmap small-circle-fm)
> > (flomap->bitmap (flomap-trim small-circle-fm))

See flomap-nonzero-rect.

> procedure (flomap-inset fm amt) → flomap
> fm : flomap
> amt : Integer
> (flomap-inset fm h-amt v-amt) → flomap
> fm : flomap
> h-amt : Integer
> v-amt : Integer
> (flomap-inset fm l-amt t-amt r-amt b-amt) → flomap
> fm : flomap
> l-amt : Integer
> t-amt : Integer
> r-amt : Integer
> b-amt : Integer

Extends fm by some amount on each side, filling any new values with 0.0. Positive inset amounts grow the flomap; negative insets shrink it. Large negative insets may shrink it to 0×0, which is a valid flomap size.

Example:
> > (flomap->bitmap (flomap-inset fm -10 20 -30 -40))

> procedure (flomap-crop fm w h left-frac top-frac) → flomap
> fm : flomap
> w : Integer
> h : Integer
> left-frac : Real
> top-frac : Real

Shrinks or grows fm to be size w×h. The proportion of points removed/added to the left and top are given by left-frac and top-frac; e.g. left-frac = 1/2 causes the same number to be removed/added to the left and right sides.

You will most likely want to use one of the following cropping functions instead, which are defined using flomap-crop.

> procedure (flomap-lt-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-lc-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-lb-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-ct-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-cc-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-cb-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-rt-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-rc-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

> procedure (flomap-rb-crop fm w h) → flomap
> fm : flomap
> w : Integer
> h : Integer

These shrink or grow fm to be size w×h. The two-letter abbreviation determines which area of the flomap is preserved. For example, flomap-lt-crop (“flomap left-top crop”) preserves the left-top corner:

> > (flomap->bitmap (flomap-lt-crop fm 150 150))

> procedure (flomap-scale fm x-scale [y-scale]) → flomap
> fm : flomap
> x-scale : Real
> y-scale : Real = x-scale

Scales fm to a proportion of its size. Uses bilinear interpolation to sample between integer coordinates, and reduces resolution (blurs) correctly before downsampling so that shrunk images are still sharp but not aliased (pixelated-looking).

Examples:
> > (flomap->bitmap (flomap-scale fm 1/8))
> > (flomap->bitmap (flomap-scale sine-fm 4))
> > (flomap-scale fm 0)
> (flomap (flvector) 4 0 0)

> procedure (flomap-resize fm w h) → flomap
> fm : flomap
> w : (Option Integer)
> h : (Option Integer)

Like flomap-scale, but accepts a width w and height h instead of scaling proportions. If either size is #f, the flomap is scaled in that direction to maintain its aspect ratio.

Examples:
> > (flomap->bitmap (flomap-resize fm 50 #f))
> > (flomap->bitmap (flomap-resize fm #f 50))
> > (flomap->bitmap (flomap-resize fm 20 50))
> > (flomap-resize fm 0 0)
> (flomap (flvector) 4 0 0)

top ← prev up next →