Difference between revisions of "Run Length Encoded"

From LifeWiki
Jump to navigation Jump to search
(48 intermediate revisions by 7 users not shown)
Line 1: Line 1:
The '''Run Length Encoded''' (or '''RLE''' for short) file format is well-suited for storing large [[pattern|patterns]]. It is more cryptic than some other file formats such as [[plaintext]] and [[Life 1.06]], but is still quite readable.
The '''Run Length Encoded''' (or '''RLE''' for short) [[:Category:File formats|file format]] is commonly-used for storing large [[pattern]]s. It is more cryptic than some other file formats such as [[plaintext]] and [[Life 1.06]], but is still quite readable. Many features of the RLE file format are incorporated in the [[MCell (file format)|MCell]] file format. RLE files are saved with a .rle file extension.  


==Description of Format==
==Description of format==
The first line is a header line, which has the form
The first line is a header line, which has the form


<code>x = m, y = n</code>
x = m, y = n


where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence if items of the form &lt;run_count&gt;&lt;tag&gt;, where &lt;run_count&gt; is the number of occurrences of &lt;tag&gt; and &lt;tag&gt; is one of the following three characters:
where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence of items of the form &lt;run_count&gt;&lt;tag&gt;, where &lt;run_count&gt; is the number of occurrences of &lt;tag&gt; and &lt;tag&gt; is one of the following three characters:


{| class="wikitable"
{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:center;"
|-
|-
! &lt;tag&gt;
! &lt;tag&gt;
Line 23: Line 23:
|}
|}


&lt;run_count&gt; can be omitted if it is equal to 1. The last <run_count><tag> item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between <run_count><tag> items (and between the last <run_count><tag> item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a <run_count><tag> item, although it's a good idea for RLE-readers to be able to cope with this anyway.
&lt;run_count&gt; can be omitted if it is equal to 1. The last &lt;run_count&gt;&lt;tag&gt; item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between &lt;run_count&gt;&lt;tag&gt; items (and between the last &lt;run_count&gt;&lt;tag&gt; item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a &lt;run_count&gt;&lt;tag&gt; item.


Lines in the RLE file must not exceed 70 characters, but again it's a good idea for RLE-readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.
Lines in the RLE file must not exceed 70 characters, although it is a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.


Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).
Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).


Later RLE enhancements
===# lines===


(1) The header line may be preceded by any number of lines beginning with the # character. The # is followed by a letter indicating the type of information that the line provides. These letters generally follow the conventions for XLife files which are described in the file xlife.man in the XLife distribution, although some of the letters
The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for [[XLife]] files, which are described in the file xlife.man in the XLife distribution. Here is a list of letters likely to be encountered in practice:
described there are not necessarily meaningful in RLE files. An RLE-reader should ignore any line marked with a letter it does not know about. Here is a list of letters likely to be encountered in practice:


C - indicates that a line of comment follows. This is the only really common use of # lines. Example:
{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:left;"
|-
! letter
! description
|-
| C
| Indicates that a line of comment follows. This is the only really common use of # lines.<br />Example: #C 'Twas brillig and the slithy toves
|-
| c
| Same as C, but not recommended.
|-
| N
| The name of the pattern.<br />Example: #N My awesome pattern
|-
| O
| Says when and by whom the file was created. RLE files produced by XLife usually have this line.<br />Example: #O John Smith john@gmail.com Fri Apr 30 19:38:52 1999
|-
| P
| Essentially the same as R, below. This line is produced by Life32, which generates coordinates which should represent the top-left corner of the Life pattern.<br />Example: #P 90 136
|-
| R
| Gives the coordinates of the top-left corner of the pattern. RLE files produced by XLife usually have this line, and the coordinates are usually negative, with the intention of placing the centre of the pattern at the origin.<br />Example: #R -22 -57
|-
| r
| Gives the [[rules]] for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.<br />Example: #r 23/3
|}
 
===Other features===


#C 'Twas brillig and the slithy toves
The rule for which the pattern is designed can be indicated in the header line, which then takes the form
c - same as C, but not really correct. Example:


#c Did gyre and gimble in the wabe.
x = m, y = n, rule = abc
O - says when and by whom the file was created. RLE files produced by XLife usually have this line. Example:


