MRF image format specification



MRF image format specification

NAME
DESCRIPTION
SEE ALSO
AUTHOR

NAME

MRF - monochrome recursive format (compressed bitmaps)

DESCRIPTION

This program is part of Netpbm(1)

MRF is a compressed format for bilevel (1-bit mono) images. It achieves better compression for some such images than either GIF or PNG. (It’s also very easy to implement (about the same difficulty as RLE, I’d say) and an MRF reader needs no tables/buffers, which may make it useful for tiny machines).

In case the above hasn’t made it sufficiently clear, I’ll make this next point explicitly: MRF cannot represent color at all. Nor can it represent grayscale. It’s a specifically mono format. (If you want to compress a color or grayscale image, my advice is to use JPEG2000).

First, here’s what goes where in an MRF file. I’ll explain how the compression works afterward.

Offset

Description

0

magic number - ’MRF1’ (in ASCII)

4

width (32-bit, MSB first (i.e. big-endian))

8

height (same)

12

reserved (single byte, must be zero)

13

compressed data

Note that there is no end-of-file marker in the file itself - the compressed data carries on right up to EOF.

The way the picture is compressed is essentially very simple, but as they say, the devil is in the detail. So don’t be put off if it sounds confusing.

The image is treated as a number of 64x64 squares, forming a grid large enough to encompass it. (If an image is (say) 129x65, it’ll be treated in the same way as a 192x128 one. On decompression, the extra area which was encoded (the contents of this area is undefined) should be ignored.) Each of these squares in turn (in left-to-right, top-to-bottom order) is recursively subdivided until the smallest completely black or white squares are found. Some pseudocode (eek!) for the recursive subdivision routine should make things clearer:

if square size > 1x1 and square is all one color, output 1 bit
if whole square is black, output a 0 bit and return
if whole square is white, output a 1 bit and return
output a 0 bit
divide the square into four quarters, calling routine for
each in this order: top-left, top-right, bottom-left, bottom-right

(Note that the ’output a 0 bit’ stage is not reached for squares of size 1x1, which is what stops it recursing infinitely. I mention this as it may not be immediately obvious.)

The whole of the compressed data is made up of the bits output by the above routine. The bits are packed into bytes MSB first, so for example outputting the bits 1,0,0,0,0,0,0,0 would result in a 80h byte being output. Any ‘unused’ bits in the last byte output are undefined; these are effectively after EOF and their value is unimportant.

If writing that sounds too much like hard work :-), you could always adapt pbmtomrf and/or mrftopbm. That’s the main reason their source code is public domain, after all.

Above, I said the contents of any extra area encoded (when a bitmap smaller than the grid of squares is compressed) is undefined. This is deliberate so that the MRF compressor can make these unseen areas anything it wants so as to maximize compression, rather than simply leaving it blank. pbmtomrf does a little in this respect but could definitely be improved upon.

mrftopbm’s -1 option causes it to include the edges, if any, in the output PBM. This may help when debugging a compressor’s edge optimization.

Note that the "F" in the name "MRF" comes from "format," which is redundant because it is the name of a format. That sort of makes "MRF format" sound as stupid as "PIN number," but it’s not really that bad.

SEE ALSO

mrftopbm(1) , pbmtomrf(1)

AUTHOR

Russell Marks.




More Linux Commands

manpages/_nc_freeall.3ncurses.html
_nc_freeall(3ncurses) - curses memory-leak checking.........
These functions are used to simplify analysis of memory leaks in the ncurses library. They are normally not available; they must be configured into the library

manpages/XkbKeyGroupWidth.3.html
XkbKeyGroupWidth(3) - Computes the width of the type associa
XkbKeyGroupWidth.3 - The key width and number of groups associated with a key are used to form a small two-dimensional array of KeySyms for a key. This array ma

manpages/getrusage.2.html
getrusage(2) - get resource usage - Linux manual page.......
getrusage() returns resource usage measures for who, which can be one of the following: RUSAGE_SELF Return resource usage statistics for the calling process, wh

manpages/FcPatternGet-Type.3.html
FcPatternGet-Type(3) - Return a typed value from a pattern
These are convenience functions that call FcPatternGet and verify that the returned data is of the expected type. They return FcResultTypeMismatch if this is no

manpages/socat.1.html
socat(1) Multipurpose relay (SOcket CAT) - Linux man page...
Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed fr

manpages/bindresvport.3.html
bindresvport(3) - bind a socket to a privileged IP port.....
bindresvport() is used to bind a socket descriptor to a privileged anonymous IP port, that is, a port number arbitrarily selected from the range 512 to 1023. If

manpages/win.3form.html
win(3form) - make and break form window and subwindow associ
Every form has an associated pair of curses windows. The form window displays any title and border associated with the window; the form subwindow displays the i

manpages/hypot.3.html
hypot(3) - Euclidean distance function - Linux manual page
The hypot() function returns sqrt(x*x+y*y). This is the length of the hypotenuse of a right-angled triangle with sides of length x and y, or the distance of the

manpages/XtRemoveSignal.3.html
XtRemoveSignal(3) - register and remove a signal source.....
The XtAppAddSignal function initiates a mechanism for handling signals within the context of the Intrinsics. Prior to establishing an operating system dependent

manpages/get_mempolicy.2.html
get_mempolicy(2) - Retrieve NUMA memory policy for a process
get_mempolicy() retrieves the NUMA policy of the calling process or of a memory address, depending on the setting of flags. A NUMA machine has different memory

manpages/XInitImage.3.html
XInitImage(3) - image utilities (Library - Linux man page)
The XInitImage function initializes the internal image manipulation routines of an image structure, based on the values of the various structure members. All fi

manpages/border_set.3ncurses.html
border_set(3ncurses) - create curses borders or lines using
border_set.3ncurses - The border_set and wborder_set functions draw a border around the edges of the current or specified window. These functions do not change





We can't live, work or learn in freedom unless the software we use is free.