/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* FUNCTION
* mlib_ImageConvKernelConvert - Convert convolution kernel from
* floating point version to integer
* version.
*
* SYNOPSIS
* mlib_status mlib_ImageConvKernelConvert(mlib_s32 *ikernel,
* mlib_s32 *iscale,
* const mlib_d64 *fkernel,
* mlib_s32 m,
* mlib_s32 n,
* mlib_type type);
*
* ARGUMENT
* ikernel integer kernel
* iscale scaling factor of the integer kernel
* fkernel floating-point kernel
* m width of the convolution kernel
* n height of the convolution kernel
* type image type
*
* DESCRIPTION
* Convert a floating point convolution kernel to integer kernel
* with scaling factor. The result integer kernel and scaling factor
* can be used in convolution functions directly without overflow.
*
* RESTRICTION
* The type can be MLIB_BYTE, MLIB_SHORT, MLIB_USHORT or MLIB_INT.
*/
#include <stdlib.h>
#include "mlib_image.h"
#include "mlib_SysMath.h"
#include "mlib_ImageConv.h"
/***************************************************************/
#ifdef __sparc
#else
}
#endif /* __sparc */
/***************************************************************/
mlib_s32 m,
mlib_s32 n,
{
return MLIB_FAILURE;
}
sum_pos = 0;
sum_neg = 0;
for (i = 0; i < m * n; i++) {
if (fkernel[i] > 0)
else
}
scale++;
}
else { /* MLIB_SHORT */
sum = 0;
max = 0;
for (i = 0; i < m * n; i++) {
sum += f;
}
scale++;
}
if (scale <= 16)
return MLIB_FAILURE;
if (scale > 31)
scale = 31;
if (!chk_flag) {
for (i = 0; i < m * n; i++) {
}
return MLIB_SUCCESS;
}
/* try to round coefficients */
#ifdef __sparc
#else
if (chk_flag == 3)
else
#endif /* __sparc */
for (i = 0; i < m * n; i++) {
if (fkernel[i] > 0)
else
}
isum_pos = 0;
isum_neg = 0;
test = 0;
for (i = 0; i < m * n; i++) {
if (ikernel[i] > 0)
else
}
test = 1;
}
else {
test = 1;
for (i = 0; i < m * n; i++) {
test = 1;
}
}
for (i = 0; i < m * n; i++)
}
else { /* rounding is Ok */
for (i = 0; i < m * n; i++)
}
return MLIB_SUCCESS;
}
max = 0;
for (i = 0; i < m * n; i++) {
}
if (scale > 29)
return MLIB_FAILURE;
if (scale < -100)
scale = -100;
norm = 1.0;
while (scale > 30) {
scale -= 30;
}
for (i = 0; i < m * n; i++) {
if (fkernel[i] > 0) {
}
else {
}
}
return MLIB_SUCCESS;
}
else {
return MLIB_FAILURE;
}
}
/***************************************************************/