summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2011-04-09 09:24:44 +0000
committerKim Woelders <kim@woelders.dk>2011-04-09 09:24:44 +0000
commit41c3a967d03321166fb6194921dbdee3e31856e6 (patch)
treef5963ef4a0f4f297890660c38f328c420e0aab3d
parent4c55d2c3f63771519d0a610dca0b7ccf0ef17133 (diff)
downloadimlib2-41c3a967d03321166fb6194921dbdee3e31856e6.tar.gz
Indent (most) .c files.
SVN revision: 58518
-rw-r--r--src/bin/imlib2_bumpmap.c38
-rw-r--r--src/bin/imlib2_colorspace.c45
-rw-r--r--src/bin/imlib2_grab.c13
-rw-r--r--src/bin/imlib2_poly.c55
-rw-r--r--src/bin/imlib2_show.c324
-rw-r--r--src/bin/imlib2_test.c135
-rw-r--r--src/lib/api.c2
-rw-r--r--src/lib/blend.c4
-rw-r--r--src/lib/color.c1
-rw-r--r--src/lib/grab.c4
-rw-r--r--src/lib/image.c2
-rw-r--r--src/lib/rend.c8
-rw-r--r--src/lib/rgba.c12
-rw-r--r--src/lib/rgbadraw.c24
-rw-r--r--src/lib/script.c6
-rw-r--r--src/lib/span.c6
-rw-r--r--src/modules/filters/filter_bumpmap.c4
-rw-r--r--src/modules/filters/filter_colormod.c2
-rw-r--r--src/modules/filters/filter_test.c4
-rw-r--r--src/modules/loaders/loader_argb.c4
-rw-r--r--src/modules/loaders/loader_bmp.c384
-rw-r--r--src/modules/loaders/loader_bz2.c200
-rw-r--r--src/modules/loaders/loader_gif.c9
-rw-r--r--src/modules/loaders/loader_id3.c974
-rw-r--r--src/modules/loaders/loader_jpeg.c18
-rw-r--r--src/modules/loaders/loader_lbm.c806
-rw-r--r--src/modules/loaders/loader_png.c94
-rw-r--r--src/modules/loaders/loader_pnm.c1122
-rw-r--r--src/modules/loaders/loader_tga.c297
-rw-r--r--src/modules/loaders/loader_zlib.c210
30 files changed, 2532 insertions, 2275 deletions
diff --git a/src/bin/imlib2_bumpmap.c b/src/bin/imlib2_bumpmap.c
index c1ab30d..16fb6f2 100644
--- a/src/bin/imlib2_bumpmap.c
+++ b/src/bin/imlib2_bumpmap.c
@@ -45,19 +45,18 @@ main(int argc, char **argv)
* First tests to determine which rendering task to perform
*/
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
- win =
- XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
- 0);
+ win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
+ 0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask);
@@ -74,8 +73,8 @@ main(int argc, char **argv)
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
- im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");
- im = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");
+ im_bg = imlib_load_image(PACKAGE_DATA_DIR "/data/images/imlib2.png");
+ im = imlib_load_image(PACKAGE_DATA_DIR "/data/images/imlib2.png");
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
@@ -96,16 +95,16 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
- case Expose:
- break;
- case ButtonRelease:
- exit(0);
- break;
- case MotionNotify:
- x = ev.xmotion.x;
- y = ev.xmotion.y;
- default:
- break;
+ case Expose:
+ break;
+ case ButtonRelease:
+ exit(0);
+ break;
+ case MotionNotify:
+ x = ev.xmotion.x;
+ y = ev.xmotion.y;
+ default:
+ break;
}
}
@@ -122,7 +121,8 @@ main(int argc, char **argv)
* first = 0; */
imlib_apply_filter
- ("bump_map_point(x=[],y=[],map="PACKAGE_DATA_DIR"/data/images/imlib2.png);", &x, &y);
+ ("bump_map_point(x=[],y=[],map=" PACKAGE_DATA_DIR
+ "/data/images/imlib2.png);", &x, &y);
temp2 = im_bg;
im_bg = temp;
diff --git a/src/bin/imlib2_colorspace.c b/src/bin/imlib2_colorspace.c
index bd9e5e0..8f704c9 100644
--- a/src/bin/imlib2_colorspace.c
+++ b/src/bin/imlib2_colorspace.c
@@ -35,19 +35,18 @@ main(int argc, char **argv)
* First tests to determine which rendering task to perform
*/
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
- win =
- XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
- 0);
+ win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
+ 0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);
@@ -56,7 +55,7 @@ main(int argc, char **argv)
* Start rendering
*/
imlib_set_font_cache_size(512 * 1024);
- imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
+ imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts");
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
@@ -83,22 +82,22 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
- case ButtonRelease:
- exit(0);
- break;
- case KeyPress:
- XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
- NULL);
- switch (*kbuf)
- {
- case 'q':
- exit(0);
- default:
- break;
- }
- break;
- default:
- break;
+ case ButtonRelease:
+ exit(0);
+ break;
+ case KeyPress:
+ XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
+ NULL);
+ switch (*kbuf)
+ {
+ case 'q':
+ exit(0);
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
}
}
diff --git a/src/bin/imlib2_grab.c b/src/bin/imlib2_grab.c
index 58ee6ba..6333474 100644
--- a/src/bin/imlib2_grab.c
+++ b/src/bin/imlib2_grab.c
@@ -23,7 +23,8 @@ int image_width = 0, image_height = 0;
static void
usage(void)
{
- printf("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] [-height <height>] [-noshape] <output file>\n");
+ printf
+ ("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] [-height <height>] [-noshape] <output file>\n");
}
int
@@ -102,12 +103,12 @@ main(int argc, char **argv)
file = argv[0];
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
@@ -123,9 +124,9 @@ main(int argc, char **argv)
XGetGeometry(disp, draw, &rr, &x, &y, &w, &h, &bw, &depth);
if (wo == 0)
- wo = w;
+ wo = w;
if (ho == 0)
- ho = h;
+ ho = h;
if (verbose)
{
printf("Drawable: %#lx: x,y: %d,%d wxh=%ux%u bw=%u depth=%u\n",
diff --git a/src/bin/imlib2_poly.c b/src/bin/imlib2_poly.c
index cb53548..6833828 100644
--- a/src/bin/imlib2_poly.c
+++ b/src/bin/imlib2_poly.c
@@ -34,19 +34,18 @@ main(int argc, char **argv)
* First tests to determine which rendering task to perform
*/
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
- win =
- XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
- 0);
+ win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
+ 0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);
@@ -96,28 +95,28 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
- case ButtonRelease:
- exit(0);
- break;
- case KeyPress:
- XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
- NULL);
- switch (*kbuf)
- {
- case ' ':
- imlib_context_set_anti_alias
- (!imlib_context_get_anti_alias());
- printf("AA is %s\n",
- imlib_context_get_anti_alias()? "on" : "off");
- break;
- case 'q':
- exit(0);
- default:
- break;
- }
- break;
- default:
- break;
+ case ButtonRelease:
+ exit(0);
+ break;
+ case KeyPress:
+ XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
+ NULL);
+ switch (*kbuf)
+ {
+ case ' ':
+ imlib_context_set_anti_alias
+ (!imlib_context_get_anti_alias());
+ printf("AA is %s\n",
+ imlib_context_get_anti_alias()? "on" : "off");
+ break;
+ case 'q':
+ exit(0);
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
}
}
diff --git a/src/bin/imlib2_show.c b/src/bin/imlib2_show.c
index 025aa56..91430d1 100644
--- a/src/bin/imlib2_show.c
+++ b/src/bin/imlib2_show.c
@@ -110,33 +110,33 @@ main(int argc, char **argv)
printf("-up\t\tWhen doing scal test scale up, not down.\n");
printf("-both\t\tScale horizontally AND vertically in scale test.\n");
printf
- ("-orig\t\tKeep original width and height in each pass of scale test.\n");
+ ("-orig\t\tKeep original width and height in each pass of scale test.\n");
printf("-blend\t\tBlending test.\n");
printf("-dither\t\tTurn dithering on for depths < 24bpp\n");
printf("-colormod <r> <g> <b> <a>\t\tSet up color mod tables\n");
printf("-scale\t\tScale test.\n");
printf("-noloop\t\tDont loop - timing test.\n");
printf
- ("-rotate\t\tAlso rotate background image with mouse in interative test.\n");
+ ("-rotate\t\tAlso rotate background image with mouse in interative test.\n");
printf("-size <w> <h>\t\tScale from w x h down in scaling test.\n"); // require parameters w / h
printf("-maxcolors <n>\t\tLimit color allocation count to n colors.\n"); // require parameter nb colors
printf
- ("-text\t\tDisplays the text following this option. Need a loaded font.\n");
+ ("-text\t\tDisplays the text following this option. Need a loaded font.\n");
printf
- ("-font\t\tLoads a font. The parameter must follow the police_name/size format. Example: loading the grunge font at size 18 is : grunge/18.\n\t\tThe XFD font also can be specified. Ex. 'notepad/32,-*--24-*'.\n");
+ ("-font\t\tLoads a font. The parameter must follow the police_name/size format. Example: loading the grunge font at size 18 is : grunge/18.\n\t\tThe XFD font also can be specified. Ex. 'notepad/32,-*--24-*'.\n");
printf("-poly\t\tPerforms a poly test\n");
printf("The following options requires a file to work properly.\n");
printf("-textdir\t\tText Direction. 0: L to R, 1: R to L\n");
printf(" 2: U to D, 3: D to U, 4: angle\n");
printf("-xfdtest\t\tXFD Font queue test.\n");
printf
- ("-xfdcachetest <f> [<l>]\t\tXFD tFont cache test.\n\t\tThe file f is drawn l times\n");
+ ("-xfdcachetest <f> [<l>]\t\tXFD tFont cache test.\n\t\tThe file f is drawn l times\n");
printf("-blast\t\tDisplays the file.\n");
printf("-loop\t\tScales down the image.\n");
printf("-blendtest\tPerforms a blending test on the file.\n");
printf("-rotatetest\tPerforms a rotate test on the file.\n");
printf
- ("-filter\t\tPerforms filtering. Possible filters are,\n\t\t\t1:Blur filter, 2:Sharpen filter, 3:Color blur filter, \n\t\t\t4:Emboss filter, 5:Grayscale filter, 6:Saturation filter,\n\t\t\t7:Edge detection filter.\n");
+ ("-filter\t\tPerforms filtering. Possible filters are,\n\t\t\t1:Blur filter, 2:Sharpen filter, 3:Color blur filter, \n\t\t\t4:Emboss filter, 5:Grayscale filter, 6:Saturation filter,\n\t\t\t7:Edge detection filter.\n");
printf("-bmp2pt\t\tPerformas Bump Mapping to a point\n");
return 0;
}
@@ -265,13 +265,14 @@ main(int argc, char **argv)
if (!blendtest)
{
const char *display_name = getenv("DISPLAY");
+
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
@@ -286,8 +287,8 @@ main(int argc, char **argv)
else
{
win =
- XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10,
- 10, 0, 0, 0);
+ XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10,
+ 10, 0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
| PointerMotionMask | ExposureMask);
@@ -381,7 +382,7 @@ main(int argc, char **argv)
if (file)
im_bg = imlib_load_image(file);
else
- im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bg.png");
+ im_bg = imlib_load_image(PACKAGE_DATA_DIR "/data/images/bg.png");
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
h = imlib_image_get_height();
@@ -406,9 +407,9 @@ main(int argc, char **argv)
double xx, yy;
xx = (w / 2) +
- (cos(a) * points[i][0]) + (cos(a + A90) * points[i][1]);
+ (cos(a) * points[i][0]) + (cos(a + A90) * points[i][1]);
yy = (h / 2) +
- (sin(a) * points[i][0]) + (sin(a + A90) * points[i][1]);
+ (sin(a) * points[i][0]) + (sin(a + A90) * points[i][1]);
imlib_polygon_add_point(poly, xx, yy);
}
printf("draw angle %3.3f\n", a);
@@ -482,9 +483,9 @@ main(int argc, char **argv)
Imlib_Image im_tmp;
im_tmp =
- imlib_create_cropped_scaled_image(0, 0, w, h, w,
- (((i) * h) /
- w));
+ imlib_create_cropped_scaled_image(0, 0, w, h, w,
+ (((i) * h) /
+ w));
if (im_tmp)
{
imlib_context_set_image(im_tmp);
@@ -498,9 +499,9 @@ main(int argc, char **argv)
Imlib_Image im_tmp;
im_tmp =
- imlib_create_cropped_scaled_image(0, 0, w, h, w,
- (((i) * h) /
- w));
+ imlib_create_cropped_scaled_image(0, 0, w, h, w,
+ (((i) * h) /
+ w));
if (im_tmp)
{
imlib_context_set_image(im_tmp);
@@ -521,8 +522,8 @@ main(int argc, char **argv)
Imlib_Image im_tmp;
im_tmp =
- imlib_create_cropped_scaled_image(0, 0, w, h,
- 2 * w - i, h);
+ imlib_create_cropped_scaled_image(0, 0, w, h,
+ 2 * w - i, h);
if (im_tmp)
{
imlib_context_set_image(im_tmp);
@@ -547,10 +548,10 @@ main(int argc, char **argv)
Imlib_Image im_tmp;
im_tmp =
- imlib_create_cropped_scaled_image(0, 0, w, h,
- 2 * w - i,
- (((i) * h) /
- w));
+ imlib_create_cropped_scaled_image(0, 0, w, h,
+ 2 * w - i,
+ (((i) * h) /
+ w));
if (im_tmp)
{
imlib_context_set_image(im_tmp);
@@ -616,7 +617,7 @@ main(int argc, char **argv)
* pixels += (2 * w - i) * (((i) * h) / w);
* }
* }
- * } */// end if loop
+ * } */// end if loop
else if (blendtest)
{
Imlib_Image im2;
@@ -704,74 +705,74 @@ main(int argc, char **argv)
imlib_context_set_filter(imlib_create_filter(0));
switch (filter)
{
- default:
- case 1:
- /*\ Blur filter \ */
- imlib_filter_set(0, 0, 0, 8, 8, 8);
- imlib_filter_set(-1, 0, 0, 4, 4, 4);
- imlib_filter_set(0, -1, 0, 4, 4, 4);
- imlib_filter_set(1, 0, 0, 4, 4, 4);
- imlib_filter_set(0, 1, 0, 4, 4, 4);
- imlib_filter_set(-2, 0, 0, 1, 1, 1);
- imlib_filter_set(0, -2, 0, 1, 1, 1);
- imlib_filter_set(2, 0, 0, 1, 1, 1);
- imlib_filter_set(0, 2, 0, 1, 1, 1);
- imlib_filter_set(-1, -1, 0, 1, 1, 1);
- imlib_filter_set(-1, 1, 0, 1, 1, 1);
- imlib_filter_set(1, -1, 0, 1, 1, 1);
- imlib_filter_set(1, 1, 0, 1, 1, 1);
- break;
- case 2:
- /*\ Sharpen filter \ */
- imlib_filter_set(0, 0, 0, 5, 5, 5);
- imlib_filter_set(-1, 0, 0, -1, -1, -1);
- imlib_filter_set(0, -1, 0, -1, -1, -1);
- imlib_filter_set(1, 0, 0, -1, -1, -1);
- imlib_filter_set(0, 1, 0, -1, -1, -1);
- break;
- case 3:
- /*\ Color blur filter \ */
- imlib_filter_set(0, 0, 0, 3, 3, 3);
- imlib_filter_set(-1, -1, 0, 1, 0, 0);
- imlib_filter_set(1, -1, 0, 0, 1, 0);
- imlib_filter_set(0, 1, 0, 0, 0, 1);
- break;
- case 4:
- /*\ Emboss filter \ */
- imlib_filter_set_red(-1, -1, 0, -1, -1, -1);
- imlib_filter_set_red(0, 0, 0, 1, 1, 1);
- imlib_filter_set_green(-1, -1, 0, -1, -1, -1);
- imlib_filter_set_green(0, 0, 0, 1, 1, 1);
- imlib_filter_set_blue(-1, -1, 0, -1, -1, -1);
- imlib_filter_set_blue(0, 0, 0, 1, 1, 1);
-
- imlib_filter_constants(0, 768, 768, 768);
- imlib_filter_divisors(0, 6, 6, 6);
- break;
- case 5:
- /*\ Grayscale filter \ */
- imlib_filter_set_red(0, 0, 0, 80, 1, 1);
- imlib_filter_set_green(0, 0, 0, 1, 80, 1);
- imlib_filter_set_blue(0, 0, 0, 1, 1, 80);
- break;
- case 6:
- /*\ Saturation filter \ */
- imlib_filter_set_red(0, 0, 0, 80, -1, -1);
- imlib_filter_set_green(0, 0, 0, -1, 80, -1);
- imlib_filter_set_blue(0, 0, 0, -1, -1, 80);
- break;
- case 7:
- /*\ Edge detection filter \ */
- imlib_filter_set(-1, -1, 0, -1, -1, -1);
- imlib_filter_set(-1, 0, 0, -3, -3, -3);
- imlib_filter_set(-1, 1, 0, -1, -1, -1);
- imlib_filter_set(0, -1, 0, -3, -3, -3);
- imlib_filter_set(0, 0, 0, 16, 16, 16);
- imlib_filter_set(0, 1, 0, -3, -3, -3);
- imlib_filter_set(1, -1, 0, -1, -1, -1);
- imlib_filter_set(1, 0, 0, -3, -3, -3);
- imlib_filter_set(1, 1, 0, -1, -1, -1);
- imlib_filter_divisors(0, 3, 3, 3);
+ default:
+ case 1:
+ /*\ Blur filter \ */
+ imlib_filter_set(0, 0, 0, 8, 8, 8);
+ imlib_filter_set(-1, 0, 0, 4, 4, 4);
+ imlib_filter_set(0, -1, 0, 4, 4, 4);
+ imlib_filter_set(1, 0, 0, 4, 4, 4);
+ imlib_filter_set(0, 1, 0, 4, 4, 4);
+ imlib_filter_set(-2, 0, 0, 1, 1, 1);
+ imlib_filter_set(0, -2, 0, 1, 1, 1);
+ imlib_filter_set(2, 0, 0, 1, 1, 1);
+ imlib_filter_set(0, 2, 0, 1, 1, 1);
+ imlib_filter_set(-1, -1, 0, 1, 1, 1);
+ imlib_filter_set(-1, 1, 0, 1, 1, 1);
+ imlib_filter_set(1, -1, 0, 1, 1, 1);
+ imlib_filter_set(1, 1, 0, 1, 1, 1);
+ break;
+ case 2:
+ /*\ Sharpen filter \ */
+ imlib_filter_set(0, 0, 0, 5, 5, 5);
+ imlib_filter_set(-1, 0, 0, -1, -1, -1);
+ imlib_filter_set(0, -1, 0, -1, -1, -1);
+ imlib_filter_set(1, 0, 0, -1, -1, -1);
+ imlib_filter_set(0, 1, 0, -1, -1, -1);
+ break;
+ case 3:
+ /*\ Color blur filter \ */
+ imlib_filter_set(0, 0, 0, 3, 3, 3);
+ imlib_filter_set(-1, -1, 0, 1, 0, 0);
+ imlib_filter_set(1, -1, 0, 0, 1, 0);
+ imlib_filter_set(0, 1, 0, 0, 0, 1);
+ break;
+ case 4:
+ /*\ Emboss filter \ */
+ imlib_filter_set_red(-1, -1, 0, -1, -1, -1);
+ imlib_filter_set_red(0, 0, 0, 1, 1, 1);
+ imlib_filter_set_green(-1, -1, 0, -1, -1, -1);
+ imlib_filter_set_green(0, 0, 0, 1, 1, 1);
+ imlib_filter_set_blue(-1, -1, 0, -1, -1, -1);
+ imlib_filter_set_blue(0, 0, 0, 1, 1, 1);
+
+ imlib_filter_constants(0, 768, 768, 768);
+ imlib_filter_divisors(0, 6, 6, 6);
+ break;
+ case 5:
+ /*\ Grayscale filter \ */
+ imlib_filter_set_red(0, 0, 0, 80, 1, 1);
+ imlib_filter_set_green(0, 0, 0, 1, 80, 1);
+ imlib_filter_set_blue(0, 0, 0, 1, 1, 80);
+ break;
+ case 6:
+ /*\ Saturation filter \ */
+ imlib_filter_set_red(0, 0, 0, 80, -1, -1);
+ imlib_filter_set_green(0, 0, 0, -1, 80, -1);
+ imlib_filter_set_blue(0, 0, 0, -1, -1, 80);
+ break;
+ case 7:
+ /*\ Edge detection filter \ */
+ imlib_filter_set(-1, -1, 0, -1, -1, -1);
+ imlib_filter_set(-1, 0, 0, -3, -3, -3);
+ imlib_filter_set(-1, 1, 0, -1, -1, -1);
+ imlib_filter_set(0, -1, 0, -3, -3, -3);
+ imlib_filter_set(0, 0, 0, 16, 16, 16);
+ imlib_filter_set(0, 1, 0, -3, -3, -3);
+ imlib_filter_set(1, -1, 0, -1, -1, -1);
+ imlib_filter_set(1, 0, 0, -3, -3, -3);
+ imlib_filter_set(1, 1, 0, -1, -1, -1);
+ imlib_filter_divisors(0, 3, 3, 3);
}
pixels = 0;
imlib_render_image_on_drawable_at_size(0, 0, w, h);
@@ -812,7 +813,7 @@ main(int argc, char **argv)
/* "ARIAL/30" "COMIC/30" "IMPACT/30" "Prole/30" "Proteron/30" */
/* "TIMES/30" "badacid/30" "bajoran/30" "bigfish/30" */
- imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
+ imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts");
if (xfdtest)
{
@@ -823,10 +824,10 @@ main(int argc, char **argv)
f, f->next, f->type, f->ref, f->name);
imlib_context_set_font((Imlib_Font) f);
printf
- ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
- imlib_get_font_ascent(), imlib_get_font_descent(),
- imlib_get_maximum_font_ascent(),
- imlib_get_maximum_font_descent());
+ ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
+ imlib_get_font_ascent(), imlib_get_font_descent(),
+ imlib_get_maximum_font_ascent(),
+ imlib_get_maximum_font_descent());
imlib_free_font();
printf("imlib_free_font: f=%p, next=%p, type=%d, ref=%d, '%s'\n",
f, f->next, f->type, f->ref, f->name);
@@ -837,10 +838,10 @@ main(int argc, char **argv)
f, f->next, f->type, f->ref, f->name);
imlib_context_set_font((Imlib_Font) f);
printf
- ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
- imlib_get_font_ascent(), imlib_get_font_descent(),
- imlib_get_maximum_font_ascent(),
- imlib_get_maximum_font_descent());
+ ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
+ imlib_get_font_ascent(), imlib_get_font_descent(),
+ imlib_get_maximum_font_ascent(),
+ imlib_get_maximum_font_descent());
imlib_free_font();
printf("imlib_free_font: f=%p, next=%p, type=%d, ref=%d, '%s'\n",
f, f->next, f->type, f->ref, f->name);
@@ -900,10 +901,10 @@ main(int argc, char **argv)
f, f->next, f->type, f->ref, f->name);
imlib_context_set_font((Imlib_Font) f1);
printf
- ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
- imlib_get_font_ascent(), imlib_get_font_descent(),
- imlib_get_maximum_font_ascent(),
- imlib_get_maximum_font_descent());
+ ("\t\t ascent=%d, descent=%d, max_ascent=%d, max_descent=%d\n",
+ imlib_get_font_ascent(), imlib_get_font_descent(),
+ imlib_get_maximum_font_ascent(),
+ imlib_get_maximum_font_descent());
printf("Font Cache test end\n");
}
@@ -932,7 +933,7 @@ main(int argc, char **argv)
if (file)
im_bg = imlib_load_image(file);
else
- im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bg.png");
+ im_bg = imlib_load_image(PACKAGE_DATA_DIR "/data/images/bg.png");
imlib_context_set_image(im_bg);
im_tmp = imlib_clone_image();
w = imlib_image_get_width();
@@ -958,47 +959,60 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
- case Expose:
- up = imlib_update_append_rect(up,
- ev.xexpose.x,
- ev.xexpose.y,
- ev.xexpose.width,
- ev.xexpose.height);
- break;
- case ButtonRelease:
- if (fon)
- {
- imlib_context_set_font(fn);
- imlib_free_font();
- }
- exit(0);
- break;
- case MotionNotify:
- x = ev.xmotion.x;
- y = ev.xmotion.y;
- default:
- break;
+ case Expose:
+ up = imlib_update_append_rect(up,
+ ev.xexpose.x,
+ ev.xexpose.y,
+ ev.xexpose.width,
+ ev.xexpose.height);
+ break;
+ case ButtonRelease:
+ if (fon)
+ {
+ imlib_context_set_font(fn);
+ imlib_free_font();
+ }
+ exit(0);
+ break;
+ case MotionNotify:
+ x = ev.xmotion.x;
+ y = ev.xmotion.y;
+ default:
+ break;
}
}
while (XPending(disp));
- im_sh1 = imlib_load_image(PACKAGE_DATA_DIR"/data/images/sh1.png");
- im_sh2 = imlib_load_image(PACKAGE_DATA_DIR"/data/images/sh2.png");
- im_sh3 = imlib_load_image(PACKAGE_DATA_DIR"/data/images/sh3.png");
- im_ic[0] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/audio.png");
- im_ic[1] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/folder.png");
- im_ic[2] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
- im_ic[3] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/paper.png");
- im_ic[4] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mail.png");
- im_ic[5] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/calc.png");
- im_ic[6] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/cal.png");
- im_ic[7] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/stop.png");
- im_ic[8] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/globe.png");
- im_ic[9] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/menu.png");
- im_ic[10] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/tnt.png");
- im_ic[11] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bulb.png");
- im_ic[12] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/lock.png");
+ im_sh1 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh1.png");
+ im_sh2 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh2.png");
+ im_sh3 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh3.png");
+ im_ic[0] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/audio.png");
+ im_ic[1] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/folder.png");
+ im_ic[2] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/mush.png");
+ im_ic[3] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/paper.png");
+ im_ic[4] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/mail.png");
+ im_ic[5] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/calc.png");
+ im_ic[6] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/cal.png");
+ im_ic[7] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/stop.png");
+ im_ic[8] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/globe.png");
+ im_ic[9] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/menu.png");
+ im_ic[10] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/tnt.png");
+ im_ic[11] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/bulb.png");
+ im_ic[12] =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/lock.png");
imlib_context_set_image(im);
if (first)
@@ -1214,7 +1228,7 @@ main(int argc, char **argv)
else if (fon)
{
int retw, reth, tx, ty, nx, ny, cx, cy, cw,
- ch, cp;
+ ch, cp;
int cx2, cy2, cw2, ch2;
if (!str)
@@ -1242,15 +1256,15 @@ main(int argc, char **argv)
up = imlib_update_append_rect(up, tx, ty, retw, reth);
switch (textdir)
{
- case IMLIB_TEXT_TO_RIGHT:
- case IMLIB_TEXT_TO_LEFT:
- case IMLIB_TEXT_TO_ANGLE:
- ty += ny;
- break;
- case IMLIB_TEXT_TO_DOWN:
- case IMLIB_TEXT_TO_UP:
- tx += nx;
- break;
+ case IMLIB_TEXT_TO_RIGHT:
+ case IMLIB_TEXT_TO_LEFT:
+ case IMLIB_TEXT_TO_ANGLE:
+ ty += ny;
+ break;
+ case IMLIB_TEXT_TO_DOWN:
+ case IMLIB_TEXT_TO_UP:
+ tx += nx;
+ break;
}
}
cp = imlib_text_get_index_and_location(str, x - 50, y - 50,
diff --git a/src/bin/imlib2_test.c b/src/bin/imlib2_test.c
index 2eae420..33a7c95 100644
--- a/src/bin/imlib2_test.c
+++ b/src/bin/imlib2_test.c
@@ -41,12 +41,12 @@ main(int argc, char **argv)
/* connect to X */
if (!display_name)
- display_name = ":0";
+ display_name = ":0";
disp = XOpenDisplay(display_name);
if (!disp)
{
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
+ fprintf(stderr, "Can't open display %s\n", display_name);
+ return 1;
}
/* get default visual , colormap etc. you could ask imlib2 for what it */
/* thinks is the best, but this example is intended to be simple */
@@ -68,7 +68,7 @@ main(int argc, char **argv)
imlib_set_font_cache_size(512 * 1024);
/* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */
/* in that dir for the text to display */
- imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
+ imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts");
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
/* dither for depths < 24bpp */
@@ -95,70 +95,71 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
- case Expose:
- /* window rectangle was exposed - add it to the list of */
- /* rectangles we need to re-render */
- updates = imlib_update_append_rect(updates,
- ev.xexpose.x,
- ev.xexpose.y,
- ev.xexpose.width,
- ev.xexpose.height);
- break;
- case ButtonPress:
- /* if we click anywhere in the window, exit */
- exit(0);
- break;
- case MotionNotify:
- /* if the mouse moves - note it */
- /* add a rectangle update for the new mouse position */
- image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
- imlib_context_set_image(image);
- w = imlib_image_get_width();
- h = imlib_image_get_height();
- imlib_context_set_image(image);
- imlib_free_image();
- /* the old position - so we wipe over where it used to be */
- updates = imlib_update_append_rect(updates,
- mouse_x - (w / 2),
- mouse_y - (h / 2), w, h);
- font = imlib_load_font("notepad/30");
- if (font)
- {
- char text[4096];
+ case Expose:
+ /* window rectangle was exposed - add it to the list of */
+ /* rectangles we need to re-render */
+ updates = imlib_update_append_rect(updates,
+ ev.xexpose.x,
+ ev.xexpose.y,
+ ev.xexpose.width,
+ ev.xexpose.height);
+ break;
+ case ButtonPress:
+ /* if we click anywhere in the window, exit */
+ exit(0);
+ break;
+ case MotionNotify:
+ /* if the mouse moves - note it */
+ /* add a rectangle update for the new mouse position */
+ image =
+ imlib_load_image(PACKAGE_DATA_DIR "/data/images/mush.png");
+ imlib_context_set_image(image);
+ w = imlib_image_get_width();
+ h = imlib_image_get_height();
+ imlib_context_set_image(image);
+ imlib_free_image();
+ /* the old position - so we wipe over where it used to be */
+ updates = imlib_update_append_rect(updates,
+ mouse_x - (w / 2),
+ mouse_y - (h / 2), w, h);
+ font = imlib_load_font("notepad/30");
+ if (font)
+ {
+ char text[4096];
- imlib_context_set_font(font);
- sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
- imlib_get_text_size(text, &text_w, &text_h);
- imlib_free_font();
- updates = imlib_update_append_rect(updates,
- 320 - (text_w / 2),
- 240 - (text_h / 2),
- text_w, text_h);
- }
+ imlib_context_set_font(font);
+ sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
+ imlib_get_text_size(text, &text_w, &text_h);
+ imlib_free_font();
+ updates = imlib_update_append_rect(updates,
+ 320 - (text_w / 2),
+ 240 - (text_h / 2),
+ text_w, text_h);
+ }
- mouse_x = ev.xmotion.x;
- mouse_y = ev.xmotion.y;
- /* the new one */
- updates = imlib_update_append_rect(updates,
- mouse_x - (w / 2),
- mouse_y - (h / 2), w, h);
- font = imlib_load_font("notepad/30");
- if (font)
- {
- char text[4096];
+ mouse_x = ev.xmotion.x;
+ mouse_y = ev.xmotion.y;
+ /* the new one */
+ updates = imlib_update_append_rect(updates,
+ mouse_x - (w / 2),
+ mouse_y - (h / 2), w, h);
+ font = imlib_load_font("notepad/30");
+ if (font)
+ {
+ char text[4096];
- imlib_context_set_font(font);
- sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
- imlib_get_text_size(text, &text_w, &text_h);
- imlib_free_font();
- updates = imlib_update_append_rect(updates,
- 320 - (text_w / 2),
- 240 - (text_h / 2),
- text_w, text_h);
- }
- default:
- /* any other events - do nothing */
- break;
+ imlib_context_set_font(font);
+ sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
+ imlib_get_text_size(text, &text_w, &text_h);
+ imlib_free_font();
+ updates = imlib_update_append_rect(updates,
+ 320 - (text_w / 2),
+ 240 - (text_h / 2),
+ text_w, text_h);
+ }
+ default:
+ /* any other events - do nothing */
+ break;
}
}
while (XPending(disp));
@@ -187,7 +188,7 @@ main(int argc, char **argv)
/* fill the window background */
/* load the background image - you'll need to have some images */
/* in ./test_images lying around for this to actually work */
- image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bg.png");
+ image = imlib_load_image(PACKAGE_DATA_DIR "/data/images/bg.png");
/* we're working with this image now */
imlib_context_set_image(image);
/* get its size */
@@ -209,7 +210,7 @@ main(int argc, char **argv)
}
/* draw an icon centered around the mouse position */
- image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
+ image = imlib_load_image(PACKAGE_DATA_DIR "/data/images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
diff --git a/src/lib/api.c b/src/lib/api.c
index d04b49a..e53fa40 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -4,7 +4,7 @@
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#else
-# define X_DISPLAY_MISSING
+#define X_DISPLAY_MISSING
#endif
#include <string.h>
#include <stdarg.h>
diff --git a/src/lib/blend.c b/src/lib/blend.c
index de34e40..dab35ed 100644
--- a/src/lib/blend.c
+++ b/src/lib/blend.c
@@ -1722,7 +1722,7 @@ __imlib_GetBlendFunction(ImlibOp op, char blend, char merge_alpha, char rgb_src,
return NULL;
#ifdef DO_MMX_ASM
- do_mmx = !!(__imlib_get_cpuid() & CPUID_MMX);
+ do_mmx = ! !(__imlib_get_cpuid() & CPUID_MMX);
#elif DO_AMD64_ASM
do_mmx = 1; // instruction set is always present
#endif
@@ -1730,7 +1730,7 @@ __imlib_GetBlendFunction(ImlibOp op, char blend, char merge_alpha, char rgb_src,
blend = 0;
if (blend && cm && rgb_src && (A_CMOD(cm, 0xff) == 0))
return NULL;
- return ibfuncs[!!do_mmx][opi][!!cm][!!merge_alpha][!!rgb_src][!!blend];
+ return ibfuncs[! !do_mmx][opi][! !cm][! !merge_alpha][! !rgb_src][! !blend];
}
void
diff --git a/src/lib/color.c b/src/lib/color.c
index 9f6fb2e..3fecbda 100644
--- a/src/lib/color.c
+++ b/src/lib/color.c
@@ -33,6 +33,7 @@ __imlib_BestVisual(Display * d, int screen, int *depth_return)
XVisualInfo xvi, *xvir;
int j, i, num, maxd = 0;
Visual *v = NULL;
+
const int visprefs[] = {
PseudoColor, TrueColor, DirectColor, StaticColor, GrayScale, StaticGray
};
diff --git a/src/lib/grab.c b/src/lib/grab.c
index a649ed1..7734a55 100644
--- a/src/lib/grab.c
+++ b/src/lib/grab.c
@@ -668,7 +668,7 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
if (x_does_shm)
{
xim = __imlib_ShmGetXImage(d, v, p, xatt.depth, x, y, w, h, &shminfo);
- is_shm = !!xim;
+ is_shm = ! !xim;
}
if (!xim)
xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
@@ -683,7 +683,7 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
if ((m) && (domask))
{
mxim = __imlib_ShmGetXImage(d, v, m, 1, 0, 0, w, h, &mshminfo);
- is_mshm = !!mxim;
+ is_mshm = ! !mxim;
if (!mxim)
mxim = XGetImage(d, m, 0, 0, w, h, 0xffffffff, ZPixmap);
}
diff --git a/src/lib/image.c b/src/lib/image.c
index eaa2356..e1c064c 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -7,7 +7,7 @@
#include <ctype.h>
#include <errno.h>
#ifdef BUILD_X11
-# include <X11/Xlib.h>
+#include <X11/Xlib.h>
#endif
#include "image.h"
#include "file.h"
diff --git a/src/lib/rend.c b/src/lib/rend.c
index 1c1540f..d1927af 100644
--- a/src/lib/rend.c
+++ b/src/lib/rend.c
@@ -136,18 +136,14 @@ __imlib_RenderGetPixel(Display * d, Drawable w, Visual * v, Colormap cm,
return 0;
}
-__hidden void
- __imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
- XImage * xim, Visual * v,
- Context * ct);
-
-void
+static void
__imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
XImage * xim, Visual * v, Context * ct)
{
unsigned int x, y, r, g, b, val, hh;
unsigned int rmask, gmask, bmask;
int i, rshift, gshift, bshift;
+
const DATA8 _dither_88[8][8] = {
{0, 32, 8, 40, 2, 34, 10, 42},
{48, 16, 56, 24, 50, 18, 58, 26},
diff --git a/src/lib/rgba.c b/src/lib/rgba.c
index b05140b..8caae3b 100644
--- a/src/lib/rgba.c
+++ b/src/lib/rgba.c
@@ -2327,12 +2327,12 @@ dest += 2; src += 2; \
#if 0 /* Old fixed-threshold macros - Remove? */
#ifdef WORDS_BIGENDIAN
-# define WRITE1_RGBA_A1(src, dest) \
+#define WRITE1_RGBA_A1(src, dest) \
*dest |= ((*src & 0x80000000) >> (24 + (x & 0x7))); \
if ((x & 0x7) == 0x7) dest++; \
src++
#else
-# define WRITE1_RGBA_A1(src, dest) \
+#define WRITE1_RGBA_A1(src, dest) \
*dest |= ((*src & 0x80000000) >> (31 - (x & 0x7))); \
if ((x & 0x7) == 0x7) dest++; \
src++
@@ -2341,13 +2341,13 @@ src++
#else
#ifdef WORDS_BIGENDIAN
-# define WRITE1_RGBA_A1(src, dest, threshold) \
+#define WRITE1_RGBA_A1(src, dest, threshold) \
if ((*src >> 24) >= threshold) \
*dest |= (1 << (7 - (x & 0x7))); \
if ((x & 0x7) == 0x7) dest++; \
src++
#else
-# define WRITE1_RGBA_A1(src, dest, threshold) \
+#define WRITE1_RGBA_A1(src, dest, threshold) \
if ((*src >> 24) >= threshold) \
*dest |= (1 << (x & 0x7)); \
if ((x & 0x7) == 0x7) dest++; \
@@ -2359,7 +2359,7 @@ src++
/*****************************************************************************/
/* MACROS for dithered RGBA -> A1 conversion */
/* FIXME: Mask alpha threshold is not handled (thus the default 128 is used) */
-# define DITHER_RGBA_A1_LUT(num) \
+#define DITHER_RGBA_A1_LUT(num) \
(_dither_a1[(((x + num) & 0x7) << DM_BS1) | ((y & 0x7) << DM_BS2) | ((src[num] >> 24))])
#ifdef WORDS_BIGENDIAN
#define WRITE1_RGBA_A1_DITHER(src, dest, threshold) \
@@ -2382,7 +2382,7 @@ src++;
/* MACROS for plain RGBA -> RGB8888 conversion */
#define WRITE1_RGBA_RGB8888(src, dest) \
*dest = *src; dest++; src++;
-# define WRITE1_RGBA_BGR8888(src, dest) \
+#define WRITE1_RGBA_BGR8888(src, dest) \
*dest = (((*src) >> 16) & 0x0000ff) | \
(((*src) ) & 0x00ff00) | \
(((*src) << 16) & 0xff0000); dest++; src++;
diff --git a/src/lib/rgbadraw.c b/src/lib/rgbadraw.c
index e4dc284..f369749 100644
--- a/src/lib/rgbadraw.c
+++ b/src/lib/rgbadraw.c
@@ -604,16 +604,16 @@ __imlib_copy_alpha_data(ImlibImage * src, ImlibImage * dst, int x, int y,
jump = (src->w - w);
jump2 = (dst->w - w);
- /* work our way thru the array */
- for (yy = 0; yy < h; yy++)
- {
- for (xx = 0; xx < w; xx++)
- {
- *p2 = (*p1 & 0xff000000) | (*p2 & 0x00ffffff);
- p1++;
- p2++;
- }
- p1 += jump;
- p2 += jump2;
- }
+ /* work our way thru the array */
+ for (yy = 0; yy < h; yy++)
+ {
+ for (xx = 0; xx < w; xx++)
+ {
+ *p2 = (*p1 & 0xff000000) | (*p2 & 0x00ffffff);
+ p1++;
+ p2++;
+ }
+ p1 += jump;
+ p2 += jump2;
+ }
}
diff --git a/src/lib/script.c b/src/lib/script.c
index 7b7e310..55ebd4e 100644
--- a/src/lib/script.c
+++ b/src/lib/script.c
@@ -11,9 +11,9 @@
#include <ctype.h>
#include <errno.h>
#ifdef BUILD_X11
-# include <X11/Xlib.h>
+#include <X11/Xlib.h>
#else
-# define X_DISPLAY_MISSING
+#define X_DISPLAY_MISSING
#endif
#include "image.h"
#include "file.h"
@@ -25,7 +25,7 @@
#define FDEBUG 1
*/
#ifdef FDEBUG
-# define D( str ) printf( "DEBUG: %s\n", str )
+#define D( str ) printf( "DEBUG: %s\n", str )
#else
#define D( str )
#endif
diff --git a/src/lib/span.c b/src/lib/span.c
index 97eceb3..d303645 100644
--- a/src/lib/span.c
+++ b/src/lib/span.c
@@ -1194,7 +1194,7 @@ __imlib_GetPointDrawFunction(ImlibOp op, char dst_alpha, char blend)
if (opi == -1)
return NULL;
- return ptfuncs[opi][!!dst_alpha][!!blend];
+ return ptfuncs[opi][! !dst_alpha][! !blend];
}
ImlibSpanDrawFunction
@@ -1222,7 +1222,7 @@ __imlib_GetSpanDrawFunction(ImlibOp op, char dst_alpha, char blend)
if (opi == -1)
return NULL;
- return spanfuncs[opi][!!dst_alpha][!!blend];
+ return spanfuncs[opi][! !dst_alpha][! !blend];
}
ImlibShapedSpanDrawFunction
@@ -1250,5 +1250,5 @@ __imlib_GetShapedSpanDrawFunction(ImlibOp op, char dst_alpha, char blend)
if (opi == -1)
return NULL;
- return shapedspanfuncs[opi][!!dst_alpha][!!blend];
+ return shapedspanfuncs[opi][! !dst_alpha][! !blend];
}
diff --git a/src/modules/filters/filter_bumpmap.c b/src/modules/filters/filter_bumpmap.c
index 79451a9..f24764a 100644
--- a/src/modules/filters/filter_bumpmap.c
+++ b/src/modules/filters/filter_bumpmap.c
@@ -252,8 +252,8 @@ init(struct imlib_filter_info *info)
info->name = strdup("Bump Mapping");
info->author = strdup("Willem Monsuwe (willem@stack.nl)");
info->description =
- strdup
- ("Provides bumpmapping to a point and bumpmapping from an infinite light source. *very* cool.");
+ strdup
+ ("Provides bumpmapping to a point and bumpmapping from an infinite light source. *very* cool.");
info->num_filters = i;
info->filters = malloc(sizeof(char *) * i);
while (--i >= 0)
diff --git a/src/modules/filters/filter_colormod.c b/src/modules/filters/filter_colormod.c
index 3d90487..c66eaa7 100644
--- a/src/modules/filters/filter_colormod.c
+++ b/src/modules/filters/filter_colormod.c
@@ -232,7 +232,7 @@ init(struct imlib_filter_info *info)
info->name = strdup("Tinting");
info->author = strdup("Willem Monsuwe (willem@stack.nl)");
info->description =
- strdup("Provides most common color modification filters.");
+ strdup("Provides most common color modification filters.");
info->num_filters = i;
info->filters = malloc(sizeof(char *) * i);
while (--i >= 0)
diff --git a/src/modules/filters/filter_test.c b/src/modules/filters/filter_test.c
index d6006c4..5197f3d 100644
--- a/src/modules/filters/filter_test.c
+++ b/src/modules/filters/filter_test.c
@@ -10,8 +10,8 @@ init(struct imlib_filter_info *info)
info->name = strdup("Test Filter");
info->author = strdup("Chris Ross - Boris - chris@darkrock.co.uk");
info->description =
- strdup
- ("This filter is used to show that the imlib2 filter system works!");
+ strdup
+ ("This filter is used to show that the imlib2 filter system works!");
info->num_filters = 3;
info->filters = malloc(sizeof(char *) * 3);
for (i = 0; i < info->num_filters; i++)
diff --git a/src/modules/loaders/loader_argb.c b/src/modules/loaders/loader_argb.c
index 20aae35..176322f 100644
--- a/src/modules/loaders/loader_argb.c
+++ b/src/modules/loaders/loader_argb.c
@@ -37,10 +37,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
return 0;
}
if (!IMAGE_DIMENSIONS_OK(w, h))
- {
+ {
fclose(f);
return 0;
- }
+ }
im->w = w;
im->h = h;
if (!im->format)
diff --git a/src/modules/loaders/loader_bmp.c b/src/modules/loaders/loader_bmp.c
index 87792e7..bdd2a2a 100644
--- a/src/modules/loaders/loader_bmp.c
+++ b/src/modules/loaders/loader_bmp.c
@@ -25,9 +25,9 @@ typedef struct tagRGBQUAD {
/* 21.3.3006 - Use enumeration for RLE encoding. This makes it more readable */
enum {
- RLE_NEXT = 0, /* Next line */
- RLE_END = 1, /* End of RLE encoding */
- RLE_MOVE = 2 /* Move by X and Y (Offset is stored in two next bytes) */
+ RLE_NEXT = 0, /* Next line */
+ RLE_END = 1, /* End of RLE encoding */
+ RLE_MOVE = 2 /* Move by X and Y (Offset is stored in two next bytes) */
};
static int
@@ -38,7 +38,7 @@ ReadleShort(FILE * file, unsigned short *ret)
if (fread(b, sizeof(unsigned char), 2, file) != 2)
return 0;
- *ret = (b[1] << 8) | b[0];
+ *ret = (b[1] << 8) | b[0];
return 1;
}
@@ -57,9 +57,9 @@ ReadleLong(FILE * file, unsigned long *ret)
static int
WriteleByte(FILE * file, unsigned char val)
{
- int rc;
+ int rc;
- rc = fputc ((int) val & 0xff, file);
+ rc = fputc((int)val & 0xff, file);
if (rc == EOF)
return 0;
@@ -69,12 +69,12 @@ WriteleByte(FILE * file, unsigned char val)
static int
WriteleShort(FILE * file, unsigned short val)
{
- int rc;
+ int rc;
- rc = fputc ((int) (val & 0xff), file);
+ rc = fputc((int)(val & 0xff), file);
if (rc == EOF)
return 0;
- rc = fputc ((int) ((val >> 8) & 0xff), file);
+ rc = fputc((int)((val >> 8) & 0xff), file);
if (rc == EOF)
return 0;
@@ -84,18 +84,18 @@ WriteleShort(FILE * file, unsigned short val)
static int
WriteleLong(FILE * file, unsigned long val)
{
- int rc;
+ int rc;
- rc = fputc ((int) (val & 0xff), file);
+ rc = fputc((int)(val & 0xff), file);
if (rc == EOF)
return 0;
- rc = fputc ((int) ((val >> 8) & 0xff), file);
+ rc = fputc((int)((val >> 8) & 0xff), file);
if (rc == EOF)
return 0;
- rc = fputc ((int) ((val >> 16) & 0xff), file);
+ rc = fputc((int)((val >> 16) & 0xff), file);
if (rc == EOF)
return 0;
- rc = fputc ((int) ((val >> 24) & 0xff), file);
+ rc = fputc((int)((val >> 24) & 0xff), file);
if (rc == EOF)
return 0;
@@ -205,14 +205,16 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (headSize == 12)
{
ncols /= 3;
- if (ncols > 256) ncols = 256;
+ if (ncols > 256)
+ ncols = 256;
for (i = 0; i < ncols; i++)
fread(&rgbQuads[i], 3, 1, f);
}
else
{
ncols /= 4;
- if (ncols > 256) ncols = 256;
+ if (ncols > 256)
+ ncols = 256;
fread(rgbQuads, 4, ncols, f);
}
}
@@ -227,23 +229,29 @@ load(ImlibImage * im, ImlibProgressFunction progress,
ReadleLong(f, &bmask);
for (bit = bitcount - 1; bit >= 0; bit--)
{
- if (bmask & (1 << bit)) bshift = bit;
- if (gmask & (1 << bit)) gshift = bit;
- if (rmask & (1 << bit)) rshift = bit;
+ if (bmask & (1 << bit))
+ bshift = bit;
+ if (gmask & (1 << bit))
+ gshift = bit;
+ if (rmask & (1 << bit))
+ rshift = bit;
}
- while(((((0xffffL & bmask) >> bshift) << bleftshift) & 0x80) == 0)
+ while (((((0xffffL & bmask) >> bshift) << bleftshift) & 0x80) ==
+ 0)
{
bleftshift++;
}
- while(((((0xffffL & gmask) >> gshift) << gleftshift) & 0x80) == 0)
+ while (((((0xffffL & gmask) >> gshift) << gleftshift) & 0x80) ==
+ 0)
{
gleftshift++;
}
- while(((((0xffffL & rmask) >> rshift) << rleftshift) & 0x80) == 0)
+ while (((((0xffffL & rmask) >> rshift) << rleftshift) & 0x80) ==
+ 0)
{
rleftshift++;
}
- }
+ }
else if (bitcount == 16)
{
rmask = 0x7C00;
@@ -311,9 +319,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
byte = *(buffer_ptr++);
k = (byte >> 7) & 1;
*ptr++ = 0xff000000 |
- (rgbQuads[k].rgbRed << 16) |
- (rgbQuads[k].rgbGreen << 8) |
- rgbQuads[k].rgbBlue;
+ (rgbQuads[k].rgbRed << 16) |
+ (rgbQuads[k].rgbGreen << 8) |
+ rgbQuads[k].rgbBlue;
byte <<= 1;
}
buffer_ptr += skip;
@@ -353,7 +361,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
* - If we use 'byte = *(buffer_ptr++) in main loop we must check if
* 'buffer_ptr != buffer_end', because special or incomplete bmp file can generate
* segfault (I was writing it, because in RLE we need to read depending count of
- * bytes that depends on requester operation).
+ * bytes that depends on requester operation).
* SOLUTION: Don't read one byte, read two bytes and check.
* - If RLE teels us than single color length will be larger than allowed, we can
* stop, because bitmap is corrupted or crawled.
@@ -372,89 +380,111 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/*
* 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end'
*/
- unsigned char *buffer_end_minus_1 = buffer_end - 1;
+ unsigned char *buffer_end_minus_1 = buffer_end - 1;
+
x = 0;
y = 0;
- for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++)
+ for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1;
+ i++)
{
byte1 = buffer_ptr[0];
byte2 = buffer_ptr[1];
buffer_ptr += 2;
if (byte1)
{
- DATA32 t1, t2;
+ DATA32 t1, t2;
l = byte1;
/* Check for invalid length */
- if (l + x > w) goto _bail;
-
- t1 = 0xff000000 | (rgbQuads[byte2 >> 4].rgbRed << 16) |
- (rgbQuads[byte2 >> 4].rgbGreen << 8) |
- (rgbQuads[byte2 >> 4].rgbBlue ) ;
- t2 = 0xff000000 | (rgbQuads[byte2 & 0xF].rgbRed << 16) |
- (rgbQuads[byte2 & 0xF].rgbGreen << 8) |
- (rgbQuads[byte2 & 0xF].rgbBlue ) ;
- for (j = l/2; j; j--) {
- ptr[0] = t1;
- ptr[1] = t2;
- ptr += 2;
- }
+ if (l + x > w)
+ goto _bail;
+
+ t1 = 0xff000000 |
+ (rgbQuads[byte2 >> 4].rgbRed << 16) |
+ (rgbQuads[byte2 >> 4].rgbGreen << 8) |
+ (rgbQuads[byte2 >> 4].rgbBlue);
+ t2 = 0xff000000 |
+ (rgbQuads[byte2 & 0xF].rgbRed << 16) |
+ (rgbQuads[byte2 & 0xF].rgbGreen << 8) |
+ (rgbQuads[byte2 & 0xF].rgbBlue);
+ for (j = l / 2; j; j--)
+ {
+ ptr[0] = t1;
+ ptr[1] = t2;
+ ptr += 2;
+ }
/* tail */
- if (l & 1) *ptr++ = t1;
+ if (l & 1)
+ *ptr++ = t1;
x += l;
}
else
{
switch (byte2)
{
- case RLE_NEXT:
- x = 0;
- if (++y >= h) goto _bail;
- ptr = im->data + (h - y - 1) * w;
- break;
- case RLE_END:
- goto _bail;
- case RLE_MOVE:
- /* Need to read two bytes */
- if (buffer_ptr >= buffer_end_minus_1) goto _bail;
- x += buffer_ptr[0];
- y += buffer_ptr[1];
- buffer_ptr += 2;
- /* Check for correct coordinates */
- if (x >= w) goto _bail;
- if (y >= h) goto _bail;
- ptr = im->data + (h - y - 1) * w + x;
- break;
- default:
- l = byte2;
- /* Check for invalid length and valid buffer size */
- if (l + x > w) goto _bail;
- if (buffer_ptr + (l >> 1) + (l & 1) > buffer_end) goto _bail;
-
- for (j = l/2; j; j--) {
- byte = *buffer_ptr++;
- ptr[0] = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) |
- (rgbQuads[byte >> 4].rgbGreen << 8) |
- (rgbQuads[byte >> 4].rgbBlue ) ;
- ptr[1] = 0xff000000 | (rgbQuads[byte & 0xF].rgbRed << 16) |
- (rgbQuads[byte & 0xF].rgbGreen << 8) |
- (rgbQuads[byte & 0xF].rgbBlue ) ;
- ptr += 2;
+ case RLE_NEXT:
+ x = 0;
+ if (++y >= h)
+ goto _bail;
+ ptr = im->data + (h - y - 1) * w;
+ break;
+ case RLE_END:
+ goto _bail;
+ case RLE_MOVE:
+ /* Need to read two bytes */
+ if (buffer_ptr >= buffer_end_minus_1)
+ goto _bail;
+ x += buffer_ptr[0];
+ y += buffer_ptr[1];
+ buffer_ptr += 2;
+ /* Check for correct coordinates */
+ if (x >= w)
+ goto _bail;
+ if (y >= h)
+ goto _bail;
+ ptr = im->data + (h - y - 1) * w + x;
+ break;
+ default:
+ l = byte2;
+ /* Check for invalid length and valid buffer size */
+ if (l + x > w)
+ goto _bail;
+ if (buffer_ptr + (l >> 1) + (l & 1) >
+ buffer_end)
+ goto _bail;
+
+ for (j = l / 2; j; j--)
+ {
+ byte = *buffer_ptr++;
+ ptr[0] =
+ 0xff000000 |
+ (rgbQuads[byte >> 4].rgbRed << 16) |
+ (rgbQuads[byte >> 4].rgbGreen << 8) |
+ (rgbQuads[byte >> 4].rgbBlue);
+ ptr[1] =
+ 0xff000000 |
+ (rgbQuads[byte & 0xF].rgbRed << 16) |
+ (rgbQuads[byte & 0xF].rgbGreen << 8) |
+ (rgbQuads[byte & 0xF].rgbBlue);
+ ptr += 2;
}
- if (l & 1) {
- byte = *buffer_ptr++;
- *ptr++ = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) |
- (rgbQuads[byte >> 4].rgbGreen << 8) |
- (rgbQuads[byte >> 4].rgbBlue ) ;
+ if (l & 1)
+ {
+ byte = *buffer_ptr++;
+ *ptr++ =
+ 0xff000000 |
+ (rgbQuads[byte >> 4].rgbRed << 16) |
+ (rgbQuads[byte >> 4].rgbGreen << 8) |
+ (rgbQuads[byte >> 4].rgbBlue);
}
- x += l;
+ x += l;
- if ((l & 3) == 1)
- buffer_ptr += 2;
- else if ((l & 3) == 2)
- buffer_ptr++;
- break;
+ if ((l & 3) == 1)
+ buffer_ptr += 2;
+ else if ((l & 3) == 2)
+ buffer_ptr++;
+ break;
}
}
if (progress)
@@ -492,9 +522,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
byte = *(buffer_ptr++);
k = (byte & 0xF0) >> 4;
*ptr++ = 0xff000000 |
- (rgbQuads[k].rgbRed << 16) |
- (rgbQuads[k].rgbGreen << 8) |
- rgbQuads[k].rgbBlue;
+ (rgbQuads[k].rgbRed << 16) |
+ (rgbQuads[k].rgbGreen << 8) |
+ rgbQuads[k].rgbBlue;
byte <<= 4;
}
buffer_ptr += skip;
@@ -530,63 +560,74 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/*
* 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end'
*/
- unsigned char *buffer_end_minus_1 = buffer_end - 1;
+ unsigned char *buffer_end_minus_1 = buffer_end - 1;
+
x = 0;
y = 0;
- for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++)
+ for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1;
+ i++)
{
byte1 = buffer_ptr[0];
byte2 = buffer_ptr[1];
buffer_ptr += 2;
if (byte1)
{
- DATA32 pix = 0xff000000 | (rgbQuads[byte2].rgbRed << 16) |
- (rgbQuads[byte2].rgbGreen << 8) |
- (rgbQuads[byte2].rgbBlue ) ;
+ DATA32 pix =
+ 0xff000000 | (rgbQuads[byte2].rgbRed << 16) |
+ (rgbQuads[byte2].rgbGreen << 8) |
+ (rgbQuads[byte2].rgbBlue);
l = byte1;
- if (x + l > w) goto _bail;
- for (j = l; j; j--) *ptr++ = pix;
+ if (x + l > w)
+ goto _bail;
+ for (j = l; j; j--)
+ *ptr++ = pix;
x += l;
}
else
{
switch (byte2)
{
- case RLE_NEXT:
- x = 0;
- if (++y >= h) goto _bail;
- ptr = im->data + ((h - y - 1) * w) + x;
- break;
- case RLE_END:
- goto _bail;
- case RLE_MOVE:
- /* Need to read two bytes */
- if (buffer_ptr >= buffer_end_minus_1) goto _bail;
- x += buffer_ptr[0];
- y += buffer_ptr[1];
- buffer_ptr += 2;
- /* Check for correct coordinates */
- if (x >= w) goto _bail;
- if (y >= h) goto _bail;
- ptr = im->data + ((h - y - 1) * w) + x;
- break;
- default:
- l = byte2;
- if (x + l > w) goto _bail;
- if (buffer_ptr + l > buffer_end) goto _bail;
- for (j = 0; j < l; j++)
- {
- byte = *(buffer_ptr++);
-
- *ptr++ = 0xff000000 |
- (rgbQuads[byte].rgbRed << 16) |
- (rgbQuads[byte].rgbGreen << 8) |
- rgbQuads[byte].rgbBlue;
- }
- x += l;
- if (l & 1)
- buffer_ptr++;
- break;
+ case RLE_NEXT:
+ x = 0;
+ if (++y >= h)
+ goto _bail;
+ ptr = im->data + ((h - y - 1) * w) + x;
+ break;
+ case RLE_END:
+ goto _bail;
+ case RLE_MOVE:
+ /* Need to read two bytes */
+ if (buffer_ptr >= buffer_end_minus_1)
+ goto _bail;
+ x += buffer_ptr[0];
+ y += buffer_ptr[1];
+ buffer_ptr += 2;
+ /* Check for correct coordinates */
+ if (x >= w)
+ goto _bail;
+ if (y >= h)
+ goto _bail;
+ ptr = im->data + ((h - y - 1) * w) + x;
+ break;
+ default:
+ l = byte2;
+ if (x + l > w)
+ goto _bail;
+ if (buffer_ptr + l > buffer_end)
+ goto _bail;
+ for (j = 0; j < l; j++)
+ {
+ byte = *(buffer_ptr++);
+
+ *ptr++ = 0xff000000 |
+ (rgbQuads[byte].rgbRed << 16) |
+ (rgbQuads[byte].rgbGreen << 8) |
+ rgbQuads[byte].rgbBlue;
+ }
+ x += l;
+ if (l & 1)
+ buffer_ptr++;
+ break;
}
}
}
@@ -621,9 +662,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
byte = *(buffer_ptr++);
*ptr++ = 0xff000000 |
- (rgbQuads[byte].rgbRed << 16) |
- (rgbQuads[byte].rgbGreen << 8) |
- rgbQuads[byte].rgbBlue;
+ (rgbQuads[byte].rgbRed << 16) |
+ (rgbQuads[byte].rgbGreen << 8) |
+ rgbQuads[byte].rgbBlue;
}
ptr -= w * 2;
buffer_ptr += skip;
@@ -655,7 +696,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
else if (bitcount == 16)
{
/* 21.3.2006 - Need to check for buffer_ptr + 1 < buffer_end */
- unsigned char *buffer_end_minus_1 = buffer_end - 1;
+ unsigned char *buffer_end_minus_1 = buffer_end - 1;
+
skip = (((w * 16 + 31) / 32) * 4) - (w * 2);
for (y = 0; y < h; y++)
{
@@ -670,10 +712,13 @@ load(ImlibImage * im, ImlibProgressFunction progress,
* bshift;
* *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b;
*/
- unsigned short pix = *(unsigned short *)buffer_ptr;
- *ptr++ = 0xff000000 | ((((pix & rmask) >> rshift) << rleftshift) << 16) |
- ((((pix & gmask) >> gshift) << gleftshift) << 8) |
- ((((pix & bmask) >> bshift) << bleftshift) ) ;
+ unsigned short pix = *(unsigned short *)buffer_ptr;
+
+ *ptr++ =
+ 0xff000000 |
+ ((((pix & rmask) >> rshift) << rleftshift) << 16) |
+ ((((pix & gmask) >> gshift) << gleftshift) << 8) |
+ ((((pix & bmask) >> bshift) << bleftshift));
buffer_ptr += 2;
}
ptr -= w * 2;
@@ -704,7 +749,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
else if (bitcount == 24)
{
/* 21.3.2006 - Fix: need to check for buffer_ptr + 2 < buffer_end */
- unsigned char *buffer_end_minus_2 = buffer_end - 2;
+ unsigned char *buffer_end_minus_2 = buffer_end - 2;
+
skip = (4 - ((w * 3) % 4)) & 3;
for (y = 0; y < h; y++)
{
@@ -743,7 +789,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
else if (bitcount == 32)
{
/* 21.3.2006 - Need to check buffer_ptr + 3 < buffer_end */
- unsigned char *buffer_end_minus_3 = buffer_end_minus_3;
+ unsigned char *buffer_end_minus_3 = buffer_end_minus_3;
+
skip = (((w * 32 + 31) / 32) * 4) - (w * 4);
for (y = 0; y < h; y++)
{
@@ -761,10 +808,11 @@ load(ImlibImage * im, ImlibProgressFunction progress,
*/
/* TODO: What about alpha channel...Is used? */
- DATA32 pix = *(unsigned int *)buffer_ptr;
+ DATA32 pix = *(unsigned int *)buffer_ptr;
+
*ptr++ = 0xff000000 | (((pix & rmask) >> rshift) << 16) |
- (((pix & gmask) >> gshift) << 8) |
- (((pix & bmask) >> bshift) ) ;
+ (((pix & gmask) >> gshift) << 8) |
+ (((pix & bmask) >> bshift));
buffer_ptr += 4;
}
ptr -= w * 2;
@@ -792,7 +840,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
}
}
}
-_bail:
+ _bail:
free(buffer);
}
return 1;
@@ -816,36 +864,36 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
pad = (4 - ((im->w * 3) % 4)) & 0x03;
/* write BMP file header */
- WriteleShort(f, 0x4d42); /* prefix */
- WriteleLong(f, 54 + 3 * im->w * im->h); /* filesize */
- WriteleShort(f, 0x0000); /* reserved #1 */
- WriteleShort(f, 0x0000); /* reserved #2 */
- WriteleLong(f, 54); /* offset to image data */
+ WriteleShort(f, 0x4d42); /* prefix */
+ WriteleLong(f, 54 + 3 * im->w * im->h); /* filesize */
+ WriteleShort(f, 0x0000); /* reserved #1 */
+ WriteleShort(f, 0x0000); /* reserved #2 */
+ WriteleLong(f, 54); /* offset to image data */
/* write BMP bitmap header */
- WriteleLong(f, 40); /* 40-byte header */
+ WriteleLong(f, 40); /* 40-byte header */
WriteleLong(f, im->w);
WriteleLong(f, im->h);
- WriteleShort(f, 1); /* one plane */
- WriteleShort(f, 24); /* bits per pixel */
- WriteleLong(f, 0); /* no compression */
+ WriteleShort(f, 1); /* one plane */
+ WriteleShort(f, 24); /* bits per pixel */
+ WriteleLong(f, 0); /* no compression */
WriteleLong(f, 3 * im->w * im->h);
for (i = 0; i < 4; i++)
- WriteleLong(f, 0x0000); /* pad to end of header */
+ WriteleLong(f, 0x0000); /* pad to end of header */
/* write actual BMP data */
for (i = 0; i < im->h; i++)
- {
- for (j = 0; j < im->w; j++)
- {
- imlib_image_query_pixel (j, im->h - i - 1, &pixel_color);
- WriteleByte(f, pixel_color.blue);
- WriteleByte(f, pixel_color.green);
- WriteleByte(f, pixel_color.red);
- }
- for (j = 0; j < pad; j++)
- WriteleByte(f, 0);
- }
+ {
+ for (j = 0; j < im->w; j++)
+ {
+ imlib_image_query_pixel(j, im->h - i - 1, &pixel_color);
+ WriteleByte(f, pixel_color.blue);
+ WriteleByte(f, pixel_color.green);
+ WriteleByte(f, pixel_color.red);
+ }
+ for (j = 0; j < pad; j++)
+ WriteleByte(f, 0);
+ }
fclose(f);
return 1;
diff --git a/src/modules/loaders/loader_bz2.c b/src/modules/loaders/loader_bz2.c
index 7ac225f..adda48a 100644
--- a/src/modules/loaders/loader_bz2.c
+++ b/src/modules/loaders/loader_bz2.c
@@ -8,115 +8,127 @@
#define OUTBUF_SIZE 16384
#define INBUF_SIZE 1024
-static int uncompress_file (FILE *fp, int dest)
+static int
+uncompress_file(FILE * fp, int dest)
{
- BZFILE *bf;
- DATA8 outbuf[OUTBUF_SIZE];
- int bytes, error, ret = 1;
+ BZFILE *bf;
+ DATA8 outbuf[OUTBUF_SIZE];
+ int bytes, error, ret = 1;
- bf = BZ2_bzReadOpen (&error, fp, 0, 0, NULL, 0);
+ bf = BZ2_bzReadOpen(&error, fp, 0, 0, NULL, 0);
- if (error != BZ_OK) {
- BZ2_bzReadClose (NULL, bf);
- return 0;
- }
+ if (error != BZ_OK)
+ {
+ BZ2_bzReadClose(NULL, bf);
+ return 0;
+ }
- while (1) {
- bytes = BZ2_bzRead (&error, bf, &outbuf, OUTBUF_SIZE);
+ while (1)
+ {
+ bytes = BZ2_bzRead(&error, bf, &outbuf, OUTBUF_SIZE);
- if (error == BZ_OK || error == BZ_STREAM_END)
- write (dest, outbuf, bytes);
+ if (error == BZ_OK || error == BZ_STREAM_END)
+ write(dest, outbuf, bytes);
- if (error == BZ_STREAM_END)
- break;
- else if (error != BZ_OK) {
- ret = 0;
- break;
- }
- }
+ if (error == BZ_STREAM_END)
+ break;
+ else if (error != BZ_OK)
+ {
+ ret = 0;
+ break;
+ }
+ }
- BZ2_bzReadClose (&error, bf);
+ BZ2_bzReadClose(&error, bf);
- return ret;
+ return ret;
}
-char load (ImlibImage *im, ImlibProgressFunction progress,
- char progress_granularity, char immediate_load)
+char
+load(ImlibImage * im, ImlibProgressFunction progress,
+ char progress_granularity, char immediate_load)
{
- ImlibLoader *loader;
- FILE *fp;
- int dest, res;
- char *file, tmp[] = "/tmp/imlib2_loader_bz2-XXXXXX", *p;
- char real_ext[16];
-
- assert (im);
-
- /* make sure this file ends in ".bz2" and that there's another ext
- * (e.g. "foo.png.bz2"
- */
- p = strrchr(im->real_file, '.');
- if (p && p != im->real_file) {
- if (strcasecmp(p + 1, "bz2"))
- return 0;
- } else
- return 0;
-
- strncpy (real_ext, p - sizeof (real_ext) + 1, sizeof (real_ext));
- real_ext[sizeof (real_ext) - 1] = '\0';
-
- /* abort if there's no dot in the "real" filename */
- if (!strrchr (real_ext, '.'))
- return 0;
-
- if (!(fp = fopen (im->real_file, "rb"))) {
- return 0;
- }
-
- if ((dest = mkstemp (tmp)) < 0) {
- fclose (fp);
- return 0;
- }
-
- res = uncompress_file (fp, dest);
- fclose (fp);
- close (dest);
-
- if (!res) {
- unlink (tmp);
- return 0;
- }
-
- if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
- unlink (tmp);
- return 0;
- }
-
- /* remember the original filename */
- file = strdup (im->real_file);
-
- free (im->real_file);
- im->real_file = strdup (tmp);
- loader->load (im, progress, progress_granularity, immediate_load);
-
- free (im->real_file);
- im->real_file = file;
- unlink (tmp);
-
- return 1;
+ ImlibLoader *loader;
+ FILE *fp;
+ int dest, res;
+ char *file, tmp[] = "/tmp/imlib2_loader_bz2-XXXXXX", *p;
+ char real_ext[16];
+
+ assert(im);
+
+ /* make sure this file ends in ".bz2" and that there's another ext
+ * (e.g. "foo.png.bz2"
+ */
+ p = strrchr(im->real_file, '.');
+ if (p && p != im->real_file)
+ {
+ if (strcasecmp(p + 1, "bz2"))
+ return 0;
+ }
+ else
+ return 0;
+
+ strncpy(real_ext, p - sizeof(real_ext) + 1, sizeof(real_ext));
+ real_ext[sizeof(real_ext) - 1] = '\0';
+
+ /* abort if there's no dot in the "real" filename */
+ if (!strrchr(real_ext, '.'))
+ return 0;
+
+ if (!(fp = fopen(im->real_file, "rb")))
+ {
+ return 0;
+ }
+
+ if ((dest = mkstemp(tmp)) < 0)
+ {
+ fclose(fp);
+ return 0;
+ }
+
+ res = uncompress_file(fp, dest);
+ fclose(fp);
+ close(dest);
+
+ if (!res)
+ {
+ unlink(tmp);
+ return 0;
+ }
+
+ if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
+ {
+ unlink(tmp);
+ return 0;
+ }
+
+ /* remember the original filename */
+ file = strdup(im->real_file);
+
+ free(im->real_file);
+ im->real_file = strdup(tmp);
+ loader->load(im, progress, progress_granularity, immediate_load);
+
+ free(im->real_file);
+ im->real_file = file;
+ unlink(tmp);
+
+ return 1;
}
-void formats (ImlibLoader *l)
+void
+formats(ImlibLoader * l)
{
- /* this is the only bit you have to change... */
- char *list_formats[] = {"bz2"};
- int i;
+ /* this is the only bit you have to change... */
+ char *list_formats[] = { "bz2" };
+ int i;
/* don't bother changing any of this - it just reads this in
- * and sets the struct values and makes copies
- */
- l->num_formats = sizeof (list_formats) / sizeof (char *);
- l->formats = malloc (sizeof (char *) * l->num_formats);
+ * and sets the struct values and makes copies
+ */
+ 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]);
+ for (i = 0; i < l->num_formats; i++)
+ l->formats[i] = strdup(list_formats[i]);
}
diff --git a/src/modules/loaders/loader_gif.c b/src/modules/loaders/loader_gif.c
index 4337826..45ff0b9 100644
--- a/src/modules/loaders/loader_gif.c
+++ b/src/modules/loaders/loader_gif.c
@@ -58,11 +58,11 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
}
w = gif->Image.Width;
h = gif->Image.Height;
- if (!IMAGE_DIMENSIONS_OK(w, h))
- {
+ if (!IMAGE_DIMENSIONS_OK(w, h))
+ {
DGifCloseFile(gif);
return 0;
- }
+ }
rows = malloc(h * sizeof(GifRowType *));
if (!rows)
{
@@ -126,7 +126,8 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
DGifGetExtensionNext(gif, &ext);
}
}
- } while (rec != TERMINATE_RECORD_TYPE);
+ }
+ while (rec != TERMINATE_RECORD_TYPE);
if (transp >= 0)
{
SET_FLAG(im->flags, F_HAS_ALPHA);
diff --git a/src/modules/loaders/loader_id3.c b/src/modules/loaders/loader_id3.c
index 5318748..2b3ccb1 100644
--- a/src/modules/loaders/loader_id3.c
+++ b/src/modules/loaders/loader_id3.c
@@ -8,544 +8,604 @@
#include <id3tag.h>
#if ! defined (__STDC_VERSION__) || __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define inline __inline__
-# else
-# define inline
-# endif
+#if __GNUC__ >= 2
+#define inline __inline__
+#else
+#define inline
+#endif
#endif
#ifdef __GNUC__
-# define UNLIKELY(exp) __builtin_expect ((exp), 0)
+#define UNLIKELY(exp) __builtin_expect ((exp), 0)
#else
-# define UNLIKELY(exp) (exp)
+#define UNLIKELY(exp) (exp)
#endif
-typedef struct context
-{
- int id;
- char* filename;
- struct id3_tag* tag;
- int refcount;
- struct context* next;
+typedef struct context {
+ int id;
+ char *filename;
+ struct id3_tag *tag;
+ int refcount;
+ struct context *next;
} context;
-static context* id3_ctxs = NULL;
+static context *id3_ctxs = NULL;
-static inline struct id3_frame*
-id3_tag_get_frame (struct id3_tag* tag, size_t index)
+static inline struct id3_frame *
+id3_tag_get_frame(struct id3_tag *tag, size_t index)
{
- return tag->frames[index];
+ return tag->frames[index];
}
-static inline size_t id3_tag_get_numframes (struct id3_tag* tag)
+static inline size_t
+id3_tag_get_numframes(struct id3_tag *tag)
{
- return tag->nframes;
+ return tag->nframes;
}
-static inline char const* id3_frame_id (struct id3_frame* frame)
+static inline char const *
+id3_frame_id(struct id3_frame *frame)
{
- return frame->id;
+ return frame->id;
}
-static context* context_create (const char* filename)
+static context *
+context_create(const char *filename)
{
- context* node = (context*) malloc (sizeof (context));
- context *ptr, *last;
- int last_id = INT_MAX;
- node->refcount = 1;
- {
- struct id3_file* file;
- struct id3_tag* tag;
- unsigned int i;
- file = id3_file_open (filename, ID3_FILE_MODE_READONLY);
- if (! file) {
- fprintf (stderr, "Unable to open tagged file %s: %s\n",
- filename, strerror (errno));
- goto fail_free;
- }
- tag = id3_file_tag (file);
- if (! tag) {
- fprintf (stderr,
- "Unable to find ID3v2 tags in file %s\n",
- filename);
- id3_file_close (file);
- goto fail_free;
- }
- node->tag = id3_tag_new ();
- for (i = 0; i < id3_tag_get_numframes (tag); i ++)
- if (! strcmp (id3_frame_id
- (id3_tag_get_frame (tag, i)), "APIC"))
- id3_tag_attachframe (node->tag,
- id3_tag_get_frame (tag, i));
- id3_file_close (file);
- }
- node->filename = strdup (filename);
- if (! id3_ctxs) {
- node->id = 1;
- node->next = NULL;
- id3_ctxs = node;
- return node;
- }
- ptr = id3_ctxs;
- last = NULL;
- while (UNLIKELY (ptr && (ptr->id + 1) >= last_id)) {
- last_id = ptr->id;
- last = ptr;
- ptr = ptr->next;
- }
- /* Paranoid! this can occur only if there are INT_MAX contexts :) */
- if (UNLIKELY (!ptr)) {
- fprintf (stderr, "Too many open ID3 contexts\n");
- goto fail_close;
- }
- node->id = ptr->id + 1;
- if (UNLIKELY (!!last)) {
- node->next = last->next;
- last->next = node;
- } else {
- node->next = id3_ctxs;
- id3_ctxs = node;
- }
- return node;
-
-fail_close:
- free (node->filename);
- id3_tag_delete (node->tag);
-fail_free:
- free (node);
- return NULL;
+ context *node = (context *) malloc(sizeof(context));
+ context *ptr, *last;
+ int last_id = INT_MAX;
+
+ node->refcount = 1;
+ {
+ struct id3_file *file;
+ struct id3_tag *tag;
+ unsigned int i;
+
+ file = id3_file_open(filename, ID3_FILE_MODE_READONLY);
+ if (!file)
+ {
+ fprintf(stderr, "Unable to open tagged file %s: %s\n",
+ filename, strerror(errno));
+ goto fail_free;
+ }
+ tag = id3_file_tag(file);
+ if (!tag)
+ {
+ fprintf(stderr, "Unable to find ID3v2 tags in file %s\n", filename);
+ id3_file_close(file);
+ goto fail_free;
+ }
+ node->tag = id3_tag_new();
+ for (i = 0; i < id3_tag_get_numframes(tag); i++)
+ if (!strcmp(id3_frame_id(id3_tag_get_frame(tag, i)), "APIC"))
+ id3_tag_attachframe(node->tag, id3_tag_get_frame(tag, i));
+ id3_file_close(file);
+ }
+ node->filename = strdup(filename);
+ if (!id3_ctxs)
+ {
+ node->id = 1;
+ node->next = NULL;
+ id3_ctxs = node;
+ return node;
+ }
+ ptr = id3_ctxs;
+ last = NULL;
+ while (UNLIKELY(ptr && (ptr->id + 1) >= last_id))
+ {
+ last_id = ptr->id;
+ last = ptr;
+ ptr = ptr->next;
+ }
+ /* Paranoid! this can occur only if there are INT_MAX contexts :) */
+ if (UNLIKELY(!ptr))
+ {
+ fprintf(stderr, "Too many open ID3 contexts\n");
+ goto fail_close;
+ }
+ node->id = ptr->id + 1;
+ if (UNLIKELY(! !last))
+ {
+ node->next = last->next;
+ last->next = node;
+ }
+ else
+ {
+ node->next = id3_ctxs;
+ id3_ctxs = node;
+ }
+ return node;
+
+ fail_close:
+ free(node->filename);
+ id3_tag_delete(node->tag);
+ fail_free:
+ free(node);
+ return NULL;
}
-static void context_destroy (context* ctx)
+static void
+context_destroy(context * ctx)
{
- id3_tag_delete (ctx->tag);
- free (ctx->filename);
- free (ctx);
+ id3_tag_delete(ctx->tag);
+ free(ctx->filename);
+ free(ctx);
}
-static inline void context_addref (context* ctx)
+static inline void
+context_addref(context * ctx)
{
- ctx->refcount ++;
+ ctx->refcount++;
}
-static context* context_get (int id)
+static context *
+context_get(int id)
{
- context* ptr = id3_ctxs;
- while (ptr) {
- if (ptr->id == id) {
- context_addref (ptr);
- return ptr;
- }
- ptr = ptr->next;
- }
- fprintf (stderr, "No context by handle %d found\n", id);
- return NULL;
+ context *ptr = id3_ctxs;
+
+ while (ptr)
+ {
+ if (ptr->id == id)
+ {
+ context_addref(ptr);
+ return ptr;
+ }
+ ptr = ptr->next;
+ }
+ fprintf(stderr, "No context by handle %d found\n", id);
+ return NULL;
}
-static context* context_get_by_name (const char* name)
+static context *
+context_get_by_name(const char *name)
{
- context* ptr = id3_ctxs;
- while (ptr) {
- if (! strcmp (name, ptr->filename)) {
- context_addref (ptr);
- return ptr;
- }
- ptr = ptr->next;
- }
- return NULL;
+ context *ptr = id3_ctxs;
+
+ while (ptr)
+ {
+ if (!strcmp(name, ptr->filename))
+ {
+ context_addref(ptr);
+ return ptr;
+ }
+ ptr = ptr->next;
+ }
+ return NULL;
}
-static void context_delref (context* ctx)
+static void
+context_delref(context * ctx)
{
- ctx->refcount --;
- if (ctx->refcount <= 0) {
- context *last = NULL, *ptr = id3_ctxs;
- while (ptr) {
- if (ptr == ctx) {
- if (last)
- last->next = ctx->next;
- else
- id3_ctxs = ctx->next;
- context_destroy (ctx);
- return;
- }
- last = ptr;
- ptr = ptr->next;
- }
- }
+ ctx->refcount--;
+ if (ctx->refcount <= 0)
+ {
+ context *last = NULL, *ptr = id3_ctxs;
+
+ while (ptr)
+ {
+ if (ptr == ctx)
+ {
+ if (last)
+ last->next = ctx->next;
+ else
+ id3_ctxs = ctx->next;
+ context_destroy(ctx);
+ return;
+ }
+ last = ptr;
+ ptr = ptr->next;
+ }
+ }
}
-static int str2int (char* str, int old)
+static int
+str2int(char *str, int old)
{
- long index;
- errno = 0;
- index = strtol (str, NULL, 10);
- return ((errno || index > INT_MAX) ? old : (int)index);
+ long index;
+
+ errno = 0;
+ index = strtol(str, NULL, 10);
+ return ((errno || index > INT_MAX) ? old : (int)index);
}
-static size_t str2uint (char* str, size_t old)
+static size_t
+str2uint(char *str, size_t old)
{
- unsigned long index;
- errno = 0;
- index = strtoul (str, NULL, 10);
- return ((errno || index > UINT_MAX) ? old : (size_t)index);
+ unsigned long index;
+
+ errno = 0;
+ index = strtoul(str, NULL, 10);
+ return ((errno || index > UINT_MAX) ? old : (size_t) index);
}
-static void destructor_data (ImlibImage* im, void* data)
+static void
+destructor_data(ImlibImage * im, void *data)
{
- free (data);
+ free(data);
}
-static void destructor_context (ImlibImage* im, void* data)
+static void
+destructor_context(ImlibImage * im, void *data)
{
- context_delref ((context*)data);
+ context_delref((context *) data);
}
-typedef struct lopt
-{
- context* ctx;
- size_t index;
- int traverse;
- char cache_level;
+typedef struct lopt {
+ context *ctx;
+ size_t index;
+ int traverse;
+ char cache_level;
} lopt;
-static char get_options (lopt* opt, ImlibImage* im)
+static char
+get_options(lopt * opt, ImlibImage * im)
{
- size_t handle = 0, index = 0, traverse = 0;
- context* ctx;
-
- if (im->key) {
- char* key = strdup (im->key);
- char* tok = strtok (key, ",");
- traverse = 0;
- while (tok) {
- char* value = strchr (tok, '=');
- if (! value) {
- value = tok;
- tok = "index";
- } else {
- *value = '\0';
- value ++;
- }
- if (! strcasecmp (tok, "index"))
- index = str2uint (value, index);
- else if (! strcasecmp (tok, "context"))
- handle = str2uint (value, handle);
- else if (! strcasecmp (tok, "traverse"))
- traverse = str2int (value, traverse);
- tok = strtok (NULL, ",");
- }
- free (key);
- } else
- traverse = 1;
-
- if (! handle) {
- ImlibImageTag* htag = __imlib_GetTag (im, "context");
- if (htag && htag->val)
- handle = htag->val;
- }
- if (handle)
- ctx = context_get (handle);
- else if (! (ctx = context_get_by_name (im->real_file)) &&
- ! (ctx = context_create (im->real_file)))
- return 0;
-
- if (! index) {
- ImlibImageTag* htag = __imlib_GetTag (im, "index");
- if (htag && htag->val)
- index = htag->val;
- }
- if (index < 0 || index > id3_tag_get_numframes (ctx->tag) ||
- (index == 0 && id3_tag_get_numframes (ctx->tag) < 1)) {
- if (index)
- fprintf (stderr, "No picture frame # %d found\n", index);
- context_delref (ctx);
- return 0;
- }
- if (! index)
- index = 1;
-
- opt->ctx = ctx;
- opt->index = index;
- opt->traverse = traverse;
- opt->cache_level = (id3_tag_get_numframes (ctx->tag) > 1 ? 1 : 0);
- return 1;
+ size_t handle = 0, index = 0, traverse = 0;
+ context *ctx;
+
+ if (im->key)
+ {
+ char *key = strdup(im->key);
+ char *tok = strtok(key, ",");
+
+ traverse = 0;
+ while (tok)
+ {
+ char *value = strchr(tok, '=');
+
+ if (!value)
+ {
+ value = tok;
+ tok = "index";
+ }
+ else
+ {
+ *value = '\0';
+ value++;
+ }
+ if (!strcasecmp(tok, "index"))
+ index = str2uint(value, index);
+ else if (!strcasecmp(tok, "context"))
+ handle = str2uint(value, handle);
+ else if (!strcasecmp(tok, "traverse"))
+ traverse = str2int(value, traverse);
+ tok = strtok(NULL, ",");
+ }
+ free(key);
+ }
+ else
+ traverse = 1;
+
+ if (!handle)
+ {
+ ImlibImageTag *htag = __imlib_GetTag(im, "context");
+
+ if (htag && htag->val)
+ handle = htag->val;
+ }
+ if (handle)
+ ctx = context_get(handle);
+ else if (!(ctx = context_get_by_name(im->real_file)) &&
+ !(ctx = context_create(im->real_file)))
+ return 0;
+
+ if (!index)
+ {
+ ImlibImageTag *htag = __imlib_GetTag(im, "index");
+
+ if (htag && htag->val)
+ index = htag->val;
+ }
+ if (index < 0 || index > id3_tag_get_numframes(ctx->tag) ||
+ (index == 0 && id3_tag_get_numframes(ctx->tag) < 1))
+ {
+ if (index)
+ fprintf(stderr, "No picture frame # %d found\n", index);
+ context_delref(ctx);
+ return 0;
+ }
+ if (!index)
+ index = 1;
+
+ opt->ctx = ctx;
+ opt->index = index;
+ opt->traverse = traverse;
+ opt->cache_level = (id3_tag_get_numframes(ctx->tag) > 1 ? 1 : 0);
+ return 1;
}
-static int extract_pic (struct id3_frame* frame, int dest)
+static int
+extract_pic(struct id3_frame *frame, int dest)
{
- union id3_field* field;
- unsigned char const * data;
- id3_length_t length;
- int done = 0;
-
- field = id3_frame_field (frame, 4);
- data = id3_field_getbinarydata (field, &length);
- if (! data) {
- fprintf (stderr, "No image data found for frame\n");
- return 0;
- }
- while (length > 0) {
- ssize_t res;
- if ((res = write (dest, data + done, length)) < 0) {
- if (errno == EINTR)
- continue;
- perror ("Unable to write to file");
- return 0;
- }
- length -= res;
- done += res;
- }
- return 1;
+ union id3_field *field;
+ unsigned char const *data;
+ id3_length_t length;
+ int done = 0;
+
+ field = id3_frame_field(frame, 4);
+ data = id3_field_getbinarydata(field, &length);
+ if (!data)
+ {
+ fprintf(stderr, "No image data found for frame\n");
+ return 0;
+ }
+ while (length > 0)
+ {
+ ssize_t res;
+
+ if ((res = write(dest, data + done, length)) < 0)
+ {
+ if (errno == EINTR)
+ continue;
+ perror("Unable to write to file");
+ return 0;
+ }
+ length -= res;
+ done += res;
+ }
+ return 1;
}
#define EXT_LEN 14
-static char get_loader (lopt* opt, ImlibLoader** loader)
+static char
+get_loader(lopt * opt, ImlibLoader ** loader)
{
- union id3_field* field;
- char const * data;
- char ext[EXT_LEN + 2];
-
- ext[EXT_LEN + 1] = '\0';
- ext[0] = '.';
-
- field = id3_frame_field (id3_tag_get_frame (opt->ctx->tag,
- opt->index - 1), 1);
- data = (char const*) id3_field_getlatin1 (field);
- if (! data) {
- fprintf (stderr, "No mime type data found for image frame\n");
- return 0;
- }
- if (strncasecmp (data, "image/", 6)) {
- if (! strcmp (data, "-->")) {
- *loader = NULL;
- return 1;
- }
- fprintf (stderr,
- "Picture frame with unknown mime-type \'%s\' found\n",
- data);
- return 0;
- }
- strncpy (ext + 1, data + 6, EXT_LEN);
- if (! (*loader = __imlib_FindBestLoaderForFile (ext, 0))) {
- fprintf (stderr, "No loader found for extension %s\n", ext);
- return 0;
- }
- return 1;
+ union id3_field *field;
+ char const *data;
+ char ext[EXT_LEN + 2];
+
+ ext[EXT_LEN + 1] = '\0';
+ ext[0] = '.';
+
+ field = id3_frame_field(id3_tag_get_frame(opt->ctx->tag, opt->index - 1), 1);
+ data = (char const *)id3_field_getlatin1(field);
+ if (!data)
+ {
+ fprintf(stderr, "No mime type data found for image frame\n");
+ return 0;
+ }
+ if (strncasecmp(data, "image/", 6))
+ {
+ if (!strcmp(data, "-->"))
+ {
+ *loader = NULL;
+ return 1;
+ }
+ fprintf(stderr,
+ "Picture frame with unknown mime-type \'%s\' found\n", data);
+ return 0;
+ }
+ strncpy(ext + 1, data + 6, EXT_LEN);
+ if (!(*loader = __imlib_FindBestLoaderForFile(ext, 0)))
+ {
+ fprintf(stderr, "No loader found for extension %s\n", ext);
+ return 0;
+ }
+ return 1;
}
-static char* id3_pic_types [] = {
- /* $00 */ "Other",
- /* $01 */ "32x32 pixels file icon",
- /* $02 */ "Other file icon",
- /* $03 */ "Cover (front)",
- /* $04 */ "Cover (back)",
- /* $05 */ "Leaflet page",
- /* $06 */ "Media",
- /* $07 */ "Lead artist/lead performer/soloist",
- /* $08 */ "Artist/performer",
- /* $09 */ "Conductor",
- /* $0A */ "Band/Orchestra",
- /* $0B */ "Composer",
- /* $0C */ "Lyricist/text writer",
- /* $0D */ "Recording Location",
- /* $0E */ "During recording",
- /* $0F */ "During performance",
- /* $10 */ "Movie/video screen capture",
- /* $11 */ "A bright coloured fish",
- /* $12 */ "Illustration",
- /* $13 */ "Band/artist logotype",
- /* $14 */ "Publisher/Studio logotype"
+static char *id3_pic_types[] = {
+ /* $00 */ "Other",
+ /* $01 */ "32x32 pixels file icon",
+ /* $02 */ "Other file icon",
+ /* $03 */ "Cover (front)",
+ /* $04 */ "Cover (back)",
+ /* $05 */ "Leaflet page",
+ /* $06 */ "Media",
+ /* $07 */ "Lead artist/lead performer/soloist",
+ /* $08 */ "Artist/performer",
+ /* $09 */ "Conductor",
+ /* $0A */ "Band/Orchestra",
+ /* $0B */ "Composer",
+ /* $0C */ "Lyricist/text writer",
+ /* $0D */ "Recording Location",
+ /* $0E */ "During recording",
+ /* $0F */ "During performance",
+ /* $10 */ "Movie/video screen capture",
+ /* $11 */ "A bright coloured fish",
+ /* $12 */ "Illustration",
+ /* $13 */ "Band/artist logotype",
+ /* $14 */ "Publisher/Studio logotype"
};
#define NUM_OF_ID3_PIC_TYPES \
(sizeof(id3_pic_types) / sizeof(id3_pic_types[0]))
-static char* id3_text_encodings [] = {
- /* $00 */ "ISO-8859-1",
- /* $01 */ "UTF-16 encoded Unicode with BOM",
- /* $02 */ "UTF-16BE encoded Unicode without BOM",
- /* $03 */ "UTF-8 encoded Unicode"
+static char *id3_text_encodings[] = {
+ /* $00 */ "ISO-8859-1",
+ /* $01 */ "UTF-16 encoded Unicode with BOM",
+ /* $02 */ "UTF-16BE encoded Unicode without BOM",
+ /* $03 */ "UTF-8 encoded Unicode"
};
#define NUM_OF_ID3_TEXT_ENCODINGS \
(sizeof(id3_text_encodings) / sizeof(id3_text_encodings[0]))
-static void write_tags (ImlibImage* im, lopt* opt)
+static void
+write_tags(ImlibImage * im, lopt * opt)
{
- struct id3_frame* frame
- = id3_tag_get_frame (opt->ctx->tag, opt->index - 1);
- union id3_field* field;
- int num_data;
- char* data;
-
- if ((field = id3_frame_field (frame, 1)) &&
- (data = (char*) id3_field_getlatin1 (field)))
- __imlib_AttachTag (im, "mime-type", 0,
- strdup (data), destructor_data);
- if ((field = id3_frame_field (frame, 3)) &&
- (data = (char*) id3_field_getstring (field))) {
- size_t length;
- char* dup;
- id3_ucs4_t* ptr = (id3_ucs4_t*)data;
- while (*ptr)
- ptr ++;
- length = (ptr - (id3_ucs4_t*)data + 1) * sizeof (id3_ucs4_t);
- dup = (char*) malloc (length);
- memcpy (dup, data, length);
- __imlib_AttachTag (im, "id3-description", 0,
- dup, destructor_data);
- }
- if (field = id3_frame_field (frame, 0))
- __imlib_AttachTag (im, "id3-description-text-encoding",
- (num_data = (int)
- id3_field_gettextencoding (field)),
- num_data < NUM_OF_ID3_TEXT_ENCODINGS ?
- id3_text_encodings[num_data] : NULL, NULL);
- if (field = id3_frame_field (frame, 2))
- __imlib_AttachTag (im, "id3-picture-type",
- (num_data = id3_field_getint (field)),
- num_data < NUM_OF_ID3_PIC_TYPES ?
- id3_pic_types[num_data] : NULL, NULL);
- __imlib_AttachTag (im, "count", id3_tag_get_numframes (opt->ctx->tag),
- NULL, NULL);
- if (opt->cache_level) {
- context_addref (opt->ctx);
- __imlib_AttachTag (im, "context", opt->ctx->id,
- opt->ctx, destructor_context);
- }
- __imlib_AttachTag (im, "index", opt->index, NULL, NULL);
- if (opt->traverse) {
- char* buf = NULL;
- if ((opt->index + opt->traverse)
- <= id3_tag_get_numframes (opt->ctx->tag)
- && (opt->index + opt->traverse) > 0) {
- buf = (char*) malloc
- ((strlen (im->real_file) + 50) * sizeof (char));
- sprintf (buf, "%s:index=%d,traverse=%d", im->real_file,
- opt->index + opt->traverse, opt->traverse);
- }
- __imlib_AttachTag (im, "next", 0, buf, destructor_data);
- }
+ struct id3_frame *frame = id3_tag_get_frame(opt->ctx->tag, opt->index - 1);
+ union id3_field *field;
+ int num_data;
+ char *data;
+
+ if ((field = id3_frame_field(frame, 1)) &&
+ (data = (char *)id3_field_getlatin1(field)))
+ __imlib_AttachTag(im, "mime-type", 0, strdup(data), destructor_data);
+ if ((field = id3_frame_field(frame, 3)) &&
+ (data = (char *)id3_field_getstring(field)))
+ {
+ size_t length;
+ char *dup;
+ id3_ucs4_t *ptr = (id3_ucs4_t *) data;
+
+ while (*ptr)
+ ptr++;
+ length = (ptr - (id3_ucs4_t *) data + 1) * sizeof(id3_ucs4_t);
+ dup = (char *)malloc(length);
+ memcpy(dup, data, length);
+ __imlib_AttachTag(im, "id3-description", 0, dup, destructor_data);
+ }
+ if (field = id3_frame_field(frame, 0))
+ __imlib_AttachTag(im, "id3-description-text-encoding",
+ (num_data = (int)id3_field_gettextencoding(field)),
+ num_data < NUM_OF_ID3_TEXT_ENCODINGS ?
+ id3_text_encodings[num_data] : NULL, NULL);
+ if (field = id3_frame_field(frame, 2))
+ __imlib_AttachTag(im, "id3-picture-type",
+ (num_data = id3_field_getint(field)),
+ num_data < NUM_OF_ID3_PIC_TYPES ?
+ id3_pic_types[num_data] : NULL, NULL);
+ __imlib_AttachTag(im, "count", id3_tag_get_numframes(opt->ctx->tag),
+ NULL, NULL);
+ if (opt->cache_level)
+ {
+ context_addref(opt->ctx);
+ __imlib_AttachTag(im, "context", opt->ctx->id,
+ opt->ctx, destructor_context);
+ }
+ __imlib_AttachTag(im, "index", opt->index, NULL, NULL);
+ if (opt->traverse)
+ {
+ char *buf = NULL;
+
+ if ((opt->index + opt->traverse)
+ <= id3_tag_get_numframes(opt->ctx->tag)
+ && (opt->index + opt->traverse) > 0)
+ {
+ buf = (char *)malloc((strlen(im->real_file) + 50) * sizeof(char));
+ sprintf(buf, "%s:index=%d,traverse=%d", im->real_file,
+ opt->index + opt->traverse, opt->traverse);
+ }
+ __imlib_AttachTag(im, "next", 0, buf, destructor_data);
+ }
}
-char load (ImlibImage *im, ImlibProgressFunction progress,
- char progress_granularity, char immediate_load)
+char
+load(ImlibImage * im, ImlibProgressFunction progress,
+ char progress_granularity, char immediate_load)
{
- ImlibLoader *loader;
- lopt opt;
- int res;
- struct stat st;
-
- assert (im);
- if (stat(im->real_file, &st) < 0)
- return 0;
- if (! get_options (&opt, im))
- return 0;
-
- if (! get_loader (&opt, &loader))
- goto fail_context;
-
- if (loader) {
- char *ofile, tmp[] = "/tmp/imlib2_loader_id3-XXXXXX";
- int dest;
-
- if ((dest = mkstemp (tmp)) < 0) {
- fprintf (stderr, "Unable to create a temporary file\n");
- goto fail_context;
- }
- res = extract_pic (id3_tag_get_frame (opt.ctx->tag,
- opt.index - 1), dest);
- close (dest);
-
- if (! res) {
- unlink (tmp);
- goto fail_context;
- }
-
- ofile = im->real_file;
- im->real_file = strdup (tmp);
- res = loader->load (im, progress,
- progress_granularity, immediate_load);
- free (im->real_file);
- im->real_file = ofile;
-
- unlink (tmp);
- } else {
- /* The tag actually provides a image url rather than image data.
- * Practically, dunno if such a tag exists on earth :)
- * Here's the code anyway...
- */
- union id3_field* field;
- id3_length_t length;
- char const* data;
- char *url, *file, *ofile;
-
- field = id3_frame_field
- (id3_tag_get_frame (opt.ctx->tag, opt.index - 1), 4);
- data = (char const*) id3_field_getbinarydata (field, &length);
- if (! data || ! length) {
- fprintf (stderr, "No link image URL present\n");
- goto fail_context;
- }
- url = (char*) malloc ((length + 1) * sizeof (char));
- strncpy (url, data, length);
- url[length] = '\0';
- file = (strncmp (url, "file://", 7) ? url : url + 7);
- if (! (loader = __imlib_FindBestLoaderForFile (file, 0))) {
- fprintf (stderr, "No loader found for file %s\n", file);
- free (url);
- goto fail_context;
- }
- ofile = im->real_file;
- im->real_file = file;
- res = loader->load (im, progress,
- progress_granularity, immediate_load);
- if (! im->loader)
- __imlib_AttachTag (im, "id3-link-url", 0,
- url, destructor_data);
- else
- free (url);
- im->real_file = ofile;
- }
-
- if (! im->loader)
- write_tags (im, &opt);
+ ImlibLoader *loader;
+ lopt opt;
+ int res;
+ struct stat st;
+
+ assert(im);
+ if (stat(im->real_file, &st) < 0)
+ return 0;
+ if (!get_options(&opt, im))
+ return 0;
+
+ if (!get_loader(&opt, &loader))
+ goto fail_context;
+
+ if (loader)
+ {
+ char *ofile, tmp[] = "/tmp/imlib2_loader_id3-XXXXXX";
+ int dest;
+
+ if ((dest = mkstemp(tmp)) < 0)
+ {
+ fprintf(stderr, "Unable to create a temporary file\n");
+ goto fail_context;
+ }
+ res = extract_pic(id3_tag_get_frame(opt.ctx->tag, opt.index - 1), dest);
+ close(dest);
+
+ if (!res)
+ {
+ unlink(tmp);
+ goto fail_context;
+ }
+
+ ofile = im->real_file;
+ im->real_file = strdup(tmp);
+ res = loader->load(im, progress, progress_granularity, immediate_load);
+ free(im->real_file);
+ im->real_file = ofile;
+
+ unlink(tmp);
+ }
+ else
+ {
+ /* The tag actually provides a image url rather than image data.
+ * Practically, dunno if such a tag exists on earth :)
+ * Here's the code anyway...
+ */
+ union id3_field *field;
+ id3_length_t length;
+ char const *data;
+ char *url, *file, *ofile;
+
+ field = id3_frame_field
+ (id3_tag_get_frame(opt.ctx->tag, opt.index - 1), 4);
+ data = (char const *)id3_field_getbinarydata(field, &length);
+ if (!data || !length)
+ {
+ fprintf(stderr, "No link image URL present\n");
+ goto fail_context;
+ }
+ url = (char *)malloc((length + 1) * sizeof(char));
+ strncpy(url, data, length);
+ url[length] = '\0';
+ file = (strncmp(url, "file://", 7) ? url : url + 7);
+ if (!(loader = __imlib_FindBestLoaderForFile(file, 0)))
+ {
+ fprintf(stderr, "No loader found for file %s\n", file);
+ free(url);
+ goto fail_context;
+ }
+ ofile = im->real_file;
+ im->real_file = file;
+ res = loader->load(im, progress, progress_granularity, immediate_load);
+ if (!im->loader)
+ __imlib_AttachTag(im, "id3-link-url", 0, url, destructor_data);
+ else
+ free(url);
+ im->real_file = ofile;
+ }
+
+ if (!im->loader)
+ write_tags(im, &opt);
#ifdef DEBUG
- if (! im->loader) {
- ImlibImageTag* cur = im->tags;
- fprintf (stderr, "Tags for file %s:\n", im->file);
- while (cur) {
- fprintf (stderr, "\t%s: (%d) %s\n", cur->key,
- cur->val, (char*) cur->data);
- cur = cur->next;
- }
- }
+ if (!im->loader)
+ {
+ ImlibImageTag *cur = im->tags;
+
+ fprintf(stderr, "Tags for file %s:\n", im->file);
+ while (cur)
+ {
+ fprintf(stderr, "\t%s: (%d) %s\n", cur->key,
+ cur->val, (char *)cur->data);
+ cur = cur->next;
+ }
+ }
#endif
- context_delref (opt.ctx);
- return res;
+ context_delref(opt.ctx);
+ return res;
-fail_context:
- context_delref (opt.ctx);
- return 0;
+ fail_context:
+ context_delref(opt.ctx);
+ return 0;
}
-void formats (ImlibLoader *l)
+void
+formats(ImlibLoader * l)
{
- /* this is the only bit you have to change... */
- char *list_formats[] = {"mp3"};
- int i;
-
- /* don't bother changing any of this - it just reads this in
- * and sets the struct values and makes copies
- */
- l->num_formats = sizeof (list_formats) / sizeof (char *);
- l->formats = (char**) malloc (sizeof (char *) * l->num_formats);
-
- for (i = 0; i < l->num_formats; i++)
- l->formats[i] = strdup (list_formats[i]);
+ /* this is the only bit you have to change... */
+ char *list_formats[] = { "mp3" };
+ int i;
+
+ /* don't bother changing any of this - it just reads this in
+ * and sets the struct values and makes copies
+ */
+ l->num_formats = sizeof(list_formats) / sizeof(char *);
+ l->formats = (char **)malloc(sizeof(char *) * l->num_formats);
+
+ for (i = 0; i < l->num_formats; i++)
+ l->formats[i] = strdup(list_formats[i]);
}
diff --git a/src/modules/loaders/loader_jpeg.c b/src/modules/loaders/loader_jpeg.c
index 085f368..94e956a 100644
--- a/src/modules/loaders/loader_jpeg.c
+++ b/src/modules/loaders/loader_jpeg.c
@@ -76,13 +76,13 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
im->w = w = cinfo.output_width;
im->h = h = cinfo.output_height;
- if (!IMAGE_DIMENSIONS_OK(w, h))
- {
+ if (!IMAGE_DIMENSIONS_OK(w, h))
+ {
im->w = im->h = 0;
jpeg_destroy_decompress(&cinfo);
fclose(f);
return 0;
- }
+ }
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("jpeg");
}
@@ -138,10 +138,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
for (x = 0; x < w; x++)
{
- *ptr2 =
- (0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) <<
- 8) |
- (ptr[2]);
+ *ptr2 = (0xff000000) | ((ptr[0]) << 16) |
+ ((ptr[1]) << 8) | (ptr[2]);
ptr += cinfo.output_components;
ptr2++;
}
@@ -184,10 +182,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
for (x = 0; x < w; x++)
{
- *ptr2 =
- (0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) <<
- 8) |
- (ptr[0]);
+ *ptr2 = (0xff000000) | ((ptr[0]) << 16) |
+ ((ptr[0]) << 8) | (ptr[0]);
ptr++;
ptr2++;
}
diff --git a/src/modules/loaders/loader_lbm.c b/src/modules/loaders/loader_lbm.c
index 6a869ce..8027eae 100644
--- a/src/modules/loaders/loader_lbm.c
+++ b/src/modules/loaders/loader_lbm.c
@@ -17,123 +17,149 @@
#define L2RWORD(a) ((((long)((a)[0]) & 0xff) << 8) + ((long)((a)[1]) & 0xff))
typedef struct CHUNK {
- long size;
- unsigned char *data;
+ long size;
+ unsigned char *data;
} CHUNK;
typedef struct ILBM {
- CHUNK bmhd;
- CHUNK camg;
- CHUNK cmap;
- CHUNK ctbl;
- CHUNK sham;
- CHUNK body;
-
- int depth;
- int mask;
- int ham;
- int hbrite;
-
- int row;
-
- int offset;
- int count;
- int rle;
+ CHUNK bmhd;
+ CHUNK camg;
+ CHUNK cmap;
+ CHUNK ctbl;
+ CHUNK sham;
+ CHUNK body;
+
+ int depth;
+ int mask;
+ int ham;
+ int hbrite;
+
+ int row;
+
+ int offset;
+ int count;
+ int rle;
} ILBM;
-
/*------------------------------------------------------------------------------
* Frees memory allocated as part of an ILBM structure.
*------------------------------------------------------------------------------*/
-static void freeilbm(ILBM *ilbm)
+static void
+freeilbm(ILBM * ilbm)
{
- if (ilbm->bmhd.data) free(ilbm->bmhd.data);
- if (ilbm->camg.data) free(ilbm->camg.data);
- if (ilbm->cmap.data) free(ilbm->cmap.data);
- if (ilbm->ctbl.data) free(ilbm->ctbl.data);
- if (ilbm->sham.data) free(ilbm->sham.data);
- if (ilbm->body.data) free(ilbm->body.data);
-
- memset(ilbm, 0, sizeof(*ilbm));
+ if (ilbm->bmhd.data)
+ free(ilbm->bmhd.data);
+ if (ilbm->camg.data)
+ free(ilbm->camg.data);
+ if (ilbm->cmap.data)
+ free(ilbm->cmap.data);
+ if (ilbm->ctbl.data)
+ free(ilbm->ctbl.data);
+ if (ilbm->sham.data)
+ free(ilbm->sham.data);
+ if (ilbm->body.data)
+ free(ilbm->body.data);
+
+ memset(ilbm, 0, sizeof(*ilbm));
}
-
/*------------------------------------------------------------------------------
* Reads the given chunks out of a file, returns 0 if the file had a problem.
*
* Format FORMsizeILBMtag.size....tag.size....tag.size....
*------------------------------------------------------------------------------*/
-static int loadchunks(char *name, ILBM *ilbm, int full)
+static int
+loadchunks(char *name, ILBM * ilbm, int full)
{
-CHUNK *c;
-FILE *f;
-size_t s;
-long formsize, pos, z;
-int ok, seek;
-char buf[12];
-
- ok = 0;
-
- f = fopen(name, "rb");
- if (f) {
+ CHUNK *c;
+ FILE *f;
+ size_t s;
+ long formsize, pos, z;
+ int ok, seek;
+ char buf[12];
+
+ ok = 0;
+
+ f = fopen(name, "rb");
+ if (f)
+ {
s = fread(buf, 1, 12, f);
- if (s == 12 && !memcmp(buf, "FORM", 4) && !memcmp(buf + 8, "ILBM", 4)) {
- memset(ilbm, 0, sizeof(*ilbm));
- formsize = L2RLONG(buf + 4);
-
- while (1) {
- pos = ftell(f);
- if (pos < 0 || pos >= formsize + 8) break; /* Error or FORM data is finished. */
- seek = 1;
-
- s = fread(buf, 1, 8, f);
- if (s != 8) break; /* Error or short file. */
-
- z = L2RLONG(buf + 4);
- if (z < 0) break; /* Corrupt file. */
-
- c = NULL;
- if (!memcmp(buf, "BMHD", 4)) c = &(ilbm->bmhd);
- else if (full) {
- if (!memcmp(buf, "CAMG", 4)) c = &(ilbm->camg);
- else if (!memcmp(buf, "CMAP", 4)) c = &(ilbm->cmap);
- else if (!memcmp(buf, "CTBL", 4)) c = &(ilbm->ctbl);
- else if (!memcmp(buf, "SHAM", 4)) c = &(ilbm->sham);
- else if (!memcmp(buf, "BODY", 4)) c = &(ilbm->body);
- }
-
- if (c && !c->data) {
- c->size = z;
- c->data = malloc(c->size);
- if (!c->data) break; /* Out of memory. */
-
- s = fread(c->data, 1, c->size, f);
- if (s != c->size) break; /* Error or short file. */
-
- seek = 0;
- if (!full) { /* Only BMHD required. */
- ok = 1;
- break;
+ if (s == 12 && !memcmp(buf, "FORM", 4) && !memcmp(buf + 8, "ILBM", 4))
+ {
+ memset(ilbm, 0, sizeof(*ilbm));
+ formsize = L2RLONG(buf + 4);
+
+ while (1)
+ {
+ pos = ftell(f);
+ if (pos < 0 || pos >= formsize + 8)
+ break; /* Error or FORM data is finished. */
+ seek = 1;
+
+ s = fread(buf, 1, 8, f);
+ if (s != 8)
+ break; /* Error or short file. */
+
+ z = L2RLONG(buf + 4);
+ if (z < 0)
+ break; /* Corrupt file. */
+
+ c = NULL;
+ if (!memcmp(buf, "BMHD", 4))
+ c = &(ilbm->bmhd);
+ else if (full)
+ {
+ if (!memcmp(buf, "CAMG", 4))
+ c = &(ilbm->camg);
+ else if (!memcmp(buf, "CMAP", 4))
+ c = &(ilbm->cmap);
+ else if (!memcmp(buf, "CTBL", 4))
+ c = &(ilbm->ctbl);
+ else if (!memcmp(buf, "SHAM", 4))
+ c = &(ilbm->sham);
+ else if (!memcmp(buf, "BODY", 4))
+ c = &(ilbm->body);
+ }
+
+ if (c && !c->data)
+ {
+ c->size = z;
+ c->data = malloc(c->size);
+ if (!c->data)
+ break; /* Out of memory. */
+
+ s = fread(c->data, 1, c->size, f);
+ if (s != c->size)
+ break; /* Error or short file. */
+
+ seek = 0;
+ if (!full)
+ { /* Only BMHD required. */
+ ok = 1;
+ break;
+ }
}
- }
- if (pos + 8 + z >= formsize + 8) break; /* This was last chunk. */
+ if (pos + 8 + z >= formsize + 8)
+ break; /* This was last chunk. */
- if (seek && fseek(f, z, SEEK_CUR) != 0) break;
- }
+ if (seek && fseek(f, z, SEEK_CUR) != 0)
+ break;
+ }
- /* File may end strangely, especially if body size is uneven, but it's
- * ok if we have the chunks we want. !full check is already done. */
- if (ilbm->bmhd.data && ilbm->body.data) ok = 1;
- if (!ok) freeilbm(ilbm);
- }
+ /* File may end strangely, especially if body size is uneven, but it's
+ * ok if we have the chunks we want. !full check is already done. */
+ if (ilbm->bmhd.data && ilbm->body.data)
+ ok = 1;
+ if (!ok)
+ freeilbm(ilbm);
+ }
fclose(f);
- }
+ }
- return ok;
+ return ok;
}
-
/*------------------------------------------------------------------------------
* Unpacks a row of possibly RLE data at a time.
*
@@ -145,227 +171,276 @@ char buf[12];
*
* In theory RLE compression is not supposed to create runs across scanlines.
*------------------------------------------------------------------------------*/
-static void bodyrow(unsigned char *p, int z, ILBM *ilbm)
+static void
+bodyrow(unsigned char *p, int z, ILBM * ilbm)
{
-int i, x, w;
-unsigned char b;
+ int i, x, w;
+ unsigned char b;
- if (ilbm->offset >= ilbm->body.size) {
+ if (ilbm->offset >= ilbm->body.size)
+ {
memset(p, 0, z);
return;
- }
+ }
- if (!ilbm->rle) {
+ if (!ilbm->rle)
+ {
w = ilbm->body.size - ilbm->offset;
- if (w > z) w = z;
+ if (w > z)
+ w = z;
memcpy(p, ilbm->body.data + ilbm->offset, w);
- if (w < z) memset(p + w, 0, z - w);
+ if (w < z)
+ memset(p + w, 0, z - w);
ilbm->offset += w;
return;
- }
+ }
- for (i = 0; i < z; ) {
+ for (i = 0; i < z;)
+ {
b = ilbm->body.data[ilbm->offset++];
- while (b == 0x80 && ilbm->offset < ilbm->body.size) b = ilbm->body.data[ilbm->offset++];
- if (ilbm->offset >= ilbm->body.size) break;
-
- if (b & 0x80) {
- w = (0x100 - b) + 1;
- if (w > z - i) w = z - i;
-
- b = ilbm->body.data[ilbm->offset++];
- memset(p + i, b, w);
- i += w;
- }
- else {
- w = (b & 0x7f) + 1;
- if (w > ilbm->body.size - ilbm->offset) w = ilbm->body.size - ilbm->offset;
- x = (w <= z - i)? w: z - i;
- memcpy(p + i, ilbm->body.data + ilbm->offset, x);
- i += x;
- ilbm->offset += w;
- }
- }
-
- if (i < z) memset(p, 0, z - i);
+ while (b == 0x80 && ilbm->offset < ilbm->body.size)
+ b = ilbm->body.data[ilbm->offset++];
+ if (ilbm->offset >= ilbm->body.size)
+ break;
+
+ if (b & 0x80)
+ {
+ w = (0x100 - b) + 1;
+ if (w > z - i)
+ w = z - i;
+
+ b = ilbm->body.data[ilbm->offset++];
+ memset(p + i, b, w);
+ i += w;
+ }
+ else
+ {
+ w = (b & 0x7f) + 1;
+ if (w > ilbm->body.size - ilbm->offset)
+ w = ilbm->body.size - ilbm->offset;
+ x = (w <= z - i) ? w : z - i;
+ memcpy(p + i, ilbm->body.data + ilbm->offset, x);
+ i += x;
+ ilbm->offset += w;
+ }
+ }
+
+ if (i < z)
+ memset(p, 0, z - i);
}
-
/*------------------------------------------------------------------------------
* Shifts a value to produce an 8-bit colour gun, and fills in the lower bits
* from the high bits of the value so that, for example, 4-bit 0x0f scales to
* 0xff, or 1-bit 0x01 scales to 0xff.
*------------------------------------------------------------------------------*/
-static unsigned char scalegun(unsigned char v, int sl)
+static unsigned char
+scalegun(unsigned char v, int sl)
{
-int sr;
+ int sr;
- switch (sl) {
- case 1:
- case 2:
- case 3:
- sr = 8 - sl;
- return (v << sl) | (v >> sr);
+ switch (sl)
+ {
+ case 1:
+ case 2:
+ case 3:
+ sr = 8 - sl;
+ return (v << sl) | (v >> sr);
- case 4:
- return (v << 4) | v;
+ case 4:
+ return (v << 4) | v;
- case 5:
- return v * 0x24;
+ case 5:
+ return v * 0x24;
- case 6:
- return v * 0x55;
+ case 6:
+ return v * 0x55;
- case 7:
- return v * 0xff;
- }
- return v;
+ case 7:
+ return v * 0xff;
+ }
+ return v;
}
-
/*------------------------------------------------------------------------------
* Scales the colours in a CMAP chunk if they all look like 4-bit colour, so
* that they use all 8-bits. This is done by copying the high nybble into the
* low nybble, so for example 0xf0 becomes 0xff.
*------------------------------------------------------------------------------*/
-static void scalecmap(ILBM *ilbm)
+static void
+scalecmap(ILBM * ilbm)
{
-int i;
+ int i;
- if (!ilbm->cmap.data) return;
+ if (!ilbm->cmap.data)
+ return;
- for (i = 0; i < ilbm->cmap.size; i++)
- if (ilbm->cmap.data[i] & 0x0f) return;
+ for (i = 0; i < ilbm->cmap.size; i++)
+ if (ilbm->cmap.data[i] & 0x0f)
+ return;
- for (i = 0; i < ilbm->cmap.size; i++)
- ilbm->cmap.data[i] |= ilbm->cmap.data[i] >> 4;
+ for (i = 0; i < ilbm->cmap.size; i++)
+ ilbm->cmap.data[i] |= ilbm->cmap.data[i] >> 4;
}
-
/*------------------------------------------------------------------------------
* Deplanes and converts an array of bitplanes to a single scanline of DATA32
* (unsigned int) values. DATA32 is ARGB.
*------------------------------------------------------------------------------*/
-static void deplane(DATA32 *row, int w, ILBM *ilbm, unsigned char *plane[])
+static void
+deplane(DATA32 * row, int w, ILBM * ilbm, unsigned char *plane[])
{
-unsigned long l;
-int i, o, x;
-unsigned char bit, r, g, b, a, v, h, *pal;
-
- pal = NULL;
- if (ilbm->sham.data && ilbm->sham.size >= 2 + (ilbm->row + 1) * 2 * 16)
- pal = ilbm->sham.data + 2 + ilbm->row * 2 * 16;
- if (ilbm->ctbl.data && ilbm->ctbl.size >= (ilbm->row + 1) * 2 * 16)
- pal = ilbm->ctbl.data + ilbm->row * 2 * 16;
-
- if (ilbm->ham) r = g = b = 0;
-
- bit = 0x80;
- o = 0;
- for (x = 0; x < w; x++) {
+ unsigned long l;
+ int i, o, x;
+ unsigned char bit, r, g, b, a, v, h, *pal;
+
+ pal = NULL;
+ if (ilbm->sham.data && ilbm->sham.size >= 2 + (ilbm->row + 1) * 2 * 16)
+ pal = ilbm->sham.data + 2 + ilbm->row * 2 * 16;
+ if (ilbm->ctbl.data && ilbm->ctbl.size >= (ilbm->row + 1) * 2 * 16)
+ pal = ilbm->ctbl.data + ilbm->row * 2 * 16;
+
+ if (ilbm->ham)
+ r = g = b = 0;
+
+ bit = 0x80;
+ o = 0;
+ for (x = 0; x < w; x++)
+ {
l = 0;
- for (i = ilbm->depth - 1; i >= 0; i--) {
- l = l << 1;
- if (plane[i][o] & bit) l = l | 1;
- }
- a = (ilbm->mask == 0 || (ilbm->mask == 1 && (plane[ilbm->depth][o] & bit)) || ilbm->mask == 2)? 0xff: 0x00;
-
- if (ilbm->depth == 32) {
- a = (l >> 24) & 0xff;
- b = (l >> 16) & 0xff;
- g = (l >> 8) & 0xff;
- r = l & 0xff;
- }
- else if (ilbm->depth == 24) {
- b = (l >> 16) & 0xff;
- g = (l >> 8) & 0xff;
- r = l & 0xff;
- }
- else if (ilbm->ham) {
- v = l & ((1 << (ilbm->depth - 2)) - 1);
- h = (l & ~v) >> (ilbm->depth - 2);
-
- if (h == 0x00) {
- if (!pal) {
- if ((v + 1) * 3 <= ilbm->cmap.size) {
- r = ilbm->cmap.data[v * 3];
- g = ilbm->cmap.data[v * 3 + 1];
- b = ilbm->cmap.data[v * 3 + 2];
+ for (i = ilbm->depth - 1; i >= 0; i--)
+ {
+ l = l << 1;
+ if (plane[i][o] & bit)
+ l = l | 1;
+ }
+ a = (ilbm->mask == 0
+ || (ilbm->mask == 1 && (plane[ilbm->depth][o] & bit))
+ || ilbm->mask == 2) ? 0xff : 0x00;
+
+ if (ilbm->depth == 32)
+ {
+ a = (l >> 24) & 0xff;
+ b = (l >> 16) & 0xff;
+ g = (l >> 8) & 0xff;
+ r = l & 0xff;
+ }
+ else if (ilbm->depth == 24)
+ {
+ b = (l >> 16) & 0xff;
+ g = (l >> 8) & 0xff;
+ r = l & 0xff;
+ }
+ else if (ilbm->ham)
+ {
+ v = l & ((1 << (ilbm->depth - 2)) - 1);
+ h = (l & ~v) >> (ilbm->depth - 2);
+
+ if (h == 0x00)
+ {
+ if (!pal)
+ {
+ if ((v + 1) * 3 <= ilbm->cmap.size)
+ {
+ r = ilbm->cmap.data[v * 3];
+ g = ilbm->cmap.data[v * 3 + 1];
+ b = ilbm->cmap.data[v * 3 + 2];
+ }
+ else
+ r = g = b = 0;
+ }
+ else
+ {
+ r = scalegun(pal[v * 2] & 0x0f, 4);
+ g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
+ b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
+ }
+ }
+ else if (h == 0x01)
+ b = scalegun(v, 8 - (ilbm->depth - 2));
+ else if (h == 0x02)
+ r = scalegun(v, 8 - (ilbm->depth - 2));
+ else
+ g = scalegun(v, 8 - (ilbm->depth - 2));
+ }
+ else if (ilbm->hbrite)
+ {
+ v = l & ((1 << (ilbm->depth - 1)) - 1);
+ h = (l & ~v) >> (ilbm->depth - 1);
+
+ if (!pal)
+ {
+ if ((v + 1) * 3 <= ilbm->cmap.size)
+ {
+ r = ilbm->cmap.data[v * 3];
+ g = ilbm->cmap.data[v * 3 + 1];
+ b = ilbm->cmap.data[v * 3 + 2];
}
- else r = g = b = 0;
- }
- else {
- r = scalegun(pal[v * 2] & 0x0f, 4);
- g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
- b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
- }
- }
- else if (h == 0x01) b = scalegun(v, 8 - (ilbm->depth - 2));
- else if (h == 0x02) r = scalegun(v, 8 - (ilbm->depth - 2));
- else g = scalegun(v, 8 - (ilbm->depth - 2));
- }
- else if (ilbm->hbrite) {
- v = l & ((1 << (ilbm->depth - 1)) - 1);
- h = (l & ~v) >> (ilbm->depth - 1);
-
- if (!pal) {
- if ((v + 1) * 3 <= ilbm->cmap.size) {
- r = ilbm->cmap.data[v * 3];
- g = ilbm->cmap.data[v * 3 + 1];
- b = ilbm->cmap.data[v * 3 + 2];
- }
- else r = g = b = 0;
- }
- else {
- r = scalegun(pal[v * 2] & 0x0f, 4);
- g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
- b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
- }
-
- if (h) {
- r = r >> 1;
- g = g >> 1;
- b = b >> 1;
- }
-
- if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12)) a = 0x00;
- }
- else if (ilbm->cmap.size == 0 && !pal) {
- v = l & ((1 << ilbm->depth) - 1);
- r = scalegun(v, ilbm->depth);
- g = r;
- b = r;
- }
- else {
- v = l & 0xff;
- if (!pal) {
- if ((v + 1) * 3 <= ilbm->cmap.size) {
- r = ilbm->cmap.data[v * 3];
- g = ilbm->cmap.data[v * 3 + 1];
- b = ilbm->cmap.data[v * 3 + 2];
- }
- else r = g = b = 0;
- }
- else {
- r = scalegun(pal[v * 2] & 0x0f, 4);
- g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
- b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
- }
-
- if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12)) a = 0x00;
- }
-
- row[x] = ((unsigned long)a << 24) | ((unsigned long)r << 16) | ((unsigned long)g << 8) | (unsigned long)b;
+ else
+ r = g = b = 0;
+ }
+ else
+ {
+ r = scalegun(pal[v * 2] & 0x0f, 4);
+ g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
+ b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
+ }
+
+ if (h)
+ {
+ r = r >> 1;
+ g = g >> 1;
+ b = b >> 1;
+ }
+
+ if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12))
+ a = 0x00;
+ }
+ else if (ilbm->cmap.size == 0 && !pal)
+ {
+ v = l & ((1 << ilbm->depth) - 1);
+ r = scalegun(v, ilbm->depth);
+ g = r;
+ b = r;
+ }
+ else
+ {
+ v = l & 0xff;
+ if (!pal)
+ {
+ if ((v + 1) * 3 <= ilbm->cmap.size)
+ {
+ r = ilbm->cmap.data[v * 3];
+ g = ilbm->cmap.data[v * 3 + 1];
+ b = ilbm->cmap.data[v * 3 + 2];
+ }
+ else
+ r = g = b = 0;
+ }
+ else
+ {
+ r = scalegun(pal[v * 2] & 0x0f, 4);
+ g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
+ b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
+ }
+
+ if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12))
+ a = 0x00;
+ }
+
+ row[x] =
+ ((unsigned long)a << 24) | ((unsigned long)r << 16) |
+ ((unsigned long)g << 8) | (unsigned long)b;
bit = bit >> 1;
- if (bit == 0) {
- o++;
- bit = 0x80;
- }
- }
+ if (bit == 0)
+ {
+ o++;
+ bit = 0x80;
+ }
+ }
}
-
/*------------------------------------------------------------------------------
* Loads an image. If im->loader is non-zero, or immediate_load is non-zero, or
* progress is non-zero, then the file is fully loaded, otherwise only the width
@@ -373,74 +448,97 @@ unsigned char bit, r, g, b, a, v, h, *pal;
*
* Imlib2 doesn't support reading comment chunks like ANNO.
*------------------------------------------------------------------------------*/
-char load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, char immediate_load)
+char
+load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
+ char immediate_load)
{
-char *env;
-int cancel, full, i, n, ok, y, z, gran, nexty, prevy;
-unsigned char *plane[40];
-ILBM ilbm;
+ char *env;
+ int cancel, full, i, n, ok, y, z, gran, nexty, prevy;
+ unsigned char *plane[40];
+ ILBM ilbm;
/*----------
* Do nothing if the data is already loaded.
*----------*/
- if (im->data) return 0;
+ if (im->data)
+ return 0;
/*----------
* Load the chunk(s) we're interested in. If full is not true, then we only
* want the image size and format.
*----------*/
- full = (im->loader || immediate_load || progress);
- ok = loadchunks(im->real_file, &ilbm, full);
- if (!ok) return 0;
+ full = (im->loader || immediate_load || progress);
+ ok = loadchunks(im->real_file, &ilbm, full);
+ if (!ok)
+ return 0;
/*----------
* Use and check header.
*----------*/
- ok = 0;
- if (ilbm.bmhd.size >= 20) {
+ ok = 0;
+ if (ilbm.bmhd.size >= 20)
+ {
ok = 1;
im->w = L2RWORD(ilbm.bmhd.data);
im->h = L2RWORD(ilbm.bmhd.data + 2);
- if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
- {
- ok = 0;
- }
+ if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
+ {
+ ok = 0;
+ }
ilbm.depth = ilbm.bmhd.data[8];
- if (ilbm.depth < 1 || (ilbm.depth > 8 && ilbm.depth != 24 && ilbm.depth != 32)) ok = 0; /* Only 1 to 8, 24, or 32 planes. */
+ if (ilbm.depth < 1
+ || (ilbm.depth > 8 && ilbm.depth != 24 && ilbm.depth != 32))
+ ok = 0; /* Only 1 to 8, 24, or 32 planes. */
ilbm.rle = ilbm.bmhd.data[10];
- if (ilbm.rle < 0 || ilbm.rle > 1) ok = 0; /* Only NONE or RLE compression. */
+ if (ilbm.rle < 0 || ilbm.rle > 1)
+ ok = 0; /* Only NONE or RLE compression. */
ilbm.mask = ilbm.bmhd.data[9];
- if (ilbm.mask || ilbm.depth == 32) SET_FLAG(im->flags, F_HAS_ALPHA);
- else UNSET_FLAG(im->flags, F_HAS_ALPHA);
+ if (ilbm.mask || ilbm.depth == 32)
+ SET_FLAG(im->flags, F_HAS_ALPHA);
+ else
+ UNSET_FLAG(im->flags, F_HAS_ALPHA);
env = getenv("IMLIB2_LBM_NOMASK");
- if (env && (!strcmp(env, "true") || !strcmp(env, "1") || !strcmp(env, "yes") || !strcmp(env, "on"))) UNSET_FLAG(im->flags, F_HAS_ALPHA);
+ if (env
+ && (!strcmp(env, "true") || !strcmp(env, "1") || !strcmp(env, "yes")
+ || !strcmp(env, "on")))
+ UNSET_FLAG(im->flags, F_HAS_ALPHA);
- if (!im->format) im->format = strdup("lbm");
+ if (!im->format)
+ im->format = strdup("lbm");
ilbm.ham = 0;
ilbm.hbrite = 0;
- if (ilbm.depth <= 8) {
- if (ilbm.camg.size == 4) {
- if (ilbm.camg.data[2] & 0x08) ilbm.ham = 1;
- if (ilbm.camg.data[3] & 0x80) ilbm.hbrite = 1;
- }
- else { /* Only guess at ham and hbrite if CMAP is present. */
- if (ilbm.depth == 6 && full && ilbm.cmap.size >= 3 * 16) ilbm.ham = 1;
- if (full && !ilbm.ham && ilbm.depth > 1 && ilbm.cmap.size == 3 * (1 << (ilbm.depth - 1))) ilbm.hbrite = 1;
- }
- }
- }
- if (!full || !ok) {
+ if (ilbm.depth <= 8)
+ {
+ if (ilbm.camg.size == 4)
+ {
+ if (ilbm.camg.data[2] & 0x08)
+ ilbm.ham = 1;
+ if (ilbm.camg.data[3] & 0x80)
+ ilbm.hbrite = 1;
+ }
+ else
+ { /* Only guess at ham and hbrite if CMAP is present. */
+ if (ilbm.depth == 6 && full && ilbm.cmap.size >= 3 * 16)
+ ilbm.ham = 1;
+ if (full && !ilbm.ham && ilbm.depth > 1
+ && ilbm.cmap.size == 3 * (1 << (ilbm.depth - 1)))
+ ilbm.hbrite = 1;
+ }
+ }
+ }
+ if (!full || !ok)
+ {
im->w = im->h = 0;
freeilbm(&ilbm);
return ok;
- }
+ }
/*----------
* The source data is planar. Each plane is an even number of bytes wide. If
@@ -448,88 +546,102 @@ ILBM ilbm;
* from each plane are interleaved, from top to bottom. The first plane is the
* 0 bit.
*----------*/
- ok = 0;
- cancel = 0;
- plane[0] = NULL;
-
- im->data = malloc(im->w * im->h * sizeof(DATA32));
- n = ilbm.depth;
- if (ilbm.mask == 1) n++;
- plane[0] = malloc(((im->w + 15) / 16) * 2 * n);
- if (im->data && plane[0]) {
- for (i = 1; i < n; i++) plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2;
+ ok = 0;
+ cancel = 0;
+ plane[0] = NULL;
+
+ im->data = malloc(im->w * im->h * sizeof(DATA32));
+ n = ilbm.depth;
+ if (ilbm.mask == 1)
+ n++;
+ plane[0] = malloc(((im->w + 15) / 16) * 2 * n);
+ if (im->data && plane[0])
+ {
+ for (i = 1; i < n; i++)
+ plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2;
z = ((im->w + 15) / 16) * 2 * n;
- if (progress) {
- prevy = 0;
- if (progress_granularity <= 0) progress_granularity = 1;
- gran = progress_granularity;
- nexty = ((im->h * gran) / 100);
- }
+ if (progress)
+ {
+ prevy = 0;
+ if (progress_granularity <= 0)
+ progress_granularity = 1;
+ gran = progress_granularity;
+ nexty = ((im->h * gran) / 100);
+ }
scalecmap(&ilbm);
- for (y = 0; y < im->h; y++) {
- bodyrow(plane[0], z, &ilbm);
-
- deplane(im->data + im->w * y, im->w, &ilbm, plane);
- ilbm.row++;
-
- if (progress && (y >= nexty || y == im->h - 1)) {
- if (!progress(im, (char)((100 * (y + 1)) / im->h), 0, prevy, im->w, y + 1)) {
- cancel = 1;
- break;
- }
- prevy = y;
- gran += progress_granularity;
- nexty = ((im->h * gran) / 100);
- }
- }
+ for (y = 0; y < im->h; y++)
+ {
+ bodyrow(plane[0], z, &ilbm);
+
+ deplane(im->data + im->w * y, im->w, &ilbm, plane);
+ ilbm.row++;
+
+ if (progress && (y >= nexty || y == im->h - 1))
+ {
+ if (!progress
+ (im, (char)((100 * (y + 1)) / im->h), 0, prevy, im->w,
+ y + 1))
+ {
+ cancel = 1;
+ break;
+ }
+ prevy = y;
+ gran += progress_granularity;
+ nexty = ((im->h * gran) / 100);
+ }
+ }
ok = !cancel;
- }
+ }
/*----------
* We either had a successful decode, the user cancelled, or we couldn't get
* the memory for im->data or plane[0].
*----------*/
- if (!ok) {
+ if (!ok)
+ {
im->w = im->h = 0;
- if (im->data) free(im->data);
+ if (im->data)
+ free(im->data);
im->data = NULL;
- }
+ }
- if (plane[0]) free(plane[0]);
+ if (plane[0])
+ free(plane[0]);
- freeilbm(&ilbm);
+ freeilbm(&ilbm);
- return (cancel)? 2: ok;
+ return (cancel) ? 2 : ok;
}
-
/*------------------------------------------------------------------------------
* Perhaps save only in 32-bit format? The IFF ILBM format has pretty much gone
* the way of the Amiga, who saves in this format any more?
*------------------------------------------------------------------------------*/
#if 0
-char save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity)
+char
+save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
- return 0;
+ return 0;
}
#endif
-
/*------------------------------------------------------------------------------
* Identifies the file extensions this loader handles. Standard code from other
* loaders.
*------------------------------------------------------------------------------*/
-void formats(ImlibLoader *l)
+void
+formats(ImlibLoader * l)
{
-char *list_formats[] = { "iff", "ilbm", "lbm" };
-int i;
+ char *list_formats[] = { "iff", "ilbm", "lbm" };
+ int i;
- l->num_formats = sizeof(list_formats) / sizeof(list_formats[0]);
- l->formats = malloc(l->num_formats * sizeof(list_formats[0]));
- for (i = 0; i < l->num_formats; i++) l->formats[i] = strdup(list_formats[i]);
+ l->num_formats = sizeof(list_formats) / sizeof(list_formats[0]);
+ l->formats = malloc(l->num_formats * sizeof(list_formats[0]));
+ for (i = 0; i < l->num_formats; i++)
+ l->formats[i] = strdup(list_formats[i]);
}
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index e776a55..fbfb991 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -45,7 +45,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
}
rewind(f);
png_ptr =
- png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fclose(f);
@@ -110,7 +110,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
png_set_palette_to_rgb(png_ptr);
/* expand gray (w/reduced bits) -> 8-bit RGB if necessary */
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
- (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
+ (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
{
png_set_gray_to_rgb(png_ptr);
if (bit_depth < 8)
@@ -166,7 +166,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (progress)
{
int y, count, prevy, pass, number_passes, per,
- nrows = 1;
+ nrows = 1;
count = 0;
number_passes = png_set_interlace_handling(png_ptr);
@@ -278,7 +278,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
if ((tag = __imlib_GetTag(im, "interlacing")) && tag->val)
{
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
- interlace = PNG_INTERLACE_ADAM7;
+ interlace = PNG_INTERLACE_ADAM7;
#endif
}
@@ -350,51 +350,51 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
for (pass = 0; pass < num_passes; pass++)
{
- ptr = im->data;
+ ptr = im->data;
- for (y = 0; y < im->h; y++)
- {
- if (im->flags & F_HAS_ALPHA)
- row_ptr = (png_bytep) ptr;
- else
- {
- for (j = 0, x = 0; x < im->w; x++)
- {
- data[j++] = (ptr[x] >> 16) & 0xff;
- data[j++] = (ptr[x] >> 8) & 0xff;
- data[j++] = (ptr[x]) & 0xff;
- }
- row_ptr = (png_bytep) data;
- }
- png_write_rows(png_ptr, &row_ptr, 1);
- if (progress)
- {
- char per;
- int l;
+ for (y = 0; y < im->h; y++)
+ {
+ if (im->flags & F_HAS_ALPHA)
+ row_ptr = (png_bytep) ptr;
+ else
+ {
+ for (j = 0, x = 0; x < im->w; x++)
+ {
+ data[j++] = (ptr[x] >> 16) & 0xff;
+ data[j++] = (ptr[x] >> 8) & 0xff;
+ data[j++] = (ptr[x]) & 0xff;
+ }
+ row_ptr = (png_bytep) data;
+ }
+ png_write_rows(png_ptr, &row_ptr, 1);
+ if (progress)
+ {
+ char per;
+ int l;
- per = 100 * (pass + y / (float) im->h) / num_passes;
- if ((per - pper) >= progress_granularity)
- {
- l = y - pl;
- if (!progress(im, per, 0, (y - l), im->w, l))
- {
- if (data)
- free(data);
- png_write_end(png_ptr, info_ptr);
- png_destroy_write_struct(&png_ptr,
- (png_infopp) & info_ptr);
- png_destroy_info_struct(png_ptr,
- (png_infopp) & info_ptr);
- fclose(f);
- return 2;
- }
- pper = per;
- pl = y;
- }
- }
- ptr += im->w;
- }
- }
+ per = 100 * (pass + y / (float)im->h) / num_passes;
+ if ((per - pper) >= progress_granularity)
+ {
+ l = y - pl;
+ if (!progress(im, per, 0, (y - l), im->w, l))
+ {
+ if (data)
+ free(data);
+ png_write_end(png_ptr, info_ptr);
+ png_destroy_write_struct(&png_ptr,
+ (png_infopp) & info_ptr);
+ png_destroy_info_struct(png_ptr,
+ (png_infopp) & info_ptr);
+ fclose(f);
+ return 2;
+ }
+ pper = per;
+ pl = y;
+ }
+ }
+ ptr += im->w;
+ }
+ }
if (data)
free(data);
png_write_end(png_ptr, info_ptr);
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index 04ea4e4..afbee22 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -79,18 +79,18 @@ 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;
}
}
}
@@ -105,8 +105,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
im->h = h;
if (!IMAGE_DIMENSIONS_OK(w, h))
{
- fclose(f);
- return 0;
+ fclose(f);
+ return 0;
}
if (!im->format)
{
@@ -138,551 +138,557 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* 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')
- *ptr2 = 0xffffffff;
- 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;
-
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, 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)
- {
- int k;
- /* check 4 chars ahead to see if we need to
- fill the buffer */
- for (k = 0; k < 4; k++)
- {
- if (!buf[i+k]) /* fill buffer */
- {
- if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
- {
- free(idata);
- fclose(f);
- return 0;
- }
- i = 0;
- break;
- }
- }
- 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;
-
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- 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)
- {
- int k;
- /* check 4 chars ahead to see if we need to
- fill the buffer */
- for (k = 0; k < 4; k++)
- {
- if (!buf[i+k]) /* fill buffer */
- {
- if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
- {
- free(idata);
- fclose(f);
- return 0;
- }
- i = 0;
- break;
- }
- }
- while (buf[i] && isspace(buf[i]))
+ 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')
+ *ptr2 = 0xffffffff;
+ else
+ {
+ fclose(f);
+ return 0;
+ }
+ ptr2++;
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 | (((iptr[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;
-
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- 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;
-
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- 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;
-
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- 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 = 0;
-
- per = (char)((100 * y) / im->h);
- if (((per - pper) >= progress_granularity)
- || (y == (im->h - 1)))
- {
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- 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 = 0;
-
- per = (char)((100 * y) / im->h);
- if (((per - pper) >= progress_granularity)
- || (y == (im->h - 1)))
- {
- /* fix off by one in case of the last line */
- if (y == (im->h - 1))
- l++;
-
- if (!progress(im, per, 0, pl, im->w, l))
- {
- free(data);
- fclose(f);
- return 2;
- }
- pper = per;
- pl = y;
- }
- }
- }
- break;
- default:
- fclose(f);
- return 0;
- break;
+ }
+ }
+ if (progress)
+ {
+ char per;
+ int l;
+
+ per = (char)((100 * y) / im->h);
+ if (((per - pper) >= progress_granularity)
+ || (y == (im->h - 1)))
+ {
+ l = y - pl;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, 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)
+ {
+ int k;
+
+ /* check 4 chars ahead to see if we need to
+ * fill the buffer */
+ for (k = 0; k < 4; k++)
+ {
+ if (!buf[i + k]) /* fill buffer */
+ {
+ if (fseek(f, -k, SEEK_CUR) == -1 ||
+ !fgets(buf, 255, f))
+ {
+ free(idata);
+ fclose(f);
+ return 0;
+ }
+ i = 0;
+ break;
+ }
+ }
+ 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;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ 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)
+ {
+ int k;
+
+ /* check 4 chars ahead to see if we need to
+ * fill the buffer */
+ for (k = 0; k < 4; k++)
+ {
+ if (!buf[i + k]) /* fill buffer */
+ {
+ if (fseek(f, -k, SEEK_CUR) == -1 ||
+ !fgets(buf, 255, f))
+ {
+ free(idata);
+ fclose(f);
+ return 0;
+ }
+ i = 0;
+ break;
+ }
+ }
+ 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 |
+ (((iptr[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;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ 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;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ 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;
+
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ 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 = 0;
+
+ per = (char)((100 * y) / im->h);
+ if (((per - pper) >= progress_granularity)
+ || (y == (im->h - 1)))
+ {
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ 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 = 0;
+
+ per = (char)((100 * y) / im->h);
+ if (((per - pper) >= progress_granularity)
+ || (y == (im->h - 1)))
+ {
+ /* fix off by one in case of the last line */
+ if (y == (im->h - 1))
+ l++;
+
+ if (!progress(im, per, 0, pl, im->w, l))
+ {
+ free(data);
+ fclose(f);
+ return 2;
+ }
+ pper = per;
+ pl = y;
+ }
+ }
+ }
+ break;
+ default:
+ fclose(f);
+ return 0;
+ break;
}
if (idata)
free(idata);
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c
index 80fb749..d132e1e 100644
--- a/src/modules/loaders/loader_tga.c
+++ b/src/modules/loaders/loader_tga.c
@@ -156,7 +156,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l))
{
- free(buf);
+ free(buf);
fclose(f);
return 2;
}
@@ -192,13 +192,13 @@ load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
int fd;
- void *seg, *filedata;
+ void *seg, *filedata;
struct stat ss;
int bpp, vinverted = 0;
int rle = 0, footer_present = 0;
- tga_header *header;
- tga_footer *footer;
+ tga_header *header;
+ tga_footer *footer;
if (im->data)
return 0;
@@ -222,7 +222,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (seg == MAP_FAILED)
{
close(fd);
- return 0;
+ return 0;
}
filedata = seg;
@@ -239,10 +239,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* skip over header */
filedata = (char *)filedata + sizeof(tga_header);
-
+
/* skip over alphanumeric ID field */
if (header->idLength)
- filedata = (char *)filedata + header->idLength;
+ filedata = (char *)filedata + header->idLength;
/* now parse the header */
@@ -251,20 +251,20 @@ load(ImlibImage * im, ImlibProgressFunction progress,
switch (header->imageType)
{
- case TGA_TYPE_COLOR_RLE:
- case TGA_TYPE_GRAY_RLE:
- rle = 1;
- break;
-
- case TGA_TYPE_COLOR:
- case TGA_TYPE_GRAY:
- rle = 0;
- break;
-
- default:
- munmap(seg, ss.st_size);
- close(fd);
- return 0;
+ case TGA_TYPE_COLOR_RLE:
+ case TGA_TYPE_GRAY_RLE:
+ rle = 1;
+ break;
+
+ case TGA_TYPE_COLOR:
+ case TGA_TYPE_GRAY:
+ rle = 0;
+ break;
+
+ default:
+ munmap(seg, ss.st_size);
+ close(fd);
+ return 0;
}
/* bits per pixel */
@@ -272,7 +272,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!((bpp == 32) || (bpp == 24) || (bpp == 8)))
{
- munmap(seg, ss.st_size);
+ munmap(seg, ss.st_size);
close(fd);
return 0;
}
@@ -283,7 +283,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
{
- munmap(seg, ss.st_size);
+ munmap(seg, ss.st_size);
close(fd);
return 0;
}
@@ -311,7 +311,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!im->data)
{
im->w = 0;
- munmap(seg, ss.st_size);
+ munmap(seg, ss.st_size);
close(fd);
return 0;
}
@@ -323,13 +323,13 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* (this is NOT simply width*height*4, due to compression) */
datasize = ss.st_size - sizeof(tga_header) - header->idLength -
- (footer_present ? sizeof(tga_footer) : 0);
+ (footer_present ? sizeof(tga_footer) : 0);
/* buffer is ready for parsing */
/* bufptr is the next byte to be read from the buffer */
bufptr = filedata;
- bufend = filedata + datasize;
+ bufend = filedata + datasize;
/* dataptr is the next 32-bit pixel to be filled in */
dataptr = im->data;
@@ -348,56 +348,50 @@ load(ImlibImage * im, ImlibProgressFunction progress,
else
dataptr = im->data + (y * im->w);
- for (x = 0;
- (x < im->w) && (bufptr + bpp / 8 <= bufend);
- x++) /* for each pixel in the row */
+ for (x = 0; (x < im->w) && (bufptr + bpp / 8 <= bufend); x++) /* for each pixel in the row */
{
switch (bpp)
{
- /* 32-bit BGRA pixels */
- case 32:
- WRITE_RGBA(dataptr,
- *(bufptr + 2), /* R */
- *(bufptr + 1), /* G */
- *(bufptr + 0), /* B */
- *(bufptr + 3) /* A */
- );
- dataptr++;
- bufptr += 4;
- break;
-
- /* 24-bit BGR pixels */
- case 24:
- WRITE_RGBA(dataptr,
- *(bufptr + 2), /* R */
- *(bufptr + 1), /* G */
- *(bufptr + 0), /* B */
- (char)0xff /* A */
- );
- dataptr++;
- bufptr += 3;
- break;
-
- /* 8-bit grayscale */
- case 8:
- WRITE_RGBA(dataptr, /* grayscale */
- *bufptr,
- *bufptr,
- *bufptr, (char)0xff);
- dataptr++;
- bufptr += 1;
- break;
+ /* 32-bit BGRA pixels */
+ case 32:
+ WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
+ *(bufptr + 1), /* G */
+ *(bufptr + 0), /* B */
+ *(bufptr + 3) /* A */
+ );
+ dataptr++;
+ bufptr += 4;
+ break;
+
+ /* 24-bit BGR pixels */
+ case 24:
+ WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
+ *(bufptr + 1), /* G */
+ *(bufptr + 0), /* B */
+ (char)0xff /* A */
+ );
+ dataptr++;
+ bufptr += 3;
+ break;
+
+ /* 8-bit grayscale */
+ case 8:
+ WRITE_RGBA(dataptr, /* grayscale */
+ *bufptr, *bufptr, *bufptr, (char)0xff);
+ dataptr++;
+ bufptr += 1;
+ break;
}
} /* end for (each pixel) */
- }
- if (progress)
- {
- progress(im, 100, 0, 0, im->w, im->h);
- } /* end for (each row) */
+ }
+ if (progress)
+ {
+ progress(im, 100, 0, 0, im->w, im->h);
+ } /* end for (each row) */
}
- /* end if (!RLE) */
+ /* end if (!RLE) */
/* decode RLE compressed data */
else
{
@@ -405,9 +399,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
DATA32 *final_pixel = dataptr + im->w * im->h;
/* loop until we've got all the pixels or run out of input */
- while ((dataptr < final_pixel) &&
- ((bufptr + 1 + (bpp / 8)) <= bufend))
- {
+ while ((dataptr < final_pixel) &&
+ ((bufptr + 1 + (bpp / 8)) <= bufend))
+ {
int count;
curbyte = *bufptr++;
@@ -419,39 +413,42 @@ load(ImlibImage * im, ImlibProgressFunction progress,
switch (bpp)
{
- case 32:
- blue = *bufptr++;
- green = *bufptr++;
- red = *bufptr++;
- alpha = *bufptr++;
- for (i = 0; (i < count) && (dataptr < final_pixel); i++)
- {
- WRITE_RGBA(dataptr, red, green, blue, alpha);
- dataptr++;
- }
- break;
-
- case 24:
- blue = *bufptr++;
- green = *bufptr++;
- red = *bufptr++;
- for (i = 0; (i < count) && (dataptr < final_pixel); i++)
- {
- WRITE_RGBA(dataptr, red, green, blue,
- (char)0xff);
- dataptr++;
- }
- break;
-
- case 8:
- alpha = *bufptr++;
- for (i = 0; (i < count) && (dataptr < final_pixel); i++)
- {
- WRITE_RGBA(dataptr, alpha, alpha, alpha,
- (char)0xff);
- dataptr++;
- }
- break;
+ case 32:
+ blue = *bufptr++;
+ green = *bufptr++;
+ red = *bufptr++;
+ alpha = *bufptr++;
+ for (i = 0; (i < count) && (dataptr < final_pixel);
+ i++)
+ {
+ WRITE_RGBA(dataptr, red, green, blue, alpha);
+ dataptr++;
+ }
+ break;
+
+ case 24:
+ blue = *bufptr++;
+ green = *bufptr++;
+ red = *bufptr++;
+ for (i = 0; (i < count) && (dataptr < final_pixel);
+ i++)
+ {
+ WRITE_RGBA(dataptr, red, green, blue,
+ (char)0xff);
+ dataptr++;
+ }
+ break;
+
+ case 8:
+ alpha = *bufptr++;
+ for (i = 0; (i < count) && (dataptr < final_pixel);
+ i++)
+ {
+ WRITE_RGBA(dataptr, alpha, alpha, alpha,
+ (char)0xff);
+ dataptr++;
+ }
+ break;
}
} /* end if (RLE packet) */
@@ -465,47 +462,48 @@ load(ImlibImage * im, ImlibProgressFunction progress,
switch (bpp)
{
- /* 32-bit BGRA pixels */
- case 32:
- WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
- *(bufptr + 1), /* G */
- *(bufptr + 0), /* B */
- *(bufptr + 3) /* A */
- );
- dataptr++;
- bufptr += 4;
- break;
-
- /* 24-bit BGR pixels */
- case 24:
- WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
- *(bufptr + 1), /* G */
- *(bufptr + 0), /* B */
- (char)0xff /* A */
- );
- dataptr++;
- bufptr += 3;
- break;
-
- /* 8-bit grayscale */
- case 8:
- WRITE_RGBA(dataptr, *bufptr, /* pseudo-grayscale */
- *bufptr, *bufptr, (char)0xff);
- dataptr++;
- bufptr += 1;
- break;
+ /* 32-bit BGRA pixels */
+ case 32:
+ WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
+ *(bufptr + 1), /* G */
+ *(bufptr + 0), /* B */
+ *(bufptr + 3) /* A */
+ );
+ dataptr++;
+ bufptr += 4;
+ break;
+
+ /* 24-bit BGR pixels */
+ case 24:
+ WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
+ *(bufptr + 1), /* G */
+ *(bufptr + 0), /* B */
+ (char)0xff /* A */
+ );
+ dataptr++;
+ bufptr += 3;
+ break;
+
+ /* 8-bit grayscale */
+ case 8:
+ WRITE_RGBA(dataptr, *bufptr, /* pseudo-grayscale */
+ *bufptr, *bufptr, (char)0xff);
+ dataptr++;
+ bufptr += 1;
+ break;
}
}
} /* end if (raw packet) */
} /* end for (each packet) */
/* must now flip a bottom-up image */
- if (vinverted) tgaflip(im->data, im->w, im->h);
- if (progress)
- {
- progress(im, 100, 0, 0, im->w, im->h);
- } /* end for (each row) */
+ if (vinverted)
+ tgaflip(im->data, im->w, im->h);
+ if (progress)
+ {
+ progress(im, 100, 0, 0, im->w, im->h);
+ } /* end for (each row) */
}
- /* end if (image is RLE) */
+ /* end if (image is RLE) */
}
/* end if (loading pixel data) */
@@ -534,23 +532,24 @@ formats(ImlibLoader * l)
/* flip a DATA32 image block vertically in place */
static void
-tgaflip (DATA32 * in, int w, int h)
+tgaflip(DATA32 * in, int w, int h)
{
- DATA32 *adv, *adv2;
- int x, y;
+ DATA32 *adv, *adv2;
+ int x, y;
adv = in;
adv2 = in + (w * (h - 1));
for (y = 0; y < (h / 2); y++)
{
- DATA32 tmp;
- for (x = 0; x < w; x++)
- {
- tmp = adv[x];
- adv[x] = adv2[x];
- adv2[x] = tmp;
- }
+ DATA32 tmp;
+
+ for (x = 0; x < w; x++)
+ {
+ tmp = adv[x];
+ adv[x] = adv2[x];
+ adv2[x] = tmp;
+ }
adv2 -= w;
adv += w;
}
diff --git a/src/modules/loaders/loader_zlib.c b/src/modules/loaders/loader_zlib.c
index c313d1d..401ea0a 100644
--- a/src/modules/loaders/loader_zlib.c
+++ b/src/modules/loaders/loader_zlib.c
@@ -7,113 +7,125 @@
#define OUTBUF_SIZE 16484
-static int uncompress_file (int src, int dest)
+static int
+uncompress_file(int src, int dest)
{
- gzFile gf;
- DATA8 outbuf[OUTBUF_SIZE];
- int ret = 1, bytes;
-
- gf = gzdopen (dup (src), "rb");
- if (!gf)
- return 0;
-
- while (1) {
- bytes = gzread (gf, outbuf, OUTBUF_SIZE);
-
- if (!bytes)
- break;
- else if (bytes == -1) {
- ret = 0;
- break;
- } else
- write (dest, outbuf, bytes);
- }
-
- gzclose (gf);
-
- return ret;
+ gzFile gf;
+ DATA8 outbuf[OUTBUF_SIZE];
+ int ret = 1, bytes;
+
+ gf = gzdopen(dup(src), "rb");
+ if (!gf)
+ return 0;
+
+ while (1)
+ {
+ bytes = gzread(gf, outbuf, OUTBUF_SIZE);
+
+ if (!bytes)
+ break;
+ else if (bytes == -1)
+ {
+ ret = 0;
+ break;
+ }
+ else
+ write(dest, outbuf, bytes);
+ }
+
+ gzclose(gf);
+
+ return ret;
}
-char load (ImlibImage *im, ImlibProgressFunction progress,
- char progress_granularity, char immediate_load)
+char
+load(ImlibImage * im, ImlibProgressFunction progress,
+ char progress_granularity, char immediate_load)
{
- ImlibLoader *loader;
- int src, dest, res;
- char *file, *p, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX";
- char real_ext[16];
- struct stat st;
-
- assert (im);
-
- /* check that this file ends in *.gz and that there's another ext
- * (e.g. "foo.png.gz"
- */
- p = strrchr(im->real_file, '.');
- if (p && p != im->real_file) {
- if (strcasecmp(p + 1, "gz"))
- return 0;
- } else
- return 0;
-
- strncpy (real_ext, p - sizeof (real_ext) + 1, sizeof (real_ext));
- real_ext[sizeof (real_ext) - 1] = '\0';
-
- /* abort if there's no dot in the "real" filename */
- if (!strrchr (real_ext, '.'))
- return 0;
-
- if (stat (im->real_file, &st) < 0)
- return 0;
-
- if ((src = open (im->real_file, O_RDONLY)) < 0) {
- return 0;
- }
-
- if ((dest = mkstemp (tmp)) < 0) {
- close (src);
- return 0;
- }
-
- res = uncompress_file (src, dest);
- close (src);
- close (dest);
-
- if (!res) {
- unlink (tmp);
- return 0;
- }
-
- if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
- unlink (tmp);
- return 0;
- }
-
- /* remember the original filename */
- file = strdup (im->real_file);
-
- free (im->real_file);
- im->real_file = strdup (tmp);
- loader->load (im, progress, progress_granularity, immediate_load);
-
- free (im->real_file);
- im->real_file = file;
- unlink (tmp);
-
- return 1;
+ ImlibLoader *loader;
+ int src, dest, res;
+ char *file, *p, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX";
+ char real_ext[16];
+ struct stat st;
+
+ assert(im);
+
+ /* check that this file ends in *.gz and that there's another ext
+ * (e.g. "foo.png.gz"
+ */
+ p = strrchr(im->real_file, '.');
+ if (p && p != im->real_file)
+ {
+ if (strcasecmp(p + 1, "gz"))
+ return 0;
+ }
+ else
+ return 0;
+
+ strncpy(real_ext, p - sizeof(real_ext) + 1, sizeof(real_ext));
+ real_ext[sizeof(real_ext) - 1] = '\0';
+
+ /* abort if there's no dot in the "real" filename */
+ if (!strrchr(real_ext, '.'))
+ return 0;
+
+ if (stat(im->real_file, &st) < 0)
+ return 0;
+
+ if ((src = open(im->real_file, O_RDONLY)) < 0)
+ {
+ return 0;
+ }
+
+ if ((dest = mkstemp(tmp)) < 0)
+ {
+ close(src);
+ return 0;
+ }
+
+ res = uncompress_file(src, dest);
+ close(src);
+ close(dest);
+
+ if (!res)
+ {
+ unlink(tmp);
+ return 0;
+ }
+
+ if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
+ {
+ unlink(tmp);
+ return 0;
+ }
+
+ /* remember the original filename */
+ file = strdup(im->real_file);
+
+ free(im->real_file);
+ im->real_file = strdup(tmp);
+ loader->load(im, progress, progress_granularity, immediate_load);
+
+ free(im->real_file);
+ im->real_file = file;
+ unlink(tmp);
+
+ return 1;
}
-void formats (ImlibLoader *l)
+void
+formats(ImlibLoader * l)
{
- /* this is the only bit you have to change... */
- char *list_formats[] = {"gz"};
- int i;
+ /* this is the only bit you have to change... */
+ char *list_formats[] = { "gz" };
+ int i;
/* don't bother changing any of this - it just reads this in
- * and sets the struct values and makes copies
- */
- l->num_formats = sizeof (list_formats) / sizeof (char *);
- l->formats = malloc (sizeof (char *) * l->num_formats);
+ * and sets the struct values and makes copies
+ */
+ 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]);
+ for (i = 0; i < l->num_formats; i++)
+ l->formats[i] = strdup(list_formats[i]);
}