Products| Business Software: | Home and Family: | ||
| Load! - Container Optimization | Ages! - Family Tree Software | ||
| Name | Size | Description | |||
|---|---|---|---|---|---|
| Signature | 6 bytes | 'GIF87a' or 'GIF89a' | |||
| GlobalDescriptor | 7 bytes | global descriptor, always present | |||
| Width | 2 bytes | width in pixels | |||
| Height | 2 bytes | height in pixels | |||
| Flags | 1 byte | global descriptor flags | |||
| GlobalColorMap | bit 7 | =1 if GlobalColorMap exists (should be true in almost all cases) =0 if default map is used, or if every image has a LocalColorMap | |||
| ColorResolutionBits | bits 6-4 | +1 = significant bits per color in GlobalColorMap | |||
| reserved | bit 3 | =0 | |||
| PixelBits | bits 2-0 | +1 = ColorDepth, NumberOfGlobalColors := 2ColorDepth | |||
| BackgroundColor | 1 byte | background color number (from GlobalColorMap or default map) | |||
| AspectRatio | 1 byte | usually =0 | |||
| GlobalColorMap | NumberOfGlobalColors * 3 | global color table, present only when GlobalDescriptor.Flags.GlobalColorMap = 1 | |||
| Red | 1 byte | red intensity of color (not necessarily 8 significant bits) | |||
| Green | 1 byte | green intensity of color (not necessarily 8 significant bits) | |||
| Blue | 1 byte | blue intensity of color (not necessarily 8 significant bits) | |||
| repeated NumberOfGlobalColors times | |||||
| ExtensionBlocks | cannot be pre calculated | optional, may be repeated any number of times. read first byte to check its presence. | |||
| Header | 1 byte | =$21 | |||
| FunctionCode | 1 byte | there is a list of known function codes below | |||
| Length | 1 byte | >0 ! | |||
| Data | Length bytes | interpretation of this data depends on its function code | |||
| repeated any number of times. read first byte to check for terminator | |||||
| Terminator | 1 byte | =0 | |||
| LocalDescriptor | 10 bytes | local descriptor. always present | |||
| Header | 1 bytes | =$2C | |||
| PosX | 2 bytes | horizontal position of image in global image | |||
| PosY | 2 bytes | vertical position of image in global image | |||
| Width | 2 bytes | width of image | |||
| Height | 2 bytes | height of image | |||
| Flags | 1 byte | local descriptor Flags | |||
| LocalColorMap | bit 7 | =1 if LocalColorMap exists =0 if GlobalColorMap (or default map) is used | |||
| InterlacedImage | bit 6 | =1 Interlaced ! =0 Non Interlaced | |||
| Sorted | bit 5 | usually =0 | |||
| reserved | bit 4-3 | =0 | |||
| PixelBits | bit 2-0 | +1 = ColorDepth, NumberOfLocalColors := 2ColorDepth | |||
| LocalColorMap | NumberOfLocalColors * 3 | local color table, present only when LocalDescriptor.Flags.LocalColorMap = 1 | |||
| Red | 1 byte | red intensity of color | |||
| Green | 1 byte | green intensity of color | |||
| Blue | 1 byte | blue intensity of color | |||
| repeated NumberOfLocalColors times | |||||
| Raster Data Block | cannot be pre calculated | always present | |||
| InitialCodeSize | 1 byte | usually = ColorDepth, except for black&white, where it is 2! | |||
| Length | 1 byte | >0 | |||
| Data | Length bytes | The pixel data bit stream. See decompression and compression schemes | |||
| repeated any number of times. read first byte to check for terminator | |||||
| Terminator | 1 byte | =0! | |||
| ExtensionBlocks | cannot be pre calculated | optional. read first byte to check its presence - format is identical to the ExtensionBlock above | |||
| Terminator | 1 byte | =$3B | |||
| Function Code | Name | Size | Description | ||
|---|---|---|---|---|---|
| 1 | PlaintextExtension | any | < incomplete > | ||
| 249 | LocalDescriptorExtension | 4 bytes | |||
| Flags | 1 byte | ||||
| reserved ? | bits 7-5 | ||||
| Undraw | bits 4-2 | 000 undefined (portability warning) 001 leave image for overwrite 010 restore background 011 restore previous 1xx undefined _ | |||
| User Input | bit 1 | ||||
| Transparent | bit 0 | =1 image has a transparent color =0 no transparent color | |||
| Duration | 2 bytes | ||||
| TransparentColor | 1 byte | ||||
| 254 | CommentExtension | any | |||
| 255 | ApplicationExtension | any | |||
| Initialize string table. (entries 0 .. End-Of-Information) codesize = InitialCodeSize + 1 c := empty output a ClearCode _ | |||
| p := next pixel | |||
| is (c + appended p) in string table? | |||
| Yes: | c := c + appended p | ||
| No: | append (c + appended p) to string table output code for c to file c := p if code = max. for code size (code = 511 @ 9bits?) increase codesize by 1 if codesize = 13 reset string table, output a 12bit ClearCode and reset codesize to (InitialCodeSize + 1) (see portability warning) | ||
| repeat until no more pixels | |||
| if c <> empty output code for c output End-Of-Information | |||
| codesize = InitialCodeSize + 1 ClearCode = 2^CodeSize EndOfInformation = ClearCode + 1 counter = EndOfInformation + 1 output a ClearCode | ||
| p := next pixel c := p + added high order bit 0 output c increment counter if counter = max. for CodeSize - 1: write ClearCode and reset counter to EndOfInformation + 1 | ||
| repeat until no more pixels | ||
| output End-Of-Information | ||
| colordepth in bits | codesize overhead in bits approx. | overhead % | |
|---|---|---|---|
| 8 | 9 n + 9n / 253 | 13% | |
| 7 | 8 n + 8n / 125 | 15% | |
| 6 | 7 n + 7n / 61 | 19% | |
| 5 | 6 n + 6n / 29 | 24% | |
| 4 | 5 n + 5n / 13 | 35% | |
| 3 | 4 n + 4n / 5 | 60% | |
| 2 | 3 n + 3n | 200% | |
| 1 | 3 2n + 3n | 500% | |
| encoding schemes with increasing code lengths | |||
| 2 | 3+4 1.66n + 4n / 8 | 191% | |
| 1 | 3+4 2.66n + 4n / 8 | 316% | |
| Initialize string table (entries 0 .. End-Of-Information) codesize = InitialCodeSize + 1 code <- first code from file c <- string table entry for code output c old <- c | |||
| code <- next code from file if code = ClearCode: Reinitialize string table, and reset codesize to InitialCodeSize + 1 is code in string table? | |||
| Yes: | add to string table: (old + appended first pixel of c) c <- string table entry for code | ||
| No: | add to string table: (old + appended first pixel of old) c <- new string table entry | ||
| output c old <- c if (added-table-entry# = max. for codesize) and (codesize < 12 ) (code = 511 @ 9bits?) increase codesize by 1 | |||
| repeat until code = EndOfInformation | |||
| codesize = InitialCodeSize + 1 ClearCode = 2^CodeSize EndOfInformation = ClearCode + 1 counter = EndOfInformation + 1 | ||
| code <- next code from file increment counter if code < ClearCode: output a pixel of color (code) if code = ClearCode: counter = Endofinformation + 1, codesize = InitialCodeSize + 1 if (counter = max. for codesize) and (codesize < 12) increase codesize by 1 | ||
| repeat until code >= EndOfInformation | ||
| if last code was not EndOfInformation: throw away image | ||
| Pass | Scheme | Lines | Number of Lines | |
|---|---|---|---|---|
| 1 | Every 8th line, starting from line 0 | 0, 8, 16, 24, ... | (height+7) div 8 | |
| 2 | Every 8th line, starting from line 4 | 4, 12, 20, 28, ... | (height+3) div 8 | |
| 3 | Every 4th line, starting from line 2 | 2, 6, 10, 14, ... | (height+1) div 4 | |
| 4 | Every 2nd line, starting from line 1 (all odd lines) | 1, 3, 5, 7, 9, ... | (height) div 2 | |