• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

swfから画像を抽出するコマンドラインアプリケーション


Commit MetaInfo

Revision8c379159e471629de9bb5204ca7b98ee2e103dff (tree)
Zeit2016-09-16 21:44:25
Autormasakih <masakih@user...>
Commitermasakih

Log Message

画像の保存処理を関数にまとめた

Ändern Zusammenfassung

Diff

--- a/KanColleGraphicDivider/main.m
+++ b/KanColleGraphicDivider/main.m
@@ -36,6 +36,27 @@ void printHex(const unsigned char *p) {
3636 }
3737 }
3838
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+
3960 void storeImage(const unsigned char *p, UInt32 length, int tagCount) {
4061 printLog("#### TYPE IS PICTURE ####\n\n");
4162 if(length == 0) return;
@@ -47,10 +68,7 @@ void storeImage(const unsigned char *p, UInt32 length, int tagCount) {
4768 return;
4869 }
4970
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);
5472 }
5573
5674 void storeBitsJPEG3(const unsigned char *p, UInt32 length, int tagCount) {
@@ -116,20 +134,7 @@ void storeBitsJPEG3(const unsigned char *p, UInt32 length, int tagCount) {
116134 }
117135 [image unlockFocus];
118136
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);
133138 }
134139
135140 void storeBitLossless2ColorTable(const unsigned char *p, UInt32 length, int tagCount) {
@@ -190,20 +195,7 @@ void storeBitLossless2ColorTable(const unsigned char *p, UInt32 length, int tagC
190195 free(imageDataP);
191196 imageDataP = NULL;
192197
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);
207199 }
208200 void storeBitsLossless2(const unsigned char *p, UInt32 length, int tagCount) {
209201 printLog("#### TYPE IS PICTURE ####\n\n");
@@ -235,20 +227,7 @@ void storeBitsLossless2(const unsigned char *p, UInt32 length, int tagCount) {
235227 colorSpaceName:NSCalibratedRGBColorSpace
236228 bytesPerRow:data->width * 4
237229 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);
252231 }
253232
254233 int main(int argc, const char * argv[]) {