• R/O
  • SSH
  • HTTPS

mani2: Commit


Commit MetaInfo

Revision69 (tree)
Time2009-06-28 21:42:10
Authorhikarin

Log Message

[mani2/cocoa] * removed createNSImageFromCGImage and rename to inflateZlibFromDeflatedData

Change Summary

Incremental Difference

--- trunk/cocoa/Classes/MMAux.m (revision 68)
+++ trunk/cocoa/Classes/MMAux.m (revision 69)
@@ -44,8 +44,9 @@
4444 *blue = (CGFloat)(color & 0x000000ff) / 255.0;
4545 }
4646
47-+ (NSData *)inflateZlibCompressedFromData:(NSData *)deflatedData
48- error:(NSError **)error
47++ (BOOL)inflateZlibFromDeflatedData:(NSData *)deflatedData
48+ inflatedData:(NSData **)inflatedData
49+ error:(NSError **)error
4950 {
5051 NSUInteger deflatedLength = [deflatedData length];
5152 // 12はzlibにおける固定長のきまり。
@@ -53,13 +54,20 @@
5354 uLongf inflatedLength = deflatedLength * 5 + 12;
5455 Bytef *inflatedBytes = (Bytef *)malloc(inflatedLength);
5556 if (inflatedBytes == NULL)
56- return nil;
57+ return NO;
5758 int ret = uncompress(inflatedBytes, &inflatedLength, [deflatedData bytes], deflatedLength);
5859 if (ret == Z_OK) {
5960 // inflatedBytesのメモリ管理権はNSDataに移動したのでfreeしてはいけない
6061 // このNSDataが解放されると同時にinflatedBytesも解放される
61- return [[NSData alloc] initWithBytesNoCopy:inflatedBytes
62- length:(NSUInteger)inflatedLength];
62+ if (inflatedData != nil) {
63+ if (*inflatedData != nil)
64+ [*inflatedData release];
65+ *inflatedData = [[NSData alloc] initWithBytesNoCopy:inflatedBytes
66+ length:(NSUInteger)inflatedLength];
67+ }
68+ else
69+ free(inflatedBytes);
70+ return YES;
6371 }
6472 else {
6573 // エラーで使われなくなったので解放する
@@ -66,11 +74,14 @@
6674 free(inflatedBytes);
6775 inflatedBytes = NULL;
6876 const char *err = zError(ret);
69- NSString *errstr = [NSString stringWithCString:err
70- length:strlen(err)];
71- *error = [MMAux createErrorFromString:errstr
72- domain:kMMZlibErrorDomain];
73- return nil;
77+ NSString *errstr = [NSString stringWithUTF8String:err];
78+ if (error != nil) {
79+ if (*error != nil)
80+ [*error release];
81+ *error = [MMAux createErrorFromString:errstr
82+ domain:kMMZlibErrorDomain];
83+ }
84+ return NO;
7485 }
7586 }
7687
@@ -94,27 +105,6 @@
94105 userInfo:userInfo];
95106 }
96107
97-#if !MM_PLATHOME_IPHONE
98-//
99-// このコードは下記URLを参考にした
100-// http://www.cocoadev.com/index.pl?CGImageRef
101-//
102-+ (NSImage *)createNSImageFromCGImage:(CGImageRef)image
103-{
104- size_t height = CGImageGetHeight(image);
105- size_t width = CGImageGetWidth(image);
106- NSRect rect = NSMakeRect(0.0, 0.0, width, height);
107- // autoreleaseは外してある。外さなかったことが原因でreleaseが二重に入ってしまい、メモリ保護違反になった
108- NSImage *newImage = [[NSImage alloc] initWithSize:rect.size];
109- [newImage setFlipped:YES];
110- [newImage lockFocus];
111- CGContextRef graphics = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
112- CGContextDrawImage(graphics, *(CGRect*)&rect, image);
113- [newImage unlockFocus];
114- return newImage;
115-}
116-#endif /* MM_PLATHOME_IPHONE */
117-
118108 + (NSError *)errorFromException:(NSException *)exception
119109 domain:(NSString *)domain
120110 {
--- trunk/cocoa/Classes/MMAux.h (revision 68)
+++ trunk/cocoa/Classes/MMAux.h (revision 69)
@@ -54,15 +54,13 @@
5454
5555 @interface MMAux : NSObject {
5656 }
57-+ (NSData *)inflateZlibCompressedFromData:(NSData *)deflatedData
58- error:(NSError **)error;
57++ (BOOL)inflateZlibFromDeflatedData:(NSData *)deflatedData
58+ inflatedData:(NSData **)inflatedData
59+ error:(NSError **)error;
5960 + (NSDictionary *)deserializeObjectFromJsonData:(NSString *)jsonData
6061 error:(NSError **)error;
6162 + (NSError *)createErrorFromString:(NSString *)errstr
6263 domain:(NSString *)domain;
63-#if !MM_PLATHOME_IPHONE
64-+ (NSImage *)createNSImageFromCGImage:(CGImageRef)image;
65-#endif
6664 + (NSError *)errorFromException:(NSException *)exception
6765 domain:(NSString *)domain;
6866 + (void)colorFromHexValue:(uint32_t)color
Show on old repository browser