{ 0, 0.0, 0.0, 0.0 },
};
+color_t *_findcolor (float red, float green, float blue, color_t *colors, int nbcolors)
+{
+ float dist = 3;
+ color_t *color = NULL;
+ int i;
+ for (i = 0; i < nbcolors; i++) {
+ float r = (colors + i)->red - red;
+ float g = (colors + i)->green - green;
+ float b = (colors + i)->blue - blue;
+ float d = r * r + g * g + b * b;
+ if (d < dist) {
+ dist = d;
+ color = colors + i;
+ }
+ }
+ return color;
+}
+
color_t *findcolor (float red, float green, float blue, int colormap)
{
- int nbcolors;
- color_t *colors;
+ int nbcolors = 0;
+ color_t *colors = NULL;
switch (colormap) {
case 0:
nbcolors = nbcolors0;
}
color_t *color = NULL;
- int i;
- float dist;
switch (colormap) {
case 0:
case 1:
case 2:
- dist = 3;
- for (i = 0; i < nbcolors; i++) {
- float r = (colors + i)->red - red;
- float g = (colors + i)->green - green;
- float b = (colors + i)->blue - blue;
- float d = r * r + g * g + b * b;
- if (d < dist) {
- dist = d;
- color = colors + i;
- }
- }
+ color = _findcolor (red, green, blue, colors, nbcolors);
break;
default:
case 3:
printf ("\e[48;2;%d;%d;%dm%s\e[0m", (color + 0)->code, (color + 1)->code, (color + 2)->code, str);
}
+color_t *findncolor (float red, float green, float blue, int nbcolors)
+{
+ return _findcolor (red, green, blue, colors2, nbcolors);
+}
+
/* vim: set ts=4 sw=4 et: */
void cprint24 (color_t *color, char *str);
+color_t *findncolor (float red, float green, float blue, int nbcolors);
+
#endif /* __COLOR_H__ */
/* vim: set ts=4 sw=4 et: */
char *progname = NULL;
char *version = "0.1";
-int colormap = 2;
float gf[3] = { 1.0f, 1.0f, 1.0f };
int mode = 1;
int scale = 1;
#define MAXSCALE 4
+#define MAXCOLORS 256
+
char *help =
"<i> Move up\n"
"<j> Move left\n"
}
/* check */
- if ((colormap < 0) || (colormap > 3)) {
- VERBOSE (ERROR, fprintf (stderr, "incorrect colormap (%d)\n", colormap));
- return 1;
- }
if ((gf[0] <= 0) || (gf[1] <= 0) || (gf[2] <= 0)) {
VERBOSE (ERROR, fprintf (stderr, "incorrect gamma (%.1f:%.1f;%.1f)\n", gf[0], gf[1], gf[2]));
return 1;
curs_set (0);
start_color ();
+ /* check */
+ if (COLORS == 0) {
+ VERBOSE (ERROR, fprintf (stderr, "no color avaliable\n"));
+ return 1;
+ }
+
/* cursor definition */
int xcursor = 0;
int ycursor = 0;
/* init colormap */
int c;
- for (c = 0; c < 256; c++) {
+ for (c = 0; c < MAXCOLORS; c++) {
init_pair (c, 0, c);
}
if (ind >= images[scale]->width * images[scale]->height) {
continue;
}
- color_t *color = findcolor (correction (images[scale]->red[ind], gf[0]),
+ color_t *color = findncolor (correction (images[scale]->red[ind], gf[0]),
correction (images[scale]->green[ind], gf[1]),
- correction (images[scale]->blue[ind], gf[2]), colormap);
+ correction (images[scale]->blue[ind], gf[2]), COLORS);
attron (COLOR_PAIR (color->code));
move (y, x * mode);
}
/* test: ndisplay.exe 2>&1 | grep 'no file specified' */
+/* test: TERM=vt100 ndisplay.exe image/laurent4p.ppm 2>&1 | grep 'no color avaliable' */
/* test: ndisplay.exe -h | grep usage */
/* test: ndisplay.exe -v 2>&1 | grep missing */
/* test: ndisplay.exe image/bogus1.ppm 2>&1 | grep "can't read PNM file" */