Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <limits.h>
00031
00032 #include "io_png.h"
00033 #include "colorbalance_lib.h"
00034
00038 int main(int argc, char *const *argv)
00039 {
00040 float smin, smax;
00041 size_t nx, ny, size, i;
00042
00043
00044 if (2 <= argc && 0 == strcmp("-v", argv[1])) {
00045 fprintf(stdout, "%s version " __DATE__ "\n", argv[0]);
00046 return EXIT_SUCCESS;
00047 }
00048
00049 if (6 != argc) {
00050 fprintf(stderr, "usage : %s mode Smin Smax in.png out.png\n",
00051 argv[0]);
00052 fprintf(stderr, " mode is rgb or irgb\n");
00053 fprintf(stderr, " (see README.txt for details)\n");
00054 fprintf(stderr, " Smin and Smax are percentage of pixels\n");
00055 fprintf(stderr, " saturated to min and max,\n");
00056 fprintf(stderr, " in [0-100[\n");
00057 return EXIT_FAILURE;
00058 }
00059
00060
00061 smin = atof(argv[2]);
00062 smax = atof(argv[3]);
00063 if (0. > smin || 100. <= smin || 0. > smax || 100. <= smax) {
00064 fprintf(stderr, "the saturation percentages must be in [0-100[\n");
00065 return EXIT_FAILURE;
00066 }
00067
00068
00069 if (0 == strcmp(argv[1], "rgb")) {
00070 unsigned char *rgb;
00071
00072
00073 if (NULL == (rgb = io_png_read_u8_rgb(argv[4], &nx, &ny))) {
00074 fprintf(stderr, "the image could not be properly read\n");
00075 return EXIT_FAILURE;
00076 }
00077 size = nx * ny;
00078
00079
00080 (void) colorbalance_rgb_u8(rgb, size,
00081 size * (smin / 100.),
00082 size * (smax / 100.));
00083
00084
00085 io_png_write_u8(argv[5], rgb, nx, ny, 3);
00086 free(rgb);
00087 }
00088 else if (0 == strcmp(argv[1], "irgb")) {
00089 float *rgb;
00090
00091
00093 if (NULL == (rgb = io_png_read_f32_rgb(argv[4], &nx, &ny))) {
00094 fprintf(stderr, "the image could not be properly read\n");
00095 return EXIT_FAILURE;
00096 }
00097 size = nx * ny;
00098 for (i = 0; i < 3 * size; i++)
00099 rgb[i] /= 255.;
00100
00101
00102 (void) colorbalance_irgb_f32(rgb, size,
00103 size * (smin / 100.),
00104 size * (smax / 100.));
00105
00106
00108 for (i = 0; i < 3 * size; i++)
00109 rgb[i] *= 255.;
00110 io_png_write_f32(argv[5], rgb, nx, ny, 3);
00111 free(rgb);
00112 }
00113 else {
00114 fprintf(stderr, "mode must be rgb or irgb\n");
00115 return EXIT_FAILURE;
00116 }
00117
00118 return EXIT_SUCCESS;
00119 }