1MRF image format specification(0)            MRF image format specification(0)
2
3
4

NAME

6       MRF - monochrome recursive format (compressed bitmaps)
7
8

DESCRIPTION

10       This program is part of Netpbm(1).
11
12       MRF  is  a  compressed  format  for  bilevel  (1-bit  mono) images.  It
13       achieves better compression for some such images  than  either  GIF  or
14       PNG.  (It's  also  very easy to implement (about the same difficulty as
15       RLE, I'd say) and an MRF reader needs no tables/buffers, which may make
16       it useful for tiny machines).
17
18       In  case  the  above  hasn't made it sufficiently clear, I'll make this
19       next point explicitly: MRF cannot represent color at all.  Nor  can  it
20       represent grayscale.  It's a specifically mono format.  (If you want to
21       compress a color or grayscale image, my advice is to use JPEG2000).
22
23       First, here's what goes where in an MRF file. I'll explain how the com‐
24       pression works afterward.
25
26
27
28       Offset Description
29
30       0      magic number - "MRF1" (in ASCII)
31
32
33       4      width (32-bit, MSB first (i.e. big-endian))
34
35
36       8      height (same)
37
38
39       12     reserved (single byte, must be zero)
40
41
42       13     compressed data
43
44
45
46       Note  that there is no end-of-file marker in the file itself - the com‐
47       pressed data carries on right up to EOF.
48
49       The way the picture is compressed is essentially very  simple,  but  as
50       they say, the devil is in the detail.  So don't be put off if it sounds
51       confusing.
52
53       The image is treated as a number of 64x64 squares, forming a grid large
54       enough  to encompass it. (If an image is (say) 129x65, it'll be treated
55       in the same way as a 192x128 one.  On  decompression,  the  extra  area
56       which  was  encoded  (the contents of this area is undefined) should be
57       ignored.) Each of these squares in turn (in left-to-right,  top-to-bot‐
58       tom  order)  is  recursively  subdivided  until the smallest completely
59       black or white squares are  found.  Some  pseudocode  (eek!)   for  the
60       recursive subdivision routine should make things clearer:
61
62           if square size > 1x1 and square is all one color, output 1 bit
63           if whole square is black, output a 0 bit and return
64           if whole square is white, output a 1 bit and return
65           output a 0 bit
66           divide the square into four quarters, calling routine for
67           each in this order: top-left, top-right, bottom-left, bottom-right
68
69       (Note  that  the  "output  a 0 bit" stage is not reached for squares of
70       size 1x1, which is what stops it recursing infinitely.  I mention  this
71       as it may not be immediately obvious.)
72
73       The  whole  of the compressed data is made up of the bits output by the
74       above routine. The bits are packed into bytes MSB first, so for example
75       outputting  the  bits  1,0,0,0,0,0,0,0 would result in a 80h byte being
76       output. Any `unused' bits in the last byte output are undefined;  these
77       are effectively after EOF and their value is unimportant.
78
79       If  writing  that  sounds too much like hard work :-), you could always
80       adapt pbmtomrf and/or mrftopbm.  That's the main  reason  their  source
81       code is public domain, after all.
82
83       Above,  I  said  the  contents of any extra area encoded (when a bitmap
84       smaller than the grid of squares is compressed) is undefined.  This  is
85       deliberate  so that the MRF compressor can make these unseen areas any‐
86       thing it wants so as to maximize compression, rather than simply  leav‐
87       ing  it  blank.  pbmtomrf does a little in this respect but could defi‐
88       nitely be improved upon.
89
90       mrftopbm's -1 option causes it to include the edges,  if  any,  in  the
91       output PBM.  This may help when debugging a compressor's edge optimiza‐
92       tion.
93
94       Note that the "F" in the name  "MRF"  comes  from  "format,"  which  is
95       redundant  because it is the name of a format.  That sort of makes "MRF
96       format" sound as stupid as "PIN number," but it's not really that bad.
97
98
99

SEE ALSO

101       mrftopbm(1), pbmtomrf(1)
102
103

AUTHOR

105       Russell Marks.
106

DOCUMENT SOURCE

108       This manual page was generated by the Netpbm tool 'makeman'  from  HTML
109       source.  The master documentation is at
110
111              http://netpbm.sourceforge.net/doc/mrf.html
112
113netpbm documentation                 1991    MRF image format specification(0)
Impressum