1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-21 21:38:00 +01:00

Change to the linux kernel coding style

for arq in `git ls-files *.c`; do
    echo $arq;
    indent -linux -l115 $arq;
    done

The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
Carlos R. Mafra
2009-08-20 00:59:40 +02:00
parent 59fc927dc9
commit 688a56e8ab
209 changed files with 87034 additions and 98138 deletions

View File

@@ -31,14 +31,13 @@
# ifdef _AIX
# pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca();
# endif
# endif
# endif
#endif
#ifdef USE_PNG
#include <stdlib.h>
@@ -49,193 +48,184 @@ char *alloca ();
#include "wraster.h"
RImage*
RLoadPNG(RContext *context, char *file, int index)
RImage *RLoadPNG(RContext * context, char *file, int index)
{
char *tmp;
RImage *image=NULL;
FILE *f;
png_structp png;
png_infop pinfo, einfo;
png_color_16p bkcolor;
int alpha;
int x, y, i;
double gamma, sgamma;
png_uint_32 width, height;
int depth, junk, color_type;
png_bytep *png_rows;
unsigned char *ptr;
char *tmp;
RImage *image = NULL;
FILE *f;
png_structp png;
png_infop pinfo, einfo;
png_color_16p bkcolor;
int alpha;
int x, y, i;
double gamma, sgamma;
png_uint_32 width, height;
int depth, junk, color_type;
png_bytep *png_rows;
unsigned char *ptr;
f = fopen(file, "rb");
if (!f) {
RErrorCode = RERR_OPEN;
return NULL;
}
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
if (!png) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
return NULL;
}
f = fopen(file, "rb");
if (!f) {
RErrorCode = RERR_OPEN;
return NULL;
}
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, (png_error_ptr) NULL, (png_error_ptr) NULL);
if (!png) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
return NULL;
}
pinfo = png_create_info_struct(png);
if (!pinfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, NULL, NULL);
return NULL;
}
pinfo = png_create_info_struct(png);
if (!pinfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, NULL, NULL);
return NULL;
}
einfo = png_create_info_struct(png);
if (!einfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, &pinfo, NULL);
return NULL;
}
einfo = png_create_info_struct(png);
if (!einfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, &pinfo, NULL);
return NULL;
}
RErrorCode = RERR_INTERNAL;
if (setjmp(png->jmpbuf)) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
if (image)
RReleaseImage(image);
return NULL;
}
RErrorCode = RERR_INTERNAL;
if (setjmp(png->jmpbuf)) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
if (image)
RReleaseImage(image);
return NULL;
}
png_init_io(png, f);
png_init_io(png, f);
png_read_info(png, pinfo);
png_read_info(png, pinfo);
png_get_IHDR(png, pinfo, &width, &height, &depth, &color_type,
&junk, &junk, &junk);
png_get_IHDR(png, pinfo, &width, &height, &depth, &color_type, &junk, &junk, &junk);
/* sanity check */
if (width < 1 || height < 1) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
/* sanity check */
if (width < 1 || height < 1) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
/* check for an alpha channel */
if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
alpha = True;
else
alpha = (color_type & PNG_COLOR_MASK_ALPHA);
/* allocate RImage */
image = RCreateImage(width, height, alpha);
if (!image) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
return NULL;
}
/* check for an alpha channel */
if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
alpha = True;
else
alpha = (color_type & PNG_COLOR_MASK_ALPHA);
/* normalize to 8bpp with alpha channel */
if (color_type == PNG_COLOR_TYPE_PALETTE && depth <= 8)
png_set_expand(png);
/* allocate RImage */
image = RCreateImage(width, height, alpha);
if (!image) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
return NULL;
}
if (color_type == PNG_COLOR_TYPE_GRAY && depth <= 8)
png_set_expand(png);
/* normalize to 8bpp with alpha channel */
if (color_type == PNG_COLOR_TYPE_PALETTE && depth <= 8)
png_set_expand(png);
if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
png_set_expand(png);
if (color_type == PNG_COLOR_TYPE_GRAY && depth <= 8)
png_set_expand(png);
if (depth == 16)
png_set_strip_16(png);
if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
png_set_expand(png);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
if (depth == 16)
png_set_strip_16(png);
/* set gamma correction */
if ((context->attribs->flags & RC_GammaCorrection)
&& context->depth != 8) {
sgamma = (context->attribs->rgamma + context->attribs->ggamma + context->attribs->bgamma) / 3;
} else if ((tmp = getenv("DISPLAY_GAMMA")) != NULL) {
sgamma = atof(tmp);
if (sgamma == 0)
sgamma = 1;
} else {
/* blah */
sgamma = 2.2;
}
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
if (png_get_gAMA(png, pinfo, &gamma))
png_set_gamma(png, sgamma, gamma);
else
png_set_gamma(png, sgamma, 0.45);
/* set gamma correction */
if ((context->attribs->flags & RC_GammaCorrection)
&& context->depth != 8) {
sgamma = (context->attribs->rgamma + context->attribs->ggamma +
context->attribs->bgamma) / 3;
} else if ((tmp = getenv("DISPLAY_GAMMA")) != NULL) {
sgamma = atof(tmp);
if (sgamma==0)
sgamma = 1;
} else {
/* blah */
sgamma = 2.2;
}
/* do the transforms */
png_read_update_info(png, pinfo);
if (png_get_gAMA(png, pinfo, &gamma))
png_set_gamma(png, sgamma, gamma);
else
png_set_gamma(png, sgamma, 0.45);
/* set background color */
if (png_get_bKGD(png, pinfo, &bkcolor)) {
image->background.red = bkcolor->red >> 8;
image->background.green = bkcolor->green >> 8;
image->background.blue = bkcolor->blue >> 8;
}
/* do the transforms */
png_read_update_info(png, pinfo);
/* set background color */
if (png_get_bKGD(png, pinfo, &bkcolor)) {
image->background.red = bkcolor->red >> 8;
image->background.green = bkcolor->green >> 8;
image->background.blue = bkcolor->blue >> 8;
}
png_rows = alloca(sizeof(char*)*height);
if (!png_rows) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
png_rows = alloca(sizeof(char *) * height);
if (!png_rows) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
#ifdef C_ALLOCA
alloca(0);
alloca(0);
#endif
return NULL;
}
for (y=0; y<height; y++) {
png_rows[y] = alloca(png_get_rowbytes(png, pinfo));
if (!png_rows[y]) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
return NULL;
}
for (y = 0; y < height; y++) {
png_rows[y] = alloca(png_get_rowbytes(png, pinfo));
if (!png_rows[y]) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
#ifdef C_ALLOCA
alloca(0);
alloca(0);
#endif
return NULL;
}
}
/* read data */
png_read_image(png, png_rows);
return NULL;
}
}
/* read data */
png_read_image(png, png_rows);
png_read_end(png, einfo);
png_read_end(png, einfo);
png_destroy_read_struct(&png, &pinfo, &einfo);
png_destroy_read_struct(&png, &pinfo, &einfo);
fclose(f);
fclose(f);
ptr = image->data;
ptr = image->data;
/* convert to RImage */
if (alpha) {
for (y=0; y<height; y++) {
for (x=0, i=width*4; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
} else {
for (y=0; y<height; y++) {
for (x=0, i=width*3; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
}
/* convert to RImage */
if (alpha) {
for (y = 0; y < height; y++) {
for (x = 0, i = width * 4; x < i; x++, ptr++) {
*ptr = *(png_rows[y] + x);
}
}
} else {
for (y = 0; y < height; y++) {
for (x = 0, i = width * 3; x < i; x++, ptr++) {
*ptr = *(png_rows[y] + x);
}
}
}
#ifdef C_ALLOCA
alloca(0);
alloca(0);
#endif
return image;
return image;
}
#endif /* USE_PNG */
#endif /* USE_PNG */