diff options
author | Hubert Figuière <hub@figuiere.net> | 2012-05-23 23:59:51 -0700 |
---|---|---|
committer | Hubert Figuière <hub@figuiere.net> | 2012-05-24 00:20:54 -0700 |
commit | 721415dd11bf60fa32c6a39e82dbb0faa2676341 (patch) | |
tree | 4cc576e3189e75a3aacf91e3d568e830a7751566 /demo | |
parent | fb1261e73466108e063c94301cd41d0718709f8f (diff) |
Reorg / reindent thumbc demo.
Diffstat (limited to 'demo')
-rw-r--r-- | demo/thumbc.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/demo/thumbc.c b/demo/thumbc.c index 288382a..63febc1 100644 --- a/demo/thumbc.c +++ b/demo/thumbc.c @@ -33,6 +33,15 @@ main(int argc, char **argv) int thumb_size = 160; int opt; ORThumbnailRef thumbnail = NULL; + + void *thumbnailData; + or_data_type thumbnailFormat; + size_t dataSize; + size_t writtenSize; + FILE *output; + uint32_t x, y; + or_error err; + const char* outfname = "thumb.raw"; while ((opt = getopt(argc, argv, "s:")) != -1) { switch(opt) { @@ -53,65 +62,56 @@ main(int argc, char **argv) or_debug_set_level(DEBUG2); - if(filename && *filename) + if(!filename || !*filename) { - void *thumbnailData; - or_data_type thumbnailFormat; - size_t dataSize; - size_t writtenSize; - FILE *output; - uint32_t x, y; - or_error err; - - err = or_get_extract_thumbnail(filename, - thumb_size, &thumbnail); - - if (err == OR_ERROR_NONE) { - const char* outfname = "thumb.raw"; - thumbnailFormat = or_thumbnail_format(thumbnail); - dataSize = or_thumbnail_data_size(thumbnail); - or_thumbnail_dimensions(thumbnail, &x, &y); - - switch (thumbnailFormat) { - case OR_DATA_TYPE_JPEG: - printf("Thumbnail in JPEG format, thumb size is %u, %u\n", x, y); - outfname = "thumb.jpg"; - break; - case OR_DATA_TYPE_PIXMAP_8RGB: - printf("Thumbnail in 8RGB format, thumb size is %u, %u\n", x, y); - outfname = "thumb.ppm"; - break; - default: - printf("Thumbnail in UNKNOWN format, thumb size is %u, %u\n", x, y); - break; - } - output = fopen(outfname, "wb"); - thumbnailData = or_thumbnail_data(thumbnail); - if(thumbnailFormat == OR_DATA_TYPE_PIXMAP_8RGB) { - fprintf(output, "P6\n"); - fprintf(output, "%u\n%u\n", x, y); - fprintf(output, "%d\n", 255); - } - writtenSize = fwrite(thumbnailData, dataSize, 1, output); - if(writtenSize != dataSize) { - printf("short write\n"); - } - fclose(output); - printf("output %ld bytes in '%s'\n", dataSize, outfname); - err = or_thumbnail_release(thumbnail); - if (err != OR_ERROR_NONE) - { - printf("error release %d\n", err); - } - } - else { - printf("error %d\n", err); - } - } - else { printf("No input file name\n"); + return 1; + } + + err = or_get_extract_thumbnail(filename, + thumb_size, &thumbnail); + + if (err != OR_ERROR_NONE) { + printf("error %d\n", err); + return 1; } + + thumbnailFormat = or_thumbnail_format(thumbnail); + dataSize = or_thumbnail_data_size(thumbnail); + or_thumbnail_dimensions(thumbnail, &x, &y); + switch (thumbnailFormat) { + case OR_DATA_TYPE_JPEG: + printf("Thumbnail in JPEG format, thumb size is %u, %u\n", x, y); + outfname = "thumb.jpg"; + break; + case OR_DATA_TYPE_PIXMAP_8RGB: + printf("Thumbnail in 8RGB format, thumb size is %u, %u\n", x, y); + outfname = "thumb.ppm"; + break; + default: + printf("Thumbnail in UNKNOWN format, thumb size is %u, %u\n", x, y); + break; + } + output = fopen(outfname, "wb"); + thumbnailData = or_thumbnail_data(thumbnail); + if(thumbnailFormat == OR_DATA_TYPE_PIXMAP_8RGB) { + fprintf(output, "P6\n"); + fprintf(output, "%u\n%u\n", x, y); + fprintf(output, "%d\n", 255); + } + writtenSize = fwrite(thumbnailData, dataSize, 1, output); + if(writtenSize != dataSize) { + printf("short write\n"); + } + fclose(output); + printf("output %ld bytes in '%s'\n", dataSize, outfname); + err = or_thumbnail_release(thumbnail); + if (err != OR_ERROR_NONE) + { + printf("error release %d\n", err); + } + return 0; } /* |