Skip to content

Commit

Permalink
element-hq#638 - updated camera
Browse files Browse the repository at this point in the history
  • Loading branch information
ianscott313 committed Jan 25, 2018
1 parent 8564656 commit 491ac62
Show file tree
Hide file tree
Showing 41 changed files with 2,803 additions and 2,367 deletions.
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ abstract_target 'RiotPods' do
pod 'OLMKit'
#pod 'OLMKit', :path => '../olm/OLMKit.podspec'
pod 'Realm', '~> 3.0.1'

pod 'LLSimpleCamera', :inhibit_warnings => true

# Remove warnings from "bad" pods
pod 'OLMKit', :inhibit_warnings => true
pod 'cmark', :inhibit_warnings => true
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ PODS:
- GZIP (1.2.1)
- HPGrowingTextView (1.1)
- libPhoneNumber-iOS (0.9.13)
- LLSimpleCamera (5.0.0)
- MatrixKit (0.7.4):
- cmark (~> 0.24.1)
- DTCoreText (~> 1.6.17)
Expand Down Expand Up @@ -82,6 +83,7 @@ DEPENDENCIES:
- DTCoreText
- GBDeviceInfo (~> 4.4.0)
- GoogleAnalytics
- LLSimpleCamera
- MatrixKit (= 0.7.4)
- MatrixKit/AppExtension (= 0.7.4)
- OLMKit
Expand All @@ -98,12 +100,13 @@ SPEC CHECKSUMS:
GZIP: 7ee835f989fb3c6ea79005fc90b8fa6af710a70d
HPGrowingTextView: 88a716d97fb853bcb08a4a08e4727da17efc9b19
libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa
LLSimpleCamera: 7175ccb81be71c83d79933089322eb662b1f0327
MatrixKit: 9bc9da0fe38044efe091cda90150297004ede2a9
MatrixSDK: 66bca5fec7ce03bd9872a42a7877473fcbf822e3
OLMKit: b9d8c0ffee9ea8c45bc0aaa9afb47f93fba7efbd
Realm: 6f23fd1f178a09342eac21bfa7c2bf4312a7a180
WebRTC: 141474ba648e0b940a70696c183451b4a3b2b10f

PODFILE CHECKSUM: 696d4bf991b3e4e4bc898955d56aa02367abc642
PODFILE CHECKSUM: b371e605ce896eeaee2b2ab15eda9c904aa6df05

COCOAPODS: 1.3.1
146 changes: 112 additions & 34 deletions Riot.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Riot.xcodeproj/xcshareddata/xcschemes/Riot.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
buildImplicitDependencies = "NO">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Binary file added Riot/Assets/Images/camera-flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/cancel2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/send.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Riot/Assets/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Riot/Riot.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>group.im.vector</string>
<string>group.im.vector</string>
</array>
</dict>
</plist>
13 changes: 13 additions & 0 deletions Riot/Utils/Camera/UIImage+Crop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIImage+Crop.h
// LLSimpleCamera
//
// Created by Ömer Faruk Gül on 27/10/14.
// Copyright (c) 2014 Ömer Faruk Gül. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImage(CropCategory)
- (UIImage *)crop:(CGRect)rect;
@end
24 changes: 24 additions & 0 deletions Riot/Utils/Camera/UIImage+Crop.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// UIImage+Crop.m
// LLSimpleCamera
//
// Created by Ömer Faruk Gül on 27/10/14.
// Copyright (c) 2014 Ömer Faruk Gül. All rights reserved.
//

#import "UIImage+Crop.h"

@implementation UIImage(CropCategory)
- (UIImage *)crop:(CGRect)rect {

rect = CGRectMake(rect.origin.x * self.scale,
rect.origin.y * self.scale,
rect.size.width * self.scale,
rect.size.height * self.scale);

CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
CGImageRelease(imageRef);
return result;
}
@end
36 changes: 36 additions & 0 deletions Riot/Utils/Camera/UIImage+Resize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/***********************************************************************************
*
* Copyright (c) 2010 Olivier Halligon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
***********************************************************************************
*
* Any comment or suggestion welcome. Referencing this project in your AboutBox is appreciated.
* Please tell me if you use this class so we can cross-reference our projects.
*
***********************************************************************************/


#import <UIKit/UIKit.h>

@interface UIImage(ResizeCategory)
-(UIImage*)resizedImageToSize:(CGSize)dstSize;
-(UIImage*)resizedImageToFitInSize:(CGSize)boundingSize scaleIfSmaller:(BOOL)scale;
@end
153 changes: 153 additions & 0 deletions Riot/Utils/Camera/UIImage+Resize.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//
// UIImage+Resize.m
//
// Created by Olivier Halligon on 12/08/09.
// Copyright 2009 AliSoftware. All rights reserved.
//

