Bug Summary

File:jdk/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_8ext.c
Warning:line 786, column 16
Assigned value is garbage or undefined

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name mlib_ImageConv_8ext.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -D LIBC=gnu -D _GNU_SOURCE -D _REENTRANT -D _LARGEFILE64_SOURCE -D LINUX -D DEBUG -D _LITTLE_ENDIAN -D ARCH="amd64" -D amd64 -D _LP64=1 -D __USE_J2D_NAMES -D __MEDIALIB_OLD_NAMES -D MLIB_NO_LIBSUNMATH -D MLIB_OS64BIT -I /home/daniel/Projects/java/jdk/src/java.desktop/share/native/libmlib_image -I /home/daniel/Projects/java/jdk/src/java.desktop/share/native/common/awt/medialib -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/java.desktop -D _FORTIFY_SOURCE=2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-unused -Wno-unused-function -std=c99 -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c /home/daniel/Projects/java/jdk/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_8ext.c
1/*
2 * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27/*
28 * FUNCTION
29 * Internal functions for mlib_ImageConv* on U8/S16/U16 type and
30 * MLIB_EDGE_SRC_EXTEND mask
31 */
32
33#include "mlib_image.h"
34#include "mlib_ImageConv.h"
35#include "mlib_c_ImageConv.h"
36
37/*
38 * This define switches between functions of different data types
39 */
40
41#define IMG_TYPE1 1
42
43/***************************************************************/
44#if IMG_TYPE1 == 1
45
46#define DTYPEmlib_u8 mlib_u8
47#define CONV_FUNC(KERN)mlib_c_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_c_conv##KERN##ext_u8(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
48#define CONV_FUNC_MxNmlib_c_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_c_convMxNext_u8(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
49#define CONV_FUNC_I(KERN)mlib_i_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_i_conv##KERN##ext_u8(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
50#define CONV_FUNC_MxN_Imlib_i_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_i_convMxNext_u8(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
51#define DSCALE(1 << 24) (1 << 24)
52#define FROM_S32(x)(((x) >> 24) ^ 128) (((x) >> 24) ^ 128)
53#define S64TOS32(x)(x) (x)
54#define SAT_OFF-(1u << 31) -(1u << 31)
55
56#elif IMG_TYPE1 == 2
57
58#define DTYPEmlib_u8 mlib_s16
59#define CONV_FUNC(KERN)mlib_c_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_conv##KERN##ext_s16(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
60#define CONV_FUNC_MxNmlib_c_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_convMxNext_s16(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
61#define CONV_FUNC_I(KERN)mlib_i_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_i_conv##KERN##ext_s16(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
62#define CONV_FUNC_MxN_Imlib_i_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_i_convMxNext_s16(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
63#define DSCALE(1 << 24) 65536.0
64#define FROM_S32(x)(((x) >> 24) ^ 128) ((x) >> 16)
65#define S64TOS32(x)(x) ((x) & 0xffffffff)
66#define SAT_OFF-(1u << 31)
67
68#elif IMG_TYPE1 == 3
69
70#define DTYPEmlib_u8 mlib_u16
71#define CONV_FUNC(KERN)mlib_c_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_conv##KERN##ext_u16(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
72#define CONV_FUNC_MxNmlib_c_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_convMxNext_u16(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
73#define CONV_FUNC_I(KERN)mlib_i_convKERNext_u8(mlib_image *dst, const mlib_image *src,
mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const
mlib_s32 *kern, mlib_s32 scalef_expon, mlib_s32 cmask)
mlib_i_conv##KERN##ext_u16(PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
)
74#define CONV_FUNC_MxN_Imlib_i_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
mlib_i_convMxNext_u16(PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
)
75#define DSCALE(1 << 24) 65536.0
76#define FROM_S32(x)(((x) >> 24) ^ 128) (((x) >> 16) ^ 0x8000)
77#define S64TOS32(x)(x) (x)
78#define SAT_OFF-(1u << 31) -(1u << 31)
79
80#endif /* IMG_TYPE == 1 */
81
82/***************************************************************/
83#define PARAMmlib_image *dst, const mlib_image *src, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, const mlib_s32 *kern, mlib_s32
scalef_expon, mlib_s32 cmask
\
84 mlib_image *dst, \
85 const mlib_image *src, \
86 mlib_s32 dx_l, \
87 mlib_s32 dx_r, \
88 mlib_s32 dy_t, \
89 mlib_s32 dy_b, \
90 const mlib_s32 *kern, \
91 mlib_s32 scalef_expon, \
92 mlib_s32 cmask
93
94/***************************************************************/
95#define PARAM_MxNmlib_image *dst, const mlib_image *src, const mlib_s32 *kernel
, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32 dx_r, mlib_s32
dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32 cmask
\
96 mlib_image *dst, \
97 const mlib_image *src, \
98 const mlib_s32 *kernel, \
99 mlib_s32 m, \
100 mlib_s32 n, \
101 mlib_s32 dx_l, \
102 mlib_s32 dx_r, \
103 mlib_s32 dy_t, \
104 mlib_s32 dy_b, \
105 mlib_s32 scale, \
106 mlib_s32 cmask
107
108/***************************************************************/
109#define FTYPEmlib_d64 mlib_d64
110
111#ifndef MLIB_USE_FTOI_CLAMPING
112
113#define CLAMP_S32(x)(((x) <= (-2147483647 -1)) ? (-2147483647 -1) : (((x) >=
2147483647) ? 2147483647 : (mlib_s32)(x)))
\
114 (((x) <= MLIB_S32_MIN(-2147483647 -1)) ? MLIB_S32_MIN(-2147483647 -1) : (((x) >= MLIB_S32_MAX2147483647) ? MLIB_S32_MAX2147483647 : (mlib_s32)(x)))
115
116#else
117
118#define CLAMP_S32(x)(((x) <= (-2147483647 -1)) ? (-2147483647 -1) : (((x) >=
2147483647) ? 2147483647 : (mlib_s32)(x)))
((mlib_s32)(x))
119
120#endif /* MLIB_USE_FTOI_CLAMPING */
121
122/***************************************************************/
123#define D2I(x)((((x) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((x) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((x) -(1u << 31))))
CLAMP_S32((x) SAT_OFF)((((x) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((x) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((x) -(1u << 31))))
124
125/***************************************************************/
126#ifdef _NO_LONGLONG
127
128#define LOAD_BUFF(buff)*(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) |
((mlib_s64)sp[0])
\
129 buff[i ] = sp[0]; \
130 buff[i + 1] = sp[chan1]
131
132#else /* _NO_LONGLONG */
133
134#ifdef _LITTLE_ENDIAN1
135
136#define LOAD_BUFF(buff)*(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) |
((mlib_s64)sp[0])
\
137 *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])((mlib_s64)sp[0])
138
139#else /* _LITTLE_ENDIAN */
140
141#define LOAD_BUFF(buff)*(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) |
((mlib_s64)sp[0])
\
142 *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])((mlib_s64)sp[chan1])
143
144#endif /* _LITTLE_ENDIAN */
145#endif /* _NO_LONGLONG */
146
147/***************************************************************/
148typedef union {
149 mlib_d64 d64;
150 struct {
151 mlib_s32 i0;
152 mlib_s32 i1;
153 } i32s;
154} d64_2x32;
155
156/***************************************************************/
157#define GET_SRC_DST_PARAMETERS(type)hgt = mlib_ImageGetHeight(src); wid = mlib_ImageGetWidth(src)
; nchannel = mlib_ImageGetChannels(src); sll = mlib_ImageGetStride
(src) / sizeof(type); dll = mlib_ImageGetStride(dst) / sizeof
(type); adr_src = (type *)mlib_ImageGetData(src); adr_dst = (
type *)mlib_ImageGetData(dst)
\
158 hgt = mlib_ImageGetHeight(src); \
159 wid = mlib_ImageGetWidth(src); \
160 nchannel = mlib_ImageGetChannels(src); \
161 sll = mlib_ImageGetStride(src) / sizeof(type); \
162 dll = mlib_ImageGetStride(dst) / sizeof(type); \
163 adr_src = (type *)mlib_ImageGetData(src); \
164 adr_dst = (type *)mlib_ImageGetData(dst)
165
166/***************************************************************/
167#if IMG_TYPE1 == 1
168
169/*
170 * Test for the presence of any "1" bit in bits
171 8 to 31 of val. If present, then val is either
172 negative or >255. If over/underflows of 8 bits
173 are uncommon, then this technique can be a win,
174 since only a single test, rather than two, is
175 necessary to determine if clamping is needed.
176 On the other hand, if over/underflows are common,
177 it adds an extra test.
178*/
179#define CLAMP_STORE(dst, val)if (val & 0xffffff00) { if (val < 0) dst = 0; else dst
= (127*2 +1); } else { dst = (mlib_u8)val; }
\
180 if (val & 0xffffff00) { \
181 if (val < MLIB_U8_MIN0) \
182 dst = MLIB_U8_MIN0; \
183 else \
184 dst = MLIB_U8_MAX(127*2 +1); \
185 } else { \
186 dst = (mlib_u8)val; \
187 }
188
189#elif IMG_TYPE1 == 2
190
191#define CLAMP_STORE(dst, val)if (val & 0xffffff00) { if (val < 0) dst = 0; else dst
= (127*2 +1); } else { dst = (mlib_u8)val; }
\
192 if (val >= MLIB_S16_MAX32767) \
193 dst = MLIB_S16_MAX32767; \
194 else if (val <= MLIB_S16_MIN(-32767 -1)) \
195 dst = MLIB_S16_MIN(-32767 -1); \
196 else \
197 dst = (mlib_s16)val
198
199#elif IMG_TYPE1 == 3
200
201#define CLAMP_STORE(dst, val)if (val & 0xffffff00) { if (val < 0) dst = 0; else dst
= (127*2 +1); } else { dst = (mlib_u8)val; }
\
202 if (val >= MLIB_U16_MAX(32767 *2 +1)) \
203 dst = MLIB_U16_MAX(32767 *2 +1); \
204 else if (val <= MLIB_U16_MIN0) \
205 dst = MLIB_U16_MIN0; \
206 else \
207 dst = (mlib_u16)val
208
209#endif /* IMG_TYPE == 1 */
210
211/***************************************************************/
212#define MAX_KER7 7
213#define MAX_N15 15
214#define BUFF_SIZE1600 1600
215#define CACHE_SIZE(64*1024) (64*1024)
216
217static mlib_status mlib_ImageConv1xN_ext(mlib_image *dst,
218 const mlib_image *src,
219 const mlib_d64 *k,
220 mlib_s32 n,
221 mlib_s32 dy_t,
222 mlib_s32 dy_b,
223 mlib_s32 cmask)
224{
225 DTYPEmlib_u8 *adr_src, *sl;
226 DTYPEmlib_u8 *adr_dst, *dl, *dp;
227 FTYPEmlib_d64 buff[BUFF_SIZE1600];
228 FTYPEmlib_d64 *buffd;
229 FTYPEmlib_d64 *pbuff = buff;
230 const FTYPEmlib_d64 *pk;
231 FTYPEmlib_d64 k0, k1, k2, k3;
232 FTYPEmlib_d64 p0, p1, p2, p3, p4;
233 FTYPEmlib_d64 *sbuff;
234 mlib_s32 l, k_off, off, bsize;
235 mlib_s32 max_hsize, smax_hsize, shgt, hsize, kh;
236 mlib_s32 d0, d1, ii;
237 mlib_s32 wid, hgt, sll, dll;
238 mlib_s32 nchannel;
239 mlib_s32 i, j, c;
240 GET_SRC_DST_PARAMETERS(DTYPE)hgt = mlib_ImageGetHeight(src); wid = mlib_ImageGetWidth(src)
; nchannel = mlib_ImageGetChannels(src); sll = mlib_ImageGetStride
(src) / sizeof(mlib_u8); dll = mlib_ImageGetStride(dst) / sizeof
(mlib_u8); adr_src = (mlib_u8 *)mlib_ImageGetData(src); adr_dst
= (mlib_u8 *)mlib_ImageGetData(dst)
;
241
242 max_hsize = ((CACHE_SIZE(64*1024)/sizeof(DTYPEmlib_u8))/sll) - (n - 1);
243
244 if (max_hsize < 1) max_hsize = 1;
245 if (max_hsize > hgt) max_hsize = hgt;
246
247 shgt = hgt + (n - 1);
248 smax_hsize = max_hsize + (n - 1);
249
250 bsize = 2 * (smax_hsize + 1);
251
252 if (bsize > BUFF_SIZE1600) {
253 pbuff = mlib_malloc(sizeof(FTYPEmlib_d64)*bsize);
254
255 if (pbuff == NULL((void*)0)) return MLIB_FAILURE;
256 }
257
258 sbuff = pbuff;
259 buffd = sbuff + smax_hsize;
260
261 shgt -= (dy_t + dy_b);
262 k_off = 0;
263
264 for (l = 0; l < hgt; l += hsize) {
265 hsize = hgt - l;
266
267 if (hsize > max_hsize) hsize = max_hsize;
268
269 smax_hsize = hsize + (n - 1);
270
271 for (c = 0; c < nchannel; c++) {
272 if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
273
274 sl = adr_src + c;
275 dl = adr_dst + c;
276
277 for (i = 0; i < hsize; i++) buffd[i] = 0.0;
278
279 for (j = 0; j < wid; j++) {
280 FTYPEmlib_d64 *buff = sbuff;
281
282 for (i = k_off, ii = 0; (i < dy_t) && (ii < smax_hsize); i++, ii++) {
283 sbuff[i - k_off] = (FTYPEmlib_d64)sl[0];
284 }
285
286 for (; (i < shgt + dy_t) && (ii < smax_hsize); i++, ii++) {
287 sbuff[i - k_off] = (FTYPEmlib_d64)sl[(i - dy_t)*sll];
288 }
289
290 for (; (i < shgt + dy_t + dy_b) && (ii < smax_hsize); i++, ii++) {
291 sbuff[i - k_off] = (FTYPEmlib_d64)sl[(shgt - 1)*sll];
292 }
293
294 pk = k;
295
296 for (off = 0; off < (n - 4); off += 4) {
297
298 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
299 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
300
301 for (i = 0; i < hsize; i += 2) {
302 p0 = p2; p1 = p3; p2 = p4;
303
304 p3 = buff[i + 3]; p4 = buff[i + 4];
305
306 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
307 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
308 }
309
310 pk += 4;
311 buff += 4;
312 }
313
314 dp = dl;
315 kh = n - off;
316
317 if (kh == 4) {
318 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
319 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
320
321 for (i = 0; i <= (hsize - 2); i += 2) {
322 p0 = p2; p1 = p3; p2 = p4;
323
324 p3 = buff[i + 3]; p4 = buff[i + 4];
325
326 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ]) -(1u << 31
)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1
*k1 + p2*k2 + p3*k3 + buffd[i ]) -(1u << 31)) >= 2147483647
) ? 2147483647 : (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd
[i ]) -(1u << 31))))
;
327 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]) -(1u <<
31)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 +
p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]) -(1u << 31)) >=
2147483647) ? 2147483647 : (mlib_s32)((p1*k0 + p2*k1 + p3*k2
+ p4*k3 + buffd[i + 1]) -(1u << 31))))
;
328
329 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
330 dp[dll] = FROM_S32(d1)(((d1) >> 24) ^ 128);
331
332 buffd[i ] = 0.0;
333 buffd[i + 1] = 0.0;
334
335 dp += 2*dll;
336 }
337
338 if (i < hsize) {
339 p0 = p2; p1 = p3; p2 = p4;
340 p3 = buff[i + 3];
341 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i]) -(1u << 31
)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1
*k1 + p2*k2 + p3*k3 + buffd[i]) -(1u << 31)) >= 2147483647
) ? 2147483647 : (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd
[i]) -(1u << 31))))
;
342 dp[0] = FROM_S32(d0)(((d0) >> 24) ^ 128);
343 buffd[i] = 0.0;
344 }
345
346 } else if (kh == 3) {
347
348 p2 = buff[0]; p3 = buff[1];
349 k0 = pk[0]; k1 = pk[1]; k2 = pk[2];
350
351 for (i = 0; i <= (hsize - 2); i += 2) {
352 p0 = p2; p1 = p3;
353
354 p2 = buff[i + 2]; p3 = buff[i + 3];
355
356 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + buffd[i ]) -(1u << 31)) <=
(-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + p2
*k2 + buffd[i ]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + buffd[i ]) -(1u <<
31))))
;
357 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]) -(1u << 31)) <=
(-2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 + p2*k1 + p3
*k2 + buffd[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]) -(1u <<
31))))
;
358
359 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
360 dp[dll] = FROM_S32(d1)(((d1) >> 24) ^ 128);
361
362 buffd[i ] = 0.0;
363 buffd[i + 1] = 0.0;
364
365 dp += 2*dll;
366 }
367
368 if (i < hsize) {
369 p0 = p2; p1 = p3;
370 p2 = buff[i + 2];
371 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + buffd[i])((((p0*k0 + p1*k1 + p2*k2 + buffd[i]) -(1u << 31)) <=
(-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + p2
*k2 + buffd[i]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + buffd[i]) -(1u <<
31))))
;
372 dp[0] = FROM_S32(d0)(((d0) >> 24) ^ 128);
373
374 buffd[i] = 0.0;
375 }
376
377 } else if (kh == 2) {
378
379 p2 = buff[0];
380 k0 = pk[0]; k1 = pk[1];
381
382 for (i = 0; i <= (hsize - 2); i += 2) {
383 p0 = p2;
384
385 p1 = buff[i + 1]; p2 = buff[i + 2];
386
387 d0 = D2I(p0*k0 + p1*k1 + buffd[i ])((((p0*k0 + p1*k1 + buffd[i ]) -(1u << 31)) <= (-2147483647
-1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + buffd[i ]) -(1u
<< 31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p0
*k0 + p1*k1 + buffd[i ]) -(1u << 31))))
;
388 d1 = D2I(p1*k0 + p2*k1 + buffd[i + 1])((((p1*k0 + p2*k1 + buffd[i + 1]) -(1u << 31)) <= (-
2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 + p2*k1 + buffd
[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647 : (
mlib_s32)((p1*k0 + p2*k1 + buffd[i + 1]) -(1u << 31))))
;
389
390 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
391 dp[dll] = FROM_S32(d1)(((d1) >> 24) ^ 128);
392
393 buffd[i ] = 0.0;
394 buffd[i + 1] = 0.0;
395
396 dp += 2*dll;
397 }
398
399 if (i < hsize) {
400 p0 = p2;
401 p1 = buff[i + 1];
402 d0 = D2I(p0*k0 + p1*k1 + buffd[i])((((p0*k0 + p1*k1 + buffd[i]) -(1u << 31)) <= (-2147483647
-1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + buffd[i]) -(1u
<< 31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p0
*k0 + p1*k1 + buffd[i]) -(1u << 31))))
;
403 dp[0] = FROM_S32(d0)(((d0) >> 24) ^ 128);
404
405 buffd[i] = 0.0;
406 }
407
408 } else /* kh == 1 */{
409
410 k0 = pk[0];
411
412 for (i = 0; i <= (hsize - 2); i += 2) {
413 p0 = buff[i]; p1 = buff[i + 1];
414
415 d0 = D2I(p0*k0 + buffd[i ])((((p0*k0 + buffd[i ]) -(1u << 31)) <= (-2147483647 -
1)) ? (-2147483647 -1) : ((((p0*k0 + buffd[i ]) -(1u <<
31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p0*k0 + buffd
[i ]) -(1u << 31))))
;
416 d1 = D2I(p1*k0 + buffd[i + 1])((((p1*k0 + buffd[i + 1]) -(1u << 31)) <= (-2147483647
-1)) ? (-2147483647 -1) : ((((p1*k0 + buffd[i + 1]) -(1u <<
31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p1*k0 + buffd
[i + 1]) -(1u << 31))))
;
417
418 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
419 dp[dll] = FROM_S32(d1)(((d1) >> 24) ^ 128);
420
421 buffd[i ] = 0.0;
422 buffd[i + 1] = 0.0;
423
424 dp += 2*dll;
425 }
426
427 if (i < hsize) {
428 p0 = buff[i];
429 d0 = D2I(p0*k0 + buffd[i])((((p0*k0 + buffd[i]) -(1u << 31)) <= (-2147483647 -
1)) ? (-2147483647 -1) : ((((p0*k0 + buffd[i]) -(1u << 31
)) >= 2147483647) ? 2147483647 : (mlib_s32)((p0*k0 + buffd
[i]) -(1u << 31))))
;
430 dp[0] = FROM_S32(d0)(((d0) >> 24) ^ 128);
431
432 buffd[i] = 0.0;
433 }
434 }
435
436 /* next line */
437 sl += nchannel;
438 dl += nchannel;
439 }
440 }
441
442 k_off += max_hsize;
443 adr_dst += max_hsize*dll;
444 }
445
446 if (pbuff != buff) mlib_free(pbuff);
447
448 return MLIB_SUCCESS;
449}
450
451/***************************************************************/
452mlib_status CONV_FUNC_MxNmlib_c_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
453{
454 DTYPEmlib_u8 *adr_src, *sl, *sp = NULL((void*)0);
455 DTYPEmlib_u8 *adr_dst, *dl, *dp = NULL((void*)0);
456 FTYPEmlib_d64 buff[BUFF_SIZE1600], *buffs_arr[2*(MAX_N15 + 1)];
457 FTYPEmlib_d64 **buffs = buffs_arr, *buffd;
458 FTYPEmlib_d64 akernel[256], *k = akernel, fscale = DSCALE(1 << 24);
459 FTYPEmlib_d64 *pbuff = buff;
460 FTYPEmlib_d64 k0, k1, k2, k3, k4, k5, k6;
461 FTYPEmlib_d64 p0, p1, p2, p3, p4, p5, p6, p7;
462 mlib_s32 *buffi;
463 mlib_s32 mn, l, off, kw, bsize, buff_ind;
464 mlib_s32 d0, d1;
465 mlib_s32 wid, hgt, sll, dll;
466 mlib_s32 nchannel, chan1, chan2;
467 mlib_s32 i, j, c, swid;
468 d64_2x32 dd;
469 mlib_status status = MLIB_SUCCESS;
470
471 GET_SRC_DST_PARAMETERS(DTYPE)hgt = mlib_ImageGetHeight(src); wid = mlib_ImageGetWidth(src)
; nchannel = mlib_ImageGetChannels(src); sll = mlib_ImageGetStride
(src) / sizeof(mlib_u8); dll = mlib_ImageGetStride(dst) / sizeof
(mlib_u8); adr_src = (mlib_u8 *)mlib_ImageGetData(src); adr_dst
= (mlib_u8 *)mlib_ImageGetData(dst)
;
472
473 if (scale > 30) {
1
Assuming 'scale' is <= 30
2
Taking false branch
474 fscale *= 1.0/(1 << 30);
475 scale -= 30;
476 }
477
478 fscale /= (1 << scale);
479
480 mn = m*n;
481
482 if (mn > 256) {
3
Assuming 'mn' is <= 256
4
Taking false branch
483 k = mlib_malloc(mn*sizeof(mlib_d64));
484
485 if (k == NULL((void*)0)) return MLIB_FAILURE;
486 }
487
488 for (i = 0; i < mn; i++) {
5
Assuming 'i' is >= 'mn'
6
Loop condition is false. Execution continues on line 492
489 k[i] = kernel[i]*fscale;
490 }
491
492 if (m == 1) {
7
Assuming 'm' is not equal to 1
8
Taking false branch
493 status = mlib_ImageConv1xN_ext(dst, src, k, n, dy_t, dy_b, cmask);
494 FREE_AND_RETURN_STATUSif (pbuff != buff) mlib_free(pbuff); if (k != akernel) mlib_free
(k); return status
;
495 }
496
497 swid = wid + (m - 1);
498
499 bsize = (n + 3)*swid;
500
501 if ((bsize > BUFF_SIZE1600) || (n > MAX_N15)) {
9
Assuming 'bsize' is <= BUFF_SIZE
10
Assuming 'n' is <= MAX_N
11
Taking false branch
502 pbuff = mlib_malloc(sizeof(FTYPEmlib_d64)*bsize + sizeof(FTYPEmlib_d64 *)*2*(n + 1));
503
504 if (pbuff == NULL((void*)0)) {
505 status = MLIB_FAILURE;
506 FREE_AND_RETURN_STATUSif (pbuff != buff) mlib_free(pbuff); if (k != akernel) mlib_free
(k); return status
;
507 }
508 buffs = (FTYPEmlib_d64 **)(pbuff + bsize);
509 }
510
511 for (l = 0; l < (n + 1); l++) buffs[l] = pbuff + l*swid;
12
Assuming the condition is true
13
Loop condition is true. Entering loop body
14
Assuming the condition is true
15
Loop condition is true. Entering loop body
16
Assuming the condition is false
17
Loop condition is false. Execution continues on line 512
512 for (l = 0; l < (n + 1); l++) buffs[l + (n + 1)] = buffs[l];
18
Loop condition is true. Entering loop body
19
Loop condition is true. Entering loop body
20
Loop condition is false. Execution continues on line 513
513 buffd = buffs[n] + swid;
514 buffi = (mlib_s32*)(buffd + swid);
515
516 chan1 = nchannel;
517 chan2 = chan1 + chan1;
518
519 swid -= (dx_l + dx_r);
520
521 for (c = 0; c < nchannel; c++) {
21
Assuming 'c' is < 'nchannel'
22
Loop condition is true. Entering loop body
522 if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
23
Assuming the condition is false
24
Taking false branch
523
524 sl = adr_src + c;
525 dl = adr_dst + c;
526
527 for (l = 0; l < n; l++) {
25
Loop condition is true. Entering loop body
33
Loop condition is false. Execution continues on line 545
528 FTYPEmlib_d64 *buff = buffs[l];
529
530 for (i = 0; i < dx_l; i++) {
26
Assuming 'i' is >= 'dx_l'
27
Loop condition is false. Execution continues on line 534
531 buff[i] = (FTYPEmlib_d64)sl[0];
532 }
533
534 for (i = 0; i < swid; i++) {
28
Assuming 'i' is >= 'swid'
29
Loop condition is false. Execution continues on line 538
535 buff[i + dx_l] = (FTYPEmlib_d64)sl[i*chan1];
536 }
537
538 for (i = 0; i < dx_r; i++) {
30
Assuming 'i' is >= 'dx_r'
31
Loop condition is false. Execution continues on line 542
539 buff[swid + dx_l + i] = buff[swid + dx_l - 1];
540 }
541
542 if ((l >= dy_t) && (l < hgt + n - dy_b - 2)) sl += sll;
32
Assuming 'l' is < 'dy_t'
543 }
544
545 buff_ind = 0;
546
547 for (i = 0; i < wid; i++) buffd[i] = 0.0;
34
Assuming 'i' is >= 'wid'
35
Loop condition is false. Execution continues on line 549
548
549 for (j = 0; j < hgt; j++) {
36
Assuming 'j' is < 'hgt'
37
Loop condition is true. Entering loop body
550 FTYPEmlib_d64 **buffc = buffs + buff_ind;
551 FTYPEmlib_d64 *buffn = buffc[n];
552 FTYPEmlib_d64 *pk = k;
553
554 for (l = 0; l < n; l++) {
38
Loop condition is true. Entering loop body
555 FTYPEmlib_d64 *buff_l = buffc[l];
556
557 for (off = 0; off < m;) {
39
Assuming 'off' is < 'm'
40
Loop condition is true. Entering loop body
558 FTYPEmlib_d64 *buff = buff_l + off;
559
560 kw = m - off;
561
562 if (kw > 2*MAX_KER7) kw = MAX_KER7; else
41
Assuming the condition is false
42
Taking false branch
563 if (kw > MAX_KER7) kw = kw/2;
43
Assuming 'kw' is <= MAX_KER
44
Taking false branch
564 off += kw;
565
566 sp = sl;
567 dp = dl;
568
569 if (kw == 7) {
45
Assuming 'kw' is not equal to 7
46
Taking false branch
570
571 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
572 p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
573
574 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
575 k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
576
577 if (l < (n - 1) || off < m) {
578 for (i = 0; i <= (wid - 2); i += 2) {
579 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
580
581 p6 = buff[i + 6]; p7 = buff[i + 7];
582
583 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
584 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
585 }
586
587 } else {
588 for (i = 0; i <= (wid - 2); i += 2) {
589 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
590
591 p6 = buff[i + 6]; p7 = buff[i + 7];
592
593 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
594
595 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
596 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
597 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
598
599 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd
[i ]) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6
*k6 + buffd[i ]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 +
p6*k6 + buffd[i ]) -(1u << 31))))
;
600 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd
[i + 1]) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7
*k6 + buffd[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 +
p7*k6 + buffd[i + 1]) -(1u << 31))))
;
601
602 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
603 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
604
605 buffd[i ] = 0.0;
606 buffd[i + 1] = 0.0;
607
608 sp += chan2;
609 dp += chan2;
610 }
611 }
612
613 } else if (kw == 6) {
47
Assuming 'kw' is not equal to 6
48
Taking false branch
614
615 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
616 p5 = buff[3]; p6 = buff[4];
617
618 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
619 k4 = pk[4]; k5 = pk[5];
620
621 if (l < (n - 1) || off < m) {
622 for (i = 0; i <= (wid - 2); i += 2) {
623 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
624
625 p5 = buff[i + 5]; p6 = buff[i + 6];
626
627 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
628 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
629 }
630
631 } else {
632 for (i = 0; i <= (wid - 2); i += 2) {
633 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
634
635 p5 = buff[i + 5]; p6 = buff[i + 6];
636
637 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
638
639 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
640 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
641 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
642
643 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i ]
) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647 -
1) : ((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd
[i ]) -(1u << 31)) >= 2147483647) ? 2147483647 : (mlib_s32
)((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i ])
-(1u << 31))))
;
644 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i +
1]) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd
[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647 : (
mlib_s32)((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd
[i + 1]) -(1u << 31))))
;
645
646 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
647 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
648
649 buffd[i ] = 0.0;
650 buffd[i + 1] = 0.0;
651
652 sp += chan2;
653 dp += chan2;
654 }
655 }
656
657 } else if (kw == 5) {
49
Assuming 'kw' is not equal to 5
50
Taking false branch
658
659 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
660 p5 = buff[3];
661
662 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
663 k4 = pk[4];
664
665 if (l < (n - 1) || off < m) {
666 for (i = 0; i <= (wid - 2); i += 2) {
667 p0 = p2; p1 = p3; p2 = p4; p3 = p5;
668
669 p4 = buff[i + 4]; p5 = buff[i + 5];
670
671 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
672 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
673 }
674
675 } else {
676 for (i = 0; i <= (wid - 2); i += 2) {
677 p0 = p2; p1 = p3; p2 = p4; p3 = p5;
678
679 p4 = buff[i + 4]; p5 = buff[i + 5];
680
681 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
682
683 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
684 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
685 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
686
687 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i ]) -(1u <<
31)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 +
p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i ]) -(1u << 31)
) >= 2147483647) ? 2147483647 : (mlib_s32)((p0*k0 + p1*k1 +
p2*k2 + p3*k3 + p4*k4 + buffd[i ]) -(1u << 31))))
;
688 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]) -(1u
<< 31)) <= (-2147483647 -1)) ? (-2147483647 -1) : (
(((p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]) -(1u
<< 31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p1
*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]) -(1u <<
31))))
;
689
690 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
691 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
692
693 buffd[i ] = 0.0;
694 buffd[i + 1] = 0.0;
695
696 sp += chan2;
697 dp += chan2;
698 }
699 }
700
701 } else if (kw == 4) {
51
Assuming 'kw' is not equal to 4
52
Taking false branch
702
703 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
704
705 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
706
707 if (l < (n - 1) || off < m) {
708 for (i = 0; i <= (wid - 2); i += 2) {
709 p0 = p2; p1 = p3; p2 = p4;
710
711 p3 = buff[i + 3]; p4 = buff[i + 4];
712
713 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
714 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
715 }
716
717 } else {
718 for (i = 0; i <= (wid - 2); i += 2) {
719 p0 = p2; p1 = p3; p2 = p4;
720
721 p3 = buff[i + 3]; p4 = buff[i + 4];
722
723 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
724
725 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
726 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
727 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
728
729 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ]) -(1u << 31
)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1
*k1 + p2*k2 + p3*k3 + buffd[i ]) -(1u << 31)) >= 2147483647
) ? 2147483647 : (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd
[i ]) -(1u << 31))))
;
730 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]) -(1u <<
31)) <= (-2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 +
p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]) -(1u << 31)) >=
2147483647) ? 2147483647 : (mlib_s32)((p1*k0 + p2*k1 + p3*k2
+ p4*k3 + buffd[i + 1]) -(1u << 31))))
;
731
732 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
733 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
734
735 buffd[i ] = 0.0;
736 buffd[i + 1] = 0.0;
737
738 sp += chan2;
739 dp += chan2;
740 }
741 }
742
743 } else if (kw == 3) {
53
Assuming 'kw' is not equal to 3
54
Taking false branch
744
745 p2 = buff[0]; p3 = buff[1];
746 k0 = pk[0]; k1 = pk[1]; k2 = pk[2];
747
748 if (l < (n - 1) || off < m) {
749 for (i = 0; i <= (wid - 2); i += 2) {
750 p0 = p2; p1 = p3;
751
752 p2 = buff[i + 2]; p3 = buff[i + 3];
753
754 buffd[i ] += p0*k0 + p1*k1 + p2*k2;
755 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2;
756 }
757
758 } else {
759 for (i = 0; i <= (wid - 2); i += 2) {
760 p0 = p2; p1 = p3;
761
762 p2 = buff[i + 2]; p3 = buff[i + 3];
763
764 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
765
766 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
767 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
768 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
769
770 d0 = D2I(p0*k0 + p1*k1 + p2*k2 + buffd[i ])((((p0*k0 + p1*k1 + p2*k2 + buffd[i ]) -(1u << 31)) <=
(-2147483647 -1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + p2
*k2 + buffd[i ]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p0*k0 + p1*k1 + p2*k2 + buffd[i ]) -(1u <<
31))))
;
771 d1 = D2I(p1*k0 + p2*k1 + p3*k2 + buffd[i + 1])((((p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]) -(1u << 31)) <=
(-2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 + p2*k1 + p3
*k2 + buffd[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]) -(1u <<
31))))
;
772
773 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
774 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
775
776 buffd[i ] = 0.0;
777 buffd[i + 1] = 0.0;
778
779 sp += chan2;
780 dp += chan2;
781 }
782 }
783
784 } else /* if (kw == 2) */ {
785
786 p2 = buff[0];
55
Assigned value is garbage or undefined
787 k0 = pk[0]; k1 = pk[1];
788
789 if (l < (n - 1) || off < m) {
790 for (i = 0; i <= (wid - 2); i += 2) {
791 p0 = p2;
792
793 p1 = buff[i + 1]; p2 = buff[i + 2];
794
795 buffd[i ] += p0*k0 + p1*k1;
796 buffd[i + 1] += p1*k0 + p2*k1;
797 }
798
799 } else {
800 for (i = 0; i <= (wid - 2); i += 2) {
801 p0 = p2;
802
803 p1 = buff[i + 1]; p2 = buff[i + 2];
804
805 LOAD_BUFF(buffi)*(mlib_s64*)(buffi + i) = (((mlib_s64)sp[chan1]) << 32)
| ((mlib_s64)sp[0])
;
806
807 dd.d64 = *(FTYPEmlib_d64 *)(buffi + i);
808 buffn[i + dx_l ] = (FTYPEmlib_d64)dd.i32s.i0;
809 buffn[i + dx_l + 1] = (FTYPEmlib_d64)dd.i32s.i1;
810
811 d0 = D2I(p0*k0 + p1*k1 + buffd[i ])((((p0*k0 + p1*k1 + buffd[i ]) -(1u << 31)) <= (-2147483647
-1)) ? (-2147483647 -1) : ((((p0*k0 + p1*k1 + buffd[i ]) -(1u
<< 31)) >= 2147483647) ? 2147483647 : (mlib_s32)((p0
*k0 + p1*k1 + buffd[i ]) -(1u << 31))))
;
812 d1 = D2I(p1*k0 + p2*k1 + buffd[i + 1])((((p1*k0 + p2*k1 + buffd[i + 1]) -(1u << 31)) <= (-
2147483647 -1)) ? (-2147483647 -1) : ((((p1*k0 + p2*k1 + buffd
[i + 1]) -(1u << 31)) >= 2147483647) ? 2147483647 : (
mlib_s32)((p1*k0 + p2*k1 + buffd[i + 1]) -(1u << 31))))
;
813
814 dp[0 ] = FROM_S32(d0)(((d0) >> 24) ^ 128);
815 dp[chan1] = FROM_S32(d1)(((d1) >> 24) ^ 128);
816
817 buffd[i ] = 0.0;
818 buffd[i + 1] = 0.0;
819
820 sp += chan2;
821 dp += chan2;
822 }
823 }
824 }
825
826 pk += kw;
827 }
828 }
829
830 /* last pixels */
831 for (; i < wid; i++) {
832 FTYPEmlib_d64 *pk = k, s = 0;
833 mlib_s32 x, d0;
834
835 for (l = 0; l < n; l++) {
836 FTYPEmlib_d64 *buff = buffc[l] + i;
837
838 for (x = 0; x < m; x++) s += buff[x] * (*pk++);
839 }
840
841 d0 = D2I(s)((((s) -(1u << 31)) <= (-2147483647 -1)) ? (-2147483647
-1) : ((((s) -(1u << 31)) >= 2147483647) ? 2147483647
: (mlib_s32)((s) -(1u << 31))))
;
842 dp[0] = FROM_S32(d0)(((d0) >> 24) ^ 128);
843
844 buffn[i + dx_l] = (FTYPEmlib_d64)sp[0];
845
846 sp += chan1;
847 dp += chan1;
848 }
849
850 for (; i < swid; i++) {
851 buffn[i + dx_l] = (FTYPEmlib_d64)sp[0];
852 sp += chan1;
853 }
854
855 for (i = 0; i < dx_l; i++) buffn[i] = buffn[dx_l];
856 for (i = 0; i < dx_r; i++) buffn[swid + dx_l + i] = buffn[swid + dx_l - 1];
857
858 /* next line */
859
860 if (j < hgt - dy_b - 2) sl += sll;
861 dl += dll;
862
863 buff_ind++;
864
865 if (buff_ind >= n + 1) buff_ind = 0;
866 }
867 }
868
869 FREE_AND_RETURN_STATUSif (pbuff != buff) mlib_free(pbuff); if (k != akernel) mlib_free
(k); return status
;
870}
871
872/***************************************************************/
873/* for x86, using integer multiplies is faster */
874
875#define STORE_RES(res, x)x >>= shift2; if (x & 0xffffff00) { if (x < 0) res
= 0; else res = (127*2 +1); } else { res = (mlib_u8)x; }
\
876 x >>= shift2; \
877 CLAMP_STORE(res, x)if (x & 0xffffff00) { if (x < 0) res = 0; else res = (
127*2 +1); } else { res = (mlib_u8)x; }
878
879mlib_status CONV_FUNC_MxN_Imlib_i_convMxNext_u8(mlib_image *dst, const mlib_image *src, const
mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dx_l, mlib_s32
dx_r, mlib_s32 dy_t, mlib_s32 dy_b, mlib_s32 scale, mlib_s32
cmask)
880{
881 DTYPEmlib_u8 *adr_src, *sl, *sp = NULL((void*)0);
882 DTYPEmlib_u8 *adr_dst, *dl, *dp = NULL((void*)0);
883 mlib_s32 buff[BUFF_SIZE1600], *buffs_arr[2*(MAX_N15 + 1)];
884 mlib_s32 *pbuff = buff;
885 mlib_s32 **buffs = buffs_arr, *buffd;
886 mlib_s32 l, off, kw, bsize, buff_ind;
887 mlib_s32 d0, d1, shift1, shift2;
888 mlib_s32 k0, k1, k2, k3, k4, k5, k6;
889 mlib_s32 p0, p1, p2, p3, p4, p5, p6, p7;
890 mlib_s32 wid, hgt, sll, dll;
891 mlib_s32 nchannel, chan1;
892 mlib_s32 i, j, c, swid;
893 mlib_s32 chan2;
894 mlib_s32 k_locl[MAX_N15*MAX_N15], *k = k_locl;
895 GET_SRC_DST_PARAMETERS(DTYPE)hgt = mlib_ImageGetHeight(src); wid = mlib_ImageGetWidth(src)
; nchannel = mlib_ImageGetChannels(src); sll = mlib_ImageGetStride
(src) / sizeof(mlib_u8); dll = mlib_ImageGetStride(dst) / sizeof
(mlib_u8); adr_src = (mlib_u8 *)mlib_ImageGetData(src); adr_dst
= (mlib_u8 *)mlib_ImageGetData(dst)
;
896
897#if IMG_TYPE1 != 1
898 shift1 = 16;
899#else
900 shift1 = 8;
901#endif /* IMG_TYPE != 1 */
902 shift2 = scale - shift1;
903
904 chan1 = nchannel;
905 chan2 = chan1 + chan1;
906
907 swid = wid + (m - 1);
908
909 bsize = (n + 2)*swid;
910
911 if ((bsize > BUFF_SIZE1600) || (n > MAX_N15)) {
912 pbuff = mlib_malloc(sizeof(mlib_s32)*bsize + sizeof(mlib_s32 *)*2*(n + 1));
913
914 if (pbuff == NULL((void*)0)) return MLIB_FAILURE;
915 buffs = (mlib_s32 **)(pbuff + bsize);
916 }
917
918 for (l = 0; l < (n + 1); l++) buffs[l] = pbuff + l*swid;
919 for (l = 0; l < (n + 1); l++) buffs[l + (n + 1)] = buffs[l];
920 buffd = buffs[n] + swid;
921
922 if (m*n > MAX_N15*MAX_N15) {
923 k = mlib_malloc(sizeof(mlib_s32)*(m*n));
924
925 if (k == NULL((void*)0)) {
926 if (pbuff != buff) mlib_free(pbuff);
927 return MLIB_FAILURE;
928 }
929 }
930
931 for (i = 0; i < m*n; i++) {
932 k[i] = kernel[i] >> shift1;
933 }
934
935 swid -= (dx_l + dx_r);
936
937 for (c = 0; c < nchannel; c++) {
938 if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
939
940 sl = adr_src + c;
941 dl = adr_dst + c;
942
943 for (l = 0; l < n; l++) {
944 mlib_s32 *buff = buffs[l];
945
946 for (i = 0; i < dx_l; i++) {
947 buff[i] = (mlib_s32)sl[0];
948 }
949
950 for (i = 0; i < swid; i++) {
951 buff[i + dx_l] = (mlib_s32)sl[i*chan1];
952 }
953
954 for (i = 0; i < dx_r; i++) {
955 buff[swid + dx_l + i] = buff[swid + dx_l - 1];
956 }
957
958 if ((l >= dy_t) && (l < hgt + n - dy_b - 2)) sl += sll;
959 }
960
961 buff_ind = 0;
962
963 for (i = 0; i < wid; i++) buffd[i] = 0;
964
965 for (j = 0; j < hgt; j++) {
966 mlib_s32 **buffc = buffs + buff_ind;
967 mlib_s32 *buffn = buffc[n];
968 mlib_s32 *pk = k;
969
970 for (l = 0; l < n; l++) {
971 mlib_s32 *buff_l = buffc[l];
972
973 for (off = 0; off < m;) {
974 mlib_s32 *buff = buff_l + off;
975
976 sp = sl;
977 dp = dl;
978
979 kw = m - off;
980
981 if (kw > 2*MAX_KER7) kw = MAX_KER7; else
982 if (kw > MAX_KER7) kw = kw/2;
983 off += kw;
984
985 if (kw == 7) {
986
987 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
988 p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
989
990 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
991 k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
992
993 if (l < (n - 1) || off < m) {
994 for (i = 0; i <= (wid - 2); i += 2) {
995 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
996
997 p6 = buff[i + 6]; p7 = buff[i + 7];
998
999 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
1000 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
1001 }
1002
1003 } else {
1004 for (i = 0; i <= (wid - 2); i += 2) {
1005 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
1006
1007 p6 = buff[i + 6]; p7 = buff[i + 7];
1008
1009 buffn[i + dx_l ] = (mlib_s32)sp[0];
1010 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1011
1012 d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i ]);
1013 d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]);
1014
1015 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1016 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1017
1018 buffd[i ] = 0;
1019 buffd[i + 1] = 0;
1020
1021 sp += chan2;
1022 dp += chan2;
1023 }
1024 }
1025
1026 } else if (kw == 6) {
1027
1028 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
1029 p5 = buff[3]; p6 = buff[4];
1030
1031 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
1032 k4 = pk[4]; k5 = pk[5];
1033
1034 if (l < (n - 1) || off < m) {
1035 for (i = 0; i <= (wid - 2); i += 2) {
1036 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
1037
1038 p5 = buff[i + 5]; p6 = buff[i + 6];
1039
1040 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
1041 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
1042 }
1043
1044 } else {
1045 for (i = 0; i <= (wid - 2); i += 2) {
1046 p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
1047
1048 p5 = buff[i + 5]; p6 = buff[i + 6];
1049
1050 buffn[i + dx_l ] = (mlib_s32)sp[0];
1051 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1052
1053 d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i ]);
1054 d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1]);
1055
1056 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1057 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1058
1059 buffd[i ] = 0;
1060 buffd[i + 1] = 0;
1061
1062 sp += chan2;
1063 dp += chan2;
1064 }
1065 }
1066
1067 } else if (kw == 5) {
1068
1069 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
1070 p5 = buff[3];
1071
1072 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
1073 k4 = pk[4];
1074
1075 if (l < (n - 1) || off < m) {
1076 for (i = 0; i <= (wid - 2); i += 2) {
1077 p0 = p2; p1 = p3; p2 = p4; p3 = p5;
1078
1079 p4 = buff[i + 4]; p5 = buff[i + 5];
1080
1081 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
1082 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
1083 }
1084
1085 } else {
1086 for (i = 0; i <= (wid - 2); i += 2) {
1087 p0 = p2; p1 = p3; p2 = p4; p3 = p5;
1088
1089 p4 = buff[i + 4]; p5 = buff[i + 5];
1090
1091 buffn[i + dx_l ] = (mlib_s32)sp[0];
1092 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1093
1094 d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i ]);
1095 d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]);
1096
1097 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1098 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1099
1100 buffd[i ] = 0;
1101 buffd[i + 1] = 0;
1102
1103 sp += chan2;
1104 dp += chan2;
1105 }
1106 }
1107
1108 } else if (kw == 4) {
1109
1110 p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
1111
1112 k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
1113
1114 if (l < (n - 1) || off < m) {
1115 for (i = 0; i <= (wid - 2); i += 2) {
1116 p0 = p2; p1 = p3; p2 = p4;
1117
1118 p3 = buff[i + 3]; p4 = buff[i + 4];
1119
1120 buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
1121 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
1122 }
1123
1124 } else {
1125 for (i = 0; i <= (wid - 2); i += 2) {
1126 p0 = p2; p1 = p3; p2 = p4;
1127
1128 p3 = buff[i + 3]; p4 = buff[i + 4];
1129
1130 buffn[i + dx_l ] = (mlib_s32)sp[0];
1131 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1132
1133 d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ]);
1134 d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]);
1135
1136 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1137 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1138
1139 buffd[i ] = 0;
1140 buffd[i + 1] = 0;
1141
1142 sp += chan2;
1143 dp += chan2;
1144 }
1145 }
1146
1147 } else if (kw == 3) {
1148
1149 p2 = buff[0]; p3 = buff[1];
1150 k0 = pk[0]; k1 = pk[1]; k2 = pk[2];
1151
1152 if (l < (n - 1) || off < m) {
1153 for (i = 0; i <= (wid - 2); i += 2) {
1154 p0 = p2; p1 = p3;
1155
1156 p2 = buff[i + 2]; p3 = buff[i + 3];
1157
1158 buffd[i ] += p0*k0 + p1*k1 + p2*k2;
1159 buffd[i + 1] += p1*k0 + p2*k1 + p3*k2;
1160 }
1161
1162 } else {
1163 for (i = 0; i <= (wid - 2); i += 2) {
1164 p0 = p2; p1 = p3;
1165
1166 p2 = buff[i + 2]; p3 = buff[i + 3];
1167
1168 buffn[i + dx_l ] = (mlib_s32)sp[0];
1169 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1170
1171 d0 = (p0*k0 + p1*k1 + p2*k2 + buffd[i ]);
1172 d1 = (p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]);
1173
1174 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1175 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1176
1177 buffd[i ] = 0;
1178 buffd[i + 1] = 0;
1179
1180 sp += chan2;
1181 dp += chan2;
1182 }
1183 }
1184
1185 } else if (kw == 2) {
1186
1187 p2 = buff[0];
1188 k0 = pk[0]; k1 = pk[1];
1189
1190 if (l < (n - 1) || off < m) {
1191 for (i = 0; i <= (wid - 2); i += 2) {
1192 p0 = p2;
1193
1194 p1 = buff[i + 1]; p2 = buff[i + 2];
1195
1196 buffd[i ] += p0*k0 + p1*k1;
1197 buffd[i + 1] += p1*k0 + p2*k1;
1198 }
1199
1200 } else {
1201 for (i = 0; i <= (wid - 2); i += 2) {
1202 p0 = p2;
1203
1204 p1 = buff[i + 1]; p2 = buff[i + 2];
1205
1206 buffn[i + dx_l ] = (mlib_s32)sp[0];
1207 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1208
1209 d0 = (p0*k0 + p1*k1 + buffd[i ]);
1210 d1 = (p1*k0 + p2*k1 + buffd[i + 1]);
1211
1212 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1213 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1214
1215 buffd[i ] = 0;
1216 buffd[i + 1] = 0;
1217
1218 sp += chan2;
1219 dp += chan2;
1220 }
1221 }
1222
1223 } else /* kw == 1 */{
1224
1225 k0 = pk[0];
1226
1227 if (l < (n - 1) || off < m) {
1228 for (i = 0; i <= (wid - 2); i += 2) {
1229 p0 = buff[i]; p1 = buff[i + 1];
1230
1231 buffd[i ] += p0*k0;
1232 buffd[i + 1] += p1*k0;
1233 }
1234
1235 } else {
1236 for (i = 0; i <= (wid - 2); i += 2) {
1237 p0 = buff[i]; p1 = buff[i + 1];
1238
1239 buffn[i + dx_l ] = (mlib_s32)sp[0];
1240 buffn[i + dx_l + 1] = (mlib_s32)sp[chan1];
1241
1242 d0 = (p0*k0 + buffd[i ]);
1243 d1 = (p1*k0 + buffd[i + 1]);
1244
1245 STORE_RES(dp[0 ], d0)d0 >>= shift2; if (d0 & 0xffffff00) { if (d0 < 0
) dp[0 ] = 0; else dp[0 ] = (127*2 +1); } else { dp[0 ] = (mlib_u8
)d0; }
;
1246 STORE_RES(dp[chan1], d1)d1 >>= shift2; if (d1 & 0xffffff00) { if (d1 < 0
) dp[chan1] = 0; else dp[chan1] = (127*2 +1); } else { dp[chan1
] = (mlib_u8)d1; }
;
1247
1248 buffd[i ] = 0;
1249 buffd[i + 1] = 0;
1250
1251 sp += chan2;
1252 dp += chan2;
1253 }
1254 }
1255 }
1256
1257 pk += kw;
1258 }
1259 }
1260
1261 /* last pixels */
1262 for (; i < wid; i++) {
1263 mlib_s32 *pk = k, x, s = 0;
1264
1265 for (l = 0; l < n; l++) {
1266 mlib_s32 *buff = buffc[l] + i;
1267
1268 for (x = 0; x < m; x++) s += buff[x] * (*pk++);
1269 }
1270
1271 STORE_RES(dp[0], s)s >>= shift2; if (s & 0xffffff00) { if (s < 0) dp
[0] = 0; else dp[0] = (127*2 +1); } else { dp[0] = (mlib_u8)s
; }
;
1272
1273 buffn[i + dx_l] = (mlib_s32)sp[0];
1274
1275 sp += chan1;
1276 dp += chan1;
1277 }
1278
1279 for (; i < swid; i++) {
1280 buffn[i + dx_l] = (mlib_s32)sp[0];
1281 sp += chan1;
1282 }
1283
1284 for (i = 0; i < dx_l; i++) buffn[i] = buffn[dx_l];
1285 for (i = 0; i < dx_r; i++) buffn[swid + dx_l + i] = buffn[swid + dx_l - 1];
1286
1287 /* next line */
1288
1289 if (j < hgt - dy_b - 2) sl += sll;
1290 dl += dll;
1291
1292 buff_ind++;
1293
1294 if (buff_ind >= n + 1) buff_ind = 0;
1295 }
1296 }
1297
1298 if (pbuff != buff) mlib_free(pbuff);
1299 if (k != k_locl) mlib_free(k);
1300
1301 return MLIB_SUCCESS;
1302}
1303
1304/***************************************************************/