mlib_status
__mlib_ImageColorConvert1_Fp(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_d64 *fmat)
{
	mlib_s32 slb, dlb, xsize, ysize;
	mlib_type dtype;
	void *sa, *da;

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

	if (fmat == NULL)
		return (MLIB_NULLPOINTER);

	dtype = mlib_ImageGetType(dst);
	xsize = mlib_ImageGetWidth(dst);
	ysize = mlib_ImageGetHeight(dst);
	slb = mlib_ImageGetStride(src);
	dlb = mlib_ImageGetStride(dst);
	sa = mlib_ImageGetData(src);
	da = mlib_ImageGetData(dst);

	if (dtype == MLIB_FLOAT) {
		return mlib_ImageColorConvert1_F32(sa, slb / 4,
		    da, dlb / 4, xsize, ysize, fmat);
	} else if (dtype == MLIB_DOUBLE) {
		return mlib_ImageColorConvert1_D64(sa, slb / 8,
		    da, dlb / 8, xsize, ysize, fmat);
	} else
		return (MLIB_FAILURE);
}
mlib_status
__mlib_ImageColorXYZ2RGB(
    mlib_image *dst,
    const mlib_image *src)
{
/* CIE XYZ to Rec709 RGB with D64 White Point */
	mlib_d64 fmat[9] = { 3.240479, -1.537150, -0.498535,
		-0.969256, 1.875992, 0.041566,
		0.055648, -0.204043, 1.057311
	};
	mlib_s32 slb, dlb, xsize, ysize;
	mlib_type dtype;
	mlib_u8 *psrc, *pdst;
	mlib_s32 j;

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

	dtype = mlib_ImageGetType(dst);
	xsize = mlib_ImageGetWidth(dst);
	ysize = mlib_ImageGetHeight(dst);
	dlb = mlib_ImageGetStride(dst);
	pdst = (void *)mlib_ImageGetData(dst);

	slb = mlib_ImageGetStride(src);
	psrc = mlib_ImageGetData(src);

	if (dtype == MLIB_BYTE) {

		for (j = 0; j < ysize; j++) {
			mlib_u8 *ps = psrc,
			    *pd = pdst, *pend = pdst + 3 * xsize;

#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
			for (; pd < pend; pd += 3) {
				MLIB_CONVERT_U8_1(pd, ps);
				ps += 3;
			}

			psrc += slb;
			pdst += dlb;
		}

		return (MLIB_SUCCESS);

	} else {

		return (__mlib_ImageColorConvert1(dst, src, fmat));
	}
}
mlib_status
__mlib_ImageMinFilter3x3(
    mlib_image *dst,
    const mlib_image *src)
{
	mlib_image dst_i[1], src_i[1];
	mlib_type type;
	mlib_s32 wid, hgt, slb, dlb;
	mlib_status ret;
	void *da, *sa;

	ret = mlib_ImageClipping(dst_i, src_i, NULL, NULL, NULL, dst, src, 3);

	if (ret != MLIB_SUCCESS)
		return (ret);

	MLIB_IMAGE_HAVE_CHAN(dst, 1);

	type = mlib_ImageGetType(dst_i);
	wid = mlib_ImageGetWidth(dst_i);
	hgt = mlib_ImageGetHeight(dst_i);
	dlb = mlib_ImageGetStride(dst_i);
	da = (void *)mlib_ImageGetData(dst_i);

	sa = mlib_ImageGetData(src_i);
	slb = mlib_ImageGetStride(src_i);

	if (wid < 3 || hgt < 3)
		return (MLIB_SUCCESS);

	switch (type) {
	case MLIB_BIT:
		return mlib_ImageMinFilter3x3_BIT(da, sa, dlb, slb, wid, hgt,
		    mlib_ImageGetBitOffset(dst_i),
		    mlib_ImageGetBitOffset(src_i));

	case MLIB_BYTE:
		return (mlib_ImageMinFilter3x3_U8(da, sa, dlb, slb, wid, hgt));

	case MLIB_SHORT:
		return (mlib_ImageMinFilter3x3_S16(da, sa, dlb, slb, wid, hgt));

	case MLIB_USHORT:
		return (mlib_ImageMinFilter3x3_U16(da, sa, dlb, slb, wid, hgt));

	case MLIB_INT:
		return (mlib_ImageMinFilter3x3_S32(da, sa, dlb, slb, wid, hgt));

	default:
		return (MLIB_FAILURE);
	}
}
Example #4
0
mlib_status
__mlib_ImageSqrShift(
    mlib_image *dst,
    const mlib_image *src,
    mlib_s32 shift)
{
	mlib_type dtype;

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

	dtype = mlib_ImageGetType(dst);

	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_INT) {
		if ((shift < -1023) || (shift > 1022)) {
			return (MLIB_OUTOFRANGE);
		}
	}

	if (dtype == MLIB_BYTE) {

		return (mlib_c_ImageSqrShift_U8(dst, src, shift));
	} else {

		void *sa = mlib_ImageGetData(src);
		void *da = mlib_ImageGetData(dst);
		mlib_s32 slb = mlib_ImageGetStride(src);
		mlib_s32 dlb = mlib_ImageGetStride(dst);
		mlib_s32 nchan = mlib_ImageGetChannels(src);
		mlib_s32 xsize = mlib_ImageGetWidth(src) * nchan;
		mlib_s32 ysize = mlib_ImageGetHeight(src);

		if (dtype == MLIB_SHORT) {

			mlib_c_ImageSqrShift_S16((mlib_s16 *)sa, (slb >> 1),
			    (mlib_s16 *)da, (dlb >> 1), xsize, ysize, shift);
			return (MLIB_SUCCESS);
		} else if (dtype == MLIB_USHORT) {
Example #5
0
void mlib_v_ImageClear_BIT_1(mlib_image     *img,
                             const mlib_s32 *color)
{
  mlib_u8 *pimg = (mlib_u8 *) mlib_ImageGetData(img);
  mlib_s32 img_height = mlib_ImageGetHeight(img);
  mlib_s32 img_width = mlib_ImageGetWidth(img);
  mlib_s32 img_stride = mlib_ImageGetStride(img);
  mlib_s32 img_bitoff = mlib_ImageGetBitOffset(img);
  mlib_s32 i, j, b_j, k;
  mlib_u8 bcolor0, bmask, emask, src;
  mlib_d64 dcolor, *dpimg;
  mlib_u32 color0;

  if (img_width == img_stride * 8) {
    img_width *= img_height;
    img_height = 1;
  }

  color0 = ((color[0] & 1) << 31) >> 31;
  bcolor0 = color0 & 0xFF;

  dcolor = vis_to_double_dup(color0);
  for (i = 0, j = 0; i < img_height; i++) {
    mlib_u8 *pimg_row = pimg + i * img_stride, *pimg_row_end;

    if (img_bitoff + img_width <= 8) {
      bmask = (0xFF >> (8 - img_width)) << (8 - img_bitoff - img_width);
      src = pimg_row[0];
      pimg_row[0] = (src & ~bmask) | (color0 & bmask);
      continue;
    }
    else {
Example #6
0
void *mlib_ImageCreateRowTable(mlib_image *img)
{
  mlib_u8  **rtable, *tline;
  mlib_s32 i, im_height, im_stride;

  if (img == NULL) return NULL;
  if (img -> state)  return img -> state;

  im_height = mlib_ImageGetHeight(img);
  im_stride = mlib_ImageGetStride(img);
  tline     = mlib_ImageGetData(img);
  rtable    = mlib_malloc((3 + im_height)*sizeof(mlib_u8 *));

  if (rtable == NULL || tline == NULL) return NULL;

  rtable[0] = 0;
  rtable[1] = (mlib_u8*)((void **)rtable + 1);
  rtable[2 + im_height] = (mlib_u8*)((void **)rtable + 1);
  for (i = 0; i < im_height; i++) {
    rtable[i+2] = tline;
    tline    += im_stride;
  }

  img -> state = ((void **)rtable + 2);
  return img -> state;
}
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_ImageConstMulShift(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_s32 *consts,
    mlib_s32 shift)
{
	mlib_type type;
	void *psrc, *pdst;
	mlib_s32 slb, dlb, xsize, ysize, nchan;
	mlib_s32 beta[4] = { 0, 0, 0, 0 };
	mlib_d64 dalpha[4], dbeta[4], dshift;
	mlib_s32 k;

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

	MLIB_IMAGE_GET_ALL_PARAMS(dst, type, nchan, xsize, ysize, dlb, pdst);
	slb = mlib_ImageGetStride(src);
	psrc = mlib_ImageGetData(src);

	if (shift < 0 || shift > 31)
		return (MLIB_OUTOFRANGE);

/* branch to ImageScale if possible */

	if (type == MLIB_BYTE || type == MLIB_SHORT || type == MLIB_USHORT) {
		if (__mlib_ImageScale(dst, src, consts, beta,
		    shift) == MLIB_SUCCESS)
			return (MLIB_SUCCESS);
	}

	dshift = 1.0 / (1u << shift);
	for (k = 0; k < nchan; k++) {
		dalpha[k] = consts[k] * dshift;
		dbeta[k] = 0;
	}

	if (type == MLIB_BYTE) {

		return (mlib_ImageScale2_U8(dst, src, dalpha, dbeta));
	} else if (type == MLIB_SHORT) {

		return (mlib_ImageScale2_S16(dst, src, dalpha, dbeta));
	} else if (type == MLIB_USHORT) {

		return (mlib_ImageScale2_U16(dst, src, dalpha, dbeta));
	} else if (type == MLIB_INT) {

		return mlib_ImageDConstMul_S32(pdst, psrc, xsize, ysize, nchan,
		    slb / 4, dlb / 4, dalpha);
	}

	return (MLIB_FAILURE);
}
mlib_status
__mlib_ImageMaxFilter3x3_Fp(
    mlib_image *dst,
    const mlib_image *src)
{
	mlib_image dst_i[1], src_i[1];
	mlib_type type;
	mlib_s32 wid, hgt, slb, dlb;
	mlib_status ret;
	void *da, *sa;

	ret = mlib_ImageClipping(dst_i, src_i, NULL, NULL, NULL, dst, src, 3);

	if (ret != MLIB_SUCCESS)
		return (ret);

	MLIB_IMAGE_HAVE_CHAN(dst, 1);

	type = mlib_ImageGetType(dst_i);
	wid = mlib_ImageGetWidth(dst_i);
	hgt = mlib_ImageGetHeight(dst_i);
	dlb = mlib_ImageGetStride(dst_i);
	da = (void *)mlib_ImageGetData(dst_i);

	sa = mlib_ImageGetData(src_i);
	slb = mlib_ImageGetStride(src_i);

	if (wid < 3 || hgt < 3)
		return (MLIB_SUCCESS);

	switch (type) {
	case MLIB_FLOAT:
		return (mlib_ImageMaxFilter3x3_F32(da, sa, dlb, slb, wid, hgt));

	case MLIB_DOUBLE:
		return (mlib_ImageMaxFilter3x3_D64(da, sa, dlb, slb, wid, hgt));

	default:
		return (MLIB_FAILURE);
	}
}
void
mlib_ImageMinimum_S32_124(
    mlib_s32 *res,
    const mlib_image *img)
{
	mlib_s32 *sl;
	mlib_s32 nchan, xsize, ysize, slb;
	mlib_s32 res0, res1, res2, res3;
	mlib_s32 i, j;

	nchan = mlib_ImageGetChannels(img);
	xsize = mlib_ImageGetWidth(img);
	ysize = mlib_ImageGetHeight(img);
	slb = mlib_ImageGetStride(img);
	sl = (void *)mlib_ImageGetData(img);

	slb /= 4;
	xsize *= nchan;

	if (slb == xsize) {
		xsize *= ysize;
		ysize = 1;
	}

	res0 = res1 = res2 = res3 = MLIB_S32_MAX;

	for (j = 0; j < ysize; j++) {
		for (i = 0; i <= (xsize - 4); i += 4) {
			PXL_OPER_S32(res0, sl[i]);
			PXL_OPER_S32(res1, sl[i + 1]);
			PXL_OPER_S32(res2, sl[i + 2]);
			PXL_OPER_S32(res3, sl[i + 3]);
		}

		if (i < xsize)
			PXL_OPER_S32(res0, sl[i]);
		i++;

		if (i < xsize)
			PXL_OPER_S32(res1, sl[i]);
		i++;

		if (i < xsize)
			PXL_OPER_S32(res2, sl[i]);

		sl += slb;
	}

	res[0] = res0;
	res[1] = res1;
	res[2] = res2;
	res[3] = res3;
}
Example #11
0
mlib_status
mlib_ImageDiv_Fp_D64(
    mlib_image *dst,
    const mlib_image *src1,
    const mlib_image *src2)
{
	mlib_d64 *dl, *sl1, *sl2;
	mlib_s32 slb1, slb2, dlb, xsize, ysize, nchan;
	mlib_s32 i, j;

	nchan = mlib_ImageGetChannels(dst);
	xsize = mlib_ImageGetWidth(dst);
	ysize = mlib_ImageGetHeight(dst);
	dlb = mlib_ImageGetStride(dst);
	dl = (void *)mlib_ImageGetData(dst);

	dlb /= 8;
	slb1 = mlib_ImageGetStride(src1) / 8;
	sl1 = mlib_ImageGetData(src1);
	slb2 = mlib_ImageGetStride(src2) / 8;
	sl2 = mlib_ImageGetData(src2);
	xsize *= nchan;

	for (j = 0; j < ysize; j++) {
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
		for (i = 0; i < xsize; i++) {
			dl[i] = sl1[i] / sl2[i];
		}

		dl += dlb;
		sl1 += slb1;
		sl2 += slb2;
	}

	return (MLIB_SUCCESS);
}
void
mlib_ImageMinimum_S32_3(
    mlib_s32 *res,
    const mlib_image *img)
{
	mlib_s32 *sl;
	mlib_s32 xsize, ysize, slb;
	mlib_s32 res0, res1, res2;
	mlib_s32 i, j;

	xsize = mlib_ImageGetWidth(img);
	ysize = mlib_ImageGetHeight(img);
	slb = mlib_ImageGetStride(img);
	sl = (void *)mlib_ImageGetData(img);

	slb /= 4;
	xsize *= 3;

	if (slb == xsize) {
		xsize *= ysize;
		ysize = 1;
	}

	res0 = res1 = res2 = MLIB_S32_MAX;

	for (j = 0; j < ysize; j++) {
		for (i = 0; i <= (xsize - 3); i += 3) {
			PXL_OPER_S32(res0, sl[i]);
			PXL_OPER_S32(res1, sl[i + 1]);
			PXL_OPER_S32(res2, sl[i + 2]);
		}

		if (i < xsize)
			PXL_OPER_S32(res0, sl[i]);
		i++;

		if (i < xsize)
			PXL_OPER_S32(res1, sl[i]);

		sl += slb;
	}

	res[0] = res0;
	res[1] = res1;
	res[2] = res2;
}
Example #13
0
void
mlib_ImageMinimum_D64_3(
    const mlib_image *img,
    mlib_d64 *min)
{
/* pointer to the data of image */
	mlib_d64 *psrc = (mlib_d64 *)mlib_ImageGetData(img);

/* minimums by channels */
	mlib_d64 min1, min2, min3;

/* height of image */
	mlib_s32 height = mlib_ImageGetHeight(img);

/* elements to next row */
	mlib_s32 src_stride = mlib_ImageGetStride(img) / 8;

/* number of elements in the row */
	mlib_s32 size_row = mlib_ImageGetWidth(img) * 3;

/* indices */
	mlib_s32 i, j;

	if (src_stride == size_row) {
/* This images is not a sub-images and can be treated as a 1-D vectors */
		size_row *= height;
		height = 1;
	}

	min1 = min2 = min3 = MLIB_D64_MAX;
	for (i = 0; i < height; i++) {
		for (j = 0; j <= (size_row - 3); j += 3) {
			MIN(min1, psrc[j]);
			MIN(min2, psrc[j + 1]);
			MIN(min3, psrc[j + 2]);
		}

		psrc += src_stride;
	}

	min[0] = min1;
	min[1] = min2;
	min[2] = min3;
}
mlib_status mlib_ImageConvClearEdge_Bit(mlib_image     *img,
                                        mlib_s32       dx_l,
                                        mlib_s32       dx_r,
                                        mlib_s32       dy_t,
                                        mlib_s32       dy_b,
                                        const mlib_s32 *color,
                                        mlib_s32       cmask)
{
  mlib_u8  *pimg = mlib_ImageGetData(img), *pd;
  mlib_s32 img_height = mlib_ImageGetHeight(img);
  mlib_s32 img_width  = mlib_ImageGetWidth(img);
  mlib_s32 img_stride = mlib_ImageGetStride(img);
  mlib_s32 bitoff = mlib_ImageGetBitOffset(img);
  mlib_s32 bitoff_end;
  mlib_u8  color_i, mask, mask_end, tmp_color;
  mlib_u8  tmp_start, tmp_end;
  mlib_s32 i, j, amount;

  if ((mlib_ImageGetType(img) != MLIB_BIT) || (mlib_ImageGetChannels(img) != 1))
    return MLIB_FAILURE;

  color_i = (mlib_u8)(color[0] & 1);
  color_i |= (color_i << 1);
  color_i |= (color_i << 2);
  color_i |= (color_i << 4);

  pd = pimg;

  if (dx_l > 0) {
    if (bitoff + dx_l <= 8) {
      mask = (0xFF >> bitoff) & (0xFF << ((8 - (bitoff + dx_l)) & 7));
      tmp_color = color_i & mask;
      mask = ~mask;

      for (i = dy_t; i < (img_height - dy_b); i++) {
        pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;
      }

    } else {
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_ImagePolynomialWarp_0_BC2(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 wx,
    mlib_d64 wy)
{
	mlib_d64 a0, a1, a2, a3;
	mlib_d64 r0, r1, r2, r3, res;
	mlib_d64 fx0, fx1, fx2, fx3;
	mlib_d64 fy0, fy1, fy2, fy3;
	mlib_d64 dx, dy;
	mlib_s32 i, srcYStride, srcChannels, color[4];
	mlib_type srcType;
	mlib_d64 limit_lo, limit_hi;

	srcType = mlib_ImageGetType(src);
	srcYStride = mlib_ImageGetStride(src);
	srcChannels = mlib_ImageGetChannels(src);

	dx = wx - (mlib_s32)wx;
	dy = wy - (mlib_s32)wy;

	fx0 = S0_BC2(dx);
	fx1 = S1_BC2(dx);
	fx2 = S2_BC2(dx);
	fx3 = S3_BC2(dx);
	fy0 = S0_BC2(dy);
	fy1 = S1_BC2(dy);
	fy2 = S2_BC2(dy);
	fy3 = S3_BC2(dy);

	switch (srcType) {
	case MLIB_BYTE:
	    {
		    mlib_u8 *srcData0, *srcData = mlib_ImageGetData(src);

		    limit_lo = MLIB_U8_MIN;
		    limit_hi = MLIB_U8_MAX;

		    srcData = srcData + ((mlib_s32)wy - 1) * srcYStride;
		    srcData += ((mlib_s32)wx - 1) * srcChannels;

		    CALC_BICUBIC;
	    }

		break;

	case MLIB_SHORT:
	    {
		    mlib_s16 *srcData0, *srcData = mlib_ImageGetData(src);

		    limit_lo = MLIB_S16_MIN;
		    limit_hi = MLIB_S16_MAX;

		    srcData =
			(void *)((mlib_u8 *)srcData + ((mlib_s32)wy -
			1) * srcYStride);
		    srcData += ((mlib_s32)wx - 1) * srcChannels;

		    CALC_BICUBIC;
	    }

		break;

	case MLIB_USHORT:
	    {
		    mlib_u16 *srcData0, *srcData = mlib_ImageGetData(src);

		    limit_lo = MLIB_U16_MIN;
		    limit_hi = MLIB_U16_MAX;

		    srcData =
			(void *)((mlib_u8 *)srcData + ((mlib_s32)wy -
			1) * srcYStride);
		    srcData += ((mlib_s32)wx - 1) * srcChannels;

		    CALC_BICUBIC;
	    }

		break;

	case MLIB_INT:
	    {
		    mlib_s32 *srcData0, *srcData = mlib_ImageGetData(src);

		    limit_lo = MLIB_S32_MIN;
		    limit_hi = MLIB_S32_MAX;

		    srcData =
			(void *)((mlib_u8 *)srcData + ((mlib_s32)wy -
			1) * srcYStride);
		    srcData += ((mlib_s32)wx - 1) * srcChannels;

		    CALC_BICUBIC;
	    }

		break;

	default:
		return (MLIB_FAILURE);
	}

	return (__mlib_ImageClear(dst, color));
}
mlib_status
mlib_ImagePolynomialWarp_0_BL(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 wx,
    mlib_d64 wy)
{
	mlib_d64 a0, a1, a2, a3, r0, r1, dx, dy;
	mlib_s32 i, srcYStride, srcChannels, color[4];
	mlib_type srcType;

	srcType = mlib_ImageGetType(src);
	srcYStride = mlib_ImageGetStride(src);
	srcChannels = mlib_ImageGetChannels(src);

	dx = wx - (mlib_s32)wx;
	dy = wy - (mlib_s32)wy;

	switch (srcType) {
	case MLIB_BYTE:
	    {
		    mlib_u8 *srcData0 = mlib_ImageGetData(src), *srcData1;

		    srcData0 = srcData0 + (mlib_s32)wy *srcYStride;
		    srcData0 += (mlib_s32)wx *srcChannels;

		    srcData1 = srcData0 + srcYStride;

		    for (i = 0; i < srcChannels; i++) {
			    a0 = srcData0[i];
			    a1 = srcData0[srcChannels + i];
			    a2 = srcData1[srcChannels + i];
			    a3 = srcData1[i];

			    r0 = a0 + (a1 - a0) * dx;
			    r1 = a3 + (a2 - a3) * dx;
			    color[i] = (mlib_s32)(r0 + (r1 - r0) * dy);
		    }
	    }

		break;

	case MLIB_SHORT:
	    {
		    mlib_s16 *srcData0 = mlib_ImageGetData(src), *srcData1;

		    srcData0 =
			(void *)((mlib_u8 *)srcData0 +
			(mlib_s32)wy * srcYStride);
		    srcData0 += (mlib_s32)wx *srcChannels;

		    srcData1 = (void *)((mlib_u8 *)srcData0 + srcYStride);

		    for (i = 0; i < srcChannels; i++) {
			    a0 = srcData0[i];
			    a1 = srcData0[srcChannels + i];
			    a2 = srcData1[srcChannels + i];
			    a3 = srcData1[i];

			    r0 = a0 + (a1 - a0) * dx;
			    r1 = a3 + (a2 - a3) * dx;
			    color[i] = (mlib_s32)(r0 + (r1 - r0) * dy);
		    }
	    }

		break;

	case MLIB_USHORT:
	    {
		    mlib_u16 *srcData0 = mlib_ImageGetData(src), *srcData1;

		    srcData0 =
			(void *)((mlib_u8 *)srcData0 +
			(mlib_s32)wy * srcYStride);
		    srcData0 += (mlib_s32)wx *srcChannels;

		    srcData1 = (void *)((mlib_u8 *)srcData0 + srcYStride);

		    for (i = 0; i < srcChannels; i++) {
			    a0 = srcData0[i];
			    a1 = srcData0[srcChannels + i];
			    a2 = srcData1[srcChannels + i];
			    a3 = srcData1[i];

			    r0 = a0 + (a1 - a0) * dx;
			    r1 = a3 + (a2 - a3) * dx;
			    color[i] = (mlib_s32)(r0 + (r1 - r0) * dy);
		    }
	    }

		break;

	case MLIB_INT:
	    {
		    mlib_s32 *srcData0 = mlib_ImageGetData(src), *srcData1;

		    srcData0 =
			(void *)((mlib_u8 *)srcData0 +
			(mlib_s32)wy * srcYStride);
		    srcData0 += (mlib_s32)wx *srcChannels;

		    srcData1 = (void *)((mlib_u8 *)srcData0 + srcYStride);

		    for (i = 0; i < srcChannels; i++) {
			    a0 = srcData0[i];
			    a1 = srcData0[srcChannels + i];
			    a2 = srcData1[srcChannels + i];
			    a3 = srcData1[i];

			    r0 = a0 + (a1 - a0) * dx;
			    r1 = a3 + (a2 - a3) * dx;
			    color[i] = (mlib_s32)(r0 + (r1 - r0) * dy);
		    }
	    }

		break;

	default:
		return (MLIB_FAILURE);
	}

	return (__mlib_ImageClear(dst, color));
}
mlib_status
mlib_ImagePolynomialWarp_0_NN(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 wx,
    mlib_d64 wy)
{
	mlib_s32 srcYStride, srcChannels, i, color[4];
	mlib_type srcType;

	srcType = mlib_ImageGetType(src);
	srcYStride = mlib_ImageGetStride(src);
	srcChannels = mlib_ImageGetChannels(src);

	switch (srcType) {
	case MLIB_BYTE:
	    {
		    mlib_u8 *srcData = mlib_ImageGetData(src);

		    srcData = srcData + (mlib_s32)wy *srcYStride;
		    srcData += (mlib_s32)wx *srcChannels;

		    for (i = 0; i < srcChannels; i++)
			color[i] = srcData[i];
	    }

		break;

	case MLIB_USHORT:
	case MLIB_SHORT:
	    {
		    mlib_s16 *srcData = mlib_ImageGetData(src);

		    srcData =
			(void *)((mlib_u8 *)srcData +
			(mlib_s32)wy * srcYStride);
		    srcData += (mlib_s32)wx *srcChannels;

		    for (i = 0; i < srcChannels; i++)
			color[i] = srcData[i];
	    }

		break;

	case MLIB_INT:
	    {
		    mlib_s32 *srcData = mlib_ImageGetData(src);

		    srcData =
			(void *)((mlib_u8 *)srcData +
			(mlib_s32)wy * srcYStride);
		    srcData += (mlib_s32)wx *srcChannels;

		    for (i = 0; i < srcChannels; i++)
			color[i] = srcData[i];
	    }

		break;
	default:
		return (MLIB_FAILURE);
	}

	return (__mlib_ImageClear(dst, color));
}
void
mlib_ImagePolynomialWarp_2_5(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_u8 **lineAddr,
    mlib_PWS * pws,
    const mlib_d64 *xCoeffs,
    const mlib_d64 *yCoeffs,
    mlib_d64 preShiftX,
    mlib_d64 preShiftY,
    mlib_filter filter,
    mlib_edge edge)
{
	mlib_IPWFCall_NN func_array_nn_all[4][3][4] = {
		{
/* degree = 2 */
			    {TIN(2_NN_U8_1), TIN(2_NN_U8_2), TIN(2_NN_U8_3),
				    TIN(2_NN_U8_4)},
			    {TIN(2_NN_S16_1), TIN(2_NN_S16_2),
				    TIN(2_NN_S16_3), TIN(2_NN_S16_4)},
			    {TIN(2_NN_S32_1), TIN(2_NN_S32_2),
				    TIN(2_NN_S32_3), TIN(2_NN_S32_4)},
		    },
		{
/* degree = 3 */
			    {TIN(3_NN_U8_1), TIN(3_NN_U8_2), TIN(3_NN_U8_3),
				    TIN(3_NN_U8_4)},
			    {TIN(3_NN_S16_1), TIN(3_NN_S16_2),
				    TIN(3_NN_S16_3), TIN(3_NN_S16_4)},
			    {TIN(3_NN_S32_1), TIN(3_NN_S32_2),
				    TIN(3_NN_S32_3), TIN(3_NN_S32_4)},
		    },
		{
/* degree = 4 */
			    {TIN(4_NN_U8_1), TIN(4_NN_U8_2), TIN(4_NN_U8_3),
				    TIN(4_NN_U8_4)},
			    {TIN(4_NN_S16_1), TIN(4_NN_S16_2),
				    TIN(4_NN_S16_3), TIN(4_NN_S16_4)},
			    {TIN(4_NN_S32_1), TIN(4_NN_S32_2),
				    TIN(4_NN_S32_3), TIN(4_NN_S32_4)},
		    },
		{
/* degree = 5 */
			    {TIN(5_NN_U8_1), TIN(5_NN_U8_2), TIN(5_NN_U8_3),
				    TIN(5_NN_U8_4)},
			    {TIN(5_NN_S16_1), TIN(5_NN_S16_2),
				    TIN(5_NN_S16_3), TIN(5_NN_S16_4)},
			    {TIN(5_NN_S32_1), TIN(5_NN_S32_2),
				    TIN(5_NN_S32_3), TIN(5_NN_S32_4)},
		    }
	};

	mlib_IPWClipLine array_func_clip_all[12] = {
/* degree = 2 */
		mlib_ImagePolynomialWarpClipLine_DG_2_2,
		mlib_ImagePolynomialWarpClipLine_DG_2_0,
		mlib_ImagePolynomialWarpClipLine_DG_2_1,
/* degree = 3 */
		mlib_ImagePolynomialWarpClipLine_DG_3_2,
		mlib_ImagePolynomialWarpClipLine_DG_3_0,
		mlib_ImagePolynomialWarpClipLine_DG_3_1,
/* degree = 4 */
		mlib_ImagePolynomialWarpClipLine_DG_4_2,
		mlib_ImagePolynomialWarpClipLine_DG_4_0,
		mlib_ImagePolynomialWarpClipLine_DG_4_1,
/* degree = 5 */
		mlib_ImagePolynomialWarpClipLine_DG_5_2,
		mlib_ImagePolynomialWarpClipLine_DG_5_0,
		mlib_ImagePolynomialWarpClipLine_DG_5_1,
	};

	mlib_IPWFCall func_array_call[2][4][4] = {
		{
			    {TIN(BL_U8_1), TIN(BL_U8_2), TIN(BL_U8_3),
				    TIN(BL_U8_4)},
			    {TIN(BL_S16_1), TIN(BL_S16_2), TIN(BL_S16_3),
				    TIN(BL_S16_4)},
			    {TIN(BL_U16_1), TIN(BL_U16_2), TIN(BL_U16_3),
				    TIN(BL_U16_4)},
			    {TIN(BL_S32_1), TIN(BL_S32_2), TIN(BL_S32_3),
				    TIN(BL_S32_4)},
		    },
		{
			    {TIN(BC_U8_1), TIN(BC_U8_2), TIN(BC_U8_3),
				    TIN(BC_U8_4)},
			    {TIN(BC_S16_1), TIN(BC_S16_2), TIN(BC_S16_3),
				    TIN(BC_S16_4)},
			    {TIN(BC_U16_1), TIN(BC_U16_2), TIN(BC_U16_3),
				    TIN(BC_U16_4)},
			    {TIN(BC_S32_1), TIN(BC_S32_2), TIN(BC_S32_3),
				    TIN(BC_S32_4)},
		    }
	};

	mlib_type type = mlib_ImageGetType(dst);
	mlib_u8 *srcData = mlib_ImageGetData(src);
	mlib_u8 *dstData = mlib_ImageGetData(dst);
	mlib_s32 pos, i, channels, len, n;
	mlib_s32 srcWidth = mlib_ImageGetWidth(src);
	mlib_s32 srcHeight = mlib_ImageGetHeight(src);
	mlib_s32 srcStride = mlib_ImageGetStride(src);
	mlib_s32 dstWidth = mlib_ImageGetWidth(dst);
	mlib_s32 dstHeight = mlib_ImageGetHeight(dst);
	mlib_s32 dstStride = mlib_ImageGetStride(dst);
	mlib_d64 y = 0.5 + preShiftY;
	mlib_IPWClipLine func_clip;
	mlib_IPWFCall_NN func_array_nn;
	mlib_IPWFCall func_array;

	if (filter == MLIB_NEAREST) {

		channels = mlib_ImageGetChannels(dst);
		pos = (type == MLIB_BYTE) ? 1 : ((type == MLIB_SHORT ||
		    type == MLIB_USHORT) ? 2 : 4);

		lineAddr[0] = srcData;
		srcData -= channels * pos;
		for (i = 0; i <= srcHeight; i++) {
			lineAddr[i + 1] = srcData;
			srcData += srcStride;
		}

		pos = (type == MLIB_BYTE) ? 0 : ((type == MLIB_SHORT ||
		    type == MLIB_USHORT) ? 1 : 2);
		func_array_nn =
		    func_array_nn_all[pws->degree][pos][channels - 1];

		func_array_nn(dstData, lineAddr,
		    xCoeffs, yCoeffs, preShiftX, preShiftY,
		    srcWidth, srcHeight, dstWidth, dstHeight, dstStride);
	} else {

		channels = mlib_ImageGetChannels(dst);
		pos =
		    (type == MLIB_BYTE) ? 0 : ((type ==
		    MLIB_SHORT) ? 1 : ((type == MLIB_USHORT) ? 2 : 3));

		if ((filter == MLIB_BICUBIC || filter == MLIB_BILINEAR) &&
		    type == MLIB_INT)
			func_clip = array_func_clip_all[pws->degree * 3 + 0];
		else {
			if (filter == MLIB_BILINEAR)
				func_clip =
				    array_func_clip_all[pws->degree * 3 + 1];
			else
				func_clip =
				    array_func_clip_all[pws->degree * 3 + 2];
		}

		for (i = 0; i < srcHeight; i++) {
			lineAddr[i] = srcData;
			srcData += srcStride;
		}

		func_array = func_array_call[0][pos][channels - 1];
		if (filter == MLIB_BICUBIC)
			func_array = func_array_call[1][pos][channels - 1];

		for (i = 0; i < dstHeight; i++) {

			len = func_clip(pws, y, preShiftX, dstWidth, n);

			func_array(dstData, lineAddr, pws, len);
			dstData += dstStride;

			y += 1.0;
		}
	}
}
Example #20
0
mlib_status
__mlib_ImageAutoCorrel(
    mlib_d64 *correl,
    const mlib_image *img,
    mlib_s32 dx,
    mlib_s32 dy)
{
	mlib_image images[2], *img1, *img2;

/* height of image */
	mlib_s32 height;

/* width of image */
	mlib_s32 width;

/* type of image */
	mlib_type type;

/* channels of image */
	mlib_s32 channels;

/* stride of image */
	mlib_s32 stride;

/* data pointer of image */
	mlib_u8 *data, *data2;
	mlib_d64 rez[4];
	mlib_d64 divider;

/* check for obvious errors */
	MLIB_IMAGE_CHECK(img);

	if (correl == NULL)
		return (MLIB_NULLPOINTER);

	if (dx < 0 || dy < 0)
		return (MLIB_OUTOFRANGE);

	width = mlib_ImageGetWidth(img) - dx;
	height = mlib_ImageGetHeight(img) - dy;
	type = mlib_ImageGetType(img);
	channels = mlib_ImageGetChannels(img);
	stride = mlib_ImageGetStride(img);
	data = (mlib_u8 *)mlib_ImageGetData(img);

	divider = 1.0 / ((mlib_d64)width * height);

	switch (type) {
	case MLIB_BYTE:
		data2 = data + dy * stride + channels * dx;
		break;
	case MLIB_USHORT:
	case MLIB_SHORT:
		data2 = data + dy * stride + channels * dx * 2;
		break;
	case MLIB_INT:
		data2 = data + dy * stride + channels * dx * 4;
		break;
	default:
		return (MLIB_FAILURE);
	}

	img1 =
	    mlib_ImageSet(&images[0], type, channels, width, height, stride,
	    (void *)data);

	if (!img1)
		return (MLIB_FAILURE);

	img2 =
	    mlib_ImageSet(&images[1], type, channels, width, height, stride,
	    (void *)data2);

	if (!img2)
		return (MLIB_FAILURE);

	switch (type) {
/* handle MLIB_BYTE data type of image */
	case MLIB_BYTE:

		if (channels == 3)
			mlib_c_ImageCrossCorrel_U8_3(img1, img2, rez);
		else
			mlib_c_ImageCrossCorrel_U8_124(img1, img2, rez);
		break;

/* handle MLIB_USHORT data type of image */
	case MLIB_USHORT:

		if (channels == 3)
			mlib_c_ImageCrossCorrel_U16_3(img1, img2, rez);
		else
			mlib_c_ImageCrossCorrel_U16_124(img1, img2, rez);
		break;

/* handle MLIB_SHORT data type of image */
	case MLIB_SHORT:

		if (channels == 3)
			mlib_c_ImageCrossCorrel_S16_3(img1, img2, rez);
		else
			mlib_c_ImageCrossCorrel_S16_124(img1, img2, rez);
		break;

/* handle MLIB_INT data type of image */
	case MLIB_INT:

		if (channels == 3)
			mlib_c_ImageCrossCorrel_S32_3(img1, img2, rez);
		else
			mlib_c_ImageCrossCorrel_S32_124(img1, img2, rez);
		break;

/* discard any other data types */
	default:
		return (MLIB_FAILURE);
	}

	switch (channels) {
	case 1:
		correl[0] = (rez[0] + rez[1] + rez[2] + rez[3]) * divider;
		break;

	case 2:
		correl[0] = (rez[0] + rez[2]) * divider;
		correl[1] = (rez[1] + rez[3]) * divider;
		break;

	case 4:
		correl[3] = rez[3] * divider;
	case 3:
		correl[0] = rez[0] * divider;
		correl[1] = rez[1] * divider;
		correl[2] = rez[2] * divider;
	}

	return (MLIB_SUCCESS);
}
Example #21
0
mlib_status
__mlib_ImageInvert_Fp(
    mlib_image *dst,
    const mlib_image *src)
{
	mlib_s32 slb, dlb, xsize, ysize, nchan;
	mlib_type dtype;
	mlib_u8 *psrc, *pdst;
	mlib_s32 i, j;

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

	MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, nchan, xsize, ysize, dlb, pdst);
	slb = mlib_ImageGetStride(src);
	psrc = mlib_ImageGetData(src);
	xsize *= nchan;

	if (dtype == MLIB_FLOAT) {

		for (j = 0; j < ysize; j++) {
			mlib_f32 *ps = (mlib_f32 *)psrc;
			mlib_f32 *pd = (mlib_f32 *)pdst;
			mlib_f32 *pend = pd + xsize;

			if ((mlib_addr)pd & 7)
				(*pd++) = -((*ps++));

			if (((mlib_addr)ps & 7) == 0) {
#pragma pipeloop(0)
				for (; pd < (pend - 1); pd += 2, ps += 2) {
					d64_2_f32 d0;

					d0.d64 = *(mlib_d64 *)ps;
					d0.f32s.f0 = -d0.f32s.f0;
					d0.f32s.f1 = -d0.f32s.f1;
					*(mlib_d64 *)pd = d0.d64;
				}
			} else {
#pragma pipeloop(0)
				for (; pd < (pend - 1); pd += 2, ps += 2) {
					d64_2_f32 d0;

					d0.f32s.f0 = -(*ps);
					d0.f32s.f1 = -(*(ps + 1));
					*(mlib_d64 *)pd = d0.d64;
				}
			}

			if (pd < pend)
				(*pd++) = -((*ps++));
			psrc += slb;
			pdst += dlb;
		}

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

		for (j = 0; j < ysize; j++) {
#pragma pipeloop(0)
			for (i = 0; i < xsize - 1; i += 2) {
				((mlib_d64 *)pdst)[i] =
				    -(((mlib_d64 *)psrc)[i]);
				((mlib_d64 *)pdst)[i + 1] =
				    -(((mlib_d64 *)psrc)[i + 1]);
			}

#pragma pipeloop(0)
			for (; i < xsize; i++)
				((mlib_d64 *)pdst)[i] =
				    -(((mlib_d64 *)psrc)[i]);
			psrc += slb;
			pdst += dlb;
		}

		return (MLIB_SUCCESS);
	}

	return (MLIB_FAILURE);
}
mlib_status
__mlib_GraphicsFloodFill_32(
    mlib_image *buffer,
    mlib_s16 x,
    mlib_s16 y,
    mlib_s32 c,
    mlib_s32 c2)
{
	mlib_s32 stride = mlib_ImageGetStride(buffer) / sizeof (imtype);
	mlib_s32 width = mlib_ImageGetWidth(buffer);
	mlib_s32 height = mlib_ImageGetHeight(buffer);
	imtype *data = mlib_ImageGetData(buffer);
	imtype *line = data + y * stride, *sline;
	mlib_s32 cline, curl, curr, spl, spr;
	mlib_s32 parline, parl, parr;

/* stack counters */
	mlib_s32 stacktop = 0;

/* number of additional mem blocks */
	mlib_s32 nexspan = 0;
	span *spanp;

	mlib_d64 dc = vis_to_double_dup(c);
	mlib_d64 dc2 = vis_to_double_dup(c2);

/* ptrs to span stack blocks */
	span *pexspan[256];

/* 1st block of span stack */
	span spanstack[SPANSTACKSIZE];

	if (!data)
		return (MLIB_NULLPOINTER);

	if (x < 0 || x >= width || y < 0 || y >= height || stride < width)
		return (MLIB_FAILURE);

	if (line[x] != c2)
		return (MLIB_SUCCESS);

	pexspan[0] = spanstack;
	curl = curr = x;

/*  fill first with finding borders  */
	while (curl > 0 && line[curl - 1] == c2) {
		--curl;
		line[curl] = c;
	}

	while (curr < width && line[curr] == c2) {
		line[curr] = c;
		++curr;
	}

	if (height == 1)
		return (MLIB_SUCCESS);

	cline = y;
	parline = y + 1;
	sline = line - stride;
	CHECKFORW;
	parline = y - 1;
	sline = line + stride;
	CHECKFORW;

	for (; ; ) {
		GETSPAN;
		line = data + cline * stride;
		sline = line + stride * (parline - cline);
		CHECKBACK;
		sline = line - stride * (parline - cline);
		CHECKFORW;

	}	/* end of main loop */

/*  free stubs  */
	for (; nexspan; nexspan--)
		__mlib_free(pexspan[nexspan]);

	return (MLIB_SUCCESS);
}
mlib_status mlib_AffineEdges(mlib_affine_param *param,
                             const mlib_image  *dst,
                             const mlib_image  *src,
                             void              *buff_lcl,
                             mlib_s32          buff_size,
                             mlib_s32          kw,
                             mlib_s32          kh,
                             mlib_s32          kw1,
                             mlib_s32          kh1,
                             mlib_edge         edge,
                             const mlib_d64    *mtx,
                             mlib_s32          shiftx,
                             mlib_s32          shifty)
{
  mlib_u8 *buff = buff_lcl;
  mlib_u8 **lineAddr = param->lineAddr;
  mlib_s32 srcWidth, dstWidth, srcHeight, dstHeight, srcYStride, dstYStride;
  mlib_s32 *leftEdges, *rightEdges, *xStarts, *yStarts, bsize0, bsize1 = 0;
  mlib_u8 *srcData, *dstData;
  mlib_u8 *paddings;
  void *warp_tbl = NULL;
  mlib_s32 yStart = 0, yFinish = -1, dX, dY;

  mlib_d64 xClip, yClip, wClip, hClip;
  mlib_d64 delta = 0.;
  mlib_d64 minX, minY, maxX, maxY;

  mlib_d64 coords[4][2];
  mlib_d64 a = mtx[0], b = mtx[1], tx = mtx[2], c = mtx[3], d = mtx[4], ty = mtx[5];
  mlib_d64 a2, b2, tx2, c2, d2, ty2;
  mlib_d64 dx, dy, div;
  mlib_s32 sdx, sdy;
  mlib_d64 dTop;
  mlib_d64 val0;
  mlib_s32 top, bot;
  mlib_s32 topIdx, max_xsize = 0;
  mlib_s32 i, j, t;

  srcData = mlib_ImageGetData(src);
  dstData = mlib_ImageGetData(dst);
  srcWidth = mlib_ImageGetWidth(src);
  srcHeight = mlib_ImageGetHeight(src);
  dstWidth = mlib_ImageGetWidth(dst);
  dstHeight = mlib_ImageGetHeight(dst);
  srcYStride = mlib_ImageGetStride(src);
  dstYStride = mlib_ImageGetStride(dst);
  paddings = mlib_ImageGetPaddings(src);

  if (srcWidth >= (1 << 15) || srcHeight >= (1 << 15)) {
    return MLIB_FAILURE;
  }

  div = a * d - b * c;

  if (div == 0.0) {
    return MLIB_FAILURE;
  }

  bsize0 = (dstHeight * sizeof(mlib_s32) + 7) & ~7;

  if (lineAddr == NULL) {
    bsize1 = ((srcHeight + 4 * kh) * sizeof(mlib_u8 *) + 7) & ~7;
  }

  param->buff_malloc = NULL;

  if ((4 * bsize0 + bsize1) > buff_size) {
    buff = param->buff_malloc = mlib_malloc(4 * bsize0 + bsize1);

    if (buff == NULL)
      return MLIB_FAILURE;
  }

  leftEdges = (mlib_s32 *) (buff);
  rightEdges = (mlib_s32 *) (buff += bsize0);
  xStarts = (mlib_s32 *) (buff += bsize0);
  yStarts = (mlib_s32 *) (buff += bsize0);

  if (lineAddr == NULL) {
    mlib_u8 *srcLinePtr = srcData;
    lineAddr = (mlib_u8 **) (buff += bsize0);
    for (i = 0; i < 2 * kh; i++)
      lineAddr[i] = srcLinePtr;
    lineAddr += 2 * kh;
    for (i = 0; i < srcHeight - 1; i++) {
      lineAddr[i] = srcLinePtr;
      srcLinePtr += srcYStride;
    }

    for (i = srcHeight - 1; i < srcHeight + 2 * kh; i++)
      lineAddr[i] = srcLinePtr;
  }

  if ((mlib_s32) edge < 0) {                               /* process edges */
    minX = 0;
    minY = 0;
    maxX = srcWidth;
    maxY = srcHeight;
  }
  else {

    if (kw > 1)
      delta = -0.5;                                        /* for MLIB_NEAREST filter delta = 0. */

    minX = (kw1 - delta);
    minY = (kh1 - delta);
    maxX = srcWidth - ((kw - 1) - (kw1 - delta));
    maxY = srcHeight - ((kh - 1) - (kh1 - delta));

    if (edge == MLIB_EDGE_SRC_PADDED) {
      if (minX < paddings[0])
        minX = paddings[0];

      if (minY < paddings[1])
        minY = paddings[1];

      if (maxX > (srcWidth - paddings[2]))
        maxX = srcWidth - paddings[2];

      if (maxY > (srcHeight - paddings[3]))
        maxY = srcHeight - paddings[3];
    }
  }

  xClip = minX;
  yClip = minY;
  wClip = maxX;
  hClip = maxY;

/*
 *   STORE_PARAM(param, src);
 *   STORE_PARAM(param, dst);
 */
  param->src = (void *)src;
  param->dst = (void *)dst;
  STORE_PARAM(param, lineAddr);
  STORE_PARAM(param, dstData);
  STORE_PARAM(param, srcYStride);
  STORE_PARAM(param, dstYStride);
  STORE_PARAM(param, leftEdges);
  STORE_PARAM(param, rightEdges);
  STORE_PARAM(param, xStarts);
  STORE_PARAM(param, yStarts);
  STORE_PARAM(param, max_xsize);
  STORE_PARAM(param, yStart);
  STORE_PARAM(param, yFinish);
  STORE_PARAM(param, warp_tbl);

  if ((xClip >= wClip) || (yClip >= hClip)) {
    return MLIB_SUCCESS;
  }

  a2 = d;
  b2 = -b;
  tx2 = (-d * tx + b * ty);
  c2 = -c;
  d2 = a;
  ty2 = (c * tx - a * ty);

  dx = a2;
  dy = c2;

  tx -= 0.5;
  ty -= 0.5;

  coords[0][0] = xClip * a + yClip * b + tx;
  coords[0][1] = xClip * c + yClip * d + ty;

  coords[2][0] = wClip * a + hClip * b + tx;
  coords[2][1] = wClip * c + hClip * d + ty;

  if (div > 0) {
    coords[1][0] = wClip * a + yClip * b + tx;
    coords[1][1] = wClip * c + yClip * d + ty;

    coords[3][0] = xClip * a + hClip * b + tx;
    coords[3][1] = xClip * c + hClip * d + ty;
  }
  else {
    coords[3][0] = wClip * a + yClip * b + tx;
    coords[3][1] = wClip * c + yClip * d + ty;

    coords[1][0] = xClip * a + hClip * b + tx;
    coords[1][1] = xClip * c + hClip * d + ty;
  }

  topIdx = 0;
  for (i = 1; i < 4; i++) {

    if (coords[i][1] < coords[topIdx][1])
      topIdx = i;
  }

  dTop = coords[topIdx][1];
  val0 = dTop;
  SAT32(top);
  bot = -1;

  if (top >= dstHeight) {
    return MLIB_SUCCESS;
  }

  if (dTop >= 0.0) {
    mlib_d64 xLeft, xRight, x;
    mlib_s32 nextIdx;

    if (dTop == top) {
      xLeft = coords[topIdx][0];
      xRight = coords[topIdx][0];
      nextIdx = (topIdx + 1) & 0x3;

      if (dTop == coords[nextIdx][1]) {
        x = coords[nextIdx][0];
        xLeft = (xLeft <= x) ? xLeft : x;
        xRight = (xRight >= x) ? xRight : x;
      }

      nextIdx = (topIdx - 1) & 0x3;

      if (dTop == coords[nextIdx][1]) {
        x = coords[nextIdx][0];
        xLeft = (xLeft <= x) ? xLeft : x;
        xRight = (xRight >= x) ? xRight : x;
      }

      val0 = xLeft;
      SAT32(t);
      leftEdges[top] = (t >= xLeft) ? t : ++t;

      if (xLeft >= MLIB_S32_MAX)
        leftEdges[top] = MLIB_S32_MAX;

      val0 = xRight;
      SAT32(rightEdges[top]);
    }
    else
      top++;
  }
  else
    top = 0;

  for (i = 0; i < 2; i++) {
    mlib_d64 dY1 = coords[(topIdx - i) & 0x3][1];
    mlib_d64 dX1 = coords[(topIdx - i) & 0x3][0];
    mlib_d64 dY2 = coords[(topIdx - i - 1) & 0x3][1];
    mlib_d64 dX2 = coords[(topIdx - i - 1) & 0x3][0];
    mlib_d64 x = dX1, slope = (dX2 - dX1) / (dY2 - dY1);
    mlib_s32 y1;
    mlib_s32 y2;

    if (dY1 == dY2)
      continue;

    if (dY1 < 0.0)
      y1 = 0;
    else {
      val0 = dY1 + 1;
      SAT32(y1);
    }

    val0 = dY2;
    SAT32(y2);

    if (y2 >= dstHeight)
      y2 = (mlib_s32) (dstHeight - 1);

    x += slope * (y1 - dY1);
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
    for (j = y1; j <= y2; j++) {
      val0 = x;
      SAT32(t);
      leftEdges[j] = (t >= x) ? t : ++t;

      if (x >= MLIB_S32_MAX)
        leftEdges[j] = MLIB_S32_MAX;
      x += slope;
    }
  }

  for (i = 0; i < 2; i++) {
    mlib_d64 dY1 = coords[(topIdx + i) & 0x3][1];
    mlib_d64 dX1 = coords[(topIdx + i) & 0x3][0];
    mlib_d64 dY2 = coords[(topIdx + i + 1) & 0x3][1];
    mlib_d64 dX2 = coords[(topIdx + i + 1) & 0x3][0];
    mlib_d64 x = dX1, slope = (dX2 - dX1) / (dY2 - dY1);
    mlib_s32 y1;
    mlib_s32 y2;

    if (dY1 == dY2)
      continue;

    if (dY1 < 0.0)
      y1 = 0;
    else {
      val0 = dY1 + 1;
      SAT32(y1);
    }

    val0 = dY2;
    SAT32(y2);

    if (y2 >= dstHeight)
      y2 = (mlib_s32) (dstHeight - 1);

    x += slope * (y1 - dY1);
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
    for (j = y1; j <= y2; j++) {
      val0 = x;
      SAT32(rightEdges[j]);
      x += slope;
    }

    bot = y2;
  }

  {
    mlib_d64 dxCl = xClip * div;
    mlib_d64 dyCl = yClip * div;
    mlib_d64 dwCl = wClip * div;
    mlib_d64 dhCl = hClip * div;

    mlib_s32 xCl = (mlib_s32) (xClip + delta);
    mlib_s32 yCl = (mlib_s32) (yClip + delta);
    mlib_s32 wCl = (mlib_s32) (wClip + delta);
    mlib_s32 hCl = (mlib_s32) (hClip + delta);

    /*
     * mlib_s32 xCl = (mlib_s32)(xClip + delta);
     * mlib_s32 yCl = (mlib_s32)(yClip + delta);
     * mlib_s32 wCl = (mlib_s32)(wClip);
     * mlib_s32 hCl = (mlib_s32)(hClip);
     */

    if (edge == MLIB_EDGE_SRC_PADDED) {
      xCl = kw1;
      yCl = kh1;
      wCl = (mlib_s32) (srcWidth - ((kw - 1) - kw1));
      hCl = (mlib_s32) (srcHeight - ((kh - 1) - kh1));
    }

    div = 1.0 / div;

    sdx = (mlib_s32) (a2 * div * (1 << shiftx));
    sdy = (mlib_s32) (c2 * div * (1 << shifty));

    if (div > 0) {

#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
      for (i = top; i <= bot; i++) {
        mlib_s32 xLeft = leftEdges[i];
        mlib_s32 xRight = rightEdges[i];
        mlib_s32 xs, ys, x_e, y_e, x_s, y_s;
        mlib_d64 dxs, dys, dxe, dye;
        mlib_d64 xl, ii, xr;

        xLeft = (xLeft < 0) ? 0 : xLeft;
        xRight = (xRight >= dstWidth) ? (mlib_s32) (dstWidth - 1) : xRight;

        xl = xLeft + 0.5;
        ii = i + 0.5;
        xr = xRight + 0.5;
        dxs = xl * a2 + ii * b2 + tx2;
        dys = xl * c2 + ii * d2 + ty2;

        if ((dxs < dxCl) || (dxs >= dwCl) || (dys < dyCl) || (dys >= dhCl)) {
          dxs += dx;
          dys += dy;
          xLeft++;

          if ((dxs < dxCl) || (dxs >= dwCl) || (dys < dyCl) || (dys >= dhCl))
            xRight = -1;
        }

        dxe = xr * a2 + ii * b2 + tx2;
        dye = xr * c2 + ii * d2 + ty2;

        if ((dxe < dxCl) || (dxe >= dwCl) || (dye < dyCl) || (dye >= dhCl)) {
          dxe -= dx;
          dye -= dy;
          xRight--;

          if ((dxe < dxCl) || (dxe >= dwCl) || (dye < dyCl) || (dye >= dhCl))
            xRight = -1;
        }

        xs = (mlib_s32) ((dxs * div + delta) * (1 << shiftx));
        x_s = xs >> shiftx;

        ys = (mlib_s32) ((dys * div + delta) * (1 << shifty));
        y_s = ys >> shifty;

        if (x_s < xCl)
          xs = (xCl << shiftx);
        else if (x_s >= wCl)
          xs = ((wCl << shiftx) - 1);

        if (y_s < yCl)
          ys = (yCl << shifty);
        else if (y_s >= hCl)
          ys = ((hCl << shifty) - 1);

        if (xRight >= xLeft) {
          x_e = ((xRight - xLeft) * sdx + xs) >> shiftx;
          y_e = ((xRight - xLeft) * sdy + ys) >> shifty;

          if ((x_e < xCl) || (x_e >= wCl)) {
            if (sdx > 0)
              sdx -= 1;
            else
              sdx += 1;
          }

          if ((y_e < yCl) || (y_e >= hCl)) {
            if (sdy > 0)
              sdy -= 1;
            else
              sdy += 1;
          }
        }

        leftEdges[i] = xLeft;
        rightEdges[i] = xRight;
        xStarts[i] = xs;
        yStarts[i] = ys;

        if ((xRight - xLeft + 1) > max_xsize)
          max_xsize = (xRight - xLeft + 1);
      }
    }
    else {

#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
      for (i = top; i <= bot; i++) {
Example #24
0
mlib_status
__mlib_ImageThresh2(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_s32 *thresh,
    const mlib_s32 *glow)
{
	mlib_s32 sstride, dstride, width, height, nchan;
	mlib_type dtype;
	void *psrc, *pdst;
	mlib_s32 th[4], gl[4];
	mlib_s32 i;

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

	dtype = mlib_ImageGetType(src);
	nchan = mlib_ImageGetChannels(src);
	width = mlib_ImageGetWidth(src);
	height = mlib_ImageGetHeight(src);
	sstride = mlib_ImageGetStride(src);
	dstride = mlib_ImageGetStride(dst);
	psrc = mlib_ImageGetData(src);
	pdst = mlib_ImageGetData(dst);

	if (dtype == MLIB_BYTE) {

		for (i = 0; i < nchan; i++) {
			gl[i] = glow[i] & 255;

			if (thresh[i] > MLIB_U8_MAX)
				th[i] = MLIB_U8_MAX;
			else if (thresh[i] < 0) {
				th[i] = 0;
				gl[i] = 0;
			} else
				th[i] = thresh[i];
		}

/* x * 3.5 < x * 2.2 + 256 */
		if ((width * height) < 200) {
			switch (nchan) {
			case 1:
				mlib_c_ImageThresh2_U81(psrc, sstride, pdst,
				    dstride, width, height, th, gl);
				break;
			case 2:
				mlib_c_ImageThresh2_U82(psrc, sstride, pdst,
				    dstride, width, height, th, gl);
				break;
			case 3:
				mlib_c_ImageThresh2_U83(psrc, sstride, pdst,
				    dstride, width, height, th, gl);
				break;
			case 4:
				mlib_c_ImageThresh2_U84(psrc, sstride, pdst,
				    dstride, width, height, th, gl);
				break;
			}
		} else {
			mlib_s32 i, c, t;
			mlib_d64 lookup[128];
			mlib_u8 *arr[4], *p;
			mlib_u8 glu;

			arr[0] = (mlib_u8 *)(&(lookup[0]));
			arr[1] = (mlib_u8 *)(&(lookup[32]));
			arr[2] = (mlib_u8 *)(&(lookup[64]));
			arr[3] = (mlib_u8 *)(&(lookup[96]));
			for (c = 0; c < nchan; c++) {
				p = arr[c];
				t = th[c];
				glu = gl[c];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
				for (i = 0; i <= t; i++) {
					p[i] = glu;
				}

#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
				for (; i < 256; i++) {
					p[i] = i;
				}
			}

			return (__mlib_ImageLookUp
				(dst, src, (const void **)arr));
		}

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

		for (i = 0; i < nchan; i++) {
			gl[i] = (glow[i] << 16) >> 16;

			if (thresh[i] > MLIB_S16_MAX)
				th[i] = MLIB_S16_MAX;
			else if (thresh[i] < MLIB_S16_MIN) {
				th[i] = MLIB_S16_MIN;
				gl[i] = MLIB_S16_MIN;
			} else
				th[i] = thresh[i];
		}

		switch (nchan) {
		case 1:
			mlib_c_ImageThresh2_S161(psrc, sstride, pdst, dstride,
			    width, height, th, gl);
			break;
		case 2:
			mlib_c_ImageThresh2_S162(psrc, sstride, pdst, dstride,
			    width, height, th, gl);
			break;
		case 3:
			mlib_c_ImageThresh2_S163(psrc, sstride, pdst, dstride,
			    width, height, th, gl);
			break;
		case 4:
			mlib_c_ImageThresh2_S164(psrc, sstride, pdst, dstride,
			    width, height, th, gl);
			break;
		}

		return (MLIB_SUCCESS);
	} else if (dtype == MLIB_USHORT) {
mlib_status
mlib_ImagePolynomialWarpTable_0(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_d64 *xCoeffs,
    const mlib_d64 *yCoeffs,
    mlib_d64 postShiftX,
    mlib_d64 postShiftY,
    mlib_d64 postScaleX,
    mlib_d64 postScaleY,
    const void *interp_table,
    mlib_edge edge)
{
	mlib_s32 color[4];
	mlib_d64 wx, wy;
	mlib_d64 Xstart, Ystart, Xstop, Ystop;
	mlib_s32 wkernel = mlib_ImageGetInterpWidth(interp_table);
	mlib_s32 hkernel = mlib_ImageGetInterpHeight(interp_table);
	mlib_s32 top = mlib_ImageGetInterpTopPadding(interp_table);
	mlib_s32 left = mlib_ImageGetInterpLeftPadding(interp_table);
	mlib_u8 *srcData = mlib_ImageGetData(src);
	mlib_type itype = mlib_ImageGetType(src);
	mlib_s32 type = (itype == MLIB_BYTE) ? 1 :
	    ((itype == MLIB_SHORT || itype == MLIB_USHORT) ? 2 : 4);
	mlib_d64 *pH = mlib_ImageGetInterpDoubleDataH(interp_table);
	mlib_d64 *pV = mlib_ImageGetInterpDoubleDataV(interp_table);
	mlib_d64 scaleH = 1 << mlib_ImageGetInterpSubsampleBitsH(interp_table);
	mlib_d64 scaleV = 1 << mlib_ImageGetInterpSubsampleBitsV(interp_table);
	mlib_s32 shiftH = mlib_ImageGetInterpWidthBits(interp_table);
	mlib_s32 shiftV = mlib_ImageGetInterpHeightBits(interp_table);
	mlib_s32 src_stride = mlib_ImageGetStride(src);
	mlib_s32 channel = mlib_ImageGetChannels(src);

	wx = xCoeffs[0] * postScaleX - postShiftX;
	wy = yCoeffs[0] * postScaleY - postShiftY;

	Xstart = left + 0.5;
	Ystart = top + 0.5;
	Xstop = mlib_ImageGetWidth(src) - (wkernel - Xstart);
	Ystop = mlib_ImageGetHeight(src) - (hkernel - Ystart);

	if (edge == MLIB_EDGE_SRC_PADDED) {
		mlib_u8 *paddings = mlib_ImageGetPaddings(src);

		if (paddings[0] > Xstart)
			Xstart = paddings[0];

		if (paddings[1] > Ystart)
			Ystart = paddings[1];

		if ((mlib_ImageGetWidth(src) - paddings[2]) < Xstop)
			Xstop = mlib_ImageGetWidth(src) - paddings[2];

		if ((mlib_ImageGetHeight(src) - paddings[3]) < Ystop)
			Ystop = mlib_ImageGetHeight(src) - paddings[3];
	}

	if (!(wx >= Xstart && wx < Xstop && wy >= Ystart && wy < Ystop))
		return (MLIB_SUCCESS);

	wx -= 0.5;
	wy -= 0.5;

	srcData +=
	    ((mlib_s32)wy - top) * src_stride + ((mlib_s32)wx -
	    left) * channel * type;

	pH += (mlib_s32)((wx - (mlib_s32)wx) * scaleH) << shiftH;
	pV += (mlib_s32)((wy - (mlib_s32)wy) * scaleV) << shiftV;

	switch (itype) {
	case MLIB_BYTE:
		COMP_POINT(mlib_u8,
		    MLIB_U8_MIN,
		    MLIB_U8_MAX);

		break;

	case MLIB_SHORT:
		COMP_POINT(mlib_s16,
		    MLIB_S16_MIN,
		    MLIB_S16_MAX);

		break;

	case MLIB_USHORT:
		COMP_POINT(mlib_u16,
		    MLIB_U16_MIN,
		    MLIB_U16_MAX);

		break;

	case MLIB_INT:
		COMP_POINT(mlib_s32,
		    MLIB_S32_MIN,
		    MLIB_S32_MAX);

		break;

	default:
		return (MLIB_FAILURE);
	}

	return (__mlib_ImageClear(dst, color));
}
Example #26
0
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_GraphicsDrawArc_AB_32(
    mlib_image *buffer,
    mlib_s16 x,
    mlib_s16 y,
    mlib_s32 r,
    mlib_f32 t1,
    mlib_f32 t2,
    mlib_s32 c,
    mlib_s32 a)
{
	mlib_s32 stride = mlib_ImageGetStride(buffer) / sizeof (mlib_s32);
	mlib_s32 width = mlib_ImageGetWidth(buffer) - 1;
	mlib_s32 height = mlib_ImageGetHeight(buffer) - 1;
	mlib_s32 *data = mlib_ImageGetData(buffer);
	mlib_s32 *line0, *line;
	mlib_s32 cx, cy, del, mask;

	mlib_s32 sin1, cos1, sin2, cos2, oct1, oct2, flagc, flagd;
	pinfo buf0[BUFSIZE], *buf = 0;
	mlib_s32 count, scount;
	mlib_s32 start, end;

	mlib_s32 ind0, ind1, ind2, mdel, k;
	mlib_d64 c0, c1, c2;
	mlib_f32 cf;
	mlib_d64 d_one = ((mlib_d64 *)mlib_v_TabAlias)[0];

	mlib_s32 a1;
	mlib_f32 fa;
	mlib_d64 da, da1, dc;
	mlib_f32 falpha = vis_to_float(0xFF000000);

	a &= 0xff;
	a1 = ~a & 0xff;

	fa = vis_to_float((a << 16) | (a << 8) | a);
	da = vis_to_double((a << 6), (a << 22) | (a << 6));
	da1 = vis_to_double((a1 << 6), (a1 << 22) | (a1 << 6));
	dc = vis_fmul8x16al(vis_to_float(c), vis_to_float(0x4000));
	vis_write_gsr((1 << 3) + 0);

	c |= 0xFF000000;
	cf = vis_to_float(c);
	if (!data)
		return (MLIB_NULLPOINTER);

	if (r < 0)
		return (MLIB_FAILURE);

	CHECK_INTERSECTION;

	if (r == 0) {
		if (INSIDE(x, y))
			BLE32((data + (stride * y + x)), 0);
		return (MLIB_SUCCESS);
	}

	if (mlib_fabs(t1 - t2) >= PIx2)
		return (__mlib_GraphicsDrawCircle_AB_32(buffer, x, y, r, c, a));
	{
		mlib_f32 tt = t1;

		t1 = -t2;
		t2 = -tt;
	}

	if (t1 > t2)
		t2 += PIx2;

	line0 = data + stride * y + x;

	if (r > RADMAX) {
		buf = (pinfo *) __mlib_malloc(sizeof (pinfo) * r);

		if (!buf)
			return (MLIB_FAILURE);
	} else
		buf = buf0;

	k = (0x100000 / r);

	FILL_BUF;

	GET_BORDERS;

	FILL_FLAGS;

	FILL_CL_FLAGS;

	start = 0;
	end = count;
	PROC_OCT(y, y - height, x - width, x, 2, cos, 1, 2, stride, -1);
	start = 1;
	end = count;
	PROC_OCT(y, y - height, -x, width - x, 1, cos, 2, 1, stride, 1);
	start = 0;
	end = count;
	PROC_OCT(height - y, -y, x - width, x, 5, cos, 2, 1, -stride, -1);
	start = 1;
	end = count;
	PROC_OCT(height - y, -y, -x, width - x, 6, cos, 1, 2, -stride, 1);

	start = 1;
	end = scount;
	PROC_OCT(x, x - width, y - height, y, 3, sin, 2, 1, 1, -stride);
	start = 0;
	end = scount;
	PROC_OCT(x, x - width, -y, height - y, 4, sin, 1, 2, 1, stride);
	start = 1;
	end = scount;
	PROC_OCT(width - x, -x, y - height, y, 0, sin, 1, 2, -1, -stride);
	start = 0;
	end = scount;
	PROC_OCT(width - x, -x, -y, height - y, 7, sin, 2, 1, -1, stride);

	if (buf != buf0)
		__mlib_free(buf);

	return (MLIB_SUCCESS);
}
Example #28
0
mlib_status
__mlib_ImageMax_Fp(
    mlib_image *dst,
    const mlib_image *src1,
    const mlib_image *src2)
{
	mlib_type dst_type;
	mlib_s32 dst_chan, dst_width, dst_height;
	mlib_s32 dst_stride, src1_stride, src2_stride;
	mlib_u8 *dst_data, *src1_data, *src2_data;
	mlib_s32 xsize;
	mlib_s32 i, j;

	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_CHECK(src1);
	MLIB_IMAGE_CHECK(src2);
	MLIB_IMAGE_FULL_EQUAL(dst, src1);
	MLIB_IMAGE_FULL_EQUAL(dst, src2);

	MLIB_IMAGE_GET_ALL_PARAMS(dst, dst_type, dst_chan, dst_width,
	    dst_height, dst_stride, dst_data);
	src1_stride = mlib_ImageGetStride(src1);
	src1_data = mlib_ImageGetData(src1);
	src2_stride = mlib_ImageGetStride(src2);
	src2_data = mlib_ImageGetData(src2);

	xsize = dst_width * dst_chan;

	if (dst_type == MLIB_FLOAT) {
		for (i = 0; i < dst_height; i++) {
			for (j = 0; j < xsize - 3; j += 4) {
				mlib_f32 x0 = ((mlib_f32 *)src1_data)[j];
				mlib_f32 y0 = ((mlib_f32 *)src2_data)[j];
				mlib_f32 x1 = ((mlib_f32 *)src1_data)[j + 1];
				mlib_f32 y1 = ((mlib_f32 *)src2_data)[j + 1];
				mlib_f32 x2 = ((mlib_f32 *)src1_data)[j + 2];
				mlib_f32 y2 = ((mlib_f32 *)src2_data)[j + 2];
				mlib_f32 x3 = ((mlib_f32 *)src1_data)[j + 3];
				mlib_f32 y3 = ((mlib_f32 *)src2_data)[j + 3];

				((mlib_f32 *)dst_data)[j] = MAX(x0, y0);
				((mlib_f32 *)dst_data)[j + 1] = MAX(x1, y1);
				((mlib_f32 *)dst_data)[j + 2] = MAX(x2, y2);
				((mlib_f32 *)dst_data)[j + 3] = MAX(x3, y3);
			}

			for (; j < xsize; j++) {
				mlib_f32 x = ((mlib_f32 *)src1_data)[j];
				mlib_f32 y = ((mlib_f32 *)src2_data)[j];

				((mlib_f32 *)dst_data)[j] = MAX(x, y);
			}

			dst_data += dst_stride;
			src1_data += src1_stride;
			src2_data += src2_stride;
		}

		return (MLIB_SUCCESS);
	} else if (dst_type == MLIB_DOUBLE) {
		for (i = 0; i < dst_height; i++) {
			for (j = 0; j < xsize - 3; j += 4) {
				mlib_d64 x0 = ((mlib_d64 *)src1_data)[j];
				mlib_d64 y0 = ((mlib_d64 *)src2_data)[j];
				mlib_d64 x1 = ((mlib_d64 *)src1_data)[j + 1];
				mlib_d64 y1 = ((mlib_d64 *)src2_data)[j + 1];
				mlib_d64 x2 = ((mlib_d64 *)src1_data)[j + 2];
				mlib_d64 y2 = ((mlib_d64 *)src2_data)[j + 2];
				mlib_d64 x3 = ((mlib_d64 *)src1_data)[j + 3];
				mlib_d64 y3 = ((mlib_d64 *)src2_data)[j + 3];

				((mlib_d64 *)dst_data)[j] = MAX(x0, y0);
				((mlib_d64 *)dst_data)[j + 1] = MAX(x1, y1);
				((mlib_d64 *)dst_data)[j + 2] = MAX(x2, y2);
				((mlib_d64 *)dst_data)[j + 3] = MAX(x3, y3);
			}

			for (; j < xsize; j++) {
				mlib_d64 x = ((mlib_d64 *)src1_data)[j];
				mlib_d64 y = ((mlib_d64 *)src2_data)[j];

				((mlib_d64 *)dst_data)[j] = MAX(x, y);
			}

			dst_data += dst_stride;
			src1_data += src1_stride;
			src2_data += src2_stride;
		}

		return (MLIB_SUCCESS);
	}

	return (MLIB_FAILURE);
}
mlib_status
__mlib_ImageScalarBlend(
    mlib_image *dst,
    const mlib_image *src1,
    const mlib_image *src2,
    const mlib_s32 *alpha)
{
	mlib_s32 slb1, slb2, dlb, xsize, ysize, nchan;
	mlib_type dtype;
	void *sa1, *sa2, *da;
	mlib_s32 i, j;

	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_CHECK(src1);
	MLIB_IMAGE_CHECK(src2);
	MLIB_IMAGE_FULL_EQUAL(dst, src1);
	MLIB_IMAGE_FULL_EQUAL(dst, src2);

	if (alpha == NULL)
		return (MLIB_FAILURE);
	for (i = 0; i < mlib_ImageGetChannels(dst); i++) {
		if (alpha[i] < 0) {
			return (MLIB_FAILURE);
		}
	}

	MLIB_IMAGE_GET_ALL_PARAMS(dst, dtype, nchan, xsize, ysize, dlb, da);
	slb1 = mlib_ImageGetStride(src1);
	sa1 = mlib_ImageGetData(src1);
	slb2 = mlib_ImageGetStride(src2);
	sa2 = mlib_ImageGetData(src2);

	if (dtype == MLIB_BYTE) {

		mlib_u8 plut[4 * 511], *lut[4], *lutj;
		mlib_s32 res, acc, al;

		for (j = 0; j < nchan; j++) {
/* acc = 0.5 */
			acc = 1 << 22;
/* variable for alpha coefficients */
			al = (alpha[j] & MASK) >> 8;
			lut[j] = lutj = plut + j * 511 + 255;
			lutj[0] = 0;
			for (i = 1; i < 256; i++) {
				acc += al;
				res = acc >> 23;
				lutj[i] = res;
				lutj[-i] = -res;
			}
		}

		switch (nchan) {

		case 1:
			lut[1] = lut[2] = lut[3] = lut[0];
			mlib_c_ImageScalarBlend_U8_124((mlib_u8 *)sa1, slb1,
			    (mlib_u8 *)sa2, slb2, (mlib_u8 *)da, dlb, xsize,
			    ysize, lut);
			break;

		case 2:
			lut[2] = lut[0];
			lut[3] = lut[1];
			mlib_c_ImageScalarBlend_U8_124((mlib_u8 *)sa1, slb1,
			    (mlib_u8 *)sa2, slb2, (mlib_u8 *)da, dlb, 2 * xsize,
			    ysize, lut);
			break;

		case 3:
			mlib_c_ImageScalarBlend_U8_3((mlib_u8 *)sa1, slb1,
			    (mlib_u8 *)sa2, slb2, (mlib_u8 *)da, dlb, 3 * xsize,
			    ysize, lut);
			break;

		case 4:
			mlib_c_ImageScalarBlend_U8_124((mlib_u8 *)sa1, slb1,
			    (mlib_u8 *)sa2, slb2, (mlib_u8 *)da, dlb, 4 * xsize,
			    ysize, lut);
			break;

		default:
			return (MLIB_FAILURE);
		}

		return (MLIB_SUCCESS);
	} else if (dtype == MLIB_SHORT) {
mlib_status
__mlib_GraphicsFillArc_AB_32(
    mlib_image *buffer,
    mlib_s16 x,
    mlib_s16 y,
    mlib_s32 r,
    mlib_f32 t1,
    mlib_f32 t2,
    mlib_s32 c,
    mlib_s32 a)
{
	mlib_s32 stride = mlib_ImageGetStride(buffer) / sizeof (mlib_s32);
	mlib_s32 width = mlib_ImageGetWidth(buffer) - 1;
	mlib_s32 height = mlib_ImageGetHeight(buffer) - 1;
	mlib_s32 lwidth = width - 1;
	mlib_s32 lheight = height - 1;
	mlib_s32 *data = mlib_ImageGetData(buffer);
	mlib_s32 *line0, *line;
	mlib_s32 cx, cy, del, mask;
	mlib_status rez;

	mlib_s32 stepsignx1, stepsignx2, stepsigny1, stepsigny2;
	mlib_s32 lineindex1 = 0, lineindex2 = 0;
	mlib_s32 ifoverlap = 0;

	mlib_f32 tt1 = t1, tt2 = t2;
	mlib_s32 sn1, cs1, sn2, cs2;
	mlib_s32 sin1, cos1, sin2, cos2, oct1, oct2, flagc, flagd;
	mlib_s32 xx, yy, ux, uy, dx, dy;

	pinfo buf0[BUFSIZE], *buf = 0;
	pinfo_line buf0_line1[RADMAX+1], *buf_line1 = 0;
	pinfo_line buf0_line2[RADMAX+1], *buf_line2 = 0;
	pinfo_line *buf_line;

	mlib_s32 count, scount;
	mlib_s32 start, end;

	mlib_s32 ind0, ind1, ind2, c0, c1, c2, mdel, k;
	mlib_s32 alpha0, alpha1, alpha2;
	mlib_s32 cf0 = c & 0xff, cf1 = (c & 0xff00) >> 8, cf2 =
	    (c & 0xff0000) >> 16;
	mlib_u8 cfalpha = 0xFF;
	mlib_d64 A0, A1;

	a &= 0xff;
	A1 = a / 255.;
	A0 = 1. - A1;

	if (!data)
		return (MLIB_NULLPOINTER);

	if (r < 0)
		return (MLIB_FAILURE);

	CHECK_INTERSECTION;

	if (r == 0) {
		if (INSIDE(x, y)) {
			BLEND32((data + (stride * y + x))[0], c, a);
		}
		return (MLIB_SUCCESS);
	}

	if (mlib_fabs(t1 - t2) >= PIx2) {
		return (__mlib_GraphicsFillCircle_AB_32(buffer, x, y, r, c, a));
	}
	{
		mlib_f32 tt = t1;

		t1 = -t2;
		t2 = -tt;
	}

	if (t1 > t2)
		t2 += PIx2;

	line0 = data + stride * y + x;

	if (r > RADMAX) {
		buf = (pinfo *) __mlib_malloc(sizeof (pinfo) * r);

		if (!buf)
			return (MLIB_FAILURE);

		buf_line1 = (pinfo_line *) __mlib_malloc(sizeof (pinfo_line)
			* (r + 1));

		if (!buf_line1) {
			__mlib_free(buf);
			return (MLIB_FAILURE);
		}
		buf_line2 = (pinfo_line *) __mlib_malloc(sizeof (pinfo_line)
			* (r + 1));
		if (!buf_line2) {
			__mlib_free(buf);
			__mlib_free(buf_line1);
			return (MLIB_FAILURE);
		}
	} else {
		buf = buf0;
		buf_line1 = buf0_line1;
		buf_line2 = buf0_line2;
	}


	k = (0x100000 / r);

	FILL_BUF;

	GET_BORDERS;

	if (t1 == t2) {
		FREE_MEM;
		return (__mlib_GraphicsDrawLine_AB_32(buffer, x, y,
		    x + cs1, y - sn1, c, a));
	}

	FILL_FLAGS;

	FILL_CL_FLAGS;

	SET_STEPSIGN;

	ARC_FILL_LINEBUF(1);
	ARC_FILL_LINEBUF(2);

	start = 0;
	end = count;
	PROC_OCT(y, y - height, x - width, x, 2, cos, 1, 2, stride, -1);
	start = 1;
	end = count;
	PROC_OCT(y, y - height, -x, width - x, 1, cos, 2, 1, stride, 1);
	start = 0;
	end = count;
	PROC_OCT(height - y, -y, x - width, x, 5, cos, 2, 1, -stride, -1);
	start = 1;
	end = count;
	PROC_OCT(height - y, -y, -x, width - x, 6, cos, 1, 2, -stride, 1);

	start = 1;
	end = scount;
	PROC_OCT(x, x - width, y - height, y, 3, sin, 2, 1, 1, -stride);
	start = 0;
	end = scount;
	PROC_OCT(x, x - width, -y, height - y, 4, sin, 1, 2, 1, stride);
	start = 1;
	end = scount;
	PROC_OCT(width - x, -x, y - height, y, 0, sin, 1, 2, -1, -stride);
	start = 0;
	end = scount;
	PROC_OCT(width - x, -x, -y, height - y, 7, sin, 2, 1, -1, stride);

	rez = __mlib_GraphicsFillArc_B_32(buffer, x, y, r - 1, tt1, tt2, c, a);
	if (rez != MLIB_SUCCESS) {
		FREE_MEM;
		return (rez);
	}

	DRAW_LINE_AB(1, 2);
	DRAW_LINE_AB(2, 1);

	FREE_MEM;

	return (MLIB_SUCCESS);
}