{"record":{"id":"8f1e4d56f28c3463","repo":"flxzt/rnote","slug":"imagememoryformat-try-from-gdk-memoryformat-fai","errorCode":null,"errorMessage":"ImageMemoryFormat try_from() gdk::MemoryFormat failed, unsupported MemoryFormat `{:?}`","messagePattern":"ImageMemoryFormat try_from\\(\\) gdk::MemoryFormat failed, unsupported MemoryFormat `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/image.rs","lineNumber":44,"sourceCode":"#[non_exhaustive]\n#[derive(Debug, Copy, Clone, Serialize, Deserialize)]\npub enum ImageMemoryFormat {\n    R8g8b8a8Premultiplied,\n}\n\nimpl Default for ImageMemoryFormat {\n    fn default() -> Self {\n        Self::R8g8b8a8Premultiplied\n    }\n}\n\n#[cfg(feature = \"ui\")]\nimpl TryFrom<gtk4::gdk::MemoryFormat> for ImageMemoryFormat {\n    type Error = anyhow::Error;\n    fn try_from(value: gtk4::gdk::MemoryFormat) -> Result<Self, Self::Error> {\n        match value {\n            gtk4::gdk::MemoryFormat::R8g8b8a8Premultiplied => Ok(Self::R8g8b8a8Premultiplied),\n            _ => Err(anyhow::anyhow!(\n                \"ImageMemoryFormat try_from() gdk::MemoryFormat failed, unsupported MemoryFormat `{:?}`\",\n                value\n            )),\n        }\n    }\n}\n\n#[cfg(feature = \"ui\")]\nimpl From<ImageMemoryFormat> for gtk4::gdk::MemoryFormat {\n    fn from(value: ImageMemoryFormat) -> Self {\n        match value {\n            ImageMemoryFormat::R8g8b8a8Premultiplied => {\n                gtk4::gdk::MemoryFormat::R8g8b8a8Premultiplied\n            }\n        }\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/image.rs#L26-L62","documentation":"Converting a GDK MemoryFormat to the engine's ImageMemoryFormat failed because the format was anything other than R8g8b8a8Premultiplied. The engine only supports this single premultiplied RGBA layout when importing GTK/GDK image textures.","triggerScenarios":"Calling ImageMemoryFormat::try_from(gdk::MemoryFormat) with a texture whose memory format is e.g. B8g8r8a8Premultiplied, R8g8b8a8, R16g16b16a16, or any non-premultiplied variant.","commonSituations":"Pasting or importing images from other applications that deliver textures in BGRA order (common on some platforms/Python bindings); renderers producing 16-bit float textures.","solutions":["Convert the GdkTexture/MemoryTexture to R8g8b8a8Premultiplied before the try_from (e.g. download bytes and swizzle or request the right format).","Add a conversion branch for the offending MemoryFormat in image.rs instead of failing.","Downsample/normalize the source image to standard 8-bit premultiplied RGBA upstream.","Log the unsupported format value and fall back to re-encoding the image through PNG which guarantees RGBA8."],"exampleFix":"// before\nlet fmt = ImageMemoryFormat::try_from(mem_format)?;\n// after\nlet fmt = match ImageMemoryFormat::try_from(mem_format) {\n    Ok(f) => f,\n    Err(_) => { /* convert bytes to R8g8b8a8Premultiplied first */ ImageMemoryFormat::R8g8b8a8Premultiplied }\n};","handlingStrategy":"fallback","validationCode":"// rust\nlet supported = matches!(mem_format, gdk::MemoryFormat::R8g8b8a8Premultiplied);\nif !supported { /* convert before calling try_from */ }","typeGuard":"fn is_rgba8_premultiplied(f: gdk::MemoryFormat) -> bool {\n    matches!(f, gdk::MemoryFormat::R8g8b8a8Premultiplied)\n}","tryCatchPattern":"let fmt = match ImageMemoryFormat::try_from(mem_format) {\n    Ok(f) => f,\n    Err(e) => { log::warn!(\"{e}; converting to RGBA8\"); convert_to_rgba8(mem_format)? }\n};","preventionTips":["Check the texture's memory format before importing.","Convert non-RGBA8 textures to R8g8b8a8Premultiplied upstream.","Re-encode exotic images through PNG as a universal fallback."],"tags":["image","gtk","enum-conversion"],"backgroundTag":"unsupported-enum-value","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}