Also, set the red/green/blue offsets for TJPF_GRAY to -1 rather than 0.
It was undefined behavior for an application to use those arrays/methods
with TJPF_GRAY anyhow, and this makes it easier for applications to
programmatically detect whether a given pixel format has red, green, and
blue components.
libjpeg-turbo to quickly develop a complete JPEG compression/decompression
program.
+14. The TurboJPEG C API now includes a new convenience array
+(`tjAlphaOffset[]`) that contains the alpha component index for each pixel
+format (or -1 if the pixel format lacks an alpha component.) The TurboJPEG
+Java API now includes a new method (`TJ.getAlphaOffset()`) that returns the
+same value. In addition, the `tjRedOffset[]`, `tjGreenOffset[]`, and
+`tjBlueOffset[]` arrays-- and the corresponding `TJ.getRedOffset()`,
+`TJ.getGreenOffset()`, and `TJ.getBlueOffset()` methods-- now return -1 for
+`TJPF_GRAY`/`TJ.PF_GRAY` rather than 0. This allows programs to easily
+determine whether a pixel format has red, green, blue, and alpha components.
+
1.5.2
=====
<tr class="memitem:ga84e2e35d3f08025f976ec1ec53693dea"><td class="memItemLeft" align="right" valign="top">static const int </td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga84e2e35d3f08025f976ec1ec53693dea">tjBlueOffset</a> [<a class="el" href="group___turbo_j_p_e_g.html#ga7010a4402f54a45ba822ad8675a4655e">TJ_NUMPF</a>]</td></tr>
<tr class="memdesc:ga84e2e35d3f08025f976ec1ec53693dea"><td class="mdescLeft"> </td><td class="mdescRight">Blue offset (in bytes) for a given pixel format. <a href="#ga84e2e35d3f08025f976ec1ec53693dea">More...</a><br/></td></tr>
<tr class="separator:ga84e2e35d3f08025f976ec1ec53693dea"><td class="memSeparator" colspan="2"> </td></tr>
+<tr class="memitem:ga5af0ab065feefd526debf1e20c43e837"><td class="memItemLeft" align="right" valign="top">static const int </td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga5af0ab065feefd526debf1e20c43e837">tjAlphaOffset</a> [<a class="el" href="group___turbo_j_p_e_g.html#ga7010a4402f54a45ba822ad8675a4655e">TJ_NUMPF</a>]</td></tr>
+<tr class="memdesc:ga5af0ab065feefd526debf1e20c43e837"><td class="mdescLeft"> </td><td class="mdescRight">Alpha offset (in bytes) for a given pixel format. <a href="#ga5af0ab065feefd526debf1e20c43e837">More...</a><br/></td></tr>
+<tr class="separator:ga5af0ab065feefd526debf1e20c43e837"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gad77cf8fe5b2bfd3cb3f53098146abb4c"><td class="memItemLeft" align="right" valign="top">static const int </td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c">tjPixelSize</a> [<a class="el" href="group___turbo_j_p_e_g.html#ga7010a4402f54a45ba822ad8675a4655e">TJ_NUMPF</a>]</td></tr>
<tr class="memdesc:gad77cf8fe5b2bfd3cb3f53098146abb4c"><td class="mdescLeft"> </td><td class="mdescRight">Pixel size (in bytes) for a given pixel format. <a href="#gad77cf8fe5b2bfd3cb3f53098146abb4c">More...</a><br/></td></tr>
<tr class="separator:gad77cf8fe5b2bfd3cb3f53098146abb4c"><td class="memSeparator" colspan="2"> </td></tr>
</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
+<a class="anchor" id="ga5af0ab065feefd526debf1e20c43e837"></a>
+<div class="memitem">
+<div class="memproto">
+<table class="mlabels">
+ <tr>
+ <td class="mlabels-left">
+ <table class="memname">
+ <tr>
+ <td class="memname">const int tjAlphaOffset[<a class="el" href="group___turbo_j_p_e_g.html#ga7010a4402f54a45ba822ad8675a4655e">TJ_NUMPF</a>]</td>
+ </tr>
+ </table>
+ </td>
+ <td class="mlabels-right">
+<span class="mlabels"><span class="mlabel">static</span></span> </td>
+ </tr>
+</table>
+</div><div class="memdoc">
+
+<p>Alpha offset (in bytes) for a given pixel format. </p>
+<p>This specifies the number of bytes that the Alpha component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRA is stored in <code>char pixel[]</code>, then the alpha component will be <code>pixel[tjAlphaOffset[TJ_BGRA]]</code>. This will be -1 if the pixel format does not have an alpha component. </p>
+
+</div>
+</div>
<a class="anchor" id="ga84e2e35d3f08025f976ec1ec53693dea"></a>
<div class="memitem">
<div class="memproto">
</div><div class="memdoc">
<p>Blue offset (in bytes) for a given pixel format. </p>
-<p>This specifies the number of bytes that the Blue component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the blue component will be <code>pixel[tjBlueOffset[TJ_BGRX]]</code>. </p>
+<p>This specifies the number of bytes that the Blue component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the blue component will be <code>pixel[tjBlueOffset[TJ_BGRX]]</code>. This will be -1 if the pixel format does not have a blue component. </p>
</div>
</div>
</div><div class="memdoc">
<p>Green offset (in bytes) for a given pixel format. </p>
-<p>This specifies the number of bytes that the green component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the green component will be <code>pixel[tjGreenOffset[TJ_BGRX]]</code>. </p>
+<p>This specifies the number of bytes that the green component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the green component will be <code>pixel[tjGreenOffset[TJ_BGRX]]</code>. This will be -1 if the pixel format does not have a green component. </p>
</div>
</div>
</div><div class="memdoc">
<p>Red offset (in bytes) for a given pixel format. </p>
-<p>This specifies the number of bytes that the red component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the red component will be <code>pixel[tjRedOffset[TJ_BGRX]]</code>. </p>
+<p>This specifies the number of bytes that the red component is offset from the start of the pixel. For instance, if a pixel of format TJ_BGRX is stored in <code>char pixel[]</code>, then the red component will be <code>pixel[tjRedOffset[TJ_BGRX]]</code>. This will be -1 if the pixel format does not have a red component. </p>
</div>
</div>
['tj_5fnumsamp',['TJ_NUMSAMP',['../group___turbo_j_p_e_g.html#ga5ef3d169162ce77ce348e292a0b7477c',1,'turbojpeg.h']]],
['tj_5fnumxop',['TJ_NUMXOP',['../group___turbo_j_p_e_g.html#ga0f6dbd18adf38b7d46ac547f0f4d562c',1,'turbojpeg.h']]],
['tjalloc',['tjAlloc',['../group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff',1,'turbojpeg.h']]],
+ ['tjalphaoffset',['tjAlphaOffset',['../group___turbo_j_p_e_g.html#ga5af0ab065feefd526debf1e20c43e837',1,'turbojpeg.h']]],
['tjblueoffset',['tjBlueOffset',['../group___turbo_j_p_e_g.html#ga84e2e35d3f08025f976ec1ec53693dea',1,'turbojpeg.h']]],
['tjbufsize',['tjBufSize',['../group___turbo_j_p_e_g.html#gaccc5bca7f12fcdcc302e6e1c6d4b311b',1,'turbojpeg.h']]],
['tjbufsizeyuv2',['tjBufSizeYUV2',['../group___turbo_j_p_e_g.html#gaf451664a62c1f6c7cc5a6401f32908c9',1,'turbojpeg.h']]],
var searchData=
[
+ ['tjalphaoffset',['tjAlphaOffset',['../group___turbo_j_p_e_g.html#ga5af0ab065feefd526debf1e20c43e837',1,'turbojpeg.h']]],
['tjblueoffset',['tjBlueOffset',['../group___turbo_j_p_e_g.html#ga84e2e35d3f08025f976ec1ec53693dea',1,'turbojpeg.h']]],
['tjgreenoffset',['tjGreenOffset',['../group___turbo_j_p_e_g.html#ga82d6e35da441112a411da41923c0ba2f',1,'turbojpeg.h']]],
['tjmcuheight',['tjMCUHeight',['../group___turbo_j_p_e_g.html#gabd247bb9fecb393eca57366feb8327bf',1,'turbojpeg.h']]],
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
};
- private static final int[] alphaOffset = {
- -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
- };
-
private static final int[] _3byteFormats = {
TJ.PF_RGB, TJ.PF_BGR
};
int roffset = TJ.getRedOffset(pf);
int goffset = TJ.getGreenOffset(pf);
int boffset = TJ.getBlueOffset(pf);
- int aoffset = alphaOffset[pf];
+ int aoffset = TJ.getAlphaOffset(pf);
int ps = TJ.getPixelSize(pf);
int index, row, col, halfway = 16;
int rshift = TJ.getRedOffset(pf) * 8;
int gshift = TJ.getGreenOffset(pf) * 8;
int bshift = TJ.getBlueOffset(pf) * 8;
- int ashift = alphaOffset[pf] * 8;
+ int ashift = TJ.getAlphaOffset(pf) * 8;
int index, row, col, halfway = 16;
Arrays.fill(buf, 0);
int roffset = TJ.getRedOffset(pf);
int goffset = TJ.getGreenOffset(pf);
int boffset = TJ.getBlueOffset(pf);
- int aoffset = alphaOffset[pf];
+ int aoffset = TJ.getAlphaOffset(pf);
int ps = TJ.getPixelSize(pf);
int index, row, col, retval = 1;
int halfway = 16 * sf.getNum() / sf.getDenom();
try {
+ if (pf == TJ.PF_GRAY)
+ roffset = goffset = boffset = 0;
+
if (pf == TJ.PF_CMYK) {
for (row = 0; row < h; row++) {
for (col = 0; col < w; col++) {
int rshift = TJ.getRedOffset(pf) * 8;
int gshift = TJ.getGreenOffset(pf) * 8;
int bshift = TJ.getBlueOffset(pf) * 8;
- int ashift = alphaOffset[pf] * 8;
+ int ashift = TJ.getAlphaOffset(pf) * 8;
int index, row, col, retval = 1;
int halfway = 16 * sf.getNum() / sf.getDenom();
int blockSize = 8 * sf.getNum() / sf.getDenom();
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="Constant Field Values";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="Constant Field Values";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="Deprecated List";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="Deprecated List";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="API Help";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="API Help";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="Index";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="Index";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</a>
<h2 class="title">G</h2>
<dl>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#getAlphaOffset(int)">getAlphaOffset(int)</a></span> - Static method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
+<dd>
+<div class="block">For the given pixel format, returns the number of bytes that the alpha
+ component is offset from the start of the pixel.</div>
+</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#getBlueOffset(int)">getBlueOffset(int)</a></span> - Static method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
<dd>
<div class="block">For the given pixel format, returns the number of bytes that the blue
<head>
<title>Generated Documentation (Untitled)</title>
<script type="text/javascript">
- targetPage = "" + window.location.search;
- if (targetPage != "" && targetPage != "undefined")
- targetPage = targetPage.substring(1);
- if (targetPage.indexOf(":") != -1 || (targetPage != "" && !validURL(targetPage)))
- targetPage = "undefined";
+ tmpTargetPage = "" + window.location.search;
+ if (tmpTargetPage != "" && tmpTargetPage != "undefined")
+ tmpTargetPage = tmpTargetPage.substring(1);
+ if (tmpTargetPage.indexOf(":") != -1 || (tmpTargetPage != "" && !validURL(tmpTargetPage)))
+ tmpTargetPage = "undefined";
+ targetPage = tmpTargetPage;
function validURL(url) {
try {
url = decodeURIComponent(url);
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJ";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJ";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getAlphaOffset(int)">getAlphaOffset</a></strong>(int pixelFormat)</code>
+<div class="block">For the given pixel format, returns the number of bytes that the alpha
+ component is offset from the start of the pixel.</div>
+</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getBlueOffset(int)">getBlueOffset</a></strong>(int pixelFormat)</code>
<div class="block">For the given pixel format, returns the number of bytes that the blue
component is offset from the start of the pixel.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getGreenOffset(int)">getGreenOffset</a></strong>(int pixelFormat)</code>
<div class="block">For the given pixel format, returns the number of bytes that the green
component is offset from the start of the pixel.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getMCUHeight(int)">getMCUHeight</a></strong>(int subsamp)</code>
<div class="block">Returns the MCU block height for the given level of chrominance
subsampling.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getMCUWidth(int)">getMCUWidth</a></strong>(int subsamp)</code>
<div class="block">Returns the MCU block width for the given level of chrominance
subsampling.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getPixelSize(int)">getPixelSize</a></strong>(int pixelFormat)</code>
<div class="block">Returns the pixel size (in bytes) for the given pixel format.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getRedOffset(int)">getRedOffset</a></strong>(int pixelFormat)</code>
<div class="block">For the given pixel format, returns the number of bytes that the red
component is offset from the start of the pixel.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>static <a href="../../../org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg">TJScalingFactor</a>[]</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#getScalingFactors()">getScalingFactors</a></strong>()</code>
<div class="block">Returns a list of fractional scaling factors that the JPEG decompressor in
this implementation of TurboJPEG supports.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#planeHeight(int,%20int,%20int)">planeHeight</a></strong>(int componentID,
int height,
<div class="block">Returns the plane height of a YUV image plane with the given parameters.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#planeSizeYUV(int,%20int,%20int,%20int,%20int)">planeSizeYUV</a></strong>(int componentID,
int width,
plane with the given parameters.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#planeWidth(int,%20int,%20int)">planeWidth</a></strong>(int componentID,
int width,
then the red component will be
<code>pixel[TJ.getRedOffset(TJ.PF_BGRX)]</code>.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>pixelFormat</code> - the pixel format (one of <code>PF_*</code>)</dd>
-<dt><span class="strong">Returns:</span></dt><dd>the red offset for the given pixel format.</dd></dl>
+<dt><span class="strong">Returns:</span></dt><dd>the red offset for the given pixel format, or -1 if the pixel
+ format does not have a red component.</dd></dl>
</li>
</ul>
<a name="getGreenOffset(int)">
then the green component will be
<code>pixel[TJ.getGreenOffset(TJ.PF_BGRX)]</code>.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>pixelFormat</code> - the pixel format (one of <code>PF_*</code>)</dd>
-<dt><span class="strong">Returns:</span></dt><dd>the green offset for the given pixel format.</dd></dl>
+<dt><span class="strong">Returns:</span></dt><dd>the green offset for the given pixel format, or -1 if the pixel
+ format does not have a green component.</dd></dl>
</li>
</ul>
<a name="getBlueOffset(int)">
then the blue component will be
<code>pixel[TJ.getBlueOffset(TJ.PF_BGRX)]</code>.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>pixelFormat</code> - the pixel format (one of <code>PF_*</code>)</dd>
-<dt><span class="strong">Returns:</span></dt><dd>the blue offset for the given pixel format.</dd></dl>
+<dt><span class="strong">Returns:</span></dt><dd>the blue offset for the given pixel format, or -1 if the pixel
+ format does not have a blue component.</dd></dl>
+</li>
+</ul>
+<a name="getAlphaOffset(int)">
+<!-- -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>getAlphaOffset</h4>
+<pre>public static int getAlphaOffset(int pixelFormat)</pre>
+<div class="block">For the given pixel format, returns the number of bytes that the alpha
+ component is offset from the start of the pixel. For instance, if a pixel
+ of format <code>TJ.PF_BGRA</code> is stored in <code>char pixel[]</code>,
+ then the alpha component will be
+ <code>pixel[TJ.getAlphaOffset(TJ.PF_BGRA)]</code>.</div>
+<dl><dt><span class="strong">Parameters:</span></dt><dd><code>pixelFormat</code> - the pixel format (one of <code>PF_*</code>)</dd>
+<dt><span class="strong">Returns:</span></dt><dd>the alpha offset for the given pixel format, or -1 if the pixel
+ format does not have a alpha component.</dd></dl>
</li>
</ul>
<a name="bufSize(int, int, int)">
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJCompressor";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJCompressor";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJCustomFilter";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJCustomFilter";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJDecompressor";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJDecompressor";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJException";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJException";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJScalingFactor";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJScalingFactor";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJTransform";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJTransform";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="TJTransformer";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TJTransformer";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="YUVImage";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="YUVImage";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="org.libjpegturbo.turbojpeg";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="org.libjpegturbo.turbojpeg";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="org.libjpegturbo.turbojpeg Class Hierarchy";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="org.libjpegturbo.turbojpeg Class Hierarchy";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="Class Hierarchy";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="Class Hierarchy";
+ }
+ }
+ catch(err) {
}
//-->
</script>
</head>
<body>
<script type="text/javascript"><!--
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="Serialized Form";
+ try {
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="Serialized Form";
+ }
+ }
+ catch(err) {
}
//-->
</script>
*
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
- * @return the red offset for the given pixel format.
+ * @return the red offset for the given pixel format, or -1 if the pixel
+ * format does not have a red component.
*/
public static int getRedOffset(int pixelFormat) {
checkPixelFormat(pixelFormat);
}
private static final int[] redOffset = {
- 0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1
+ 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
};
*
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
- * @return the green offset for the given pixel format.
+ * @return the green offset for the given pixel format, or -1 if the pixel
+ * format does not have a green component.
*/
public static int getGreenOffset(int pixelFormat) {
checkPixelFormat(pixelFormat);
}
private static final int[] greenOffset = {
- 1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1
+ 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
};
*
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
- * @return the blue offset for the given pixel format.
+ * @return the blue offset for the given pixel format, or -1 if the pixel
+ * format does not have a blue component.
*/
public static int getBlueOffset(int pixelFormat) {
checkPixelFormat(pixelFormat);
}
private static final int[] blueOffset = {
- 2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1
+ 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
+ };
+
+
+ /**
+ * For the given pixel format, returns the number of bytes that the alpha
+ * component is offset from the start of the pixel. For instance, if a pixel
+ * of format <code>TJ.PF_BGRA</code> is stored in <code>char pixel[]</code>,
+ * then the alpha component will be
+ * <code>pixel[TJ.getAlphaOffset(TJ.PF_BGRA)]</code>.
+ *
+ * @param pixelFormat the pixel format (one of <code>PF_*</code>)
+ *
+ * @return the alpha offset for the given pixel format, or -1 if the pixel
+ * format does not have a alpha component.
+ */
+ public static int getAlphaOffset(int pixelFormat) {
+ checkPixelFormat(pixelFormat);
+ return alphaOffset[pixelFormat];
+ }
+
+ private static final int[] alphaOffset = {
+ -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
};
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
};
-const int alphaOffset[TJ_NUMPF] = {-1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1};
-
const int _3byteFormats[]={TJPF_RGB, TJPF_BGR};
const int _4byteFormats[]={TJPF_RGBX, TJPF_BGRX, TJPF_XBGR, TJPF_XRGB,
TJPF_CMYK};
int roffset=tjRedOffset[pf];
int goffset=tjGreenOffset[pf];
int boffset=tjBlueOffset[pf];
- int aoffset=alphaOffset[pf];
+ int aoffset=tjAlphaOffset[pf];
int ps=tjPixelSize[pf];
int index, row, col, retval=1;
int halfway=16*sf.num/sf.denom;
int blocksize=8*sf.num/sf.denom;
+ if(pf==TJPF_GRAY) roffset=goffset=boffset=0;
+
if(pf==TJPF_CMYK)
{
for(row=0; row<h; row++)
int roffset=tjRedOffset[pf];
int goffset=tjGreenOffset[pf];
int boffset=tjBlueOffset[pf];
- int aoffset=alphaOffset[pf];
+ int aoffset=tjAlphaOffset[pf];
int ps=tjPixelSize[pf];
int i, j;
TJPF_UNKNOWN = -1
};
-
/**
* Red offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the red component is offset from the start of the pixel. For
* instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
- * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.
+ * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. This
+ * will be -1 if the pixel format does not have a red component.
*/
-static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1};
+static const int tjRedOffset[TJ_NUMPF] = {
+ 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
+};
/**
* Green offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the green component is offset from the start of the pixel.
* For instance, if a pixel of format TJ_BGRX is stored in
* <tt>char pixel[]</tt>, then the green component will be
- * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.
+ * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. This will be -1 if the pixel format
+ * does not have a green component.
*/
-static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1};
+static const int tjGreenOffset[TJ_NUMPF] = {
+ 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
+};
/**
* Blue offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the Blue component is offset from the start of the pixel. For
* instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
- * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.
+ * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. This
+ * will be -1 if the pixel format does not have a blue component.
+ */
+static const int tjBlueOffset[TJ_NUMPF] = {
+ 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
+};
+/**
+ * Alpha offset (in bytes) for a given pixel format. This specifies the number
+ * of bytes that the Alpha component is offset from the start of the pixel.
+ * For instance, if a pixel of format TJ_BGRA is stored in
+ * <tt>char pixel[]</tt>, then the alpha component will be
+ * <tt>pixel[tjAlphaOffset[TJ_BGRA]]</tt>. This will be -1 if the pixel format
+ * does not have an alpha component.
*/
-static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1};
+static const int tjAlphaOffset[TJ_NUMPF] = {
+ -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
+};
/**
- * Pixel size (in bytes) for a given pixel format.
+ * Pixel size (in bytes) for a given pixel format
*/
-static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4};
+static const int tjPixelSize[TJ_NUMPF] = {
+ 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
+};
/**