Ejemplo n.º 1
0
mlib_status mlib_ImageClippingMxN(mlib_image       *dst_i,
                                  mlib_image       *src_i,
                                  mlib_image       *dst_e,
                                  mlib_image       *src_e,
                                  mlib_s32         *edg_sizes,
                                  const mlib_image *dst,
                                  const mlib_image *src,
                                  mlib_s32         kw,
                                  mlib_s32         kh,
                                  mlib_s32         kw1,
                                  mlib_s32         kh1)
{
  mlib_s32  kw2 = kw - 1 - kw1;
  mlib_s32  kh2 = kh - 1 - kh1;
  mlib_s32  src_wid, src_hgt, dst_wid, dst_hgt;
  mlib_s32  dx, dy, dxd, dxs, dyd, dys, wid_e, hgt_e;
  mlib_s32  dx_l, dx_r, dy_t, dy_b, wid_i, hgt_i;

  MLIB_IMAGE_CHECK(dst);
  MLIB_IMAGE_CHECK(src);
  MLIB_IMAGE_TYPE_EQUAL(dst, src);
  MLIB_IMAGE_CHAN_EQUAL(dst, src);

  dst_wid = mlib_ImageGetWidth(dst);
  dst_hgt = mlib_ImageGetHeight(dst);
  src_wid = mlib_ImageGetWidth(src);
  src_hgt = mlib_ImageGetHeight(src);

  /* X clipping */
  dx = src_wid - dst_wid;

  if (dx > 0) {
    dxs = (dx + 1) >> 1;
    dxd = 0;
  } else {
Ejemplo n.º 2
0
mlib_status
__mlib_ImageRotateIndex(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 angle,
    mlib_d64 xcenter,
    mlib_d64 ycenter,
    mlib_filter filter,
    mlib_edge edge,
    const void *colormap)
{
	mlib_d64 mtx[6];
	mlib_d64 cos1, sin1;

	cos1 = mlib_cos(-angle);
	sin1 = mlib_sin(-angle);
	mtx[0] = cos1;
	mtx[1] = sin1;
	mtx[2] =
	    0.5 * (mlib_ImageGetWidth(dst) - OFFSET) - xcenter * cos1 -
	    ycenter * sin1;
	mtx[3] = -sin1;
	mtx[4] = cos1;
	mtx[5] =
	    0.5 * (mlib_ImageGetHeight(dst) - OFFSET) + xcenter * sin1 -
	    ycenter * cos1;
	return (__mlib_ImageAffineIndex(dst, src, mtx, filter, edge, colormap));
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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 {
Ejemplo n.º 5
0
mlib_status
__mlib_ImageCopy(
    mlib_image *dst,
    const mlib_image *src)
{
	mlib_s32 s_offset, d_offset, width, height;
	mlib_s32 size, s_stride, d_stride;
	mlib_u8 *sa, *da;
	mlib_s32 j;

	MLIB_IMAGE_CHECK(src);
	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_TYPE_EQUAL(src, dst);
	MLIB_IMAGE_CHAN_EQUAL(src, dst);
	MLIB_IMAGE_SIZE_EQUAL(src, dst);

	switch (mlib_ImageGetType(dst)) {
	case MLIB_BIT:

		sa = (mlib_u8 *)mlib_ImageGetData(src);
		da = (mlib_u8 *)mlib_ImageGetData(dst);

		width = mlib_ImageGetWidth(src) * mlib_ImageGetChannels(src);
		height = mlib_ImageGetHeight(src);

		if (!mlib_ImageIsNotOneDvector(src) &&
		    !mlib_ImageIsNotOneDvector(dst)) {
			size = height * (width >> 3);
			mlib_ImageCopy_na(sa, da, size);
		} else {
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
mlib_status mlib_ImageCopy(mlib_image       *dst,
                           const mlib_image *src)
{
  mlib_s32 s_offset, d_offset;
  mlib_s32 size, s_stride, d_stride;
  mlib_s32 width;                                     /* width in bytes of src and dst */
  mlib_s32 height;                                    /* height in lines of src and dst */
  mlib_u8 *sa, *da;
  mlib_s32 j;

  MLIB_IMAGE_CHECK(src);
  MLIB_IMAGE_CHECK(dst);
  MLIB_IMAGE_TYPE_EQUAL(src, dst);
  MLIB_IMAGE_CHAN_EQUAL(src, dst);
  MLIB_IMAGE_SIZE_EQUAL(src, dst);

  switch (mlib_ImageGetType(dst)) {
    case MLIB_BIT:
      width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); /* size in bits */
      height = mlib_ImageGetHeight(src);
      sa = (mlib_u8 *) mlib_ImageGetData(src);
      da = (mlib_u8 *) mlib_ImageGetData(dst);

      if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst)) {
        size = height * (width >> 3);
        if (!mlib_ImageIsNotAligned8(src) && !mlib_ImageIsNotAligned8(dst) && ((size & 7) == 0)) {

          mlib_c_ImageCopy_a1((TYPE_64BIT *) sa, (TYPE_64BIT *) da, size >> 3);
        }
        else {
Ejemplo n.º 8
0
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));
	}
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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);
	}
}
Ejemplo n.º 11
0
mlib_status
__mlib_ImageZoomIndex(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 zoomx,
    mlib_d64 zoomy,
    mlib_filter filter,
    mlib_edge edge,
    const void *colormap)
{
	mlib_d64 tx, ty;

	MLIB_IMAGE_CHECK(src);
	MLIB_IMAGE_CHECK(dst);

	tx = (mlib_ImageGetWidth(dst) - zoomx * mlib_ImageGetWidth(src)) * 0.5;
	ty = (mlib_ImageGetHeight(dst) -
	    zoomy * mlib_ImageGetHeight(src)) * 0.5;

	return __mlib_ImageZoomTranslateIndex(dst, src, zoomx, zoomy, tx, ty,
	    filter, edge, colormap);
}
Ejemplo n.º 12
0
mlib_status
mlib_ImageConvCopyEdge_Fp(
    mlib_image *dst,
    const mlib_image *src,
    mlib_s32 dx_l,
    mlib_s32 dx_r,
    mlib_s32 dy_t,
    mlib_s32 dy_b,
    mlib_s32 cmask)
{
	mlib_s32 img_width = mlib_ImageGetWidth(dst);
	mlib_s32 img_height = mlib_ImageGetHeight(dst);
	mlib_s32 channel = mlib_ImageGetChannels(dst);

	if (dx_l + dx_r > img_width) {
		dx_l = img_width;
		dx_r = 0;
	}

	if (dy_t + dy_b > img_height) {
		dy_t = img_height;
		dy_b = 0;
	}

	if (channel == 1)
		cmask = 1;

	switch (mlib_ImageGetType(src)) {
#if defined(_NO_LONGLONG)
	case MLIB_FLOAT:
		EDGES(channel, mlib_f32, cmask)
		break;

	case MLIB_DOUBLE:
		EDGES(channel, mlib_d64, cmask)
		break;
#else
	case MLIB_FLOAT:
		EDGES(channel, mlib_s32, cmask)
		break;

	case MLIB_DOUBLE:
		EDGES(channel, mlib_s64, cmask)
		break;
#endif
	default:
		return (MLIB_FAILURE);
	}

	return (MLIB_SUCCESS);
}
Ejemplo n.º 13
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) {
Ejemplo n.º 14
0
mlib_status mlib_ImageConvCopyEdge(mlib_image       *dst,
                                   const mlib_image *src,
                                   mlib_s32         dx_l,
                                   mlib_s32         dx_r,
                                   mlib_s32         dy_t,
                                   mlib_s32         dy_b,
                                   mlib_s32         cmask)
{
    mlib_s32 img_width = mlib_ImageGetWidth(dst);
    mlib_s32 img_height = mlib_ImageGetHeight(dst);
    mlib_s32 channel = mlib_ImageGetChannels(dst);

    if (dx_l + dx_r > img_width) {
        dx_l = img_width;
        dx_r = 0;
    }

    if (dy_t + dy_b > img_height) {
        dy_t = img_height;
        dy_b = 0;
    }

    if (channel == 1)
        cmask = 1;

    switch (mlib_ImageGetType(src)) {
    case MLIB_BIT:
        return mlib_ImageConvCopyEdge_Bit(dst, src, dx_l, dx_r, dy_t, dy_b, cmask);
    case MLIB_BYTE:
        EDGES(channel, mlib_u8, cmask)
        break;
    case MLIB_SHORT:
    case MLIB_USHORT:
        EDGES(channel, mlib_u16, cmask)
        break;
    case MLIB_INT:
    case MLIB_FLOAT:
        EDGES(channel, mlib_u32, cmask)
        break;
    case MLIB_DOUBLE:
        EDGES(channel, mlib_d64, cmask)
        break;
    default:
        return MLIB_FAILURE;
    }

    return MLIB_SUCCESS;
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
mlib_status mlib_ImageConvClearEdge(mlib_image     *dst,
                                    mlib_s32       dx_l,
                                    mlib_s32       dx_r,
                                    mlib_s32       dy_t,
                                    mlib_s32       dy_b,
                                    const mlib_s32 *color,
                                    mlib_s32       cmask)
{
  mlib_s32 dst_width = mlib_ImageGetWidth(dst);
  mlib_s32 dst_height = mlib_ImageGetHeight(dst);
  mlib_s32 channel = mlib_ImageGetChannels(dst);

  if (dx_l + dx_r > dst_width) {
    dx_l = dst_width;
    dx_r = 0;
  }

  if (dy_t + dy_b > dst_height) {
    dy_t = dst_height;
    dy_b = 0;
  }

  if (channel == 1)
    cmask = 1;

  switch (mlib_ImageGetType(dst)) {
    case MLIB_BIT:
      return mlib_ImageConvClearEdge_Bit(dst, dx_l, dx_r, dy_t, dy_b, color, cmask);
    case MLIB_BYTE:
      EDGES(channel, mlib_u8, cmask)
        break;
    case MLIB_SHORT:
    case MLIB_USHORT:
      EDGES(channel, mlib_s16, cmask)
        break;
    case MLIB_INT:
      EDGES(channel, mlib_s32, cmask)
        break;
    default:
      return MLIB_FAILURE;
  }

  return MLIB_SUCCESS;
}
Ejemplo n.º 19
0
mlib_status
__mlib_ImageGridWarpTable(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_f32 *xWarpPos,
    const mlib_f32 *yWarpPos,
    mlib_d64 postShiftX,
    mlib_d64 postShiftY,
    mlib_s32 xStart,
    mlib_s32 xStep,
    mlib_s32 xNumCells,
    mlib_s32 yStart,
    mlib_s32 yStep,
    mlib_s32 yNumCells,
    const void *table,
    mlib_edge edge)
{
	mlib_type type = mlib_ImageGetType(dst);
	mlib_s32 dstWidth = mlib_ImageGetWidth(dst);
	mlib_s32 dstHeight = mlib_ImageGetHeight(dst);

	if (type != MLIB_BYTE && type != MLIB_SHORT && type != MLIB_USHORT &&
	    type != MLIB_INT)
		return (MLIB_FAILURE);

	if (xWarpPos == NULL || yWarpPos == NULL)
		return (MLIB_FAILURE);

	if (edge != MLIB_EDGE_DST_NO_WRITE && edge != MLIB_EDGE_SRC_PADDED)
		return (MLIB_FAILURE);

	if (xNumCells < 0 || yNumCells <= 0 || xStep <= 0 || yStep <= 0)
		return (MLIB_FAILURE);

	if (xStart >= dstWidth || ((xStart + xStep * xNumCells) <= 0) ||
	    yStart >= dstHeight || ((yStart + yStep * yNumCells) <= 0))
		return (MLIB_SUCCESS);

	return mlib_ImageGridWarpTable_alltypes(dst, src, xWarpPos, yWarpPos,
	    postShiftX, postShiftY,
	    xStart, xStep, xNumCells, yStart, yStep, yNumCells, table, edge);
}
Ejemplo n.º 20
0
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);
	}
}
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 {
Ejemplo n.º 22
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);
}
mlib_status mlib_ImageConvClearEdge_Fp(mlib_image     *img,
                                       mlib_s32       dx_l,
                                       mlib_s32       dx_r,
                                       mlib_s32       dy_t,
                                       mlib_s32       dy_b,
                                       const mlib_d64 *color,
                                       mlib_s32       cmask)
{
  mlib_s32 img_width  = mlib_ImageGetWidth(img);
  mlib_s32 img_height = mlib_ImageGetHeight(img);
  mlib_s32 channel    = mlib_ImageGetChannels(img);

  if (dx_l + dx_r > img_width) {
    dx_l = img_width;
    dx_r = 0;
  }

  if (dy_t + dy_b > img_height) {
    dy_t = img_height;
    dy_b = 0;
  }

  if (channel == 1) cmask = 1;

  switch (mlib_ImageGetType(img)) {
    case MLIB_FLOAT:
      EDGES(channel,mlib_f32, cmask);
      break;
    case MLIB_DOUBLE:
      EDGES(channel,mlib_d64, cmask);
      break;
    default:
      return MLIB_FAILURE;
  }

  return MLIB_SUCCESS;
}
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;
		}
	}
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
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);
}
Ejemplo n.º 27
0
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));
}
Ejemplo n.º 28
0
mlib_status
__mlib_ImageZoomTranslate(
    mlib_image *dst,
    const mlib_image *src,
    mlib_d64 zoomx,
    mlib_d64 zoomy,
    mlib_d64 tx,
    mlib_d64 ty,
    mlib_filter filter,
    mlib_edge edge)
{
	mlib_type type;
	mlib_s32 nchan, t_ind;
	mlib_status res;
#ifndef	_NO_LONGLONG
	const mlib_s16 *flt_table;
#else
	const mlib_f32 *flt_table;
#endif
	mlib_clipping nearest, current;
	mlib_work_image border, *param = &border;

	MLIB_IMAGE_CHECK(src);
	MLIB_IMAGE_CHECK(dst);
	MLIB_IMAGE_TYPE_EQUAL(src, dst);
	MLIB_IMAGE_CHAN_EQUAL(src, dst);

	if (zoomx <= 0 || zoomy <= 0)
		return (MLIB_OUTOFRANGE);

	if (mlib_ImageGetWidth(src) >= (1 << 15) ||
	    mlib_ImageGetHeight(src) >= (1 << 15)) {
		return (MLIB_FAILURE);
	}

	border.nearest = &nearest;
	border.current = &current;

	mlib_ImageZoomClipping(dst, src, zoomx, zoomy, tx, ty, filter, edge,
	    &border);

	type = mlib_ImageGetType(src);
	nchan = mlib_ImageGetChannels(src);

	switch (type) {
	case MLIB_BIT:
		if (nchan != 1 || filter != MLIB_NEAREST) {
			return (MLIB_FAILURE);
		}
		if (current.width > 0) {
			int s_bitoff = mlib_ImageGetBitOffset(src);
			int d_bitoff = mlib_ImageGetBitOffset(dst);

			return mlib_ImageZoom_BIT_1_Nearest(&border, s_bitoff,
			    d_bitoff);
		}
		return (MLIB_SUCCESS);

	case MLIB_BYTE:
		t_ind = 0;
		break;
	case MLIB_SHORT:
		t_ind = 1;
		break;
	case MLIB_USHORT:
		t_ind = 2;
		break;
	case MLIB_INT:
		t_ind = 3;
		break;
	default:
		return (MLIB_FAILURE);
	}

	if (current.width > 0) {
		switch (filter) {
		case MLIB_NEAREST:
			res = mlib_zoom_nn_funs[border.ind_fun_nn] (&border);
			break;

		case MLIB_BILINEAR:
			if (zoomy < mlib_zoom_bl_level[t_ind]) {
				res =
				    mlib_zoom_bl_lo[4 * t_ind + (nchan -
				    1)] (&border);
			} else {
				res =
				    mlib_zoom_bl_hi[4 * t_ind + (nchan -
				    1)] (&border);
			}
			break;

		case MLIB_BICUBIC:
		case MLIB_BICUBIC2:
			if (type == MLIB_INT) {
				res = mlib_zoom_bc_s32[nchan - 1] (&border);
				break;
			}

#ifndef	_NO_LONGLONG
			if (filter == MLIB_BICUBIC) {
				if (type == MLIB_BYTE) {
					flt_table = mlib_filters_u8_bc;
				} else {
					flt_table = mlib_filters_s16_bc;
				}
			} else {
				if (type == MLIB_BYTE) {
					flt_table = mlib_filters_u8_bc2;
				} else {
					flt_table = mlib_filters_s16_bc2;
				}
			}
#else
			if (filter == MLIB_BICUBIC) {
				if (type == MLIB_BYTE) {
					flt_table = mlib_filters_u8f_bc;
				} else {
					flt_table = mlib_filters_s16f_bc;
				}
			} else {
				if (type == MLIB_BYTE) {
					flt_table = mlib_filters_u8f_bc2;
				} else {
					flt_table = mlib_filters_s16f_bc2;
				}
			}
#endif

			if (zoomy < mlib_zoom_bc_level[t_ind]) {
				res =
				    mlib_zoom_bc_lo[4 * t_ind + (nchan -
				    1)] (&border, flt_table);
			} else {
				res =
				    mlib_zoom_bc_hi[4 * t_ind + (nchan -
				    1)] (&border, flt_table);
			}
			break;

		default:
			return (MLIB_FAILURE);
		}

		if (res != MLIB_SUCCESS)
			return (res);
	}

	if (filter == MLIB_NEAREST && edge != MLIB_EDGE_SRC_EXTEND_INDEF) {
		return (MLIB_SUCCESS);
	}

	MLIB_EDGE_RULES;

	return (MLIB_SUCCESS);
}
Ejemplo n.º 29
0
mlib_status
__mlib_ImageConv5x5Index(
    mlib_image *dst,
    const mlib_image *src,
    const mlib_s32 *kernel,
    mlib_s32 scale,
    mlib_edge edge,
    const void *colormap)
{
    mlib_status stat;
    mlib_type src_dtype, lut_type;
    mlib_s32 zero[4];
    mlib_s32 offset;

    if (dst == NULL || src == NULL || colormap == NULL || kernel == NULL)
        return (MLIB_FAILURE);

    MLIB_IMAGE_FULL_EQUAL(dst, src);
    MLIB_IMAGE_HAVE_CHAN(src, 1);

    src_dtype = mlib_ImageGetType(src);
    lut_type = mlib_ImageGetLutType(colormap);
    offset = (mlib_s32)mlib_ImageGetLutOffset(colormap);
    zero[0] = zero[1] = zero[2] = zero[3] = offset;

    if (mlib_ImageGetWidth(src) < 5 || mlib_ImageGetHeight(src) < 5)
        return (MLIB_FAILURE);

    if (((lut_type == MLIB_BYTE) && (scale < 16 || scale > 31)) ||
            ((lut_type == MLIB_SHORT) && (scale < 17 || scale > 32)))
        return (MLIB_FAILURE);

    switch (src_dtype) {
    case MLIB_BYTE:
        switch (lut_type) {
        case MLIB_BYTE:
            switch (edge) {
            case MLIB_EDGE_DST_FILL_ZERO:
                stat =
                    mlib_v_conv5x5Index_8_8nw(src, dst, kernel,
                                              scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvClearEdge(dst, 2, 2, 2, 2,
                                            zero, 1);
                break;
            case MLIB_EDGE_DST_COPY_SRC:
                stat =
                    mlib_v_conv5x5Index_8_8nw(src, dst, kernel,
                                              scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvCopyEdge(dst, src, 2, 2, 2, 2,
                                           1);
                break;
            case MLIB_EDGE_SRC_EXTEND:
                stat =
                    mlib_v_conv5x5Index_8_8ext(src, dst, kernel,
                                               scale, colormap);
                break;
            case MLIB_EDGE_DST_NO_WRITE:
            default:
                stat =
                    mlib_v_conv5x5Index_8_8nw(src, dst, kernel,
                                              scale, colormap);
                break;
            }

            break;
        case MLIB_SHORT:
            switch (edge) {
            case MLIB_EDGE_DST_FILL_ZERO:
                stat =
                    mlib_conv5x5Index_16_8nw(src, dst, kernel,
                                             scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvClearEdge(dst, 2, 2, 2, 2,
                                            zero, 1);
                break;
            case MLIB_EDGE_DST_COPY_SRC:
                stat =
                    mlib_conv5x5Index_16_8nw(src, dst, kernel,
                                             scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvCopyEdge(dst, src, 2, 2, 2, 2,
                                           1);
                break;
            case MLIB_EDGE_SRC_EXTEND:
                stat =
                    mlib_conv5x5Index_16_8ext(src, dst, kernel,
                                              scale, colormap);
                break;
            case MLIB_EDGE_DST_NO_WRITE:
            default:
                stat =
                    mlib_conv5x5Index_16_8nw(src, dst, kernel,
                                             scale, colormap);
                break;
            }

            break;
        }

        break;
    case MLIB_SHORT:	/* convert wid from pixels to bytes */
        switch (lut_type) {
        case MLIB_SHORT:
            switch (edge) {
            case MLIB_EDGE_DST_FILL_ZERO:
                stat =
                    mlib_conv5x5Index_16_16nw(src, dst, kernel,
                                              scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvClearEdge(dst, 2, 2, 2, 2,
                                            zero, 1);
                break;
            case MLIB_EDGE_DST_COPY_SRC:
                stat =
                    mlib_conv5x5Index_16_16nw(src, dst, kernel,
                                              scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvCopyEdge(dst, src, 2, 2, 2, 2,
                                           1);
                break;
            case MLIB_EDGE_SRC_EXTEND:
                stat =
                    mlib_conv5x5Index_16_16ext(src, dst, kernel,
                                               scale, colormap);
                break;
            case MLIB_EDGE_DST_NO_WRITE:
            default:
                stat =
                    mlib_conv5x5Index_16_16nw(src, dst, kernel,
                                              scale, colormap);
                break;
            }

            break;
        case MLIB_BYTE:
            switch (edge) {
            case MLIB_EDGE_DST_FILL_ZERO:
                stat =
                    mlib_v_conv5x5Index_8_16nw(src, dst, kernel,
                                               scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvClearEdge(dst, 2, 2, 2, 2,
                                            zero, 1);
                break;
            case MLIB_EDGE_DST_COPY_SRC:
                stat =
                    mlib_v_conv5x5Index_8_16nw(src, dst, kernel,
                                               scale, colormap);

                if (stat != MLIB_SUCCESS)
                    break;
                stat =
                    mlib_ImageConvCopyEdge(dst, src, 2, 2, 2, 2,
                                           1);
                break;
            case MLIB_EDGE_SRC_EXTEND:
                stat =
                    mlib_v_conv5x5Index_8_16ext(src, dst,
                                                kernel, scale, colormap);
                break;
            case MLIB_EDGE_DST_NO_WRITE:
            default:
                stat =
                    mlib_v_conv5x5Index_8_16nw(src, dst, kernel,
                                               scale, colormap);
                break;
            }

            break;
        }

        break;
    default:
        stat = MLIB_FAILURE;
        break;
    }

    return (stat);
}
Ejemplo n.º 30
0
mlib_status
mlib_ImagePolynomialWarp_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,
    mlib_filter filter,
    mlib_edge edge)
{
	mlib_d64 wx, wy, Xstart, Ystart, Xstop, Ystop;
	mlib_s32 srcWidth, srcHeight;

	srcWidth = mlib_ImageGetWidth(src);
	srcHeight = mlib_ImageGetHeight(src);

	if (filter == MLIB_BILINEAR && (srcWidth < 2 || srcHeight < 2))
		return (MLIB_SUCCESS);

	if ((filter == MLIB_BICUBIC || filter == MLIB_BICUBIC2) &&
	    (srcWidth < 4 || srcHeight < 4))
		return (MLIB_SUCCESS);

	wx = xCoeffs[0] * postScaleX - postShiftX;
	wx -= (filter != MLIB_NEAREST) ? 0.5 : 0.0;

	wy = yCoeffs[0] * postScaleY - postShiftY;
	wy -= (filter != MLIB_NEAREST) ? 0.5 : 0.0;

	Xstart =
	    (filter == MLIB_NEAREST) ? 0.0 : ((filter ==
	    MLIB_BILINEAR) ? 0.5 : 1.5);
	Ystart =
	    (filter == MLIB_NEAREST) ? 0.0 : ((filter ==
	    MLIB_BILINEAR) ? 0.5 : 1.5);
	Xstop = srcWidth - Xstart;
	Ystop = srcHeight - 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 ((srcWidth - paddings[2]) < Xstop)
			Xstop = srcWidth - paddings[2];

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

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

	switch (filter) {
	case MLIB_NEAREST:
		return (mlib_ImagePolynomialWarp_0_NN(dst, src, wx, wy));

	case MLIB_BILINEAR:
		return (mlib_ImagePolynomialWarp_0_BL(dst, src, wx, wy));

	case MLIB_BICUBIC:
		return (mlib_ImagePolynomialWarp_0_BC(dst, src, wx, wy));

	case MLIB_BICUBIC2:
		return (mlib_ImagePolynomialWarp_0_BC2(dst, src, wx, wy));

	default:
		return (MLIB_FAILURE);
	}
}