Skip to content

Commit

Permalink
update codelinks to use newernames
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Feb 21, 2024
1 parent 5df5ada commit a12f55a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func encode(png path:String, size:(x:Int, y:Int), pixels:[PNG.RGBA<UInt8>]) thro

- ***Batteries included.*** *Swift PNG* comes with [built-in color targets](https://tayloraswift.github.io/swift-png/PNG/Color/) with support for [premultiplied alpha](https://tayloraswift.github.io/swift-png/PNG/RGBA/premultiplied/). [Convolution](https://tayloraswift.github.io/swift-png/PNG/convolve(_:dereference:kernel:)/) and [deconvolution](https://tayloraswift.github.io/swift-png/PNG/deconvolve(_:reference:kernel:)/) helper functions make [implementing custom color targets](examples/#custom-color-targets) a breeze.

On MacOS and Linux, *Swift PNG* has built-in file system support, allowing you to [compress](https://tayloraswift.github.io/swift-png/PNG/Data/Rectangular/compress(path:level:hint:)/) or [decompress](https://tayloraswift.github.io/swift-png/PNG/Data/Rectangular/decompress(path:)/) an image, given a filepath, in a single function call. Other platforms can take advantage of *Swift PNG*’s [protocol-oriented IO](https://tayloraswift.github.io/swift-png/PNG/Bytestream/) to implement their own data loading.
On MacOS and Linux, *Swift PNG* has built-in file system support, allowing you to [compress](https://tayloraswift.github.io/swift-png/PNG/Image/compress(path:level:hint:)/) or [decompress](https://tayloraswift.github.io/swift-png/PNG/Image/decompress(path:)/) an image, given a filepath, in a single function call. Other platforms can take advantage of *Swift PNG*’s [protocol-oriented IO](https://tayloraswift.github.io/swift-png/PNG/Bytestream/) to implement their own data loading.

- ***First-class iPhone optimization support.*** *Swift PNG* requires no custom setup or third-party plugins to handle [iPhone-optimized](examples/#using-iphone-optimized-images) PNG images. iPhone-optimized images just work, on all platforms. Reproduce [`pngcrush`](https://developer.apple.com/library/archive/qa/qa1681/_index.html)’s output with [bit width-aware alpha premultiplication](https://tayloraswift.github.io/swift-png/PNG/RGBA/premultiplied(as:)/), for seamless integration anywhere in your application stack.

Expand Down
5 changes: 5 additions & 0 deletions Snippets/PNG/BasicDecoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ else
fatalError("failed to open file '\(path).png.va'")
}

// snippet.V

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

// snippet.end

guard
let _:Void = (System.File.Destination.open(path: "\(path).png.v")
{
Expand Down
40 changes: 20 additions & 20 deletions Snippets/README.md

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Sources/PNG/ColorTargets/PNG.Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ protocol _PNGColor<Aggregate>
/// - Parameters:
/// - interleaved:
/// An image data buffer. It is expected to be obtained from the
/// ``Data/Rectangular/storage`` property of a ``Data/Rectangular`` image.
/// ``Image/storage`` property of a ``Image`` image.
/// - format:
/// The color format associated with the given data buffer.
/// It is expected to be obtained from the the ``PNG/Layout/format`` property of a
/// ``PNG/Data/Rectangular`` image.
/// ``PNG/Image`` image.
/// - deindexer:
/// A function which uses the palette entries in the color `format` to
/// generate a dereferencing function. This function should only be invoked
Expand All @@ -57,7 +57,7 @@ protocol _PNGColor<Aggregate>
/// The color format to pack the given pixels as in the returned data buffer.
///
/// When the library uses an implementation of this function to construct
/// a ``PNG/Data/Rectangular`` image, this color format will be stored in
/// a ``PNG/Image`` image, this color format will be stored in
/// its ``PNG/Layout/format`` property.
/// - indexer:
/// A function which uses the palette entries in the color `format` to
Expand All @@ -73,8 +73,8 @@ protocol _PNGColor<Aggregate>
/// necessarily in the same order within each individual pixel.)
///
/// When the library uses an implementation of this function to construct
/// a ``PNG/Data/Rectangular`` image, this data buffer will be stored in
/// its ``PNG/Data/Rectangular/storage`` property.
/// a ``PNG/Image`` image, this data buffer will be stored in
/// its ``PNG/Image/storage`` property.
static
func pack(_ pixels:[Self],
as format:PNG.Format,
Expand All @@ -98,12 +98,12 @@ protocol _PNGColor<Aggregate>
/// - Parameters:
/// - interleaved:
/// An image data buffer. It is expected to be obtained from the
/// ``PNG/Data/Rectangular/storage`` property of a ``PNG/Data/Rectangular``
/// ``PNG/Image/storage`` property of a ``PNG/Image``
/// image.
/// - format:
/// The color format associated with the given data buffer. It is
/// expected to be obtained from the the ``PNG/Layout/format`` property of a
/// ``PNG/Data/Rectangular`` image.
/// ``PNG/Image`` image.
/// - Returns:
/// A pixel array containing instances of this color target. The pixels
/// should appear in the same order as they do in the image data buffer.
Expand Down Expand Up @@ -140,7 +140,7 @@ protocol _PNGColor<Aggregate>
/// The color format to pack the given pixels as in the returned data buffer.
///
/// When the library uses an implementation of this function to construct
/// a ``PNG/Data/Rectangular`` image, this color format will be stored in
/// a ``PNG/Image`` image, this color format will be stored in
/// its ``PNG/Layout/format`` property.
///
/// - Returns:
Expand All @@ -149,8 +149,8 @@ protocol _PNGColor<Aggregate>
/// necessarily in the same order within each individual pixel.)
///
/// When the library uses an implementation of this function to construct
/// a ``PNG/Data/Rectangular`` image, this data buffer will be stored in
/// its ``PNG/Data/Rectangular/storage`` property.
/// a ``PNG/Image`` image, this data buffer will be stored in
/// its ``PNG/Image/storage`` property.
static
func pack(_ pixels:[Self], as format:PNG.Format) -> [UInt8]
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/PNG/ColorTargets/PNG.RGBA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ extension PNG.RGBA:PNG.Color
/// computed from the color `format`.
/// - Parameter interleaved:
/// An image data buffer. It is expected to be obtained from the
/// ``Image/storage`` property of a ``Data/Rectangular``
/// ``Image/storage`` property of a ``Image``
/// image.
/// - Parameter format:
/// The color format associated with the given data buffer.
/// It is expected to be obtained from the the `layout.format` property of a
/// ``Data/Rectangular`` image.
/// ``Image`` image.
/// - Parameter deindexer:
/// A function which uses the palette entries in the color `format` to
/// generate a dereferencing function. This function is only invoked
Expand Down Expand Up @@ -382,7 +382,7 @@ extension PNG.RGBA:PNG.Color
/// The color format to pack the given pixels as in the returned data buffer.
///
/// When the library uses an implementation of this function to construct
/// a ``Data/Rectangular`` image, this color format will be stored in
/// a ``Image`` image, this color format will be stored in
/// its `layout.format` property.
/// - Parameter indexer:
/// A function which uses the palette entries in the color `format` to
Expand All @@ -398,7 +398,7 @@ extension PNG.RGBA:PNG.Color
/// necessarily in the same order within each individual pixel.)
///
/// When the library uses an implementation of this function to construct
/// a ``Data/Rectangular`` image, this data buffer will be stored in
/// a ``Image`` image, this data buffer will be stored in
/// its ``Image/storage`` property.
@_specialize(where T == UInt8)
@_specialize(where T == UInt16)
Expand Down
8 changes: 4 additions & 4 deletions Sources/PNG/ColorTargets/PNG.VA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ extension PNG.VA:PNG.Color
/// computed from the color `format`.
/// - Parameter interleaved:
/// An image data buffer. It is expected to be obtained from the
/// ``Image/storage`` property of a ``Data/Rectangular``
/// ``Image/storage`` property of a ``Image``
/// image.
/// - Parameter format:
/// The color format associated with the given data buffer.
/// It is expected to be obtained from the the `layout.format` property of a
/// ``Data/Rectangular`` image.
/// ``Image`` image.
/// - Parameter deindexer:
/// A function which uses the palette entries in the color `format` to
/// generate a dereferencing function. This function is only invoked
Expand Down Expand Up @@ -308,7 +308,7 @@ extension PNG.VA:PNG.Color
/// The color format to pack the given pixels as in the returned data buffer.
///
/// When the library uses an implementation of this function to construct
/// a ``Data/Rectangular`` image, this color format will be stored in
/// a ``Image`` image, this color format will be stored in
/// its `layout.format` property.
/// - Parameter indexer:
/// A function which uses the palette entries in the color `format` to
Expand All @@ -323,7 +323,7 @@ extension PNG.VA:PNG.Color
/// in the same order as the pixels in the `pixels` array.
///
/// When the library uses an implementation of this function to construct
/// a ``Data/Rectangular`` image, this data buffer will be stored in
/// a ``Image`` image, this data buffer will be stored in
/// its ``Image/storage`` property.
@_specialize(where T == UInt8)
@_specialize(where T == UInt16)
Expand Down
13 changes: 7 additions & 6 deletions Sources/PNG/docs.docc/BasicDecoding/BasicDecoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ We could also have unpacked the image pixels to the [`PNG.VA<UInt8>`](/PNG/VA) b
}

The ``Image/unpack(as:)`` method is non-mutating, so you can unpack the same image to multiple color targets without having to re-decode the file each time.

The [`unpack(as:)`](https://tayloraswift.github.io/swift-png/PNG/Data/Rectangular/unpack(as:)/) method is [non-mutating](https://docs.swift.org/swift-book/LanguageGuide/Methods.html#ID239), so you can unpack the same image to multiple color targets without having to re-decode the file each time.

The [`unpack(as:)`](https://tayloraswift.github.io/swift-png/PNG/Data/Rectangular/unpack(as:)/) method also has an [overload](https://tayloraswift.github.io/swift-png/PNG/Data/Rectangular/1-unpack(as:)/) which allows you to unpack an image into scalar grayscale samples.
The ``Image/unpack(as:)`` method also has an overload which allows you to unpack an image into scalar grayscale samples.

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

<img src="decode-basic/example.png.v.png" alt="output png" width=300/>
@Image(source: "BasicDecoding.png.v", 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.
The two `unpack(as:)` methods support all Swift integer types that conform to [`FixedWidthInteger`](https://developer.apple.com/documentation/swift/fixedwidthinteger)`&`[`UnsignedInteger`](https://developer.apple.com/documentation/swift/unsignedinteger). They have generic specializations for [`UInt8`](https://developer.apple.com/documentation/swift/uint8), [`UInt16`](https://developer.apple.com/documentation/swift/uint16), [`UInt32`](https://developer.apple.com/documentation/swift/uint32), [`UInt64`](https://developer.apple.com/documentation/swift/uint64), and [`UInt`](https://developer.apple.com/documentation/swift/uint).
}

The two `unpack(as:)` methods support all Swift integer types that conform to ``FixedWidthInteger`` `&` ``UnsignedInteger``. They have generic specializations for ``UInt8``, [`UInt16`](https://developer.apple.com/documentation/swift/uint16), [`UInt32`](https://developer.apple.com/documentation/swift/uint32), [`UInt64`](https://developer.apple.com/documentation/swift/uint64), and [`UInt`](https://developer.apple.com/documentation/swift/uint).

If you unpack an image to an integer type `T` with a bit width different from the color depth of the original image, the samples will be scaled to fill the range `T.min ... T.max`. The scaling is done arithmetically, so if you unpack an 8-bit image to a [`UInt16`](https://developer.apple.com/documentation/swift/uint16)-based color target, then samples with the value `255` will become `65535`, not `65280`.

> **warning:** the built-in grayscale color targets do not compute luminance for rgb- and rgba-type images. they simply use the red component as the gray value, and discard the green and blue components. to perform more sophisticated pixel unpacking, [define a custom pixel kernel](#custom-color-targets).
> **warning:** the built-in grayscale color targets do not compute luminance for rgb- and rgba-type images. they simply use the red component as the gray value, and discard the green and blue components. to perform more sophisticated pixel unpacking, [define a custom pixel kernel](/CustomColor).

0 comments on commit a12f55a

Please sign in to comment.