Indent (most) .c files.

SVN revision: 58518
This commit is contained in:
Kim Woelders 2011-04-09 09:24:44 +00:00
parent 4c55d2c3f6
commit 41c3a967d0
30 changed files with 2420 additions and 2163 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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",

View File

@ -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;
}
}

View File

@ -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);
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);
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,

View File

@ -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();

View File

@ -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>

View File

@ -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

View File

@ -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
};

View File

@ -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);
}

View File

@ -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"

View File

@ -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},

View File

@ -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++;

View File

@ -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;
}
}

View File

@ -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

View File

@ -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];
}

View File

@ -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)

View File

@ -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)

View File

@ -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++)

View File

@ -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)

View File

@ -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;
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;
}
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;
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;
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++);
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;
*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;

View File

@ -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];
ImlibLoader *loader;
FILE *fp;
int dest, res;
char *file, tmp[] = "/tmp/imlib2_loader_bz2-XXXXXX", *p;
char real_ext[16];
assert (im);
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;
/* 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';
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;
/* 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 (!(fp = fopen(im->real_file, "rb")))
{
return 0;
}
if ((dest = mkstemp (tmp)) < 0) {
fclose (fp);
return 0;
}
if ((dest = mkstemp(tmp)) < 0)
{
fclose(fp);
return 0;
}
res = uncompress_file (fp, dest);
fclose (fp);
close (dest);
res = uncompress_file(fp, dest);
fclose(fp);
close(dest);
if (!res) {
unlink (tmp);
return 0;
}
if (!res)
{
unlink(tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
unlink (tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
{
unlink(tmp);
return 0;
}
/* remember the original filename */
file = strdup (im->real_file);
/* 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 = strdup(tmp);
loader->load(im, progress, progress_granularity, immediate_load);
free (im->real_file);
im->real_file = file;
unlink (tmp);
free(im->real_file);
im->real_file = file;
unlink(tmp);
return 1;
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]);
}

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -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++;
}

View File

@ -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;
CHUNK bmhd;
CHUNK camg;
CHUNK cmap;
CHUNK ctbl;
CHUNK sham;
CHUNK body;
int depth;
int mask;
int ham;
int hbrite;
int depth;
int mask;
int ham;
int hbrite;
int row;
int row;
int offset;
int count;
int rle;
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);
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));
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];
CHUNK *c;
FILE *f;
size_t s;
long formsize, pos, z;
int ok, seek;
char buf[12];
ok = 0;
ok = 0;
f = fopen(name, "rb");
if (f) {
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);
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;
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. */
s = fread(buf, 1, 8, f);
if (s != 8)
break; /* Error or short file. */
z = L2RLONG(buf + 4);
if (z < 0) break; /* Corrupt 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;
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 (pos + 8 + z >= formsize + 8) break; /* This was last chunk. */
if (c && !c->data)
{
c->size = z;
c->data = malloc(c->size);
if (!c->data)
break; /* Out of memory. */
if (seek && fseek(f, z, SEEK_CUR) != 0) break;
}
s = fread(c->data, 1, c->size, f);
if (s != c->size)
break; /* Error or short file. */
/* 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);
}
seek = 0;
if (!full)
{ /* Only BMHD required. */
ok = 1;
break;
}
}
if (pos + 8 + z >= formsize + 8)
break; /* This was last chunk. */
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);
}
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;
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);
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;
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;
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;
if (ilbm->ham)
r = g = b = 0;
bit = 0x80;
o = 0;
for (x = 0; x < w; x++) {
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;
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 (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];
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 = 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);
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 (!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 (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;
}
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;
}
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;
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;
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;
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);
for (y = 0; y < im->h; y++)
{
bodyrow(plane[0], z, &ilbm);
deplane(im->data + im->w * y, im->w, &ilbm, plane);
ilbm.row++;
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);
}
}
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]);
}

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -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_RLE:
case TGA_TYPE_GRAY_RLE:
rle = 1;
break;
case TGA_TYPE_COLOR:
case TGA_TYPE_GRAY:
rle = 0;
break;
case TGA_TYPE_COLOR:
case TGA_TYPE_GRAY:
rle = 0;
break;
default:
munmap(seg, ss.st_size);
close(fd);
return 0;
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;
/* 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;
/* 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;
/* 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 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 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 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;
/* 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;
/* 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;
/* 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;
}

View File

@ -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;
gzFile gf;
DATA8 outbuf[OUTBUF_SIZE];
int ret = 1, bytes;
gf = gzdopen (dup (src), "rb");
if (!gf)
return 0;
gf = gzdopen(dup(src), "rb");
if (!gf)
return 0;
while (1) {
bytes = gzread (gf, outbuf, OUTBUF_SIZE);
while (1)
{
bytes = gzread(gf, outbuf, OUTBUF_SIZE);
if (!bytes)
break;
else if (bytes == -1) {
ret = 0;
break;
} else
write (dest, outbuf, bytes);
}
if (!bytes)
break;
else if (bytes == -1)
{
ret = 0;
break;
}
else
write(dest, outbuf, bytes);
}
gzclose (gf);
gzclose(gf);
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;
int src, dest, res;
char *file, *p, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX";
char real_ext[16];
struct stat st;
ImlibLoader *loader;
int src, dest, res;
char *file, *p, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX";
char real_ext[16];
struct stat st;
assert (im);
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;
/* 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';
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;
/* 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 (stat(im->real_file, &st) < 0)
return 0;
if ((src = open (im->real_file, O_RDONLY)) < 0) {
return 0;
}
if ((src = open(im->real_file, O_RDONLY)) < 0)
{
return 0;
}
if ((dest = mkstemp (tmp)) < 0) {
close (src);
return 0;
}
if ((dest = mkstemp(tmp)) < 0)
{
close(src);
return 0;
}
res = uncompress_file (src, dest);
close (src);
close (dest);
res = uncompress_file(src, dest);
close(src);
close(dest);
if (!res) {
unlink (tmp);
return 0;
}
if (!res)
{
unlink(tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
unlink (tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
{
unlink(tmp);
return 0;
}
/* remember the original filename */
file = strdup (im->real_file);
/* 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 = strdup(tmp);
loader->load(im, progress, progress_granularity, immediate_load);
free (im->real_file);
im->real_file = file;
unlink (tmp);
free(im->real_file);
im->real_file = file;
unlink(tmp);
return 1;
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]);
}