mlib_status CONV_FUNC(MxN)(mlib_image *dst, const mlib_image *src, const mlib_s32 *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dm, mlib_s32 dn, mlib_s32 scale, mlib_s32 cmask) { FTYPE buff[BUFF_SIZE], *buffs_arr[2*(MAX_N + 1)]; FTYPE **buffs = buffs_arr, *buffd; FTYPE akernel[256], *k = akernel, fscale = DSCALE; mlib_s32 mn, l, off, kw, bsize, buff_ind; mlib_s32 d0, d1; FTYPE k0, k1, k2, k3, k4, k5, k6; FTYPE p0, p1, p2, p3, p4, p5, p6, p7; d64_2x32 dd; DEF_VARS(DTYPE); mlib_s32 chan2; mlib_s32 *buffo, *buffi; mlib_status status = MLIB_SUCCESS; GET_SRC_DST_PARAMETERS(DTYPE); if (scale > 30) { fscale *= 1.0/(1 << 30); scale -= 30; } fscale /= (1 << scale); mn = m*n; if (mn > 256) { k = mlib_malloc(mn*sizeof(mlib_d64)); if (k == NULL) return MLIB_FAILURE; } for (i = 0; i < mn; i++) { k[i] = kernel[i]*fscale; } if (m == 1) { status = mlib_ImageConv1xN(dst, src, k, n, dn, cmask); FREE_AND_RETURN_STATUS; } bsize = (n + 3)*wid; if ((bsize > BUFF_SIZE) || (n > MAX_N)) { pbuff = mlib_malloc(sizeof(FTYPE)*bsize + sizeof(FTYPE *)*2*(n + 1)); if (pbuff == NULL) { status = MLIB_FAILURE; FREE_AND_RETURN_STATUS; } buffs = (FTYPE **)(pbuff + bsize); } for (l = 0; l < (n + 1); l++) buffs[l] = pbuff + l*wid; for (l = 0; l < (n + 1); l++) buffs[l + (n + 1)] = buffs[l]; buffd = buffs[n] + wid; buffo = (mlib_s32*)(buffd + wid); buffi = buffo + (wid &~ 1); chan1 = nchannel; chan2 = chan1 + chan1; wid -= (m - 1); hgt -= (n - 1); adr_dst += dn*dll + dm*nchannel; for (c = 0; c < nchannel; c++) { if (!(cmask & (1 << (chan1 - 1 - c)))) continue; sl = adr_src + c; dl = adr_dst + c; for (l = 0; l < n; l++) { FTYPE *buff = buffs[l]; #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < wid + (m - 1); i++) { buff[i] = (FTYPE)sl[i*chan1]; } sl += sll; } buff_ind = 0; #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < wid; i++) buffd[i] = 0.0; for (j = 0; j < hgt; j++) { FTYPE **buffc = buffs + buff_ind; FTYPE *buffn = buffc[n]; FTYPE *pk = k; for (l = 0; l < n; l++) { FTYPE *buff_l = buffc[l]; for (off = 0; off < m;) { FTYPE *buff = buff_l + off; kw = m - off; if (kw > 2*MAX_KER) kw = MAX_KER; else if (kw > MAX_KER) kw = kw/2; off += kw; sp = sl; dp = dl; p2 = buff[0]; p3 = buff[1]; p4 = buff[2]; p5 = buff[3]; p6 = buff[4]; p7 = buff[5]; k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3]; k4 = pk[4]; k5 = pk[5]; k6 = pk[6]; pk += kw; if (kw == 7) { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7; p6 = buff[i + 6]; p7 = buff[i + 7]; buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6; buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7; p6 = buff[i + 6]; p7 = buff[i + 7]; LOAD_BUFF(buffi); dd.d64 = *(FTYPE *)(buffi + i); buffn[i ] = (FTYPE)dd.i32s.i0; buffn[i + 1] = (FTYPE)dd.i32s.i1; d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } else if (kw == 6) { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = buff[i + 5]; p6 = buff[i + 6]; buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5; buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = buff[i + 5]; p6 = buff[i + 6]; buffn[i ] = (FTYPE)sp[0]; buffn[i + 1] = (FTYPE)sp[chan1]; d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } else if (kw == 5) { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = buff[i + 4]; p5 = buff[i + 5]; buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4; buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = buff[i + 4]; p5 = buff[i + 5]; buffn[i ] = (FTYPE)sp[0]; buffn[i + 1] = (FTYPE)sp[chan1]; d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } else if (kw == 4) { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = buff[i + 3]; p4 = buff[i + 4]; buffd[i ] += p0*k0 + p1*k1 + p2*k2 + p3*k3; buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = p4; p3 = buff[i + 3]; p4 = buff[i + 4]; buffn[i ] = (FTYPE)sp[0]; buffn[i + 1] = (FTYPE)sp[chan1]; d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } else if (kw == 3) { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = buff[i + 2]; p3 = buff[i + 3]; buffd[i ] += p0*k0 + p1*k1 + p2*k2; buffd[i + 1] += p1*k0 + p2*k1 + p3*k2; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = p3; p2 = buff[i + 2]; p3 = buff[i + 3]; buffn[i ] = (FTYPE)sp[0]; buffn[i + 1] = (FTYPE)sp[chan1]; d0 = D2I(p0*k0 + p1*k1 + p2*k2 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } else /*if (kw == 2)*/ { if (l < (n - 1) || off < m) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = buff[i + 1]; p2 = buff[i + 2]; buffd[i ] += p0*k0 + p1*k1; buffd[i + 1] += p1*k0 + p2*k1; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i <= (wid - 2); i += 2) { p0 = p2; p1 = buff[i + 1]; p2 = buff[i + 2]; buffn[i ] = (FTYPE)sp[0]; buffn[i + 1] = (FTYPE)sp[chan1]; d0 = D2I(p0*k0 + p1*k1 + buffd[i ]); d1 = D2I(p1*k0 + p2*k1 + buffd[i + 1]); dp[0 ] = FROM_S32(d0); dp[chan1] = FROM_S32(d1); buffd[i ] = 0.0; buffd[i + 1] = 0.0; sp += chan2; dp += chan2; } } } } } /* last pixels */ for (; i < wid; i++) { FTYPE *pk = k, s = 0; mlib_s32 x, d0; for (l = 0; l < n; l++) { FTYPE *buff = buffc[l] + i; for (x = 0; x < m; x++) s += buff[x] * (*pk++); } d0 = D2I(s); dp[0] = FROM_S32(d0); buffn[i] = (FTYPE)sp[0]; sp += chan1; dp += chan1; } for (l = 0; l < (m - 1); l++) buffn[wid + l] = sp[l*chan1]; /* next line */ sl += sll; dl += dll; buff_ind++; if (buff_ind >= n + 1) buff_ind = 0; } } FREE_AND_RETURN_STATUS; }
mlib_status mlib_c_conv2x2ext_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_d64 buff_arr[4 * BUFF_LINE]; mlib_s32 *pbuff = (mlib_s32 *)buff_arr, *buff0, *buff1, *buff2, *buffT; DTYPE *adr_src, *sl, *sp, *sl1; DTYPE *adr_dst, *dl, *dp; mlib_d64 k0, k1, k2, k3, scalef = 1.0; mlib_d64 p00, p01, p02, p10, p11, p12; mlib_s32 wid, hgt, sll, dll, wid1; mlib_s32 nchannel, chan1, chan2; mlib_s32 i, j, c, swid; LOAD_KERNEL_INTO_DOUBLE(); GET_SRC_DST_PARAMETERS(DTYPE); vis_write_gsr(23 << 3); swid = wid + D_KER; wid1 = (swid + 1) & ~1; if (wid1 > BUFF_LINE) { pbuff = __mlib_malloc(4 * sizeof (mlib_s32) * wid1); if (pbuff == NULL) return (MLIB_FAILURE); } buff0 = pbuff; buff1 = buff0 + wid1; buff2 = buff1 + wid1; chan1 = nchannel; chan2 = chan1 + chan1; swid -= dx_r; for (c = 0; c < nchannel; c++) { if (!(cmask & (1 << (nchannel - 1 - c)))) continue; sl = adr_src + c; dl = adr_dst + c; if ((hgt - dy_b) > 0) sl1 = sl + sll; else sl1 = sl; #pragma pipeloop(0) for (i = 0; i < swid; i++) { buff0[i - 1] = (mlib_s32)sl[i * chan1]; buff1[i - 1] = (mlib_s32)sl1[i * chan1]; } if (dx_r != 0) { buff0[swid - 1] = buff0[swid - 2]; buff1[swid - 1] = buff1[swid - 2]; } if ((hgt - dy_b) > 1) sl = sl1 + sll; else sl = sl1; for (j = 0; j < hgt; j++) { sp = sl; dp = dl; buff2[-1] = (mlib_s32)sp[0]; sp += chan1; p02 = buff0[-1]; p12 = buff1[-1]; #pragma pipeloop(0) for (i = 0; i <= (wid - 2); i += 2) { d64_2x32 sd0, sd1; d64_2x32 dd0, dd1; p00 = p02; p10 = p12; sd0.d64 = *(TYPE_64BIT *) (buff0 + i); sd1.d64 = *(TYPE_64BIT *) (buff1 + i); p01 = (mlib_d64)sd0.i32s.i0; p02 = (mlib_d64)sd0.i32s.i1; p11 = (mlib_d64)sd1.i32s.i0; p12 = (mlib_d64)sd1.i32s.i1; LOAD_BUFF(buff2); dd0.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3); dd0.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3); dd1.d64 = vis_fpack32(dd1.d64, dd0.d64); STORE2(dd1.i32s.i0, dd1.i32s.i1); sp += chan2; dp += chan2; } for (; i < wid; i++) { d64_2x32 dd0, dd1; p00 = buff0[i - 1]; p10 = buff1[i - 1]; p01 = buff0[i]; p11 = buff1[i]; buff2[i] = (mlib_s32)sp[0]; dd0.i32s.i1 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3); dd1.d64 = vis_fpack32(dd1.d64, dd0.d64); dp[0] = dd1.i32s.i1; sp += chan1; dp += chan1; } if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2]; if (j < hgt - dy_b - 2) sl += sll; dl += dll; buffT = buff0; buff0 = buff1; buff1 = buff2; buff2 = buffT; } } if (pbuff != (mlib_s32 *)buff_arr) __mlib_free(pbuff); return (MLIB_SUCCESS); }