mlib_status __mlib_ImageMaximum( mlib_s32 *res, const mlib_image *img) { mlib_s32 j, channels; mlib_s32 res32[4]; MLIB_IMAGE_CHECK(img); if (res == NULL) return (MLIB_NULLPOINTER); channels = mlib_ImageGetChannels(img); switch (mlib_ImageGetType(img)) { case MLIB_BYTE: switch (channels) { case 1: case 2: case 4: mlib_m_ImageMaximum_U8_124(res32, img); break; case 3: mlib_m_ImageMaximum_U8_3(res32, img); break; } break; case MLIB_SHORT: switch (channels) { case 1: case 2: case 4: mlib_m_ImageMaximum_S16_124(res32, img); break; case 3: mlib_m_ImageMaximum_S16_3(res32, img); break; } break; case MLIB_USHORT: switch (channels) { case 1: case 2: case 4: mlib_m_ImageMaximum_U16_124(res32, img); break; case 3: mlib_m_ImageMaximum_U16_3(res32, img); break; } break; case MLIB_INT: switch (channels) { case 1: case 2: case 4: mlib_c_ImageMaximum_S32_124(res32, img); break; case 3: mlib_c_ImageMaximum_S32_3(res32, img); break; } break; default: return (MLIB_FAILURE); } for (j = 0; j < channels; j++) res[j] = res32[j]; return (MLIB_SUCCESS); }
void mlib_m_ImageMaximum_U8_124( mlib_s32 *res32, const mlib_image *img) { /* src address */ __m64 *sp, *sl; /* src data */ __m64 sd; /* min values */ __m64 max; __m64 _4s16_1, _4s16_2; __m64 _2s32_1, _2s32_2; /* edge mask */ mlib_s32 emask; /* loop variables */ mlib_s32 n1; /* height of image */ mlib_s32 height = mlib_ImageGetHeight(img); /* elements to next row */ mlib_s32 slb = mlib_ImageGetStride(img); /* number of image channels */ mlib_s32 channels = mlib_ImageGetChannels(img); mlib_s32 width = mlib_ImageGetWidth(img) * channels; mlib_s32 s1, s2; if (slb == width) { width *= height; height = 1; } sp = sl = (__m64 *) mlib_ImageGetData(img); /* min values */ max = _mm_set1_pi8(MLIB_U8_MIN); for (; height > 0; height--) { n1 = width; for (; n1 > 7; n1 -= 8) { sd = (*sp++); MLIB_M_IMAGE_MAXIMUM_U8(max, max, sd); } if (n1 > 0) { emask = (0xFF << (8 - n1)); sd = *sp; MLIB_M_IMAGE_MAXIMUM_U8_M32(max, max, sd, emask); } sp = sl = (__m64 *) ((mlib_u8 *)sl + slb); } switch (channels) { case 1: { MLIB_M_CONVERT_8U8_4S16(_4s16_1, _4s16_2, max); MLIB_M_IMAGE_MAXIMUM_S16(_4s16_1, _4s16_1, _4s16_2); MLIB_M_CONVERT_4S16_2S32(_2s32_1, _2s32_2, _4s16_1); MLIB_M_IMAGE_MAXIMUM_S32(_2s32_1, _2s32_1, _2s32_2); MLIB_M_CONVERT_2S32_S32(s1, s2, _2s32_1); MLIB_M_IMAGE_MAXIMUM(res32[0], s1, s2); break; } case 2: { MLIB_M_CONVERT_8U8_4S16(_4s16_1, _4s16_2, max); MLIB_M_IMAGE_MAXIMUM_S16(_4s16_1, _4s16_1, _4s16_2); MLIB_M_CONVERT_4S16_2S32(_2s32_1, _2s32_2, _4s16_1); MLIB_M_IMAGE_MAXIMUM_S32(_2s32_1, _2s32_1, _2s32_2); ((__m64 *) res32)[0] = _2s32_1; break; } case 4: { MLIB_M_CONVERT_8U8_4S16(_4s16_1, _4s16_2, max); MLIB_M_IMAGE_MAXIMUM_S16(_4s16_1, _4s16_1, _4s16_2); MLIB_M_CONVERT_4S16_2S32(_2s32_1, _2s32_2, _4s16_1); ((__m64 *) res32)[0] = _2s32_2; ((__m64 *) res32)[1] = _2s32_1; break; } } _mm_empty(); }
mlib_status __mlib_ImageNot( mlib_image *dst, const mlib_image *src) { /* start point in source */ mlib_u8 *sa; /* start points in destination */ mlib_u8 *da; /* width in bytes of src and dst */ mlib_s32 width; /* height in lines of src and dst */ mlib_s32 height; /* stride in bytes in src */ mlib_s32 stride; /* stride in bytes in dst */ mlib_s32 dstride; /* indices for x, y */ mlib_s32 j; mlib_s32 size; mlib_s32 type; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(dst, src); MLIB_IMAGE_TYPE_EQUAL(dst, src); MLIB_IMAGE_CHAN_EQUAL(dst, src); width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); height = mlib_ImageGetHeight(dst); sa = (mlib_u8 *)mlib_ImageGetData(src); da = (mlib_u8 *)mlib_ImageGetData(dst); type = mlib_ImageGetType(dst); if ((type != MLIB_BYTE) && (type != MLIB_SHORT) && (type != MLIB_USHORT) && (type != MLIB_BIT) && (type != MLIB_INT)) return (MLIB_FAILURE); if (type != MLIB_BIT) { switch (type) { case MLIB_BYTE: break; case MLIB_SHORT: case MLIB_USHORT: width *= 2; break; case MLIB_INT: width *= 4; break; default: return (MLIB_FAILURE); } size = height * width; if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst) && ((((mlib_addr)sa ^ (mlib_addr)da) & 7) == 0) && (size > CASHSIZE)) { mlib_s32 tail = 0x40 - ((mlib_addr)da & 0x3F); mlib_v_ImageNot_na(sa, da, tail & 0x3F); sa += tail & 0x3F; da += tail & 0x3F; size -= tail & 0x3F; /* (size >> 6) should be > 1 */ mlib_v_ImageNot_blk(sa, da, size >> 6); sa += size & ~0x3F; da += size & ~0x3F; mlib_v_ImageNot_na(sa, da, size & 0x3F); return (MLIB_SUCCESS); } else {
mlib_status __mlib_ImageSConv7x7( mlib_image *dst, const mlib_image *src, const mlib_s32 *hkernel, const mlib_s32 *vkernel, mlib_s32 scale, mlib_s32 cmask, mlib_edge edge) { mlib_s32 ksize = 7, ksize2 = ksize / 2; mlib_image dst_i[1], src_i[1], dst_e[1], src_e[1]; mlib_s32 edg_sizes[4]; mlib_type type; mlib_s32 nchan, dx_l, dx_r, dy_t, dy_b; mlib_s32 zero[4] = { 0, 0, 0, 0 }; mlib_status ret; ret = mlib_ImageClipping(dst_i, src_i, dst_e, src_e, edg_sizes, dst, src, ksize); if (ret != MLIB_SUCCESS) return (ret); if (hkernel == NULL || vkernel == NULL) return (MLIB_FAILURE); type = mlib_ImageGetType(dst); nchan = mlib_ImageGetChannels(dst); if (nchan == 1) cmask = 1; if ((cmask & ((1 << nchan) - 1)) == 0) return (MLIB_SUCCESS); dx_l = edg_sizes[0]; dx_r = edg_sizes[1]; dy_t = edg_sizes[2]; dy_b = edg_sizes[3]; if (dx_l + dx_r + dy_t + dy_b == 0) edge = MLIB_EDGE_DST_NO_WRITE; if (edge != MLIB_EDGE_SRC_EXTEND) { if (mlib_ImageGetWidth(src_i) >= ksize && mlib_ImageGetHeight(src_i) >= ksize) switch (type) { case MLIB_BYTE: if (scale < 24 || scale > 31) return (MLIB_FAILURE); mlib_sconv7x7nw_u8(dst_i, src_i, hkernel, vkernel, scale, cmask); break; case MLIB_SHORT: if (scale < 26 || scale > 33) return (MLIB_FAILURE); mlib_sconv7x7nw_s16(dst_i, src_i, hkernel, vkernel, scale, cmask); break; case MLIB_USHORT: if (scale < 26 || scale > 33) return (MLIB_FAILURE); mlib_sconv7x7nw_u16(dst_i, src_i, hkernel, vkernel, scale, cmask); break; case MLIB_INT: if (scale < 0) return (MLIB_FAILURE); mlib_sconv7x7nw_s32(dst_i, src_i, hkernel, vkernel, scale, cmask); break; default: return (MLIB_FAILURE); } switch (edge) { case MLIB_EDGE_DST_FILL_ZERO: mlib_ImageConvClearEdge(dst_e, dx_l, dx_r, dy_t, dy_b, zero, cmask); break; case MLIB_EDGE_DST_COPY_SRC: mlib_ImageConvCopyEdge(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, cmask); break; default: return (MLIB_SUCCESS); } } else if (mlib_ImageGetWidth(dst_e) > 0 && mlib_ImageGetHeight(dst_e) > 0) { /* MLIB_EDGE_SRC_EXTEND */ /* adjust src_e image */ mlib_ImageSetSubimage(src_e, src_e, dx_l - ksize2, dy_t - ksize2, mlib_ImageGetWidth(src_e), mlib_ImageGetHeight(src_e)); switch (type) { case MLIB_BYTE: if (scale < 24 || scale > 31) return (MLIB_FAILURE); mlib_sconv7x7ext_u8(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, hkernel, vkernel, scale, cmask); break; case MLIB_SHORT: if (scale < 26 || scale > 33) return (MLIB_FAILURE); mlib_sconv7x7ext_s16(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, hkernel, vkernel, scale, cmask); break; case MLIB_USHORT: if (scale < 26 || scale > 33) return (MLIB_FAILURE); mlib_sconv7x7ext_u16(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, hkernel, vkernel, scale, cmask); break; case MLIB_INT: if (scale < 0) return (MLIB_FAILURE); mlib_sconv7x7ext_s32(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, hkernel, vkernel, scale, cmask); break; default: return (MLIB_FAILURE); } } return (MLIB_SUCCESS); }
mlib_status __mlib_ImageChannelMerge( mlib_image *dst, const mlib_image **srcs) { mlib_type image_type; mlib_s32 nchan; mlib_u8 *dst_0; mlib_u8 *src_0; mlib_u8 *src_1; mlib_u8 *src_2 = NULL; mlib_u8 *src_3 = NULL; mlib_s32 dst_str; mlib_s32 src0_str; mlib_s32 src1_str; mlib_s32 src2_str = 0; mlib_s32 src3_str = 0; mlib_s32 height; mlib_s32 width; MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_CHECK(srcs); MLIB_IMAGE_CHECK(srcs[0]); MLIB_IMAGE_CHECK(srcs[1]); image_type = mlib_ImageGetType(dst); nchan = mlib_ImageGetChannels(dst); width = mlib_ImageGetWidth(dst); height = mlib_ImageGetHeight(dst); MLIB_IMAGE_HAVE_TYPE(srcs[0], image_type); MLIB_IMAGE_HAVE_TYPE(srcs[1], image_type); MLIB_IMAGE_HAVE_CHAN(srcs[0], 1); MLIB_IMAGE_HAVE_CHAN(srcs[1], 1); dst_0 = (mlib_u8 *)mlib_ImageGetData(dst); src_0 = (mlib_u8 *)mlib_ImageGetData(srcs[0]); src_1 = (mlib_u8 *)mlib_ImageGetData(srcs[1]); dst_str = mlib_ImageGetStride(dst); src0_str = mlib_ImageGetStride(srcs[0]); src1_str = mlib_ImageGetStride(srcs[1]); if (nchan > 2) { MLIB_IMAGE_CHECK(srcs[2]); MLIB_IMAGE_HAVE_CHAN(srcs[2], 1); MLIB_IMAGE_HAVE_TYPE(srcs[2], image_type); src_2 = (mlib_u8 *)mlib_ImageGetData(srcs[2]); src2_str = mlib_ImageGetStride(srcs[2]); if (nchan > 3) { MLIB_IMAGE_CHECK(srcs[3]); MLIB_IMAGE_HAVE_CHAN(srcs[3], 1); MLIB_IMAGE_HAVE_TYPE(srcs[3], image_type); src_3 = (mlib_u8 *)mlib_ImageGetData(srcs[3]); src3_str = mlib_ImageGetStride(srcs[3]); } } switch (image_type) { case MLIB_BYTE: switch (nchan) { case 2: return mlib_ImageChannelMerge2_U8(dst_0, src_0, src_1, height, width, dst_str, src0_str, src1_str); case 3: return mlib_ImageChannelMerge3_U8(dst_0, src_0, src_1, src_2, height, width, dst_str, src0_str, src1_str, src2_str); case 4: return mlib_ImageChannelMerge4_U8(dst_0, src_0, src_1, src_2, src_3, height, width, dst_str, src0_str, src1_str, src2_str, src3_str); default: return (MLIB_FAILURE); } case MLIB_USHORT: case MLIB_SHORT: dst_str >>= 1; src0_str >>= 1; src1_str >>= 1; switch (nchan) { case 2: return mlib_ImageChannelMerge2_S16((mlib_s16 *)dst_0, (mlib_s16 *)src_0, (mlib_s16 *)src_1, height, width, dst_str, src0_str, src1_str); case 3: src2_str >>= 1; return mlib_ImageChannelMerge3_S16((mlib_s16 *)dst_0, (mlib_s16 *)src_0, (mlib_s16 *)src_1, (mlib_s16 *)src_2, height, width, dst_str, src0_str, src1_str, src2_str); case 4: src2_str >>= 1; src3_str >>= 1; return mlib_ImageChannelMerge4_S16((mlib_s16 *)dst_0, (mlib_s16 *)src_0, (mlib_s16 *)src_1, (mlib_s16 *)src_2, (mlib_s16 *)src_3, height, width, dst_str, src0_str, src1_str, src2_str, src3_str); default: return (MLIB_FAILURE); } case MLIB_FLOAT: case MLIB_INT: dst_str >>= 2; src0_str >>= 2; src1_str >>= 2; switch (nchan) { case 2: return mlib_ImageChannelMerge2_FS32((mlib_s32 *)dst_0, (mlib_s32 *)src_0, (mlib_s32 *)src_1, height, width, dst_str, src0_str, src1_str); case 3: src2_str >>= 2; return mlib_ImageChannelMerge3_FS32((mlib_s32 *)dst_0, (mlib_s32 *)src_0, (mlib_s32 *)src_1, (mlib_s32 *)src_2, height, width, dst_str, src0_str, src1_str, src2_str); case 4: src2_str >>= 2; src3_str >>= 2; return mlib_ImageChannelMerge4_FS32((mlib_s32 *)dst_0, (mlib_s32 *)src_0, (mlib_s32 *)src_1, (mlib_s32 *)src_2, (mlib_s32 *)src_3, height, width, dst_str, src0_str, src1_str, src2_str, src3_str); default: return (MLIB_FAILURE); } case MLIB_DOUBLE: dst_str >>= 3; src0_str >>= 3; src1_str >>= 3; switch (nchan) { case 2: return mlib_ImageChannelMerge2_D64((mlib_d64 *)dst_0, (mlib_d64 *)src_0, (mlib_d64 *)src_1, height, width, dst_str, src0_str, src1_str); case 3: src2_str >>= 3; return mlib_ImageChannelMerge3_D64((mlib_d64 *)dst_0, (mlib_d64 *)src_0, (mlib_d64 *)src_1, (mlib_d64 *)src_2, height, width, dst_str, src0_str, src1_str, src2_str); case 4: src2_str >>= 3; src3_str >>= 3; return mlib_ImageChannelMerge4_D64((mlib_d64 *)dst_0, (mlib_d64 *)src_0, (mlib_d64 *)src_1, (mlib_d64 *)src_2, (mlib_d64 *)src_3, height, width, dst_str, src0_str, src1_str, src2_str, src3_str); default: return (MLIB_FAILURE); } default: return (MLIB_FAILURE); } }
mlib_status mlib_ImageConvMxN_f(mlib_image *dst, const mlib_image *src, const void *kernel, mlib_s32 m, mlib_s32 n, mlib_s32 dm, mlib_s32 dn, mlib_s32 scale, mlib_s32 cmask, mlib_edge edge) { mlib_image dst_i[1], src_i[1], dst_e[1], src_e[1]; mlib_type type; mlib_s32 nchan, dx_l, dx_r, dy_t, dy_b; mlib_s32 edg_sizes[8]; mlib_status ret; if (m < 1 || n < 1 || dm < 0 || dm > m - 1 || dn < 0 || dn > n - 1) return MLIB_FAILURE; if (kernel == NULL) return MLIB_NULLPOINTER; ret = mlib_ImageClippingMxN(dst_i, src_i, dst_e, src_e, edg_sizes, dst, src, m, n, dm, dn); if (ret != MLIB_SUCCESS) return ret; nchan = mlib_ImageGetChannels(dst); type = mlib_ImageGetType(dst); if (nchan == 1) cmask = 1; if ((cmask & ((1 << nchan) - 1)) == 0) return MLIB_SUCCESS; dx_l = edg_sizes[0]; dx_r = edg_sizes[1]; dy_t = edg_sizes[2]; dy_b = edg_sizes[3]; if (dx_l + dx_r + dy_t + dy_b == 0) edge = MLIB_EDGE_DST_NO_WRITE; if (edge != MLIB_EDGE_SRC_EXTEND) { if (mlib_ImageGetWidth(dst_i) >= m && mlib_ImageGetHeight(dst_i) >= n) { switch (type) { case MLIB_BYTE: ret = mlib_convMxNnw_u8(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); break; case MLIB_SHORT: #ifdef __sparc ret = mlib_convMxNnw_s16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); #else if (mlib_ImageConvVersion(m, n, scale, type) == 0) ret = mlib_convMxNnw_s16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); else ret = mlib_i_convMxNnw_s16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); #endif /* __sparc */ break; case MLIB_USHORT: #ifdef __sparc ret = mlib_convMxNnw_u16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); #else if (mlib_ImageConvVersion(m, n, scale, type) == 0) ret = mlib_convMxNnw_u16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); else ret = mlib_i_convMxNnw_u16(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); #endif /* __sparc */ break; case MLIB_INT: ret = mlib_convMxNnw_s32(dst_i, src_i, kernel, m, n, dm, dn, scale, cmask); break; case MLIB_FLOAT: ret = mlib_convMxNnw_f32(dst_i, src_i, kernel, m, n, dm, dn, cmask); break; case MLIB_DOUBLE: ret = mlib_convMxNnw_d64(dst_i, src_i, kernel, m, n, dm, dn, cmask); break; } } switch (edge) { case MLIB_EDGE_DST_FILL_ZERO: mlib_ImageConvZeroEdge(dst_e, dx_l, dx_r, dy_t, dy_b, cmask); break; case MLIB_EDGE_DST_COPY_SRC: mlib_ImageConvCopyEdge(dst_e, src_e, dx_l, dx_r, dy_t, dy_b, cmask); break; } } else { /* MLIB_EDGE_SRC_EXTEND */ /* adjust src_e image */ mlib_ImageSetSubimage(src_e, src_e, dx_l - dm, dy_t - dn, mlib_ImageGetWidth(src_e), mlib_ImageGetHeight(src_e)); switch (type) { case MLIB_BYTE: ret = mlib_convMxNext_u8(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); break; case MLIB_SHORT: #ifdef __sparc ret = mlib_convMxNext_s16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); #else if (mlib_ImageConvVersion(m, n, scale, type) == 0) ret = mlib_convMxNext_s16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); else ret = mlib_i_convMxNext_s16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); #endif /* __sparc */ break; case MLIB_USHORT: #ifdef __sparc ret = mlib_convMxNext_u16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); #else if (mlib_ImageConvVersion(m, n, scale, type) == 0) ret = mlib_convMxNext_u16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); else ret = mlib_i_convMxNext_u16(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); #endif /* __sparc */ break; case MLIB_INT: ret = mlib_convMxNext_s32(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, scale, cmask); break; case MLIB_FLOAT: mlib_convMxNext_f32(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, cmask); break; case MLIB_DOUBLE: mlib_convMxNext_d64(dst_e, src_e, kernel, m, n, dx_l, dx_r, dy_t, dy_b, cmask); break; } } return ret; }
mlib_status __mlib_ImageFlipY_Fp( mlib_image *dst, const mlib_image *src) { /* check for obvious errors */ MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); switch (mlib_ImageGetType(src)) { /* handle MLIB_FLOAT data type of image */ case MLIB_FLOAT: switch (mlib_ImageGetChannels(src)) { case 1: mlib_ImageFlipY_S32_1(dst, src); break; case 2: mlib_ImageFlipY_D64_1(dst, src); break; case 3: mlib_ImageFlipY_S32_3(dst, src); break; case 4: mlib_ImageFlipY_D64_2(dst, src); break; default: return (MLIB_FAILURE); } break; /* handle MLIB_DOUBLE data type of image */ case MLIB_DOUBLE: { switch (mlib_ImageGetChannels(src)) { case 1: mlib_ImageFlipY_D64_1(dst, src); break; case 2: mlib_ImageFlipY_D64_2(dst, src); break; case 3: mlib_ImageFlipY_D64_3(dst, src); break; case 4: mlib_ImageFlipY_D64_4(dst, src); break; default: return (MLIB_FAILURE); } break; } /* discard any other data types */ default: return (MLIB_FAILURE); } return (MLIB_SUCCESS); }
mlib_status mlib_c_ImageConstAdd_S32( mlib_image *dst, const mlib_image *src, const mlib_s32 *c) { mlib_s32 *psrc, *pdst, con0 = c[0], con1, con2, con3; mlib_s32 slb, dlb, xsize, ysize, nchan; mlib_s32 i, j; nchan = mlib_ImageGetChannels(dst); xsize = mlib_ImageGetWidth(dst); ysize = mlib_ImageGetHeight(dst); dlb = mlib_ImageGetStride(dst); pdst = (void *)mlib_ImageGetData(dst); slb = mlib_ImageGetStride(src); psrc = mlib_ImageGetData(src); slb >>= 2; dlb >>= 2; /* if src and dst - 1-D vector */ if (xsize * nchan == slb && slb == dlb) { xsize *= ysize; ysize = 1; } if (nchan == 1) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { pdst[i] = con0 + psrc[i]; } psrc += slb; pdst += dlb; } } else { con1 = c[1]; if (nchan == 2) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { pdst[2 * i] = con0 + psrc[2 * i]; pdst[2 * i + 1] = con1 + psrc[2 * i + 1]; } psrc += slb; pdst += dlb; } } else { con2 = c[2]; if (nchan == 3) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { pdst[3 * i] = con0 + psrc[3 * i]; pdst[3 * i + 1] = con1 + psrc[3 * i + 1]; pdst[3 * i + 2] = con2 + psrc[3 * i + 2]; } psrc += slb; pdst += dlb; } } else { con3 = c[3]; for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { pdst[4 * i] = con0 + psrc[4 * i]; pdst[4 * i + 1] = con1 + psrc[4 * i + 1]; pdst[4 * i + 2] = con2 + psrc[4 * i + 2]; pdst[4 * i + 3] = con3 + psrc[4 * i + 3]; } psrc += slb; pdst += dlb; } } } } return (MLIB_SUCCESS); }
mlib_status mlib_c_ImageConstAdd_U16( mlib_image *dst, const mlib_image *src, const mlib_s32 *c) { mlib_u16 *psrc, *pdst; mlib_s32 con0, con1, con2, con3, sum; mlib_s32 slb, dlb, xsize, ysize, nchan; mlib_s32 i, j; nchan = mlib_ImageGetChannels(dst); xsize = mlib_ImageGetWidth(dst); ysize = mlib_ImageGetHeight(dst); dlb = mlib_ImageGetStride(dst); pdst = (void *)mlib_ImageGetData(dst); slb = mlib_ImageGetStride(src); psrc = mlib_ImageGetData(src); slb >>= 1; dlb >>= 1; con0 = c[0]; if (con0 > MLIB_U16_MAX) con0 = MLIB_U16_MAX; if (con0 < -MLIB_U16_MAX) con0 = -MLIB_U16_MAX; /* if src and dst - 1-D vector */ if (xsize * nchan == slb && slb == dlb) { xsize *= ysize; ysize = 1; } if (nchan == 1) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { ADD_SAT_U16(pdst[i], con0, psrc[i]); } psrc += slb; pdst += dlb; } } else { con1 = c[1]; if (con1 > MLIB_U16_MAX) con1 = MLIB_U16_MAX; if (con1 < -MLIB_U16_MAX) con1 = -MLIB_U16_MAX; if (nchan == 2) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { ADD_SAT_U16(pdst[2 * i], con0, psrc[2 * i]); ADD_SAT_U16(pdst[2 * i + 1], con1, psrc[2 * i + 1]); } psrc += slb; pdst += dlb; } } else { con2 = c[2]; if (con2 > MLIB_U16_MAX) con2 = MLIB_U16_MAX; if (con2 < -MLIB_U16_MAX) con2 = -MLIB_U16_MAX; if (nchan == 3) { for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { ADD_SAT_U16(pdst[3 * i], con0, psrc[3 * i]); ADD_SAT_U16(pdst[3 * i + 1], con1, psrc[3 * i + 1]); ADD_SAT_U16(pdst[3 * i + 2], con2, psrc[3 * i + 2]); } psrc += slb; pdst += dlb; } } else { con3 = c[3]; if (con3 > MLIB_U16_MAX) con3 = MLIB_U16_MAX; if (con3 < -MLIB_U16_MAX) con3 = -MLIB_U16_MAX; for (j = 0; j < ysize; j++) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (i = 0; i < xsize; i++) { ADD_SAT_U16(pdst[4 * i], con0, psrc[4 * i]); ADD_SAT_U16(pdst[4 * i + 1], con1, psrc[4 * i + 1]); ADD_SAT_U16(pdst[4 * i + 2], con2, psrc[4 * i + 2]); ADD_SAT_U16(pdst[4 * i + 3], con3, psrc[4 * i + 3]); } psrc += slb; pdst += dlb; } } } } return (MLIB_SUCCESS); }
/* *********************************************************** */ mlib_status __mlib_ImageExtremaLocations_Fp( mlib_d64 *min, mlib_d64 *max, const mlib_image *img, mlib_s32 xStart, mlib_s32 yStart, mlib_s32 xPeriod, mlib_s32 yPeriod, mlib_s32 saveLocations, mlib_s32 maxRuns, mlib_s32 *minCounts, mlib_s32 *maxCounts, mlib_s32 **minLocations, mlib_s32 **maxLocations, mlib_s32 len) { mlib_status stat; mlib_s32 nchan = mlib_ImageGetChannels(img); mlib_d64 dmin[4], dmax[4]; mlib_s32 buf_test_min[4]; mlib_s32 buf_test_max[4]; mlib_s32 i; #ifdef __SUNPRO_C #pragma unroll(1) #endif /* __SUNPRO_C */ for (i = 0; i < nchan; i++) { dmin[i] = min[i]; dmax[i] = max[i]; } stat = __mlib_ImageExtrema2_Fp(dmin, dmax, img, xStart, yStart, xPeriod, yPeriod); if (stat != MLIB_SUCCESS) return (stat); #ifdef __SUNPRO_C #pragma unroll(1) #endif /* __SUNPRO_C */ for (i = 0; i < nchan; i++) { min[i] = (min[i] < dmin[i]) ? min[i] : dmin[i]; max[i] = (max[i] > dmax[i]) ? max[i] : dmax[i]; } if (saveLocations == 0) return (MLIB_SUCCESS); if (maxRuns < 1) return (MLIB_OUTOFRANGE); if ((minCounts == NULL) || (maxCounts == NULL)) return (MLIB_FAILURE); if ((minLocations == NULL) || (maxLocations == NULL)) return (MLIB_FAILURE); for (i = 0; i < nchan; i++) { if ((minLocations[i] == NULL) || (maxLocations[i] == NULL)) return (MLIB_FAILURE); } #ifdef __SUNPRO_C #pragma unroll(1) #endif /* __SUNPRO_C */ for (i = 0; i < nchan; i++) { buf_test_min[i] = 0; buf_test_max[i] = 0; if (dmin[i] != min[i]) buf_test_min[i] = 1; if (dmax[i] != max[i]) buf_test_max[i] = 1; } switch (mlib_ImageGetType(img)) { case MLIB_FLOAT: stat = mlib_ImageExtremaLocations_f32(min, max, img, xStart, yStart, xPeriod, yPeriod, maxRuns, minCounts, maxCounts, minLocations, maxLocations, buf_test_min, buf_test_max, len); break; case MLIB_DOUBLE: stat = mlib_ImageExtremaLocations_d64(min, max, img, xStart, yStart, xPeriod, yPeriod, maxRuns, minCounts, maxCounts, minLocations, maxLocations, buf_test_min, buf_test_max, len); break; default: stat = MLIB_FAILURE; } return (stat); }
mlib_status mlib_ZoomBlendEdge( mlib_image *dst, const mlib_image *src, mlib_work_image * param, mlib_filter filter, mlib_edge edge, mlib_s32 alp_ind) { mlib_s32 schan, dchan, t_ind, bsize, i, j, k; mlib_blend blend = param->blend; mlib_edge_box *edges = param->edges; mlib_u8 *buff, *pbuff; schan = mlib_ImageGetChannels(src); dchan = mlib_ImageGetChannels(dst); t_ind = (schan - 3) + 2 * (dchan - 3); bsize = 0; for (i = 0; i < 4; i++) { if (edges[i].w < 0) edges[i].w = 0; if (edges[i].h < 0) edges[i].h = 0; bsize += edges[i].w * edges[i].h; } if (!bsize) return (MLIB_SUCCESS); bsize *= schan; mlib_ImageCopy_na((void *)edges, (void *)&(param->edges_blend), sizeof (param->edges_blend)); pbuff = buff = __mlib_malloc(bsize); if (buff == NULL) return (MLIB_FAILURE); for (i = 0; i < 4; i++) { mlib_s32 dlb = schan * edges[i].w; edges[i].dp = pbuff; edges[i].dlb = dlb; pbuff += dlb * edges[i].h; } MLIB_EDGE_RULES; for (k = 0; k < 4; k++) { mlib_s32 ww = edges[k].w; mlib_s32 hh = edges[k].h; mlib_s32 slb = edges[k].dlb; mlib_s32 dlb = param->edges_blend[k].dlb; mlib_u8 *sp = edges[k].dp; mlib_u8 *dp = param->edges_blend[k].dp; if (ww == 0 || hh == 0) continue; if (alp_ind == -1) { if (schan == 4) sp++; if (dchan == 4) dp++; } /* 33 */ if (t_ind == 0) { FP_TYPE a0 = (param->alpha) * (F_ONE / 255); for (j = 0; j < hh; j++) { for (i = 0; i < 3 * ww; i++) { BLEND33(dp[i], sp[i]); } sp += slb; dp += dlb; } } else if (t_ind == 1) { /* 43 */ FP_TYPE a0 = (param->alpha) * (F_ONE / 255), dalpha = a0 * (F_ONE / 255); if (edge == MLIB_EDGE_SRC_EXTEND || edge == MLIB_EDGE_SRC_EXTEND_INDEF) { FP_TYPE a1; if (blend == MLIB_BLEND_GTK_SRC) { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { STORE(dp[3 * i], sp[4 * i]); STORE(dp[3 * i + 1], sp[4 * i + 1]); STORE(dp[3 * i + 2], sp[4 * i + 2]); } sp += slb; dp += dlb; } } else { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { a1 = 1 - dalpha * sp[4 * i + alp_ind]; BLEND43(dp[3 * i], sp[4 * i]); BLEND43(dp[3 * i + 1], sp[4 * i + 1]); BLEND43(dp[3 * i + 2], sp[4 * i + 2]); } sp += slb; dp += dlb; } } } else { if (blend == MLIB_BLEND_GTK_SRC) { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { a0 = sp[4 * i + alp_ind] * (F_ONE / 255); dp[3 * i] = (mlib_u8)(a0 * sp[4 * i]); dp[3 * i + 1] = (mlib_u8)(a0 * sp[4 * i + 1]); dp[3 * i + 2] = (mlib_u8)(a0 * sp[4 * i + 2]); } sp += slb; dp += dlb; } } else { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { a0 = dalpha * sp[4 * i + alp_ind]; BLEND33(dp[3 * i], sp[4 * i]); BLEND33(dp[3 * i + 1], sp[4 * i + 1]); BLEND33(dp[3 * i + 2], sp[4 * i + 2]); } sp += slb; dp += dlb; } } } } else if (t_ind == 2) { /* 34 */ FP_TYPE w0 = (FP_TYPE) param->alpha; FP_TYPE w1s = F_ONE - w0 * (F_ONE / 255); FP_TYPE w1, w, rw; if (blend == MLIB_BLEND_GTK_SRC_OVER2) { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { w1 = w1s * dp[4 * i + alp_ind]; w = w0 + w1; FP_DIV(rw, w0, w); BLEND34(dp[4 * i], sp[3 * i]); BLEND34(dp[4 * i + 1], sp[3 * i + 1]); BLEND34(dp[4 * i + 2], sp[3 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } sp += slb; dp += dlb; } } else { for (j = 0; j < hh; j++) { for (i = 0; i < ww; i++) { w1 = w1s * dp[4 * i + alp_ind]; w = w0 + w1; FP_INV(rw, w); BLEND34z(dp[4 * i], sp[3 * i]); BLEND34z(dp[4 * i + 1], sp[3 * i + 1]); BLEND34z(dp[4 * i + 2], sp[3 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } sp += slb; dp += dlb; } } } else if (t_ind == 3) { /* 44 */ FP_TYPE dalpha0 = (FP_TYPE) param->alpha, dalpha = dalpha0 * (F_ONE / 255); FP_TYPE w0, w1, w, rw; if (edge == MLIB_EDGE_SRC_EXTEND || edge == MLIB_EDGE_SRC_EXTEND_INDEF) { for (j = 0; j < hh; j++) { if (blend == MLIB_BLEND_GTK_SRC) { for (i = 0; i < ww; i++) { w = sp[4 * i + alp_ind]; FP_DIV(rw, 255, w); BLEND_GTK_SRC(dp[4 * i], sp[4 * i]); BLEND_GTK_SRC(dp[4 * i + 1], sp[4 * i + 1]); BLEND_GTK_SRC(dp[4 * i + 2], sp[4 * i + 2]); dp[4 * i + alp_ind] = sp[4 * i + alp_ind]; } } else if (blend == MLIB_BLEND_GTK_SRC_OVER2) { for (i = 0; i < ww; i++) { w0 = dalpha * sp[4 * i + alp_ind]; w1 = (F_ONE - w0 * (F_ONE / 255)) * dp[4 * i + alp_ind]; w = w0 + w1; FP_INV(rw, w); BLEND44(dp[4 * i], sp[4 * i]); BLEND44(dp[4 * i + 1], sp[4 * i + 1]); BLEND44(dp[4 * i + 2], sp[4 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } } else { for (i = 0; i < ww; i++) { w0 = dalpha * sp[4 * i + alp_ind]; w1 = (F_ONE - w0 * (F_ONE / 255)) * dp[4 * i + alp_ind]; w = w0 + w1; FP_INV(rw, w); BLEND44z(dp[4 * i], sp[4 * i]); BLEND44z(dp[4 * i + 1], sp[4 * i + 1]); BLEND44z(dp[4 * i + 2], sp[4 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } } sp += slb; dp += dlb; } } else { for (j = 0; j < hh; j++) { if (blend == MLIB_BLEND_GTK_SRC) { for (i = 0; i < ww; i++) { dp[4 * i] = sp[4 * i]; dp[4 * i + 1] = sp[4 * i + 1]; dp[4 * i + 2] = sp[4 * i + 2]; dp[4 * i + alp_ind] = sp[4 * i + alp_ind]; } } else if (blend == MLIB_BLEND_GTK_SRC_OVER2) { for (i = 0; i < ww; i++) { w0 = dalpha * sp[4 * i + alp_ind]; w1 = (F_ONE - w0 * (F_ONE / 255)) * dp[4 * i + alp_ind]; w = w0 + w1; FP_DIV(rw, w0, w); BLEND34(dp[4 * i], sp[4 * i]); BLEND34(dp[4 * i + 1], sp[4 * i + 1]); BLEND34(dp[4 * i + 2], sp[4 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } } else { for (i = 0; i < ww; i++) { w0 = dalpha * sp[4 * i + alp_ind]; w1 = (F_ONE - w0 * (F_ONE / 255)) * dp[4 * i + alp_ind]; w = w0 + w1; FP_INV(rw, w); BLEND34z(dp[4 * i], sp[4 * i]); BLEND34z(dp[4 * i + 1], sp[4 * i + 1]); BLEND34z(dp[4 * i + 2], sp[4 * i + 2]); dp[4 * i + alp_ind] = (mlib_u8)w; } } sp += slb; dp += dlb; } } } } __mlib_free(buff); return (MLIB_SUCCESS); }