1 /* UIKit Tools - command-line utilities for UIKit
2 * Copyright (C) 2008-2012 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #import <CoreFoundation/CFData.h>
41 #import <CoreGraphics/CGImage.h>
42 #import <Foundation/Foundation.h>
43 #import <UIKit/UIImage-UIImageInternal.h>
48 #define _trace() NSLog(@"_trace():%s:%u", __FILE__, __LINE__)
50 extern "C" CGImageRef UIGetScreenImage();
51 extern "C" NSData *UIImagePNGRepresentation(UIImage *);
52 extern "C" NSData *UIImageJPEGRepresentation(UIImage *);
54 int main(int argc, char *argv[]) {
55 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
57 CGImageRef screen = UIGetScreenImage();
58 UIImage *image = [UIImage imageWithCGImage:screen];
59 NSData *png = UIImagePNGRepresentation(image);
62 NSString *dcim = [NSString stringWithFormat:@"%@/Media/DCIM", NSHomeDirectory()];
63 NSString *apple = [NSString stringWithFormat:@"%@/999APPLE", dcim];
65 NSFileManager *manager = [NSFileManager defaultManager];
68 if (![manager fileExistsAtPath:apple isDirectory:&directory]) {
70 createDirectoryAtPath:apple
71 withIntermediateDirectories:YES
75 NSLog(@"%@ does not exist and cannot be created", apple);
78 } else if (!directory) {
79 NSLog(@"%@ exists and is not a directory", apple);
85 for (unsigned i(0); i != 100 && !taken; ++i) {
86 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
88 for (unsigned j(0); j != 100 && !taken; ++j) {
89 unsigned index = i * 100 + j;
93 NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index];
95 if (![manager fileExistsAtPath:file isDirectory:&directory]) {
96 [png writeToFile:file atomically:YES];
98 NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index];
99 UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1];
100 NSData *jpeg = UIImageJPEGRepresentation(thumb);
101 [jpeg writeToFile:thm atomically:YES];
103 NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index];
104 [jpeg writeToFile:poster atomically:YES];
106 CFNotificationCenterPostNotification(
107 CFNotificationCenterGetDarwinNotifyCenter(),
108 (CFStringRef) @"PictureWasTakenNotification",
114 NSLog(@"DONE: %@", file);
122 NSLog(@"%@ is too full", apple);