Skip to content

Commit

Permalink
replace deprecated names
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Feb 21, 2024
1 parent 4729967 commit 5df5ada
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Compression/Swift/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum Benchmark
}
}
}
extension Benchmark.Encode.Blob:PNG.Bytestream.Destination
extension Benchmark.Encode.Blob:PNG.BytestreamDestination
{
mutating
func write(_ data:[UInt8]) -> Void?
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/Decompression/Swift/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum Benchmark
}
}
}
extension Benchmark.Decode.Blob:PNG.Bytestream.Source
extension Benchmark.Decode.Blob:PNG.BytestreamSource
{
static
func load(path:String) -> Self?
Expand Down
2 changes: 1 addition & 1 deletion Notes/improving-deflate-compression-speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clang -lpng ${prefix}/main.c -o ${binary}

The same script also builds an equivalent Swift program in [`Benchmarks/compression/swift/`](../Benchmarks/compression/swift) using the Swift Package Manager. The Swift program, of course, invokes Swift *PNG* instead of *libpng*.

Disk latency contributes a noticeable (but not overwhelming) proportion of the time needed to encode a PNG file, especially at low compression levels. To avoid this problem, the C and Swift benchmarks both have their respective backends configured to write output images to memory instead of the file system. For *libpng*, you can do this by creating a custom buffer context and passing a callback function to `png_set_write_fn(_:_:_:_:)`. For Swift *PNG*, you can do this statically by conforming a buffer type of your choice to the `PNG.Bytestream.Destination` protocol.
Disk latency contributes a noticeable (but not overwhelming) proportion of the time needed to encode a PNG file, especially at low compression levels. To avoid this problem, the C and Swift benchmarks both have their respective backends configured to write output images to memory instead of the file system. For *libpng*, you can do this by creating a custom buffer context and passing a callback function to `png_set_write_fn(_:_:_:_:)`. For Swift *PNG*, you can do this statically by conforming a buffer type of your choice to the `PNG.BytestreamDestination` protocol.

The memory target for the baseline C program is a `malloc`-based vector which uses the following reallocation rule:

Expand Down
2 changes: 1 addition & 1 deletion Snippets/PNG/ImagesInMemory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension System
}
}

extension System.Blob:PNG.Bytestream.Source, PNG.Bytestream.Destination
extension System.Blob:PNG.BytestreamSource, PNG.BytestreamDestination
{
init(_ data:[UInt8])
{
Expand Down
2 changes: 1 addition & 1 deletion Snippets/PNG/OnlineDecoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Stream
available:Int
}

extension Stream:PNG.Bytestream.Source
extension Stream:PNG.BytestreamSource
{
init(_ data:[UInt8])
{
Expand Down
8 changes: 4 additions & 4 deletions Snippets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,10 @@ extension System
}
```

There are two **bytestream protocols** a custom data stream type can support: [`PNG.Bytestream.Source`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Source), and [`PNG.Bytestream.Destination`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Destination). The first one enables image decoding, while the second one enables image encoding. We can conform to both with the following implementations:
There are two **bytestream protocols** a custom data stream type can support: [`PNG.BytestreamSource`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Source), and [`PNG.BytestreamDestination`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Destination). The first one enables image decoding, while the second one enables image encoding. We can conform to both with the following implementations:

```swift
extension System.Blob:PNG.Bytestream.Source, PNG.Bytestream.Destination
extension System.Blob:PNG.BytestreamSource, PNG.BytestreamDestination
{
init(_ data:[UInt8])
{
Expand Down Expand Up @@ -1103,7 +1103,7 @@ struct Stream
Each time we try to [`read`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Source/read(count:)/) from this stream, it will either return data from the available portion of the buffer, or it will return `nil` and “download” an additional 4 KB of the file. We also allow for rewinding the current file position to an earlier state.

```swift
extension Stream:PNG.Bytestream.Source
extension Stream:PNG.BytestreamSource
{
init(_ data:[UInt8])
{
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func chunk() throws -> (type:PNG.Chunk, data:[UInt8])

A valid PNG file consists of a signature, followed by a sequence of chunks.

The lexer functions are provided as extensions on the [`PNG.Bytestream.Source`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Source/) protocol, so they are available on any conforming data stream type, including our custom `Stream` type.
The lexer functions are provided as extensions on the [`PNG.BytestreamSource`](https://tayloraswift.github.io/swift-png/PNG/Bytestream/Source/) protocol, so they are available on any conforming data stream type, including our custom `Stream` type.

Normally, the three aforementioned errors would indicate an unexpected end-of-stream. In this case, they just mean that there is not enough data available yet, so the client needs to wait for more of the file to arrive before decoding can proceed. To allow the lexing functions to recover on end-of-stream instead of crashing the application, we wrap them in the following `waitSignature(stream:)` and `waitChunk(stream:)` functions, making sure to reset the file position if end-of-stream is encountered.

Expand Down
4 changes: 2 additions & 2 deletions Sources/PNG/PNG.Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ extension PNG.Image
/// The decoded image.
public static
func decompress<Source>(stream:inout Source) throws -> Self
where Source:PNG.Bytestream.Source
where Source:PNG.BytestreamSource
{
try stream.signature()
let (standard, header):(PNG.Standard, PNG.Header) = try
Expand Down Expand Up @@ -574,7 +574,7 @@ extension PNG.Image
public
func compress<Destination>(stream:inout Destination, level:Int = 9, hint:Int = 1 << 15)
throws
where Destination:PNG.Bytestream.Destination
where Destination:PNG.BytestreamDestination
{
try stream.signature()

Expand Down
4 changes: 2 additions & 2 deletions Sources/PNG/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ extension System.File.Destination
}

// declare conformance (as a formality)
extension System.File.Source:PNG.Bytestream.Source
extension System.File.Source:PNG.BytestreamSource
{
}
extension System.File.Destination:PNG.Bytestream.Destination
extension System.File.Destination:PNG.BytestreamDestination
{
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PNG/__Entrypoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension __Entrypoint
}
}
}
extension __Entrypoint.Benchmark.Decode.Blob:PNG.Bytestream.Source
extension __Entrypoint.Benchmark.Decode.Blob:PNG.BytestreamSource
{
static
func load(path:String) -> Self?
Expand Down Expand Up @@ -103,7 +103,7 @@ extension __Entrypoint.Benchmark.Decode.Blob:PNG.Bytestream.Source
self.count = self.buffer.count
}
}
extension __Entrypoint.Benchmark.Encode.Blob:PNG.Bytestream.Destination
extension __Entrypoint.Benchmark.Encode.Blob:PNG.BytestreamDestination
{
mutating
func write(_ data:[UInt8]) -> Void?
Expand Down

0 comments on commit 5df5ada

Please sign in to comment.