• R/O
  • SSH
  • HTTPS

mani2: コミット


コミットメタ情報

リビジョン70 (tree)
日時2009-06-28 21:43:11
作者hikarin

ログメッセージ

[mani2/cocoa] * fixed some bugs found by clang and changed playerFromSource to initWithSource

変更サマリ

差分

--- trunk/cocoa/Classes/MMPlayer.m (revision 69)
+++ trunk/cocoa/Classes/MMPlayer.m (revision 70)
@@ -144,6 +144,123 @@
144144 return self;
145145 }
146146
147+static void CreateUrlsFromCanvasId(int canvasId, NSURL **logURL, NSURL **jsonURL, NSURL **layerURL)
148+{
149+ NSString *logURLString = [NSString stringWithFormat:kMMLogURLFormat, canvasId];
150+ NSString *jsonURLString = [NSString stringWithFormat:kMMJsonURLFormat, canvasId];
151+ NSString *layerURLString = [NSString stringWithFormat:kMMLayerUrlFormat, canvasId];
152+ *logURL = [NSURL URLWithString:logURLString];
153+ *jsonURL = [NSURL URLWithString:jsonURLString];
154+ *layerURL = [NSURL URLWithString:layerURLString];
155+}
156+
157+- (id)initWithSource:(NSString *)source
158+ error:(NSError **)aError
159+{
160+ NSError *error = nil;
161+ NSURL *logURL = nil, *jsonURL = nil, *layerURL = nil;
162+ int canvasId = [source intValue];
163+ if (canvasId > 0)
164+ CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
165+ else {
166+ NSURL *url = [NSURL URLWithString:source];
167+ if (url != nil && [[url absoluteString] hasPrefix:kMMImageUrl]
168+ && (canvasId = [[[[url path] lastPathComponent] stringByDeletingPathExtension] intValue]) > 0) {
169+ CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
170+ }
171+ else if (url != nil && [[url scheme] isEqualToString:@"mani2"]
172+ && (canvasId = [[[url resourceSpecifier] substringFromIndex:2] intValue]) > 0) {
173+ CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
174+ }
175+ else {
176+ if (aError != nil) {
177+ if (*aError != nil)
178+ [*aError release];
179+ *aError = [MMAux createErrorFromString:@"Invalid canvas ID or URL"
180+ domain:kMMApplicationExceptionErrorDomain];
181+ }
182+ return nil;
183+ }
184+ }
185+
186+ // お絵描きログそのもの
187+ NSData *logData = [[NSData alloc] initWithContentsOfURL:logURL
188+ options:NSMappedRead
189+ error:&error];
190+ if (logData == nil) {
191+ if (aError != nil) {
192+ if (*aError != nil)
193+ [*aError release];
194+ *aError = error;
195+ }
196+ return nil;
197+ }
198+
199+ // レイヤー画像。縦の長さが(画像 * レイヤー数)になる。
200+ /*
201+ NSData *layerData = [[NSData alloc] initWithContentsOfURL:layerURL options:NSMappedRead error:&error];
202+ if (layerData == nil) {
203+ [*aError release];
204+ *aError = error;
205+ return NO;
206+ }
207+ */
208+
209+ // お絵描きした情報
210+ NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL
211+ encoding:NSUTF8StringEncoding
212+ error:&error];
213+ if (jsonData == nil) {
214+ if (aError != nil) {
215+ if (*aError != nil)
216+ [*aError release];
217+ *aError = error;
218+ }
219+ [logData release];
220+ return nil;
221+ }
222+
223+ // お絵描きログがzlibで圧縮されているので解凍する
224+ NSData *inflatedData = nil;
225+ if (![MMAux inflateZlibFromDeflatedData:logData
226+ inflatedData:&inflatedData
227+ error:&error]) {
228+ if (aError != nil) {
229+ if (*aError != nil)
230+ [*aError release];
231+ *aError = error;
232+ }
233+ [logData release];
234+ [jsonData release];
235+ return nil;
236+ }
237+
238+ /*
239+ NSDictionary *info = [MMAux deserializeObjectFromJsonData:jsonData error:&error];
240+ NSArray *layerInfo = [[NSArray alloc] initWithArray:(NSArray *)[info objectForKey:@"layer_infos"]];
241+ if (layerInfo == nil)
242+ layerInfo = [[NSArray alloc] init];
243+
244+ CGContextRef layerBitmap;
245+ void *layerBitmapData;
246+ if (![MMPlayer createBitmapFromLayerImageData:layerData bitmap:&layerBitmap data:&layerBitmapData])
247+ return NO;
248+ */
249+
250+ MMPlayer *player = [self init];
251+ [player loadData:inflatedData
252+ bitmap:NULL
253+ layerInfo:nil];
254+ /*
255+ [MMAux releaseBitmap:&layerBitmap data:&layerBitmapData];
256+ [layerInfo release];
257+ [layerData release];
258+ */
259+ [logData release];
260+ [jsonData release];
261+ return player;
262+}
263+
147264 - (void)dealloc
148265 {
149266 [MMAux releaseBitmap:&drawLayer
@@ -357,7 +474,7 @@
357474 break;
358475 case kMMLineStyleMiterLimit:
359476 doubleValue = [log readDouble];
360- //[self setLineMiterLimit:doubleValue];
477+ [self setLineMiterLimit:doubleValue];
361478 break;
362479 case kMMLineStyleBlendMode:
363480 stringValue = [log readNSString];
@@ -623,7 +740,7 @@
623740 {
624741 MMLayers *layersDataForUndo = [undo undo];
625742 if (layersDataForUndo != nil)
626- layers.layersDataForUndo = layersDataForUndo;
743+ [layers setLayersDataForUndo:layersDataForUndo];
627744 MMLogAction(@"undo");
628745 }
629746
@@ -631,7 +748,7 @@
631748 {
632749 MMLayers *layersDataForUndo = [undo redo];
633750 if (layersDataForUndo != nil)
634- layers.layersDataForUndo = layersDataForUndo;
751+ [layers setLayersDataForUndo:layersDataForUndo];
635752 MMLogAction(@"redo");
636753 }
637754
@@ -777,8 +894,11 @@
777894 CGRect rect = CGRectMake(0, 0, layerWidth, layerHeight);
778895 if (![MMAux createBitmap:layerBitmap
779896 size:size
780- data:layerBitmapData])
897+ data:layerBitmapData]) {
898+ CGImageRelease(layerImage);
899+ CFRelease(layerSource);
781900 return NO;
901+ }
782902 CGContextDrawImage(*layerBitmap, rect, layerImage);
783903 #if MM_PLATHOME_IPHONE
784904 [layerSource release];
@@ -789,106 +909,5 @@
789909 return YES;
790910 }
791911
792-static void CreateUrlsFromCanvasId(int canvasId, NSURL **logURL, NSURL **jsonURL, NSURL **layerURL)
793-{
794- NSString *logURLString = [NSString stringWithFormat:kMMLogURLFormat, canvasId];
795- NSString *jsonURLString = [NSString stringWithFormat:kMMJsonURLFormat, canvasId];
796- NSString *layerURLString = [NSString stringWithFormat:kMMLayerUrlFormat, canvasId];
797- *logURL = [NSURL URLWithString:logURLString];
798- *jsonURL = [NSURL URLWithString:jsonURLString];
799- *layerURL = [NSURL URLWithString:layerURLString];
800-}
801-
802-+ (MMPlayer *)playerWithSource:(NSString *)source
803- error:(NSError **)aError
804-{
805- NSError *error = nil;
806- NSURL *logURL = nil, *jsonURL = nil, *layerURL = nil;
807- int canvasId = [source intValue];
808- if (canvasId > 0)
809- CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
810- else {
811- NSURL *url = [NSURL URLWithString:source];
812- if (url != nil && [[url absoluteString] hasPrefix:kMMImageUrl]
813- && (canvasId = [[[[url path] lastPathComponent] stringByDeletingPathExtension] intValue]) > 0) {
814- CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
815- }
816- else if (url != nil && [[url scheme] isEqualToString:@"mani2"]
817- && (canvasId = [[[url resourceSpecifier] substringFromIndex:2] intValue]) > 0) {
818- CreateUrlsFromCanvasId(canvasId, &logURL, &jsonURL, &layerURL);
819- }
820- else {
821- *aError = [MMAux createErrorFromString:@"Invalid canvas ID or URL"
822- domain:kMMApplicationExceptionErrorDomain];
823- return nil;
824- }
825- }
826-
827- // お絵描きログそのもの
828- NSData *logData = [[NSData alloc] initWithContentsOfURL:logURL
829- options:NSMappedRead
830- error:&error];
831- if (logData == nil) {
832- [*aError release];
833- *aError = error;
834- return nil;
835- }
836-
837- // レイヤー画像。縦の長さが(画像 * レイヤー数)になる。
838- /*
839- NSData *layerData = [[NSData alloc] initWithContentsOfURL:layerURL options:NSMappedRead error:&error];
840- if (layerData == nil) {
841- [*aError release];
842- *aError = error;
843- return NO;
844- }
845- */
846-
847- // お絵描きした情報
848- NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL
849- encoding:NSUTF8StringEncoding
850- error:&error];
851- if (jsonData == nil) {
852- [*aError release];
853- *aError = error;
854- return nil;
855- }
856-
857- // お絵描きログがzlibで圧縮されているので解凍する
858- NSData *inflatedData = [MMAux inflateZlibCompressedFromData:logData
859- error:&error];
860- if (inflatedData == nil) {
861- [*aError release];
862- *aError = error;
863- return nil;
864- }
865-
866- /*
867- NSDictionary *info = [MMAux deserializeObjectFromJsonData:jsonData error:&error];
868- NSArray *layerInfo = [[NSArray alloc] initWithArray:(NSArray *)[info objectForKey:@"layer_infos"]];
869- if (layerInfo == nil)
870- layerInfo = [[NSArray alloc] init];
871-
872- CGContextRef layerBitmap;
873- void *layerBitmapData;
874- if (![MMPlayer createBitmapFromLayerImageData:layerData bitmap:&layerBitmap data:&layerBitmapData])
875- return NO;
876- */
877-
878- BOOL ret = NO;
879- MMPlayer *player = [[MMPlayer alloc] init];
880- ret = [player loadData:inflatedData
881- bitmap:NULL
882- layerInfo:nil];
883- /*
884- [MMAux releaseBitmap:&layerBitmap data:&layerBitmapData];
885- [layerInfo release];
886- [layerData release];
887- */
888- [inflatedData release];
889- [logData release];
890- return ret ? player : nil;
891-}
892-
893912 @end
894913
--- trunk/cocoa/Classes/MMPlayer.h (revision 69)
+++ trunk/cocoa/Classes/MMPlayer.h (revision 70)
@@ -98,12 +98,12 @@
9898 NSString *blendMode;
9999 }
100100
101+- (id)initWithSource:(NSString *)source
102+ error:(NSError **)aError;
101103 - (BOOL)loadData:(NSData *)inflatedBytes
102104 bitmap:(CGContextRef)bitmap
103105 layerInfo:(NSArray *)layerInfo;
104106 - (BOOL)nextFrame;
105-+ (MMPlayer *)playerWithSource:(NSString *)source
106- error:(NSError **)err;
107107
108108 @property(readonly) CGContextRef bitmap;
109109 @property(readonly) CGSize size;
旧リポジトリブラウザで表示