diff options
| author | 2017-06-18 04:10:57 +0200 | |
|---|---|---|
| committer | 2017-06-18 04:10:57 +0200 | |
| commit | 835d84b678d23f92622445f5bf142c2bf52a7e9b (patch) | |
| tree | 42f0d40b3ebf985fe2a6d7e76829c9c0b6a95c5a | |
| parent | 53fede06af98e24e26939127fcc71c6acfaf4c12 (diff) | |
| download | libimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.gz libimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.bz2 | |
idevicescreenshot: Detect screenshot image format to determine file extension
| -rw-r--r-- | tools/idevicescreenshot.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c index da229e2..74acdf6 100644 --- a/tools/idevicescreenshot.c +++ b/tools/idevicescreenshot.c | |||
| @@ -99,12 +99,22 @@ int main(int argc, char **argv) | |||
| 99 | } else { | 99 | } else { |
| 100 | char *imgdata = NULL; | 100 | char *imgdata = NULL; |
| 101 | uint64_t imgsize = 0; | 101 | uint64_t imgsize = 0; |
| 102 | if (!filename) { | ||
| 103 | time_t now = time(NULL); | ||
| 104 | filename = (char*)malloc(36); | ||
| 105 | strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); | ||
| 106 | } | ||
| 107 | if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { | 102 | if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { |
| 103 | if (!filename) { | ||
| 104 | const char *fileext = NULL; | ||
| 105 | if (memcmp(imgdata, "\x89PNG", 4) == 0) { | ||
| 106 | fileext = ".png"; | ||
| 107 | } else if (memcmp(imgdata, "MM\x00*", 4) == 0) { | ||
| 108 | fileext = ".tiff"; | ||
| 109 | } else { | ||
| 110 | printf("WARNING: screenshot data has unexpected image format.\n"); | ||
| 111 | fileext = ".dat"; | ||
| 112 | } | ||
| 113 | time_t now = time(NULL); | ||
| 114 | filename = (char*)malloc(36); | ||
| 115 | size_t pos = strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S", gmtime(&now)); | ||
| 116 | sprintf(filename+pos, "%s", fileext); | ||
| 117 | } | ||
| 108 | FILE *f = fopen(filename, "wb"); | 118 | FILE *f = fopen(filename, "wb"); |
| 109 | if (f) { | 119 | if (f) { |
| 110 | if (fwrite(imgdata, 1, (size_t)imgsize, f) == (size_t)imgsize) { | 120 | if (fwrite(imgdata, 1, (size_t)imgsize, f) == (size_t)imgsize) { |
