Debian Codegraph @

upstream/debian-unstable/man1/mrf.1

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