~/bend-docscommunity

deflate_rgb.bend checks

raw source on the hub · import element-image@0.1.0.0/deflate_rgb.bend as Deflate_rgb

1 import
import Base

Types

type S source · line 6 · raw

Data

RGB scanlines -> a zlib stream, in Bend. RFC 1951 sections 3.2.5/3.2.6: fixed Huffman codes and distance-three matches for repeated RGB pixels. Runs are capped at 86 pixels, so all Adler-32 arithmetic fits U32.

Definitions

def flush source · line 9 · raw

@full:Bool -> @s:S -> S

def flush_one source · line 16 · raw

@s:S -> S

def put source · line 22 · raw

@s:S -> @value:U32 -> @width:U32 -> S

At most 13 bits enter a buffer holding at most seven: flush twice.

def reverse source · line 27 · raw

@n:Nat -> @+x:U32 -> @out:U32 -> U32

def literal_kind source · line 34 · raw

@small:Bool -> @s:S -> @c:U32 -> S

def literal source · line 41 · raw

@s:S -> @+c:U32 -> S

def length_code_kind source · line 44 · raw

@short:Bool -> @s:S -> @code:U32 -> S

def length_code source · line 51 · raw

@s:S -> @+code:U32 -> S

def extra source · line 54 · raw

@+n:U32 -> U32

def length_kind source · line 59 · raw

@short:Bool -> @s:S -> @+n:U32 -> S

def repeat_pixels source · line 70 · raw

@repeat:Bool -> @s:S -> @+n:U32 -> S

def continued_length source · line 79 · raw

@full:Bool -> @s:S -> @+n:U32 -> S

def run_body source · line 88 · raw

@continued:Bool -> @s:S -> @+r:U32 -> @+g:U32 -> @+b:U32 -> @+n:U32 -> S

def adler_rgb source · line 98 · raw

@s:S -> @+n:U32 -> @+r:U32 -> @+g:U32 -> @+b:U32 -> S

For n repetitions of RGB: A += n*(r+g+b), and B adds the weighted byte sum plus 3*n*A(old). Max n=86 keeps the largest product < 2^32.

def run_kind source · line 108 · raw

@empty:Bool -> @s:S -> @+color:U32 -> @+n:U32 -> @continued:Bool -> S

def run source · line 118 · raw

@s:S -> @color:U32 -> @+n:U32 -> @continued:Bool -> S

def next_run source · line 121 · raw

@same:Bool -> @s:S -> @color:U32 -> @n:U32 -> @continued:Bool -> S

def row source · line 128 · raw

@xs:List<&2, U32> -> @s:S -> @+color:U32 -> @+n:U32 -> @+continued:Bool -> S

def filter source · line 138 · raw

@s:S -> S

def rows source · line 143 · raw

@xs:List<&2, List<&2, U32>> -> @s:S -> S

def final_bytes source · line 150 · raw

@empty:Bool -> @bits:U32 -> @out:List<&2, U32> -> List<&2, U32>

def finish source · line 157 · raw

@s:S -> List<&2, U32>

def zlib source · line 164 · raw

@xs:List<&2, List<&2, U32>> -> List<&2, U32>