Skip to content

Commit

Permalink
Update IconWorkspace.st with sage advice. [ci skpi]
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotmiranda committed Aug 24, 2021
1 parent 73f30ab commit f88bc9e
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions platforms/iOS/vm/OSX/IconWorkspace.text
@@ -1,4 +1 @@
"This workspace has two doits. The first parses a macOS .icns file. The second concatenates the output of Image2Icon.app (brew install image2icon). Image2Icon.app takes any image and produces an iconset directory containing PNG files. The second doit creates a .icns file from these (delete the null file Image2icon.app produces)" [| f chunks |chunks := OrderedDictionary new.f := FileStream oldFileNamed: '/Users/eliot/Cog/3dicc/terf-cogvm/platforms/iOS/vm/OSX/Terf.icns'.f binary.[| pos size type | chunks at: (f next: 4) asString put: f nextInt32. [f atEnd] whileFalse: [pos := f position. type := (f next: 4) asString. size := f nextInt32. type = 'TOC ' ifTrue: [chunks at: type put: pos -> ((1 to: size - 8 / 8) collect: [:i| (f next: 4) asString -> f nextInt32])] ifFalse: [chunks at: type put: pos -> size. f skip: size - 8]]] ensure: [f close].chunks]. "an OrderedDictionary('icns'->337372 'TOC '->8->{'ic07'->20963 . 'ic14'->185621 . 'ic08'->63373 . 'ic11'->3167 . 'is32'->539 . 's8mk'->264 . 'ic13'->63373} 'ic07'->72->20963 'ic14'->21035->185621 'ic08'->206656->63373 'ic11'->270029->3167 'is32'->273196->539 's8mk'->273735->264 'ic13'->273999->63373 ) "

