124l_int32 y, yincr, inityincr, hshift;
125l_float32 tanangle, invangle;
128 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
130 return (
PIX *)ERROR_PTR(
"invalid incolor value", __func__, pixd);
133 if (!pixGetColormap(pixs)) {
136 PIX *pix1 = pixCopy(NULL, pixs);
137 pixHShear(pixd, pix1, yloc, radang, incolor);
145 if ((pixd = pixCreateTemplate(pixs)) == NULL)
146 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
148 pixResizeImageData(pixd, pixs);
152 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
153 if (radang == 0.0 || tan(radang) == 0.0)
154 return pixCopy(pixd, pixs);
157 pixSetBlackOrWhite(pixd, incolor);
159 pixGetDimensions(pixs, &w, &h, NULL);
160 sign = L_SIGN(radang);
161 tanangle = tan(radang);
162 invangle = L_ABS(1. / tanangle);
163 inityincr = (l_int32)(invangle / 2.);
164 yincr = (l_int32)invangle;
165 pixRasterop(pixd, 0, yloc - inityincr, w, 2 * inityincr,
PIX_SRC,
166 pixs, 0, yloc - inityincr);
168 for (hshift = 1, y = yloc + inityincr; y < h; hshift++) {
169 yincr = (l_int32)(invangle * (hshift + 0.5) + 0.5) - (y - yloc);
172 pixRasterop(pixd, -sign*hshift, y, w, yincr,
PIX_SRC, pixs, 0, y);
174 lept_stderr(
"y = %d, hshift = %d, yincr = %d\n", y, hshift, yincr);
179 for (hshift = -1, y = yloc - inityincr; y > 0; hshift--) {
180 yincr = (y - yloc) - (l_int32)(invangle * (hshift - 0.5) + 0.5);
183 pixRasterop(pixd, -sign*hshift, y - yincr, w, yincr,
PIX_SRC,
186 lept_stderr(
"y = %d, hshift = %d, yincr = %d\n",
187 y - yincr, hshift, yincr);
243l_int32 x, xincr, initxincr, vshift;
244l_float32 tanangle, invangle;
247 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
249 return (
PIX *)ERROR_PTR(
"invalid incolor value", __func__, NULL);
252 if (!pixGetColormap(pixs)) {
255 PIX *pix1 = pixCopy(NULL, pixs);
256 pixVShear(pixd, pix1, xloc, radang, incolor);
264 if ((pixd = pixCreateTemplate(pixs)) == NULL)
265 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
267 pixResizeImageData(pixd, pixs);
271 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
272 if (radang == 0.0 || tan(radang) == 0.0)
273 return pixCopy(pixd, pixs);
276 pixSetBlackOrWhite(pixd, incolor);
278 pixGetDimensions(pixs, &w, &h, NULL);
279 sign = L_SIGN(radang);
280 tanangle = tan(radang);
281 invangle = L_ABS(1. / tanangle);
282 initxincr = (l_int32)(invangle / 2.);
283 xincr = (l_int32)invangle;
284 pixRasterop(pixd, xloc - initxincr, 0, 2 * initxincr, h,
PIX_SRC,
285 pixs, xloc - initxincr, 0);
287 for (vshift = 1, x = xloc + initxincr; x < w; vshift++) {
288 xincr = (l_int32)(invangle * (vshift + 0.5) + 0.5) - (x - xloc);
291 pixRasterop(pixd, x, sign*vshift, xincr, h,
PIX_SRC, pixs, x, 0);
293 lept_stderr(
"x = %d, vshift = %d, xincr = %d\n", x, vshift, xincr);
298 for (vshift = -1, x = xloc - initxincr; x > 0; vshift--) {
299 xincr = (x - xloc) - (l_int32)(invangle * (vshift - 0.5) + 0.5);
302 pixRasterop(pixd, x - xincr, sign*vshift, xincr, h,
PIX_SRC,
305 lept_stderr(
"x = %d, vshift = %d, xincr = %d\n",
306 x - xincr, vshift, xincr);
465l_int32 y, yincr, inityincr, hshift;
466l_float32 tanangle, invangle;
469 return ERROR_INT(
"pixs not defined", __func__, 1);
471 return ERROR_INT(
"invalid incolor value", __func__, 1);
472 if (pixGetColormap(pixs))
473 return ERROR_INT(
"pixs is colormapped", __func__, 1);
476 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
477 if (radang == 0.0 || tan(radang) == 0.0)
480 sign = L_SIGN(radang);
481 pixGetDimensions(pixs, &w, &h, NULL);
482 tanangle = tan(radang);
483 invangle = L_ABS(1. / tanangle);
484 inityincr = (l_int32)(invangle / 2.);
485 yincr = (l_int32)invangle;
488 pixRasteropHip(pixs, yloc - inityincr, 2 * inityincr, 0, incolor);
490 for (hshift = 1, y = yloc + inityincr; y < h; hshift++) {
491 yincr = (l_int32)(invangle * (hshift + 0.5) + 0.5) - (y - yloc);
492 if (yincr == 0)
continue;
495 pixRasteropHip(pixs, y, yincr, -sign*hshift, incolor);
499 for (hshift = -1, y = yloc - inityincr; y > 0; hshift--) {
500 yincr = (y - yloc) - (l_int32)(invangle * (hshift - 0.5) + 0.5);
501 if (yincr == 0)
continue;
504 pixRasteropHip(pixs, y - yincr, yincr, -sign*hshift, incolor);
538l_int32 x, xincr, initxincr, vshift;
539l_float32 tanangle, invangle;
542 return ERROR_INT(
"pixs not defined", __func__, 1);
544 return ERROR_INT(
"invalid incolor value", __func__, 1);
545 if (pixGetColormap(pixs))
546 return ERROR_INT(
"pixs is colormapped", __func__, 1);
549 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
550 if (radang == 0.0 || tan(radang) == 0.0)
553 sign = L_SIGN(radang);
554 pixGetDimensions(pixs, &w, &h, NULL);
555 tanangle = tan(radang);
556 invangle = L_ABS(1. / tanangle);
557 initxincr = (l_int32)(invangle / 2.);
558 xincr = (l_int32)invangle;
561 pixRasteropVip(pixs, xloc - initxincr, 2 * initxincr, 0, incolor);
563 for (vshift = 1, x = xloc + initxincr; x < w; vshift++) {
564 xincr = (l_int32)(invangle * (vshift + 0.5) + 0.5) - (x - xloc);
565 if (xincr == 0)
continue;
568 pixRasteropVip(pixs, x, xincr, sign*vshift, incolor);
572 for (vshift = -1, x = xloc - initxincr; x > 0; vshift--) {
573 xincr = (x - xloc) - (l_int32)(invangle * (vshift - 0.5) + 0.5);
574 if (xincr == 0)
continue;
577 pixRasteropVip(pixs, x - xincr, xincr, sign*vshift, incolor);
618l_int32 i, jd, x, xp, xf, w, h, d, wm, wpls, wpld, val, rval, gval, bval;
619l_uint32 word0, word1;
620l_uint32 *datas, *datad, *lines, *lined;
621l_float32 tanangle, xshift;
625 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
626 pixGetDimensions(pixs, &w, &h, &d);
627 if (d != 8 && d != 32 && !pixGetColormap(pixs))
628 return (
PIX *)ERROR_PTR(
"pixs not 8, 32 bpp, or cmap", __func__, NULL);
630 return (
PIX *)ERROR_PTR(
"invalid incolor value", __func__, NULL);
631 if (yloc < 0 || yloc >= h)
632 return (
PIX *)ERROR_PTR(
"yloc not in [0 ... h-1]", __func__, NULL);
634 if (pixGetColormap(pixs))
637 pix = pixClone(pixs);
640 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
641 if (radang == 0.0 || tan(radang) == 0.0) {
643 return pixCopy(NULL, pixs);
647 pixd = pixCreateTemplate(pix);
648 pixSetBlackOrWhite(pixd, incolor);
651 d = pixGetDepth(pixd);
652 datas = pixGetData(pix);
653 datad = pixGetData(pixd);
654 wpls = pixGetWpl(pix);
655 wpld = pixGetWpl(pixd);
656 tanangle = tan(radang);
657 for (i = 0; i < h; i++) {
658 lines = datas + i * wpls;
659 lined = datad + i * wpld;
660 xshift = (yloc - i) * tanangle;
661 for (jd = 0; jd < w; jd++) {
662 x = (l_int32)(64.0 * (-xshift + jd) + 0.5);
666 if (xp < 0 || xp > wm)
continue;
677 word0 = *(lines + xp);
678 word1 = *(lines + xp + 1);
679 rval = ((63 - xf) * ((word0 >> L_RED_SHIFT) & 0xff) +
680 xf * ((word1 >> L_RED_SHIFT) & 0xff) + 31) / 63;
681 gval = ((63 - xf) * ((word0 >> L_GREEN_SHIFT) & 0xff) +
682 xf * ((word1 >> L_GREEN_SHIFT) & 0xff) + 31) / 63;
683 bval = ((63 - xf) * ((word0 >> L_BLUE_SHIFT) & 0xff) +
684 xf * ((word1 >> L_BLUE_SHIFT) & 0xff) + 31) / 63;
685 composeRGBPixel(rval, gval, bval, lined + jd);
687 lined[jd] = lines[xp];
728l_int32 id, y, yp, yf, j, w, h, d, hm, wpls, wpld, val, rval, gval, bval;
729l_uint32 word0, word1;
730l_uint32 *datas, *datad, *lines, *lined;
731l_float32 tanangle, yshift;
735 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
736 pixGetDimensions(pixs, &w, &h, &d);
737 if (d != 8 && d != 32 && !pixGetColormap(pixs))
738 return (
PIX *)ERROR_PTR(
"pixs not 8, 32 bpp, or cmap", __func__, NULL);
740 return (
PIX *)ERROR_PTR(
"invalid incolor value", __func__, NULL);
741 if (xloc < 0 || xloc >= w)
742 return (
PIX *)ERROR_PTR(
"xloc not in [0 ... w-1]", __func__, NULL);
744 if (pixGetColormap(pixs))
747 pix = pixClone(pixs);
750 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
751 if (radang == 0.0 || tan(radang) == 0.0) {
753 return pixCopy(NULL, pixs);
757 pixd = pixCreateTemplate(pix);
758 pixSetBlackOrWhite(pixd, incolor);
761 d = pixGetDepth(pixd);
762 datas = pixGetData(pix);
763 datad = pixGetData(pixd);
764 wpls = pixGetWpl(pix);
765 wpld = pixGetWpl(pixd);
766 tanangle = tan(radang);
767 for (j = 0; j < w; j++) {
768 yshift = (j - xloc) * tanangle;
769 for (
id = 0;
id < h;
id++) {
770 y = (l_int32)(64.0 * (-yshift +
id) + 0.5);
774 if (yp < 0 || yp > hm)
continue;
775 lines = datas + yp * wpls;
776 lined = datad +
id * wpld;
787 word0 = *(lines + j);
788 word1 = *(lines + wpls + j);
789 rval = ((63 - yf) * ((word0 >> L_RED_SHIFT) & 0xff) +
790 yf * ((word1 >> L_RED_SHIFT) & 0xff) + 31) / 63;
791 gval = ((63 - yf) * ((word0 >> L_GREEN_SHIFT) & 0xff) +
792 yf * ((word1 >> L_GREEN_SHIFT) & 0xff) + 31) / 63;
793 bval = ((63 - yf) * ((word0 >> L_BLUE_SHIFT) & 0xff) +
794 yf * ((word1 >> L_BLUE_SHIFT) & 0xff) + 31) / 63;
795 composeRGBPixel(rval, gval, bval, lined + j);