Files
a0_basic_app
a1_vehicle
a2_async_sim
ab_glyph
ab_glyph_rasterizer
adler
adler32
agents
aho_corasick
anyhow
approx
aquamarine
ash
atty
bitflags
bytemuck
byteorder
cache_padded
cfg_if
chrono
color_quant
crc32fast
crossbeam_channel
crossbeam_deque
crossbeam_epoch
crossbeam_utils
deflate
draw2d
either
flexi_logger
generic_array
gif
glfw
glfw_sys
glob
image
indoc
itertools
jpeg_decoder
lazy_static
libc
libloading
log
matrixmultiply
memchr
memoffset
miniz_oxide
nalgebra
base
geometry
linalg
third_party
num_complex
num_cpus
num_integer
num_iter
num_rational
num_traits
owned_ttf_parser
paste
png
proc_macro2
proc_macro_error
proc_macro_error_attr
quote
raw_window_handle
rawpointer
rayon
rayon_core
regex
regex_syntax
scoped_threadpool
scopeguard
semver
semver_parser
serde
serde_derive
simba
smawk
spin_sleep
syn
terminal_size
textwrap
thiserror
thiserror_impl
tiff
time
triple_buffer
ttf_parser
typenum
unicode_width
unicode_xid
unindent
vk_sys
weezl
yansi
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! # GIF en- and decoding library [![Build Status](https://github.com/image-rs/image-gif/workflows/Rust%20CI/badge.svg)](https://github.com/image-rs/image-gif/actions)
//! 
//! GIF en- and decoder written in Rust ([API Documentation](https://docs.rs/gif)).
//! 
//! # GIF encoding and decoding library
//! 
//! This library provides all functions necessary to de- and encode GIF files.
//! 
//! ## High level interface
//! 
//! The high level interface consists of the two types
//! [`Encoder`](struct.Encoder.html) and [`Decoder`](struct.Decoder.html).
//! 
//! ### Decoding GIF files
//! 
//! ```rust
//! // Open the file
//! use std::fs::File;
//! let mut decoder = gif::DecodeOptions::new();
//! // Configure the decoder such that it will expand the image to RGBA.
//! decoder.set_color_output(gif::ColorOutput::RGBA);
//! // Read the file header
//! let file = File::open("tests/samples/sample_1.gif").unwrap();
//! let mut decoder = decoder.read_info(file).unwrap();
//! while let Some(frame) = decoder.read_next_frame().unwrap() {
//!     // Process every frame
//! }
//! ```
//! 
//! 
//! 
//! ### Encoding GIF files
//!
//! The encoder can be used so save simple computer generated images:
//! 
//! ```rust
//! use gif::{Frame, Encoder, Repeat};
//! use std::fs::File;
//! use std::borrow::Cow;
//! 
//! let color_map = &[0xFF, 0xFF, 0xFF, 0, 0, 0];
//! let (width, height) = (6, 6);
//! let mut beacon_states = [[
//!     0, 0, 0, 0, 0, 0,
//!     0, 1, 1, 0, 0, 0,
//!     0, 1, 1, 0, 0, 0,
//!     0, 0, 0, 1, 1, 0,
//!     0, 0, 0, 1, 1, 0,
//!     0, 0, 0, 0, 0, 0,
//! ], [
//!     0, 0, 0, 0, 0, 0,
//!     0, 1, 1, 0, 0, 0,
//!     0, 1, 0, 0, 0, 0,
//!     0, 0, 0, 0, 1, 0,
//!     0, 0, 0, 1, 1, 0,
//!     0, 0, 0, 0, 0, 0,
//! ]];
//! let mut image = File::create("tests/samples/beacon.gif").unwrap();;
//! let mut encoder = Encoder::new(&mut image, width, height, color_map).unwrap();
//! encoder.set_repeat(Repeat::Infinite).unwrap();
//! for state in &beacon_states {
//!     let mut frame = Frame::default();
//!     frame.width = width;
//!     frame.height = height;
//!     frame.buffer = Cow::Borrowed(&*state);
//!     encoder.write_frame(&frame).unwrap();
//! }
//! ```
//!
//! [`Frame::from_*`](struct.Frame.html) can be used to convert a true color image to a paletted
//! image with a maximum of 256 colors:
//!
//! ```rust
//! use std::fs::File;
//! 
//! // Get pixel data from some source
//! let mut pixels: Vec<u8> = vec![0; 30_000];
//! // Create frame from data
//! let frame = gif::Frame::from_rgb(100, 100, &mut *pixels);
//! // Create encoder
//! let mut image = File::create("target/indexed_color.gif").unwrap();
//! let mut encoder = gif::Encoder::new(&mut image, frame.width, frame.height, &[]).unwrap();
//! // Write frame to file
//! encoder.write_frame(&frame).unwrap();
//! ```

// TODO: make this compile
// ```rust
// use gif::{Frame, Encoder};
// use std::fs::File;
// let color_map = &[0, 0, 0, 0xFF, 0xFF, 0xFF];
// let mut frame = Frame::default();
// // Generate checkerboard lattice
// for (i, j) in (0..10).zip(0..10) {
//     frame.buffer.push(if (i * j) % 2 == 0 {
//         1
//     } else {
//         0
//     })
// }
// # (|| {
// {
// let mut file = File::create("test.gif")?;
// let mut encoder = Encoder::new(&mut file, 100, 100);
// encoder.write_global_palette(color_map)?.write_frame(&frame)
// }
// # })().unwrap();
// ```
#![deny(missing_docs)]
#![cfg(feature = "std")]

mod traits;
mod common;
mod reader;
mod encoder;

pub use crate::common::{AnyExtension, Block, Extension, DisposalMethod, Frame};

pub use crate::reader::{StreamingDecoder, Decoded, DecodingError, DecodingFormatError};
/// StreamingDecoder configuration parameters
pub use crate::reader::{ColorOutput, MemoryLimit, Extensions};
pub use crate::reader::{DecodeOptions, Decoder};

pub use crate::encoder::{Encoder, ExtensionData, Repeat, EncodingError};

#[cfg(test)]
#[test]
fn round_trip() {
    use std::io::prelude::*;
    use std::fs::File;
    let mut data = vec![];
    File::open("tests/samples/sample_1.gif").unwrap().read_to_end(&mut data).unwrap();
    let mut decoder = Decoder::new(&*data).unwrap();
    let palette: Vec<u8> = decoder.palette().unwrap().into();
    let frame = decoder.read_next_frame().unwrap().unwrap();
    let mut data2 = vec![];
    {
        let mut encoder = Encoder::new(&mut data2, frame.width, frame.height, &palette).unwrap();
        encoder.write_frame(frame).unwrap();
    }
    assert_eq!(&data[..], &data2[..])
}

macro_rules! insert_as_doc {
    { $content:expr } => {
        #[doc = $content] extern { }
    }
}

// Provides the README.md as doc, to ensure the example works!
insert_as_doc!(include_str!("../README.md"));