X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fimage-tool.c;h=3e40bcb95b5c2464f6fa5ab0f33bab1410148f7d;hb=4142115bf20293bef998d1f683ac7ce3008178fb;hp=831c65773cdc71e8c5382a0c8438ee943d16facc;hpb=cc158370cbaee83cafb5965f20dc2df848a4faef;p=libucw.git diff --git a/images/image-tool.c b/images/image-tool.c index 831c6577..3e40bcb9 100644 --- a/images/image-tool.c +++ b/images/image-tool.c @@ -1,5 +1,5 @@ /* - * Simple image manupulation utility + * Image Library -- Simple image manipulation utility * * (c) 2006 Pavel Charvat * @@ -34,11 +34,12 @@ Usage: image-tool [options] infile [outfile]\n\ -g --background background color (hexadecimal RRGGBB)\n\ -G --default-background background applied only if the image contains no background info (RRGGBB, default=FFFFFF)\n\ -a --remove-alpha remove alpha channel\n\ -", stderr); +-e --exif reads Exif data\n" +, stderr); exit(1); } -static char *shortopts = "qf:F:s:b:c:Q:g:G:a"; +static char *shortopts = "qf:F:s:b:c:Q:g:G:ae"; static struct option longopts[] = { { "quiet", 0, 0, 'q' }, @@ -51,9 +52,10 @@ static struct option longopts[] = { "background", 0, 0, 'g' }, { "default-background", 0, 0, 'G' }, { "remove-alpha", 0, 0, 'a' }, + { "exif", 0, 0, 'e' }, { NULL, 0, 0, 0 } }; - + static uns verbose = 1; static byte *input_file_name; static enum image_format input_format; @@ -67,13 +69,14 @@ static uns jpeg_quality; static struct color background_color; static struct color default_background_color; static uns remove_alpha; +static uns exif; static void parse_color(struct color *color, byte *s) { if (strlen(s) != 6) usage(); - s = 0; + errno = 0; char *end; long int v = strtol(s, &end, 16); if (errno || *end || v < 0) @@ -142,6 +145,9 @@ main(int argc, char **argv) case 'a': remove_alpha++; break; + case 'e': + exif++; + break; default: usage(); } @@ -151,18 +157,21 @@ main(int argc, char **argv) input_file_name = argv[optind++]; if (argc > optind) output_file_name = argv[optind]; - -#define TRY(x) do{ if (!(x)) die("Error: %s", it.err_msg); }while(0) + +#define TRY(x) do{ if (!(x)) exit(1); }while(0) MSG("Initializing image library"); - struct image_thread it; + struct image_context ctx; struct image_io io; - image_thread_init(&it); - if (!image_io_init(&it, &io)) - die("Cannot initialize image I/O (%s)", it.err_msg); + image_context_init(&ctx); + ctx.tracing_level = ~0U; + if (!image_io_init(&ctx, &io)) + die("Cannot initialize image I/O"); MSG("Reading %s", input_file_name); io.fastbuf = bopen(input_file_name, O_RDONLY, 1 << 18); io.format = input_format ? : image_file_name_to_format(input_file_name); + if (exif) + io.flags |= IMAGE_IO_WANT_EXIF; TRY(image_io_read_header(&io)); if (!output_file_name) { @@ -177,6 +186,8 @@ main(int argc, char **argv) color_put_rgb(rgb, &io.background_color); printf("Background: %02x%02x%02x\n", rgb[0], rgb[1], rgb[2]); } + if (io.exif_size) + printf("ExifSize: %u\n", io.exif_size); } else { @@ -214,9 +225,9 @@ main(int argc, char **argv) TRY(image_io_write(&io)); bclose(io.fastbuf); } - + image_io_cleanup(&io); - image_thread_cleanup(&it); + image_context_cleanup(&ctx); MSG("Done."); return 0; }