Reneli
Reneli

Reputation: 1866

JPEG2000 & UIImage

i was comparing Jpeg2000 and Jpeg display speed using UIImage (UIImageView) and noticed that displaying Jpeg2000 is pretty slow compared to Jpeg.

Is this expected and are there and ways to speed it up?

Thanks, -r

Upvotes: 3

Views: 1542

Answers (4)

Alexander Ruzmanov
Alexander Ruzmanov

Reputation: 21

You can convert received image data to .jpg format and then use this kind of data.

import Foundation
import UIKit
import SDWebImageWebPCoder

extension Data {
    var jpegData: Data? {
    var image: UIImage?
    image = UIImage(data: self) ?? SDImageWebPCoder.shared.decodedImage(with: self, options: nil)
    return image?.jpegData(compressionQuality: 1.0)
   }
}

You can don't use SDImageWepPCoder if you are not interested in usage of WepP images. Example of usage:

func loadImage(_ url: URL) {
    DispatchQueue.global(qos: .background).async { [weak self] in
        guard let data = try? Data(contentsOf: url) else {return}
        if let jpegData = data.jpegData {
            DispatchQueue.main.async {
                let displayingImage = UIImage(data: jpegData)
                yourImageView.image = displayingImage
            }
        }
    }
}

This decision can allow you to convert your jp2 data to JPEG in background thread and then use it as usual (with high speed of rendering and without UI freezes)

Upvotes: 0

Lars
Lars

Reputation: 1

Everything that was mentioned here is somewhat true. However, there are implementations of JPEG2000 that are faster for the entire encoding/decoding process than standard JPEG encoders/decoders. They achieve that with excessive multithreading and NEON accelerations.

Check out http://kakadusoftware.com/ and https://groups.yahoo.com/neo/groups/kakadu_jpeg2000/conversations/messages for more details. The library is commercial. There are business versions and ones for individuals / non-commercial. There are quite some efforts to implement it for iOS. BTW: Apple provides JPEG2000 support just with this API for Quicktime and Mac. To a certain extent also iOS.

Upvotes: 0

jjxtra
jjxtra

Reputation: 21140

You can create a UIImage from JPEG 2000 data. The decoding process will be slower than decoding JPEG, but once it's decoded, displaying it in a UIImageView should be just as fast as any other format. If you have lots of JPEG 2000 images, you may want to cache the decoded images in NSCache.

Upvotes: 1

anon
anon

Reputation:

No, there is nothing you can do about that (except not using JPEG 2000, of course). JPEG 2000 requires much more CPU power to en- and decode than plain JPEG files. So even including a third party decoder will probably not bring a huge improvement.

Upvotes: 3

Related Questions