mlib_status __mlib_ImageCopy( mlib_image *dst, const mlib_image *src) { mlib_s32 s_offset, d_offset, width, height; mlib_s32 size, s_stride, d_stride; mlib_u8 *sa, *da; mlib_s32 j; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); switch (mlib_ImageGetType(dst)) { case MLIB_BIT: sa = (mlib_u8 *)mlib_ImageGetData(src); da = (mlib_u8 *)mlib_ImageGetData(dst); width = mlib_ImageGetWidth(src) * mlib_ImageGetChannels(src); height = mlib_ImageGetHeight(src); if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst)) { size = height * (width >> 3); mlib_ImageCopy_na(sa, da, size); } else {
mlib_status mlib_ImageCopy(mlib_image *dst, const mlib_image *src) { mlib_s32 s_offset, d_offset; mlib_s32 size, s_stride, d_stride; mlib_s32 width; /* width in bytes of src and dst */ mlib_s32 height; /* height in lines of src and dst */ mlib_u8 *sa, *da; mlib_s32 j; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); switch (mlib_ImageGetType(dst)) { case MLIB_BIT: width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); /* size in bits */ height = mlib_ImageGetHeight(src); sa = (mlib_u8 *) mlib_ImageGetData(src); da = (mlib_u8 *) mlib_ImageGetData(dst); if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst)) { size = height * (width >> 3); if (!mlib_ImageIsNotAligned8(src) && !mlib_ImageIsNotAligned8(dst) && ((size & 7) == 0)) { mlib_c_ImageCopy_a1((TYPE_64BIT *) sa, (TYPE_64BIT *) da, size >> 3); } else {
mlib_status __mlib_ImageCopyMask_Fp( mlib_image *dst, const mlib_image *src, const mlib_image *mask, const mlib_d64 *thresh) { mlib_type dtype; mlib_s32 slb, mlb, dlb, xsize, ysize, nchan; void *sa, *ma, *da; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_CHECK(mask); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_TYPE_EQUAL(mask, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(mask, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(mask, dst); dtype = mlib_ImageGetType(dst); nchan = mlib_ImageGetChannels(dst); xsize = mlib_ImageGetWidth(dst); ysize = mlib_ImageGetHeight(dst); slb = mlib_ImageGetStride(src); mlb = mlib_ImageGetStride(mask); dlb = mlib_ImageGetStride(dst); sa = mlib_ImageGetData(src); ma = mlib_ImageGetData(mask); da = mlib_ImageGetData(dst); if (dtype == MLIB_FLOAT) { mlib_ImageCopyMask_Fp_f32(sa, slb, ma, mlb, da, dlb, xsize, ysize, nchan, thresh); return (MLIB_SUCCESS); } else if (dtype == MLIB_DOUBLE) { mlib_ImageCopyMask_Fp_d64(sa, slb, ma, mlb, da, dlb, xsize, ysize, nchan, thresh); return (MLIB_SUCCESS); } else return (MLIB_FAILURE); }
mlib_status __mlib_ImageScale( mlib_image *dst, const mlib_image *src, const mlib_s32 *alpha, const mlib_s32 *beta, mlib_s32 shift) { mlib_type stype, dtype; mlib_s32 k, nchan; mlib_d64 dshift, dalpha[4], dbeta[4]; MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_CHECK(src); MLIB_IMAGE_SIZE_EQUAL(dst, src); MLIB_IMAGE_CHAN_EQUAL(dst, src); if (alpha == NULL) return (MLIB_FAILURE); if (beta == NULL) return (MLIB_FAILURE); if (shift < 0 || shift > 31) return (MLIB_OUTOFRANGE); stype = mlib_ImageGetType(src); dtype = mlib_ImageGetType(dst); nchan = mlib_ImageGetChannels(dst); if (mlib_ImageScale_CheckForVIS(alpha, beta, shift, stype, dtype, nchan) < -1) { return (MLIB_OUTOFRANGE); } dshift = 1.0 / (1u << shift); for (k = 0; k < nchan; k++) { dalpha[k] = alpha[k] * dshift; dbeta[k] = beta[k]; } if (stype == MLIB_BYTE) return (mlib_ImageScale2_U8(dst, src, dalpha, dbeta)); if (stype == MLIB_SHORT) return (mlib_ImageScale2_S16(dst, src, dalpha, dbeta)); if (stype == MLIB_USHORT) return (mlib_ImageScale2_U16(dst, src, dalpha, dbeta)); if (stype == MLIB_INT) return (mlib_ImageScale2_S32(dst, src, dalpha, dbeta)); return (MLIB_FAILURE); }
mlib_status __mlib_ImageLookUpMask( mlib_image *dst, const mlib_image *src, const void **table, mlib_s32 channels, mlib_s32 cmask) { mlib_type stype, dtype; mlib_s32 slb, dlb, xsize, ysize, dchan, schan, i; mlib_s32 table_i[4], dst_i[4], src_i[4], chan = 0; mlib_u8 *sa, *da; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); stype = mlib_ImageGetType(src); dtype = mlib_ImageGetType(dst); schan = mlib_ImageGetChannels(src); dchan = mlib_ImageGetChannels(dst); xsize = mlib_ImageGetWidth(src); ysize = mlib_ImageGetHeight(src); slb = mlib_ImageGetStride(src); dlb = mlib_ImageGetStride(dst); sa = mlib_ImageGetData(src); da = mlib_ImageGetData(dst); for (i = dchan - 1; i >= 0; i--, cmask >>= 1) if ((cmask & 1) == 1) { dst_i[chan] = i; src_i[chan] = i; table_i[chan] = i; chan++; } if (((channels < chan) && (channels != 1)) || ((schan != dchan) && (schan != 1) && (schan != chan))) return (MLIB_FAILURE); if (chan == 0) return (MLIB_SUCCESS); if (chan == dchan) { mlib_u8 *look_up_table[4]; if (channels == 1) for (i = 0; i < chan; i++) look_up_table[i] = (void *)table[0]; else for (i = 0; i < chan; i++) look_up_table[i] = (void *)table[i]; return __mlib_ImageLookUp(dst, src, (const void **)look_up_table); } if (schan == 1) for (i = 0; i < chan; i++) src_i[i] = 0; else if (schan != dchan) for (i = 0; i < chan; i++) src_i[i] = chan - 1 - i; if (channels == 1) for (i = 0; i < chan; i++) table_i[i] = 0; else if (channels < dchan) for (i = 0; i < chan; i++) table_i[i] = chan - 1 - i; if (stype == MLIB_BYTE) { if (dtype == MLIB_BYTE) if ((schan == 1) && ((xsize * ysize) > 250)) mlib_v_ImageLookUpMaskSI_U8_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, table_i, dchan, chan); else if ((((schan - chan) == 1) && (chan > 1)) || ((schan == chan) && (dchan == 3) && (chan == 2))) mlib_v_ImageLookUpMaskMN_U8_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, table_i, dchan, schan, chan); else mlib_ImageLookUpMask_U8_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if ((dtype == MLIB_SHORT) || (dtype == MLIB_USHORT)) if ((schan == 1) && ((xsize * ysize) > 250)) mlib_v_ImageLookUpMaskSI_S16_U8((mlib_s16 *)da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, table_i, dchan, chan); else if ((((schan - chan) == 1) && (chan > 1)) || ((schan == chan) && (dchan == 3) && (chan == 2))) mlib_v_ImageLookUpMaskMN_S16_U8((mlib_s16 *)da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, table_i, dchan, schan, chan); else mlib_ImageLookUpMask_S16_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_INT || dtype == MLIB_FLOAT) if ((schan == 1) && ((xsize * ysize) > 250) && (((dchan - chan) == 1) || ((chan == 2) && (dchan == 4)))) mlib_v_ImageLookUpMaskSI_S32_U8((mlib_s32 *)da, dlb, sa, slb, xsize, ysize, (const mlib_s32 **)table, dst_i, table_i, dchan, chan); else mlib_ImageLookUpMask_S32_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_s32 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_DOUBLE) { if ((schan == 1) && (chan >= 2)) { if (chan == 2) { mlib_ImageLookUpMask_3_4_D64_U8( (mlib_d64 *)da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, table_i, dchan); } else { mlib_ImageLookUpMask_4_D64_U8((mlib_d64 *)da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, table_i); } } else { mlib_ImageLookUpMask_D64_U8(da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, src_i, table_i, dchan, schan, chan); } } else return (MLIB_FAILURE); } else if (stype == MLIB_SHORT) { if (dtype == MLIB_BYTE) mlib_ImageLookUpMask_U8_S16(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_SHORT || dtype == MLIB_USHORT) mlib_ImageLookUpMask_S16_S16(da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_INT || dtype == MLIB_FLOAT) mlib_ImageLookUpMask_S32_S16(da, dlb, sa, slb, xsize, ysize, (const mlib_s32 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_DOUBLE) mlib_ImageLookUpMask_D64_S16(da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, src_i, table_i, dchan, schan, chan); else return (MLIB_FAILURE); } else if (stype == MLIB_USHORT) { if (dtype == MLIB_BYTE) mlib_ImageLookUpMask_U8_U16(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_SHORT || dtype == MLIB_USHORT) mlib_ImageLookUpMask_S16_U16(da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_INT || dtype == MLIB_FLOAT) mlib_ImageLookUpMask_S32_U16(da, dlb, sa, slb, xsize, ysize, (const mlib_s32 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_DOUBLE) mlib_ImageLookUpMask_D64_U16(da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, src_i, table_i, dchan, schan, chan); else return (MLIB_FAILURE); } else if (stype == MLIB_INT) { if (dtype == MLIB_BYTE) mlib_ImageLookUpMask_U8_S32(da, dlb, sa, slb, xsize, ysize, (const mlib_u8 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_SHORT || dtype == MLIB_USHORT) mlib_ImageLookUpMask_S16_S32(da, dlb, sa, slb, xsize, ysize, (const mlib_s16 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_INT || dtype == MLIB_FLOAT) mlib_ImageLookUpMask_S32_S32(da, dlb, sa, slb, xsize, ysize, (const mlib_s32 **)table, dst_i, src_i, table_i, dchan, schan, chan); else if (dtype == MLIB_DOUBLE) mlib_ImageLookUpMask_D64_S32(da, dlb, sa, slb, xsize, ysize, (const mlib_d64 **)table, dst_i, src_i, table_i, dchan, schan, chan); else return (MLIB_FAILURE); } else return (MLIB_FAILURE); return (MLIB_SUCCESS); }
mlib_status __mlib_ImageChannelInsert( mlib_image *dst, const mlib_image *src, mlib_s32 cmask) { const mlib_s32 X16 = 0xF; const mlib_s32 X8 = 0x7; const mlib_s32 X4 = 0x3; const mlib_s32 D1 = MLIB_IMAGE_ONEDVECTOR; const mlib_s32 A8D1 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_ONEDVECTOR; const mlib_s32 A8D2X8 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH8X; const mlib_s32 A8D2X4 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH4X; /* pointer for pixel in src */ void *sp; /* pointer for pixel in dst */ void *dp; /* normalized channel mask */ mlib_s32 ncmask = 0; /* number of channels for src */ mlib_s32 channels; /* number of channels for dst */ mlib_s32 channeld; /* for src and dst */ mlib_s32 width, height; /* strides in bytes for src */ mlib_s32 strides; /* strides in bytes for dst */ mlib_s32 strided; mlib_s32 flags; mlib_s32 flagd; mlib_s32 dsize; mlib_s32 i, bit1count = 0; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); channels = mlib_ImageGetChannels(src); channeld = mlib_ImageGetChannels(dst); width = mlib_ImageGetWidth(src); height = mlib_ImageGetHeight(src); strides = mlib_ImageGetStride(src); strided = mlib_ImageGetStride(dst); sp = mlib_ImageGetData(src); dp = mlib_ImageGetData(dst); flags = mlib_ImageGetFlags(src); flagd = mlib_ImageGetFlags(dst); dsize = width * height; /* normalize the cmask, and count the number of bit with value 1 */ for (i = (channeld - 1); i >= 0; i--) { if (((cmask & (1 << i)) != 0) && (bit1count < channels)) { ncmask += (1 << i); bit1count++; } } /* * do not support the cases in which the number of selected channels is * less than the number of channels in the source image */ if (bit1count < channels) { return (MLIB_FAILURE); } if (((channels == 1) && (channeld == 1)) || ((channels == 2) && (channeld == 2)) || ((channels == 3) && (channeld == 3)) || ((channels == 4) && (channeld == 4))) { return (__mlib_ImageCopy(dst, src)); } switch (mlib_ImageGetType(src)) { case MLIB_BYTE: if (channels == 1) { switch (channeld) { case 2: if (((flags & D1) == 0) && ((flagd & D1) == 0) && ((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0)) { mlib_s_ImageChannelInsert_U8_12_A8D1X8( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageChannelInsert_U8_12_A8D2X8( (mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageChannelInsert_U8_12_D1( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else { mlib_s_ImageChannelInsert_U8_12((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } break; case 3: mlib_s_ImageChannelInsert_U8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, channels, channeld, width, height, ncmask); break; case 4: if (((flags & D1) == 0) && ((flagd & D1) == 0) && ((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0)) { mlib_s_ImageChannelInsert_U8_14_A8D1X8( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageChannelInsert_U8_14_A8D2X8( (mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageChannelInsert_U8_14_D1( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else { mlib_s_ImageChannelInsert_U8_14((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } break; default: return (MLIB_FAILURE); } } else { mlib_s_ImageChannelInsert_U8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, channels, channeld, width, height, ncmask); } break; case MLIB_SHORT: case MLIB_USHORT: if (channels == 1) { switch (channeld) { case 2: if (((flags & D1) == 0) && ((flagd & D1) == 0) && ((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0)) { mlib_s_ImageChannelInsert_S16_12_A8D1X4( (mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageChannelInsert_S16_12_A8D2X4( (mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageChannelInsert_S16_12_D1( (mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else { mlib_s_ImageChannelInsert_S16_12( (mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } break; case 3: mlib_s_ImageChannelInsert_S16((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, channels, channeld, width, height, ncmask); break; case 4: mlib_s_ImageChannelInsert_S16((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, channels, channeld, width, height, ncmask); break; default: return (MLIB_FAILURE); } } else { mlib_s_ImageChannelInsert_S16((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, channels, channeld, width, height, ncmask); } break; case MLIB_INT: mlib_s_ImageChannelInsert_S32((mlib_s32 *)sp, strides, (mlib_s32 *)dp, strided, channels, channeld, width, height, ncmask); break; case MLIB_FLOAT: mlib_s_ImageChannelInsert_S32((mlib_s32 *)sp, strides, (mlib_s32 *)dp, strided, channels, channeld, width, height, ncmask); break; case MLIB_DOUBLE: mlib_s_ImageChannelInsert_D64((mlib_d64 *)sp, strides, (mlib_d64 *)dp, strided, channels, channeld, width, height, ncmask); break; case MLIB_BIT: default: /* MLIB_BIT is not supported here */ return (MLIB_FAILURE); } return (MLIB_SUCCESS); }
mlib_status __mlib_ImageColorOrderedDitherMxN( mlib_image *dst, const mlib_image *src, const mlib_s32 **dmask, mlib_s32 m, mlib_s32 n, mlib_s32 scale, const void *colormap) { mlib_type stype, dtype; const mlib_s32 *dmask0, *dmask1, *dmask2, *dmask3; mlib_u8 *sl, *dl; mlib_s32 nchan, dchan, sll, dll, sw, sh, dw, dh, num_blk; mlib_s32 off, mstep, line_size, kern_size, dsize, i, j, k, fun_ind; __m128i *pbuff, *pb; mlib_s32 *p_dim; mlib_u8 *kern, *pkern; __m128i *dkern; __m128i ss, d0, d1; __m128i k0, k1; mlib_s32 step0, step1, step2, step3; mlib_d64 srange, dscale, dscale0, dscale1, dscale2, dscale3; mlib_s32 half_step0, half_step1, half_step2, half_step3; mlib_s32 v0, v1, v2, v3; __m128i _s_zero = _mm_xor_si128(_s_zero, _s_zero); line_func_type line_func; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); MLIB_IMAGE_HAVE_CHAN(dst, 1); MLIB_IMAGE_AND_COLORMAP_ARE_COMPAT(src, colormap); MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, dchan, dw, dh, dll, dl); MLIB_IMAGE_GET_ALL_PARAMS(src, stype, nchan, sw, sh, sll, sl); if (stype == MLIB_BYTE && nchan == 1 && dtype == MLIB_BIT) { return mlib_ImageColorOrderedDitherBit_MxN(dst, src, dmask, m, n, scale, colormap); } if (!(stype == MLIB_BYTE || stype == MLIB_SHORT)) { return (MLIB_FAILURE); } if (!(dtype == MLIB_BYTE || dtype == MLIB_SHORT)) { return (MLIB_FAILURE); } if (!(nchan >= 3 && nchan <= 4)) { return (MLIB_FAILURE); } if (dmask == NULL || colormap == NULL) { return (MLIB_NULLPOINTER); } if (scale <= 0) { return (MLIB_OUTOFRANGE); } fun_ind = nchan - 3; if (dtype == MLIB_SHORT) fun_ind += 2; if (stype == MLIB_SHORT) fun_ind += 4; line_func = line_func_arr[fun_ind]; num_blk = (sw + (m - 1)) / m; mstep = m * nchan; GET_STEPS; if (stype == MLIB_BYTE) { FILL_KERN(mlib_s16); dsize = (nchan * sw + 15) / 16; } else { FILL_KERN(mlib_s32); dsize = (nchan * sw + 7) / 8; } pbuff = __mlib_malloc(dsize * sizeof (__m128i)); if (pbuff == NULL) { __mlib_free(kern); return (MLIB_FAILURE); } pkern = kern; #ifdef __SUNPRO_C #pragma pipeloop(0) #endif for (j = 0; j < sh; j++) { dkern = (__m128i *)pkern; __m128i *sp = (__m128i *)sl; pb = pbuff; if (stype == MLIB_BYTE) { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif for (i = 0; i < dsize; i++) { ss = _mm_loadu_si128(sp); sp++; k0 = _mm_loadu_si128(dkern); dkern++; k1 = _mm_loadu_si128(dkern); dkern++; d0 = _mm_unpacklo_epi8(ss, _s_zero); d1 = _mm_unpackhi_epi8(ss, _s_zero); d0 = _mm_add_epi16(d0, k0); d1 = _mm_add_epi16(d1, k1); d1 = _mm_packus_epi16(d0, d1); _mm_storeu_si128(pb, d1); pb++; } } else { #ifdef __SUNPRO_C #pragma pipeloop(0) #endif for (i = 0; i < dsize; i++) { ss = _mm_loadu_si128(sp); sp++; k0 = _mm_loadu_si128(dkern); dkern++; k1 = _mm_loadu_si128(dkern); dkern++; d0 = _mm_srai_epi32( _mm_unpacklo_epi16(_s_zero, ss), 16); d1 = _mm_srai_epi32( _mm_unpackhi_epi16(_s_zero, ss), 16); d0 = _mm_add_epi32(d0, k0); d1 = _mm_add_epi32(d1, k1); d1 = _mm_packs_epi32(d0, d1); _mm_storeu_si128(pb, d1); pb++; } } pkern += line_size; if (pkern >= kern + kern_size) pkern = kern; line_func(pbuff, dl, sw, colormap); sl += sll; dl += dll; } __mlib_free(pbuff); __mlib_free(kern); return (MLIB_SUCCESS); }
mlib_status __mlib_ImageThresh1( mlib_image *dst, const mlib_image *src, const mlib_s32 *thresh, const mlib_s32 *ghigh, const mlib_s32 *glow) { mlib_s32 nchan, width, height, sstride, dstride; void *sdata, *ddata; mlib_type type; mlib_d64 cnst[6]; mlib_s32 i, t_sh, algn; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_TYPE_DSTBIT_OR_EQ(src, dst); if (thresh == NULL) return (MLIB_NULLPOINTER); if (ghigh == NULL) return (MLIB_NULLPOINTER); if (glow == NULL) return (MLIB_NULLPOINTER); MLIB_IMAGE_GET_ALL_PARAMS(dst, type, nchan, width, height, dstride, ddata); sstride = mlib_ImageGetStride(src); sdata = mlib_ImageGetData(src); if (type == MLIB_BIT) { return (mlib_ImageThresh1B(dst, src, thresh, ghigh, glow)); } else if (type == MLIB_BYTE) { mlib_u8 *pcol1 = (void *)cnst; mlib_u8 *pcol2 = (void *)(cnst + 2); mlib_u8 *pcol3 = (void *)(cnst + 4); t_sh = 0; for (i = 0; i < nchan; i++) { pcol1[i] = CLAMP_U8(thresh[i]); pcol2[i] = ghigh[i]; pcol3[i] = glow[i]; if (thresh[i] < MLIB_U8_MIN) pcol3[i] = pcol2[i]; } for (i = nchan; i < 16; i++) { pcol1[i] = pcol1[i - nchan]; pcol2[i] = pcol2[i - nchan]; pcol3[i] = pcol3[i - nchan]; } } else if (type == MLIB_SHORT) { mlib_s16 *pcol1 = (void *)cnst; mlib_s16 *pcol2 = (void *)(cnst + 2); mlib_s16 *pcol3 = (void *)(cnst + 4); t_sh = 1; for (i = 0; i < nchan; i++) { pcol1[i] = CLAMP_S16(thresh[i]); pcol2[i] = ghigh[i]; pcol3[i] = glow[i]; if (thresh[i] < MLIB_S16_MIN) pcol3[i] = pcol2[i]; } for (i = nchan; i < 8; i++) { pcol1[i] = pcol1[i - nchan]; pcol2[i] = pcol2[i - nchan]; pcol3[i] = pcol3[i - nchan]; } } else if (type == MLIB_USHORT) { mlib_s16 *pcol1 = (void *)cnst; mlib_s16 *pcol2 = (void *)(cnst + 2); mlib_s16 *pcol3 = (void *)(cnst + 4); t_sh = 1; for (i = 0; i < nchan; i++) { pcol1[i] = CLAMP_U16(thresh[i]); pcol2[i] = ghigh[i]; pcol3[i] = glow[i]; if (thresh[i] < MLIB_U16_MIN) pcol3[i] = pcol2[i]; } for (i = nchan; i < 8; i++) { pcol1[i] = pcol1[i - nchan]; pcol2[i] = pcol2[i - nchan]; pcol3[i] = pcol3[i - nchan]; } } else { mlib_s32 *pcol1 = (void *)cnst; mlib_s32 *pcol2 = (void *)(cnst + 2); mlib_s32 *pcol3 = (void *)(cnst + 4); t_sh = 2; for (i = 0; i < nchan; i++) { pcol1[i] = thresh[i]; pcol2[i] = ghigh[i]; pcol3[i] = glow[i]; } for (i = nchan; i < 4; i++) { pcol1[i] = pcol1[i - nchan]; pcol2[i] = pcol2[i - nchan]; pcol3[i] = pcol3[i - nchan]; } } if (sstride == dstride && sstride == ((nchan * width) << t_sh)) { width *= height; height = 1; } algn = (int)sdata | (int)ddata; if (height > 1) algn |= (sstride | dstride); algn &= 7; if (nchan == 3) algn = 1; sstride >>= t_sh; dstride >>= t_sh; switch (type) { case MLIB_BYTE: return mlib_v_ImageThresh1_U8_3(sdata, ddata, sstride, dstride, width, height, nchan, cnst); case MLIB_SHORT: if (algn == 0) { return mlib_v_ImageThresh1_S16_A(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } else { return mlib_v_ImageThresh1_S16_3(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } case MLIB_USHORT: if (algn == 0) { return mlib_v_ImageThresh1_U16_A(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } else { return mlib_v_ImageThresh1_U16_3(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } case MLIB_INT: if (nchan == 4) { return mlib_v_ImageThresh1_S32_2(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } if (algn == 0) { return mlib_v_ImageThresh1_S32_A(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } else { return mlib_v_ImageThresh1_S32_3(sdata, ddata, sstride, dstride, width, height, nchan, cnst); } default: return (MLIB_FAILURE); } }
mlib_status __mlib_ImageDataTypeConvert( mlib_image *dst, const mlib_image *src) { const mlib_s32 X16 = 0xF; const mlib_s32 X8 = 0x7; const mlib_s32 X4 = 0x3; const mlib_s32 D1 = MLIB_IMAGE_ONEDVECTOR; const mlib_s32 A8D1 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_ONEDVECTOR; const mlib_s32 A8D2 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X; /* data types of src and dst */ mlib_type stype, dtype; /* pointer for pixel in src */ void *sp; /* pointer for pixel in dst */ void *dp; /* number of channels for src and dst */ mlib_s32 channels; /* for src and dst */ mlib_s32 width, height; /* strides in bytes for src */ mlib_s32 strides; /* strides in bytes for dst */ mlib_s32 strided; mlib_s32 flags; mlib_s32 flagd; mlib_s32 dsize; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); stype = mlib_ImageGetType(src); dtype = mlib_ImageGetType(dst); channels = mlib_ImageGetChannels(src); width = mlib_ImageGetWidth(src); height = mlib_ImageGetHeight(src); strides = mlib_ImageGetStride(src); strided = mlib_ImageGetStride(dst); sp = mlib_ImageGetData(src); dp = mlib_ImageGetData(dst); flags = mlib_ImageGetFlags(src); flagd = mlib_ImageGetFlags(dst); width = width * channels; dsize = width * height; switch (stype) { case MLIB_BIT: switch (dtype) { case MLIB_BYTE: mlib_s_ImageDataTypeConvert_BIT_U8(src, dst); break; case MLIB_USHORT: /* BIT -> U16 equal to BIT -> S16 */ mlib_s_ImageDataTypeConvert_BIT_S16(src, dst); break; case MLIB_SHORT: mlib_s_ImageDataTypeConvert_BIT_S16(src, dst); break; case MLIB_INT: mlib_s_ImageDataTypeConvert_BIT_S32(src, dst); break; case MLIB_FLOAT: if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_s_ImageDataTypeConvert_BIT_F32_A8D1X8( (mlib_u8 *)sp, (mlib_f32 *)dp, dsize); } else if (((flagd & A8D2) == 0) && ((width & X8) == 0)) { mlib_s_ImageDataTypeConvert_BIT_F32_A8D2X8( (mlib_u8 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_s_ImageDataTypeConvert_BIT_F32_D1((mlib_u8 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_BIT_F32((mlib_u8 *) sp, strides, (mlib_f32 *)dp, strided, width, height); } break; case MLIB_DOUBLE: mlib_s_ImageDataTypeConvert_BIT_D64(src, dst); break; default: return (MLIB_FAILURE); } break; case MLIB_BYTE: switch (dtype) { case MLIB_BIT: if ((((mlib_addr)sp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_BIT_A8D1X8( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((strides & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_BIT_A8D2X8( (mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_BIT_D1( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_BIT((mlib_u8 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_USHORT: /* U8 -> U16 equal to U8 -> S16 */ if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_A8D1X8((void *)sp, (void *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_A8D2X8((void *)sp, strides, (void *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_D1((void *) sp, (void *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_S16((void *)sp, strides, (void *)dp, strided, width, height); } break; case MLIB_SHORT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_A8D1X8((void *)sp, (void *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_A8D2X8((void *)sp, strides, (void *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S16_D1((void *) sp, (void *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_S16((void *)sp, strides, (void *)dp, strided, width, height); } break; case MLIB_INT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S32_A8D1X8( (mlib_u8 *)sp, (mlib_s32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_S32_A8D2X8( (mlib_u8 *)sp, strides, (mlib_s32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_S32_D1((mlib_u8 *)sp, (mlib_s32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_S32((mlib_u8 *) sp, strides, (mlib_s32 *)dp, strided, width, height); } break; case MLIB_FLOAT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_F32_A8D1X8( (mlib_u8 *)sp, (mlib_f32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_F32_A8D2X8( (mlib_u8 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_F32_D1((mlib_u8 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_F32((mlib_u8 *) sp, strides, (mlib_f32 *)dp, strided, width, height); } break; case MLIB_DOUBLE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_D64_A8D1X8( (mlib_u8 *)sp, (mlib_d64 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U8_D64_A8D2X8( (mlib_u8 *)sp, strides, (mlib_d64 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U8_D64_D1((mlib_u8 *)sp, (mlib_d64 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U8_D64((mlib_u8 *) sp, strides, (mlib_d64 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; case MLIB_USHORT: switch (dtype) { case MLIB_BIT: if ((((mlib_addr)sp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_BIT_A8D1X8( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((strides & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_BIT_A8D2X8( (mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_BIT_D1( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_BIT((mlib_u8 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_BYTE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_U8_A8D1X8( (mlib_u16 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_U8_A8D2X8( (mlib_u16 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_U8_D1((mlib_u16 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_U8((mlib_u16 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_SHORT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_S16_A8D1X8( (mlib_u16 *)sp, (mlib_s16 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_S16_A8D2X8( (mlib_u16 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_S16_D1((mlib_u16 *)sp, (mlib_s16 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_S16((mlib_u16 *) sp, strides, (mlib_s16 *)dp, strided, width, height); } break; case MLIB_INT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_S32_A8D1X8( (mlib_u16 *)sp, (mlib_s32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_S32_A8D2X8( (mlib_u16 *)sp, strides, (mlib_s32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_S32_D1((mlib_u16 *)sp, (mlib_s32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_S32((mlib_u16 *) sp, strides, (mlib_s32 *)dp, strided, width, height); } break; case MLIB_FLOAT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_F32_A8D1X8( (mlib_u16 *)sp, (mlib_f32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_F32_A8D2X8( (mlib_u16 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_F32_D1((mlib_u16 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_F32((mlib_u16 *) sp, strides, (mlib_f32 *)dp, strided, width, height); } break; case MLIB_DOUBLE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_D64_A8D1X8( (mlib_u16 *)sp, (mlib_d64 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_U16_D64_A8D2X8( (mlib_u16 *)sp, strides, (mlib_d64 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_U16_D64_D1((mlib_u16 *)sp, (mlib_d64 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_U16_D64((mlib_u16 *) sp, strides, (mlib_d64 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; case MLIB_SHORT: switch (dtype) { case MLIB_BIT: if ((((mlib_addr)sp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_BIT_A8D1X8( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((strides & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_BIT_A8D2X8( (mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_BIT_D1( (mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_BIT((mlib_u8 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_BYTE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_U8_A8D1X8( (mlib_s16 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_U8_A8D2X8( (mlib_s16 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_U8_D1((mlib_s16 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_U8((mlib_s16 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_USHORT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_U16_A8D1X8( (mlib_s16 *)sp, (mlib_u16 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_U16_A8D2X8( (mlib_s16 *)sp, strides, (mlib_u16 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_U16_D1((mlib_s16 *)sp, (mlib_u16 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_U16((mlib_s16 *) sp, strides, (mlib_u16 *)dp, strided, width, height); } break; case MLIB_INT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_S32_A8D1X8( (mlib_s16 *)sp, (mlib_s32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_S32_A8D2X8( (mlib_s16 *)sp, strides, (mlib_s32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_S32_D1((mlib_s16 *)sp, (mlib_s32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_S32((mlib_s16 *) sp, strides, (mlib_s32 *)dp, strided, width, height); } break; case MLIB_FLOAT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_F32_A8D1X8( (mlib_s16 *)sp, (mlib_f32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_F32_A8D2X8( (mlib_s16 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_F32_D1((mlib_s16 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_F32((mlib_s16 *) sp, strides, (mlib_f32 *)dp, strided, width, height); } break; case MLIB_DOUBLE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_D64_A8D1X8( (mlib_s16 *)sp, (mlib_d64 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S16_D64_A8D2X8( (mlib_s16 *)sp, strides, (mlib_d64 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S16_D64_D1((mlib_s16 *)sp, (mlib_d64 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S16_D64((mlib_s16 *) sp, strides, (mlib_d64 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; case MLIB_INT: switch (dtype) { case MLIB_BIT: if ((((mlib_addr)sp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_A8D1X8((void *)sp, (void *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((strides & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_A8D2X8((void *)sp, strides, (void *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_D1((void *)sp, (void *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_BIT((void *)sp, strides, (void *)dp, strided, width, height); } break; case MLIB_BYTE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_U8_A8D1X8( (mlib_s32 *)sp, (mlib_u8 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_U8_A8D2X8( (mlib_s32 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_U8_D1((mlib_s32 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_U81((mlib_s32 *) sp, strides, (mlib_u8 *)dp, strided, width, height); } break; case MLIB_USHORT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_U16_A8D1X8( (mlib_s32 *)sp, (mlib_u16 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_U16_A8D2X8( (mlib_s32 *)sp, strides, (mlib_u16 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_U16_D1((mlib_s32 *)sp, (mlib_u16 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_U16((mlib_s32 *) sp, strides, (mlib_u16 *)dp, strided, width, height); } break; case MLIB_SHORT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_S16_A8D1X8( (mlib_s32 *)sp, (mlib_s16 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_S16_A8D2X8( (mlib_s32 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_S16_D1((mlib_s32 *)sp, (mlib_s16 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_S16((mlib_s32 *) sp, strides, (mlib_s16 *)dp, strided, width, height); } break; case MLIB_FLOAT: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_F32_A8D1X8( (mlib_s32 *)sp, (mlib_f32 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_F32_A8D2X8( (mlib_s32 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_F32_D1((mlib_s32 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_F32((mlib_s32 *) sp, strides, (mlib_f32 *)dp, strided, width, height); } break; case MLIB_DOUBLE: if ((((mlib_addr)sp & X16) == 0) && (((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_D64_A8D1X8( (mlib_s32 *)sp, (mlib_d64 *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_D64_A8D2X8( (mlib_s32 *)sp, strides, (mlib_d64 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_D64_D1((mlib_s32 *)sp, (mlib_d64 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_D64((mlib_s32 *) sp, strides, (mlib_d64 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; case MLIB_FLOAT: switch (dtype) { case MLIB_BIT: /* F32 -> BIT equal to S32 -> BIT */ if ((((mlib_addr)sp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_A8D1X8((void *)sp, (void *)dp, dsize); } else if (((((mlib_addr)sp) & X16) == 0) && ((strides & X16) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_A8D2X8((void *)sp, strides, (void *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_S32_BIT_D1((void *)sp, (void *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_S32_BIT((void *)sp, strides, (void *)dp, strided, width, height); } break; case MLIB_BYTE: mlib_s_ImageDataTypeConvert_F32_U8(src, dst); break; case MLIB_USHORT: mlib_s_ImageDataTypeConvert_F32_U16(src, dst); break; case MLIB_SHORT: mlib_s_ImageDataTypeConvert_F32_S16(src, dst); break; case MLIB_INT: mlib_s_ImageDataTypeConvert_F32_S32(src, dst); break; case MLIB_DOUBLE: if ((((mlib_addr)dp & X16) == 0) && ((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_F32_D64_A8D1X8( (mlib_f32 *)sp, (mlib_d64 *)dp, dsize); } else if (((((mlib_addr)dp) & X16) == 0) && ((strides & X16) == 0) && ((strided & X16) == 0)) { mlib_s_ImageDataTypeConvert_F32_D64_A8D2X8( (mlib_f32 *)sp, strides, (mlib_d64 *)dp, strided, width, height); } else if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_F32_D64_D1((mlib_f32 *)sp, (mlib_d64 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_F32_D64((mlib_f32 *) sp, strides, (mlib_d64 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; case MLIB_DOUBLE: switch (dtype) { case MLIB_BIT: mlib_s_ImageDataTypeConvert_D64_BIT(src, dst); break; case MLIB_BYTE: mlib_s_ImageDataTypeConvert_D64_U8(src, dst); break; case MLIB_USHORT: mlib_s_ImageDataTypeConvert_D64_U16(src, dst); break; case MLIB_SHORT: mlib_s_ImageDataTypeConvert_D64_S16(src, dst); break; case MLIB_INT: mlib_s_ImageDataTypeConvert_D64_S32(src, dst); break; case MLIB_FLOAT: if (((flags & D1) == 0) && ((flagd & D1) == 0)) { mlib_s_ImageDataTypeConvert_D64_F32_D1( (mlib_d64 *)sp, (mlib_f32 *)dp, dsize); } else { mlib_s_ImageDataTypeConvert_D64_F32( (mlib_d64 *)sp, strides, (mlib_f32 *)dp, strided, width, height); } break; default: return (MLIB_FAILURE); } break; default: return (MLIB_FAILURE); } return (MLIB_SUCCESS); }
mlib_status __mlib_ImageChannelCopy( mlib_image *dst, const mlib_image *src, mlib_s32 cmask) { mlib_type dtype; mlib_s32 src_stride, dst_stride, src_width, src_height, nchannels; mlib_s32 mask; void *sa, *da; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); dtype = mlib_ImageGetType(src); nchannels = mlib_ImageGetChannels(src); src_stride = mlib_ImageGetStride(src); dst_stride = mlib_ImageGetStride(dst); src_height = mlib_ImageGetHeight(src); src_width = mlib_ImageGetWidth(src); sa = mlib_ImageGetData(src); da = mlib_ImageGetData(dst); mask = cmask & ((1 << nchannels) - 1); if (!mask) return (MLIB_SUCCESS); if (((nchannels == 1) && (cmask == 1)) || ((nchannels == 2) && (cmask == 3)) || ((nchannels == 3) && (cmask == 7)) || ((nchannels == 4) && (cmask == 15))) { return (__mlib_ImageCopy(dst, src)); } else { mlib_s32 src_width_nchannels = src_width * nchannels; if (src_width_nchannels == src_stride && src_width_nchannels == dst_stride) { src_width *= src_height; src_height = 1; } if (dtype == MLIB_BYTE) { if (nchannels == 3) { mlib_c_ImageChannelCopy_u8_3((mlib_u8 *)sa, src_stride, (mlib_u8 *)da, dst_stride, src_width, src_height, mask); return (MLIB_SUCCESS); } else { mlib_c_ImageChannelCopy_u8_24((mlib_u8 *)sa, src_stride, (mlib_u8 *)da, dst_stride, nchannels, src_width, src_height, mask); return (MLIB_SUCCESS); } } else if ((dtype == MLIB_SHORT) || (dtype == MLIB_USHORT)) { if (nchannels == 4) { mlib_c_ImageChannelCopy_s16_4((mlib_s16 *)sa, src_stride, (mlib_s16 *)da, dst_stride, src_width, src_height, mask); return (MLIB_SUCCESS); } else if (nchannels == 3) { mlib_c_ImageChannelCopy_s16_3((mlib_s16 *)sa, src_stride, (mlib_s16 *)da, dst_stride, src_width, src_height, mask); return (MLIB_SUCCESS); } else if (nchannels == 2) { mlib_c_ImageChannelCopy_s16_2((mlib_s16 *)sa, src_stride, (mlib_s16 *)da, dst_stride, src_width, src_height, mask); return (MLIB_SUCCESS); } return (MLIB_SUCCESS); } else if ((dtype == MLIB_INT) || (dtype == MLIB_FLOAT)) { mlib_c_ImageChannelCopy_s32((mlib_s32 *)sa, src_stride, (mlib_s32 *)da, dst_stride, nchannels, src_width, src_height, mask); return (MLIB_SUCCESS); } else if (dtype == MLIB_DOUBLE) { mlib_c_ImageChannelCopy_d64((mlib_d64 *)sa, src_stride, (mlib_d64 *)da, dst_stride, nchannels, src_width, src_height, mask); return (MLIB_SUCCESS); } else { return (MLIB_FAILURE); } } }
mlib_status __mlib_ImageCopy( 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; /* bit offset of src */ mlib_s32 s_offset; /* bit offset of dst */ mlib_s32 d_offset; /* stride in bytes in src */ mlib_s32 stride; /* stride in bytes in dst */ mlib_s32 dstride; /* indices for x, y */ mlib_s32 i, j; mlib_s32 size; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_CHAN_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); height = mlib_ImageGetHeight(dst); sa = (mlib_u8 *)mlib_ImageGetData(src); da = (mlib_u8 *)mlib_ImageGetData(dst); switch (mlib_ImageGetType(dst)) { case MLIB_BIT: if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst)) { size = height * (width >> 3); if ((size & 0x3f) == 0 && !mlib_ImageIsNotAligned64(src) && !mlib_ImageIsNotAligned64(dst)) { mlib_v_ImageCopy_blk(sa, da, size); return (MLIB_SUCCESS); } if (!mlib_ImageIsNotAligned8(src) && !mlib_ImageIsNotAligned8(dst) && ((size & 7) == 0)) { mlib_v_ImageCopy_a1((mlib_d64 *)sa, (mlib_d64 *)da, size >> 3); } else {
mlib_status mlib_ImageLookUp(mlib_image *dst, const mlib_image *src, const void **table) { mlib_s32 slb, dlb, xsize, ysize, nchan, ichan, bitoff_src; mlib_type stype, dtype; void *sa, *da; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); MLIB_IMAGE_CHAN_SRC1_OR_EQ(src, dst); stype = mlib_ImageGetType(src); dtype = mlib_ImageGetType(dst); ichan = mlib_ImageGetChannels(src); nchan = mlib_ImageGetChannels(dst); xsize = mlib_ImageGetWidth(src); ysize = mlib_ImageGetHeight(src); slb = mlib_ImageGetStride(src); dlb = mlib_ImageGetStride(dst); sa = mlib_ImageGetData(src); da = mlib_ImageGetData(dst); if (ichan == nchan) { if (dtype == MLIB_BYTE) { if (stype == MLIB_BYTE) { CALL_FUNC(U8, U8, mlib_u8); } else if (stype == MLIB_SHORT) { CALL_FUNC(S16, U8, mlib_u8); } else if (stype == MLIB_USHORT) { CALL_FUNC(U16, U8, mlib_u8); } else if (stype == MLIB_INT) { CALL_FUNC(S32, U8, mlib_u8); } else if (stype == MLIB_BIT) { if (nchan != 1) return MLIB_FAILURE; bitoff_src = mlib_ImageGetBitOffset(src); /* bits to first byte */ return mlib_ImageLookUp_Bit_U8_1(sa, slb, da, dlb, xsize, ysize, nchan, bitoff_src, (const mlib_u8 **) table); } } else if (dtype == MLIB_SHORT) { if (stype == MLIB_BYTE) { CALL_FUNC(U8, S16, mlib_s16); } else if (stype == MLIB_SHORT) { CALL_FUNC(S16, S16, mlib_s16); } else if (stype == MLIB_USHORT) { CALL_FUNC(U16, S16, mlib_s16); } else if (stype == MLIB_INT) { CALL_FUNC(S32, S16, mlib_s16); } } else if (dtype == MLIB_USHORT) { if (stype == MLIB_BYTE) { CALL_FUNC(U8, U16, mlib_u16); } else if (stype == MLIB_SHORT) { CALL_FUNC(S16, U16, mlib_u16); } else if (stype == MLIB_USHORT) { CALL_FUNC(U16, U16, mlib_u16); } else if (stype == MLIB_INT) { CALL_FUNC(S32, U16, mlib_u16); } } else if (dtype == MLIB_INT) { if (stype == MLIB_BYTE) { CALL_FUNC(U8, S32, mlib_s32); } else if (stype == MLIB_SHORT) { CALL_FUNC(S16, S32, mlib_s32); } else if (stype == MLIB_USHORT) { CALL_FUNC(U16, S32, mlib_s32); } else if (stype == MLIB_INT) { if ((nchan >= 1) && (nchan <= 4)) { mlib_v_ImageLookUp_S32_S32(sa, slb, da, dlb, xsize, ysize, (const mlib_s32 **) table, nchan); return MLIB_SUCCESS; } else { return MLIB_FAILURE; } } } else if (dtype == MLIB_FLOAT) { if (stype == MLIB_BYTE) { CALL_FUNC(U8, S32, mlib_s32); } else if (stype == MLIB_SHORT) { CALL_FUNC(S16, S32, mlib_s32); } else if (stype == MLIB_USHORT) { CALL_FUNC(U16, S32, mlib_s32); } else if (stype == MLIB_INT) { if ((nchan >= 1) && (nchan <= 4)) { mlib_v_ImageLookUp_S32_S32(sa, slb, da, dlb, xsize, ysize, (const mlib_s32 **) table, nchan); return MLIB_SUCCESS; } else { return MLIB_FAILURE; } } } else if (dtype == MLIB_DOUBLE) { if (stype == MLIB_BYTE) { mlib_ImageLookUp_U8_D64(sa, slb, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_SHORT) { mlib_ImageLookUp_S16_D64(sa, slb / 2, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_USHORT) { mlib_ImageLookUp_U16_D64(sa, slb / 2, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_INT) { mlib_ImageLookUp_S32_D64(sa, slb / 4, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } } } else if (ichan == 1) { if (dtype == MLIB_BYTE) { if (stype == MLIB_BYTE) { CALL_SIFUNC(U8, U8, mlib_u8); } else if (stype == MLIB_SHORT) { CALL_SIFUNC(S16, U8, mlib_u8); } else if (stype == MLIB_USHORT) { CALL_SIFUNC(U16, U8, mlib_u8); } else if (stype == MLIB_INT) { CALL_SIFUNC(S32, U8, mlib_u8); } else if (stype == MLIB_BIT) { bitoff_src = mlib_ImageGetBitOffset(src); /* bits to first byte */ if (nchan == 2) { return mlib_ImageLookUp_Bit_U8_2(sa, slb, da, dlb, xsize, ysize, nchan, bitoff_src, (const mlib_u8 **) table); } else if (nchan == 3) { return mlib_ImageLookUp_Bit_U8_3(sa, slb, da, dlb, xsize, ysize, nchan, bitoff_src, (const mlib_u8 **) table); } else { /* (nchan == 4) */ return mlib_ImageLookUp_Bit_U8_4(sa, slb, da, dlb, xsize, ysize, nchan, bitoff_src, (const mlib_u8 **) table); } } } else if (dtype == MLIB_SHORT) { if (stype == MLIB_BYTE) { CALL_SIFUNC(U8, S16, mlib_s16); } else if (stype == MLIB_SHORT) { CALL_SIFUNC(S16, S16, mlib_s16); } else if (stype == MLIB_USHORT) { CALL_SIFUNC(U16, S16, mlib_s16); } else if (stype == MLIB_INT) { CALL_SIFUNC(S32, S16, mlib_s16); } } else if (dtype == MLIB_USHORT) { if (stype == MLIB_BYTE) { CALL_SIFUNC(U8, U16, mlib_u16); } else if (stype == MLIB_SHORT) { CALL_SIFUNC(S16, U16, mlib_u16); } else if (stype == MLIB_USHORT) { CALL_SIFUNC(U16, U16, mlib_u16); } else if (stype == MLIB_INT) { CALL_SIFUNC(S32, U16, mlib_u16); } } else if (dtype == MLIB_INT) { if (stype == MLIB_BYTE) { CALL_SIFUNC(U8, S32, mlib_s32); } else if (stype == MLIB_SHORT) { CALL_SIFUNC(S16, S32, mlib_s32); } else if (stype == MLIB_USHORT) { CALL_SIFUNC(U16, S32, mlib_s32); } else if (stype == MLIB_INT) { if ((nchan >= 1) && (nchan <= 4)) { mlib_v_ImageLookUpSI_S32_S32(sa, slb, da, dlb, xsize, ysize, (const mlib_s32 **) table, nchan); return MLIB_SUCCESS; } else { return MLIB_FAILURE; } } } else if (dtype == MLIB_FLOAT) { if (stype == MLIB_BYTE) { CALL_SIFUNC(U8, S32, mlib_s32); } else if (stype == MLIB_SHORT) { CALL_SIFUNC(S16, S32, mlib_s32); } else if (stype == MLIB_USHORT) { CALL_SIFUNC(U16, S32, mlib_s32); } else if (stype == MLIB_INT) { if ((nchan >= 1) && (nchan <= 4)) { mlib_v_ImageLookUpSI_S32_S32(sa, slb, da, dlb, xsize, ysize, (const mlib_s32 **) table, nchan); return MLIB_SUCCESS; } else { return MLIB_FAILURE; } } } else if (dtype == MLIB_DOUBLE) { if (stype == MLIB_BYTE) { mlib_ImageLookUpSI_U8_D64(sa, slb, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_SHORT) { mlib_ImageLookUpSI_S16_D64(sa, slb / 2, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_USHORT) { mlib_ImageLookUpSI_U16_D64(sa, slb / 2, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } else if (stype == MLIB_INT) { mlib_ImageLookUpSI_S32_D64(sa, slb / 4, da, dlb / 8, xsize, ysize, nchan, (const mlib_d64 **) table); return MLIB_SUCCESS; } } } return MLIB_FAILURE; }
mlib_status mlib_ImageChannelExtract(mlib_image *dst, mlib_image *src, mlib_s32 cmask) #endif { const mlib_s32 X8 = 0x7; const mlib_s32 X4 = 0x3; const mlib_s32 X2 = 0x1; const mlib_s32 A8D1 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_ONEDVECTOR; const mlib_s32 A8D2X8 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH8X; const mlib_s32 A8D2X4 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH4X; const mlib_s32 A8D2X2 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH2X; void *sp; /* pointer for pixel in src */ void *dp; /* pointer for pixel in dst */ mlib_s32 ncmask = 0; /* normalized channel mask */ mlib_s32 channels; /* number of channels for src */ mlib_s32 channeld; /* number of channels for dst */ mlib_s32 width, height; /* for src and dst */ mlib_s32 strides; /* strides in bytes for src */ mlib_s32 strided; /* strides in bytes for dst */ mlib_s32 flags; mlib_s32 flagd; mlib_s32 dsize; int delta0 = 0; /* offset of first selected channel */ int count1 = 0; /* number of channels in first group */ int i, bit1count = 0; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_TYPE_EQUAL(src, dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); channels = mlib_ImageGetChannels(src); channeld = mlib_ImageGetChannels(dst); width = mlib_ImageGetWidth(src); height = mlib_ImageGetHeight(src); strides = mlib_ImageGetStride(src); strided = mlib_ImageGetStride(dst); sp = mlib_ImageGetData(src); dp = mlib_ImageGetData(dst); flags = mlib_ImageGetFlags(src); flagd = mlib_ImageGetFlags(dst); dsize = width * height; /* normalize the cmask, and count the number of bit with value 1 */ for (i = (channels - 1); i >= 0; i--) { if (((cmask & (1 << i)) != 0) && (bit1count < channeld)) { ncmask += (1 << i); bit1count++; } } /* do not support the cases in which the number of selected channels is * less than the nubmber of channels in the destination image */ if (bit1count < channeld) { return MLIB_FAILURE; } if (channels == channeld) { #ifdef MLIB_TEST mlib_v_ImageCopy(dst, src); #else mlib_ImageCopy(dst, src); #endif return MLIB_SUCCESS; } switch (mlib_ImageGetType(src)) { case MLIB_BYTE: if (channeld == 1) { switch (channels) { case 2: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_v_ImageChannelExtract_U8_21_A8D1X8((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) { mlib_v_ImageChannelExtract_U8_21_A8D2X8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_U8_21_D1((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_U8_21((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; case 3: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_v_ImageChannelExtract_U8_31_A8D1X8((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) { mlib_v_ImageChannelExtract_U8_31_A8D2X8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_U8_31_D1((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_U8_31((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; case 4: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_v_ImageChannelExtract_U8_41_A8D1X8((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) { mlib_v_ImageChannelExtract_U8_41_A8D2X8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_U8_41_D1((mlib_u8 *)sp, (mlib_u8 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_U8_41((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; default: return MLIB_FAILURE; } } else if ((channels == 4) && (channeld == 3) && (ncmask == 7)) { if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_v_ImageChannelExtract_U8_43R_A8D1X8((mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) { mlib_v_ImageChannelExtract_U8_43R_A8D2X8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_U8_43R_D1((mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_v_ImageChannelExtract_U8_43R((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } return MLIB_SUCCESS; } else if ((channels == 4) && (channeld == 3) && (ncmask == 14)) { if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X8) == 0)) { mlib_v_ImageChannelExtract_U8_43L_A8D1X8((mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) { mlib_v_ImageChannelExtract_U8_43L_A8D2X8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_U8_43L_D1((mlib_u8 *)sp, (mlib_u8 *)dp, dsize); } else { mlib_v_ImageChannelExtract_U8_43L((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, width, height); } return MLIB_SUCCESS; } break; case MLIB_SHORT: if (channeld == 1) { switch (channels) { case 2: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X4) == 0)) { mlib_v_ImageChannelExtract_S16_21_A8D1X4((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) { mlib_v_ImageChannelExtract_S16_21_A8D2X4((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_S16_21_D1((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_S16_21((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; case 3: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X4) == 0)) { mlib_v_ImageChannelExtract_S16_31_A8D1X4((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) { mlib_v_ImageChannelExtract_S16_31_A8D2X4((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_S16_31_D1((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_S16_31((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; case 4: if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X4) == 0)) { mlib_v_ImageChannelExtract_S16_41_A8D1X4((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) { mlib_v_ImageChannelExtract_S16_41_A8D2X4((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_S16_41_D1((mlib_s16 *)sp, (mlib_s16 *)dp, dsize, ncmask); } else { mlib_v_ImageChannelExtract_S16_41((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height, ncmask); } return MLIB_SUCCESS; default: return MLIB_FAILURE; } } else if ((channels == 4) && (channeld == 3) && (ncmask == 7)) { if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X4) == 0)) { mlib_v_ImageChannelExtract_S16_43R_A8D1X4((mlib_s16 *)sp, (mlib_s16 *)dp, dsize); } else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) { mlib_v_ImageChannelExtract_S16_43R_A8D2X4((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_S16_43R_D1((mlib_s16 *)sp, (mlib_s16 *)dp, dsize); } else { mlib_v_ImageChannelExtract_S16_43R((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } return MLIB_SUCCESS; } else if ((channels == 4) && (channeld == 3) && (ncmask == 14)) { if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) && ((dsize & X4) == 0)) { mlib_v_ImageChannelExtract_S16_43L_A8D1X4((mlib_s16 *)sp, (mlib_s16 *)dp, dsize); } else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) { mlib_v_ImageChannelExtract_S16_43L_A8D2X4((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) && ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) { mlib_v_ImageChannelExtract_S16_43L_D1((mlib_s16 *)sp, (mlib_s16 *)dp, dsize); } else { mlib_v_ImageChannelExtract_S16_43L((mlib_s16 *)sp, strides, (mlib_s16 *)dp, strided, width, height); } return MLIB_SUCCESS; } break; } /***************************************************************/ /* From C version */ for (i = (channels - 1); i >= 0; i--) { if (!(ncmask & (1 << i))) delta0++; else break; } for (; i >= 0; i--) { if (ncmask & (1 << i)) count1++; else break; } switch (mlib_ImageGetType(src)) { case MLIB_BYTE: { mlib_u8 *sl = (mlib_u8 *)sp + delta0; mlib_u8 *dl = (mlib_u8 *)dp; switch (channels*10 + channeld) { case 32: mlib_v_ImageChannelExtract_U8_3_2(sl, strides, dl, strided, width, height, count1); return MLIB_SUCCESS; case 42: if (ncmask == 0xA || ncmask == 0x5) { /* mask 1010 or 0101 */ mlib_v_ImageChannelExtract_U8_2_1(sl, strides, dl, strided, 2*width, height); return MLIB_SUCCESS; } mlib_v_ImageChannelExtract_U8_4_2(sl, strides, dl, strided, width, height, count1); return MLIB_SUCCESS; case 43: mlib_v_ImageChannelExtract_U8((mlib_u8 *)sp, strides, (mlib_u8 *)dp, strided, channels, channeld, width, height, ncmask); return MLIB_SUCCESS; default: return MLIB_FAILURE; } } case MLIB_SHORT: mlib_v_ImageChannelExtract_S16((mlib_u16 *)sp, strides, (mlib_u16 *)dp, strided, channels, channeld, width, height, ncmask); break; case MLIB_INT: case MLIB_FLOAT: { mlib_f32 *sl = (mlib_f32 *)sp + delta0; mlib_f32 *dl = (mlib_f32 *)dp; strides /= 4; strided /= 4; switch (channels*10 + channeld) { case 21: mlib_v_ImageChannelExtract_32_2_1(sl, strides, dl, strided, width, height); return MLIB_SUCCESS; case 31: mlib_v_ImageChannelExtract_32_3_1(sl, strides, dl, strided, width, height); return MLIB_SUCCESS; case 32: mlib_v_ImageChannelExtract_32_3_2(sl, strides, dl, strided, width, height, count1); return MLIB_SUCCESS; case 41: mlib_v_ImageChannelExtract_32_4_1(sl, strides, dl, strided, width, height); return MLIB_SUCCESS; case 42: if (ncmask == 0xA || ncmask == 0x5) { /* mask 1010 or 0101 */ mlib_v_ImageChannelExtract_32_2_1(sl, strides, dl, strided, 2*width, height); } else { mlib_v_ImageChannelExtract_32_4_2(sl, strides, dl, strided, width, height, count1); } return MLIB_SUCCESS; case 43: mlib_v_ImageChannelExtract_32_4_3(sl, strides, dl, strided, width, height, count1); return MLIB_SUCCESS; default: return MLIB_FAILURE; } } case MLIB_DOUBLE: mlib_v_ImageChannelExtract_D64((mlib_d64 *)sp, strides, (mlib_d64 *)dp, strided, channels, channeld, width, height, ncmask); break; case MLIB_BIT: default: return MLIB_FAILURE; /* MLIB_BIT is not supported here */ } return MLIB_SUCCESS; }
mlib_status __mlib_ImageScale_Fp( mlib_image *dst, const mlib_image *src, const mlib_d64 *alpha, const mlib_d64 *beta) { mlib_type stype, dtype; mlib_s32 slb, dlb, xsize, ysize, nchan; mlib_u8 *psrc, *pdst; mlib_d64 v; mlib_d64 da[4], db[4]; mlib_s32 i, j, k; MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_CHECK(src); MLIB_IMAGE_SIZE_EQUAL(dst, src); MLIB_IMAGE_CHAN_EQUAL(dst, src); MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, nchan, xsize, ysize, dlb, pdst); stype = mlib_ImageGetType(src); slb = mlib_ImageGetStride(src); psrc = mlib_ImageGetData(src); if (stype == MLIB_FLOAT) { if (dtype == MLIB_BYTE) { SCALEHEAD(f32, u8); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(f32, u8); } else if (dtype == MLIB_SHORT) { SCALEHEAD(f32, s16); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(f32, s16); } else if (dtype == MLIB_USHORT) { SCALEHEAD(f32, u16); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(f32, u16); } else if (dtype == MLIB_INT) { SCALEHEAD(f32, s32); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(f32, s32); } else if (dtype == MLIB_FLOAT) { mlib_ImageScale_Fp_F32_F32(pdst, psrc, xsize, ysize, nchan, slb, dlb, alpha, beta); return (MLIB_SUCCESS); } else if (dtype == MLIB_DOUBLE) { SCALEHEAD(f32, d64); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(f32, d64); } } else if (stype == MLIB_DOUBLE) { if (dtype == MLIB_BYTE) { SCALEHEAD(d64, u8); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, u8); } else if (dtype == MLIB_SHORT) { SCALEHEAD(d64, s16); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, s16); } else if (dtype == MLIB_USHORT) { SCALEHEAD(d64, u16); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, u16); } else if (dtype == MLIB_INT) { SCALEHEAD(d64, s32); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, s32); } else if (dtype == MLIB_FLOAT) { SCALEHEAD(d64, f32); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, f32); } else if (dtype == MLIB_DOUBLE) { SCALEHEAD(d64, d64); #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ SCALE(d64, d64); } } return (MLIB_FAILURE); }
mlib_status __mlib_ImageColorOrderedDither8x8( mlib_image *dst, const mlib_image *src, const mlib_s32 *dmask, mlib_s32 scale, const void *colormap) { mlib_status stat; mlib_s32 src_nch; mlib_type src_dtype, dst_dtype; mlib_s32 method; MLIB_IMAGE_CHECK(src); MLIB_IMAGE_CHECK(dst); MLIB_IMAGE_SIZE_EQUAL(src, dst); MLIB_IMAGE_HAVE_CHAN(dst, 1); MLIB_IMAGE_AND_COLORMAP_ARE_COMPAT(src, colormap); if (dmask == NULL || colormap == NULL) return (MLIB_NULLPOINTER); src_dtype = mlib_ImageGetType(src); dst_dtype = mlib_ImageGetType(dst); src_nch = mlib_ImageGetChannels(src); if (scale < 0) { stat = MLIB_OUTOFRANGE; } else { method = mlib_ImageGetMethod(colormap); if (method != LUT_COLOR_CUBE_SEARCH) { if (method == LUT_COLOR_DIMENSIONS) { mlib_s32 dmask1[64], dmask2[64], dmask3[64], *pmask[4]; mlib_s32 i, j; for (j = 0; j < 8; j++) { for (i = 0; i < 8; i++) { dmask3[8 * (7 - j) + (7 - i)] = dmask2[8 * (7 - j) + i] = dmask1[8 * j + (7 - i)] = dmask[8 * j + i]; } } pmask[0] = (void *)dmask; pmask[1] = dmask1; pmask[2] = dmask2; pmask[3] = dmask3; return __mlib_ImageColorOrderedDitherMxN(dst, src, (const mlib_s32 **)pmask, 8, 8, scale, colormap); } return (MLIB_FAILURE); } else { switch (src_dtype) { case MLIB_BYTE: switch (dst_dtype) { case MLIB_BYTE: switch (src_nch) { case 3: stat = FUNC_NAME(3_8_8) (src, dst, dmask, scale, colormap); break; case 4: stat = FUNC_NAME(4_8_8) (src, dst, dmask, scale, colormap); break; default: stat = MLIB_FAILURE; break; } break; case MLIB_SHORT: /* * convert wid from * pixels to bytes */ switch (src_nch) { case 3: stat = FUNC_NAME(3_8_16) (src, dst, dmask, scale, colormap); break; case 4: stat = FUNC_NAME(4_8_16) (src, dst, dmask, scale, colormap); break; default: stat = MLIB_FAILURE; break; } break; case MLIB_BIT: default: stat = MLIB_FAILURE; break; } break; case MLIB_SHORT: /* * convert wid from pixels to * bytes */ switch (dst_dtype) { case MLIB_BYTE: switch (src_nch) { case 3: stat = FUNC_NAME(3_16_8) (src, dst, dmask, scale, colormap); break; case 4: stat = FUNC_NAME(4_16_8) (src, dst, dmask, scale, colormap); break; default: stat = MLIB_FAILURE; break; } break; case MLIB_SHORT: /* * convert wid from * pixels to bytes */ switch (src_nch) { case 3: stat = FUNC_NAME(3_16_16) (src, dst, dmask, scale, colormap); break; case 4: stat = FUNC_NAME(4_16_16) (src, dst, dmask, scale, colormap); break; default: stat = MLIB_FAILURE; break; } break; case MLIB_BIT: default: stat = MLIB_FAILURE; break; } break; case MLIB_BIT: default: stat = MLIB_FAILURE; break; } } } return (stat); }
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 {