Skip to documentation
DocumentationAll documentsEnglish

BWROT(1)

NAME

bwrot - rotate, invert, or reverse a black and white bw file

On this page

SYNOPSIS

bwrot [-rifb | -a _angle_] [-# _bytes/pixel_] [-s _squaresize_] [-w _in_width_] [-n _in_height_] [-o _out.bw_] [_file.bw_] [> _out.bw_]

DESCRIPTION

bwrot rotates, vertically inverts, or horizontally reverses the pixels in a black and white bw(5) format file. By default the input is assumed to be 512x512; use -w, -n, or -s to specify other dimensions. If no input file is given, bwrot reads from standard input, and unless -o is used the result is written to standard output.

The orthogonal operations (-r, -i, -f, -b) may be combined; for example, -r and -i together produce a 180-degree rotation. The -a option performs an arbitrary-angle rotation instead and requires that the entire image fit in memory. Because the program works on fixed-size byte entities, the -# option lets it process any data composed of equal-sized elements (e.g. the color channels of a pix(5) file).

OPTIONS

-r

Reverse the scan lines horizontally (left to right).

-i

Invert the image vertically (top to bottom). Ignored if -b or -f is given.

-f

Rotate the image 90 degrees forward (clockwise, in lower-left-origin coordinates).

-b

Rotate the image 90 degrees backward (counterclockwise, in lower-left-origin coordinates).

-a angle

Rotate the image counterclockwise by an arbitrary angle in degrees. This overrides the orthogonal rotation, inversion, and reversal flags, and requires the whole image to fit in the in-memory buffer.

-# bytes/pixel

Set the number of bytes per pixel (default 1), allowing other fixed-element data formats to be processed.

-s squaresize, -S squaresize

Set both the input width and height to squaresize pixels.

-w in_width, -W in_width

Set the input width in pixels (default 512).

-n in_height, -N in_height

Set the input height in scan lines (default 512).

-o out.bw

Write output to out.bw. If standard output is also redirected, the same output is written there as well.

-h, -?

Print a usage message and exit.

METHOD

A large buffer is kept in memory so that, file size permitting, the entire rotation can occur without seeking. The algorithm processes the input sequentially, so any required seeking happens on output only. If those seeks fail (e.g. the output is a pipe), bwrot reports that it needs a real file on output; use -o in that case.

EXAMPLES

Example 1. Rotate an image 90 degrees clockwise
$ bwrot -f -w 1024 -n 768 image.bw > rotated.bw

Rotates the 1024x768 image image.bw 90 degrees forward (clockwise) into rotated.bw. The output dimensions become 768x1024.

Example 2. Flip an image upside down before display
$ bwrot -i -s 256 image.bw | bw-pix | pix-fb

Vertically inverts a 256x256 black and white image, converts it to color with bw-pix(1), and displays it on the framebuffer with pix-fb(1) — handy for correcting top-down versus bottom-up scanline ordering.

Example 3. Arbitrary angle rotation
$ bwrot -a 45.5 -s 1024 input.bw > rotated.bw

Rotates the 1024x1024 image input.bw counterclockwise by 45.5 degrees.

SEE ALSO

brlcad(1), pixrot(1), bwscale(1), bwrect(1), bw-pix(1), bw(5)

BUGS

If the file is very large and does not fit in the buffer, excessive seeking may occur on output and the rotation can take a very long time. Arbitrary-angle rotation (-a) requires the entire image to fit in memory.

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