56 #include <config_auto.h>
61 #include "allheaders.h"
64 static const l_float32 MinDiffFromHalfPi = 0.04;
66 static l_float32 normalizeAngleForShear(l_float32 radang, l_float32 mindif);
124 l_int32 y, yincr, inityincr, hshift;
125 l_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)) {
137 pixHShear(pixd, pix1, yloc, radang, incolor);
146 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
152 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
153 if (radang == 0.0 || tan(radang) == 0.0)
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;
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);
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);
187 y - yincr, hshift, yincr);
243 l_int32 x, xincr, initxincr, vshift;
244 l_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)) {
256 pixVShear(pixd, pix1, xloc, radang, incolor);
265 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
271 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
272 if (radang == 0.0 || tan(radang) == 0.0)
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;
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);
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);
306 x - xincr, vshift, xincr);
342 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
344 return pixHShear(pixd, pixs, 0, radang, incolor);
371 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
373 return pixVShear(pixd, pixs, 0, radang, incolor);
400 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
402 return pixHShear(pixd, pixs, pixGetHeight(pixs) / 2, radang, incolor);
429 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
431 return pixVShear(pixd, pixs, pixGetWidth(pixs) / 2, radang, incolor);
465 l_int32 y, yincr, inityincr, hshift;
466 l_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);
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;
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;
538 l_int32 x, xincr, initxincr, vshift;
539 l_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);
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;
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;
618 l_int32 i, jd, x, xp, xf, w, h, d, wm, wpls, wpld, val, rval, gval, bval;
619 l_uint32 word0, word1;
620 l_uint32 *datas, *datad, *lines, *lined;
621 l_float32 tanangle, xshift;
625 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
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))
640 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
641 if (radang == 0.0 || tan(radang) == 0.0) {
651 d = pixGetDepth(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;
687 lined[jd] = lines[xp];
728 l_int32 id, y, yp, yf, j, w, h, d, hm, wpls, wpld, val, rval, gval, bval;
729 l_uint32 word0, word1;
730 l_uint32 *datas, *datad, *lines, *lined;
731 l_float32 tanangle, yshift;
735 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
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))
750 radang = normalizeAngleForShear(radang, MinDiffFromHalfPi);
751 if (radang == 0.0 || tan(radang) == 0.0) {
761 d = pixGetDepth(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;
812 normalizeAngleForShear(l_float32 radang,
818 pi2 = 3.14159265 / 2.0;
819 if (radang < -pi2 || radang > pi2)
820 radang = radang - (l_int32)(radang / pi2) * pi2;
823 if (radang > pi2 - mindif) {
824 L_WARNING(
"angle close to pi/2; shifting away\n", __func__);
825 radang = pi2 - mindif;
826 }
else if (radang < -pi2 + mindif) {
827 L_WARNING(
"angle close to -pi/2; shifting away\n", __func__);
828 radang = -pi2 + mindif;
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixResizeImageData(PIX *pixd, const PIX *pixs)
pixResizeImageData()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
@ REMOVE_CMAP_BASED_ON_SRC
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_ok pixRasteropHip(PIX *pixd, l_int32 by, l_int32 bh, l_int32 hshift, l_int32 incolor)
pixRasteropHip()
l_ok pixRasteropVip(PIX *pixd, l_int32 bx, l_int32 bw, l_int32 vshift, l_int32 incolor)
pixRasteropVip()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
PIX * pixHShearCenter(PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
pixHShearCenter()
PIX * pixVShear(PIX *pixd, PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
pixVShear()
l_ok pixHShearIP(PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
pixHShearIP()
PIX * pixVShearCenter(PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
pixVShearCenter()
PIX * pixHShearLI(PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
pixHShearLI()
PIX * pixVShearCorner(PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
pixVShearCorner()
PIX * pixHShearCorner(PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
pixHShearCorner()
l_ok pixVShearIP(PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
pixVShearIP()
PIX * pixVShearLI(PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
pixVShearLI()
PIX * pixHShear(PIX *pixd, PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
pixHShear()
void lept_stderr(const char *fmt,...)
lept_stderr()