{"record":{"id":"495fa3ad9134e6d0","repo":"tonhowtf/omniget","slug":"n-o-codifiquei-o-jpeg","errorCode":null,"errorMessage":"não codifiquei o JPEG: {}","messagePattern":"não codifiquei o JPEG: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/image_compress.rs","lineNumber":72,"sourceCode":"    pub height: u32,\n    pub scaled: bool,\n    pub hit_target: bool,\n    pub ok: bool,\n    pub error: Option<String>,\n}\n\n#[derive(Debug, Clone, Serialize)]\npub struct CompressResult {\n    pub items: Vec<CompressItem>,\n    pub bytes_before: u64,\n    pub bytes_after: u64,\n}\n\npub fn encode_jpeg(img: &DynamicImage, quality: u8) -> anyhow::Result<Vec<u8>> {\n    let mut buf = Cursor::new(Vec::new());\n    let mut enc = JpegEncoder::new_with_quality(&mut buf, quality.clamp(1, 100));\n    enc.encode_image(&img.to_rgb8())\n        .map_err(|e| anyhow!(\"não codifiquei o JPEG: {}\", e))?;\n    Ok(buf.into_inner())\n}\n\n/// Busca binária da qualidade que cabe no alvo. Devolve `(bytes, qualidade)`\n/// com a **maior** qualidade que ainda cabe; se nem no mínimo couber, devolve\n/// a do mínimo para quem chamou decidir se encolhe a imagem.\npub fn fit_quality(\n    img: &DynamicImage,\n    target_bytes: u64,\n    min_quality: u8,\n    max_quality: u8,\n) -> anyhow::Result<(Vec<u8>, u8, bool)> {\n    let (mut lo, mut hi) = (min_quality.max(1), max_quality.min(100));\n    let mut best: Option<(Vec<u8>, u8)> = None;\n    // 7 passos cobrem a faixa 1-100 com folga.\n    for _ in 0..7 {\n        if lo > hi {\n            break;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/image_compress.rs#L54-L90","documentation":"Encoder failure in encode_jpeg: the image crate's JpegEncoder rejected the RGB buffer or failed mid-write (unsupported dimensions, I/O on the in-memory cursor, or encoder panic captured as an error), so no JPEG bytes are returned for this quality attempt.","triggerScenarios":"Thrown at src-tauri/omniget-core/src/core/tools/image_compress.rs:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the input DynamicImage has non-zero dimensions","Retry with a different quality value; the binary search may hit edge cases","Convert to rgb8 explicitly before encoding if the input layout is unusual"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}