/* * The Npic library and tools * * Copyright (C) 2003 Edouard Thiel * * This program is free software under the terms of the * GNU Lesser General Public License (LGPL) version 2.1. */ /* * npic-conv.c - 13/11/2008 * */ #include void ShowUsage () { printf ( "npic-conv - Convert image file in other file format from its extension.\n" "Usage:\n" " npic-conv -h | -help | --help : print help\n" " npic-conv in1 out1 [-c|-l|-d] : convert in1 to out1\n" "\n" "-c|-l|-d : convert pixel type to char, long, double\n" "in1, out1 : image in " NPIC_KNOWN_IMAGE_EXT " format\n" ); } void ArgcExit (int argc, int n) { if (argc < n) { fprintf (stderr, "ERROR: %d argument(s) missing, " "type \"npic-conv -h\" to get help.\n", n-argc); exit (1); } } int main (int argc, char *argv[]) { char *in1, *out1, *conv = ""; Npic_image *np1; ArgcExit (argc, 2); if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "-help") == 0 || strcmp (argv[1], "--help") == 0) { ShowUsage (); exit (0); } ArgcExit (argc, 2+1); in1 = argv[1]; out1 = argv[2]; if (argc > 3) conv = argv[3]; printf ("Loading \"%s\"\n", in1); np1 = NpicReadImage (in1); if (np1 == NULL) exit (1); if (strcmp (conv, "-c") == 0) NpicConvertImage_c (np1); else if (strcmp (conv, "-l") == 0) NpicConvertImage_l (np1); else if (strcmp (conv, "-d") == 0) NpicConvertImage_d (np1); else if (strcmp (conv, "") != 0) { fprintf (stderr, "ERROR: argument \"%s\" unexpected\n", conv); exit (1); } printf ("Saving \"%s\"\n", out1); if (NpicWriteImage (np1, out1) != NPIC_SUCCESS) exit(1); NpicDestroyImage (np1); exit (0); }