Upgrade to Pro — share decks privately, control downloads, hide ads and more …

まだJPEGで消耗してるの?/iOSDC-Reject-Conference

 まだJPEGで消耗してるの?/iOSDC-Reject-Conference

Taketo Yoshida

August 30, 2016
Tweet

More Decks by Taketo Yoshida

Other Decks in Programming

Transcript

  1. 15 private func freeImageData(info: UnsafeMutablePointer<Void>, data: UnsafePointer<Void>, size: Int) {

    free(UnsafeMutablePointer<Void>(data)) } extension UIImage { static func imageFromWebPData(data: NSData) -> UIImage? { var config = WebPDecoderConfig() if WebPInitDecoderConfig(&config) == 0 { return nil } if WebPGetFeatures(UnsafePointer<UInt8>(data.bytes), data.length, &config.input) != VP8_STATUS_OK { return nil } config.output.colorspace = config.input.has_alpha != 0 ? MODE_rgbA : MODE_RGB if WebPDecode(UnsafePointer<UInt8>(data.bytes), data.length, &config) != VP8_STATUS_OK { return nil } let width = config.input.width let height = config.input.height let provider = CGDataProviderCreateWithData(nil, config.output.u.RGBA.rgba, config.output.u.RGBA.size, freeImageData) let colorSpaceRef = CGColorSpaceCreateDeviceRGB() let components = config.input.has_alpha != 0 ? 4 : 3 let bi = config.input.has_alpha != 0 ? CGBitmapInfo(rawValue: CGBitmapInfo.ByteOrderDefault.rawValue | CGImageAlphaInfo.PremultipliedLast.rawValue) : CGBitmapInfo.ByteOrderMask guard let imageRef = CGImageCreate( Int(width), Int(height), 8, components * 8, components * Int(width), colorSpaceRef, bi, provider, nil, true, .RenderingIntentDefault) else { return nil } return UIImage(CGImage: imageRef) } } MJCXFCQΛѻ͍΍͘͢͢ΔͨΊʹ&YUFOTJPOΛॻ͘
  2. 21

  3. 25

  4. 26

  5. 34 ը૾ͷԣαΠζ QY +1&(ͷαΠζ ,# 8FC1ͷαΠζ ,#   

                dͷαΠζͷ࡟ݮ
  6. 39 var start = NSDate() [download(url128a), download(url128b), download(url128c), download(url128d), download(url128e)].sequence().then

    { images in let elapsed = NSDate().timeIntervalSinceDate(start) NSLog(elapsed) } ͭͷϑΝΠϧΛಉ࣌ʹμ΢ϯϩʔυͯ͠6**NBHF·Ͱ མͱ͜͠Μͩ࣌ͷ࣌ؒΛ࣮࣭ͷμ΢ϯϩʔυ࣌ؒͱͯ͠ܭଌ ˞࣮ݧ؀ڥJ1IPOFT4PGUCBOL(-5&
  7. 40 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6

    1.8 2 128 256 512 1024 2048 ) ( webp jpeg ը૾αΠζ͕େ͖͍΄Ͳ࣮࣭ͷμ΢ϯϩʔυ࣌ؒ͸୹ॖ͞ΕΔ