Skip to content

Commit

Permalink
Merge pull request #108 from nextcloud/develop
Browse files Browse the repository at this point in the history
V 0.99.4
  • Loading branch information
Ivansss committed Jan 11, 2022
2 parents c8e3eac + 6e332cc commit c7aabb4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
4 changes: 2 additions & 2 deletions NCCommunication.xcodeproj/project.pbxproj
Expand Up @@ -451,7 +451,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.99.3;
MARKETING_VERSION = 0.99.4;
PLIST_FILE_OUTPUT_FORMAT = "same-as-input";
PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.NCCommunication;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -486,7 +486,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.99.3;
MARKETING_VERSION = 0.99.4;
PLIST_FILE_OUTPUT_FORMAT = "same-as-input";
PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.NCCommunication;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
48 changes: 8 additions & 40 deletions NCCommunication/UIImage+Extensions.swift
Expand Up @@ -4,8 +4,10 @@
//
// Created by Marino Faggiana on 21/12/20.
// Copyright © 2020 Marino Faggiana. All rights reserved.
// Copyright © 2021 Henrik Storch. All rights reserved.
//
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
// Author Henrik Storch <henrik.storch@nextcloud.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -22,60 +24,26 @@
//

import UIKit
import Accelerate

extension UIImage {

internal func resizeImage(size: CGSize, isAspectRation: Bool) -> UIImage? {

let originRatio = self.size.width / self.size.height
let newRatio = size.width / size.height
var newSize = size
let cgImage = self.cgImage!

if isAspectRation {
if originRatio < newRatio {
newSize.height = size.height
newSize.width = size.height * originRatio
} else {
newSize.width = size.width;
newSize.width = size.width
newSize.height = size.width / originRatio
}
}

var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent)
var sourceBuffer = vImage_Buffer()

defer {
free(sourceBuffer.data)
}

var error = vImageBuffer_InitWithCGImage(&sourceBuffer, &format, nil, cgImage, numericCast(kvImageNoFlags))
guard error == kvImageNoError else { return nil }

// create a destination buffer
let destWidth = Int(newSize.width)
let destHeight = Int(newSize.height)
let bytesPerPixel = self.cgImage!.bitsPerPixel/8
let destBytesPerRow = destWidth * bytesPerPixel
let destData = UnsafeMutablePointer<UInt8>.allocate(capacity: destHeight * destBytesPerRow)
defer {
destData.deallocate()
}
var destBuffer = vImage_Buffer(data: destData, height: vImagePixelCount(destHeight), width: vImagePixelCount(destWidth), rowBytes: destBytesPerRow)

// scale the image
error = vImageScale_ARGB8888(&sourceBuffer, &destBuffer, nil, numericCast(kvImageHighQualityResampling))
guard error == kvImageNoError else { return nil }

// create a CGImage from vImage_Buffer
var destCGImage = vImageCreateCGImageFromBuffer(&destBuffer, &format, nil, nil, numericCast(kvImageNoFlags), &error)?.takeRetainedValue()
guard error == kvImageNoError else { return nil }

// create a UIImage
let resizedImage = destCGImage.flatMap { UIImage(cgImage: $0, scale: 0.0, orientation: self.imageOrientation) }
destCGImage = nil

return resizedImage

UIGraphicsBeginImageContextWithOptions(newSize, true, 1.0)
self.draw(in: CGRect(origin: .zero, size: newSize))
defer { UIGraphicsEndImageContext() }
return UIGraphicsGetImageFromCurrentImageContext()
}
}

0 comments on commit c7aabb4

Please sign in to comment.