Skip to content

Commit

Permalink
why not use PNG itself to display its examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Feb 21, 2024
1 parent d3aa6f9 commit ac0f87e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6,114 deletions.
38 changes: 10 additions & 28 deletions Snippets/PNG/BasicDecoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,20 @@ let va:[PNG.VA<UInt8>] = image.unpack(as: PNG.VA<UInt8>.self)

// snippet.end

guard
let _:Void = (System.File.Destination.open(path: "\(path).png.va")
{
guard
let _:Void = $0.write(va.flatMap{ [$0.v, $0.a] })
else
{
fatalError("failed to write to file '\(path).png.va'")
}
})
else
{
fatalError("failed to open file '\(path).png.va'")
}
let vaReencoded:PNG.Image = .init(packing: va,
size: image.size,
layout: .init(format: .va8(fill: nil)),
metadata: image.metadata)
try vaReencoded.compress(path: "\(path).va.png", level: 9)

// snippet.V

let v:[UInt8] = image.unpack(as: UInt8.self)

// snippet.end

guard
let _:Void = (System.File.Destination.open(path: "\(path).png.v")
{
guard
let _:Void = $0.write(v)
else
{
fatalError("failed to write to file '\(path).png.v'")
}
})
else
{
fatalError("failed to open file '\(path).png.v'")
}
let vReencoded:PNG.Image = .init(packing: v,
size: image.size,
layout: .init(format: .v8(fill: nil, key: nil)),
metadata: image.metadata)
try vReencoded.compress(path: "\(path).v.png", level: 9)
4 changes: 2 additions & 2 deletions Sources/PNG/docs.docc/BasicDecoding/BasicDecoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ We could also have unpacked the image pixels to the [`PNG.VA<UInt8>`](/PNG/VA) b

@Snippet(id: "BasicDecoding", slice: "VA")

@Image(source: "BasicDecoding.png.va", alt: "output png") {
@Image(source: "BasicDecoding.va.png", alt: "output png") {

> The example image, decoded to an grayscale-alpha data file, and re-encoded as a png.
Expand All @@ -36,7 +36,7 @@ The ``Image/unpack(as:)`` method also has an overload which allows you to unpack
let v:[UInt8] = image.unpack(as: UInt8.self)
```

@Image(source: "BasicDecoding.png.v", alt: "output png") {
@Image(source: "BasicDecoding.v.png", alt: "output png") {

> the example image, decoded to an grayscale data file, and re-encoded as a png. it looks the same as the grayscale-alpha output because the original image has no transparent pixels.
Expand Down
3,042 changes: 0 additions & 3,042 deletions Sources/PNG/docs.docc/BasicDecoding/BasicDecoding.png.v

This file was deleted.

3,042 changes: 0 additions & 3,042 deletions Sources/PNG/docs.docc/BasicDecoding/BasicDecoding.png.va

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac0f87e

Please sign in to comment.