1\
2.\" This man page was generated by the Netpbm tool 'makeman' from HTML source.
3.\" Do not hand-hack it!  If you have bug fixes or improvements, please find
4.\" the corresponding HTML page on the Netpbm website, generate a patch
5.\" against that, and send it to the Netpbm maintainer.
6.TH "MRF image format specification" 0 "1991" "netpbm documentation"
7
8.UN lbAB
9.SH NAME
10
11MRF - monochrome recursive format (compressed bitmaps)
12
13.UN lbAC
14.SH DESCRIPTION
15.PP
16This program is part of
17.BR "Netpbm" (1)\c
18\&.
19.PP
20MRF is a compressed format for bilevel (1-bit mono) images.  It
21achieves better compression for some such images than either GIF or
22PNG. (It's also very easy to implement (about the same difficulty as
23RLE, I'd say) and an MRF reader needs no tables/buffers, which may
24make it useful for tiny machines).
25.PP
26In case the above hasn't made it sufficiently clear, I'll make this
27next point explicitly: \fIMRF cannot represent color at all.\fP Nor
28can it represent grayscale.  It's a specifically mono format.  (If you
29want to compress a color or grayscale image, my advice is to use
30JPEG2000).
31.PP
32First, here's what goes where in an MRF file. I'll explain how the
33compression works afterward.
34
35
36.TP
37Offset
38Description
39.TP
400
41magic number - "MRF1" (in ASCII)
42
43.TP
444
45width (32-bit, MSB first (i.e. big-endian))
46
47.TP
488
49height (same)
50
51.TP
5212
53reserved (single byte, must be zero)
54
55.TP
5613
57compressed data
58
59
60.PP
61Note that there is no end-of-file marker in the file itself - the
62compressed data carries on right up to EOF.
63.PP
64The way the picture is compressed is essentially very simple, but
65as they say, the devil is in the detail.  So don't be put off if it
66sounds confusing.
67.PP
68The image is treated as a number of 64x64 squares, forming a grid
69large enough to encompass it. (If an image is (say) 129x65, it'll be
70treated in the same way as a 192x128 one. On decompression, the extra
71area which was encoded (the contents of this area is undefined) should
72be ignored.) Each of these squares in turn (in left-to-right,
73top-to-bottom order) is recursively subdivided until the smallest
74completely black or white squares are found. Some pseudocode (eek!)
75for the recursive subdivision routine should make things clearer:
76
77.nf
78    if square size > 1x1 and square is all one color, output 1 bit
79    if whole square is black, output a 0 bit and return
80    if whole square is white, output a 1 bit and return
81    output a 0 bit
82    divide the square into four quarters, calling routine for
83    each in this order: top-left, top-right, bottom-left, bottom-right
84.fi
85.PP
86(Note that the "output a 0 bit" stage is not reached for squares
87of size 1x1, which is what stops it recursing infinitely.  I mention
88this as it may not be immediately obvious.)
89.PP
90The whole of the compressed data is made up of the bits output by
91the above routine. The bits are packed into bytes MSB first, so for
92example outputting the bits 1,0,0,0,0,0,0,0 would result in a 80h byte
93being output. Any `unused' bits in the last byte output are undefined;
94these are effectively after EOF and their value is unimportant.
95.PP
96If writing that sounds too much like hard work :-), you could
97always adapt \fBpbmtomrf\fP and/or \fBmrftopbm\fP.  That's the main
98reason their source code is public domain, after all.
99.PP
100Above, I said the contents of any extra area encoded (when a bitmap
101smaller than the grid of squares is compressed) is undefined.  This is
102deliberate so that the MRF compressor can make these unseen areas
103anything it wants so as to maximize compression, rather than simply
104leaving it blank. \fBpbmtomrf\fP does a little in this respect but
105could definitely be improved upon.
106.PP
107\fBmrftopbm\fP's \fB-1\fP option causes it to include the edges, if
108any, in the output PBM.  This may help when debugging a compressor's
109edge optimization.
110.PP
111Note that the "F" in the name "MRF" comes from "format," which is redundant
112because it is the name of a format.  That sort of makes "MRF format" sound
113as stupid as "PIN number," but it's not really that bad.
114
115
116.UN lbAE
117.SH SEE ALSO
118.BR "mrftopbm" (1)\c
119\&,
120.BR "pbmtomrf" (1)\c
121\&
122
123.UN lbAF
124.SH AUTHOR
125
126Russell Marks.
127.SH DOCUMENT SOURCE
128This manual page was generated by the Netpbm tool 'makeman' from HTML
129source.  The master documentation is at
130.IP
131.B http://netpbm.sourceforge.net/doc/mrf.html
132.PP