swfから画像を抽出するコマンドラインアプリケーション
Revision | 8c379159e471629de9bb5204ca7b98ee2e103dff (tree) |
---|---|
Zeit | 2016-09-16 21:44:25 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
画像の保存処理を関数にまとめた
@@ -36,6 +36,27 @@ void printHex(const unsigned char *p) { | ||
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | + | |
40 | +void saveDataWithExtension(id data, NSString *extention, int tagCount) { | |
41 | + NSString *path = [NSString stringWithFormat:@"%@-%d.%@", sOriginalName, tagCount, extention]; | |
42 | + path = [sCurrentDir stringByAppendingPathComponent:path]; | |
43 | + NSURL *url = [NSURL fileURLWithPath:path]; | |
44 | + [data writeToURL:url atomically:YES]; | |
45 | +} | |
46 | + | |
47 | +void saveImageAsPNG(id image, int tagCount) { | |
48 | + NSData *tiffData = [image TIFFRepresentation]; | |
49 | + if(!tiffData) { | |
50 | + fprintf(stderr, "Can not create masked image.\n"); | |
51 | + return; | |
52 | + } | |
53 | + | |
54 | + NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:tiffData]; | |
55 | + NSData *imageData = [rep representationUsingType:NSPNGFileType | |
56 | + properties:@{}]; | |
57 | + saveDataWithExtension(imageData, @"png", tagCount); | |
58 | +} | |
59 | + | |
39 | 60 | void storeImage(const unsigned char *p, UInt32 length, int tagCount) { |
40 | 61 | printLog("#### TYPE IS PICTURE ####\n\n"); |
41 | 62 | if(length == 0) return; |
@@ -47,10 +68,7 @@ void storeImage(const unsigned char *p, UInt32 length, int tagCount) { | ||
47 | 68 | return; |
48 | 69 | } |
49 | 70 | |
50 | - NSString *path = [NSString stringWithFormat:@"%@-%d.jpg", sOriginalName, tagCount]; | |
51 | - path = [sCurrentDir stringByAppendingPathComponent:path]; | |
52 | - NSURL *url = [NSURL fileURLWithPath:path]; | |
53 | - [pic writeToURL:url atomically:YES]; | |
71 | + saveDataWithExtension(pic, @"jpg", tagCount); | |
54 | 72 | } |
55 | 73 | |
56 | 74 | void storeBitsJPEG3(const unsigned char *p, UInt32 length, int tagCount) { |
@@ -116,20 +134,7 @@ void storeBitsJPEG3(const unsigned char *p, UInt32 length, int tagCount) { | ||
116 | 134 | } |
117 | 135 | [image unlockFocus]; |
118 | 136 | |
119 | - // PNGで保存 | |
120 | - NSData *tiffData = image.TIFFRepresentation; | |
121 | - if(!tiffData) { | |
122 | - fprintf(stderr, "Can not create masked image.\n"); | |
123 | - return; | |
124 | - } | |
125 | - | |
126 | - NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:tiffData]; | |
127 | - NSData *imageData = [rep representationUsingType:NSPNGFileType | |
128 | - properties:@{}]; | |
129 | - NSString *path = [NSString stringWithFormat:@"%@-%d.png", sOriginalName, tagCount]; | |
130 | - path = [sCurrentDir stringByAppendingPathComponent:path]; | |
131 | - NSURL *url = [NSURL fileURLWithPath:path]; | |
132 | - [imageData writeToURL:url atomically:YES]; | |
137 | + saveImageAsPNG(image, tagCount); | |
133 | 138 | } |
134 | 139 | |
135 | 140 | void storeBitLossless2ColorTable(const unsigned char *p, UInt32 length, int tagCount) { |
@@ -190,20 +195,7 @@ void storeBitLossless2ColorTable(const unsigned char *p, UInt32 length, int tagC | ||
190 | 195 | free(imageDataP); |
191 | 196 | imageDataP = NULL; |
192 | 197 | |
193 | - // PNGで保存 | |
194 | - NSData *tiffData = imageRef.TIFFRepresentation; | |
195 | - if(!tiffData) { | |
196 | - fprintf(stderr, "Can not create tiff image.\n"); | |
197 | - return; | |
198 | - } | |
199 | - | |
200 | - NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:tiffData]; | |
201 | - NSData *pndData = [rep representationUsingType:NSPNGFileType | |
202 | - properties:@{}]; | |
203 | - NSString *path = [NSString stringWithFormat:@"%@-%d.png", sOriginalName, tagCount]; | |
204 | - path = [sCurrentDir stringByAppendingPathComponent:path]; | |
205 | - NSURL *url = [NSURL fileURLWithPath:path]; | |
206 | - [pndData writeToURL:url atomically:YES]; | |
198 | + saveImageAsPNG(imageRef, tagCount); | |
207 | 199 | } |
208 | 200 | void storeBitsLossless2(const unsigned char *p, UInt32 length, int tagCount) { |
209 | 201 | printLog("#### TYPE IS PICTURE ####\n\n"); |
@@ -235,20 +227,7 @@ void storeBitsLossless2(const unsigned char *p, UInt32 length, int tagCount) { | ||
235 | 227 | colorSpaceName:NSCalibratedRGBColorSpace |
236 | 228 | bytesPerRow:data->width * 4 |
237 | 229 | bitsPerPixel:0]; |
238 | - // PNGで保存 | |
239 | - NSData *tiffData = imageRef.TIFFRepresentation; | |
240 | - if(!tiffData) { | |
241 | - fprintf(stderr, "Can not create tiff image.\n"); | |
242 | - return; | |
243 | - } | |
244 | - | |
245 | - NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:tiffData]; | |
246 | - NSData *pndData = [rep representationUsingType:NSPNGFileType | |
247 | - properties:@{}]; | |
248 | - NSString *path = [NSString stringWithFormat:@"%@-%d.png", sOriginalName, tagCount]; | |
249 | - path = [sCurrentDir stringByAppendingPathComponent:path]; | |
250 | - NSURL *url = [NSURL fileURLWithPath:path]; | |
251 | - [pndData writeToURL:url atomically:YES]; | |
230 | + saveImageAsPNG(imageRef, tagCount); | |
252 | 231 | } |
253 | 232 | |
254 | 233 | int main(int argc, const char * argv[]) { |