kernel/model/image.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! What a picture is on the canonical conversation.
7//! The part `crates/kernel/spec/Model.lean` specifies this module with the
8//! rest of `kernel::model`.
9//!
10//! The ledger holds a reference and four integers, never bytes: the
11//! bytes live in `storage::cas` under the locator this value carries, so
12//! a history stays a file a person can read and the float ban holds
13//! without an exception for pixels.
14
15use serde::{Deserialize, Serialize};
16
17use crate::locator::Locator;
18
19/// The picture formats this city carries.
20///
21/// Closed rather than `non_exhaustive`, because this is not a vocabulary
22/// a provider hands us: it is the set we decided to accept, and adding
23/// one has to answer [`ImageType::mime`] in the same edit.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
25#[serde(rename_all = "snake_case")]
26pub enum ImageType {
27 Png,
28 Jpeg,
29 Webp,
30 Gif,
31}
32
33impl ImageType {
34 /// The media type both provider wires spell this format with.
35 #[must_use]
36 pub fn mime(&self) -> &'static str {
37 match self {
38 ImageType::Png => "image/png",
39 ImageType::Jpeg => "image/jpeg",
40 ImageType::Webp => "image/webp",
41 ImageType::Gif => "image/gif",
42 }
43 }
44}
45
46/// One picture, as everything except the wire refers to it.
47///
48/// The same value stands in a [`crate::ContentBlock::Image`] block and in
49/// a tool result's attachments, because they are the same four facts. A
50/// second definition of them would be a second authority: adding a field
51/// would then have to be remembered twice.
52///
53/// `width` and `height` are pixel counts, so they are integers; a
54/// display that wants a ratio computes it where the drawing happens.
55#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct ImageRef {
57 /// A `cas:` locator. The bytes are fetched from the content store by
58 /// whoever is about to send them, and never travel in the ledger.
59 pub locator: Locator,
60 pub media_type: ImageType,
61 pub width: u32,
62 pub height: u32,
63}