diff --git a/filters/filter_bumpmap.c b/filters/filter_bumpmap.c index be3204f..13cba38 100644 --- a/filters/filter_bumpmap.c +++ b/filters/filter_bumpmap.c @@ -227,7 +227,7 @@ bump_map_point(Imlib_Image im, pIFunctionParam par) return im; } -void +static void init(struct imlib_filter_info *info) { char *filters[] = { "bump_map_point", "bump_map" }; @@ -243,13 +243,13 @@ init(struct imlib_filter_info *info) } -void +static void deinit() { return; } -void * +static void * exec(char *filter, void *im, pIFunctionParam par) { if (!strcmp(filter, "bump_map")) diff --git a/filters/filter_colormod.c b/filters/filter_colormod.c index 55331ee..db703ce 100644 --- a/filters/filter_colormod.c +++ b/filters/filter_colormod.c @@ -63,7 +63,7 @@ colormod(Imlib_Image im, pIFunctionParam par) DATA8 a_b[256], r_b[256], g_b[256], b_b[256]; pIFunctionParam ptr; int x = 0, y = 0, h, w, i; - double v; + double v=0.0; imlib_context_set_image(im); w = imlib_image_get_width(); @@ -168,7 +168,7 @@ colormod(Imlib_Image im, pIFunctionParam par) return im; } -void +static void init(struct imlib_filter_info *info) { char *filters[] = { "colormod" }; @@ -184,13 +184,13 @@ init(struct imlib_filter_info *info) } -void +static void deinit() { return; } -void * +static void * exec(char *filter, void *im, pIFunctionParam par) { if (!strcmp(filter, "colormod")) diff --git a/filters/filter_test.c b/filters/filter_test.c index 3e736f9..b3035f9 100644 --- a/filters/filter_test.c +++ b/filters/filter_test.c @@ -12,7 +12,7 @@ #include "dynamic_filters.h" void init( struct imlib_filter_info *info ); -void deinit(); +void deinit(void); void *exec( char *filter, void *im, pIFunctionParam params ); void init( struct imlib_filter_info *info ) @@ -30,7 +30,7 @@ void init( struct imlib_filter_info *info ) } -void deinit() +void deinit(void) { return; } diff --git a/loaders/loader_bmp.c b/loaders/loader_bmp.c index dd84ff4..85a957d 100644 --- a/loaders/loader_bmp.c +++ b/loaders/loader_bmp.c @@ -35,7 +35,7 @@ RGBQUAD; #define BI_RLE4 2 #define BI_BITFIELDS 3 -int ReadleShort(FILE *file, unsigned short *ret) +static int ReadleShort(FILE *file, unsigned short *ret) { unsigned char b[2]; @@ -46,7 +46,7 @@ int ReadleShort(FILE *file, unsigned short *ret) return 1; } -int ReadleLong(FILE *file, unsigned long *ret) +static int ReadleLong(FILE *file, unsigned long *ret) { unsigned char b[4]; @@ -63,7 +63,7 @@ load (ImlibImage *im, ImlibProgressFunction progress, { FILE *f; char pper = 0; - int pl = 0, alpha = 0; + int pl = 0; char type[2]; unsigned long size, offset, headSize, comp, imgsize, j, k, l; unsigned short tmpShort, planes, bitcount, ncols, skip; diff --git a/loaders/loader_db.c b/loaders/loader_db.c index 8839155..4034449 100644 --- a/loaders/loader_db.c +++ b/loaders/loader_db.c @@ -231,9 +231,9 @@ save (ImlibImage *im, ImlibProgressFunction progress, int alpha = 0; char file[4096], key[4096], *cp; DATA32 *header; - DATA32 *buf, *buf2; + DATA32 *buf; E_DB_File *db; - int compression = 0, size; + int compression = 0, size = 0; DATA32 *ret; @@ -330,7 +330,6 @@ save (ImlibImage *im, ImlibProgressFunction progress, } if (compression == 0) { - int y; memcpy(&(buf[8]), im->data, im->w * im->h * sizeof(DATA32)); header[4] = compression; #ifdef WORDS_BIGENDIAN diff --git a/loaders/loader_pnm.c b/loaders/loader_pnm.c index 877e782..88d5c18 100644 --- a/loaders/loader_pnm.c +++ b/loaders/loader_pnm.c @@ -10,21 +10,22 @@ #include #include "image.h" -char load (ImlibImage *im, ImlibProgressFunction progress, - char progress_granularity, char immediate_load); -char save (ImlibImage *im, ImlibProgressFunction progress, - char progress_granularity); -void formats (ImlibLoader *l); +char load(ImlibImage * im, ImlibProgressFunction progress, + char progress_granularity, char immediate_load); +char save(ImlibImage * im, ImlibProgressFunction progress, -char -load (ImlibImage *im, ImlibProgressFunction progress, - char progress_granularity, char immediate_load) + char progress_granularity); +void formats(ImlibLoader * l); + +char +load(ImlibImage * im, ImlibProgressFunction progress, + char progress_granularity, char immediate_load) { - char p = ' ', numbers = 3, count = 0; - int w = 0, h = 0, v = 255, c = 0; - char buf[256]; - FILE *f = NULL; - + char p = ' ', numbers = 3, count = 0; + int w = 0, h = 0, v = 255, c = 0; + char buf[256]; + FILE *f = NULL; + if (im->data) return 0; f = fopen(im->file, "rb"); @@ -37,45 +38,46 @@ load (ImlibImage *im, ImlibProgressFunction progress, * no chance to distinguish between end of buffer * and a binary 0. */ - - /* read the header info */ - + + /* read the header info */ + c = fgetc(f); if (c != 'P') - { - fclose(f); - return 0; - } - + { + fclose(f); + return 0; + } + p = fgetc(f); if (p == '1' || p == '4') - numbers = 2; /* bitimages don't have max value */ - + numbers = 2; /* bitimages don't have max value */ + count = 0; while (count < numbers) - { + { c = fgetc(f); - + if (c == EOF) - { - fclose(f); - return 0; - } - + { + fclose(f); + return 0; + } + /* eat whitespace */ while (isspace(c)) c = fgetc(f); /* if comment, eat that */ if (c == '#') - { + { do c = fgetc(f); while (c != '\n' && c != EOF); - } + } /* no comment -> proceed */ - else - { + else + { int i = 0; + /* read numbers */ while (c != EOF && !isspace(c)) { @@ -88,573 +90,577 @@ load (ImlibImage *im, ImlibProgressFunction progress, count++; switch (count) { - /* width */ - case 1: w = atoi(buf); break; - /* height */ - case 2: h = atoi(buf); break; - /* max value, only for color and greyscale */ - case 3: v = atoi(buf); break; + /* width */ + case 1: + w = atoi(buf); + break; + /* height */ + case 2: + h = atoi(buf); + break; + /* max value, only for color and greyscale */ + case 3: + v = atoi(buf); + break; } - } - } - } - - im->w = w; - im->h = h; - if (!im->format) - { - if (p == '8') - SET_FLAG(im->flags, F_HAS_ALPHA); - else - UNSET_FLAG(im->flags, F_HAS_ALPHA); - im->format = strdup("pnm"); - } - + } + } + } + + im->w = w; + im->h = h; + if (!im->format) + { + if (p == '8') + SET_FLAG(im->flags, F_HAS_ALPHA); + else + UNSET_FLAG(im->flags, F_HAS_ALPHA); + im->format = strdup("pnm"); + } + if (((!im->data) && (im->loader)) || (immediate_load) || (progress)) - { - DATA8 *data = NULL; /* for the binary versions */ - DATA8 *ptr; - int *idata = NULL; /* for the ASCII versions */ - int *iptr; - char buf2[256]; - DATA32 *ptr2; - int i, j, x, y, pl = 0; - char pper = 0; - - /* must set the im->data member before callign progress function */ - ptr2 = im->data = malloc(w * h * sizeof(DATA32)); - if (!im->data) - { - fclose(f); - return 0; - } - /* start reading the data */ - switch (p) - { - case '1': /* ASCII monochrome */ - buf[0] = 0; - i = 0; - for (y = 0; y < h; y++) - { - x = 0; - while (x < w) - { - if (!buf[i]) /* fill buffer */ - { - if (!fgets(buf, 255, f)) - { - fclose(f); - return 0; - } - i = 0; - } - while (buf[i] && isspace(buf[i])) - i++; - if(buf[i]) - { - if (buf[i] == '1') + { + DATA8 *data = NULL; /* for the binary versions */ + DATA8 *ptr; + int *idata = NULL; /* for the ASCII versions */ + int *iptr; + char buf2[256]; + DATA32 *ptr2; + int i, j, x, y, pl = 0; + char pper = 0; + + /* must set the im->data member before callign progress function */ + ptr2 = im->data = malloc(w * h * sizeof(DATA32)); + if (!im->data) + { + fclose(f); + return 0; + } + /* start reading the data */ + switch (p) + { + case '1': /* ASCII monochrome */ + buf[0] = 0; + i = 0; + for (y = 0; y < h; y++) + { + x = 0; + while (x < w) + { + if (!buf[i]) /* fill buffer */ + { + if (!fgets(buf, 255, f)) + { + fclose(f); + return 0; + } + i = 0; + } + while (buf[i] && isspace(buf[i])) + i++; + if (buf[i]) + { + if (buf[i] == '1') *ptr2 = 0xff000000; - else if (buf[i] == '0') + else if (buf[i] == '0') *ptr2 = 0xffffffff; - else - { - fclose(f); - return 0; - } - ptr2++; - i++; - } - } - if (progress) - { - char per; - int l; + else + { + fclose(f); + return 0; + } + ptr2++; + i++; + } + } + if (progress) + { + char per; + int l; - per = (char) ((100 * y) / im->h); - if (((per - pper) >= progress_granularity) - || (y == (im->h - 1))) - { - l = y - pl; - if (!progress(im, per, 0, (y - l), im->w, l)) - { - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '2': /* ASCII greyscale */ - idata = malloc(sizeof(int) * w); - if (!idata) - { - fclose(f); - return 0; - } - buf[0] = 0; - i = 0; - j = 0; - for (y = 0; y < h; y++) - { - iptr = idata; - x = 0; - while (x < w) - { - if (!buf[i]) /* fill buffer */ - { - if (!fgets(buf, 255, f)) - { - free(idata); - fclose(f); - return 0; - } - i = 0; - } - while (buf[i] && isspace(buf[i])) - i++; - while (buf[i] && !isspace(buf[i])) - buf2[j++] = buf[i++]; - if (j) - { - buf2[j] = 0; - *(iptr++) = atoi(buf2); - j = 0; - x++; - } - } - iptr = idata; - if (v == 255) - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (iptr[0] << 16) | - (iptr[0] << 8) | - iptr[0]; - ptr2++; - iptr++; - } - } - else - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (((iptr[0] * 255) / v) << 16) | - (((iptr[0] * 255) / v) << 8) | - ((iptr[0] * 255) / v); - ptr2++; - iptr++; - } - } - if (progress) - { - char per; - int l; + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '2': /* ASCII greyscale */ + idata = malloc(sizeof(int) * w); - per = (char) ((100 * y) / im->h); - if (((per - pper) >= progress_granularity) - || (y == (im->h - 1))) - { - l = y - pl; - if (!progress(im, per, 0, (y - l), im->w, l)) - { - if (idata) - free(idata); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '3': /* ASCII RGB */ - idata = malloc(3 * sizeof(int) * w); - if (!idata) - { - fclose(f); - return 0; - } - buf[0] = 0; - i = 0; - j = 0; - for (y = 0; y < h; y++) - { - int w3 = 3 * w; - iptr = idata; - x = 0; - while (x < w3) - { - if (!buf[i]) /* fill buffer */ - { - if (!fgets(buf, 255, f)) - { - free(idata); - fclose(f); - return 0; - } - i = 0; - } - while (buf[i] && isspace(buf[i])) - i++; - while (buf[i] && !isspace(buf[i])) - buf2[j++] = buf[i++]; - if (j) - { - buf2[j] = 0; - *(iptr++) = atoi(buf2); - j = 0; - x++; - } - } - iptr = idata; - if (v == 255) - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (iptr[0] << 16) | - (iptr[1] << 8) | - iptr[2]; - ptr2++; - iptr+=3; - } - } - else - { - for (x = 0; x < w; x++) - { - *ptr2 = - 0xff000000 | - (((ptr[0] * 255) / v) << 16) | - (((iptr[1] * 255) / v) << 8) | - ((iptr[2] * 255) / v); - ptr2++; - iptr+=3; - } - } - if (progress) - { - char per; - int l; - - per = (char) ((100 * y) / im->h); - if (((per - pper) >= progress_granularity) - || (y == (im->h - 1))) - { - l = y - pl; - if (!progress(im, per, 0, (y - l), im->w, l)) - { - if (idata) - free(idata); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '4': /* binary 1bit monochrome */ - data = malloc(1 * sizeof(DATA8)); - if (!data) - { - fclose(f); - return 0; - } - ptr2 = im->data; - j = 0; - while ((fread(data, 1, 1, f)) && (j < (w * h))) - { - for (i = 7; i >= 0; i--) - { - if (j < (w * h)) - { - if (data[0] & (1 << i)) - *ptr2 = 0xff000000; - else - *ptr2 = 0xffffffff; - ptr2++; - } - j++; - } - } - break; - case '5': /* binary 8bit grayscale GGGGGGGG */ - data = malloc(1 * sizeof(DATA8) * w); - if (!data) - { - fclose(f); - return 0; - } - ptr2 = im->data; - for (y = 0; y < h; y++) - { - if (!fread(data, w * 1, 1, f)) - { - free(data); - fclose(f); - return 1; - } - ptr = data; - if (v == 255) - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (ptr[0] << 16) | - (ptr[0] << 8) | - ptr[0]; - ptr2++; - ptr ++; - } - } - else - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (((ptr[0] * 255) / v) << 16) | - (((ptr[0] * 255) / v) << 8) | - ((ptr[0] * 255) / v); - ptr2++; - ptr++; - } - } - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - if (data) - free(data); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '6': /* 24bit binary RGBRGBRGB */ - data = malloc(3 * sizeof(DATA8) * w); - if (!data) - { - fclose(f); - return 0; - } - ptr2 = im->data; - for (y = 0; y < h; y++) - { - if (!fread(data, w * 3, 1, f)) - { - free(data); - fclose(f); - return 1; - } - ptr = data; - if (v == 255) - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (ptr[0] << 16) | - (ptr[1] << 8) | - ptr[2]; - ptr2++; - ptr += 3; - } - } - else - { - for (x = 0; x < w; x++) - { - *ptr2 = 0xff000000 | - (((ptr[0] * 255) / v) << 16) | - (((ptr[1] * 255) / v) << 8) | - ((ptr[2] * 255) / v); - ptr2++; - ptr += 3; - } - } - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - if (data) - free(data); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '7': /* XV's 8bit 332 format */ - data = malloc(1 * sizeof(DATA8) * w); - if (!data) - { - fclose(f); - return 0; - } - ptr2 = im->data; - for (y = 0; y < h; y++) - { - if (!fread(data, w * 1, 1, f)) - { - free(data); - fclose(f); - return 1; - } - ptr = data; - for (x = 0; x < w; x++) - { - int r, g, b; - - r = (*ptr >> 5) & 0x7; - g = (*ptr >> 2) & 0x7; - b = (*ptr ) & 0x3; - *ptr2 = 0xff000000 | - (((r << 21) | (r << 18) | (r << 15)) & 0xff0000) | - (((g << 13) | (g << 10) | (g << 7)) & 0xff00) | - ((b << 6) | (b << 4) | (b << 2) | (b << 0)); - ptr2++; - ptr++; - } - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - if (data) - free(data); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - case '8': /* 24bit binary RGBARGBARGBA */ - data = malloc(4 * sizeof(DATA8) * w); - if (!data) - { - fclose(f); - return 0; - } - ptr2 = im->data; - for (y = 0; y < h; y++) - { - if (!fread(data, w * 4, 1, f)) - { - free(data); - fclose(f); - return 1; - } - ptr = data; - if (v == 255) - { - for (x = 0; x < w; x++) - { - *ptr2 = (ptr[3] << 24) | - (ptr[0] << 16) | - (ptr[1] << 8) | - ptr[2]; - ptr2++; - ptr += 4; - } - } - else - { - for (x = 0; x < w; x++) - { - *ptr2 = (((ptr[3] * 255) / v) << 24) | - (((ptr[0] * 255) / v) << 16) | - (((ptr[1] * 255) / v) << 8) | - ((ptr[2] * 255) / v); - ptr2++; - ptr += 4; - } - } - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - if (data) - free(data); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - break; - default: - fclose(f); - return 0; - break; - } + if (!idata) + { + fclose(f); + return 0; + } + buf[0] = 0; + i = 0; + j = 0; + for (y = 0; y < h; y++) + { + iptr = idata; + x = 0; + while (x < w) + { + if (!buf[i]) /* fill buffer */ + { + if (!fgets(buf, 255, f)) + { + free(idata); + fclose(f); + return 0; + } + i = 0; + } + while (buf[i] && isspace(buf[i])) + i++; + while (buf[i] && !isspace(buf[i])) + buf2[j++] = buf[i++]; + if (j) + { + buf2[j] = 0; + *(iptr++) = atoi(buf2); + j = 0; + x++; + } + } + iptr = idata; + if (v == 255) + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (iptr[0] << 16) | (iptr[0] << 8) | + iptr[0]; + ptr2++; + iptr++; + } + } + else + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (((iptr[0] * 255) / v) << 16) | + (((iptr[0] * 255) / v) << 8) | ((iptr[0] * 255) / v); + ptr2++; + iptr++; + } + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (idata) + free(idata); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '3': /* ASCII RGB */ + idata = malloc(3 * sizeof(int) * w); + + if (!idata) + { + fclose(f); + return 0; + } + buf[0] = 0; + i = 0; + j = 0; + for (y = 0; y < h; y++) + { + int w3 = 3 * w; + + iptr = idata; + x = 0; + while (x < w3) + { + if (!buf[i]) /* fill buffer */ + { + if (!fgets(buf, 255, f)) + { + free(idata); + fclose(f); + return 0; + } + i = 0; + } + while (buf[i] && isspace(buf[i])) + i++; + while (buf[i] && !isspace(buf[i])) + buf2[j++] = buf[i++]; + if (j) + { + buf2[j] = 0; + *(iptr++) = atoi(buf2); + j = 0; + x++; + } + } + iptr = idata; + if (v == 255) + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (iptr[0] << 16) | (iptr[1] << 8) | + iptr[2]; + ptr2++; + iptr += 3; + } + } + else + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (((ptr[0] * 255) / v) << 16) | + (((iptr[1] * 255) / v) << 8) | ((iptr[2] * 255) / v); + ptr2++; + iptr += 3; + } + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (idata) + free(idata); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '4': /* binary 1bit monochrome */ + data = malloc(1 * sizeof(DATA8)); + if (!data) + { + fclose(f); + return 0; + } + ptr2 = im->data; + j = 0; + while ((fread(data, 1, 1, f)) && (j < (w * h))) + { + for (i = 7; i >= 0; i--) + { + if (j < (w * h)) + { + if (data[0] & (1 << i)) + *ptr2 = 0xff000000; + else + *ptr2 = 0xffffffff; + ptr2++; + } + j++; + } + } + break; + case '5': /* binary 8bit grayscale GGGGGGGG */ + data = malloc(1 * sizeof(DATA8) * w); + if (!data) + { + fclose(f); + return 0; + } + ptr2 = im->data; + for (y = 0; y < h; y++) + { + if (!fread(data, w * 1, 1, f)) + { + free(data); + fclose(f); + return 1; + } + ptr = data; + if (v == 255) + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (ptr[0] << 16) | (ptr[0] << 8) | ptr[0]; + ptr2++; + ptr++; + } + } + else + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (((ptr[0] * 255) / v) << 16) | + (((ptr[0] * 255) / v) << 8) | ((ptr[0] * 255) / v); + ptr2++; + ptr++; + } + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (data) + free(data); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '6': /* 24bit binary RGBRGBRGB */ + data = malloc(3 * sizeof(DATA8) * w); + if (!data) + { + fclose(f); + return 0; + } + ptr2 = im->data; + for (y = 0; y < h; y++) + { + if (!fread(data, w * 3, 1, f)) + { + free(data); + fclose(f); + return 1; + } + ptr = data; + if (v == 255) + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; + ptr2++; + ptr += 3; + } + } + else + { + for (x = 0; x < w; x++) + { + *ptr2 = + 0xff000000 | (((ptr[0] * 255) / v) << 16) | + (((ptr[1] * 255) / v) << 8) | ((ptr[2] * 255) / v); + ptr2++; + ptr += 3; + } + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (data) + free(data); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '7': /* XV's 8bit 332 format */ + data = malloc(1 * sizeof(DATA8) * w); + if (!data) + { + fclose(f); + return 0; + } + ptr2 = im->data; + for (y = 0; y < h; y++) + { + if (!fread(data, w * 1, 1, f)) + { + free(data); + fclose(f); + return 1; + } + ptr = data; + for (x = 0; x < w; x++) + { + int r, g, b; + + r = (*ptr >> 5) & 0x7; + g = (*ptr >> 2) & 0x7; + b = (*ptr) & 0x3; + *ptr2 = + 0xff000000 | (((r << 21) | (r << 18) | (r << 15)) & + 0xff0000) | (((g << 13) | (g << 10) | + (g << 7)) & 0xff00) | ((b << + 6) | + (b << + 4) | + (b << + 2) | + (b << + 0)); + ptr2++; + ptr++; + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (data) + free(data); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + case '8': /* 24bit binary RGBARGBARGBA */ + data = malloc(4 * sizeof(DATA8) * w); + if (!data) + { + fclose(f); + return 0; + } + ptr2 = im->data; + for (y = 0; y < h; y++) + { + if (!fread(data, w * 4, 1, f)) + { + free(data); + fclose(f); + return 1; + } + ptr = data; + if (v == 255) + { + for (x = 0; x < w; x++) + { + *ptr2 = + (ptr[3] << 24) | (ptr[0] << 16) | (ptr[1] << 8) | + ptr[2]; + ptr2++; + ptr += 4; + } + } + else + { + for (x = 0; x < w; x++) + { + *ptr2 = + (((ptr[3] * 255) / v) << 24) | (((ptr[0] * 255) / v) << + 16) | + (((ptr[1] * 255) / v) << 8) | ((ptr[2] * 255) / v); + ptr2++; + ptr += 4; + } + } + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) + || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + if (data) + free(data); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + break; + default: + fclose(f); + return 0; + break; + } if (idata) free(idata); - if (data) - free(data); - } + if (data) + free(data); + } fclose(f); return 1; } -char -save (ImlibImage *im, ImlibProgressFunction progress, - char progress_granularity) +char +save(ImlibImage * im, ImlibProgressFunction progress, + char progress_granularity) { - FILE *f; - DATA8 *buf, *bptr; - DATA32 *ptr; - int x, y, pl = 0; - char pper = 0; - + FILE *f; + DATA8 *buf, *bptr; + DATA32 *ptr; + int x, y, pl = 0; + char pper = 0; + /* no image data? abort */ if (!im->data) return 0; @@ -663,104 +669,96 @@ save (ImlibImage *im, ImlibProgressFunction progress, return 0; /* if the image has a useful alpha channel */ if (im->flags & F_HAS_ALPHA) - { - /* allocate a small buffer to convert image data */ - buf = malloc(im->w * 4 * sizeof(DATA8)); - if (!buf) - { - fclose(f); - return 0; - } - ptr = im->data; - fprintf(f, - "P8\n" - "# PNM File written by Imlib2\n" - "%i %i\n" - "255\n", im->w, im->h); - for (y = 0; y < im->h; y++) - { - bptr = buf; - for (x = 0; x < im->w; x++) - { - bptr[0] = ((*ptr) >> 16) & 0xff; - bptr[1] = ((*ptr) >> 8 ) & 0xff; - bptr[2] = ((*ptr) ) & 0xff; - bptr[3] = ((*ptr) >> 24) & 0xff; - bptr += 4; - ptr++; - } - fwrite(buf, im->w * 4, 1, f); - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - free(buf); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - } + { + /* allocate a small buffer to convert image data */ + buf = malloc(im->w * 4 * sizeof(DATA8)); + if (!buf) + { + fclose(f); + return 0; + } + ptr = im->data; + fprintf(f, "P8\n" "# PNM File written by Imlib2\n" "%i %i\n" "255\n", + im->w, im->h); + for (y = 0; y < im->h; y++) + { + bptr = buf; + for (x = 0; x < im->w; x++) + { + bptr[0] = ((*ptr) >> 16) & 0xff; + bptr[1] = ((*ptr) >> 8) & 0xff; + bptr[2] = ((*ptr)) & 0xff; + bptr[3] = ((*ptr) >> 24) & 0xff; + bptr += 4; + ptr++; + } + fwrite(buf, im->w * 4, 1, f); + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + free(buf); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + } else - { - /* allocate a small buffer to convert image data */ - buf = malloc(im->w * 3 * sizeof(DATA8)); - if (!buf) - { - fclose(f); - return 0; - } - ptr = im->data; - fprintf(f, - "P6\n" - "# PNM File written by Imlib2\n" - "%i %i\n" - "255\n", im->w, im->h); - for (y = 0; y < im->h; y++) - { - bptr = buf; - for (x = 0; x < im->w; x++) - { - bptr[0] = ((*ptr) >> 16) & 0xff; - bptr[1] = ((*ptr) >> 8 ) & 0xff; - bptr[2] = ((*ptr) ) & 0xff; - bptr += 3; - ptr++; - } - fwrite(buf, im->w * 3, 1, f); - if (progress) - { - char per; - int l; - - per = (char)((100 * y) / im->h); - if (((per - pper) >= progress_granularity) || - (y == (im->h - 1))) - { - l = y - pl; - if(!progress(im, per, 0, (y - l), im->w, l)) - { - free(buf); - fclose(f); - return 2; - } - pper = per; - pl = y; - } - } - } - } + { + /* allocate a small buffer to convert image data */ + buf = malloc(im->w * 3 * sizeof(DATA8)); + if (!buf) + { + fclose(f); + return 0; + } + ptr = im->data; + fprintf(f, "P6\n" "# PNM File written by Imlib2\n" "%i %i\n" "255\n", + im->w, im->h); + for (y = 0; y < im->h; y++) + { + bptr = buf; + for (x = 0; x < im->w; x++) + { + bptr[0] = ((*ptr) >> 16) & 0xff; + bptr[1] = ((*ptr) >> 8) & 0xff; + bptr[2] = ((*ptr)) & 0xff; + bptr += 3; + ptr++; + } + fwrite(buf, im->w * 3, 1, f); + if (progress) + { + char per; + int l; + + per = (char) ((100 * y) / im->h); + if (((per - pper) >= progress_granularity) || (y == (im->h - 1))) + { + l = y - pl; + if (!progress(im, per, 0, (y - l), im->w, l)) + { + free(buf); + fclose(f); + return 2; + } + pper = per; + pl = y; + } + } + } + } /* finish off */ free(buf); fclose(f); @@ -768,19 +766,18 @@ save (ImlibImage *im, ImlibProgressFunction progress, progress = NULL; } -void -formats (ImlibLoader *l) -{ - char *list_formats[] = - { "pnm", "ppm", "pgm", "pbm", "pam" }; +void +formats(ImlibLoader * l) +{ + char *list_formats[] = { "pnm", "ppm", "pgm", "pbm", "pam" }; - { - int i; - - l->num_formats = (sizeof(list_formats) / sizeof (char *)); - l->formats = malloc(sizeof(char *) * l->num_formats); - for (i = 0; i < l->num_formats; i++) - l->formats[i] = strdup(list_formats[i]); - } + { + int i; + + l->num_formats = (sizeof(list_formats) / sizeof(char *)); + l->formats = malloc(sizeof(char *) * l->num_formats); + + for (i = 0; i < l->num_formats; i++) + l->formats[i] = strdup(list_formats[i]); + } } - diff --git a/loaders/loader_xpm.c b/loaders/loader_xpm.c index 92b2455..f2178b1 100644 --- a/loaders/loader_xpm.c +++ b/loaders/loader_xpm.c @@ -102,7 +102,6 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, int pc, c, i, j, k, w, h, ncolors, cpp, comment, transp, quote, context, len, done, r, g, b; char *line, s[256], tok[128], col[256]; - XColor xcol; int lsz = 256; struct _cmap { @@ -112,7 +111,7 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, } *cmap; short lookup[128 - 32][128 - 32]; - float per = 0.0, per_inc; + float per = 0.0, per_inc = 0.0; int last_per = 0, last_y = 0; done = 0; diff --git a/src/api.c b/src/api.c index 768ac75..56f70c5 100644 --- a/src/api.c +++ b/src/api.c @@ -1741,7 +1741,6 @@ int imlib_get_text_inset(const char *text) { ImlibFont *fn; - int w, h; CHECK_PARAM_POINTER_RETURN("imlib_get_text_advance", "font", ctxt_font, 0); CHECK_PARAM_POINTER_RETURN("imlib_get_text_advance", "text", text, 0); diff --git a/src/dynamic_filters.c b/src/dynamic_filters.c index 98bcb1a..de664d8 100644 --- a/src/dynamic_filters.c +++ b/src/dynamic_filters.c @@ -31,7 +31,6 @@ pImlibExternalFilter __imlib_LoadFilter( char *file ) { ImlibExternalFilter *ptr; struct imlib_filter_info *info; - int i = 0; printf( "Loading filter %s\n", file ); MALLOCSHOW; @@ -78,7 +77,7 @@ pImlibExternalFilter __imlib_LoadFilter( char *file ) return ptr; } -void __imlib_dynamic_filters_init() +static void __imlib_dynamic_filters_init() { char **list; int num_filters, i = 0; @@ -118,7 +117,7 @@ void __imlib_dynamic_filters_init() } } -void __imlib_dynamic_filters_deinit() +static void __imlib_dynamic_filters_deinit() { } diff --git a/src/filter.c b/src/filter.c index d4bebcc..56336e6 100644 --- a/src/filter.c +++ b/src/filter.c @@ -168,7 +168,6 @@ void __imlib_FilterImage(ImlibImage *im, ImlibFilter *fil) { int x, y, a, r, g, b, ad, rd, gd, bd; - ImlibFilterPixel *pix; DATA32 *data, *p1, *p2; data = malloc(im->w * im->h * sizeof(DATA32)); diff --git a/src/rend.c b/src/rend.c index 7105750..4549e9e 100644 --- a/src/rend.c +++ b/src/rend.c @@ -17,6 +17,10 @@ /* size of the lines per segment we scale / render at a time */ #define LINESIZE 16 +void +__imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy, + XImage *xim, Visual *v, Context *ct); + void __imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy, XImage *xim, Visual *v, Context *ct) @@ -132,7 +136,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im, int psx, psy, psw, psh; int actual_depth = 0; char shm = 0; - ImlibRGBAFunction rgbaer, masker; + ImlibRGBAFunction rgbaer, masker = NULL; ImlibBlendFunction blender = NULL; int do_mmx; diff --git a/src/scale.c b/src/scale.c index b092520..8053a42 100644 --- a/src/scale.c +++ b/src/scale.c @@ -137,7 +137,7 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2) static int * __imlib_CalcApoints(int s, int d, int b1, int b2, int up) { - int *p, i, v, j = 0, rv = 0; + int *p, i, j = 0, rv = 0; if (d < 0) { rv = 1; @@ -303,7 +303,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow) { DATA32 *sptr, *dptr; - int x, y, i, j, end; + int x, y, end; DATA32 **ypoints = isi->ypoints; int *xpoints = isi->xpoints; int *xapoints = isi->xapoints; @@ -380,7 +380,6 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, for (x = dxx; x < end; x++) { int r, g, b, a; - int rr, gg, bb, aa; DATA32 *pix; if (XAP > 0) @@ -948,7 +947,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow) { DATA32 *sptr, *dptr; - int x, y, i, j, end; + int x, y, end; DATA32 **ypoints = isi->ypoints; int *xpoints = isi->xpoints; int *xapoints = isi->xapoints; @@ -1017,7 +1016,6 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, for (x = dxx; x < end; x++) { int r = 0, g = 0, b = 0; - int rr = 0, gg = 0, bb = 0; DATA32 *pix; if (XAP > 0) diff --git a/src/script.c b/src/script.c index 72c17c6..de5ab01 100644 --- a/src/script.c +++ b/src/script.c @@ -30,14 +30,14 @@ IVariable *vars, *current_var, *curtail; -int __imlib_find_string( char *haystack, char *needle ) +static int __imlib_find_string( char *haystack, char *needle ) { if( strstr( haystack, needle ) != NULL ) return ( strstr( haystack, needle ) - haystack ); return 0; } -char *__imlib_stripwhitespace( char *str ) +static char *__imlib_stripwhitespace( char *str ) { int i, strt = 0, in_quote = 0; char *tmpstr = calloc( strlen(str)+1, sizeof(char) ); @@ -53,7 +53,7 @@ char *__imlib_stripwhitespace( char *str ) return str; } -char *__imlib_copystr( char *str, int start, int end ) +static char *__imlib_copystr( char *str, int start, int end ) { int i = 0; char *rstr = calloc( 1024, sizeof( char ) ); @@ -66,7 +66,7 @@ char *__imlib_copystr( char *str, int start, int end ) return NULL; } -void __imlib_script_tidyup_params( IFunctionParam *param ) +static void __imlib_script_tidyup_params( IFunctionParam *param ) { if( param->next ){ __imlib_script_tidyup_params( param->next ); @@ -77,10 +77,40 @@ void __imlib_script_tidyup_params( IFunctionParam *param ) free( param ); } +static void __imlib_script_delete_variable( IVariable *var ) +{ + if( var->next != NULL ) + __imlib_script_delete_variable( var->next ); + free( var ); +} + +void __imlib_script_tidyup(void) +{ + __imlib_script_delete_variable( vars ); +} + +void *__imlib_script_get_next_var(void) +{ + if( current_var != NULL ) + current_var = current_var->next; + if( current_var != NULL ) + return current_var->ptr; + else + return NULL; +} + +void __imlib_script_add_var( void *ptr ) +{ + curtail->next = malloc( sizeof( IVariable ) ); + curtail = curtail->next; + curtail->ptr = ptr; + curtail->next = NULL; +} + IFunctionParam *__imlib_script_parse_parameters( Imlib_Image im, char *parameters ) { int i = 0, in_quote = 0, depth=0, start=0, value_start=0; - char *key = NULL, *value = NULL; + char *value = NULL; IFunctionParam *rootptr, *ptr; D( "(--) ===> Entering __imlib_script_parse_parameters()" ); @@ -181,9 +211,7 @@ Imlib_Image __imlib_script_parse_function( Imlib_Image im, char *function ) Imlib_Image __imlib_script_parse( Imlib_Image im, char *script, va_list param_list ) { int i = 0, in_quote = 0, start = 0, depth = 0; - char *scriptbuf = NULL, *function, *paramstr; - IFunction *func = NULL; - IFunctionParam *params = NULL; + char *scriptbuf = NULL, *function; D( "(--) Script Parser Start." ); if( script != NULL && strlen(script) > 0 ) @@ -237,32 +265,3 @@ Imlib_Image __imlib_script_parse( Imlib_Image im, char *script, va_list param_li } } -void __imlib_script_delete_variable( IVariable *var ) -{ - if( var->next != NULL ) - __imlib_script_delete_variable( var->next ); - free( var ); -} - -void __imlib_script_tidyup() -{ - __imlib_script_delete_variable( vars ); -} - -void *__imlib_script_get_next_var() -{ - if( current_var != NULL ) - current_var = current_var->next; - if( current_var != NULL ) - return current_var->ptr; - else - return NULL; -} - -void __imlib_script_add_var( void *ptr ) -{ - curtail->next = malloc( sizeof( IVariable ) ); - curtail = curtail->next; - curtail->ptr = ptr; - curtail->next = NULL; -} diff --git a/src/script.h b/src/script.h index b193401..6c266f9 100644 --- a/src/script.h +++ b/src/script.h @@ -57,8 +57,8 @@ typedef struct _imlib_variable Imlib_Image __imlib_script_parse( Imlib_Image im, char *script, va_list ); IFunctionParam *__imlib_script_parse_parameters( Imlib_Image im, char *parameters ); Imlib_Image __imlib_script_parse_function( Imlib_Image im, char *function ); -void __imlib_script_tidyup(); -void *__imlib_script_get_next_var(); +void __imlib_script_tidyup(void); +void *__imlib_script_get_next_var(void); void __imlib_script_add_var( void *ptr ); #endif /* _FUNCTION_H_ */