swfから画像を抽出するコマンドラインアプリケーション
Revision | 6820c3c720c9ed8b35023fd9f9532c727b5fabbd (tree) |
---|---|
Time | 2018-05-22 22:59:06 |
Author | masakih <masakih@user...> |
Commiter | masakih |
不要な部分を削除。書式をそろえた
@@ -51,7 +51,6 @@ | ||
51 | 51 | F490569220B0512C00CF637D /* Information.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Information.m; sourceTree = "<group>"; }; |
52 | 52 | F490569420B0568F00CF637D /* ImageStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageStore.h; sourceTree = "<group>"; }; |
53 | 53 | F490569520B0568F00CF637D /* ImageStore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImageStore.m; sourceTree = "<group>"; }; |
54 | - F490569720B0584600CF637D /* KanColleGraphicDivider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KanColleGraphicDivider.h; sourceTree = "<group>"; }; | |
55 | 54 | F490569820B059B800CF637D /* BitLossless2ColorTableDecoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BitLossless2ColorTableDecoder.h; sourceTree = "<group>"; }; |
56 | 55 | F490569920B059B800CF637D /* BitLossless2ColorTableDecoder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BitLossless2ColorTableDecoder.m; sourceTree = "<group>"; }; |
57 | 56 | F490569B20B05B9400CF637D /* BitsJPEG3Decoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BitsJPEG3Decoder.h; sourceTree = "<group>"; }; |
@@ -97,7 +96,6 @@ | ||
97 | 96 | isa = PBXGroup; |
98 | 97 | children = ( |
99 | 98 | F486709E20B30A3D00DB9579 /* mics */, |
100 | - F490569720B0584600CF637D /* KanColleGraphicDivider.h */, | |
101 | 99 | F44C14C11D84F27500ADE497 /* SWFStructure.h */, |
102 | 100 | F44C14BA1D84F07300ADE497 /* main.m */, |
103 | 101 | F486709C20B30A2300DB9579 /* SWFParser */, |
@@ -8,8 +8,7 @@ | ||
8 | 8 | |
9 | 9 | #import "BitLossless2ColorTableDecoder.h" |
10 | 10 | |
11 | -#include "KanColleGraphicDivider.h" | |
12 | -#import "Information.h" | |
11 | +#include "SWFStructure.h" | |
13 | 12 | #import "ImageDataConverter.h" |
14 | 13 | |
15 | 14 | #import "HMZlibData.h" |
@@ -71,13 +70,16 @@ | ||
71 | 70 | // ARGBカラーマップからARGBビットマップを作成 |
72 | 71 | UInt32 *imageDataP = calloc(4, data->width * data->height); |
73 | 72 | if(!imageDataP) { |
73 | + | |
74 | 74 | fprintf(stderr, "Can not allocate enough memory.\n"); |
75 | 75 | return nil; |
76 | 76 | } |
77 | 77 | |
78 | 78 | UInt32 *imageDataPixel = imageDataP; |
79 | 79 | for(UInt16 h = 0; h < data->height; h++) { |
80 | + | |
80 | 81 | for(UInt16 w = 0; w < data->width; w++) { |
82 | + | |
81 | 83 | *imageDataPixel++ = mapP[*colorIndexP++]; |
82 | 84 | } |
83 | 85 | colorIndexP += skipBytes; |
@@ -52,6 +52,7 @@ | ||
52 | 52 | |
53 | 53 | NSImage *pict = [[NSImage alloc] initWithData:contentData]; |
54 | 54 | if(!pict) { |
55 | + | |
55 | 56 | fprintf(stderr, "Can not create image from data.\n"); |
56 | 57 | return nil; |
57 | 58 | } |
@@ -8,7 +8,7 @@ | ||
8 | 8 | |
9 | 9 | #import "BitsJPEG3Decoder.h" |
10 | 10 | |
11 | -#include "KanColleGraphicDivider.h" | |
11 | +#include "SWFStructure.h" | |
12 | 12 | #import "ImageDataConverter.h" |
13 | 13 | |
14 | 14 | #import "BitsDecoder.h" |
@@ -75,6 +75,7 @@ | ||
75 | 75 | NSData *pic = [NSData dataWithBytes:p length:imageSize]; |
76 | 76 | NSImage *pict = [[NSImage alloc] initWithData:pic]; |
77 | 77 | if(!pict) { |
78 | + | |
78 | 79 | fprintf(stderr, "Can not create image from data.\n"); |
79 | 80 | return nil; |
80 | 81 | } |
@@ -97,6 +98,7 @@ | ||
97 | 98 | bytesPerRow:size.width |
98 | 99 | bitsPerPixel:0]; |
99 | 100 | if(!alphaImageRef) { |
101 | + | |
100 | 102 | fprintf(stderr, "Can not create alpha image from data.\n"); |
101 | 103 | return nil; |
102 | 104 | } |
@@ -8,7 +8,7 @@ | ||
8 | 8 | |
9 | 9 | #import "BitsLossless2Decoder.h" |
10 | 10 | |
11 | -#include "KanColleGraphicDivider.h" | |
11 | +#include "SWFStructure.h" | |
12 | 12 | #import "ImageDataConverter.h" |
13 | 13 | |
14 | 14 | #import "HMZlibData.h" |
@@ -12,11 +12,13 @@ NSData *convertToPNGImagaData(id<ImageConvertible> image) { | ||
12 | 12 | |
13 | 13 | NSData *tiffData = [image TIFFRepresentation]; |
14 | 14 | if(!tiffData) { |
15 | + | |
15 | 16 | fprintf(stderr, "Can not create TIFF representation.\n"); |
16 | 17 | return nil; |
17 | 18 | } |
18 | 19 | |
19 | 20 | NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:tiffData]; |
21 | + | |
20 | 22 | return [rep representationUsingType:NSPNGFileType |
21 | 23 | properties:@{}]; |
22 | 24 | } |
@@ -6,7 +6,6 @@ | ||
6 | 6 | // Copyright © 2018年 Hori,Masaki. All rights reserved. |
7 | 7 | // |
8 | 8 | |
9 | -#include "KanColleGraphicDivider.h" | |
10 | 9 | #import "ImageStore.h" |
11 | 10 | |
12 | 11 | @interface ImageStore() |
@@ -8,7 +8,6 @@ | ||
8 | 8 | |
9 | 9 | #import "Information.h" |
10 | 10 | |
11 | - | |
12 | 11 | @interface Information() |
13 | 12 | |
14 | 13 | @property (copy, readwrite) NSURL *originalURL; |
@@ -1,21 +0,0 @@ | ||
1 | -// | |
2 | -// KanColleGraphicDivider.h | |
3 | -// KanColleGraphicDivider | |
4 | -// | |
5 | -// Created by Hori,Masaki on 2018/05/19. | |
6 | -// Copyright © 2018年 Hori,Masaki. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#ifndef KanColleGraphicDivider_h | |
10 | -#define KanColleGraphicDivider_h | |
11 | - | |
12 | -#include "SWFStructure.h" | |
13 | - | |
14 | -#if 0 | |
15 | -#define printLog(...) printLogF( __VA_ARGS__) | |
16 | -void printLogF(const char *fmt, ...); | |
17 | -#else | |
18 | -#define printLog(...) | |
19 | -#endif | |
20 | - | |
21 | -#endif /* KanColleGraphicDivider_h */ |
@@ -10,27 +10,9 @@ | ||
10 | 10 | |
11 | 11 | #include <getopt.h> |
12 | 12 | |
13 | -#include "KanColleGraphicDivider.h" | |
14 | - | |
15 | 13 | #import "Information.h" |
16 | 14 | #import "SWFDecodeProcessor.h" |
17 | 15 | |
18 | -void printLogF(const char *fmt, ...) { | |
19 | - va_list ap; | |
20 | - va_start(ap, fmt); | |
21 | - vfprintf(stderr, fmt, ap); | |
22 | - va_end(ap); | |
23 | -} | |
24 | - | |
25 | -void printHex(const unsigned char *p) { | |
26 | - for(int i=0;i<1;i++) { | |
27 | - for(int j=0;j<16;j++) { | |
28 | - printLog("%02x ", *p++); | |
29 | - } | |
30 | - printLog("\n"); | |
31 | - } | |
32 | -} | |
33 | - | |
34 | 16 | const char *toolName; |
35 | 17 | const char *versionString = "1.0"; |
36 | 18 |
@@ -39,8 +21,8 @@ const char *toolNameStr(const char *argv0) | ||
39 | 21 | return [[[NSString stringWithFormat:@"%s", argv0] lastPathComponent] fileSystemRepresentation]; |
40 | 22 | } |
41 | 23 | |
42 | -static void usage(int exitVal, FILE *fp) | |
43 | -{ | |
24 | +static void usage(int exitVal, FILE *fp) { | |
25 | + | |
44 | 26 | fprintf(fp, "Usage: %s [OPTIONS] input-swf-file\n", toolName); |
45 | 27 | |
46 | 28 | fprintf(fp, "\n"); |
@@ -56,8 +38,8 @@ static void usage(int exitVal, FILE *fp) | ||
56 | 38 | |
57 | 39 | exit(exitVal); |
58 | 40 | } |
59 | -static void version() | |
60 | -{ | |
41 | +static void version() { | |
42 | + | |
61 | 43 | printf("KanColleGraphicDivider %s\n", versionString); |
62 | 44 | exit(EXIT_SUCCESS); |
63 | 45 | } |
@@ -85,6 +67,7 @@ int main(int argc, char * const *argv) { | ||
85 | 67 | }; |
86 | 68 | |
87 | 69 | while((opt = getopt_long(argc, argv, SHORTOPTS, longopts, NULL)) != -1) { |
70 | + | |
88 | 71 | switch(opt) { |
89 | 72 | case 'o': |
90 | 73 | oFilename = optarg; |
@@ -105,39 +88,46 @@ int main(int argc, char * const *argv) { | ||
105 | 88 | } |
106 | 89 | |
107 | 90 | if(optind >= argc) { |
91 | + | |
108 | 92 | usage(EXIT_FAILURE, stderr); |
109 | 93 | } |
110 | 94 | |
111 | 95 | if(oFilename) { |
96 | + | |
112 | 97 | outputDir = [[NSString alloc] initWithUTF8String:oFilename]; |
113 | 98 | if( outputDir.length == 0 ) { |
99 | + | |
114 | 100 | fprintf(stderr, "Output directory:%s can not convert file represendation.\n", oFilename); |
115 | 101 | exit(EXIT_FAILURE); |
116 | 102 | } |
117 | 103 | NSFileManager *fm = [NSFileManager defaultManager]; |
118 | 104 | BOOL isDir = NO; |
119 | 105 | if(![fm fileExistsAtPath:outputDir isDirectory:&isDir] || !isDir) { |
106 | + | |
120 | 107 | fprintf(stderr, "Output directory:%s is not found or not directory.\n", outputDir.UTF8String); |
121 | 108 | exit(EXIT_FAILURE); |
122 | 109 | } |
110 | + | |
123 | 111 | } else { |
112 | + | |
124 | 113 | NSFileManager *fm = [NSFileManager defaultManager]; |
125 | 114 | outputDir = fm.currentDirectoryPath; |
126 | 115 | } |
127 | 116 | |
128 | 117 | if(charactorid) { |
118 | + | |
129 | 119 | NSString *charactoridsString = [[NSString alloc] initWithUTF8String:charactorid]; |
130 | 120 | NSArray *ids = [charactoridsString componentsSeparatedByString:@","]; |
131 | 121 | if(ids.count != 0) { |
132 | - charactorIds = ids; | |
133 | 122 | |
134 | - printLog("CaractorIDs is %s\n", [NSString stringWithFormat:@"%@", ids].fileSystemRepresentation); | |
123 | + charactorIds = ids; | |
135 | 124 | } |
136 | 125 | } |
137 | 126 | |
138 | 127 | dispatch_group_t group = dispatch_group_create(); |
139 | 128 | dispatch_queue_t queue = dispatch_queue_create("Create image", DISPATCH_QUEUE_CONCURRENT); |
140 | 129 | for(int filePos = optind; filePos < argc; filePos++) { |
130 | + | |
141 | 131 | const char *filename = argv[filePos]; |
142 | 132 | Information *info = [Information new]; |
143 | 133 | info.outputDir = outputDir; |
@@ -154,4 +144,3 @@ int main(int argc, char * const *argv) { | ||
154 | 144 | } |
155 | 145 | return 0; |
156 | 146 | } |
157 | - |