E D R S I H C RSS
ID
Password
Join
์žฅ๋‹˜ ์•ž์—์„œ๋Š” ์• ๊พธ๊ฐ€ ๋ณต๋œ ์ž ์ด๋‹ค. - ํ”„๋ ˆ๋ฐ๋ฆฌํฌ ๋Œ€์™•

๏ปฟ * ๊ตฌ๊ธ€์—์„œ ์šฐ์—ฐํžˆ ์ฐพ์€ ํ™”์ผ์•ˆ์˜ ๋‚ด์šฉ ์ค‘ RLE ๋ถ€๋ถ„๋งŒ ๋ฒˆ์—ญํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Contents

1 ๊ฐœ์š”
2 ์ฒซ๋ฒˆ์งธ RLE ๊ตฌ์กฐ(scheme)
3 Second RLE scheme

1 ๊ฐœ์š” #

RLE์€ Run Length Encoding์˜ ์•ฝ์–ด์ด๋‹ค. ๋‹ค๋ฅธ ์•ฝ์–ด๋ฅผ ๋“ค์ž๋ฉด RLC (Run Length Coding)๋ผ๊ณ ๋„ ํ•œ๋‹ค. (๋‘˜์€ ๊ฐ™์€ ๋œป์ด๋‹ค.) ์ด ๋ฐฉ์‹์˜ ์•„์ด๋””์–ด๋Š” ๋ฐ์ดํƒ€๋ฅผ ๋ฐ˜๋ณต๋˜๋Š” ํ”„๋ ˆ์ž„์— ๊ธฐ์ค€ํ•˜์—ฌ ์žฌ์ฝ”๋”ฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ํ”„๋ ˆ์ž„์€ ํ•œ๋ฒˆ ์ด์ƒ ๋ฐ˜๋ณต๋˜๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ฐ”์ดํŠธ๋“ค์ด ๋  ์ˆ˜ ์žˆ๋‹ค.

There are several means to encode occurrences. ๋”ฐ๋ผ์„œ, ๋ช‡๊ฐ€์ง€ ์ฝ”๋ฑ(๋ณตํ˜ธ๊ธฐ)๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์ž๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฐ์—ด์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ณ  ํ•˜์ž:
0,0,0,0,0,0,255,255,255,2,3,4,2,3,4,5,8,11

๋ช‡๋ช‡ ์ฝ”๋ฑ์€ ๋‹จ์ง€ 0๊ณผ 255 ์ „์ฒด์˜ ๋ฐ˜๋ณต๋งŒ์„ ๋‹ค๋ฃฐ ๊ฒƒ์ด๊ณ , ๋ช‡๋ช‡ ์ฝ”๋ฑ์€ 0์˜ ๋ฐ˜๋ณต๊ณผ 255์˜ ๋ฐ˜๋ณต์„ ๋ณ„๋„๋กœ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค.