#O ook "The Librarian"@unseen.edu Fri Apr 30 19:38:52 1999
where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for [[HighLife]]. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.
P - essentially the same as R. This line is produced by Life32, which generates coordinates which probably won't be of use to anyone unless the user has taken care to make sure they are (which is unlikely). Best ignored. Example:


#P 90 136
Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it is a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.
R - gives the coordinates of the top left-hand corner of the pattern. RLE files produced by XLife usually have this line, and the coordinates are usually negative with the intention of placing the centre of the pattern at the origin. Example:


#R -22 -57
==Examples==
r - gives the rule for a totalistic cellular automaton in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife. But the normal method of indicating the rule is described in (2) below. Example:
The following is a [[glider]] in RLE format:


#r 23/36
<pre>
(2) The rule for which the pattern is designed can be indicated in the header line, which then takes the form
&#35;C This is a glider.
x = 3, y = 3
bo$2bo$3o!
</pre>


x = m, y = n, rule = abc
The following is the [[Gosper glider gun]] in RLE format:
where abc is the rule's designation, such as B36/S23 for HighLife. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE-writers should adhere to the spacing shown, but RLE-readers are best not to assume it.


(3) Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it's a good idea to stick to lowercase letters. RLE-readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.
<pre>&#35;N Gosper glider gun
&#35;C This was the first gun discovered.
&#35;C As its name suggests, it was discovered by Bill Gosper.
x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!
</pre>


==Examples==
==See also==
The following is a [[glider]] in RLE format:
* [[Macrocell]]
* [[apgsearch format]]


<code>
==External links==
x = 3, y = 3
{{LinkGollyHelp|formats.html#rle|title=Extended RLE format}}
<br />3o$o$bo!
{{LinkMirek|ca_files_formats.html|title=Cellular automata file formats}}
</code>
{{LinkLexicon|lex_r.htm#rle}}


The large Mark D. Niemiec's site (http://home.interserv.com/~mniemiec/) has thousands of files saved in RLE format. The files contain an RLE file syntax extension - they use “x”, “y”, and “z” characters to denote 3 more cell states.
[[Category:Everything else]][[Category:File formats]]

Revision as of 05:03, 28 August 2017

The Run Length Encoded (or RLE for short) file format is commonly-used for storing large patterns. It is more cryptic than some other file formats such as plaintext and Life 1.06, but is still quite readable. Many features of the RLE file format are incorporated in the MCell file format. RLE files are saved with a .rle file extension.

Description of format

The first line is a header line, which has the form

x = m, y = n

where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence of items of the form <run_count><tag>, where <run_count> is the number of occurrences of <tag> and <tag> is one of the following three characters:

<tag> description
b dead cell
o alive cell
$ end of line

<run_count> can be omitted if it is equal to 1. The last <run_count><tag> item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between <run_count><tag> items (and between the last <run_count><tag> item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a <run_count><tag> item.

Lines in the RLE file must not exceed 70 characters, although it is a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.

Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).

# lines

The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for XLife files, which are described in the file xlife.man in the XLife distribution. Here is a list of letters likely to be encountered in practice:

letter description
C Indicates that a line of comment follows. This is the only really common use of # lines.
Example: #C 'Twas brillig and the slithy toves
c Same as C, but not recommended.
N The name of the pattern.
Example: #N My awesome pattern
O Says when and by whom the file was created. RLE files produced by XLife usually have this line.
Example: #O John Smith john@gmail.com Fri Apr 30 19:38:52 1999
P Essentially the same as R, below. This line is produced by Life32, which generates coordinates which should represent the top-left corner of the Life pattern.
Example: #P 90 136
R Gives the coordinates of the top-left corner of the pattern. RLE files produced by XLife usually have this line, and the coordinates are usually negative, with the intention of placing the centre of the pattern at the origin.
Example: #R -22 -57
r Gives the rules for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.
Example: #r 23/3

Other features

The rule for which the pattern is designed can be indicated in the header line, which then takes the form

x = m, y = n, rule = abc

where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for HighLife. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.

Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it is a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.

Examples

The following is a glider in RLE format:

#C This is a glider.
x = 3, y = 3
bo$2bo$3o!

The following is the Gosper glider gun in RLE format:

#N Gosper glider gun
#C This was the first gun discovered.
#C As its name suggests, it was discovered by Bill Gosper.
x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!

See also

External links

Extended RLE format at Golly's online help Cellular automata file formats at Mirek Wójtowicz's Cellebration page