Skip to documentation
DocumentationAll documentsEnglish

BWSCALE(1)

NAME

bwscale - change the size of a black and white bw image

On this page

SYNOPSIS

bwscale [-r] [-s _squareinsize_] [-w _inwidth_] [-n _inheight_] [-S _squareoutsize_] [-W _outwidth_] [-N _outheight_] [_in.bw_] > _out.bw_
bwscale _in.bw_ _inwidth_ _inheight_ _outwidth_ _outheight_ > _out.bw_

DESCRIPTION

bwscale reads a black and white bw(5) image of given dimensions and writes a larger or smaller scaled version to standard output. Input is taken from the named file or, if none is given, from standard input. If the input and output dimensions are not specified, both default to 512x512.

When scaling up, bwscale uses bilinear interpolation (or nearest-neighbor pixel replication with -r); outer edge pixels are preserved and only interior pixels are interpolated. When scaling down, a "square pixel" box filter is used that preserves the light energy per unit area, with each input pixel contributing in proportion to the fraction of the output pixel it covers. A single invocation cannot stretch one axis while compressing the other.

OPTIONS

-r

Scale up by pixel replication (nearest-neighbor) instead of bilinear interpolation.

-s squareinsize

Set both the input width and height to squareinsize pixels.

-w inwidth

Set the input width in pixels (default 512).

-n inheight

Set the input height in pixels (default 512).

-S squareoutsize

Set both the output width and height to squareoutsize pixels.

-W outwidth

Set the output width in pixels (default 512).

-N outheight

Set the output height in pixels (default 512).

-h, -?

Print a usage message and exit.

As a backward-compatibility convenience, the input file and all four dimensions may instead be given as five positional arguments: in.bw inwidth inheight outwidth outheight.

EXAMPLES

Example 1. Halve the resolution of a 1024x1024 image
bwscale -s 1024 -S 512 hires.bw > thumb.bw

Down-samples a 1024x1024 image to 512x512 using the box filter, which averages the contributing input pixels to avoid aliasing.

Example 2. Build a small preview from a streamed image
gencolor -r 1048576 200 | bwscale -s 1024 -S 128 > tiny.bw

Feeds a 1024x1024 grayscale stream into bwscale, producing a 128x128 preview. bwscale reads the bw(5) data from standard input because no file name is supplied.

Example 3. Enlarge with crisp pixels
bwscale -r -s 64 -S 256 icon.bw | bw-png -s 256 - > icon.png

Quadruples a 64x64 icon to 256x256 using pixel replication (-r) so the result stays blocky rather than blurred, then converts it to PNG with bw-png(1).

SEE ALSO

brlcad(1), bwcrop(1), bwrect(1), pixscale(1), bw-png(1), bw(5)

BUGS

This program cannot scale up in one dimension and down in the other at the same time.

The box filter used for scaling down results in the usual high-frequency ripple.

Optional cubic interpolation would be nice.

AUTHOR

BRL-CAD Team

This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory.

BUG REPORTS

Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org