예제 #1
0
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_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);
}
예제 #3
0
mlib_status
__mlib_ImageConstAdd(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_s32 *c)
{
	mlib_s32 slb, dlb, xsize, ysize, dsize, nchan, flags, flagd, i;
	mlib_s32 c_new[4];
	mlib_type dtype;
	void *sa, *da;
	mlib_d64 dc, dc1, dc2;
	const mlib_s32 A8D1 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_ONEDVECTOR;
	const mlib_s32 A8D2 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X;

	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_CHECK(src);
	MLIB_IMAGE_FULL_EQUAL(dst, src);

	if (c == NULL)
		return (MLIB_FAILURE);

	MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, nchan, xsize, ysize, dlb, da);
	slb = mlib_ImageGetStride(src);
	sa = mlib_ImageGetData(src);
	flags = mlib_ImageGetFlags(src);
	flagd = mlib_ImageGetFlags(dst);

	xsize = xsize * nchan;
	dsize = xsize * ysize;

	if ((dtype == MLIB_INT) || (dtype == MLIB_USHORT)) {
		if (dtype == MLIB_USHORT) {
			for (i = 0; i < nchan; i++) {
				c_new[i] = c[i];

				if (c[i] > MLIB_U16_MAX)
					c_new[i] = MLIB_U16_MAX;
				else if (c[i] < 2 * MLIB_S16_MIN)
					c_new[i] = 2 * MLIB_S16_MIN;
				c_new[i] *= 2;
			}

			c = c_new;
		}

		switch (nchan) {
		case 1:
			dc1 = dc2 = vis_to_double_dup(c[0]);
			break;

		case 2:
			dc1 = dc2 = vis_to_double(c[0], c[1]);
			break;

		case 3:
			dc1 = vis_to_double(c[0], c[1]);
			dc2 = vis_to_double(c[2], c[0]);
			break;

		case 4:
			dc1 = vis_to_double(c[0], c[1]);
			dc2 = vis_to_double(c[2], c[3]);
			break;

		default:
			return (MLIB_FAILURE);
		}
	} else {
		if (dtype == MLIB_BYTE) {
			for (i = 0; i < nchan; i++) {
				c_new[i] = c[i];

				if (c[i] > MLIB_U8_MAX)
					c_new[i] = MLIB_U8_MAX;
				else if (c[i] < MLIB_S16_MIN)
					c_new[i] = MLIB_S16_MIN;
			}

			c = c_new;
		}

		switch (nchan) {
		case 1:
			dc = vis_to_double_dup((c[0] << 16) | (c[0] & 0xffff));
			break;

		case 2:
			dc = vis_to_double_dup((c[0] << 16) | (c[1] & 0xffff));
			break;

		case 3:
			dc = vis_to_double((c[0] << 16) | (c[1] & 0xffff),
			    (c[2] << 16) | (c[0] & 0xffff));
			break;

		case 4:
			dc = vis_to_double((c[0] << 16) | (c[1] & 0xffff),
			    (c[2] << 16) | (c[3] & 0xffff));
			break;

		default:
			return (MLIB_FAILURE);
		}
	}

	if (dtype == MLIB_BYTE) {

/* 3 channels */
		if (nchan == 3) {
			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0)) {

				mlib_v_ImageConstAdd_U8_3_A8D1((mlib_u8 *)sa,
				    (mlib_u8 *)da, dsize, dc);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_U8_3_A8D2((mlib_u8 *)sa,
				    slb, (mlib_u8 *)da, dlb, xsize, ysize, dc);
			} else {

				mlib_v_ImageConstAdd_U8_3((mlib_u8 *)sa, slb,
				    (mlib_u8 *)da, dlb, xsize, ysize, dc);
			}
		} else {
/* 1, 2 or 4 channels */
			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
			    ((dsize & 7) == 0)) {

				mlib_v_ImageConstAdd_U8_124_A8D1X8((mlib_u8 *)
				    sa, (mlib_u8 *)da, dsize, dc);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_U8_124_A8D2((mlib_u8 *)sa,
				    slb, (mlib_u8 *)da, dlb, xsize, ysize, dc);
			} else {

				mlib_v_ImageConstAdd_U8_124((mlib_u8 *)sa, slb,
				    (mlib_u8 *)da, dlb, xsize, ysize, dc);
			}
		}

		return (MLIB_SUCCESS);

	} else if (dtype == MLIB_SHORT) {

/* 3 channels */
		if (nchan == 3) {
			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0)) {

				mlib_v_ImageConstAdd_S16_3_A8D1((mlib_s16 *)sa,
				    (mlib_s16 *)da, dsize, dc);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_S16_3_A8D2((mlib_s16 *)sa,
				    slb, (mlib_s16 *)da, dlb, xsize, ysize, dc);
			} else {

				mlib_v_ImageConstAdd_S16_3((mlib_s16 *)sa, slb,
				    (mlib_s16 *)da, dlb, xsize, ysize, dc);
			}
		} else {
/* 1, 2 or 4 channels */

			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
			    ((dsize & 3) == 0)) {

				mlib_v_ImageConstAdd_S16_124_A8D1X4((mlib_s16 *)
				    sa, (mlib_s16 *)da, dsize, dc);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_S16_124_A8D2((mlib_s16 *)
				    sa, slb, (mlib_s16 *)da, dlb, xsize, ysize,
				    dc);
			} else {

				mlib_v_ImageConstAdd_S16_124((mlib_s16 *)sa,
				    slb, (mlib_s16 *)da, dlb, xsize, ysize, dc);
			}
		}

		return (MLIB_SUCCESS);

	} else if (dtype == MLIB_USHORT) {

/* 3 channels */
		if (nchan == 3) {
			mlib_v_ImageConstAdd_U16_3((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize, dc1, dc2);
		} else {
/* 1, 2 or 4 channels */

			mlib_v_ImageConstAdd_U16_124((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize, dc1, dc2);
		}

		return (MLIB_SUCCESS);

	} else if (dtype == MLIB_INT) {

/* 3 channels */
		if (nchan == 3) {
			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0)) {

				mlib_v_ImageConstAdd_S32_3_A8D1((mlib_s32 *)sa,
				    (mlib_s32 *)da, dsize, dc1, dc2);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_S32_3_A8D2((mlib_s32 *)sa,
				    slb, (mlib_s32 *)da, dlb, xsize, ysize, dc1,
				    dc2);
			} else {

				mlib_v_ImageConstAdd_S32_3((mlib_s32 *)sa, slb,
				    (mlib_s32 *)da, dlb,
				    xsize, ysize, dc1, dc2);
			}
		} else {
/* 1, 2 or 4 channels */

			if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
			    ((dsize & 3) == 0)) {

				mlib_v_ImageConstAdd_S32_124_A8D1X4((mlib_s32 *)
				    sa, (mlib_s32 *)da, dsize, dc1, dc2);

			} else if (((flags & A8D2) == 0) &&
			    ((flagd & A8D2) == 0)) {

				mlib_v_ImageConstAdd_S32_124_A8D2((mlib_s32 *)
				    sa, slb, (mlib_s32 *)da, dlb, xsize, ysize,
				    dc1, dc2);
			} else {

				mlib_v_ImageConstAdd_S32_124((mlib_s32 *)sa,
				    slb, (mlib_s32 *)da, dlb, xsize, ysize, dc1,
				    dc2);
			}
		}

		return (MLIB_SUCCESS);
	}

	return (MLIB_FAILURE);
}
예제 #4
0
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;
}
예제 #5
0
mlib_status
__mlib_ImageSqrShift(
    mlib_image *dst,
    const mlib_image *src,
    mlib_s32 shift)
{
	mlib_s32 A8D1 = MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_ONEDVECTOR;
	mlib_s32 A8D2X8 =
	    MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH8X;
	mlib_s32 A8D2X4 =
	    MLIB_IMAGE_ALIGNED8 | MLIB_IMAGE_STRIDE8X | MLIB_IMAGE_WIDTH4X;

	void *sa, *da;
	mlib_type dtype;
	mlib_s32 slb, dlb, xsize, ysize, nchan;
	mlib_s32 flags, flagd;
	mlib_s32 dsize;

	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_CHECK(src);
	MLIB_IMAGE_FULL_EQUAL(dst, src);

	MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, nchan, xsize, ysize, dlb, da);
	slb = mlib_ImageGetStride(src);
	sa = mlib_ImageGetData(src);
	flags = mlib_ImageGetFlags(src);
	flagd = mlib_ImageGetFlags(dst);

	xsize = xsize * nchan;
	dsize = xsize * ysize;

	if (dtype == MLIB_BYTE) {
		if ((shift < 4) || (shift > 11)) {
			return (MLIB_OUTOFRANGE);
		}
	}

	if (dtype == MLIB_SHORT) {
		if ((shift < 1) || (shift > 16)) {
			return (MLIB_OUTOFRANGE);
		}
	}

	if (dtype == MLIB_USHORT) {
		if ((shift < 1) || (shift > 16)) {
			return (MLIB_OUTOFRANGE);
		}
	}

	if (dtype == MLIB_INT) {
		if ((shift < -1023) || (shift > 1022)) {
			return (MLIB_OUTOFRANGE);
		}
	}

	if (dtype == MLIB_BYTE) {

/* initialize GSR scale factor */
		vis_write_gsr(((11 - shift) & 0x0f) << 3);

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 7) == 0)) {

			mlib_v_ImageSqrShift_U8_A8D1X8((mlib_u8 *)sa,
			    (mlib_u8 *)da, dsize);
		} else if (((flags & A8D2X8) == 0) && ((flagd & A8D2X8) == 0)) {

			mlib_v_ImageSqrShift_U8_A8D2X8((mlib_u8 *)sa, slb,
			    (mlib_u8 *)da, dlb, xsize, ysize);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSqrShift_U8_D1((mlib_u8 *)sa, (mlib_u8 *)da,
			    dsize);
		} else {

			mlib_v_ImageSqrShift_U8((mlib_u8 *)sa, slb,
			    (mlib_u8 *)da, dlb, xsize, ysize);
		}

		return (MLIB_SUCCESS);
	} else if ((dtype == MLIB_SHORT) && (shift != 16)) {

/* initialize GSR scale factor */
		vis_write_gsr(((16 - shift) & 0x0f) << 3);

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 3) == 0)) {

			mlib_v_ImageSqrShift_S16_A8D1X4((mlib_s16 *)sa,
			    (mlib_s16 *)da, dsize, shift);
		} else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) {

			mlib_v_ImageSqrShift_S16_A8D2X4((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize, shift);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSqrShift_S16_D1((mlib_s16 *)sa,
			    (mlib_s16 *)da, dsize, shift);
		} else {

			mlib_v_ImageSqrShift_S16((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize, shift);
		}

		return (MLIB_SUCCESS);
	} else if ((dtype == MLIB_SHORT) && (shift == 16)) {

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 3) == 0)) {

			mlib_v_ImageSquare_S16_A8D1X4((mlib_s16 *)sa,
			    (mlib_s16 *)da, dsize);
		} else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) {

			mlib_v_ImageSquare_S16_A8D2X4((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSquare_S16_D1((mlib_s16 *)sa,
			    (mlib_s16 *)da, dsize);
		} else {

			mlib_v_ImageSquare_S16((mlib_s16 *)sa, slb,
			    (mlib_s16 *)da, dlb, xsize, ysize);
		}

		return (MLIB_SUCCESS);
	} else if ((dtype == MLIB_USHORT) && (shift < 5)) {

/* initialize GSR scale factor */
		vis_write_gsr(0);

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 3) == 0)) {

			mlib_v_ImageSqrSmallShift_U16_A8D1X4((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize, shift);
		} else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) {

			mlib_v_ImageSqrSmallShift_U16_A8D2X4((mlib_u16 *)sa,
			    slb, (mlib_u16 *)da, dlb, xsize, ysize, shift);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSqrSmallShift_U16_D1((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize, shift);
		} else {

			mlib_v_ImageSqrSmallShift_U16((mlib_u16 *)sa, slb,
			    (mlib_u16 *)da, dlb, xsize, ysize, shift);
		}

		return (MLIB_SUCCESS);
	} else if ((dtype == MLIB_USHORT) && (shift != 16)) {

/* initialize GSR scale factor */
		vis_write_gsr(((18 - shift) & 0x0f) << 3);

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 3) == 0)) {

			mlib_v_ImageSqrShift_U16_A8D1X4((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize, shift);
		} else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) {

			mlib_v_ImageSqrShift_U16_A8D2X4((mlib_u16 *)sa, slb,
			    (mlib_u16 *)da, dlb, xsize, ysize, shift);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSqrShift_U16_D1((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize, shift);
		} else {

			mlib_v_ImageSqrShift_U16((mlib_u16 *)sa, slb,
			    (mlib_u16 *)da, dlb, xsize, ysize, shift);
		}

		return (MLIB_SUCCESS);
	} else if ((dtype == MLIB_USHORT) && (shift == 16)) {

		if (((flags & A8D1) == 0) && ((flagd & A8D1) == 0) &&
		    ((dsize & 3) == 0)) {

			mlib_v_ImageSquare_U16_A8D1X4((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize);
		} else if (((flags & A8D2X4) == 0) && ((flagd & A8D2X4) == 0)) {

			mlib_v_ImageSquare_U16_A8D2X4((mlib_u16 *)sa, slb,
			    (mlib_u16 *)da, dlb, xsize, ysize);
		} else if (((flags & MLIB_IMAGE_ONEDVECTOR) == 0) &&
		    ((flagd & MLIB_IMAGE_ONEDVECTOR) == 0)) {

			mlib_v_ImageSquare_U16_D1((mlib_u16 *)sa,
			    (mlib_u16 *)da, dsize);
		} else {

			mlib_v_ImageSquare_U16((mlib_u16 *)sa, slb,
			    (mlib_u16 *)da, dlb, xsize, ysize);
		}

		return (MLIB_SUCCESS);
	} else if (dtype == MLIB_INT) {

		mlib_v_ImageSqrShift_S32((mlib_s32 *)sa, (slb >> 2),
		    (mlib_s32 *)da, (dlb >> 2), xsize, ysize, shift);
		return (MLIB_SUCCESS);
	} else {