1994-09-24 04:00:00 +04:00
|
|
|
/*
|
|
|
|
* wrgif.c
|
|
|
|
*
|
2014-05-18 23:04:03 +04:00
|
|
|
* This file was part of the Independent JPEG Group's software:
|
1998-03-27 03:00:00 +03:00
|
|
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
2020-01-12 03:00:00 +03:00
|
|
|
* Modified 2015-2019 by Guido Vollbeding.
|
Replace INT32 with a new internal datatype (JLONG)
These days, INT32 is a commonly-defined datatype in system headers. We
cannot eliminate the definition of that datatype from jmorecfg.h, since
the INT32 typedef has technically been part of the libjpeg API since
version 5 (1994.) However, using INT32 internally is risky, because the
inclusion of a particular header (Xmd.h, for instance) could change the
definition of INT32 from long to int on 64-bit platforms and thus change
the internal behavior of libjpeg-turbo in unexpected ways (for instance,
failing to correctly set __INT32_IS_ACTUALLY_LONG to match the INT32
typedef-- perhaps as a result of including the wrong version of
jpeglib.h-- could cause libjpeg-turbo to produce incorrect results.)
The library has always been built in environments in which INT32 is
effectively long (on Windows, long is always 32-bit, so effectively it's
the same as int), so it makes sense to turn INT32 into an explicitly
long datatype. This ensures that libjpeg-turbo will always behave
consistently, regardless of the headers included at compile time.
Addresses a concern expressed in #26.
2015-10-15 01:32:39 +03:00
|
|
|
* libjpeg-turbo Modifications:
|
2022-01-06 18:17:30 +03:00
|
|
|
* Copyright (C) 2015, 2017, 2022, D. R. Commander.
|
2015-10-10 18:25:46 +03:00
|
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
|
|
* file.
|
1994-09-24 04:00:00 +04:00
|
|
|
*
|
1998-03-27 03:00:00 +03:00
|
|
|
* This file contains routines to write output images in GIF format.
|
|
|
|
*
|
1994-09-24 04:00:00 +04:00
|
|
|
* These routines may need modification for non-Unix environments or
|
|
|
|
* specialized applications. As they stand, they assume output to
|
|
|
|
* an ordinary stdio stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is loosely based on ppmtogif from the PBMPLUS distribution
|
|
|
|
* of Feb. 1991. That file contains the following copyright notice:
|
|
|
|
* Based on GIFENCODE by David Rowley <mgardi@watdscu.waterloo.edu>.
|
|
|
|
* Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al.
|
|
|
|
* Copyright (C) 1989 by Jef Poskanzer.
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for any purpose and without fee is hereby granted, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation. This software is provided "as is" without express or
|
|
|
|
* implied warranty.
|
|
|
|
*/
|
|
|
|
|
2014-05-11 13:36:25 +04:00
|
|
|
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
#ifdef GIF_SUPPORTED
|
|
|
|
|
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
#define MAX_LZW_BITS 12 /* maximum LZW code size (4096 symbols) */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
typedef INT16 code_int; /* must hold -1 .. 2**MAX_LZW_BITS */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
#define LZW_TABLE_SIZE ((code_int)1 << MAX_LZW_BITS)
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
#define HSIZE 5003 /* hash table size for 80% occupancy */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
typedef int hash_int; /* must hold -2*HSIZE..2*HSIZE */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
#define MAXCODE(n_bits) (((code_int)1 << (n_bits)) - 1)
|
2020-01-12 03:00:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The LZW hash table consists of two parallel arrays:
|
2020-10-27 21:28:56 +03:00
|
|
|
* hash_code[i] code of symbol in slot i, or 0 if empty slot
|
|
|
|
* hash_value[i] symbol's value; undefined if empty slot
|
2020-01-12 03:00:00 +03:00
|
|
|
* where slot values (i) range from 0 to HSIZE-1. The symbol value is
|
|
|
|
* its prefix symbol's code concatenated with its suffix character.
|
|
|
|
*
|
|
|
|
* Algorithm: use open addressing double hashing (no chaining) on the
|
|
|
|
* prefix code / suffix character combination. We do a variant of Knuth's
|
|
|
|
* algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
|
|
|
|
* secondary probe.
|
|
|
|
*/
|
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
typedef int hash_entry; /* must hold (code_int << 8) | byte */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
#define HASH_ENTRY(prefix, suffix) ((((hash_entry)(prefix)) << 8) | (suffix))
|
2020-01-12 03:00:00 +03:00
|
|
|
|
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Private version of data destination object */
|
|
|
|
|
|
|
|
typedef struct {
|
2014-05-11 13:36:25 +04:00
|
|
|
struct djpeg_dest_struct pub; /* public fields */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
2014-05-11 13:36:25 +04:00
|
|
|
j_decompress_ptr cinfo; /* back link saves passing separate parm */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
/* State for packing variable-width codes into a bitstream */
|
2014-05-11 13:36:25 +04:00
|
|
|
int n_bits; /* current number of bits/code */
|
2020-10-27 21:28:56 +03:00
|
|
|
code_int maxcode; /* maximum code, given n_bits */
|
|
|
|
int init_bits; /* initial n_bits ... restored after clear */
|
|
|
|
int cur_accum; /* holds bits not yet output */
|
2014-05-11 13:36:25 +04:00
|
|
|
int cur_bits; /* # of bits in cur_accum */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
/* LZW string construction */
|
2020-10-27 21:28:56 +03:00
|
|
|
code_int waiting_code; /* symbol not yet output; may be extendable */
|
|
|
|
boolean first_byte; /* if TRUE, waiting_code is not valid */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
1998-03-27 03:00:00 +03:00
|
|
|
/* State for GIF code assignment */
|
2020-10-27 21:28:56 +03:00
|
|
|
code_int ClearCode; /* clear code (doesn't change) */
|
|
|
|
code_int EOFCode; /* EOF code (ditto) */
|
|
|
|
code_int free_code; /* LZW: first not-yet-used symbol code */
|
|
|
|
code_int code_counter; /* not LZW: counts output symbols */
|
2020-01-12 03:00:00 +03:00
|
|
|
|
|
|
|
/* LZW hash table */
|
2020-10-27 21:28:56 +03:00
|
|
|
code_int *hash_code; /* => hash table of symbol codes */
|
|
|
|
hash_entry *hash_value; /* => hash table of symbol values */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
/* GIF data packet construction buffer */
|
2014-05-11 13:36:25 +04:00
|
|
|
int bytesinpkt; /* # of bytes in current packet */
|
|
|
|
char packetbuf[256]; /* workspace for accumulating packet */
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
} gif_dest_struct;
|
|
|
|
|
2016-02-19 17:53:33 +03:00
|
|
|
typedef gif_dest_struct *gif_dest_ptr;
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1998-03-27 03:00:00 +03:00
|
|
|
* Routines to package finished data bytes into GIF data blocks.
|
1994-09-24 04:00:00 +04:00
|
|
|
* A data block consists of a count byte (1..255) and that many data bytes.
|
|
|
|
*/
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
flush_packet(gif_dest_ptr dinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* flush any accumulated data */
|
|
|
|
{
|
2014-05-11 13:36:25 +04:00
|
|
|
if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
dinfo->packetbuf[0] = (char)dinfo->bytesinpkt++;
|
2022-02-08 00:27:50 +03:00
|
|
|
if (fwrite(dinfo->packetbuf, 1, dinfo->bytesinpkt,
|
|
|
|
dinfo->pub.output_file) != (size_t)dinfo->bytesinpkt)
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
|
|
|
|
dinfo->bytesinpkt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Add a character to current packet; flush to disk if necessary */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
#define CHAR_OUT(dinfo, c) { \
|
|
|
|
(dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char)(c); \
|
|
|
|
if ((dinfo)->bytesinpkt >= 255) \
|
|
|
|
flush_packet(dinfo); \
|
|
|
|
}
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Routine to convert variable-width codes into a byte stream */
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
2020-10-27 21:28:56 +03:00
|
|
|
output(gif_dest_ptr dinfo, code_int code)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Emit a code of n_bits bits */
|
|
|
|
/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */
|
|
|
|
{
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
dinfo->cur_accum |= ((long)code) << dinfo->cur_bits;
|
1994-09-24 04:00:00 +04:00
|
|
|
dinfo->cur_bits += dinfo->n_bits;
|
|
|
|
|
|
|
|
while (dinfo->cur_bits >= 8) {
|
|
|
|
CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
|
|
|
|
dinfo->cur_accum >>= 8;
|
|
|
|
dinfo->cur_bits -= 8;
|
|
|
|
}
|
2020-01-12 03:00:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the next entry is going to be too big for the code size,
|
|
|
|
* then increase it, if possible. We do this here to ensure
|
|
|
|
* that it's done in sync with the decoder's codesize increases.
|
|
|
|
*/
|
|
|
|
if (dinfo->free_code > dinfo->maxcode) {
|
|
|
|
dinfo->n_bits++;
|
|
|
|
if (dinfo->n_bits == MAX_LZW_BITS)
|
|
|
|
dinfo->maxcode = LZW_TABLE_SIZE; /* free_code will never exceed this */
|
|
|
|
else
|
|
|
|
dinfo->maxcode = MAXCODE(dinfo->n_bits);
|
|
|
|
}
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Compression initialization & termination */
|
|
|
|
|
|
|
|
|
|
|
|
LOCAL(void)
|
2020-10-27 21:28:56 +03:00
|
|
|
clear_hash(gif_dest_ptr dinfo)
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Fill the hash table with empty entries */
|
|
|
|
{
|
|
|
|
/* It's sufficient to zero hash_code[] */
|
2022-01-06 18:17:30 +03:00
|
|
|
memset(dinfo->hash_code, 0, HSIZE * sizeof(code_int));
|
2020-01-12 03:00:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOCAL(void)
|
2020-10-27 21:28:56 +03:00
|
|
|
clear_block(gif_dest_ptr dinfo)
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Reset compressor and issue a Clear code */
|
|
|
|
{
|
2020-10-27 21:28:56 +03:00
|
|
|
clear_hash(dinfo); /* delete all the symbols */
|
2020-01-12 03:00:00 +03:00
|
|
|
dinfo->free_code = dinfo->ClearCode + 2;
|
2020-10-27 21:28:56 +03:00
|
|
|
output(dinfo, dinfo->ClearCode); /* inform decoder */
|
|
|
|
dinfo->n_bits = dinfo->init_bits; /* reset code size */
|
2020-01-12 03:00:00 +03:00
|
|
|
dinfo->maxcode = MAXCODE(dinfo->n_bits);
|
|
|
|
}
|
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
compress_init(gif_dest_ptr dinfo, int i_bits)
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Initialize compressor */
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
|
|
|
/* init all the state variables */
|
2020-01-12 03:00:00 +03:00
|
|
|
dinfo->n_bits = dinfo->init_bits = i_bits;
|
1994-09-24 04:00:00 +04:00
|
|
|
dinfo->maxcode = MAXCODE(dinfo->n_bits);
|
2020-01-12 03:00:00 +03:00
|
|
|
dinfo->ClearCode = ((code_int) 1 << (i_bits - 1));
|
1994-09-24 04:00:00 +04:00
|
|
|
dinfo->EOFCode = dinfo->ClearCode + 1;
|
2020-01-12 03:00:00 +03:00
|
|
|
dinfo->code_counter = dinfo->free_code = dinfo->ClearCode + 2;
|
2020-10-27 21:28:56 +03:00
|
|
|
dinfo->first_byte = TRUE; /* no waiting symbol yet */
|
1994-09-24 04:00:00 +04:00
|
|
|
/* init output buffering vars */
|
|
|
|
dinfo->bytesinpkt = 0;
|
|
|
|
dinfo->cur_accum = 0;
|
|
|
|
dinfo->cur_bits = 0;
|
2020-01-12 03:00:00 +03:00
|
|
|
/* clear hash table */
|
|
|
|
if (dinfo->hash_code != NULL)
|
|
|
|
clear_hash(dinfo);
|
1994-09-24 04:00:00 +04:00
|
|
|
/* GIF specifies an initial Clear code */
|
|
|
|
output(dinfo, dinfo->ClearCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
compress_term(gif_dest_ptr dinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Clean up at end */
|
|
|
|
{
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Flush out the buffered LZW code */
|
2020-10-27 21:28:56 +03:00
|
|
|
if (!dinfo->first_byte)
|
2020-01-12 03:00:00 +03:00
|
|
|
output(dinfo, dinfo->waiting_code);
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Send an EOF code */
|
|
|
|
output(dinfo, dinfo->EOFCode);
|
|
|
|
/* Flush the bit-packing buffer */
|
|
|
|
if (dinfo->cur_bits > 0) {
|
|
|
|
CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
|
|
|
|
}
|
|
|
|
/* Flush the packet buffer */
|
|
|
|
flush_packet(dinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* GIF header construction */
|
|
|
|
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
put_word(gif_dest_ptr dinfo, unsigned int w)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Emit a 16-bit word, LSB first */
|
|
|
|
{
|
|
|
|
putc(w & 0xFF, dinfo->pub.output_file);
|
|
|
|
putc((w >> 8) & 0xFF, dinfo->pub.output_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
put_3bytes(gif_dest_ptr dinfo, int val)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Emit 3 copies of same byte value --- handy subr for colormap construction */
|
|
|
|
{
|
|
|
|
putc(val, dinfo->pub.output_file);
|
|
|
|
putc(val, dinfo->pub.output_file);
|
|
|
|
putc(val, dinfo->pub.output_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
LOCAL(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
emit_header(gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
|
1994-09-24 04:00:00 +04:00
|
|
|
/* Output the GIF file header, including color map */
|
2020-01-12 03:00:00 +03:00
|
|
|
/* If colormap == NULL, synthesize a grayscale colormap */
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
|
|
|
int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
|
|
|
|
int cshift = dinfo->cinfo->data_precision - 8;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (num_colors > 256)
|
|
|
|
ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
|
|
|
|
/* Compute bits/pixel and related values */
|
|
|
|
BitsPerPixel = 1;
|
|
|
|
while (num_colors > (1 << BitsPerPixel))
|
|
|
|
BitsPerPixel++;
|
|
|
|
ColorMapSize = 1 << BitsPerPixel;
|
|
|
|
if (BitsPerPixel <= 1)
|
|
|
|
InitCodeSize = 2;
|
|
|
|
else
|
|
|
|
InitCodeSize = BitsPerPixel;
|
|
|
|
/*
|
|
|
|
* Write the GIF header.
|
|
|
|
* Note that we generate a plain GIF87 header for maximum compatibility.
|
|
|
|
*/
|
|
|
|
putc('G', dinfo->pub.output_file);
|
|
|
|
putc('I', dinfo->pub.output_file);
|
|
|
|
putc('F', dinfo->pub.output_file);
|
|
|
|
putc('8', dinfo->pub.output_file);
|
|
|
|
putc('7', dinfo->pub.output_file);
|
|
|
|
putc('a', dinfo->pub.output_file);
|
|
|
|
/* Write the Logical Screen Descriptor */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
put_word(dinfo, (unsigned int)dinfo->cinfo->output_width);
|
|
|
|
put_word(dinfo, (unsigned int)dinfo->cinfo->output_height);
|
2014-05-11 13:36:25 +04:00
|
|
|
FlagByte = 0x80; /* Yes, there is a global color table */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
FlagByte |= (BitsPerPixel - 1) << 4; /* color resolution */
|
|
|
|
FlagByte |= (BitsPerPixel - 1); /* size of global color table */
|
1994-09-24 04:00:00 +04:00
|
|
|
putc(FlagByte, dinfo->pub.output_file);
|
|
|
|
putc(0, dinfo->pub.output_file); /* Background color index */
|
|
|
|
putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */
|
|
|
|
/* Write the Global Color Map */
|
|
|
|
/* If the color map is more than 8 bits precision, */
|
|
|
|
/* we reduce it to 8 bits by shifting */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
for (i = 0; i < ColorMapSize; i++) {
|
1994-09-24 04:00:00 +04:00
|
|
|
if (i < num_colors) {
|
|
|
|
if (colormap != NULL) {
|
2014-05-11 13:36:25 +04:00
|
|
|
if (dinfo->cinfo->out_color_space == JCS_RGB) {
|
|
|
|
/* Normal case: RGB color map */
|
2019-01-23 23:58:24 +03:00
|
|
|
putc(colormap[0][i] >> cshift, dinfo->pub.output_file);
|
|
|
|
putc(colormap[1][i] >> cshift, dinfo->pub.output_file);
|
|
|
|
putc(colormap[2][i] >> cshift, dinfo->pub.output_file);
|
2014-05-11 13:36:25 +04:00
|
|
|
} else {
|
|
|
|
/* Grayscale "color map": possible if quantizing grayscale image */
|
2019-01-23 23:58:24 +03:00
|
|
|
put_3bytes(dinfo, colormap[0][i] >> cshift);
|
2014-05-11 13:36:25 +04:00
|
|
|
}
|
1994-09-24 04:00:00 +04:00
|
|
|
} else {
|
2014-05-12 13:08:39 +04:00
|
|
|
/* Create a grayscale map of num_colors values, range 0..255 */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
put_3bytes(dinfo, (i * 255 + (num_colors - 1) / 2) / (num_colors - 1));
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* fill out the map to a power of 2 */
|
2020-01-12 03:00:00 +03:00
|
|
|
put_3bytes(dinfo, CENTERJSAMPLE >> cshift);
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Write image separator and Image Descriptor */
|
|
|
|
putc(',', dinfo->pub.output_file); /* separator */
|
2014-05-11 13:36:25 +04:00
|
|
|
put_word(dinfo, 0); /* left/top offset */
|
1994-09-24 04:00:00 +04:00
|
|
|
put_word(dinfo, 0);
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
put_word(dinfo, (unsigned int)dinfo->cinfo->output_width); /* image size */
|
|
|
|
put_word(dinfo, (unsigned int)dinfo->cinfo->output_height);
|
1994-09-24 04:00:00 +04:00
|
|
|
/* flag byte: not interlaced, no local color map */
|
|
|
|
putc(0x00, dinfo->pub.output_file);
|
|
|
|
/* Write Initial Code Size byte */
|
|
|
|
putc(InitCodeSize, dinfo->pub.output_file);
|
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Initialize for compression of image data */
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
compress_init(dinfo, InitCodeSize + 1);
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Startup: write the file header.
|
|
|
|
*/
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
METHODDEF(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
start_output_gif(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
gif_dest_ptr dest = (gif_dest_ptr)dinfo;
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
if (cinfo->quantize_colors)
|
|
|
|
emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);
|
|
|
|
else
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
emit_header(dest, 256, (JSAMPARRAY)NULL);
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write some pixel data.
|
|
|
|
* In this module rows_supplied will always be 1.
|
|
|
|
*/
|
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The LZW algorithm proper
|
|
|
|
*/
|
|
|
|
|
|
|
|
METHODDEF(void)
|
2020-10-27 21:28:56 +03:00
|
|
|
put_LZW_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
|
|
|
JDIMENSION rows_supplied)
|
2020-01-12 03:00:00 +03:00
|
|
|
{
|
2020-10-27 21:28:56 +03:00
|
|
|
gif_dest_ptr dest = (gif_dest_ptr)dinfo;
|
2020-01-12 03:00:00 +03:00
|
|
|
register JSAMPROW ptr;
|
|
|
|
register JDIMENSION col;
|
|
|
|
code_int c;
|
|
|
|
register hash_int i;
|
|
|
|
register hash_int disp;
|
|
|
|
register hash_entry probe_value;
|
|
|
|
|
|
|
|
ptr = dest->pub.buffer[0];
|
|
|
|
for (col = cinfo->output_width; col > 0; col--) {
|
|
|
|
/* Accept and compress one 8-bit byte */
|
2020-10-27 21:28:56 +03:00
|
|
|
c = (code_int)(*ptr++);
|
2020-01-12 03:00:00 +03:00
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
if (dest->first_byte) { /* need to initialize waiting_code */
|
2020-01-12 03:00:00 +03:00
|
|
|
dest->waiting_code = c;
|
|
|
|
dest->first_byte = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe hash table to see if a symbol exists for
|
|
|
|
* waiting_code followed by c.
|
|
|
|
* If so, replace waiting_code by that symbol and continue.
|
|
|
|
*/
|
2020-10-27 21:28:56 +03:00
|
|
|
i = ((hash_int)c << (MAX_LZW_BITS - 8)) + dest->waiting_code;
|
2020-01-12 03:00:00 +03:00
|
|
|
/* i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE */
|
|
|
|
if (i >= HSIZE)
|
|
|
|
i -= HSIZE;
|
|
|
|
|
|
|
|
probe_value = HASH_ENTRY(dest->waiting_code, c);
|
|
|
|
|
|
|
|
if (dest->hash_code[i] == 0) {
|
|
|
|
/* hit empty slot; desired symbol not in table */
|
|
|
|
output(dest, dest->waiting_code);
|
|
|
|
if (dest->free_code < LZW_TABLE_SIZE) {
|
2020-10-27 21:28:56 +03:00
|
|
|
dest->hash_code[i] = dest->free_code++; /* add symbol to hashtable */
|
|
|
|
dest->hash_value[i] = probe_value;
|
2020-01-12 03:00:00 +03:00
|
|
|
} else
|
2020-10-27 21:28:56 +03:00
|
|
|
clear_block(dest);
|
2020-01-12 03:00:00 +03:00
|
|
|
dest->waiting_code = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (dest->hash_value[i] == probe_value) {
|
|
|
|
dest->waiting_code = dest->hash_code[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-27 21:28:56 +03:00
|
|
|
if (i == 0) /* secondary hash (after G. Knott) */
|
2020-01-12 03:00:00 +03:00
|
|
|
disp = 1;
|
|
|
|
else
|
|
|
|
disp = HSIZE - i;
|
|
|
|
for (;;) {
|
|
|
|
i -= disp;
|
|
|
|
if (i < 0)
|
2020-10-27 21:28:56 +03:00
|
|
|
i += HSIZE;
|
2020-01-12 03:00:00 +03:00
|
|
|
if (dest->hash_code[i] == 0) {
|
2020-10-27 21:28:56 +03:00
|
|
|
/* hit empty slot; desired symbol not in table */
|
|
|
|
output(dest, dest->waiting_code);
|
|
|
|
if (dest->free_code < LZW_TABLE_SIZE) {
|
|
|
|
dest->hash_code[i] = dest->free_code++; /* add symbol to hashtable */
|
|
|
|
dest->hash_value[i] = probe_value;
|
|
|
|
} else
|
|
|
|
clear_block(dest);
|
|
|
|
dest->waiting_code = c;
|
|
|
|
break;
|
2020-01-12 03:00:00 +03:00
|
|
|
}
|
|
|
|
if (dest->hash_value[i] == probe_value) {
|
2020-10-27 21:28:56 +03:00
|
|
|
dest->waiting_code = dest->hash_code[i];
|
|
|
|
break;
|
2020-01-12 03:00:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The pseudo-compression algorithm.
|
|
|
|
*
|
|
|
|
* In this version we simply output each pixel value as a separate symbol;
|
|
|
|
* thus, no compression occurs. In fact, there is expansion of one bit per
|
|
|
|
* pixel, because we use a symbol width one bit wider than the pixel width.
|
|
|
|
*
|
|
|
|
* GIF ordinarily uses variable-width symbols, and the decoder will expect
|
|
|
|
* to ratchet up the symbol width after a fixed number of symbols.
|
|
|
|
* To simplify the logic and keep the expansion penalty down, we emit a
|
|
|
|
* GIF Clear code to reset the decoder just before the width would ratchet up.
|
|
|
|
* Thus, all the symbols in the output file will have the same bit width.
|
|
|
|
* Note that emitting the Clear codes at the right times is a mere matter of
|
|
|
|
* counting output symbols and is in no way dependent on the LZW algorithm.
|
|
|
|
*
|
|
|
|
* With a small basic pixel width (low color count), Clear codes will be
|
|
|
|
* needed very frequently, causing the file to expand even more. So this
|
|
|
|
* simplistic approach wouldn't work too well on bilevel images, for example.
|
|
|
|
* But for output of JPEG conversions the pixel width will usually be 8 bits
|
|
|
|
* (129 to 256 colors), so the overhead added by Clear symbols is only about
|
|
|
|
* one symbol in every 256.
|
|
|
|
*/
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
METHODDEF(void)
|
2020-10-27 21:28:56 +03:00
|
|
|
put_raw_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
|
|
|
JDIMENSION rows_supplied)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
gif_dest_ptr dest = (gif_dest_ptr)dinfo;
|
1994-09-24 04:00:00 +04:00
|
|
|
register JSAMPROW ptr;
|
|
|
|
register JDIMENSION col;
|
2020-01-12 03:00:00 +03:00
|
|
|
code_int c;
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
ptr = dest->pub.buffer[0];
|
|
|
|
for (col = cinfo->output_width; col > 0; col--) {
|
2020-10-27 21:28:56 +03:00
|
|
|
c = (code_int)(*ptr++);
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Accept and output one pixel value.
|
|
|
|
* The given value must be less than n_bits wide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Output the given pixel value as a symbol. */
|
|
|
|
output(dest, c);
|
|
|
|
/* Issue Clear codes often enough to keep the reader from ratcheting up
|
|
|
|
* its symbol size.
|
|
|
|
*/
|
|
|
|
if (dest->code_counter < dest->maxcode) {
|
|
|
|
dest->code_counter++;
|
|
|
|
} else {
|
|
|
|
output(dest, dest->ClearCode);
|
2020-10-27 21:28:56 +03:00
|
|
|
dest->code_counter = dest->ClearCode + 2; /* reset the counter */
|
2020-01-12 03:00:00 +03:00
|
|
|
}
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish up at the end of the file.
|
|
|
|
*/
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
METHODDEF(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
finish_output_gif(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
gif_dest_ptr dest = (gif_dest_ptr)dinfo;
|
1994-09-24 04:00:00 +04:00
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
/* Flush compression mechanism */
|
1994-09-24 04:00:00 +04:00
|
|
|
compress_term(dest);
|
|
|
|
/* Write a zero-length data block to end the series */
|
|
|
|
putc(0, dest->pub.output_file);
|
|
|
|
/* Write the GIF terminator mark */
|
|
|
|
putc(';', dest->pub.output_file);
|
|
|
|
/* Make sure we wrote the output file OK */
|
|
|
|
fflush(dest->pub.output_file);
|
|
|
|
if (ferror(dest->pub.output_file))
|
|
|
|
ERREXIT(cinfo, JERR_FILE_WRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-14 06:01:53 +03:00
|
|
|
/*
|
|
|
|
* Re-calculate buffer dimensions based on output dimensions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
METHODDEF(void)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
calc_buffer_dimensions_gif(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
|
2017-11-14 06:01:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
/*
|
|
|
|
* The module selection routine for GIF format output.
|
|
|
|
*/
|
|
|
|
|
1996-02-07 03:00:00 +03:00
|
|
|
GLOBAL(djpeg_dest_ptr)
|
2020-10-27 21:28:56 +03:00
|
|
|
jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
|
|
|
gif_dest_ptr dest;
|
|
|
|
|
|
|
|
/* Create module interface object, fill in method pointers */
|
|
|
|
dest = (gif_dest_ptr)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
|
|
sizeof(gif_dest_struct));
|
2014-05-11 13:36:25 +04:00
|
|
|
dest->cinfo = cinfo; /* make back link for subroutines */
|
1994-09-24 04:00:00 +04:00
|
|
|
dest->pub.start_output = start_output_gif;
|
|
|
|
dest->pub.finish_output = finish_output_gif;
|
2017-11-14 06:01:53 +03:00
|
|
|
dest->pub.calc_buffer_dimensions = calc_buffer_dimensions_gif;
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
if (cinfo->out_color_space != JCS_GRAYSCALE &&
|
|
|
|
cinfo->out_color_space != JCS_RGB)
|
|
|
|
ERREXIT(cinfo, JERR_GIF_COLORSPACE);
|
|
|
|
|
|
|
|
/* Force quantization if color or if > 8 bits input */
|
|
|
|
if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) {
|
|
|
|
/* Force quantization to at most 256 colors */
|
|
|
|
cinfo->quantize_colors = TRUE;
|
|
|
|
if (cinfo->desired_number_of_colors > 256)
|
|
|
|
cinfo->desired_number_of_colors = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate output image dimensions so we can allocate space */
|
|
|
|
jpeg_calc_output_dimensions(cinfo);
|
|
|
|
|
|
|
|
if (cinfo->output_components != 1) /* safety check: just one component? */
|
|
|
|
ERREXIT(cinfo, JERR_GIF_BUG);
|
|
|
|
|
|
|
|
/* Create decompressor output buffer. */
|
|
|
|
dest->pub.buffer = (*cinfo->mem->alloc_sarray)
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
((j_common_ptr)cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION)1);
|
1994-09-24 04:00:00 +04:00
|
|
|
dest->pub.buffer_height = 1;
|
|
|
|
|
2020-01-12 03:00:00 +03:00
|
|
|
if (is_lzw) {
|
|
|
|
dest->pub.put_pixel_rows = put_LZW_pixel_rows;
|
|
|
|
/* Allocate space for hash table */
|
2020-10-27 21:28:56 +03:00
|
|
|
dest->hash_code = (code_int *)
|
|
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
|
|
HSIZE * sizeof(code_int));
|
|
|
|
dest->hash_value = (hash_entry *)
|
|
|
|
(*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
|
|
HSIZE * sizeof(hash_entry));
|
2020-01-12 03:00:00 +03:00
|
|
|
} else {
|
|
|
|
dest->pub.put_pixel_rows = put_raw_pixel_rows;
|
|
|
|
/* Mark tables unused */
|
|
|
|
dest->hash_code = NULL;
|
|
|
|
dest->hash_value = NULL;
|
|
|
|
}
|
|
|
|
|
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.
2018-03-08 19:55:20 +03:00
|
|
|
return (djpeg_dest_ptr)dest;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GIF_SUPPORTED */
|