Core Image filter "CIDepthBlurEffect" not working on iOS 11 / Xcode 9.0 - core-image

I can't get the new CIDepthBlurEffect to work. Am I doing something wrong, or is this a known issue?
Below is my code in Objective-C:
NSDictionary *dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], nil] forKeys:[NSArray arrayWithObjects:kCIImageAuxiliaryDisparity, #"kCIImageApplyOrientationProperty", nil]];
CIImage *disparityImage = [CIImage imageWithData:imageData options:dict];
CIFilter *ciDepthBlurEffect = [CIFilter filterWithName:#"CIDepthBlurEffect"];
[ciDepthBlurEffect setDefaults];
[ciDepthBlurEffect setValue:disparityImage forKey:#"inputDisparityImage"];
[ciDepthBlurEffect setValue:originalImage forKey:#"inputImage"];
CIImage *outputImage = [ciDepthBlurEffect valueForKey:#"outputImage"];
EAGLContext *previewEaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
CIContext *context = [CIContext contextWithEAGLContext:previewEaglContext options:#{kCIContextWorkingFormat :[NSNumber numberWithInt:kCIFormatRGBAh]} ];
CGImageRef cgimg = [context createCGImage:disparityImage fromRect:[disparityImage extent]];
image = [[UIImage alloc] initWithCGImage:cgimg];
CGImageRelease(cgimg);

This issue was resolved with the release of Xcode 9 beta 2 and iOS 11 beta 2.

Related

GPUImageVideoCamera save video on ios 7

I'm trying to achieve the square video recording like 300*300 so I choose GPUImage but its not working on IOS 7 and giving errors like [UIView nextAvailableTextureIndex]: unrecognized selector sent to instance the error starts when we build the even the sample code
when trying to save the GPUImageVideoCamera
some times its stucks at [movieWriter startRecording]; 
is the GPUImage compatible with ios 7 or we have made some changes ?
here is the code
- (void)viewDidLoad
{
[super viewDidLoad];
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = NO;
filter = [[GPUImageSepiaFilter alloc] init];
initWithRotation:kGPUImageRotateRightFlipVertical];
[videoCamera addTarget:filter];
GPUImageView *filterView = (GPUImageView *)self.view;
[filter addTarget:filterView];
sharing
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
[filter addTarget:movieWriter];
}
- (IBAction)stopRecording:(id)sender {
[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
}
- (IBAction)startRecording:(id)sender {
videoCamera.audioEncodingTarget = movieWriter;
[movieWriter startRecording];
[videoCamera startCameraCapture];
}
My guess is that you modified the .xib or storyboard and didn't set the class of the view that is showing the camera preview to GPUImageView.

Can not show rightBarButtonItem on ipad

This is my code :
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"RETURN" style:UIBarButtonItemStylePlain target:self action:#selector(refreshPropertyList:)];
navigationController.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
[IpadAppDelegate.stackController presentModalViewController:navigationController animated:YES];
I find out the reason :
need change navigationController.navigationItem.rightBarButtonItem = anotherButton;
to: self.navigationItem.rightBarButtonItem = anotherButton;

Copy item from iPod Library

I'm trying to copy an item from the iPod Library to my local storage space - for later playback. I've got the item URl but it's (ipod-library://item/item.mp3?id=2398084975506389321) any idea how to access the actual file?
Thanks,
Rick
This will work https://gist.github.com/3304992
-(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
NSString *tempPath = NSTemporaryDirectory();
int i=1;
for (MPMediaItem *theItem in mediaItemCollection.items) {
NSURL *url = [theItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetPassthrough];
exporter.outputFileType = #"com.apple.coreaudio-format";
NSString *fname = [[NSString stringWithFormat:#"%d",i] stringByAppendingString:#".caf"];
++i;
NSString *exportFile = [tempPath stringByAppendingPathComponent: fname];
exporter.outputURL = [NSURL fileURLWithPath:exportFile];
[exporter exportAsynchronouslyWithCompletionHandler:^{
//Code for completion Handler
}];
}
[picker dismissViewControllerAnimated:YES completion:Nil];
}
use MPMediaPickerController to pick the media
This is how I'm doing it in Objective-C:
#import <CoreMedia/CoreMedia.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudio.h>
// or [NSURL URLWithString:#"ipod-library://item/item.mp3?id=2398084975506389321"]
NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSMutableData *data = [[NSMutableData alloc] init];
const uint32_t sampleRate = 16000;
const uint16_t bitDepth = 16;
const uint16_t channels = 2;
NSDictionary *opts = [NSDictionary dictionary];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:assetURL options:opts];
AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:asset error:NULL];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithFloat:(float)sampleRate], AVSampleRateKey,
[NSNumber numberWithInt:bitDepth], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
[NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
nil];
AVAssetReaderTrackOutput *output = [[AVAssetReaderTrackOutput alloc] initWithTrack:[[asset tracks] objectAtIndex:0] outputSettings:settings];
[asset release];
[reader addOutput:output];
[reader startReading];
// read the samples from the asset and append them subsequently
while ([reader status] != AVAssetReaderStatusCompleted) {
CMSampleBufferRef buffer = [output copyNextSampleBuffer];
if (buffer == NULL) continue;
CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(buffer);
size_t size = CMBlockBufferGetDataLength(blockBuffer);
uint8_t *outBytes = malloc(size);
CMBlockBufferCopyDataBytes(blockBuffer, 0, size, outBytes);
CMSampleBufferInvalidate(buffer);
CFRelease(buffer);
[data appendBytes:outBytes length:size];
free(outBytes);
}
[output release];
Here data will contain the raw PCM data of the track. Please note that you cannot directly access the file of a song or video, only its data through this method. You can compress it using e. g. FLAC (that's how I'm processing it in my tweak).
Since MonoTouch has an 1:1 mapping to Objective-C class and method names, this should be fairly easy to copy over. :)

stringWithContentsOfURL depreciated, help to update to 4.2?

Hello
Could anyone help me update this snippent to iOS 4.2:
-(void) whatever{
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: #"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser search:#"//h3"]; // get the page title - this is xpath notation
TFHppleElement *element = [elements objectAtIndex:0];
NSString *myTitle = [element content];
NSLog(myTitle);
[xpathParser release];
[htmlData release];}
The only part that needs updating is below, you can effectivly forget the rest:
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: #"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
"stringWithContentsOfURL" has been deprechiated so what would be the updated version?
Thanks
You should use
+ (id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error
And use it like that. Replace
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: #"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
by
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: #"http://www.objectgraph.com/contact.html"]] encoding:NSUTF8StringEncoding error:nil];

NSArray Release crash

In my code, i'm creating 5 sets of objects, and 5 NSArrays containing those objects. At the end of my method, two of the arrays release properly, but the other three crash my application.
Creating
UIImageView *image0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TankAxe.png"]];
NSArray *imageArray = [[NSArray alloc] initWithObjects:image0, nil];
NSString *name0 = [NSString stringWithString:#"Pistol"];
NSArray *nameArray = [[NSArray alloc] initWithObjects:name0, nil];
NSNumber *price0 = [NSNumber numberWithInt:100];
NSArray *priceArray = [[NSArray alloc] initWithObjects:price0, nil];
NSNumber *round0 = [NSNumber numberWithInt:0];
NSArray *roundArray = [[NSArray alloc] initWithObjects:round0, nil];
NSNumber *priceRound0 = [NSNumber numberWithInt:0];
NSArray *priceRoundArray = [[NSArray alloc] initWithObjects:priceRound0, nil];
Releasing
[name0 release];
[nameArray release]; //Releases properly
[image0 release];
[imageArray release]; //Releases properly
[price0 release];
NSLog(#"%i",[priceArray retainCount]); //Returns 1
[priceArray release]; //Source of the crash
[round0 release];
[roundArray release]; //Also crashes
[priceRound0 release];
[priceRoundArray release]; //Also Crashes
Anybody know how to properly release the arrays containing NSNumbers?
price0, name0,round0, and priceRound0 should not be released. They were not created with alloc, and will be autoreleased by the methods that returned them.
Once you release an object that you shouldn't, the heap is corrupted, and the program could crash at any time.
The easiest way to debug this is to turn on zombies (Tip #1):
http://www.loufranco.com/blog/files/debugging-memory-iphone.html

Resources