Alamofire / AlamofireImage

AlamofireImage is an image component library for Alamofire
MIT License
3.99k stars 523 forks source link

Feature request: Support `image/avif` to Accept header for iOS 16, macOS Ventura and more. #461

Closed r-plus closed 1 year ago

r-plus commented 2 years ago

What did you do?

iOS 16 and macOS Ventura start support AVIF image type so this feature request want adding image/avif to request Accept header as dynamic similar to image/webp support.

I'm not sure about tvOS and watchOS are support AVIF on latest version.

What did you expect to happen?

image/avif string contained in accept header when running OS is iOS 16 or macOS Ventura.

What happened instead?

Not yet added.

Alamofire Environment

Alamofire Image version: 4.2.0

Demo Project

N/A

jshier commented 2 years ago

Makes sense, I can investigate soon. Can you (or anyone) confirm whether AVIF decoding is exposed to UIImage / NSImage / CGImage and on what platforms? WebP was weird because only iOS / macOS supported it and tvOS / watchOS didn't.

r-plus commented 2 years ago

I just try to show AVIF basic image (YUV420, 8bit depth) from https://github.com/link-u/avif-sample-images by this code. It displayed hato image on iOS 16.0.3, iPhone 14 Pro device.

struct ContentView: View {
    var body: some View {
        let url = URL(string: "https://raw.githubusercontent.com/link-u/avif-sample-images/master/hato.profile0.8bpc.yuv420.avif")!
        AsyncImage(url: url) { image in
            image.resizable()
                .scaledToFit()
        } placeholder: {
            ProgressView()
        }
    }
}

additionally, check the UIImage too.

    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: "https://raw.githubusercontent.com/link-u/avif-sample-images/master/hato.profile0.8bpc.yuv420.avif")!
        let v = UIImageView(frame: .init(x: 0, y: 0, width: 300, height: 300))
        self.view.addSubview(v)
        Task {
            let result = try! await URLSession.shared.data(for: URLRequest(url: url))
            let image = UIImage.init(data: result.0)!
            v.image = image
        }
    }

not yet upgrade to macOS Ventura to check this.

r-plus commented 2 years ago

SwiftUI and NSImage correctly displayed avif image on macOS Ventura.

SwiftUI

スクリーンショット 2022-10-28 22 47 28

NSView

スクリーンショット 2022-10-28 22 50 48
jshier commented 2 years ago

Looks like AVIF is supported on macOS, iOS, and tvOS (unlike WebP still), but not watchOS. I've got the change but I need to update and deploy a new version of the test server along with a significant testing refactor for the new OSes, so it'll be a little while before this can get released.

jshier commented 1 year ago

Sorry for the long delay. This has been merged, along with JPEG XL support on the 2023 OSes, in #464 and should go out with the next release.