{deck}
version:1
card:0
size:[512,342]
name:"palimport.deck"
patterns:"%%IMG2AAgA5gBAAUEABwEBAAcBAQAHAQgABAEBAAcBAQAHAQEAAwEIAAIBAQAGAQEABgEBAAcBAgAFAQEAAgEBAAMBAQAEAQMABgEBAAYBAQAEAQEAEwEBAAsBAQATAQEACwEIAAEBAwABAQ0AAQEDAAEBCQABAQMAAQENAAEBAwABAQEAAQEDAAMBAQACAQEAAwEBAAQBAQABAQQAAwEEAAEBAQADAQMAAgEBAAMBAQACAQMAAQEBAAIBBQADAQEAAwEBAAQBAQABAQEABgEBAAsBAQAGAQEAAQECAAMBAQADAQEAAwEBAAMBAQADAQEAAwEBAAMBAQANAQEAAwEBAAkBAQADAQEADQEBAAMBAQAKAQMAAQEFAAEBAwABAQEAAQEDAAEBBQABAQMAAQEBAAEBAwABAQUAAQEDAAEBAQABAQMAAQEFAAEBAwABAQEAAQEBAAYBAQATAQEACAEBAAgBAQALAQEADAEBAAcBAQAGAQMABAEBAAMBAQACAQEABQECAAgBAgAIAQEAAQEBAAMBAQAFAQEAAwEBAAEBAQADAQEABQEBAAMBAQABAQEAAwEBAAUBAQADAQEAAQEBAAMBAQAFAQEAAwEBAAEBAQABAQEAAQEBAAEBAQACAQEAAQEBAAEBAQABAQIAAQEBAAEBAQABAQEAAgEBAAEBAQABAQEAAQECAAEBAQABAQEAAQEBAAIBAQABAQEAAQEBAAEBAgABAQEAAQEBAAEBAQACAQEAAQEBAAEBAQABAQIADAEBAAMBAQAKAQEACgEBAAIBAQALAQEABAEBAAQBAgAKAQIAAgEBAAMBAgABAQIAAQECAAMBAQACAQIACgECAAMBAgABAQQAAQECAAMBAQABAQEAAQEBAAEBAQAJAQEAAQEBAAEBAQABAQEACQEBAAEBAQABAQEAAQEBAAkBAQABAQEAAQEBAAEBAQAJAQgAAQEBAAEBAQABAQEAAQEJAAEBAQABAQEAAQEBAAEBCQABAQEAAQEBAAEBAQABAQkAAQEBAAEBAQABAQEAAQEJAAgBCAAIAQgAC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P8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8ApQ=="
{widgets}
palImport1:{"type":"contraption","size":[137,100],"pos":[334,171],"def":"palImport","widgets":{"button1":{},"button2":{},"p":{"value":"2e222f\n45293f\n7a3045\n993d41\ncd683d\nfbb954\nf2ec8b\nb0a987\n997f73\n665964\n443846\n576069\n788a87\na9b2a2\n"}}}
canvas1:{"type":"canvas","size":[150,150],"pos":[47,49],"image":"%%IMG2AJYAlgD/AO0lIABkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkLSAlEgBkL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IABeJxgpIABeJyAAdicFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAcScFKCAAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwAWiwgKBwANyogAAMsICgcADcqIAADLCAoHAA3KiAAAywgKBwANyogAAMsICgcADcqIAADLCAoHAA3KiAAAywgKBwANyogAAMsICgcABkgCQAVKiAAAywgKBwAGSAJABUqIAADLCAoHAAZIAkAFSogAAMsIAA1IAkAFSogAAMsIAA1IAkAFSogAAMsIAA1IAkAFSogAAMsIAA1IAkAFSogAAMsIAA1IAkAFSogAAMsIAA1IAkAFSogAAMsICsNACggCQAVKiAAAywgKw0AKCAJABUqIAADLCArDQAELiAABCAJABUqIAADLCArDQAELiAABCAJABUqIAADLCArDQAELiAABCAJABUqIAADLCArDQAELiAABCAJABUqIAADLCArDQAELiAABCAJABUqIAADLCArDQAELiAABCAJABUqIAAQKyAABC4gAAQgCQAVKiAAECsgAAQuIAAEIAkAFSogABArIAAELiAABCAJABUqIAAQKyAABC4gAAQgCQAVKiAAECsgAAQuIAAEIAkAFSogABArIAAELiAABCAJABUqIAAQKyAABC4gAAQgCQAVKiAAECsgAAQuIAAEIAk=","pattern":47}
field1:{"type":"field","size":[175,88],"pos":[259,60],"locked":1,"show":"transparent","border":0,"value":{"text":["this deck contains a palette importer contraption that can understand the .hex palettes available on ","lospec.com","\n(up to 16 colors, naturally.)\n\nIt's also a handy regression test for round-tripping custom palettes, which is why it lives here!"],"font":["","",""],"arg":["","https://lospec.com/palette-list",""]}}

{contraption:palImport}
size:[137,100]
margin:[0,0,0,0]
description:"a tool for importing color palettes in the .hex format as used by lospec.com."
image:"%%IMG2AIkAZAACAYUAAwEBDYUBAQABAQENhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQINhwECDYcBAg2HAQEAAQEBDYUBAQADAYUAAg=="
{widgets}
button1:{"type":"button","size":[60,20],"pos":[6,74],"script":"palImport.0p","text":"Import"}
button2:{"type":"button","size":[60,20],"pos":[71,74],"script":"palImport.1p","text":"Apply"}
p:{"type":"field","size":[125,62],"pos":[6,7],"scrollbar":1,"style":"code"}

{script:palImport.0p}
on click do
 p.text:read[]
end
{end}

{script:palImport.1p}
on color_dist a b do
 aa:"%2h%2h%2h" parse "%06h" format a
 bb:"%2h%2h%2h" parse "%06h" format b
 sum(aa-bb)^2
end

on find_closest i n do
 g:patterns[i]
 r:first n
 each v in n
  if color_dist[v g]<color_dist[r g] r:v end
 end
 patterns[i]:r
 (list r) drop n
end

on click do
 n:16 limit (list "%h") parse "\n" split p.text
 patterns[32]:16777215
 patterns[47]:0
 if 15<count n
  n:find_closest[32 n]
  n:find_closest[47 n]
 end
 each c i in n patterns[33+i]:c end
end
{end}

