00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035
00036 #include "io_tiff.h"
00037
00041 int main(int argc, char **argv)
00042 {
00043 size_t nx = 0, ny = 0;
00044 float *data;
00045 float *channel;
00046 int mask_R[4] = {0, 0, 0, 0};
00047 int mask_G[4] = {0, 0, 0, 0};
00048 int mask_B[4] = {0, 0, 0, 0};
00049 size_t i, j;
00050
00051
00052 if (2 <= argc && 0 == strcmp("-v", argv[1]))
00053 {
00054 fprintf(stdout, "%s version " __DATE__ "\n", argv[0]);
00055 return EXIT_SUCCESS;
00056 }
00057
00058 if (4 != argc)
00059 {
00060 fprintf(stderr, "usage : %s input.tiff output.tiff pattern\n",
00061 argv[0]);
00062 return EXIT_FAILURE;
00063 }
00064
00065
00066 if (0 == strcmp("RGGB", argv[3]))
00067 {
00068 mask_R[0] = 1;
00069 mask_G[1] = 1;
00070 mask_G[2] = 1;
00071 mask_B[3] = 1;
00072 }
00073 else if (0 == strcmp("GRBG", argv[3]))
00074 {
00075 mask_G[0] = 1;
00076 mask_R[1] = 1;
00077 mask_B[2] = 1;
00078 mask_G[3] = 1;
00079 }
00080 else if (0 == strcmp("GBRG", argv[3]))
00081 {
00082 mask_G[0] = 1;
00083 mask_B[1] = 1;
00084 mask_R[2] = 1;
00085 mask_G[3] = 1;
00086 }
00087 else if (0 == strcmp("BGGR", argv[3]))
00088 {
00089 mask_B[0] = 1;
00090 mask_G[1] = 1;
00091 mask_G[2] = 1;
00092 mask_R[3] = 1;
00093 }
00094 else
00095 {
00096 fprintf(stderr, "pattern must be RGGB, GRBG, GBRG or BGGR\n");
00097 return EXIT_FAILURE;
00098 }
00099
00100
00101 if (NULL == (data = read_tiff_rgba_f32(argv[1], &nx, &ny)))
00102 {
00103 fprintf(stderr, "error while reading from %s\n", argv[1]);
00104 return EXIT_FAILURE;
00105 }
00106
00107
00108
00109
00110
00111
00112 channel = data;
00113
00114 for (j = 0; j < ny; j++)
00115 for (i = 0; i < nx; i++)
00116 channel[i + nx * j] *= mask_R[(i % 2) + 2 * (j % 2)];
00117
00118
00119 channel = data + nx * ny;
00120 for (j = 0; j < ny; j++)
00121 for (i = 0; i < nx; i++)
00122 channel[i + nx * j] *= mask_G[(i % 2) + 2 * (j % 2)];
00123
00124
00125 channel = data + 2 * nx * ny;
00126 for (j = 0; j < ny; j++)
00127 for (i = 0; i < nx; i++)
00128 channel[i + nx * j] *= mask_B[(i % 2) + 2 * (j % 2)];
00129
00130
00131 write_tiff_rgba_f32(argv[2], data, nx, ny);
00132
00133 free(data);
00134
00135 return EXIT_SUCCESS;
00136 }