00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00053 #include <stdio.h>
00054 #include <stdlib.h>
00055 #include <string.h>
00056
00057
00058
00059 #include "libdemosaicking.h"
00060 #include "io_tiff.h"
00061 #include "tiffio.h"
00062
00063
00079 int main(int argc, char **argv)
00080 {
00081
00082 unsigned char redx, redy;
00083 char *pattern_str = argv[3];
00084 size_t nx = 0, ny = 0;
00085 float *data_in, *data_out;
00086 float *out_ptr, *end_ptr;
00087
00088
00089 if (2 <= argc && 0 == strcmp("-v", argv[1]))
00090 {
00091 fprintf(stdout, "%s version " __DATE__ "\n", argv[0]);
00092 return EXIT_SUCCESS;
00093 }
00094
00095 if (4 != argc)
00096 {
00097 fprintf(stderr, "usage : %s input.tiff output.tiff pattern\n",
00098 argv[0]);
00099 return EXIT_FAILURE;
00100 }
00101
00102
00103 pattern_str = argv[3];
00104 if (0 == strcmp("RGGB", pattern_str))
00105 {
00106 redx = 0;
00107 redy = 0;
00108 }
00109 else if (0 == strcmp("GRBG", pattern_str))
00110 {
00111 redx = 1;
00112 redy = 0;
00113 }
00114 else if (0 == strcmp("GBRG", pattern_str))
00115 {
00116 redx = 0;
00117 redy = 1;
00118 }
00119 else if (0 == strcmp("BGGR", pattern_str))
00120 {
00121 redx = 1;
00122 redy = 1;
00123 }
00124 else
00125 {
00126 fprintf(stderr, "pattern must be RGGB, GRBG, GBRG or BGGR\n");
00127 return EXIT_FAILURE;
00128 }
00129
00130
00131 if (NULL == (data_in = read_tiff_rgba_f32(argv[1], &nx, &ny)))
00132 {
00133 fprintf(stderr, "error while reading from %s\n", argv[1]);
00134 return EXIT_FAILURE;
00135 }
00136 if (NULL == (data_out = (float *) malloc(sizeof(float) * nx * ny * 4)))
00137 {
00138 fprintf(stderr, "allocation error. not enough memory?\n");
00139 free(data_in);
00140 return EXIT_FAILURE;
00141 }
00142
00143
00144
00145
00146 ssd_demosaicking_chain(redx, redy,
00147 data_in, data_in + nx * ny, data_in + 2 * nx * ny,
00148 data_out, data_out + nx * ny, data_out + 2 * nx * ny,
00149 (int) nx, (int) ny);
00150
00151
00152 out_ptr = data_out;
00153 end_ptr = out_ptr + 3 * nx * ny;
00154 while (out_ptr < end_ptr)
00155 {
00156 if ( 0 > *out_ptr)
00157 *out_ptr = 0;
00158 if ( 255 < *out_ptr)
00159 *out_ptr = 255;
00160 out_ptr++;
00161 }
00162
00163
00164 memcpy(data_out + 3 * nx * ny, data_in + 3 * nx * ny,
00165 nx * ny * sizeof(float));
00166
00167
00168 write_tiff_rgba_f32(argv[2], data_out, nx, ny);
00169
00170 free(data_in);
00171 free(data_out);
00172
00173 return EXIT_SUCCESS;
00174 }
00175
00176
00177