🎉 Add keep-aspect-ratio integration

This commit is contained in:
Aitor Moreno
2025-07-21 11:31:19 +02:00
committed by Andrey Antukh
parent 8bb210e7b6
commit ffb688696b
2 changed files with 12 additions and 6 deletions

View File

@@ -23,7 +23,7 @@
(def ^:const GRADIENT-STOP-SIZE 8)
(def ^:const GRADIENT-BYTE-SIZE 156)
(def ^:const SOLID-BYTE-SIZE 4)
(def ^:const IMAGE-BYTE-SIZE 28)
(def ^:const IMAGE-BYTE-SIZE 36)
(def ^:const METADATA-BYTE-SIZE 36)
(def ^:const FILL-BYTE-SIZE
(+ 4 (mth/max GRADIENT-BYTE-SIZE
@@ -121,13 +121,13 @@
(let [image-id (get image :id)
image-width (get image :width)
image-height (get image :height)
keep-ratio (get image :keep-aspect-ratio false)]
keep-aspect-ratio (get image :keep-aspect-ratio false)]
(buf/write-byte buffer (+ offset 0) 0x03)
(buf/write-bool buffer (+ offset 1) keep-ratio)
(buf/write-uuid buffer (+ offset 4) image-id)
(buf/write-float buffer (+ offset 20) opacity)
(buf/write-int buffer (+ offset 24) image-width)
(buf/write-int buffer (+ offset 28) image-height)
(buf/write-bool buffer (+ offset 32) keep-aspect-ratio)
(+ offset FILL-BYTE-SIZE)))
(defn- write-metadata
@@ -203,7 +203,7 @@
:type type}})
3
(let [ratio (buf/read-bool dbuffer (+ doffset 1))
(let [ratio (buf/read-bool dbuffer (+ doffset 32))
id (buf/read-uuid dbuffer (+ doffset 4))
alpha (buf/read-float dbuffer (+ doffset 20))
width (buf/read-int dbuffer (+ doffset 24))

View File

@@ -11,6 +11,7 @@ pub struct RawImageFillData {
opacity: f32,
width: i32,
height: i32,
keep_aspect_ratio: i32,
}
impl From<RawImageFillData> for ImageFill {
@@ -18,7 +19,12 @@ impl From<RawImageFillData> for ImageFill {
let id = uuid_from_u32_quartet(value.a, value.b, value.c, value.d);
let opacity = (value.opacity * 255.).floor() as u8;
// TODO: read keep_aspect_ratio from RawImageFillData when implemented
Self::new(id, opacity, value.width, value.height, true)
Self::new(
id,
opacity,
value.width,
value.height,
value.keep_aspect_ratio != 0,
)
}
}