{
float dist = 3;
color_t *color = NULL;
- int i;
- for (i = 0; i < nbcolors; i++) {
+ for (int i = 0; i < nbcolors; i++) {
float r = (colors + i)->red - red;
float g = (colors + i)->green - green;
float b = (colors + i)->blue - blue;
return 1;
}
- int k, l;
- for (l = 0; l < image->height; l++) {
- for (k = 0; k < image->width; k++) {
+ for (int l = 0; l < image->height; l++) {
+ for (int k = 0; k < image->width; k++) {
int ind = k + image->width * l;
color_t *color = findcolor (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]), colormap);
switch (colormap) {
free (image);
}
-int contain (char *str, char c)
+int contain (char *str, int c)
{
while (*str != c) {
if (*str++ == '\0') {
{
image_t *nimage = newimage (image->width * scale, image->height * scale, image->maxvalue);
- int i, j;
- for (i = 0; i < nimage->width; i++) {
- for (j = 0; j < nimage->height; j++) {
+ for (int i = 0; i < nimage->width; i++) {
+ for (int j = 0; j < nimage->height; j++) {
int pos = i / scale + (j / scale) * image->width;
int Pos = i + j * nimage->width;
nimage->red[Pos] = image->red[pos];
{
image_t *nimage = newimage ((image->width + scale - 1) / scale, (image->height + scale - 1) / scale, image->maxvalue);
- int i, j;
- for (i = 0; i < nimage->width; i++) {
- for (j = 0; j < nimage->height; j++) {
+ for (int i = 0; i < nimage->width; i++) {
+ for (int j = 0; j < nimage->height; j++) {
float red = 0;
float green = 0;
float blue = 0;
- int k, l, n = 0;
- for (k = 0; k < scale; k++) {
- for (l = 0; l < scale; l++) {
+ int n = 0;
+ for (int k = 0; k < scale; k++) {
+ for (int l = 0; l < scale; l++) {
int I = i * scale + k;
int J = j * scale + l;
if ((I < image->width) && (J < image->height)) {
void freeimage (image_t *image);
-int contain (char *str, char c);
+int contain (char *str, int c);
float correction (float value, float factor);
#INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
INCLUDES =
OFLAGS = -O4 -Os
+#OFLAGS = -O0
#OFLAGS = -O4 -ffast-math -finline-functions
#OFLAGS = -O4 -finline-functions
#OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
#OFLAGS += -minline-all-stringops -fsingle-precision-constant
#OFLAGS += -malign-double
CFLAGS += -W -Wall -Wextra -g
+#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
LDFLAGS += -g $(LDOPTS) $(OPTIONS)
MV = mv
ifneq (, $(findstring linux, $(MAKE_HOST)))
# Linux
-CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
else ifneq (, $(findstring mingw, $(MAKE_HOST)))
# Windows MinGw
-CFLAGS += -DPDC_WIDE
+CFLAGS += -DWIN32
#LDLIBS += -lws2_32
LDOPT = winlnk
else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
+CFLAGS += -DWIN32
# Windows CygWin
-CFLAGS += -DPDC_WIDE
LDOPT = winlnk
else ifneq (, $(findstring msdos, $(MAKE_HOST)))
# MSDOS
# Targets
-ALLEXE =
-ALLEXE += display
-ALLEXE += ndisplay
+ALLEXE = $(shell for f in *.c; do grep -q '/\*\slinker:' $$f && echo $${f/.c}; done)
SHELL = bash
all: depends
$(MAKE) $(ALLEXE:%=%.exe)
+analyze:
+ make purge
+ scan-build make
+ #scan-build -stats make
+
count:
wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
touch gcov
rm -f gcov $(wildcard *.gcda *.gcno)
$(MAKE) purge
- grep '#####' *.c.gcov || true
+ grep '^ *#####' *.c.gcov || true
gprof_%:
$(MAKE) purge
eval $$test; \
[ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
|| { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
+ test "$$RC" = 1 -a "$(STOP)" = 1 && break; \
done; \
test "$$RC" -ne 1
## Phony
-.PHONY: all clean count depends gcovs purge tests
+.PHONY: all analyze clean count depends gcovs purge tests
## Precious
/* depend: */
-/* cflags: */
+/* cflags: -D_XOPEN_SOURCE=500 */
/* linker: color.o debug.o image.o pnm.o -lncursesw -lm */
/* doslnk: color.o debug.o image.o pnm.o -lpdc~2 -lm */
/* winlnk: color.o debug.o image.o pnm.o -lpdcursesw -lm */
int main (int argc, char *argv[])
{
char *filename = NULL;
- int i;
/* get basename */
char *pt = progname = argv[0];
while (*pt) {
if ((*pt == '/') || (*pt == '\\')) {
- progname = pt + 1;
+ progname = pt + 1;
}
pt++;
}
}
char c = arg[1];
switch (c) {
- case 'g':
- arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
- if (arg == NULL) {
- VERBOSE (ERROR, fprintf (stderr, "%s: no gamma specified\n", progname));
- return usage (1);
- }
- gf[0] = strtof (arg, &pt);
- if (*pt == '\0') {
- gf[1] = gf[2] = gf[0];
- } else if (*pt == ':') {
- gf[1] = strtof (pt + 1, &pt);
- if (*pt == ':') {
- gf[2] = strtof (pt + 1, &pt);
+ case 'g':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "%s: no gamma specified\n", progname));
+ return usage (1);
+ }
+ gf[0] = strtof (arg, &pt);
+ if (*pt == '\0') {
+ gf[1] = gf[2] = gf[0];
+ } else if (*pt == ':') {
+ gf[1] = strtof (pt + 1, &pt);
+ if (*pt == ':') {
+ gf[2] = strtof (pt + 1, &pt);
+ } else {
+ gf[2] = 0;
+ }
} else {
- gf[2] = 0;
+ gf[1] = gf[2] = 0;
}
- } else {
- gf[1] = gf[2] = 0;
- }
- break;
- case 't':
- mode = 1;
- break;
- case 'v':
- arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
- if (arg == NULL) {
- VERBOSE (ERROR, fprintf (stderr, "%s: missing verbose level\n", progname));
- return usage (1);
- }
- verbose = atoi (arg);
- break;
- case 'w':
- mode = 2;
- break;
- case 'h':
- default:
- return usage (c != 'h');
+ break;
+ case 't':
+ mode = 1;
+ break;
+ case 'v':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "%s: missing verbose level\n", progname));
+ return usage (1);
+ }
+ verbose = atoi (arg);
+ break;
+ case 'w':
+ mode = 2;
+ break;
+ case 'h':
+ default:
+ return usage (c != 'h');
}
}
}
/* pre-calculate expanded and shrinked images */
- for (i = 2; i <= MAXSCALE; i++) {
+ for (int i = 2; i <= MAXSCALE; i++) {
images[i] = shrinkimage (images[1], i);
}
images[0] = expandimage (images[1], 2);
int ycursor = 0;
/* init colormap */
- int c;
- for (c = 0; c < MAXCOLORS; c++) {
+ for (int c = 0; c < MAXCOLORS; c++) {
init_pair (c, 0, c);
}
int stop = 0;
int change = 1;
while (!stop) {
- int x, y;
-
/* check cursor location */
if (images[scale]->width - xcursor < COLS / mode) {
int newxcursor = max (0, images[scale]->width - COLS / mode);
int width = min (images[scale]->width - xcursor, COLS / mode);
int height = min (images[scale]->height - ycursor, LINES);
VERBOSE (DEBUG, FILE *fd = fopen ("my.log", "a"); fprintf (fd, "(%d, %d)\n", width, height); fclose (fd));
- for (x = 0; x < width; x++) {
- for (y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
int ind = x + xcursor + images[scale]->width * (y + ycursor);
//if (ind >= images[scale]->width * images[scale]->height) {
/* cleaning before quiting */
endwin ();
- for (i = 0; i <= MAXSCALE; i++) {
+ for (int i = 0; i <= MAXSCALE; i++) {
freeimage (images[i]);
}
int mode = 0;
/* check magic number */
char magic[3] = {0};
- fread (magic, 3, 1, fd);
- if ((contain ("P", magic[0])) && (contain (" \t\n\r", magic[2]))) {
+ if ((fread (magic, 3, 1, fd) == 1) && (contain ("P", magic[0])) && (contain (" \t\n\r", magic[2]))) {
if ((magic[1] >= '1') && (magic[1] <= '6')) {
mode = magic[1] - '0';
}
{
int start = 0;
*value = 0;
- while (!feof (fd)) {
- int c = fgetc (fd);
+ int c;
+ while ((c = fgetc (fd)) != EOF) {
if (contain ("#", c)) {
- while (!feof (fd)) {
- c = fgetc (fd);
- if (contain ("\n\r", c)) {
- break;
+ do {
+ if ((c = fgetc (fd)) == EOF) {
+ return 0;
}
- }
+ } while (!contain ("\n\r", c));
} else if (contain ("0123456789", c)) {
*value = 10 * *value + c - '0';
start = 1;
int getrawvalue (FILE *fd, int nbbytes)
{
int value = fgetc (fd);
- if (value != EOF) {
- if (nbbytes == 2) {
- int value0 = fgetc (fd);
- value = (value0 != EOF) ? value * 256 + value0 : EOF;
- }
+ if ((value != EOF) && (nbbytes == 2)) {
+ int value0 = fgetc (fd);
+ value = (value0 != EOF) ? value * 256 + value0 : EOF;
}
return value;
}
{
int i = 0;
while (i < image->width * image->height) {
- int c = fgetc (fd);
- if (contain ("#", c)) {
- while (!feof (fd)) {
- c = fgetc (fd);
- if (contain ("\n\r", c)) {
- break;
+ int c;
+ if ((c = fgetc (fd)) == EOF) {
+ return 0;
+ } else if (contain ("#", c)) {
+ do {
+ if ((c = fgetc (fd)) == EOF) {
+ return 0;
}
- }
+ } while (!contain ("\n\r", c));
} else if (contain ("01", c)) {
image->red[i] = image->green[i] = image->blue[i] = '1' - c;
i++;
int value = EOF;
while (i < image->width * image->height) {
if (k == 0) {
- value = fgetc (fd);
+ if ((value = fgetc (fd)) == EOF) {
+ break;
+ }
k = 8;
}
image->red[i] = image->green[i] = image->blue[i] = !((value >> --k) & 1);
int i = 0;
mode = (mode) ? ((image->maxvalue > 255) ? 2 : 1) : 0;
int value = EOF;
- while (i < image->width * image->height) {
- value = getvalue (fd, mode);
+ while ((i < image->width * image->height) && ((value = getvalue (fd, mode)) != EOF)) {
image->red[i] = image->green[i] = image->blue[i] = value / (float)image->maxvalue;
i++;
}
mode = (mode) ? ((image->maxvalue > 255) ? 2 : 1) : 0;
int value = EOF;
while (i < image->width * image->height) {
- value = getvalue (fd, mode);
+ if ((value = getvalue (fd, mode)) == EOF) {
+ break;
+ }
image->red[i] = value / (float)image->maxvalue;
- value = getvalue (fd, mode);
+ if ((value = getvalue (fd, mode)) == EOF) {
+ break;
+ }
image->green[i] = value / (float)image->maxvalue;
- value = getvalue (fd, mode);
+ if ((value = getvalue (fd, mode)) == EOF) {
+ break;
+ }
image->blue[i] = value / (float)image->maxvalue;
i++;
}