Improve code formatting consistency
With rare exceptions ...
- Always separate line continuation characters by one space from
preceding code.
- Always use two-space indentation. Never use tabs.
- Always use K&R-style conditional blocks.
- Always surround operators with spaces, except in raw assembly code.
- Always put a space after, but not before, a comma.
- Never put a space between type casts and variables/function calls.
- Never put a space between the function name and the argument list in
function declarations and prototypes.
- Always surround braces ('{' and '}') with spaces.
- Always surround statements (if, for, else, catch, while, do, switch)
with spaces.
- Always attach pointer symbols ('*' and '**') to the variable or
function name.
- Always precede pointer symbols ('*' and '**') by a space in type
casts.
- Use the MIN() macro from jpegint.h within the libjpeg and TurboJPEG
API libraries (using min() from tjutil.h is still necessary for
TJBench.)
- Where it makes sense (particularly in the TurboJPEG code), put a blank
line after variable declaration blocks.
- Always separate statements in one-liners by two spaces.
The purpose of this was to ease maintenance on my part and also to make
it easier for contributors to figure out how to format patch
submissions. This was admittedly confusing (even to me sometimes) when
we had 3 or 4 different style conventions in the same source tree. The
new convention is more consistent with the formatting of other OSS code
bases.
This commit corrects deviations from the chosen formatting style in the
libjpeg API code and reformats the TurboJPEG API code such that it
conforms to the same standard.
NOTES:
- Although it is no longer necessary for the function name in function
declarations to begin in Column 1 (this was historically necessary
because of the ansi2knr utility, which allowed libjpeg to be built
with non-ANSI compilers), we retain that formatting for the libjpeg
code because it improves readability when using libjpeg's function
attribute macros (GLOBAL(), etc.)
- This reformatting project was accomplished with the help of AStyle and
Uncrustify, although neither was completely up to the task, and thus
a great deal of manual tweaking was required. Note to developers of
code formatting utilities: the libjpeg-turbo code base is an
excellent test bed, because AFAICT, it breaks every single one of the
utilities that are currently available.
- The legacy (MMX, SSE, 3DNow!) assembly code for i386 has been
formatted to match the SSE2 code (refer to
ff5685d5344273df321eb63a005eaae19d2496e3.) I hadn't intended to
bother with this, but the Loongson MMI implementation demonstrated
that there is still academic value to the MMX implementation, as an
algorithmic model for other 64-bit vector implementations. Thus, it
is desirable to improve its readability in the same manner as that of
the SSE2 implementation.
This commit is contained in:
103
wrppm.c
103
wrppm.c
@@ -19,8 +19,8 @@
|
||||
* an ordinary stdio stream.
|
||||
*/
|
||||
|
||||
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
#include "cmyk.h"
|
||||
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
|
||||
#ifdef PPM_SUPPORTED
|
||||
|
||||
@@ -36,23 +36,23 @@
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v)
|
||||
#define PUTPPMSAMPLE(ptr, v) *ptr++ = (char)(v)
|
||||
#define BYTESPERSAMPLE 1
|
||||
#define PPM_MAXVAL 255
|
||||
#else
|
||||
#ifdef PPM_NORAWWORD
|
||||
#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8))
|
||||
#define PUTPPMSAMPLE(ptr, v) *ptr++ = (char)((v) >> (BITS_IN_JSAMPLE - 8))
|
||||
#define BYTESPERSAMPLE 1
|
||||
#define PPM_MAXVAL 255
|
||||
#else
|
||||
/* The word-per-sample format always puts the MSB first. */
|
||||
#define PUTPPMSAMPLE(ptr,v) \
|
||||
{ register int val_ = v; \
|
||||
*ptr++ = (char) ((val_ >> 8) & 0xFF); \
|
||||
*ptr++ = (char) (val_ & 0xFF); \
|
||||
}
|
||||
#define PUTPPMSAMPLE(ptr, v) { \
|
||||
register int val_ = v; \
|
||||
*ptr++ = (char)((val_ >> 8) & 0xFF); \
|
||||
*ptr++ = (char)(val_ & 0xFF); \
|
||||
}
|
||||
#define BYTESPERSAMPLE 2
|
||||
#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1)
|
||||
#define PPM_MAXVAL ((1 << BITS_IN_JSAMPLE) - 1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -87,12 +87,12 @@ typedef ppm_dest_struct *ppm_dest_ptr;
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,10 +102,10 @@ put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
copy_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
register char *bufferptr;
|
||||
register JSAMPROW ptr;
|
||||
#if BITS_IN_JSAMPLE != 8 || (!defined(HAVE_UNSIGNED_CHAR) && !defined(__CHAR_UNSIGNED__))
|
||||
@@ -121,7 +121,7 @@ copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++));
|
||||
}
|
||||
#endif
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,10 +130,9 @@ copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
put_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
put_rgb(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
register char *bufferptr;
|
||||
register JSAMPROW ptr;
|
||||
register JDIMENSION col;
|
||||
@@ -150,7 +149,7 @@ put_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
PUTPPMSAMPLE(bufferptr, ptr[bindex]);
|
||||
ptr += ps;
|
||||
}
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,10 +158,10 @@ put_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
put_cmyk (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
put_cmyk(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
register char *bufferptr;
|
||||
register JSAMPROW ptr;
|
||||
register JDIMENSION col;
|
||||
@@ -176,7 +175,7 @@ put_cmyk (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
PUTPPMSAMPLE(bufferptr, g);
|
||||
PUTPPMSAMPLE(bufferptr, b);
|
||||
}
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,10 +185,10 @@ put_cmyk (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
put_demapped_rgb(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
register char *bufferptr;
|
||||
register int pixval;
|
||||
register JSAMPROW ptr;
|
||||
@@ -206,15 +205,15 @@ put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval]));
|
||||
PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval]));
|
||||
}
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
put_demapped_gray(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
JDIMENSION rows_supplied)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
register char *bufferptr;
|
||||
register JSAMPROW ptr;
|
||||
register JSAMPROW color_map = cinfo->colormap[0];
|
||||
@@ -225,7 +224,7 @@ put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
for (col = cinfo->output_width; col > 0; col--) {
|
||||
PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)]));
|
||||
}
|
||||
(void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
(void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,17 +233,16 @@ put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
start_output_ppm(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
|
||||
/* Emit file header */
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_GRAYSCALE:
|
||||
/* emit header for raw PGM format */
|
||||
fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n",
|
||||
(long) cinfo->output_width, (long) cinfo->output_height,
|
||||
PPM_MAXVAL);
|
||||
(long)cinfo->output_width, (long)cinfo->output_height, PPM_MAXVAL);
|
||||
break;
|
||||
case JCS_RGB:
|
||||
case JCS_EXT_RGB:
|
||||
@@ -260,8 +258,7 @@ start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
case JCS_CMYK:
|
||||
/* emit header for raw PPM format */
|
||||
fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n",
|
||||
(long) cinfo->output_width, (long) cinfo->output_height,
|
||||
PPM_MAXVAL);
|
||||
(long)cinfo->output_width, (long)cinfo->output_height, PPM_MAXVAL);
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_PPM_COLORSPACE);
|
||||
@@ -274,7 +271,7 @@ start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
finish_output_ppm(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
{
|
||||
/* Make sure we wrote the output file OK */
|
||||
fflush(dinfo->output_file);
|
||||
@@ -288,9 +285,9 @@ finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
calc_buffer_dimensions_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
calc_buffer_dimensions_ppm(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
{
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
|
||||
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
|
||||
|
||||
if (cinfo->out_color_space == JCS_GRAYSCALE)
|
||||
dest->samples_per_row = cinfo->output_width * cinfo->out_color_components;
|
||||
@@ -305,13 +302,13 @@ calc_buffer_dimensions_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(djpeg_dest_ptr)
|
||||
jinit_write_ppm (j_decompress_ptr cinfo)
|
||||
jinit_write_ppm(j_decompress_ptr cinfo)
|
||||
{
|
||||
ppm_dest_ptr dest;
|
||||
|
||||
/* Create module interface object, fill in method pointers */
|
||||
dest = (ppm_dest_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(ppm_dest_struct));
|
||||
dest->pub.start_output = start_output_ppm;
|
||||
dest->pub.finish_output = finish_output_ppm;
|
||||
@@ -321,9 +318,9 @@ jinit_write_ppm (j_decompress_ptr cinfo)
|
||||
jpeg_calc_output_dimensions(cinfo);
|
||||
|
||||
/* Create physical I/O buffer */
|
||||
dest->pub.calc_buffer_dimensions (cinfo, (djpeg_dest_ptr) dest);
|
||||
dest->iobuffer = (char *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);
|
||||
dest->pub.calc_buffer_dimensions(cinfo, (djpeg_dest_ptr)dest);
|
||||
dest->iobuffer = (char *)(*cinfo->mem->alloc_small)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, dest->buffer_width);
|
||||
|
||||
if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 ||
|
||||
sizeof(JSAMPLE) != sizeof(char) ||
|
||||
@@ -337,14 +334,14 @@ jinit_write_ppm (j_decompress_ptr cinfo)
|
||||
* separate buffer if pixel format translation must take place.
|
||||
*/
|
||||
dest->pub.buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->output_width * cinfo->output_components, (JDIMENSION) 1);
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
cinfo->output_width * cinfo->output_components, (JDIMENSION)1);
|
||||
dest->pub.buffer_height = 1;
|
||||
if (IsExtRGB(cinfo->out_color_space))
|
||||
dest->pub.put_pixel_rows = put_rgb;
|
||||
else if (cinfo->out_color_space == JCS_CMYK)
|
||||
dest->pub.put_pixel_rows = put_cmyk;
|
||||
else if (! cinfo->quantize_colors)
|
||||
else if (!cinfo->quantize_colors)
|
||||
dest->pub.put_pixel_rows = copy_pixel_rows;
|
||||
else if (cinfo->out_color_space == JCS_GRAYSCALE)
|
||||
dest->pub.put_pixel_rows = put_demapped_gray;
|
||||
@@ -353,13 +350,13 @@ jinit_write_ppm (j_decompress_ptr cinfo)
|
||||
} else {
|
||||
/* We will fwrite() directly from decompressor output buffer. */
|
||||
/* Synthesize a JSAMPARRAY pointer structure */
|
||||
dest->pixrow = (JSAMPROW) dest->iobuffer;
|
||||
dest->pub.buffer = & dest->pixrow;
|
||||
dest->pixrow = (JSAMPROW)dest->iobuffer;
|
||||
dest->pub.buffer = &dest->pixrow;
|
||||
dest->pub.buffer_height = 1;
|
||||
dest->pub.put_pixel_rows = put_pixel_rows;
|
||||
}
|
||||
|
||||
return (djpeg_dest_ptr) dest;
|
||||
return (djpeg_dest_ptr)dest;
|
||||
}
|
||||
|
||||
#endif /* PPM_SUPPORTED */
|
||||
|
||||
Reference in New Issue
Block a user