mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +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:
224
wrlib/jpeg.c
224
wrlib/jpeg.c
@@ -21,12 +21,9 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
/* Avoid a compiler warning */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
|
||||
|
||||
#ifdef USE_JPEG
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -68,149 +65,144 @@
|
||||
*/
|
||||
|
||||
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;
|
||||
typedef struct my_error_mgr *my_error_ptr;
|
||||
|
||||
/*
|
||||
* Here's the routine that will replace the standard error_exit method:
|
||||
*/
|
||||
|
||||
static void
|
||||
my_error_exit(j_common_ptr cinfo)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
RImage*
|
||||
RLoadJPEG(RContext *context, char *file_name, int index)
|
||||
RImage *RLoadJPEG(RContext * context, char *file_name, int index)
|
||||
{
|
||||
RImage *image = NULL;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
int i;
|
||||
unsigned char *ptr;
|
||||
JSAMPROW buffer[1], bptr;
|
||||
FILE *file;
|
||||
/* We use our private extension JPEG error handler.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct my_error_mgr jerr;
|
||||
RImage *image = NULL;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
int i;
|
||||
unsigned char *ptr;
|
||||
JSAMPROW buffer[1], bptr;
|
||||
FILE *file;
|
||||
/* We use our private extension JPEG error handler.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct my_error_mgr jerr;
|
||||
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
return NULL;
|
||||
}
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
jpeg_stdio_src(&cinfo, file);
|
||||
jpeg_stdio_src(&cinfo, file);
|
||||
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
if (cinfo.image_width < 1 || cinfo.image_height < 1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
goto bye;
|
||||
}
|
||||
if (cinfo.image_width < 1 || cinfo.image_height < 1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
goto bye;
|
||||
}
|
||||
|
||||
bptr = buffer[0] = (JSAMPROW)malloc(cinfo.image_width*cinfo.num_components);
|
||||
if (!buffer[0]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
}
|
||||
bptr = buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components);
|
||||
if (!buffer[0]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
}
|
||||
|
||||
if(cinfo.jpeg_color_space==JCS_GRAYSCALE) {
|
||||
cinfo.out_color_space=JCS_GRAYSCALE;
|
||||
} else
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
cinfo.quantize_colors = FALSE;
|
||||
cinfo.do_fancy_upsampling = FALSE;
|
||||
cinfo.do_block_smoothing = FALSE;
|
||||
jpeg_calc_output_dimensions(&cinfo);
|
||||
if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
|
||||
cinfo.out_color_space = JCS_GRAYSCALE;
|
||||
} else
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
cinfo.quantize_colors = FALSE;
|
||||
cinfo.do_fancy_upsampling = FALSE;
|
||||
cinfo.do_block_smoothing = FALSE;
|
||||
jpeg_calc_output_dimensions(&cinfo);
|
||||
|
||||
if (context->flags.optimize_for_speed)
|
||||
image = RCreateImage(cinfo.image_width, cinfo.image_height, True);
|
||||
else
|
||||
image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
|
||||
if (context->flags.optimize_for_speed)
|
||||
image = RCreateImage(cinfo.image_width, cinfo.image_height, True);
|
||||
else
|
||||
image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
|
||||
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
}
|
||||
jpeg_start_decompress(&cinfo);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
goto bye;
|
||||
}
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
ptr = image->data;
|
||||
ptr = image->data;
|
||||
|
||||
if (cinfo.out_color_space == JCS_RGB) {
|
||||
if (context->flags.optimize_for_speed) {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer, (JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
for (i = 0; i < cinfo.image_width; i++) {
|
||||
*ptr++ = *bptr++;
|
||||
*ptr++ = *bptr++;
|
||||
*ptr++ = *bptr++;
|
||||
ptr++; /* skip alpha channel */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer, (JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
memcpy(ptr, bptr, cinfo.image_width * 3);
|
||||
ptr += cinfo.image_width * 3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer, (JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
for (i = 0; i < cinfo.image_width; i++) {
|
||||
*ptr++ = *bptr;
|
||||
*ptr++ = *bptr;
|
||||
*ptr++ = *bptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cinfo.out_color_space==JCS_RGB) {
|
||||
if (context->flags.optimize_for_speed) {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
for (i=0; i<cinfo.image_width; i++) {
|
||||
*ptr++ = *bptr++;
|
||||
*ptr++ = *bptr++;
|
||||
*ptr++ = *bptr++;
|
||||
ptr++; /* skip alpha channel */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
memcpy(ptr, bptr, cinfo.image_width*3);
|
||||
ptr += cinfo.image_width*3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
|
||||
bptr = buffer[0];
|
||||
for (i=0; i<cinfo.image_width; i++) {
|
||||
*ptr++ = *bptr;
|
||||
*ptr++ = *bptr;
|
||||
*ptr++ = *bptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
bye:
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
bye:
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
|
||||
fclose(file);
|
||||
if (buffer[0])
|
||||
free(buffer[0]);
|
||||
|
||||
if (buffer[0])
|
||||
free(buffer[0]);
|
||||
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
#endif /* USE_JPEG */
|
||||
|
||||
#endif /* USE_JPEG */
|
||||
|
||||
Reference in New Issue
Block a user