2011-09-07 10:31:00 +04:00
|
|
|
/*
|
|
|
|
* jdcolext.c
|
|
|
|
*
|
2012-12-31 06:52:30 +04:00
|
|
|
* This file was part of the Independent JPEG Group's software:
|
2011-09-07 10:31:00 +04:00
|
|
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
2013-09-28 07:23:49 +04:00
|
|
|
* libjpeg-turbo Modifications:
|
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
|
|
|
* Copyright (C) 2009, 2011, 2015, D. R. Commander.
|
2015-10-10 18:25:46 +03:00
|
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
|
|
* file.
|
2011-09-07 10:31:00 +04:00
|
|
|
*
|
|
|
|
* This file contains output colorspace conversion routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* This file is included by jdcolor.c */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert some rows of samples to the output colorspace.
|
|
|
|
*
|
|
|
|
* Note that we change from noninterleaved, one-plane-per-component format
|
|
|
|
* to interleaved-pixel format. The output buffer is therefore three times
|
|
|
|
* as wide as the input buffer.
|
|
|
|
* A starting row offset is provided only for the input buffer. The caller
|
|
|
|
* can easily adjust the passed output_buf value to accommodate any row
|
|
|
|
* offset required on that side.
|
|
|
|
*/
|
|
|
|
|
|
|
|
INLINE
|
|
|
|
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
|
|
|
ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
|
|
|
JDIMENSION input_row, JSAMPARRAY output_buf,
|
|
|
|
int num_rows)
|
2011-09-07 10:31: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
|
|
|
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
2011-09-07 10:31:00 +04:00
|
|
|
register int y, cb, cr;
|
|
|
|
register JSAMPROW outptr;
|
|
|
|
register JSAMPROW inptr0, inptr1, inptr2;
|
|
|
|
register JDIMENSION col;
|
|
|
|
JDIMENSION num_cols = cinfo->output_width;
|
|
|
|
/* copy these pointers into registers if possible */
|
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
|
|
|
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
|
|
|
register int *Crrtab = cconvert->Cr_r_tab;
|
|
|
|
register int *Cbbtab = cconvert->Cb_b_tab;
|
|
|
|
register JLONG *Crgtab = cconvert->Cr_g_tab;
|
|
|
|
register JLONG *Cbgtab = cconvert->Cb_g_tab;
|
2011-09-07 10:31:00 +04:00
|
|
|
SHIFT_TEMPS
|
|
|
|
|
|
|
|
while (--num_rows >= 0) {
|
|
|
|
inptr0 = input_buf[0][input_row];
|
|
|
|
inptr1 = input_buf[1][input_row];
|
|
|
|
inptr2 = input_buf[2][input_row];
|
|
|
|
input_row++;
|
|
|
|
outptr = *output_buf++;
|
|
|
|
for (col = 0; col < num_cols; col++) {
|
2019-01-23 23:58:24 +03:00
|
|
|
y = inptr0[col];
|
|
|
|
cb = inptr1[col];
|
|
|
|
cr = inptr2[col];
|
2011-09-07 10:31:00 +04:00
|
|
|
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
|
|
|
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
|
|
|
|
outptr[RGB_GREEN] = range_limit[y +
|
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
|
|
|
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
|
|
|
SCALEBITS))];
|
2011-09-07 10:31:00 +04:00
|
|
|
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
2011-09-09 22:15:53 +04:00
|
|
|
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
|
|
|
/* alpha channel value */
|
|
|
|
#ifdef RGB_ALPHA
|
|
|
|
outptr[RGB_ALPHA] = 0xFF;
|
|
|
|
#endif
|
2011-09-07 10:31:00 +04:00
|
|
|
outptr += RGB_PIXELSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert grayscale to RGB: just duplicate the graylevel three times.
|
|
|
|
* This is provided to support applications that don't want to cope
|
|
|
|
* with grayscale as a separate case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
INLINE
|
|
|
|
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
|
|
|
gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
|
|
|
JDIMENSION input_row, JSAMPARRAY output_buf,
|
|
|
|
int num_rows)
|
2011-09-07 10:31:00 +04:00
|
|
|
{
|
|
|
|
register JSAMPROW inptr, outptr;
|
|
|
|
register JDIMENSION col;
|
|
|
|
JDIMENSION num_cols = cinfo->output_width;
|
|
|
|
|
|
|
|
while (--num_rows >= 0) {
|
|
|
|
inptr = input_buf[0][input_row++];
|
|
|
|
outptr = *output_buf++;
|
|
|
|
for (col = 0; col < num_cols; col++) {
|
|
|
|
outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
|
2011-09-09 22:15:53 +04:00
|
|
|
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
|
|
|
/* alpha channel value */
|
|
|
|
#ifdef RGB_ALPHA
|
|
|
|
outptr[RGB_ALPHA] = 0xFF;
|
|
|
|
#endif
|
2011-09-07 10:31:00 +04:00
|
|
|
outptr += RGB_PIXELSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 02:06:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert RGB to extended RGB: just swap the order of source pixels
|
|
|
|
*/
|
|
|
|
|
|
|
|
INLINE
|
|
|
|
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
|
|
|
rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
|
|
|
JDIMENSION input_row, JSAMPARRAY output_buf,
|
|
|
|
int num_rows)
|
2012-03-12 02:06:54 +04:00
|
|
|
{
|
|
|
|
register JSAMPROW inptr0, inptr1, inptr2;
|
|
|
|
register JSAMPROW outptr;
|
|
|
|
register JDIMENSION col;
|
|
|
|
JDIMENSION num_cols = cinfo->output_width;
|
|
|
|
|
|
|
|
while (--num_rows >= 0) {
|
|
|
|
inptr0 = input_buf[0][input_row];
|
|
|
|
inptr1 = input_buf[1][input_row];
|
|
|
|
inptr2 = input_buf[2][input_row];
|
|
|
|
input_row++;
|
|
|
|
outptr = *output_buf++;
|
|
|
|
for (col = 0; col < num_cols; col++) {
|
|
|
|
outptr[RGB_RED] = inptr0[col];
|
|
|
|
outptr[RGB_GREEN] = inptr1[col];
|
|
|
|
outptr[RGB_BLUE] = inptr2[col];
|
|
|
|
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
|
|
|
/* alpha channel value */
|
|
|
|
#ifdef RGB_ALPHA
|
|
|
|
outptr[RGB_ALPHA] = 0xFF;
|
|
|
|
#endif
|
|
|
|
outptr += RGB_PIXELSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|