#import "UIImage+Resize.h"

@implementation UIImage (ResizeCategory)

-(UIImage*)resizedImageToSize:(CGSize)dstSize
{
CGImageRef imgRef = self.CGImage;
// the below values are regardless of orientation : for UIImages from Camera, width>height (landscape)
CGSize srcSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef)); // not equivalent to self.size (which is dependant on the imageOrientation)!

/* Don't resize if we already meet the required destination size. */
if (CGSizeEqualToSize(srcSize, dstSize)) {
return self;
}

CGFloat scaleRatio = dstSize.width / srcSize.width;
UIImageOrientation orient = self.imageOrientation;
CGAffineTransform transform = CGAffineTransformIdentity;
switch(orient) {

case UIImageOrientationUp: //EXIF = 1
transform = CGAffineTransformIdentity;
break;

case UIImageOrientationUpMirrored: //EXIF = 2
transform = CGAffineTransformMakeTranslation(srcSize.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
break;

case UIImageOrientationDown: //EXIF = 3
transform = CGAffineTransformMakeTranslation(srcSize.width, srcSize.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;

case UIImageOrientationDownMirrored: //EXIF = 4
transform = CGAffineTransformMakeTranslation(0.0, srcSize.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
break;

case UIImageOrientationLeftMirrored: //EXIF = 5
dstSize = CGSizeMake(dstSize.height, dstSize.width);
transform = CGAffineTransformMakeTranslation(srcSize.height, srcSize.width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI_2);
break;

case UIImageOrientationLeft: //EXIF = 6
dstSize = CGSizeMake(dstSize.height, dstSize.width);
transform = CGAffineTransformMakeTranslation(0.0, srcSize.width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI_2);
break;

case UIImageOrientationRightMirrored: //EXIF = 7
dstSize = CGSizeMake(dstSize.height, dstSize.width);
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI_2);
break;

case UIImageOrientationRight: //EXIF = 8
dstSize = CGSizeMake(dstSize.height, dstSize.width);
transform = CGAffineTransformMakeTranslation(srcSize.height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI_2);
break;

default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];

}

/////////////////////////////////////////////////////////////////////////////
// The actual resize: draw the image on a new context, applying a transform matrix
UIGraphicsBeginImageContextWithOptions(dstSize, NO, self.scale);

CGContextRef context = UIGraphicsGetCurrentContext();

if (!context) {
return nil;
}

if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
CGContextScaleCTM(context, -scaleRatio, scaleRatio);
CGContextTranslateCTM(context, -srcSize.height, 0);
} else {
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -srcSize.height);
}

CGContextConcatCTM(context, transform);

// we use srcSize (and not dstSize) as the size to specify is in user space (and we use the CTM to apply a scaleRatio)
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, srcSize.width, srcSize.height), imgRef);
UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return resizedImage;
}



/////////////////////////////////////////////////////////////////////////////



-(UIImage*)resizedImageToFitInSize:(CGSize)boundingSize scaleIfSmaller:(BOOL)scale
{
// get the image size (independant of imageOrientation)
CGImageRef imgRef = self.CGImage;
CGSize srcSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef)); // not equivalent to self.size (which depends on the imageOrientation)!

// adjust boundingSize to make it independant on imageOrientation too for farther computations
UIImageOrientation orient = self.imageOrientation;
switch (orient) {
case UIImageOrientationLeft:
case UIImageOrientationRight:
case UIImageOrientationLeftMirrored:
case UIImageOrientationRightMirrored:
boundingSize = CGSizeMake(boundingSize.height, boundingSize.width);
break;
default:
// NOP
break;
}

// Compute the target CGRect in order to keep aspect-ratio
CGSize dstSize;

if ( !scale && (srcSize.width < boundingSize.width) && (srcSize.height < boundingSize.height) ) {
//NSLog(@"Image is smaller, and we asked not to scale it in this case (scaleIfSmaller:NO)");
dstSize = srcSize; // no resize (we could directly return 'self' here, but we draw the image anyway to take image orientation into account)
} else {
CGFloat wRatio = boundingSize.width / srcSize.width;
CGFloat hRatio = boundingSize.height / srcSize.height;

if (wRatio < hRatio) {
//NSLog(@"Width imposed, Height scaled ; ratio = %f",wRatio);
dstSize = CGSizeMake(boundingSize.width, floorf(srcSize.height * wRatio));
} else {
//NSLog(@"Height imposed, Width scaled ; ratio = %f",hRatio);
dstSize = CGSizeMake(floorf(srcSize.width * hRatio), boundingSize.height);
}
}

return [self resizedImageToSize:dstSize];
}

@end
Loading

0 comments on commit 491ac62

Please sign in to comment.