80 void (*store_data)(
int w,
int x,
int y,
int r,
int g,
int b);
81 struct jpeg_decompress_struct cinfo;
101 if((infile = fopen(fullname,
"rb")) == NULL) {
103 fprintf(stderr,
"unable to locate %s\n", fullname);
111 cinfo.err = jpeg_std_error(&jerr.
pub);
115 jpeg_destroy_decompress(&cinfo);
120 jpeg_create_decompress(&cinfo);
121 jpeg_stdio_src(&cinfo, infile);
122 jpeg_read_header(&cinfo, FALSE);
123 cinfo.do_fancy_upsampling = FALSE;
124 cinfo.do_block_smoothing = FALSE;
125 jpeg_start_decompress(&cinfo);
126 width = cinfo.output_width;
127 height = cinfo.output_height;
129 if(
Scr->d_depth == 16) {
132 ximage = XCreateImage(
dpy, CopyFromParent,
Scr->d_depth, ZPixmap, 0,
135 else if(
Scr->d_depth == 24 ||
Scr->d_depth == 32) {
138 ximage = XCreateImage(
dpy, CopyFromParent,
Scr->d_depth, ZPixmap, 0,
142 fprintf(stderr,
"Image %s unsupported depth : %d\n", name,
Scr->d_depth);
148 fprintf(stderr,
"cannot create image for %s\n", name);
154 row_stride = cinfo.output_width * cinfo.output_components;
155 buffer = (*cinfo.mem->alloc_sarray)
156 ((j_common_ptr) & cinfo, JPOOL_IMAGE, row_stride, 1);
158 bpix = cinfo.output_components;
159 while(cinfo.output_scanline < cinfo.output_height) {
160 jpeg_read_scanlines(&cinfo, buffer, 1);
162 for(i = 0; i < bpix * cinfo.output_width; i += bpix) {
163 (*store_data)(width, a, g, buffer[0][i], buffer[0][i + 1], buffer[0][i + 2]);
168 jpeg_finish_decompress(&cinfo);
169 jpeg_destroy_decompress(&cinfo);
172 gc = DefaultGC(
dpy,
Scr->screen);
173 if((width > (
Scr->rootw / 2)) || (height > (
Scr->rooth / 2))) {
176 pixret = XCreatePixmap(
dpy,
Scr->Root,
Scr->rootw,
Scr->rooth,
Scr->d_depth);
177 x = (
Scr->rootw - width) / 2;
178 y = (
Scr->rooth - height) / 2;
179 XFillRectangle(
dpy, pixret, gc, 0, 0,
Scr->rootw,
Scr->rooth);
180 XPutImage(
dpy, pixret, gc, ximage, 0, 0,
x,
y, width, height);
185 pixret = XCreatePixmap(
dpy,
Scr->Root, width, height,
Scr->d_depth);
186 XPutImage(
dpy, pixret, gc, ximage, 0, 0, 0, 0, width, height);
187 image->
width = width;
191 XDestroyImage(ximage);