56 #include <config_auto.h>
60 #include "allheaders.h"
62 extern l_float32 AlphaMaskBorderVals[2];
63 static const l_float32 MinAngleToRotate = 0.001;
64 static const l_float32 Max1BppShearAngle = 0.06;
65 static const l_float32 LimitShearAngle = 0.35;
110 PIX *pix1, *pix2, *pix3, *pixd;
113 PROCNAME(
"pixRotate");
116 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
119 return (
PIX *)ERROR_PTR(
"invalid type", procName, NULL);
121 return (
PIX *)ERROR_PTR(
"invalid incolor", procName, NULL);
123 if (L_ABS(angle) < MinAngleToRotate)
131 if (pixGetDepth(pixs) == 1) {
132 if (L_ABS(angle) > Max1BppShearAngle) {
134 L_INFO(
"1 bpp, large angle; rotate by sampling\n", procName);
137 L_INFO(
"1 bpp; rotate by shear\n", procName);
140 }
else if (L_ABS(angle) > LimitShearAngle && type ==
L_ROTATE_SHEAR) {
141 L_INFO(
"large angle; rotate by sampling\n", procName);
146 cmap = pixGetColormap(pixs);
151 cmap = pixGetColormap(pix1);
155 if (cmap && width == 0) {
167 d = pixGetDepth(pix2);
185 fillval = 0xffffff00;
249 l_int32 w, h, d, w1, h1, w2, h2, maxside, wnew, hnew, xoff, yoff, setcolor;
250 l_float64 sina, cosa, fw, fh;
253 PROCNAME(
"pixEmbedForRotation");
256 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
258 return (
PIX *)ERROR_PTR(
"invalid incolor", procName, NULL);
259 if (L_ABS(angle) < MinAngleToRotate)
264 maxside = (l_int32)(sqrt((l_float64)(width * width) +
265 (l_float64)(height * height)) + 0.5);
266 if (w >= maxside && h >= maxside)
276 w1 = (l_int32)(L_ABS(fw * cosa - fh * sina) + 0.5);
277 w2 = (l_int32)(L_ABS(-fw * cosa - fh * sina) + 0.5);
278 h1 = (l_int32)(L_ABS(fw * sina + fh * cosa) + 0.5);
279 h2 = (l_int32)(L_ABS(-fw * sina + fh * cosa) + 0.5);
280 wnew = L_MAX(w, L_MAX(w1, w2));
281 hnew = L_MAX(h, L_MAX(h1, h2));
283 if ((pixd =
pixCreate(wnew, hnew, d)) == NULL)
284 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
285 pixCopyResolution(pixd, pixs);
288 pixCopyText(pixd, pixs);
289 xoff = (wnew - w) / 2;
290 yoff = (hnew - h) / 2;
330 l_int32 w, h, d, i, j, x, y, xdif, ydif, wm1, hm1, wpld;
332 l_float32 sina, cosa;
333 l_uint32 *datad, *lined;
337 PROCNAME(
"pixRotateBySampling");
340 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
342 return (
PIX *)ERROR_PTR(
"invalid incolor", procName, NULL);
344 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
345 return (
PIX *)ERROR_PTR(
"invalid depth", procName, NULL);
347 if (L_ABS(angle) < MinAngleToRotate)
351 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
357 wpld = pixGetWpl(pixd);
364 for (i = 0; i < h; i++) {
365 lined = datad + i * wpld;
367 for (j = 0; j < w; j++) {
369 x = xcen + (l_int32)(-xdif * cosa - ydif * sina);
370 if (x < 0 || x > wm1)
continue;
371 y = ycen + (l_int32)(-ydif * cosa + xdif * sina);
372 if (y < 0 || y > hm1)
continue;
386 for (i = 0; i < h; i++) {
387 lined = datad + i * wpld;
389 for (j = 0; j < w; j++) {
391 x = xcen + (l_int32)(-xdif * cosa - ydif * sina);
392 if (x < 0 || x > wm1)
continue;
393 y = ycen + (l_int32)(-ydif * cosa + xdif * sina);
394 if (y < 0 || y > hm1)
continue;
418 return (
PIX *)ERROR_PTR(
"invalid depth", procName, NULL);
461 PIX *pix1, *pix2, *pix3, *pix4, *pixd;
463 PROCNAME(
"pixRotateBinaryNice");
465 if (!pixs || pixGetDepth(pixs) != 1)
466 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
468 return (
PIX *)ERROR_PTR(
"invalid incolor", procName, NULL);
540 l_int32 ws, hs, d, spp;
541 PIX *pixd, *pix32, *pixg2, *pixgr;
543 PROCNAME(
"pixRotateWithAlpha");
546 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
548 if (d != 32 && pixGetColormap(pixs) == NULL)
549 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", procName, NULL);
550 if (pixg && pixGetDepth(pixg) != 8) {
551 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
555 if (!pixg && (fract < 0.0 || fract > 1.0)) {
556 L_WARNING(
"invalid fract; using fully opaque\n", procName);
559 if (!pixg && fract == 0.0)
560 L_WARNING(
"transparent alpha; image will not be blended\n", procName);
567 spp = pixGetSpp(pix32);
570 pixSetSpp(pix32, spp);
578 else if (fract > 0.0)
583 if (ws > 10 && hs > 10) {
585 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
587 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define SET_DATA_FOUR_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_FOUR_BYTES(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define CLEAR_DATA_BIT(pdata, n)
#define GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
l_ok pixcmapAddBlackOrWhite(PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
pixcmapAddBlackOrWhite()
PIX * pixBlockconv(PIX *pix, l_int32 wc, l_int32 hc)
pixBlockconv()
PIX * pixUnsharpMasking(PIX *pixs, l_int32 halfwidth, l_float32 fract)
pixUnsharpMasking()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
l_ok pixCopySpp(PIX *pixd, const PIX *pixs)
pixCopySpp()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
l_ok pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
l_ok pixSetAll(PIX *pix)
pixSetAll()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
@ REMOVE_CMAP_BASED_ON_SRC
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
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 * pixRotateBySampling(PIX *pixs, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 incolor)
pixRotateBySampling()
PIX * pixRotate(PIX *pixs, l_float32 angle, l_int32 type, l_int32 incolor, l_int32 width, l_int32 height)
pixRotate()
PIX * pixRotateBinaryNice(PIX *pixs, l_float32 angle, l_int32 incolor)
pixRotateBinaryNice()
PIX * pixRotateWithAlpha(PIX *pixs, l_float32 angle, PIX *pixg, l_float32 fract)
pixRotateWithAlpha()
PIX * pixEmbedForRotation(PIX *pixs, l_float32 angle, l_int32 incolor, l_int32 width, l_int32 height)
pixEmbedForRotation()
PIX * pixRotateAM(PIX *pixs, l_float32 angle, l_int32 incolor)
pixRotateAM()
PIX * pixRotateAMColor(PIX *pixs, l_float32 angle, l_uint32 colorval)
pixRotateAMColor()
PIX * pixRotateAMGray(PIX *pixs, l_float32 angle, l_uint8 grayval)
pixRotateAMGray()
PIX * pixRotateShearCenter(PIX *pixs, l_float32 angle, l_int32 incolor)
pixRotateShearCenter()