mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 21:04:18 +01:00
changed indentation to use spaces only
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/* directjpeg.c- loads a jpeg file directly into a XImage
|
||||
*
|
||||
* WindowMaker window manager
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1999-2003 Alfredo K. Kojima
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
|
||||
|
||||
struct my_error_mgr {
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
|
||||
jmp_buf setjmp_buffer; /* for return to caller */
|
||||
jmp_buf setjmp_buffer; /* for return to caller */
|
||||
};
|
||||
|
||||
typedef struct my_error_mgr * my_error_ptr;
|
||||
@@ -53,15 +53,15 @@ typedef struct my_error_mgr * my_error_ptr;
|
||||
static void
|
||||
my_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
||||
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
||||
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
||||
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
||||
|
||||
/* Always display the message. */
|
||||
/* We could postpone this until after returning, if we chose. */
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
/* Always display the message. */
|
||||
/* We could postpone this until after returning, if we chose. */
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
|
||||
/* Return control to the setjmp point */
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
/* Return control to the setjmp point */
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ static Bool
|
||||
canLoad(RContext *rc)
|
||||
{
|
||||
if (rc->depth != 16 || rc->vclass != TrueColor
|
||||
|| rc->red_offset!=11 || rc->green_offset!=5 || rc->blue_offset!=0)
|
||||
return False;
|
||||
|| rc->red_offset!=11 || rc->green_offset!=5 || rc->blue_offset!=0)
|
||||
return False;
|
||||
|
||||
return True;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ canLoad(RContext *rc)
|
||||
|
||||
static void
|
||||
readData(RContext *rc, struct jpeg_decompress_struct *cinfo,
|
||||
JSAMPROW *buffer, RXImage *ximg)
|
||||
JSAMPROW *buffer, RXImage *ximg)
|
||||
{
|
||||
int i, j;
|
||||
unsigned long pixel;
|
||||
@@ -89,31 +89,31 @@ readData(RContext *rc, struct jpeg_decompress_struct *cinfo,
|
||||
|
||||
jpeg_read_scanlines(cinfo, buffer, (JDIMENSION)1);
|
||||
|
||||
if (cinfo->out_color_space==JCS_RGB) {
|
||||
for (i=0,j=0; i<cinfo->image_width; i++) {
|
||||
if (cinfo->out_color_space==JCS_RGB) {
|
||||
for (i=0,j=0; i<cinfo->image_width; i++) {
|
||||
|
||||
printf("%i %i %i\n",
|
||||
(((unsigned long)buffer[0][j])&0xf8)<<8,
|
||||
(((unsigned long)buffer[0][j+1])&0xf4)<<3,
|
||||
(((unsigned long)buffer[0][j+2]))>>3);
|
||||
|
||||
pixel = (((unsigned long)buffer[0][j++])&0xf8)<<8
|
||||
|(((unsigned long)buffer[0][j++])&0xf4)<<3
|
||||
|(((unsigned long)buffer[0][j++]))>>3;
|
||||
printf("%i %i %i\n",
|
||||
(((unsigned long)buffer[0][j])&0xf8)<<8,
|
||||
(((unsigned long)buffer[0][j+1])&0xf4)<<3,
|
||||
(((unsigned long)buffer[0][j+2]))>>3);
|
||||
|
||||
XPutPixel(ximg->image, i, y, pixel);
|
||||
}
|
||||
} else {
|
||||
for (i=0,j=0; i<cinfo->image_width; i++, j++) {
|
||||
pixel = (((unsigned long)buffer[0][j++])&0xf8)<<8
|
||||
|(((unsigned long)buffer[0][j++])&0xf4)<<3
|
||||
|(((unsigned long)buffer[0][j++]))>>3;
|
||||
|
||||
pixel = (unsigned long)buffer[0][j]<<8
|
||||
|(unsigned long)buffer[0][j]<<3
|
||||
|(unsigned long)buffer[0][j]>>3;
|
||||
XPutPixel(ximg->image, i, y, pixel);
|
||||
}
|
||||
} else {
|
||||
for (i=0,j=0; i<cinfo->image_width; i++, j++) {
|
||||
|
||||
XPutPixel(ximg->image, i, y, pixel);
|
||||
}
|
||||
}
|
||||
y++;
|
||||
pixel = (unsigned long)buffer[0][j]<<8
|
||||
|(unsigned long)buffer[0][j]<<3
|
||||
|(unsigned long)buffer[0][j]>>3;
|
||||
|
||||
XPutPixel(ximg->image, i, y, pixel);
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,19 +131,19 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
|
||||
Pixmap p = None;
|
||||
|
||||
if (!canLoad(rc))
|
||||
return None;
|
||||
return None;
|
||||
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
return None;
|
||||
return None;
|
||||
}
|
||||
if (fread(buf, 2, 1, file) != 1) {
|
||||
fclose(file);
|
||||
return None;
|
||||
fclose(file);
|
||||
return None;
|
||||
}
|
||||
if (buf[0] != 0xff || buf[1] != 0xd8) {
|
||||
fclose(file);
|
||||
return None;
|
||||
fclose(file);
|
||||
return None;
|
||||
}
|
||||
rewind(file);
|
||||
|
||||
@@ -151,33 +151,33 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
/* Establish the setjmp return context for my_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer)) {
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
|
||||
if (ximg) {
|
||||
RDestroyXImage(rc, ximg);
|
||||
}
|
||||
|
||||
return None;
|
||||
if (ximg) {
|
||||
RDestroyXImage(rc, ximg);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
jpeg_stdio_src(&cinfo, file);
|
||||
|
||||
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
buffer[0] = (JSAMPROW)malloc(cinfo.image_width*cinfo.num_components);
|
||||
if (!buffer[0]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
}
|
||||
|
||||
if(cinfo.jpeg_color_space==JCS_GRAYSCALE) {
|
||||
cinfo.out_color_space=JCS_GRAYSCALE;
|
||||
cinfo.out_color_space=JCS_GRAYSCALE;
|
||||
} else
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
cinfo.quantize_colors = FALSE;
|
||||
@@ -187,7 +187,7 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
|
||||
|
||||
ximg = RCreateXImage(rc, rc->depth, cinfo.image_width, cinfo.image_height);
|
||||
if (!ximg) {
|
||||
goto bye;
|
||||
goto bye;
|
||||
}
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
@@ -195,26 +195,26 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
|
||||
p = XCreatePixmap(rc->dpy, rc->drawable, cinfo.image_width,
|
||||
cinfo.image_height, rc->depth);
|
||||
p = XCreatePixmap(rc->dpy, rc->drawable, cinfo.image_width,
|
||||
cinfo.image_height, rc->depth);
|
||||
|
||||
RPutXImage(rc, p, rc->copy_gc, ximg, 0, 0, 0, 0, cinfo.image_width,
|
||||
cinfo.image_height);
|
||||
cinfo.image_height);
|
||||
|
||||
*width = cinfo.image_width;
|
||||
*height = cinfo.image_height;
|
||||
|
||||
bye:
|
||||
|
||||
bye:
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (buffer[0])
|
||||
free(buffer[0]);
|
||||
free(buffer[0]);
|
||||
|
||||
if (ximg)
|
||||
RDestroyXImage(rc, ximg);
|
||||
|
||||
RDestroyXImage(rc, ximg);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user