mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 19:46:11 +02:00
♻️ Adapt linear gradient type so it can be used for radial too (wasm)
This commit is contained in:
parent
f40ef26c69
commit
abcd050c69
6 changed files with 32 additions and 28 deletions
|
@ -50,12 +50,16 @@
|
|||
(def GRID-LAYOUT-ROW-ENTRY-SIZE 5)
|
||||
(def GRID-LAYOUT-COLUMN-ENTRY-SIZE 5)
|
||||
(def GRID-LAYOUT-CELL-ENTRY-SIZE 37)
|
||||
(def GRADIENT-STOP-SIZE 5)
|
||||
(def LINEAR-FILL-BASE-SIZE 21)
|
||||
|
||||
|
||||
(defn gradient-stop-get-entries-size
|
||||
[stops]
|
||||
(mem/get-list-size stops GRADIENT-STOP-SIZE))
|
||||
(mem/get-list-size stops sr-fills/GRADIENT-STOP-SIZE))
|
||||
|
||||
(defn gradient-byte-size
|
||||
[gradient]
|
||||
(let [stops (:stops gradient)]
|
||||
(+ sr-fills/GRADIENT-BASE-SIZE (* (count stops) sr-fills/GRADIENT-STOP-SIZE))))
|
||||
|
||||
(defn modifier-get-entries-size
|
||||
"Returns the list of a modifier list in bytes"
|
||||
|
@ -232,8 +236,7 @@
|
|||
(some? gradient)
|
||||
(case (:type gradient)
|
||||
:linear
|
||||
(let [stops (:stops gradient)
|
||||
size (+ LINEAR-FILL-BASE-SIZE (* (count stops) GRADIENT-STOP-SIZE))
|
||||
(let [size (gradient-byte-size gradient)
|
||||
offset (mem/alloc-bytes size)
|
||||
heap (mem/get-heap-u8)]
|
||||
(sr-fills/serialize-linear-fill gradient opacity heap offset)
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
[app.common.uuid :as uuid]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
|
||||
|
||||
(defn u8
|
||||
[value]
|
||||
(let [u8-arr (js/Uint8Array. 1)]
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.render-wasm.serializers.color :as clr]))
|
||||
|
||||
(def GRADIENT-STOP-SIZE 5)
|
||||
(def GRADIENT-BASE-SIZE 24)
|
||||
|
||||
(defn serialize-linear-fill
|
||||
[gradient opacity heap-u8 offset]
|
||||
(let [dview (js/DataView. (.-buffer heap-u8))
|
||||
|
@ -10,13 +13,14 @@
|
|||
start-y (dm/get-prop gradient :start-y)
|
||||
end-x (dm/get-prop gradient :end-x)
|
||||
end-y (dm/get-prop gradient :end-y)
|
||||
stops (dm/get-prop gradient :stops)]
|
||||
stops (dm/get-prop gradient :stops)
|
||||
width 0]
|
||||
(.setFloat32 dview offset start-x true)
|
||||
(.setFloat32 dview (+ offset 4) start-y true)
|
||||
(.setFloat32 dview (+ offset 8) end-x true)
|
||||
(.setFloat32 dview (+ offset 12) end-y true)
|
||||
(.setFloat32 dview (+ offset 16) opacity true)
|
||||
(.setUint8 dview (+ offset 20) (count stops))
|
||||
(.setFloat32 dview (+ offset 20) width true)
|
||||
(loop [stops (seq stops) idx 0]
|
||||
(when-not (empty? stops)
|
||||
(let [stop (first stops)
|
||||
|
@ -24,7 +28,7 @@
|
|||
opacity (dm/get-prop stop :opacity)
|
||||
rgba (clr/hex->u32argb hex-color opacity)
|
||||
stop-offset (* 100 (dm/get-prop stop :offset))
|
||||
dview-offset (+ (* idx 5) offset 21)]
|
||||
dview-offset (+ (* idx 5) offset 24)]
|
||||
(.setUint32 dview dview-offset rgba true)
|
||||
(.setUint8 dview (+ dview-offset 4) stop-offset)
|
||||
(recur (rest stops) (+ idx 1)))))))
|
Loading…
Add table
Add a link
Reference in a new issue