Skip to content

Commit

Permalink
Fix AVIF, JXL support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jshier committed Aug 3, 2023
1 parent 417d5b2 commit 9ef9041
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 29 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.3"
- xcode: "Xcode_14.3.app"
runsOn: firebreak
name: "macOS 13, Xcode 14.3, Swift 5.8.0"
testPlan: "macOS"
- xcode: "Xcode_14.2"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "macOS 12, Xcode 14.2, Swift 5.7.2"
testPlan: "macOS"
Expand Down Expand Up @@ -67,10 +67,6 @@ jobs:
runsOn: macOS-11
name: "macOS 11, Xcode 13.0, Swift 5.5.0"
testPlan: "macOS-NoTS"
- xcode: "Xcode_12.5.1.app"
runsOn: macOS-11
name: "macOS 11, Xcode 12.5.1, Swift 5.4.2"
testPlan: "macOS-NoTS"
steps:
- uses: actions/checkout@v3
- name: Install Firewalk
Expand Down Expand Up @@ -124,7 +120,7 @@ jobs:
name: "Test Old iOS"
runs-on: firebreak
env:
DEVELOPER_DIR: "/Applications/Xcode_14.1.app/Contents/Developer"
DEVELOPER_DIR: "/Applications/Xcode_14.3.app/Contents/Developer"
timeout-minutes: 10
strategy:
fail-fast: false
Expand Down Expand Up @@ -231,14 +227,14 @@ jobs:
name: Test with SPM
runs-on: ${{ matrix.runsOn }}
env:
DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}/Contents/Developer"
DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer"
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.3"
runsOn: firebreak
runsOn: macOS-13
name: "macOS 13, SPM 5.8.0 Test"
- xcode: "Xcode_14.2"
runsOn: macOS-12
Expand Down Expand Up @@ -269,4 +265,4 @@ jobs:
- name: Install Firewalk
run: brew install alamofire/alamofire/firewalk && firewalk &
- name: Test SPM
run: ${{ matrix.run }}
run: swift build -c debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "78424be314842833c04bc3bef5b72e85fff99204",
"version" : "5.6.4"
"revision" : "bc268c28fb170f494de9e9927c371b8342979ece",
"version" : "5.7.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v4)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.6.0")],
from: "5.7.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v3)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.6.0")],
from: "5.7.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v3)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.6.0")],
from: "5.7.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v4)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.6.0")],
from: "5.7.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v4)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.6.0")],
from: "5.7.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
9 changes: 8 additions & 1 deletion Source/Request+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public final class ImageResponseSerializer: ResponseSerializer {
public let emptyRequestMethods: Set<HTTPMethod>

public internal(set) static var acceptableImageContentTypes: Set<String> = {
// Universally supported image types.
var contentTypes: Set<String> = [
"application/octet-stream",
"application/octet-stream", // As a fallback for things like AWS which provide no real type.
"image/gif",
"image/ico",
"image/jp2",
Expand All @@ -71,6 +72,12 @@ public final class ImageResponseSerializer: ResponseSerializer {
contentTypes.formUnion(["image/heic", "image/heif"])
}

#if !os(watchOS)
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, *) {
contentTypes.insert("image/avif")
}
#endif

if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) {
contentTypes.insert("image/jxl")
}
Expand Down
8 changes: 4 additions & 4 deletions Source/UIButton+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@ extension UIButton {
// MARK: - Private - AssociatedKeys

private enum AssociatedKeys {
static var imageDownloader = "UIButton.af.imageDownloader"
static var sharedImageDownloader = "UIButton.af.sharedImageDownloader"
static var imageReceipts = "UIButton.af.imageReceipts"
static var backgroundImageReceipts = "UIButton.af.backgroundImageReceipts"
static var imageDownloader = true
static var sharedImageDownloader = true
static var imageReceipts = true
static var backgroundImageReceipts = true
}

#endif
2 changes: 1 addition & 1 deletion Source/UIImage+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,5 @@ extension UIImage {
// MARK: -

private enum AssociatedKeys {
static var isInflated = "UIImage.af.isInflated"
static var isInflated = true
}
6 changes: 3 additions & 3 deletions Source/UIImageView+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ extension UIImageView {
// MARK: -

private enum AssociatedKeys {
static var imageDownloader = "UIImageView.af.imageDownloader"
static var sharedImageDownloader = "UIImageView.af.sharedImageDownloader"
static var activeRequestReceipt = "UIImageView.af.activeRequestReceipt"
static var imageDownloader = true
static var sharedImageDownloader = true
static var activeRequestReceipt = true
}

#endif
36 changes: 36 additions & 0 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,42 @@ final class DataRequestTestCase: BaseTestCase {
}

#endif

func testThatImageResponseSerializerCanDownloadJPEGXLImage() {
guard #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) else { return }

// Given
let expectation = self.expectation(description: "Request should return JPEG XL response image")

var response: AFDataResponse<Image>?

// When
session.request(.image(.jxl))
.responseImage { closureResponse in
response = closureResponse
expectation.fulfill()
}

waitForExpectations(timeout: timeout)

// Then
XCTAssertNotNil(response?.request, "request should not be nil")
XCTAssertNotNil(response?.response, "response should not be nil")
XCTAssertTrue(response?.result.isSuccess ?? false, "result should be success")

guard let image = response?.result.value else {
XCTFail("JPEG XL image should not be nil")
return
}

let expectedSize = Endpoint.Image.jxl.expectedSize
#if os(iOS) || os(tvOS)
XCTAssertEqual(image.size, expectedSize.scaledToScreen, "image size does not match expected value")
XCTAssertTrue(image.isScaledToScreen, "image scale does not match expected value")
#elseif os(macOS)
XCTAssertEqual(image.size, expectedSize, "image size does not match expected value")
#endif
}

// func testThatImageResponseSerializerCanDownloadImageFromFileURL() {
// // Given
Expand Down
5 changes: 3 additions & 2 deletions Tests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ struct Endpoint {
images.remove(.webp) // WebP is only supported on macOS 11+ and iOS 14+.
images.remove(.pdf) // No platform supports direct PDF downloads.
images.remove(.avif) // No AVIF support on watchOS, only macOS 13+, iOS 16+.
images.remove(.jxl) // No JPEG XL support below 2023 OS versions.

return images
}()

case avif, bmp, jp2, jpeg, gif, heic, heif, pdf, png, webp
case avif, bmp, jp2, jpeg, jxl, gif, heic, heif, pdf, png, webp

var expectedSize: CGSize {
switch self {
case .bmp, .jp2, .jpeg, .gif, .pdf, .png, .webp:
case .bmp, .jp2, .jpeg, .jxl, .gif, .pdf, .png, .webp:
return .init(width: 1, height: 1)
case .heic, .heif:
return .init(width: 64, height: 64)
Expand Down

0 comments on commit 9ef9041

Please sign in to comment.