swfから画像を抽出するコマンドラインアプリケーション
Révision | be19272c3d9a4cb114c9de3e940cb9bb56546c8e (tree) |
---|---|
l'heure | 2018-05-22 22:41:53 |
Auteur | masakih <masakih@user...> |
Commiter | masakih |
処理を統括するSWFDecodeProcessorを作成
@@ -10,6 +10,7 @@ | ||
10 | 10 | F44C14BB1D84F07300ADE497 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F44C14BA1D84F07300ADE497 /* main.m */; }; |
11 | 11 | F44C14C41D85083E00ADE497 /* HMZlibData.m in Sources */ = {isa = PBXBuildFile; fileRef = F44C14C31D85083E00ADE497 /* HMZlibData.m */; }; |
12 | 12 | F48670A120B43D4B00DB9579 /* ImageDataConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = F48670A020B43D4B00DB9579 /* ImageDataConverter.m */; }; |
13 | + F48670A420B4533400DB9579 /* SWFDecodeProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = F48670A320B4533400DB9579 /* SWFDecodeProcessor.m */; }; | |
13 | 14 | F490569020B050D400CF637D /* BitsLossless2Decoder.m in Sources */ = {isa = PBXBuildFile; fileRef = F490568F20B050D400CF637D /* BitsLossless2Decoder.m */; }; |
14 | 15 | F490569320B0512C00CF637D /* Information.m in Sources */ = {isa = PBXBuildFile; fileRef = F490569220B0512C00CF637D /* Information.m */; }; |
15 | 16 | F490569620B0568F00CF637D /* ImageStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F490569520B0568F00CF637D /* ImageStore.m */; }; |
@@ -41,6 +42,8 @@ | ||
41 | 42 | F44C14C31D85083E00ADE497 /* HMZlibData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMZlibData.m; sourceTree = "<group>"; }; |
42 | 43 | F486709F20B43D4B00DB9579 /* ImageDataConverter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageDataConverter.h; sourceTree = "<group>"; }; |
43 | 44 | F48670A020B43D4B00DB9579 /* ImageDataConverter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImageDataConverter.m; sourceTree = "<group>"; }; |
45 | + F48670A220B4533400DB9579 /* SWFDecodeProcessor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SWFDecodeProcessor.h; sourceTree = "<group>"; }; | |
46 | + F48670A320B4533400DB9579 /* SWFDecodeProcessor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SWFDecodeProcessor.m; sourceTree = "<group>"; }; | |
44 | 47 | F490568D20B04F5300CF637D /* ImageDecoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageDecoder.h; sourceTree = "<group>"; }; |
45 | 48 | F490568E20B050D400CF637D /* BitsLossless2Decoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BitsLossless2Decoder.h; sourceTree = "<group>"; }; |
46 | 49 | F490568F20B050D400CF637D /* BitsLossless2Decoder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BitsLossless2Decoder.m; sourceTree = "<group>"; }; |
@@ -101,6 +104,8 @@ | ||
101 | 104 | F486709D20B30A3100DB9579 /* Decoder */, |
102 | 105 | F490569120B0512C00CF637D /* Information.h */, |
103 | 106 | F490569220B0512C00CF637D /* Information.m */, |
107 | + F48670A220B4533400DB9579 /* SWFDecodeProcessor.h */, | |
108 | + F48670A320B4533400DB9579 /* SWFDecodeProcessor.m */, | |
104 | 109 | F486709F20B43D4B00DB9579 /* ImageDataConverter.h */, |
105 | 110 | F48670A020B43D4B00DB9579 /* ImageDataConverter.m */, |
106 | 111 | F490569420B0568F00CF637D /* ImageStore.h */, |
@@ -215,6 +220,7 @@ | ||
215 | 220 | F490569320B0512C00CF637D /* Information.m in Sources */, |
216 | 221 | F44C14C41D85083E00ADE497 /* HMZlibData.m in Sources */, |
217 | 222 | F49056A620B078DB00CF637D /* SwfData.m in Sources */, |
223 | + F48670A420B4533400DB9579 /* SWFDecodeProcessor.m in Sources */, | |
218 | 224 | ); |
219 | 225 | runOnlyForDeploymentPostprocessing = 0; |
220 | 226 | }; |
@@ -10,8 +10,8 @@ | ||
10 | 10 | |
11 | 11 | @interface Information: NSObject |
12 | 12 | |
13 | -@property (readonly) NSURL *originalURL; | |
14 | -@property (copy, nonatomic, readonly) NSString *originalName; | |
13 | +@property (copy, readonly) NSURL *originalURL; | |
14 | +@property (copy, readonly) NSString *originalName; | |
15 | 15 | |
16 | 16 | @property (copy) NSString *outputDir; |
17 | 17 | @property (copy) NSString *filename; |
@@ -11,9 +11,9 @@ | ||
11 | 11 | |
12 | 12 | @interface Information() |
13 | 13 | |
14 | -@property (readwrite) NSURL *originalURL; | |
14 | +@property (copy, readwrite) NSURL *originalURL; | |
15 | 15 | |
16 | -@property (copy, nonatomic, readwrite) NSString *originalName; | |
16 | +@property (copy, readwrite) NSString *originalName; | |
17 | 17 | |
18 | 18 | @end |
19 | 19 |
@@ -26,6 +26,7 @@ | ||
26 | 26 | if(self.charctorIds.count == 0) return false; |
27 | 27 | |
28 | 28 | for(NSString *charID in self.charctorIds) { |
29 | + | |
29 | 30 | if(charID.integerValue == chractorid) return false; |
30 | 31 | } |
31 | 32 | return true; |
@@ -38,6 +39,7 @@ | ||
38 | 39 | NSString *filePath = [filename copy]; |
39 | 40 | |
40 | 41 | if(![filePath hasPrefix:@"/"]) { |
42 | + | |
41 | 43 | NSFileManager *fm = [NSFileManager defaultManager]; |
42 | 44 | filePath = [fm.currentDirectoryPath stringByAppendingPathComponent:filePath]; |
43 | 45 | } |
@@ -0,0 +1,19 @@ | ||
1 | +// | |
2 | +// SWFDecodeProcessor.h | |
3 | +// KanColleGraphicDivider | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2018/05/22. | |
6 | +// Copyright © 2018年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <Foundation/Foundation.h> | |
10 | + | |
11 | +#import "Information.h" | |
12 | + | |
13 | +@interface SWFDecodeProcessor : NSObject | |
14 | + | |
15 | ++ (instancetype)swfDecodeProcessorWithInformation:(Information *)infotmation; | |
16 | + | |
17 | +- (void)process; | |
18 | + | |
19 | +@end |
@@ -0,0 +1,60 @@ | ||
1 | +// | |
2 | +// SWFDecodeProcessor.m | |
3 | +// KanColleGraphicDivider | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2018/05/22. | |
6 | +// Copyright © 2018年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "SWFDecodeProcessor.h" | |
10 | + | |
11 | +#import "SwfData.h" | |
12 | +#import "ImageStore.h" | |
13 | + | |
14 | +@interface SWFDecodeProcessor() | |
15 | + | |
16 | +@property Information *information; | |
17 | + | |
18 | +@end | |
19 | + | |
20 | +@implementation SWFDecodeProcessor | |
21 | + | |
22 | ++ (instancetype)swfDecodeProcessorWithInformation:(Information *)infotmation { | |
23 | + | |
24 | + return [[self alloc] initWithInformation:infotmation]; | |
25 | +} | |
26 | + | |
27 | +- (instancetype)initWithInformation:(Information *)information { | |
28 | + | |
29 | + self = [super init]; | |
30 | + if( self ) { | |
31 | + | |
32 | + self.information = information; | |
33 | + } | |
34 | + | |
35 | + return self; | |
36 | +} | |
37 | + | |
38 | +- (void)process { | |
39 | + | |
40 | + NSData *data = [NSData dataWithContentsOfURL:self.information.originalURL]; | |
41 | + if(!data) { | |
42 | + fprintf(stderr, "Can not open %s.\n", self.information.filename.UTF8String); | |
43 | + return; | |
44 | + } | |
45 | + | |
46 | + SwfData *swf = [SwfData dataWithData:data]; | |
47 | + SwfContent *content = swf.firstContent; | |
48 | + | |
49 | + ImageStore *store = [ImageStore imageStoreWithInformation:self.information]; | |
50 | + | |
51 | + while( content ) { | |
52 | + | |
53 | + SwfContent *aContent = content; | |
54 | + content = aContent.next; | |
55 | + | |
56 | + [store store:content.decoder]; | |
57 | + } | |
58 | +} | |
59 | + | |
60 | +@end |
@@ -13,9 +13,7 @@ | ||
13 | 13 | #include "KanColleGraphicDivider.h" |
14 | 14 | |
15 | 15 | #import "Information.h" |
16 | -#import "ImageStore.h" | |
17 | - | |
18 | -#import "SwfData.h" | |
16 | +#import "SWFDecodeProcessor.h" | |
19 | 17 | |
20 | 18 | void printLogF(const char *fmt, ...) { |
21 | 19 | va_list ap; |
@@ -64,28 +62,6 @@ static void version() | ||
64 | 62 | exit(EXIT_SUCCESS); |
65 | 63 | } |
66 | 64 | |
67 | -void extractImagesFromSWFFile(Information *info) { | |
68 | - | |
69 | - NSData *data = [NSData dataWithContentsOfURL:info.originalURL]; | |
70 | - if(!data) { | |
71 | - fprintf(stderr, "Can not open %s.\n", info.filename.UTF8String); | |
72 | - return; | |
73 | - } | |
74 | - | |
75 | - SwfData *swf = [SwfData dataWithData:data]; | |
76 | - SwfContent *content = swf.firstContent; | |
77 | - | |
78 | - ImageStore *store = [ImageStore imageStoreWithInformation:info]; | |
79 | - | |
80 | - while( content ) { | |
81 | - | |
82 | - SwfContent *aContent = content; | |
83 | - content = aContent.next; | |
84 | - | |
85 | - [store store:content.decoder]; | |
86 | - } | |
87 | -} | |
88 | - | |
89 | 65 | int main(int argc, char * const *argv) { |
90 | 66 | |
91 | 67 | NSString *outputDir = nil; |
@@ -169,7 +145,9 @@ int main(int argc, char * const *argv) { | ||
169 | 145 | info.filename = [[NSString alloc] initWithUTF8String:filename]; |
170 | 146 | |
171 | 147 | dispatch_group_async(group, queue, ^{ |
172 | - extractImagesFromSWFFile(info); | |
148 | + | |
149 | + SWFDecodeProcessor *processor = [SWFDecodeProcessor swfDecodeProcessorWithInformation:info]; | |
150 | + [processor process]; | |
173 | 151 | }); |
174 | 152 | } |
175 | 153 | dispatch_group_wait(group, DISPATCH_TIME_FOREVER); |