์ด ์˜ˆ์ œ์— ๊ธฐ์ดˆํ•œ ์ค‘์š”ํ•œ ์ ๋“ค์„ ๋ช…์‹ฌํ•˜๋„๋ก. ์ฝ”๋ฑ์€ ์••์ถ•ํ•˜๋ ค๊ณ  ํ•˜๋Š” ๋ชจ๋“  ๋ฐ์ดํƒ€์— ๋™์ž‘ํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. ๊ทธ๋ž˜์„œ, ๋ฐ˜๋ณต๋˜๋Š” ์š”์†Œ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, RLE๋ฐฉ์‹์˜ ์ฝ”๋ฑ์€ ์••์ถ•ํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ํ•  ํ•„์š”๋Š” ์—†๋‹ค. ์‹ค์ œ๋กœ, ๋ฐ˜๋ณต๋˜์ง€ ์•Š์€ ๋ฐ์ดํƒ€๋ฅผ ์••์ถ•ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•  ๊ฒƒ์ด๋‹ค. (์ด๊ฒƒ์€ ๋ฐ์ดํƒ€๋ฅผ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.) ๋ฌผ๋ก , ์ž…๋ ฅ ๋ฐ์ดํƒ€์˜ ๋ณต์‚ฌ๋ณธ์€ ๊ฐ ๋ณต์‚ฌ ๋ธ”๋Ÿญ์˜ ์•ž์— "ํ—ค๋”"๊ฐ€ ๋ถ™์–ด์žˆ๋‹ค. ์ด๊ฒƒ์€ ์ „์ฒด๋ฐ์ดํƒ€๋ฅผ ์••์ถ•ํ•œ๋‹ค๊ธฐ ๋ณด๋‹ค๋Š” ๋„๋ฆฌ์–ด ํฌ๊ธฐ๋ฅผ ์ฆ๊ฐ€์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์••์ถ•๋˜๋Š” ์ „์ฒด ๋ฐ์ดํƒ€์˜ ์ž…์žฅ์—์„œ ๋ณด๋ฉด, ๋ฐ˜๋ณต๋˜๋Š” ํ”„๋ ˆ์ž„ ๋ถ€๋ถ„์˜ ์••์ถ•์€ ๋น„์••์ถ•๋ถ€๋ถ„๋ณด๋‹ค ํ›จ์”ฌ ์ ์€ ๊ณต๊ฐ„์„ ์ฐจ์ง€ํ•  ๊ฒƒ์ด๋‹ค.

RLE๋ผ๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ๋ชจ๋“  ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ 3~4๊ฐœ์˜ ์ˆ˜์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค:
  • Value saying if there's a repetition
  • Value saying how many repetitions (or non repetition)
  • Value of the length of the frame (useless if you just encode frame with one byte as maximum length)
  • Value of the frame to repeat (or not)

์–ธ๊ธ‰ํ•œ ๊ฒƒ์„ ์„ค๋ช…ํ•˜๊ธฐ์œ„ํ•ด 4๊ฐ€์ง€์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ œ์‹œํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

2 ์ฒซ๋ฒˆ์งธ RLE ๊ตฌ์กฐ(scheme) #

์ฒซ๋ฒˆ์งธ ๊ตฌ์กฐ๋Š” ๋‚ด๊ฐ€ ์•Œ๊ณ  ์žˆ๋Š” ํ•œ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๊ตฌ์กฐ์ด๋‹ค. MAC ์–ด๋“œ๋ ˆ์Šค ์‹œ์Šคํ…œ(MacPackBit)์—์„œ ์‚ฌ์šฉ๋œ ๊ฒƒ๊ณผ Targa, PCX, TIFF๋“ฑ๋“ฑ์˜ ํ™”์ผํฌ๋ฉง์—์„œ ์‚ฌ์šฉ๋œ ๋ฐฉ์‹๊ณผ ๋น„์Šทํ•˜๊ฒŒ ๋ณด์ผ ์ˆ˜๋„ ์žˆ๋‹ค.

์—ฌ๊ธฐ, ๋ชจ๋“  ์••์ถ•๋œ ๋ธ”๋Ÿญ์€ ํ—ค๋”(header)๋ผ๊ณ  ์ด๋ฆ„์ง€์–ด์ง„ 1 ๋ฐ”์ดํŠธ๋กœ ์‹œ์ž‘๋œ๋‹ค. ์ด๊ฒƒ์€ ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™๋‹ค:

Bits76543210
HeaderXXXXXXXX

  • ๋น„ํŠธ 7 : ์••์ถ• ์ƒํ™ฉ (1 = ์••์ถ•์ด ์ ์šฉ๋จ)
  • 0 ~ 6 : ๋‹ค๋ฃจ์–ด์•ผํ•  ๋ฐ”์ดํŠธ์˜ ์ˆ˜

๋”ฐ๋ผ์„œ, ๋งŒ์•ฝ ๋น„ํŠธ 7์ด 0์œผ๋กœ ์„ค์ •๋˜์—ˆ๋‹ค๋ฉด, 0 ~ 6๋น„ํŠธ ๋ถ€๋ถ„์€ ๋’ค๋”ฐ๋ผ์˜ค๋Š” ๋ฐ”์ดํŠธ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. (minus 1, to gain more over compress) So, if the bit 7 is set up to 0, the 0 to 6 bits give the number of bytes that follow (minus 1, to gain more over compress) and that were not compressed (native bytes). ๋งŒ์•ฝ ๋น„ํŠธ 7์ด 1๋กœ ์„ค์ •๋˜์–ด์žˆ์œผ๋ฉด, If the bit 7 is set up to 1, the same 0 to 6 bits give the number of repetition (minus 2) of the following byte.

๋ณด๋‹ค์‹œํ”ผ, ์ด ๋ฐฉ๋ฒ•์€ ๋‹จ์ง€ 1 ๋ฐ”์ดํŠธ๋กœ ํ”„๋ ˆ์ž„์„ ์ œ์–ดํ•  ๋ฟ์ด๋‹ค.

์ถ”๊ฐ€์‚ฌํ•ญ : ์—ฌ๋Ÿฌ๋ถ„์€ ์••์ถ•ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ ์–ด๋„ 1๊ฐœ์˜ ๋ฐ”์ด๋“œ๋ฅผ ๊ฐ€์ ธ์•ผ ํ•˜๋ฏ€๋กœ ๋น„์••์ถ• ํ”„๋ ˆ์ž„์— ๋Œ€ํ•ด.. You have 'minus 1' for non-repeated frames because you must have at least one byte to compress and 'minus 2' for repeated frames because the repetition must be 2, at least.

Compression scheme:
	      First byte=Next
		    /\
		   /  \
Count the byte         Count the occurrence of NON identical
occurrences            bytes (maximum 128 times)
(maximum 129 times)    and store them in an array
	|                        |
	|                        |
  1 bit '1'                 1 bit '0'
+ 7 bits giving           + 7 bits giving
  the number (-2)           the number (-1)
  of repetitions            of non repetition
+ repeated byte           + n non repeated bytes
	|                        |
 1xxxxxxx,yyyyyyyy        0xxxxxxx,n bytes
[-----------------]      [----------------]

Example:
Sequence of bytes to encodeCoded valuesDifferences with compression (unit: byte)
255,15,1,255,15,-1
255,255,128,255,0
15,15,128,15,0
255,255,255,129,255,+1
15,15,15,129,15,+1
255,255,255,255,130,255,+2
15,15,15,15130,15+2

See codecs source codes: codrle1.c and dcodrle1.c

3 Second RLE scheme #


In the second scheme of RLE compression you look for the less frequent byte in the source to compress and use it as an header for all compressed block.

In the best cases, the occurrence of this byte is zero in the data to compress.

Two possible schemes, firstly with handling frames with only one byte, secondly with handling frames with one byte *and* more. The first case is the subject of this current compression scheme, the second is the subject of next compression scheme.

For the frame of one byte, header byte is written in front of all repetition with at least 4 bytes. It is then followed by the repetition number minus 1 and the repeated byte. Header byte, Occurrence number-1, repeated byte

If a byte don't repeat more than tree times, the three bytes are written without changes in the destination stream (no header nor length, nor repetition in front or after theses bytes).

An exception: If the header byte appears in the source one, two, three and up times, it'll be respectively encoded as following: - Header byte, 0 - Header byte, 1 - Header byte, 2 - Header byte, Occurrence number-1, Header byte

Example, let's take the previous example. A non frequent byte is zero-ASCII because it never appears.

Sequence of bytes to encode | Coded values | Differences with compression
(unit: byte)

255,15, | 255,15, | 0 255,255, | 255,255, | 0
15,15, | 15,15, | 0
255,255,255, | 255,255,255, | 0
15,15,15, | 15,15,15, | 0
255,255,255,255, | 0,3,255, | -1
15,15,15,15 | 0,3,15 | -1

If the header would appear, we would see:

Sequence of bytes to encode | Coded values | Differences with compression
(unit: byte)

0, | 0,0, | +1
255, | 255, | 0
0,0, | 0,1, | 0 15, | 15, | 0
0,0,0, | 0,2, | -1
255, | 255, | 0
0,0,0,0 | 0,3,0 | -1

See codecs source codes: codrle2.c and dcodrle2.c

*** Third RLE scheme ***

It's the same idea as the second scheme but we can encode frames with more than one byte. So we have three cases:

- If it was the header byte, whatever is its occurrence, you encode it with: Header byte,0,number of occurrence-1 - For frames which (repetition-1)*length>3, encode it as: Header byte, Number of frame repetition-1, frame length-1,bytes of frame - If no previous cases were detected, you write them as originally (no header, nor length, nor repetition in front or after theses bytes).

Example based on the previous examples:

Sequence of bytes to encode | Coded values | Differences with compression
(unit: byte)

255,15, | 255,15, | 0 255,255, | 255,255, | 0
15,15, | 15,15, | 0
255,255,255, | 255,255,255, | 0
15,15,15, | 15,15,15, | 0
255,255,255,255, | 255,255,255,255, | 0
15,15,15,15, | 15,15,15,15, | 0
16,17,18,16,17,18, |16,17,18,16,17,18,| 0
255,255,255,255,255, | 0,4,0,255, | -1
15,15,15,15,15, | 0,4,0,15, | -1
16,17,18,16,17,18,16,17,18,| 0,2,2,16,17,18, | -3
26,27,28,29,26,27,28,29 |0,1,3,26,27,28,29 | -1

If the header (value 0) would be met, we would see:

Sequence of bytes to encode | Coded values | Differences with compression
(unit: byte)

0, | 0,0,0, | +2
255, | 255, | 0
0,0, | 0,0,1, | +1
15, | 15, | 0
0,0,0, | 0,0,2, | 0
255, | 255, | 0
0,0,0,0 | 0,0,3 | -1

See codecs source codes: codrle3.c and dcodrle3.c

*** Fourth RLE scheme ***

This last RLE algorithm better handles repetitions of any kind (one byte and more) and non repetitions, including few non repetitions, and does not read the source by twice as RLE type 3.

Compression scheme is:

First byte=Next byte?
/\
Yes / \ No
/ \
1 bit '0' 1 bit '1'
/ \
/ \
Count the Motif of several occurrences repeated byte? of 1 repeated ( 65 bytes repeated byte (maximum 257 times maxi) 16449 times) /\
/\ / \
/ \ / \
/ \ / \
/ \ / \ 1 bit '0' 1 bit '1' 1 bit '0' 1 bit '1'
+ 6 bits + 14 bits + 6 bits of | giving the giving the the length Number of non repetition length (-2) length (-66) of the motif (maximum 8224) of the of the + 8 bits of /\ repeated byte repeated byte the number (-2) < 33 / \ > 32 + repeated byte + repeated byte of repetition / \
+ bytes of the 1 bit '0' 1 bit '1'
| | motif + 5 bits of + 13 bits
| the numer (-1) of the
| | | of non number (-33)
| repetition of repetition
| | | + non + non
| repeated repeated
| | | bytes bytes
| | |
| | | | 111xxxxx,xxxxxxxx,n bytes
| | -------------------------
| | | |
| 110xxxxx,n bytes
| | | ----------------
|
| | 10xxxxxx,yyyyyyyy,n bytes
-------------------------
| | | 01xxxxxx,xxxxxxxx,1 byte | ------------------------ |
00xxxxxx,1 byte ---------------

Example, same as previously:

Sequence of bytes to encode | Coded values | Differences with compression
(unit: byte)

255,15,255,255,15,15 |11000101b,255,15,255,255,15,15 | +1
255,255,255 | 00000001b,255, | -1
15,15,15 | 00000001b,15, | -1
255,255,255,255 | 00000010b,255, | -2
15,15,15,15 | 00000010b,15, | -2
16,17,18,16,17,18 | 10000001b,0,16,17,18, | -1
255,255,255,255,255 | 00000011b,255, | -3
15,15,15,15,15 | 00000011b,15, | -3
16,17,18,16,17,18,16,17,18 | 10000001b,16,17,18, | -4
26,27,28,29,26,27,28,29 | 10000010b,26,27,28,29 | -2


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-10-28 12:42:54
Processing time 0.5361 sec