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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//! # pixo
//!
//! A minimal-dependency, high-performance image compression library with PNG
//! and JPEG encoders written entirely in Rust.
//!
//! - **PNG**: All filter types, DEFLATE compressor, palette quantization,
//! buffer reuse helpers, and presets from fast to max compression.
//! - **JPEG**: Baseline & progressive encoding, optimized Huffman tables,
//! trellis quantization, and buffer reuse helpers.
//! - **Performance**: Optional SIMD and parallel fast paths, tuned defaults,
//! optimal DEFLATE for final packing, and small WASM output.
//! - **Docs-first**: Conceptual guides (PNG, JPEG, DEFLATE, DCT, quantization,
//! performance) are embedded directly in rustdoc under [`guides`].
//!
//! ## Quickstart
//!
//! ```rust
//! use pixo::{png, jpeg, ColorType};
//! use pixo::png::PngOptions;
//! use pixo::jpeg::JpegOptions;
//!
//! # fn main() -> pixo::Result<()> {
//! // PNG: 3x1 RGB pixels (red, green, blue)
//! let png_pixels = vec![255, 0, 0, 0, 255, 0, 0, 0, 255];
//! let png_opts = PngOptions::builder(3, 1).color_type(ColorType::Rgb).build();
//! let png_bytes = png::encode(&png_pixels, &png_opts)?;
//! assert!(!png_bytes.is_empty());
//!
//! // JPEG: 1x1 RGB pixel
//! let jpg_pixels = vec![255, 0, 0];
//! let jpg_opts = JpegOptions::builder(1, 1).color_type(ColorType::Rgb).quality(85).build();
//! let jpg_bytes = jpeg::encode(&jpg_pixels, &jpg_opts)?;
//! assert!(!jpg_bytes.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! ### Custom options (PNG)
//!
//! ```rust
//! use pixo::png::{encode, FilterStrategy, PngOptions};
//! use pixo::ColorType;
//!
//! # fn main() -> pixo::Result<()> {
//! let pixels = vec![255, 0, 0, 0, 255, 0, 0, 0, 255];
//! let options = PngOptions::builder(3, 1)
//! .color_type(ColorType::Rgb)
//! .preset(1) // balanced: compression level 6, adaptive filters + lossless opts
//! .filter_strategy(FilterStrategy::Adaptive)
//! .optimize_alpha(true)
//! .build();
//! let png_bytes = encode(&pixels, &options)?;
//! assert!(!png_bytes.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! ### Custom options (JPEG)
//!
//! ```rust
//! use pixo::jpeg::{encode, JpegOptions};
//! use pixo::ColorType;
//!
//! # fn main() -> pixo::Result<()> {
//! let pixels = vec![255, 0, 0];
//! let options = JpegOptions::max(1, 1, 85); // progressive + trellis + optimized Huffman
//! let jpg_bytes = encode(&pixels, &options)?;
//! assert!(!jpg_bytes.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! ### Image resizing
//!
//! ```rust
//! use pixo::{resize, ColorType, ResizeAlgorithm, ResizeOptions};
//!
//! # fn main() -> pixo::Result<()> {
//! // 4x4 RGBA image -> 2x2 using Lanczos3 (highest quality)
//! let pixels = vec![128u8; 4 * 4 * 4];
//! let options = ResizeOptions::builder(4, 4)
//! .dst(2, 2)
//! .color_type(ColorType::Rgba)
//! .algorithm(ResizeAlgorithm::Lanczos3)
//! .build();
//! let resized = resize::resize(&pixels, &options)?;
//! assert_eq!(resized.len(), 2 * 2 * 4);
//! # Ok(())
//! # }
//! ```
//!
//! ### Buffer reuse
//!
//! ```rust
//! use pixo::{jpeg, png, ColorType};
//! use pixo::png::PngOptions;
//! use pixo::jpeg::JpegOptions;
//!
//! # fn main() -> pixo::Result<()> {
//! let pixels = vec![255, 0, 0, 0, 255, 0]; // 2 RGB pixels
//!
//! let mut png_buf = Vec::new();
//! let png_opts = PngOptions::builder(2, 1).color_type(ColorType::Rgb).build();
//! png::encode_into(&mut png_buf, &pixels, &png_opts)?;
//!
//! let mut jpg_buf = Vec::new();
//! let jpg_opts = JpegOptions::balanced(2, 1, 85);
//! jpeg::encode_into(&mut jpg_buf, &pixels, &jpg_opts)?;
//!
//! assert!(!png_buf.is_empty() && !jpg_buf.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! ## Feature flags
//! - `simd` (default): Enable SIMD-accelerated kernels with runtime detection.
//! - `parallel` (default): Parallel row-level filtering in PNG via rayon.
//! - `wasm`: WebAssembly bindings (see [`guides::wasm`]).
//! - `cli`: Command-line encoder (see [`guides::cli`]).
//!
//! ## Guides inside rustdoc
//! - [`guides::overview`] — Documentation index.
//! - [`guides::introduction_to_image_compression`] — Compression fundamentals.
//! - [`guides::png_encoding`] — PNG pipeline, filters, palette quantization.
//! - [`guides::jpeg_encoding`] — JPEG pipeline, DCT, quantization, trellis.
//! - [`guides::performance_optimization`] — SIMD/parallel/algorithm tuning.
//! - [`guides::huffman_coding`], [`guides::lz77_compression`], [`guides::deflate`] — Core compressors.
//! - [`guides::dct`] and [`guides::quantization`] — JPEG math deep dives.
//! - [`guides::wasm`] and [`guides::cli`] — Platform integration.
//!
//! ## When to use which format
//! - **PNG**: sharp UI, screenshots, graphics; lossless and optionally palette-quantized.
//! - **JPEG**: photographs and gradients; choose quality + subsampling to trade size for fidelity.
//!
//! ## Safety and performance notes
//! - Unsafe is only compiled when `simd` or `wasm` is enabled; otherwise `forbid(unsafe_code)` is applied.
//! - Prefer `encode_into` variants when encoding repeatedly to reuse allocations.
//! - For smallest PNGs, use `PngOptions::max(w, h)` (slow) or enable auto quantization for lossy palette outputs.
//! - For smallest JPEGs, use `JpegOptions::max(w, h, quality)` which enables optimized Huffman, progressive scans, and trellis quantization.
// Allow unsafe code only when SIMD or WASM feature is enabled
pub use ColorType;
pub use ;
pub use ;
/// High-level and conceptual guides rendered inside rustdoc.
///
/// The markdown files in `docs/` use relative links (e.g., `./huffman-coding.md`)
/// which work when browsing on GitHub. At build time, `build.rs` transforms these
/// to rustdoc intra-doc links (e.g., `crate::guides::huffman_coding`) so they work
/// on docs.rs.