00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "stdinc.h"
00013
00014
00015
00016 void make_header(int m, int n, FILE* output_file, char* colormap_file);
00017
00018
00019
00020 #define PAD_ROW if (pad_row && (++nchar)%m_orig == 0) putchar((unsigned char)0)
00021 #define USAGE \
00022 "Usage: make_image [-c] [-f] [-i] [-m color-map] [-s sizex [sizey]]\n"
00023
00024 main(int argc, char** argv)
00025 {
00026
00027
00028 int m = 0, n = 0;
00029 int which = 2;
00030 char* colormap = NULL;
00031
00032 int pad_row = 0, pad_col = 0;
00033 int nchar = 0;
00034
00035 int m_orig;
00036 int i;
00037 float f;
00038
00039
00040
00041 for (i = 0; i < argc; i++)
00042 if (argv[i][0] == '-') {
00043 switch (argv[i][1]) {
00044 case 'c': which = 0;
00045 break;
00046 case 'f': which = 2;
00047 break;
00048 case 'i': which = 1;
00049 break;
00050 case 'm': colormap = argv[++i];
00051 break;
00052 case 's': m = atoi(argv[++i]);
00053 if (i+1 < argc && argv[i+1][0] != '-')
00054 n = atoi(argv[++i]);
00055 else
00056 n = m;
00057 break;
00058
00059 default: fprintf(stderr, USAGE);
00060 exit(1);
00061
00062 }
00063 }
00064
00065 if (m <= 0 || n <= 0) {
00066 fprintf(stderr, "Must specify image dimensions.\n");
00067 exit(1);
00068 }
00069
00070
00071
00072
00073 if (m%2 != 0 || n%2 != 0) {
00074 m_orig = m;
00075 if (m%2 != 0) {
00076 pad_row = 1;
00077 m++;
00078 }
00079 if (n%2 != 0) {
00080 pad_col = 1;
00081 n++;
00082 }
00083 fprintf(stderr,
00084 "Image dimensions must be even. Padding data to %dx%d\n",
00085 m, n);
00086 }
00087
00088 make_header(m, n, stdout, colormap);
00089
00090 if (which == 0)
00091 while ((i = getchar()) != EOF) {
00092 putchar((unsigned char)i);
00093 PAD_ROW;
00094 }
00095 else if (which == 1)
00096 while (scanf("%d", &i) != EOF) {
00097 putchar((unsigned char)i);
00098 PAD_ROW;
00099 }
00100 else
00101 while (scanf("%f", &f) != EOF) {
00102 putchar((unsigned char)f);
00103 PAD_ROW;
00104 }
00105
00106 if (pad_col)
00107 for (i = 0; i < m; i++) putchar((unsigned char)0);
00108 }