• R/O
  • SSH
  • HTTPS

mani2: Commit


Commit MetaInfo

Revision71 (tree)
Time2009-06-28 21:44:29
Authorhikarin

Log Message

[mani2/cocoa] * fixed a memory leak found by clang and added code from createNSImageFromCGImage

Change Summary

Incremental Difference

--- trunk/cocoa/Classes/AppController.m (revision 70)
+++ trunk/cocoa/Classes/AppController.m (revision 71)
@@ -123,9 +123,9 @@
123123 // 前回のキャンバスを破棄する
124124 if (player != nil)
125125 [player release];
126- NSError *error;
127- player = [MMPlayer playerWithSource:inputtedValue
128- error:&error];
126+ NSError *error = nil;
127+ player = [[MMPlayer alloc] initWithSource:inputtedValue
128+ error:&error];
129129 self.durationString = @"0 / 0";
130130 self.frameCount = 0;
131131 if (player != nil) {
@@ -183,9 +183,9 @@
183183 self.statusString = [error localizedDescription];
184184 return;
185185 }
186- MMPlayer *play = [MMPlayer playerWithSource:[canvasIdInput stringValue]
187- error:&error];
188- if (player != nil) {
186+ MMPlayer *play = [[MMPlayer alloc] initWithSource:[canvasIdInput stringValue]
187+ error:&error];
188+ if (play != nil) {
189189 NSDictionary *addImageAttrs = [NSDictionary dictionaryWithObjectsAndKeys:@"mp4v",
190190 QTAddImageCodecType, [NSNumber numberWithLong:codecLosslessQuality],
191191 QTAddImageCodecQuality, nil];
@@ -193,6 +193,7 @@
193193 [panel filename], @"filename", movie, @"movie",
194194 addImageAttrs, @"attrs", nil];
195195 [movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
196+ [play release];
196197 self.movieTotalFrameCount = play.totalFrameCount;
197198 movieTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / 60.0)
198199 target: self
@@ -200,10 +201,9 @@
200201 userInfo:userInfoDictionary
201202 repeats:YES] retain];
202203 }
203- else {
204+ else
204205 self.statusString = [error localizedDescription];
205- [movie release];
206- }
206+ [movie release];
207207 }
208208 }
209209
@@ -215,7 +215,15 @@
215215 data:&bitmapData
216216 source:source flipped:NO];
217217 CGImageRef cgImage = CGBitmapContextCreateImage(bitmap);
218- NSImage *nsImage = [MMAux createNSImageFromCGImage:cgImage];
218+ size_t height = CGImageGetHeight(cgImage);
219+ size_t width = CGImageGetWidth(cgImage);
220+ NSRect rect = NSMakeRect(0.0, 0.0, width, height);
221+ NSImage *nsImage = [[NSImage alloc] initWithSize:rect.size];
222+ [nsImage setFlipped:YES];
223+ [nsImage lockFocus];
224+ CGContextRef graphics = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
225+ CGContextDrawImage(graphics, *(CGRect*)&rect, cgImage);
226+ [nsImage unlockFocus];
219227 [movie addImage:nsImage
220228 forDuration:duration
221229 withAttributes:addImageAttrs];
Show on old repository browser