使用 Swift 语言简单地读写 PPM 文件 (P3/P6) (macOS, iOS, tvOS, watchOS, macCatalyst, Linux)。
let ppmData = Data(...)
let cgImage = try PPM.readImage(data: ppmData)
let image: PPM.Image = try PPM.read(fileURL: ppm1URL)
// width = image.width
// height = image.height
// rawRGBBytes = image.data
注意:PPM 不支持透明度,因此任何透明度信息都会丢失。
let cgImage = CGImage(...)
let data = try PPM.writeImage(cgImage, format: .P3)
let image = PPM.Image(...)
try image.write(format: .P3, fileURL: <some_url>)
public static func image(rgbData: [PPM.RGB], width: Int, height: Int) throws -> PPM.Image
注意:rgbData 数组中的像素数量必须等于 width
* height
let pixels: [PPM.RGB] = [ ... ]
let image = PPM.image(rgbData: pixels, width: 100, height: 100)
请参阅:使用 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 中的文件,该文件也将在主机操作系统上消失。
MIT License
Copyright (c) 2022 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.