絵文字の吸出し(3)

絵文字の吸出しで全ソースを上げておきます。(ファイルはすべてUTF8にする事)

<EmojiGet>
│  EmojiGet-Info.plist
│  main.mm
│
├─<Classes>
│  │  EmojiGetAppDelegate.h
│  │  EmojiGetAppDelegate.mm
│  │
│  └─<chlibs>
│      │  chlibs.h
│      │  types.h
│      │
│      └─<ui>
│              ImageTga.h
│              ImageTga.mm
│
└─<EmojiGet.xcodeproj>
        project.pbxproj
main.mm
#import <UIKit/UIKit.h>
 
int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"EmojiGetAppDelegate");
    [pool release];
    return retVal;
}
EmojiGetAppDelegate.h
#import <UIKit/UIKit.h>
 
@interface EmojiGetAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
 
@interface EmojiView : UIView {
}
@end
EmojiGetAppDelegate.mm
#import "EmojiGetAppDelegate.h"
#import "chlibs/chlibs.h"
//*****************************************************************************
//      絵文字を一画面分描画
//*****************************************************************************
void DrawEmoji(const int page) {
    const static u16 CodeList[][2] = {          // 絵文字のコード
        {0xe001,0xe05a},
        {0xe101,0xe15a},
        {0xe201,0xe253},
        {0xe301,0xe34d},
        {0xe401,0xe44c},
        {0xe501,0xe537},
    } ;
 
    CGRect ViewRect = [[UIScreen mainScreen] bounds] ;
    CGContextRef ctx = UIGraphicsGetCurrentContext() ;
    BOOL HighReso = [UIScreen mainScreen].scale == 1.f ? NO : YES ;
 
    if(!HighReso) {
        ViewRect.size.width  /= 2.f ;
        ViewRect.size.height /= 2.f ;
    }
 
    CGContextSetRGBFillColor(ctx,0.f,0.f,0.f,0.f) ;
    CGContextFillRect(ctx,ViewRect) ;
    CGAffineTransform tr = HighReso ?
        CGAffineTransformMakeScale(2.f,2.f) : CGAffineTransformMakeScale(1.f,1.f) ;
    CGContextSaveGState(ctx) ;
    CGContextConcatCTM(ctx,tr) ;
 
    for(u16 code = CodeList[page][0] ; code <= CodeList[page][1] ; ++ code) {
        char str[8] ;
        sprintf(str,"%c%c",code & 0xff,code >> 8) ;
        float x = ((code & 0xff) % 8) * 20.f - 1.f ;
        float y = ((code & 0xff) / 8) * 20.f - 1.f ;
 
        [
            [
                [NSString alloc]
                initWithCharactersNoCopy:(unichar *)str
                length:1
                freeWhenDone:NO
            ]
            drawAtPoint:CGPointMake(x,y)
            withFont:[UIFont systemFontOfSize:20]
        ] ;
    }
 
    CGContextRestoreGState(ctx) ;
}
//*****************************************************************************
//      絵文字を一画面分保存
//*****************************************************************************
void SaveEmoji(const int page) {
    CGRect ViewRect = [[UIScreen mainScreen] bounds] ;
    BOOL HighReso = [UIScreen mainScreen].scale == 1.f ? NO : YES ;
    if(!HighReso) {
        ViewRect.size.width  /= 2.f ;
        ViewRect.size.height /= 2.f ;
    }
 
    UIGraphicsBeginImageContext(ViewRect.size) ;
 
    DrawEmoji(page) ;                           // 絵文字を描画
 
    CGImageRef ImgRef = UIGraphicsGetImageFromCurrentImageContext().CGImage ;
    CFDataRef DataRef = CGDataProviderCopyData(CGImageGetDataProvider(ImgRef)) ;
    u08 *data = (u08 *)CFDataGetBytePtr(DataRef) ;
                                                // αが適用された RGB 値を元に戻す
    for(int j = 0 ; j < CGImageGetWidth(ImgRef) * CGImageGetHeight(ImgRef) ; ++ j) {
        u08 alpha = data[j * 4 + 3] ;
        if(alpha) {
            data[j * 4 + 0] = min(data[j * 4 + 0] * 255 / alpha,255) ;
            data[j * 4 + 1] = min(data[j * 4 + 1] * 255 / alpha,255) ;
            data[j * 4 + 2] = min(data[j * 4 + 2] * 255 / alpha,255) ;
        }
    }
 
    CGDataProviderRef DataProv = CGDataProviderCreateWithCFData(
        CFDataCreate(0,data,CFDataGetLength(DataRef))
    ) ;
 
    CGImageRef NewImg = CGImageCreate(
        CGImageGetWidth(ImgRef),
        CGImageGetHeight(ImgRef),
        CGImageGetBitsPerComponent(ImgRef),
        CGImageGetBitsPerPixel(ImgRef),
        CGImageGetBytesPerRow(ImgRef),
        CGImageGetColorSpace(ImgRef),
        CGImageGetBitmapInfo(ImgRef),
        DataProv,
        0,
        CGImageGetShouldInterpolate(ImgRef),
        CGImageGetRenderingIntent(ImgRef)
    ) ;
    UIImage *SnapShot = [[UIImage alloc] initWithCGImage:NewImg] ;
 
    char filename[260] ;                        // 画像を tga で保存
    sprintf(filename,"/Documents/emoji%d_%d.tga",HighReso ? 4 : 3,page) ;
    ImageSaveTag(filename,SnapShot) ;
    [SnapShot release] ;
 
    UIGraphicsEndImageContext() ;
}
//*****************************************************************************
//      描画時に呼ばれる
//*****************************************************************************
@implementation EmojiView
- (void)drawRect:(CGRect)rect {
    DrawEmoji(0) ;
}
@end
 
@implementation EmojiGetAppDelegate
@synthesize window;
 
#pragma mark -
#pragma mark Application lifecycle
//*****************************************************************************
//      起動時に呼ばれる
//*****************************************************************************
- (BOOL)
    application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //-------------------------------------------------------------------------
    //      ステータスバーを非表示
    //-------------------------------------------------------------------------
    [
        [UIApplication sharedApplication]
        setStatusBarHidden:YES
        withAnimation:UIStatusBarAnimationFade
    ] ;
    //-------------------------------------------------------------------------
    //      ウィンドウの作成
    //-------------------------------------------------------------------------
    window = [
        [UIWindow alloc]
        initWithFrame:[[UIScreen mainScreen] bounds]
    ] ;
    //-------------------------------------------------------------------------
    //      ビューコントローラとビューの作成
    //-------------------------------------------------------------------------
    {
        UIViewController *ViewCtrl = [UIViewController alloc] ;
        [window addSubview:ViewCtrl.view] ;
 
        UIView *view = [
            [EmojiView alloc]
            initWithFrame:[[UIScreen mainScreen] bounds]
        ] ;
        [ViewCtrl.view addSubview:view] ;
 
        [ViewCtrl release] ;
        [view release] ;
    }
 
    [window makeKeyAndVisible] ;
 
#if 1
    for(int i = 0 ; i < 6 ; ++ i) SaveEmoji(i) ;
    exit(0) ;
#endif
 
    return YES ;
}
 
- (void)dealloc {
    [window release];
    [super dealloc];
}
 
@end
iphone/絵文字の吸出し_3.txt · 最終更新: 2018/03/18 09:56 (外部編集)
 
特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki