112#include <config_auto.h>
117#include "allheaders.h"
119extern l_float32 AlphaMaskBorderVals[2];
153 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
155 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
157 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
159 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
160 if (ptaGetCount(ptas) != 4)
161 return (
PIX *)ERROR_PTR(
"ptas count not 4", __func__, NULL);
162 if (ptaGetCount(ptad) != 4)
163 return (
PIX *)ERROR_PTR(
"ptad count not 4", __func__, NULL);
196l_int32 i, j, w, h, d, x, y, wpls, wpld, color, cmapindex;
198l_uint32 *datas, *datad, *lines, *lined;
203 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
205 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
207 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
208 pixGetDimensions(pixs, &w, &h, &d);
209 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
210 return (
PIX *)ERROR_PTR(
"depth not 1, 2, 4, 8 or 16", __func__, NULL);
213 pixd = pixCreateTemplate(pixs);
214 if ((cmap = pixGetColormap(pixs)) != NULL) {
219 pixcmapAddBlackOrWhite(cmap, color, &cmapindex);
220 pixSetAllArbitrary(pixd, cmapindex);
231 datas = pixGetData(pixs);
232 wpls = pixGetWpl(pixs);
233 datad = pixGetData(pixd);
234 wpld = pixGetWpl(pixd);
235 for (i = 0; i < h; i++) {
236 lined = datad + i * wpld;
237 for (j = 0; j < w; j++) {
239 if (x < 0 || y < 0 || x >=w || y >= h)
241 lines = datas + y * wpls;
248 }
else if (d == 32) {
290PIX *pixt1, *pixt2, *pixd;
293 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
295 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
297 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
299 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
300 if (ptaGetCount(ptas) != 4)
301 return (
PIX *)ERROR_PTR(
"ptas count not 4", __func__, NULL);
302 if (ptaGetCount(ptad) != 4)
303 return (
PIX *)ERROR_PTR(
"ptad count not 4", __func__, NULL);
305 if (pixGetDepth(pixs) == 1)
310 d = pixGetDepth(pixt1);
312 pixt2 = pixConvertTo8(pixt1, FALSE);
314 pixt2 = pixClone(pixt1);
315 d = pixGetDepth(pixt2);
323 colorval = 0xffffff00;
357PIX *pixt1, *pixt2, *pixd;
360 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
362 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
364 if (pixGetDepth(pixs) == 1)
369 d = pixGetDepth(pixt1);
371 pixt2 = pixConvertTo8(pixt1, FALSE);
373 pixt2 = pixClone(pixt1);
374 d = pixGetDepth(pixt2);
382 colorval = 0xffffff00;
414 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
416 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
418 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
419 if (pixGetDepth(pixs) != 32)
420 return (
PIX *)ERROR_PTR(
"pixs must be 32 bpp", __func__, NULL);
421 if (ptaGetCount(ptas) != 4)
422 return (
PIX *)ERROR_PTR(
"ptas count not 4", __func__, NULL);
423 if (ptaGetCount(ptad) != 4)
424 return (
PIX *)ERROR_PTR(
"ptad count not 4", __func__, NULL);
448l_int32 i, j, w, h, d, wpls, wpld;
450l_uint32 *datas, *datad, *lined;
452PIX *pix1, *pix2, *pixd;
455 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
456 pixGetDimensions(pixs, &w, &h, &d);
458 return (
PIX *)ERROR_PTR(
"pixs must be 32 bpp", __func__, NULL);
460 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
462 datas = pixGetData(pixs);
463 wpls = pixGetWpl(pixs);
464 pixd = pixCreateTemplate(pixs);
465 pixSetAllArbitrary(pixd, colorval);
466 datad = pixGetData(pixd);
467 wpld = pixGetWpl(pixd);
470 for (i = 0; i < h; i++) {
471 lined = datad + i * wpld;
472 for (j = 0; j < w; j++) {
482 if (pixGetSpp(pixs) == 4) {
513 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
515 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
517 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
518 if (pixGetDepth(pixs) != 8)
519 return (
PIX *)ERROR_PTR(
"pixs must be 8 bpp", __func__, NULL);
520 if (ptaGetCount(ptas) != 4)
521 return (
PIX *)ERROR_PTR(
"ptas count not 4", __func__, NULL);
522 if (ptaGetCount(ptad) != 4)
523 return (
PIX *)ERROR_PTR(
"ptad count not 4", __func__, NULL);
548l_int32 i, j, w, h, wpls, wpld, val;
549l_uint32 *datas, *datad, *lined;
554 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
555 pixGetDimensions(pixs, &w, &h, NULL);
556 if (pixGetDepth(pixs) != 8)
557 return (
PIX *)ERROR_PTR(
"pixs must be 8 bpp", __func__, NULL);
559 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
561 datas = pixGetData(pixs);
562 wpls = pixGetWpl(pixs);
563 pixd = pixCreateTemplate(pixs);
564 pixSetAllArbitrary(pixd, grayval);
565 datad = pixGetData(pixd);
566 wpld = pixGetWpl(pixd);
569 for (i = 0; i < h; i++) {
570 lined = datad + i * wpld;
571 for (j = 0; j < w; j++) {
639PIX *pixd, *pixb1, *pixb2, *pixg2, *pixga;
643 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
644 pixGetDimensions(pixs, &ws, &hs, &d);
645 if (d != 32 && pixGetColormap(pixs) == NULL)
646 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
647 if (pixg && pixGetDepth(pixg) != 8) {
648 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
652 if (!pixg && (fract < 0.0 || fract > 1.0)) {
653 L_WARNING(
"invalid fract; using 1.0 (fully transparent)\n", __func__);
656 if (!pixg && fract == 0.0)
657 L_WARNING(
"fully opaque alpha; image will not be blended\n", __func__);
659 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
661 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
664 pixb1 = pixAddBorder(pixs, border, 0);
667 ptad2 = ptaTransform(ptad, border, border, 1.0, 1.0);
668 ptas2 = ptaTransform(ptas, border, border, 1.0, 1.0);
674 pixg2 = pixCreate(ws, hs, 8);
678 pixSetAllArbitrary(pixg2, (l_int32)(255.0 * fract));
680 pixg2 = pixResizeToMatch(pixg, NULL, ws, hs);
682 if (ws > 10 && hs > 10) {
683 pixSetBorderRingVal(pixg2, 1,
684 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
685 pixSetBorderRingVal(pixg2, 2,
686 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
689 pixb2 = pixAddBorder(pixg2, border, 0);
765l_float32 x1, y1, x2, y2, x3, y3, x4, y4;
770 return ERROR_INT(
"ptas not defined", __func__, 1);
772 return ERROR_INT(
"ptad not defined", __func__, 1);
774 return ERROR_INT(
"&vc not defined", __func__, 1);
776 b = (l_float32 *)LEPT_CALLOC(8,
sizeof(l_float32));
778 ptaGetPt(ptas, 0, &x1, &y1);
779 ptaGetPt(ptas, 1, &x2, &y2);
780 ptaGetPt(ptas, 2, &x3, &y3);
781 ptaGetPt(ptas, 3, &x4, &y4);
782 ptaGetPt(ptad, 0, &b[0], &b[1]);
783 ptaGetPt(ptad, 1, &b[2], &b[3]);
784 ptaGetPt(ptad, 2, &b[4], &b[5]);
785 ptaGetPt(ptad, 3, &b[6], &b[7]);
787 for (i = 0; i < 8; i++)
788 a[i] = (l_float32 *)LEPT_CALLOC(8,
sizeof(l_float32));
792 a[0][6] = -x1 * b[0];
793 a[0][7] = -y1 * b[0];
797 a[1][6] = -x1 * b[1];
798 a[1][7] = -y1 * b[1];
802 a[2][6] = -x2 * b[2];
803 a[2][7] = -y2 * b[2];
807 a[3][6] = -x2 * b[3];
808 a[3][7] = -y2 * b[3];
812 a[4][6] = -x3 * b[4];
813 a[4][7] = -y3 * b[4];
817 a[5][6] = -x3 * b[5];
818 a[5][7] = -y3 * b[5];
822 a[6][6] = -x4 * b[6];
823 a[6][7] = -y4 * b[6];
827 a[7][6] = -x4 * b[7];
828 a[7][7] = -y4 * b[7];
832 for (i = 0; i < 8; i++)
864 return ERROR_INT(
"vc not defined", __func__, 1);
866 if ((denom = vc[6] * x + vc[7] * y + 1.0f) == 0.0f)
867 return ERROR_INT(
"denom = 0.0", __func__, 1);
868 factor = 1.0f / denom;
869 *pxp = (l_int32)(factor * (vc[0] * x + vc[1] * y + vc[2]) + 0.5f);
870 *pyp = (l_int32)(factor * (vc[3] * x + vc[4] * y + vc[5]) + 0.5f);
900 return ERROR_INT(
"vc not defined", __func__, 1);
902 if ((denom = vc[6] * x + vc[7] * y + 1.0f) == 0.0f)
903 return ERROR_INT(
"denom = 0.0", __func__, 1);
904 factor = 1.0f / denom;
905 *pxp = factor * (vc[0] * x + vc[1] * y + vc[2]);
906 *pyp = factor * (vc[3] * x + vc[4] * y + vc[5]);
l_ok linearInterpolatePixelColor(l_uint32 *datas, l_int32 wpls, l_int32 w, l_int32 h, l_float32 x, l_float32 y, l_uint32 colorval, l_uint32 *pval)
linearInterpolatePixelColor()
l_int32 gaussjordan(l_float32 **a, l_float32 *b, l_int32 n)
gaussjordan()
l_ok linearInterpolatePixelGray(l_uint32 *datas, l_int32 wpls, l_int32 w, l_int32 h, l_float32 x, l_float32 y, l_int32 grayval, l_int32 *pval)
linearInterpolatePixelGray()
#define GET_DATA_QBIT(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val)
#define SET_DATA_BIT_VAL(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
@ REMOVE_CMAP_BASED_ON_SRC
PIX * pixProjectivePtaWithAlpha(PIX *pixs, PTA *ptad, PTA *ptas, PIX *pixg, l_float32 fract, l_int32 border)
pixProjectivePtaWithAlpha()
l_ok getProjectiveXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getProjectiveXformCoeffs()
PIX * pixProjectiveGray(PIX *pixs, l_float32 *vc, l_uint8 grayval)
pixProjectiveGray()
PIX * pixProjectivePta(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
pixProjectivePta()
PIX * pixProjectiveSampled(PIX *pixs, l_float32 *vc, l_int32 incolor)
pixProjectiveSampled()
l_ok projectiveXformSampledPt(l_float32 *vc, l_int32 x, l_int32 y, l_int32 *pxp, l_int32 *pyp)
projectiveXformSampledPt()
PIX * pixProjectivePtaGray(PIX *pixs, PTA *ptad, PTA *ptas, l_uint8 grayval)
pixProjectivePtaGray()
PIX * pixProjectivePtaColor(PIX *pixs, PTA *ptad, PTA *ptas, l_uint32 colorval)
pixProjectivePtaColor()
l_ok projectiveXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
projectiveXformPt()
PIX * pixProjectiveColor(PIX *pixs, l_float32 *vc, l_uint32 colorval)
pixProjectiveColor()
PIX * pixProjective(PIX *pixs, l_float32 *vc, l_int32 incolor)
pixProjective()
PIX * pixProjectiveSampledPta(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
pixProjectiveSampledPta()