一个适用于 iOS、macOS、macCatalyst、tvOS、watchOS 和 Linux 的调色板读取/编辑/写入包。
支持以下格式:-
.ase
).aco
).act
).acb
) (只读).clr
) (仅限 macOS).rgb
).rgba
).gpl
).soc
).pal
, .psppalette
).png
, .jpg
, .gif
) (图像第一行的唯一颜色).pal
) (只读).sketchpalette
).xml
).txt
).cpl
) (只读).jsoncolorpalette
) ColorPaletteCodable 内部文件格式.hex
).txt
).svg
) (只写)colors.xml
资源文件格式.ggr
).gpf
).cpt
).jsongradient
).grd
) (只读).pspgradient
) (只读).svg
) (只写)我想在我的 Swift 应用程序中读取和写入 Adobe .ase
调色板文件。 然后它扩展到 .aco
Adobe Photoshop Color Swatch 文件。 然后扩展到其他类型 :-)
一些功能:-
类型 | 描述 |
---|---|
PAL.Palette |
调色板的完整表示 |
PAL.Group |
颜色的可选命名集合 |
PAL.Color |
可选命名的颜色 |
类型 | 描述 |
---|---|
PAL.Coder.ACB |
Adobe Color Book (.acb) |
PAL.Coder.ACO |
Adobe Photoshop Color Swatch (.aco) |
PAL.Coder.ACT |
Adobe Color Table (.act) |
PAL.Coder.AndroidColorsXML |
Android color.xml 资源 (.xml) |
PAL.Coder.ASE |
Adobe Swatch Exchange (.ase) |
PAL.Coder.BasicXML |
基本 XML 结构 (.xml) |
PAL.Coder.CLR |
NSColorList (.clr) (仅限 macOS) |
PAL.Coder.CorelPainter |
CorelPainter 色板 (.txt) |
PAL.Coder.CorelXMLPalette |
CorelDraw/Adobe Illustrator 调色板 (.xml) |
PAL.Coder.CPL |
Corel Paint (.cpl) |
PAL.Coder.CSV |
CSV (.csv) |
PAL.Coder.DCP |
DCP 二进制调色板格式 (.dcp) |
PAL.Coder.GIMP |
GIMP 调色板文件 (.gpl) |
PAL.Coder.HEX |
十六进制颜色调色板 (.hex ) |
PAL.Coder.Image |
图像文件 (.png, .jpg, .gif) |
PAL.Coder.JSON |
JSON 编码的调色板 (.jsoncolorpalette) |
PAL.Coder.OpenOfficePaletteCoder |
OpenOffice 调色板 (.soc) |
PAL.Coder.PaintNET |
Paint.NET 调色板 (.txt) |
PAL.Coder.PaintShopPro |
Paint Shop Pro 调色板 (.pal;.psppalette) |
PAL.Coder.RGBA |
RGB(A) 文本文件 (.rgba) |
PAL.Coder.RGB |
RGB 文本文件 (.rgb) |
PAL.Coder.RIFF |
Microsoft RIFF 调色板 (.pal) |
PAL.Coder.SketchPalette |
Sketch 调色板 (.sketchpalette) |
PAL.Coder.SVG |
SVG 图像文件 (.svg) |
每个编码器定义 .encode
和 .decode
。 并非所有编码器都支持编码和解码。
do {
let myFileURL = URL(fileURL: ...)
// Try to decode the palette based on its file extension
let palette = try PAL.Palette.Decode(from: myFileURL)
// do something with 'palette'
}
catch {
// Do something with 'error'
}
// Build a palette
var palette = PAL.Palette()
let c1 = try PAL.Color.rgb(name: "red", 1, 0, 0)
let c2 = try PAL.Color.rgb(name: "green", 0, 1, 0)
let c3 = try PAL.Color.rgb(name: "blue", 0, 0, 1)
palette.colors.append(contentsOf: [c1, c2, c3])
// Generate a simple image from the colors
let image = try PAL.Image.Image(colors: [c1, c2, c3], size: CGSize(width: 100, height: 25))
// Create an ASE coder
let coder = PAL.Coder.ASE()
// Get the .ase format data
let rawData = try coder.encode(palette)
// Do something with 'rawData' (like write to a file for example)
let acoFileURL = URL(fileURL: ...)
let coder = PAL.Coder.ACO()
var palette = try coder.decode(from: acoFileURL)
// do something with 'palette'
// re-encode the palette to an ASE format
let encoder = PAL.Coder.ASE()
let rawData = try encoder.encode(palette)
文件类型 | 解码? | 编码? | 命名 颜色? |
命名 调色板? |
颜色 分组? |
颜色类型 支持? |
支持 颜色空间? |
|
---|---|---|---|---|---|---|---|---|
PAL.Coder.ACB |
二进制 | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ |
PAL.Coder.ACO |
二进制 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
PAL.Coder.ACT |
二进制 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.AndroidColorsXML |
XML | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.ASE |
二进制 | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
PAL.Coder.BasicXML |
XML | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | 仅 RGB |
PAL.Coder.CLR |
二进制 (仅限 macOS) |
✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
PAL.Coder.CorelPainter |
文本 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.CPL |
二进制 | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ |
PAL.Coder.CSV |
文本 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.GIMP |
文本 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | 仅 RGB |
PAL.Coder.HEX |
文本 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.Image |
二进制 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
PAL.Coder.JSON |
JSON 文本 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
PAL.Coder.OpenOfficePalette |
XML | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
PAL.Coder.PaintNET |
文本 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.PaintShopPro |
文本 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.RGB/A |
文本 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.RIFF |
二进制 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.SketchPalette |
XML | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | 仅 RGB |
PAL.Coder.SVG |
SVG 文本 | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | 仅 RGB |
PAL.Coder.XMLPalette |
XML | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
(颜色类型代表颜色的类型(全局/专色/正常))
该库定义了 PAL.Gradients
,它定义了一个颜色集合,其中包含可用于渐变的位置。 某些渐变类型(例如 .grd
)支持同一文件中的多个渐变。
类型 | 描述 |
---|---|
PAL.Gradients |
渐变的集合 |
PAL.Gradient |
一个渐变 |
PAL.Stop |
渐变中的颜色停止点 |
PAL.TransparencyStop |
渐变中的透明度停止点 |
类型 | 描述 | 解码? | 编码? |
---|---|---|---|
PAL.Gradients.Coder.CPT |
CPT 渐变文件 (.cpt) | ✅ | ✅ |
PAL.Gradients.Coder.JSON |
内置 JSON 格式 (.jsongradient) | ✅ | ✅ |
PAL.Gradients.Coder.GGR |
GIMP 渐变文件 (.ggr) | ✅ | ✅ |
PAL.Gradients.Coder.GPF |
GNUPlot 颜色调色板文件 (.gpf) | ✅ | ✅ |
PAL.Gradients.Coder.GRD |
基本 Adobe Photoshop 渐变文件 (.grd) | ✅ | ❌ |
PAL.Gradients.Coder.PSP |
基本 Paint Shop Pro 渐变文件 (.pspgradient) | ✅ | ❌ |
PAL.Gradients.Coder.SVG |
SVG 文件 (.svg) | ❌ | ✅ |
.gpf
仅支持 rgb.ggr
支持不考虑线性以外的段混合函数(始终作为线性导入).ggr
支持不允许使用 rgb 以外的段着色函数(抛出错误).grd
支持目前非常基本。 没有正式的文档,我使用非常模糊的文档构建了它 1, 2.pspgradient
似乎 等于 grd v3 格式。 (只读)一些不错的渐变文件
cptcity 还有一个 不错的转换器 用于将渐变转换为 ggr
let gradient = PAL.Gradient(
colorPositions: [
(0.0, try PAL.Color(rgbHexString: "#FFFFFF")),
(0.5, try PAL.Color(rgbHexString: "#444444")),
(1.0, try PAL.Color(rgbHexString: "#000000"))
]
)
// Create a gradients container
let gradients = PAL.Gradients(gradients: [gradient])
// Create the appropriate coder
let coder = PAL.Gradients.Coder.GGR()
// Encode the gradient using the GIMP gradient encoder
let data = try coder.encode(gradients)
// Decode a gradient from data
let decoded = try PAL.Gradients.Decode(
from: data,
fileExtension: PAL.Gradients.Coder.GGR.fileExtension
)
// Load a gradient from a file, inferring the type from the file's extension
let gradient1 = try PAL.Gradients.Decode(from: fileURL)
// Load a specific gradient format from a file
let coder = PAL.Gradients.Coder.GRD()
let gradient2 = try coder.decode(from: i)
调色板查看器允许您查看所有支持的调色板和渐变文件的内容
您可以将颜色从预览窗口拖到支持拖放 NSColor
实例的应用程序中。
您还可以将调色板保存为新格式(例如,将 gimp .gpl
格式保存为 Adobe .aco
格式)
此软件包还包括调色板和渐变文件的 Quicklook 插件。
在 Quicklook
子文件夹中,您会找到一个 xcodeproj
,您可以使用它来构建包含 QuickLook 插件的应用程序 Palette Viewer
。
要注册插件,您需要运行该应用程序。 首次运行后,将注册 QuickLook 插件。
请参阅:使用 Docker 在 Linux 上测试 Swift 包
docker run --rm --privileged --interactive --tty --volume "$(pwd):/src" --workdir "/src" swift:latest
现在,从 Docker 容器内部运行
swift build
swift test
请注意,Linux 容器中的 /src 目录是主机操作系统上当前目录的直接镜像,而不是副本。 如果您删除 Linux 容器中 /src 中的文件,该文件也会在主机操作系统上消失。
.ase
文件格式没有正式定义,但是网络上有许多解构。 我使用了此处定义的格式分解。
.aco
文件格式定义此处。
.act
文件格式定义此处。
.acb
格式在此处讨论和定义
CorelDraw/Adobe Illustrator .xml
文件格式(有些)定义在此处
MIT License
Copyright (c) 2025 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
https://bottosson.github.io/posts/oklab/#oklab-implementations
https://bottosson.github.io/misc/License.txt
Copyright (c) 2020 Björn Ottosson
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.