"See https://en.wikipedia.org/wiki/Apple_Icon_Image_format"
"ic07:128x128 icon in JPEG 2000 or PNG formatic14:256x256@2x ''retina'' icon in JPEG 2000 or PNG formatic08:256×256 icon in JPEG 2000 or PNG formatic11:16x16@2x ''retina'' icon in JPEG 2000 or PNG formatis32:16×16 24-bit icons8mk:16x16 8-bit maskic13:128x128@2x ''retina'' icon in JPEG 2000 or PNG format"[| dir typeMap map toc size out |typeMap := Dictionary newFromPairs: #('16x16' 'icp4' '16x16@2x' 'ic11' '32x32' 'icp5' '32x32@2x' 'ic12' '128x128' 'ic07' '128x128@2x' 'ic13' '256x256' 'ic08' '256x256@2x' 'ic14' '512x512' 'ic09' '512x512@2x' 'ic10').map := Dictionary new.dir := FileDirectory on: '/Users/eliot/Cog/3dicc/virtend-vm/platforms/iOS/vm/OSX/Virtend/icon.iconset'.dir fileNames do: [:fn| map at: (typeMap at: ((FileDirectory baseNameFor: fn) allButFirst: 5)) put: fn].toc := #('ic10' 'ic09' 'ic14' 'ic08' 'ic13' 'ic07' 'ic11' 'icp4').size := dir fileNames inject: 8 + (toc size + 1 * 8) into: [:total :fn| total + (dir entryAt: fn) fileSize].out := FileStream forceNewFileNamed: '/Users/eliot/Cog/3dicc/virtend-vm/platforms/iOS/vm/OSX/Virtend.icns'.[out binary.out nextPutAll: 'icns' asByteArray; nextInt32Put: size; nextPutAll: 'TOC ' asByteArray; nextInt32Put: toc size + 1 * 8.toc do: [:content| out nextPutAll: content asByteArray; nextInt32Put: ((dir entryAt: (map at: content)) fileSize)].toc do: [:content| out nextPutAll: content asByteArray; nextInt32Put: ((dir entryAt: (map at: content)) fileSize + 8); nextPutAll: (dir oldFileNamed: (map at: content)) binary contentsOfEntireFile]] ensure: [out close]]
"This workspace has two doits. The first parses a macOS .icns file. The second concatenates the output of Image2Icon.app (brew install image2icon). Image2Icon.app takes any image and produces an iconset directory containing PNG files. The second doit creates a .icns file from these (delete the null file Image2icon.app produces)""However you'll have success following https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5, which boils down to for s in 16 32 64 128 256 512 1024; do sips -z $s $s large.png --out icon.iconset/icon_${s}x${s}.png done iconutil -c icns -o MyIcons.icns icon.iconset"[| f chunks |chunks := OrderedDictionary new.f := FileStream oldFileNamed: '/Users/eliot/Cog/3dicc/terf-cogvm/platforms/iOS/vm/OSX/Terf.icns'.f binary.[| pos size type | chunks at: (f next: 4) asString put: f nextInt32. [f atEnd] whileFalse: [pos := f position. type := (f next: 4) asString. size := f nextInt32. type = 'TOC ' ifTrue: [chunks at: type put: pos -> ((1 to: size - 8 / 8) collect: [:i| (f next: 4) asString -> f nextInt32])] ifFalse: [chunks at: type put: pos -> size. f skip: size - 8]]] ensure: [f close].chunks]. "an OrderedDictionary('icns'->337372 'TOC '->8->{'ic07'->20963 . 'ic14'->185621 . 'ic08'->63373 . 'ic11'->3167 . 'is32'->539 . 's8mk'->264 . 'ic13'->63373} 'ic07'->72->20963 'ic14'->21035->185621 'ic08'->206656->63373 'ic11'->270029->3167 'is32'->273196->539 's8mk'->273735->264 'ic13'->273999->63373 ) ""See https://en.wikipedia.org/wiki/Apple_Icon_Image_format""ic07:128x128 icon in JPEG 2000 or PNG formatic14:256x256@2x ''retina'' icon in JPEG 2000 or PNG formatic08:256x256 icon in JPEG 2000 or PNG formatic11:16x16@2x ''retina'' icon in JPEG 2000 or PNG formatis32:16x16 24-bit icons8mk:16x16 8-bit maskic13:128x128@2x ''retina'' icon in JPEG 2000 or PNG format"[| dir typeMap map toc size out |typeMap := Dictionary newFromPairs: #('16x16' 'icp4' '16x16@2x' 'ic11' '32x32' 'icp5' '32x32@2x' 'ic12' '128x128' 'ic07' '128x128@2x' 'ic13' '256x256' 'ic08' '256x256@2x' 'ic14' '512x512' 'ic09' '512x512@2x' 'ic10').map := Dictionary new.dir := FileDirectory on: '/Users/eliot/Cog/3dicc/virtend-vm/platforms/iOS/vm/OSX/Virtend/icon.iconset'.dir fileNames do: [:fn| map at: (typeMap at: ((FileDirectory baseNameFor: fn) allButFirst: 5)) put: fn].toc := #('ic10' 'ic09' 'ic14' 'ic08' 'ic13' 'ic07' 'ic11' 'icp4').size := dir fileNames inject: 8 + (toc size + 1 * 8) into: [:total :fn| total + (dir entryAt: fn) fileSize].out := FileStream forceNewFileNamed: '/Users/eliot/Cog/3dicc/virtend-vm/platforms/iOS/vm/OSX/Virtend.icns'.[out binary.out nextPutAll: 'icns' asByteArray; nextInt32Put: size; nextPutAll: 'TOC ' asByteArray; nextInt32Put: toc size + 1 * 8.toc do: [:content| out nextPutAll: content asByteArray; nextInt32Put: ((dir entryAt: (map at: content)) fileSize)].toc do: [:content| out nextPutAll: content asByteArray; nextInt32Put: ((dir entryAt: (map at: content)) fileSize + 8); nextPutAll: (dir oldFileNamed: (map at: content)) binary contentsOfEntireFile]] ensure: [out close]]
Expand Down

0 comments on commit f88bc9e

Please sign in to comment.