Leptonica  1.82.0
Image processing and image analysis suite
fpix2.c
Go to the documentation of this file.
1 /*====================================================================*
2  - Copyright (C) 2001 Leptonica. All rights reserved.
3  -
4  - Redistribution and use in source and binary forms, with or without
5  - modification, are permitted provided that the following conditions
6  - are met:
7  - 1. Redistributions of source code must retain the above copyright
8  - notice, this list of conditions and the following disclaimer.
9  - 2. Redistributions in binary form must reproduce the above
10  - copyright notice, this list of conditions and the following
11  - disclaimer in the documentation and/or other materials
12  - provided with the distribution.
13  -
14  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18  - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
104 #ifdef HAVE_CONFIG_H
105 #include <config_auto.h>
106 #endif /* HAVE_CONFIG_H */
107 
108 #include <string.h>
109 #include "allheaders.h"
110 
111 /*--------------------------------------------------------------------*
112  * FPix <--> Pix conversions *
113  *--------------------------------------------------------------------*/
129 FPIX *
131  l_int32 ncomps)
132 {
133 l_int32 w, h, d, i, j, val, wplt, wpld;
134 l_uint32 uval;
135 l_uint32 *datat, *linet;
136 l_float32 *datad, *lined;
137 PIX *pixt;
138 FPIX *fpixd;
139 
140  PROCNAME("pixConvertToFPix");
141 
142  if (!pixs)
143  return (FPIX *)ERROR_PTR("pixs not defined", procName, NULL);
144 
145  /* Convert to a single component */
146  if (pixGetColormap(pixs))
148  else if (pixGetDepth(pixs) == 32 && ncomps == 3)
149  pixt = pixConvertRGBToLuminance(pixs);
150  else
151  pixt = pixClone(pixs);
152  pixGetDimensions(pixt, &w, &h, &d);
153  if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32) {
154  pixDestroy(&pixt);
155  return (FPIX *)ERROR_PTR("invalid depth", procName, NULL);
156  }
157 
158  if ((fpixd = fpixCreate(w, h)) == NULL) {
159  pixDestroy(&pixt);
160  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
161  }
162  datat = pixGetData(pixt);
163  wplt = pixGetWpl(pixt);
164  datad = fpixGetData(fpixd);
165  wpld = fpixGetWpl(fpixd);
166  for (i = 0; i < h; i++) {
167  linet = datat + i * wplt;
168  lined = datad + i * wpld;
169  if (d == 1) {
170  for (j = 0; j < w; j++) {
171  val = GET_DATA_BIT(linet, j);
172  lined[j] = (l_float32)val;
173  }
174  } else if (d == 2) {
175  for (j = 0; j < w; j++) {
176  val = GET_DATA_DIBIT(linet, j);
177  lined[j] = (l_float32)val;
178  }
179  } else if (d == 4) {
180  for (j = 0; j < w; j++) {
181  val = GET_DATA_QBIT(linet, j);
182  lined[j] = (l_float32)val;
183  }
184  } else if (d == 8) {
185  for (j = 0; j < w; j++) {
186  val = GET_DATA_BYTE(linet, j);
187  lined[j] = (l_float32)val;
188  }
189  } else if (d == 16) {
190  for (j = 0; j < w; j++) {
191  val = GET_DATA_TWO_BYTES(linet, j);
192  lined[j] = (l_float32)val;
193  }
194  } else { /* d == 32 */
195  for (j = 0; j < w; j++) {
196  uval = GET_DATA_FOUR_BYTES(linet, j);
197  lined[j] = (l_float32)uval;
198  }
199  }
200  }
201 
202  pixDestroy(&pixt);
203  return fpixd;
204 }
205 
206 
222 DPIX *
224  l_int32 ncomps)
225 {
226 l_int32 w, h, d, i, j, val, wplt, wpld;
227 l_uint32 uval;
228 l_uint32 *datat, *linet;
229 l_float64 *datad, *lined;
230 PIX *pixt;
231 DPIX *dpixd;
232 
233  PROCNAME("pixConvertToDPix");
234 
235  if (!pixs)
236  return (DPIX *)ERROR_PTR("pixs not defined", procName, NULL);
237 
238  /* Convert to a single component */
239  if (pixGetColormap(pixs))
241  else if (pixGetDepth(pixs) == 32 && ncomps == 3)
242  pixt = pixConvertRGBToLuminance(pixs);
243  else
244  pixt = pixClone(pixs);
245  pixGetDimensions(pixt, &w, &h, &d);
246  if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32) {
247  pixDestroy(&pixt);
248  return (DPIX *)ERROR_PTR("invalid depth", procName, NULL);
249  }
250 
251  if ((dpixd = dpixCreate(w, h)) == NULL) {
252  pixDestroy(&pixt);
253  return (DPIX *)ERROR_PTR("dpixd not made", procName, NULL);
254  }
255  datat = pixGetData(pixt);
256  wplt = pixGetWpl(pixt);
257  datad = dpixGetData(dpixd);
258  wpld = dpixGetWpl(dpixd);
259  for (i = 0; i < h; i++) {
260  linet = datat + i * wplt;
261  lined = datad + i * wpld;
262  if (d == 1) {
263  for (j = 0; j < w; j++) {
264  val = GET_DATA_BIT(linet, j);
265  lined[j] = (l_float64)val;
266  }
267  } else if (d == 2) {
268  for (j = 0; j < w; j++) {
269  val = GET_DATA_DIBIT(linet, j);
270  lined[j] = (l_float64)val;
271  }
272  } else if (d == 4) {
273  for (j = 0; j < w; j++) {
274  val = GET_DATA_QBIT(linet, j);
275  lined[j] = (l_float64)val;
276  }
277  } else if (d == 8) {
278  for (j = 0; j < w; j++) {
279  val = GET_DATA_BYTE(linet, j);
280  lined[j] = (l_float64)val;
281  }
282  } else if (d == 16) {
283  for (j = 0; j < w; j++) {
284  val = GET_DATA_TWO_BYTES(linet, j);
285  lined[j] = (l_float64)val;
286  }
287  } else { /* d == 32 */
288  for (j = 0; j < w; j++) {
289  uval = GET_DATA_FOUR_BYTES(linet, j);
290  lined[j] = (l_float64)uval;
291  }
292  }
293  }
294 
295  pixDestroy(&pixt);
296  return dpixd;
297 }
298 
299 
323 PIX *
325  l_int32 outdepth,
326  l_int32 negvals,
327  l_int32 errorflag)
328 {
329 l_int32 w, h, i, j, wpls, wpld;
330 l_uint32 vald, maxval;
331 l_float32 val;
332 l_float32 *datas, *lines;
333 l_uint32 *datad, *lined;
334 PIX *pixd;
335 
336  PROCNAME("fpixConvertToPix");
337 
338  if (!fpixs)
339  return (PIX *)ERROR_PTR("fpixs not defined", procName, NULL);
340  if (negvals != L_CLIP_TO_ZERO && negvals != L_TAKE_ABSVAL)
341  return (PIX *)ERROR_PTR("invalid negvals", procName, NULL);
342  if (outdepth != 0 && outdepth != 8 && outdepth != 16 && outdepth != 32)
343  return (PIX *)ERROR_PTR("outdepth not in {0,8,16,32}", procName, NULL);
344 
345  fpixGetDimensions(fpixs, &w, &h);
346  datas = fpixGetData(fpixs);
347  wpls = fpixGetWpl(fpixs);
348 
349  /* Adaptive determination of output depth */
350  if (outdepth == 0) {
351  outdepth = 8;
352  for (i = 0; i < h && outdepth < 32; i++) {
353  lines = datas + i * wpls;
354  for (j = 0; j < w && outdepth < 32; j++) {
355  if (lines[j] > 65535.5)
356  outdepth = 32;
357  else if (lines[j] > 255.5)
358  outdepth = 16;
359  }
360  }
361  }
362  if (outdepth == 8)
363  maxval = 0xff;
364  else if (outdepth == 16)
365  maxval = 0xffff;
366  else /* outdepth == 32 */
367  maxval = 0xffffffff;
368 
369  /* Gather statistics if %errorflag = TRUE */
370  if (errorflag) {
371  l_int32 negs = 0;
372  l_int32 overvals = 0;
373  for (i = 0; i < h; i++) {
374  lines = datas + i * wpls;
375  for (j = 0; j < w; j++) {
376  val = lines[j];
377  if (val < 0.0)
378  negs++;
379  else if (val > maxval)
380  overvals++;
381  }
382  }
383  if (negs > 0)
384  L_ERROR("Number of negative values: %d\n", procName, negs);
385  if (overvals > 0)
386  L_ERROR("Number of too-large values: %d\n", procName, overvals);
387  }
388 
389  /* Make the pix and convert the data */
390  if ((pixd = pixCreate(w, h, outdepth)) == NULL)
391  return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
392  datad = pixGetData(pixd);
393  wpld = pixGetWpl(pixd);
394  for (i = 0; i < h; i++) {
395  lines = datas + i * wpls;
396  lined = datad + i * wpld;
397  for (j = 0; j < w; j++) {
398  val = lines[j];
399  if (val >= 0.0)
400  vald = (l_uint32)(val + 0.5);
401  else if (negvals == L_CLIP_TO_ZERO) /* and val < 0.0 */
402  vald = 0;
403  else
404  vald = (l_uint32)(-val + 0.5);
405  if (vald > maxval)
406  vald = maxval;
407 
408  if (outdepth == 8)
409  SET_DATA_BYTE(lined, j, vald);
410  else if (outdepth == 16)
411  SET_DATA_TWO_BYTES(lined, j, vald);
412  else /* outdepth == 32 */
413  SET_DATA_FOUR_BYTES(lined, j, vald);
414  }
415  }
416 
417  return pixd;
418 }
419 
420 
427 PIX *
429 {
430 l_uint8 dval;
431 l_int32 i, j, w, h, wpls, wpld;
432 l_float32 factor, sval, maxval;
433 l_float32 *lines, *datas;
434 l_uint32 *lined, *datad;
435 PIX *pixd;
436 
437  PROCNAME("fpixDisplayMaxDynamicRange");
438 
439  if (!fpixs)
440  return (PIX *)ERROR_PTR("fpixs not defined", procName, NULL);
441 
442  fpixGetDimensions(fpixs, &w, &h);
443  datas = fpixGetData(fpixs);
444  wpls = fpixGetWpl(fpixs);
445 
446  maxval = 0.0;
447  for (i = 0; i < h; i++) {
448  lines = datas + i * wpls;
449  for (j = 0; j < w; j++) {
450  sval = *(lines + j);
451  if (sval > maxval)
452  maxval = sval;
453  }
454  }
455 
456  pixd = pixCreate(w, h, 8);
457  if (maxval == 0.0)
458  return pixd; /* all pixels are 0 */
459 
460  datad = pixGetData(pixd);
461  wpld = pixGetWpl(pixd);
462  factor = 255. / maxval;
463  for (i = 0; i < h; i++) {
464  lines = datas + i * wpls;
465  lined = datad + i * wpld;
466  for (j = 0; j < w; j++) {
467  sval = *(lines + j);
468  if (sval < 0.0) sval = 0.0;
469  dval = (l_uint8)(factor * sval + 0.5);
470  SET_DATA_BYTE(lined, j, dval);
471  }
472  }
473 
474  return pixd;
475 }
476 
477 
484 DPIX *
486 {
487 l_int32 w, h, i, j, wpls, wpld;
488 l_float32 val;
489 l_float32 *datas, *lines;
490 l_float64 *datad, *lined;
491 DPIX *dpix;
492 
493  PROCNAME("fpixConvertToDPix");
494 
495  if (!fpix)
496  return (DPIX *)ERROR_PTR("fpix not defined", procName, NULL);
497 
498  fpixGetDimensions(fpix, &w, &h);
499  if ((dpix = dpixCreate(w, h)) == NULL)
500  return (DPIX *)ERROR_PTR("dpix not made", procName, NULL);
501 
502  datas = fpixGetData(fpix);
503  datad = dpixGetData(dpix);
504  wpls = fpixGetWpl(fpix);
505  wpld = dpixGetWpl(dpix); /* 8 byte words */
506  for (i = 0; i < h; i++) {
507  lines = datas + i * wpls;
508  lined = datad + i * wpld;
509  for (j = 0; j < w; j++) {
510  val = lines[j];
511  lined[j] = val;
512  }
513  }
514 
515  return dpix;
516 }
517 
518 
542 PIX *
544  l_int32 outdepth,
545  l_int32 negvals,
546  l_int32 errorflag)
547 {
548 l_int32 w, h, i, j, wpls, wpld, maxval;
549 l_uint32 vald;
550 l_float64 val;
551 l_float64 *datas, *lines;
552 l_uint32 *datad, *lined;
553 PIX *pixd;
554 
555  PROCNAME("dpixConvertToPix");
556 
557  if (!dpixs)
558  return (PIX *)ERROR_PTR("dpixs not defined", procName, NULL);
559  if (negvals != L_CLIP_TO_ZERO && negvals != L_TAKE_ABSVAL)
560  return (PIX *)ERROR_PTR("invalid negvals", procName, NULL);
561  if (outdepth != 0 && outdepth != 8 && outdepth != 16 && outdepth != 32)
562  return (PIX *)ERROR_PTR("outdepth not in {0,8,16,32}", procName, NULL);
563 
564  dpixGetDimensions(dpixs, &w, &h);
565  datas = dpixGetData(dpixs);
566  wpls = dpixGetWpl(dpixs);
567 
568  /* Adaptive determination of output depth */
569  if (outdepth == 0) {
570  outdepth = 8;
571  for (i = 0; i < h && outdepth < 32; i++) {
572  lines = datas + i * wpls;
573  for (j = 0; j < w && outdepth < 32; j++) {
574  if (lines[j] > 65535.5)
575  outdepth = 32;
576  else if (lines[j] > 255.5)
577  outdepth = 16;
578  }
579  }
580  }
581  maxval = 0xff;
582  if (outdepth == 16)
583  maxval = 0xffff;
584  else /* outdepth == 32 */
585  maxval = 0xffffffff;
586 
587  /* Gather statistics if %errorflag = TRUE */
588  if (errorflag) {
589  l_int32 negs = 0;
590  l_int32 overvals = 0;
591  for (i = 0; i < h; i++) {
592  lines = datas + i * wpls;
593  for (j = 0; j < w; j++) {
594  val = lines[j];
595  if (val < 0.0)
596  negs++;
597  else if (val > maxval)
598  overvals++;
599  }
600  }
601  if (negs > 0)
602  L_ERROR("Number of negative values: %d\n", procName, negs);
603  if (overvals > 0)
604  L_ERROR("Number of too-large values: %d\n", procName, overvals);
605  }
606 
607  /* Make the pix and convert the data */
608  if ((pixd = pixCreate(w, h, outdepth)) == NULL)
609  return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
610  datad = pixGetData(pixd);
611  wpld = pixGetWpl(pixd);
612  for (i = 0; i < h; i++) {
613  lines = datas + i * wpls;
614  lined = datad + i * wpld;
615  for (j = 0; j < w; j++) {
616  val = lines[j];
617  if (val >= 0.0) {
618  vald = (l_uint32)(val + 0.5);
619  } else { /* val < 0.0 */
620  if (negvals == L_CLIP_TO_ZERO)
621  vald = 0;
622  else
623  vald = (l_uint32)(-val + 0.5);
624  }
625  if (vald > maxval)
626  vald = maxval;
627  if (outdepth == 8)
628  SET_DATA_BYTE(lined, j, vald);
629  else if (outdepth == 16)
630  SET_DATA_TWO_BYTES(lined, j, vald);
631  else /* outdepth == 32 */
632  SET_DATA_FOUR_BYTES(lined, j, vald);
633  }
634  }
635 
636  return pixd;
637 }
638 
639 
646 FPIX *
648 {
649 l_int32 w, h, i, j, wpls, wpld;
650 l_float64 val;
651 l_float32 *datad, *lined;
652 l_float64 *datas, *lines;
653 FPIX *fpix;
654 
655  PROCNAME("dpixConvertToFPix");
656 
657  if (!dpix)
658  return (FPIX *)ERROR_PTR("dpix not defined", procName, NULL);
659 
660  dpixGetDimensions(dpix, &w, &h);
661  if ((fpix = fpixCreate(w, h)) == NULL)
662  return (FPIX *)ERROR_PTR("fpix not made", procName, NULL);
663 
664  datas = dpixGetData(dpix);
665  datad = fpixGetData(fpix);
666  wpls = dpixGetWpl(dpix); /* 8 byte words */
667  wpld = fpixGetWpl(fpix);
668  for (i = 0; i < h; i++) {
669  lines = datas + i * wpls;
670  lined = datad + i * wpld;
671  for (j = 0; j < w; j++) {
672  val = lines[j];
673  lined[j] = (l_float32)val;
674  }
675  }
676 
677  return fpix;
678 }
679 
680 
681 
682 /*--------------------------------------------------------------------*
683  * Min/max value *
684  *--------------------------------------------------------------------*/
694 l_ok
696  l_float32 *pminval,
697  l_int32 *pxminloc,
698  l_int32 *pyminloc)
699 {
700 l_int32 i, j, w, h, wpl, xminloc, yminloc;
701 l_float32 *data, *line;
702 l_float32 minval;
703 
704  PROCNAME("fpixGetMin");
705 
706  if (!pminval && !pxminloc && !pyminloc)
707  return ERROR_INT("no return val requested", procName, 1);
708  if (pminval) *pminval = 0.0;
709  if (pxminloc) *pxminloc = 0;
710  if (pyminloc) *pyminloc = 0;
711  if (!fpix)
712  return ERROR_INT("fpix not defined", procName, 1);
713 
714  minval = +1.0e20;
715  xminloc = 0;
716  yminloc = 0;
717  fpixGetDimensions(fpix, &w, &h);
718  data = fpixGetData(fpix);
719  wpl = fpixGetWpl(fpix);
720  for (i = 0; i < h; i++) {
721  line = data + i * wpl;
722  for (j = 0; j < w; j++) {
723  if (line[j] < minval) {
724  minval = line[j];
725  xminloc = j;
726  yminloc = i;
727  }
728  }
729  }
730 
731  if (pminval) *pminval = minval;
732  if (pxminloc) *pxminloc = xminloc;
733  if (pyminloc) *pyminloc = yminloc;
734  return 0;
735 }
736 
737 
747 l_ok
749  l_float32 *pmaxval,
750  l_int32 *pxmaxloc,
751  l_int32 *pymaxloc)
752 {
753 l_int32 i, j, w, h, wpl, xmaxloc, ymaxloc;
754 l_float32 *data, *line;
755 l_float32 maxval;
756 
757  PROCNAME("fpixGetMax");
758 
759  if (!pmaxval && !pxmaxloc && !pymaxloc)
760  return ERROR_INT("no return val requested", procName, 1);
761  if (pmaxval) *pmaxval = 0.0;
762  if (pxmaxloc) *pxmaxloc = 0;
763  if (pymaxloc) *pymaxloc = 0;
764  if (!fpix)
765  return ERROR_INT("fpix not defined", procName, 1);
766 
767  maxval = -1.0e20;
768  xmaxloc = 0;
769  ymaxloc = 0;
770  fpixGetDimensions(fpix, &w, &h);
771  data = fpixGetData(fpix);
772  wpl = fpixGetWpl(fpix);
773  for (i = 0; i < h; i++) {
774  line = data + i * wpl;
775  for (j = 0; j < w; j++) {
776  if (line[j] > maxval) {
777  maxval = line[j];
778  xmaxloc = j;
779  ymaxloc = i;
780  }
781  }
782  }
783 
784  if (pmaxval) *pmaxval = maxval;
785  if (pxmaxloc) *pxmaxloc = xmaxloc;
786  if (pymaxloc) *pymaxloc = ymaxloc;
787  return 0;
788 }
789 
790 
800 l_ok
802  l_float64 *pminval,
803  l_int32 *pxminloc,
804  l_int32 *pyminloc)
805 {
806 l_int32 i, j, w, h, wpl, xminloc, yminloc;
807 l_float64 *data, *line;
808 l_float64 minval;
809 
810  PROCNAME("dpixGetMin");
811 
812  if (!pminval && !pxminloc && !pyminloc)
813  return ERROR_INT("no return val requested", procName, 1);
814  if (pminval) *pminval = 0.0;
815  if (pxminloc) *pxminloc = 0;
816  if (pyminloc) *pyminloc = 0;
817  if (!dpix)
818  return ERROR_INT("dpix not defined", procName, 1);
819 
820  minval = +1.0e300;
821  xminloc = 0;
822  yminloc = 0;
823  dpixGetDimensions(dpix, &w, &h);
824  data = dpixGetData(dpix);
825  wpl = dpixGetWpl(dpix);
826  for (i = 0; i < h; i++) {
827  line = data + i * wpl;
828  for (j = 0; j < w; j++) {
829  if (line[j] < minval) {
830  minval = line[j];
831  xminloc = j;
832  yminloc = i;
833  }
834  }
835  }
836 
837  if (pminval) *pminval = minval;
838  if (pxminloc) *pxminloc = xminloc;
839  if (pyminloc) *pyminloc = yminloc;
840  return 0;
841 }
842 
843 
853 l_ok
855  l_float64 *pmaxval,
856  l_int32 *pxmaxloc,
857  l_int32 *pymaxloc)
858 {
859 l_int32 i, j, w, h, wpl, xmaxloc, ymaxloc;
860 l_float64 *data, *line;
861 l_float64 maxval;
862 
863  PROCNAME("dpixGetMax");
864 
865  if (!pmaxval && !pxmaxloc && !pymaxloc)
866  return ERROR_INT("no return val requested", procName, 1);
867  if (pmaxval) *pmaxval = 0.0;
868  if (pxmaxloc) *pxmaxloc = 0;
869  if (pymaxloc) *pymaxloc = 0;
870  if (!dpix)
871  return ERROR_INT("dpix not defined", procName, 1);
872 
873  maxval = -1.0e20;
874  xmaxloc = 0;
875  ymaxloc = 0;
876  dpixGetDimensions(dpix, &w, &h);
877  data = dpixGetData(dpix);
878  wpl = dpixGetWpl(dpix);
879  for (i = 0; i < h; i++) {
880  line = data + i * wpl;
881  for (j = 0; j < w; j++) {
882  if (line[j] > maxval) {
883  maxval = line[j];
884  xmaxloc = j;
885  ymaxloc = i;
886  }
887  }
888  }
889 
890  if (pmaxval) *pmaxval = maxval;
891  if (pxmaxloc) *pxmaxloc = xmaxloc;
892  if (pymaxloc) *pymaxloc = ymaxloc;
893  return 0;
894 }
895 
896 
897 /*--------------------------------------------------------------------*
898  * Special integer scaling *
899  *--------------------------------------------------------------------*/
920 FPIX *
922  l_int32 factor)
923 {
924 l_int32 i, j, k, m, ws, hs, wd, hd, wpls, wpld;
925 l_float32 val0, val1, val2, val3;
926 l_float32 *datas, *datad, *lines, *lined, *fract;
927 FPIX *fpixd;
928 
929  PROCNAME("fpixScaleByInteger");
930 
931  if (!fpixs)
932  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
933 
934  fpixGetDimensions(fpixs, &ws, &hs);
935  wd = factor * (ws - 1) + 1;
936  hd = factor * (hs - 1) + 1;
937  fpixd = fpixCreate(wd, hd);
938  datas = fpixGetData(fpixs);
939  datad = fpixGetData(fpixd);
940  wpls = fpixGetWpl(fpixs);
941  wpld = fpixGetWpl(fpixd);
942  fract = (l_float32 *)LEPT_CALLOC(factor, sizeof(l_float32));
943  for (i = 0; i < factor; i++)
944  fract[i] = i / (l_float32)factor;
945  for (i = 0; i < hs - 1; i++) {
946  lines = datas + i * wpls;
947  for (j = 0; j < ws - 1; j++) {
948  val0 = lines[j];
949  val1 = lines[j + 1];
950  val2 = lines[wpls + j];
951  val3 = lines[wpls + j + 1];
952  for (k = 0; k < factor; k++) { /* rows of sub-block */
953  lined = datad + (i * factor + k) * wpld;
954  for (m = 0; m < factor; m++) { /* cols of sub-block */
955  lined[j * factor + m] =
956  val0 * (1.0 - fract[m]) * (1.0 - fract[k]) +
957  val1 * fract[m] * (1.0 - fract[k]) +
958  val2 * (1.0 - fract[m]) * fract[k] +
959  val3 * fract[m] * fract[k];
960  }
961  }
962  }
963  }
964 
965  /* Do the right-most column of fpixd, skipping LR corner */
966  for (i = 0; i < hs - 1; i++) {
967  lines = datas + i * wpls;
968  val0 = lines[ws - 1];
969  val1 = lines[wpls + ws - 1];
970  for (k = 0; k < factor; k++) {
971  lined = datad + (i * factor + k) * wpld;
972  lined[wd - 1] = val0 * (1.0 - fract[k]) + val1 * fract[k];
973  }
974  }
975 
976  /* Do the bottom-most row of fpixd */
977  lines = datas + (hs - 1) * wpls;
978  lined = datad + (hd - 1) * wpld;
979  for (j = 0; j < ws - 1; j++) {
980  val0 = lines[j];
981  val1 = lines[j + 1];
982  for (m = 0; m < factor; m++)
983  lined[j * factor + m] = val0 * (1.0 - fract[m]) + val1 * fract[m];
984  lined[wd - 1] = lines[ws - 1]; /* LR corner */
985  }
986 
987  LEPT_FREE(fract);
988  return fpixd;
989 }
990 
991 
1012 DPIX *
1014  l_int32 factor)
1015 {
1016 l_int32 i, j, k, m, ws, hs, wd, hd, wpls, wpld;
1017 l_float64 val0, val1, val2, val3;
1018 l_float64 *datas, *datad, *lines, *lined, *fract;
1019 DPIX *dpixd;
1020 
1021  PROCNAME("dpixScaleByInteger");
1022 
1023  if (!dpixs)
1024  return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
1025 
1026  dpixGetDimensions(dpixs, &ws, &hs);
1027  wd = factor * (ws - 1) + 1;
1028  hd = factor * (hs - 1) + 1;
1029  dpixd = dpixCreate(wd, hd);
1030  datas = dpixGetData(dpixs);
1031  datad = dpixGetData(dpixd);
1032  wpls = dpixGetWpl(dpixs);
1033  wpld = dpixGetWpl(dpixd);
1034  fract = (l_float64 *)LEPT_CALLOC(factor, sizeof(l_float64));
1035  for (i = 0; i < factor; i++)
1036  fract[i] = i / (l_float64)factor;
1037  for (i = 0; i < hs - 1; i++) {
1038  lines = datas + i * wpls;
1039  for (j = 0; j < ws - 1; j++) {
1040  val0 = lines[j];
1041  val1 = lines[j + 1];
1042  val2 = lines[wpls + j];
1043  val3 = lines[wpls + j + 1];
1044  for (k = 0; k < factor; k++) { /* rows of sub-block */
1045  lined = datad + (i * factor + k) * wpld;
1046  for (m = 0; m < factor; m++) { /* cols of sub-block */
1047  lined[j * factor + m] =
1048  val0 * (1.0 - fract[m]) * (1.0 - fract[k]) +
1049  val1 * fract[m] * (1.0 - fract[k]) +
1050  val2 * (1.0 - fract[m]) * fract[k] +
1051  val3 * fract[m] * fract[k];
1052  }
1053  }
1054  }
1055  }
1056 
1057  /* Do the right-most column of dpixd, skipping LR corner */
1058  for (i = 0; i < hs - 1; i++) {
1059  lines = datas + i * wpls;
1060  val0 = lines[ws - 1];
1061  val1 = lines[wpls + ws - 1];
1062  for (k = 0; k < factor; k++) {
1063  lined = datad + (i * factor + k) * wpld;
1064  lined[wd - 1] = val0 * (1.0 - fract[k]) + val1 * fract[k];
1065  }
1066  }
1067 
1068  /* Do the bottom-most row of dpixd */
1069  lines = datas + (hs - 1) * wpls;
1070  lined = datad + (hd - 1) * wpld;
1071  for (j = 0; j < ws - 1; j++) {
1072  val0 = lines[j];
1073  val1 = lines[j + 1];
1074  for (m = 0; m < factor; m++)
1075  lined[j * factor + m] = val0 * (1.0 - fract[m]) + val1 * fract[m];
1076  lined[wd - 1] = lines[ws - 1]; /* LR corner */
1077  }
1078 
1079  LEPT_FREE(fract);
1080  return dpixd;
1081 }
1082 
1083 
1084 /*--------------------------------------------------------------------*
1085  * Arithmetic operations *
1086  *--------------------------------------------------------------------*/
1107 FPIX *
1109  FPIX *fpixs1,
1110  FPIX *fpixs2,
1111  l_float32 a,
1112  l_float32 b)
1113 {
1114 l_int32 i, j, ws, hs, w, h, wpls, wpld;
1115 l_float32 *datas, *datad, *lines, *lined;
1116 
1117  PROCNAME("fpixLinearCombination");
1118 
1119  if (!fpixs1)
1120  return (FPIX *)ERROR_PTR("fpixs1 not defined", procName, fpixd);
1121  if (!fpixs2)
1122  return (FPIX *)ERROR_PTR("fpixs2 not defined", procName, fpixd);
1123  if (fpixd && (fpixd != fpixs1))
1124  return (FPIX *)ERROR_PTR("invalid inplace operation", procName, fpixd);
1125 
1126  if (!fpixd)
1127  fpixd = fpixCopy(fpixs1);
1128  datas = fpixGetData(fpixs2);
1129  datad = fpixGetData(fpixd);
1130  wpls = fpixGetWpl(fpixs2);
1131  wpld = fpixGetWpl(fpixd);
1132  fpixGetDimensions(fpixs2, &ws, &hs);
1133  fpixGetDimensions(fpixd, &w, &h);
1134  w = L_MIN(ws, w);
1135  h = L_MIN(hs, h);
1136  for (i = 0; i < h; i++) {
1137  lines = datas + i * wpls;
1138  lined = datad + i * wpld;
1139  for (j = 0; j < w; j++)
1140  lined[j] = a * lined[j] + b * lines[j];
1141  }
1142 
1143  return fpixd;
1144 }
1145 
1146 
1163 l_ok
1165  l_float32 addc,
1166  l_float32 multc)
1167 {
1168 l_int32 i, j, w, h, wpl;
1169 l_float32 *line, *data;
1170 
1171  PROCNAME("fpixAddMultConstant");
1172 
1173  if (!fpix)
1174  return ERROR_INT("fpix not defined", procName, 1);
1175 
1176  if (addc == 0.0 && multc == 1.0)
1177  return 0;
1178 
1179  fpixGetDimensions(fpix, &w, &h);
1180  data = fpixGetData(fpix);
1181  wpl = fpixGetWpl(fpix);
1182  for (i = 0; i < h; i++) {
1183  line = data + i * wpl;
1184  if (addc == 0.0) {
1185  for (j = 0; j < w; j++)
1186  line[j] *= multc;
1187  } else if (multc == 1.0) {
1188  for (j = 0; j < w; j++)
1189  line[j] += addc;
1190  } else {
1191  for (j = 0; j < w; j++) {
1192  line[j] = multc * line[j] + addc;
1193  }
1194  }
1195  }
1196 
1197  return 0;
1198 }
1199 
1200 
1221 DPIX *
1223  DPIX *dpixs1,
1224  DPIX *dpixs2,
1225  l_float32 a,
1226  l_float32 b)
1227 {
1228 l_int32 i, j, ws, hs, w, h, wpls, wpld;
1229 l_float64 *datas, *datad, *lines, *lined;
1230 
1231  PROCNAME("dpixLinearCombination");
1232 
1233  if (!dpixs1)
1234  return (DPIX *)ERROR_PTR("dpixs1 not defined", procName, dpixd);
1235  if (!dpixs2)
1236  return (DPIX *)ERROR_PTR("dpixs2 not defined", procName, dpixd);
1237  if (dpixd && (dpixd != dpixs1))
1238  return (DPIX *)ERROR_PTR("invalid inplace operation", procName, dpixd);
1239 
1240  if (!dpixd)
1241  dpixd = dpixCopy(dpixs1);
1242  datas = dpixGetData(dpixs2);
1243  datad = dpixGetData(dpixd);
1244  wpls = dpixGetWpl(dpixs2);
1245  wpld = dpixGetWpl(dpixd);
1246  dpixGetDimensions(dpixs2, &ws, &hs);
1247  dpixGetDimensions(dpixd, &w, &h);
1248  w = L_MIN(ws, w);
1249  h = L_MIN(hs, h);
1250  for (i = 0; i < h; i++) {
1251  lines = datas + i * wpls;
1252  lined = datad + i * wpld;
1253  for (j = 0; j < w; j++)
1254  lined[j] = a * lined[j] + b * lines[j];
1255  }
1256 
1257  return dpixd;
1258 }
1259 
1260 
1277 l_ok
1279  l_float64 addc,
1280  l_float64 multc)
1281 {
1282 l_int32 i, j, w, h, wpl;
1283 l_float64 *line, *data;
1284 
1285  PROCNAME("dpixAddMultConstant");
1286 
1287  if (!dpix)
1288  return ERROR_INT("dpix not defined", procName, 1);
1289 
1290  if (addc == 0.0 && multc == 1.0)
1291  return 0;
1292 
1293  dpixGetDimensions(dpix, &w, &h);
1294  data = dpixGetData(dpix);
1295  wpl = dpixGetWpl(dpix);
1296  for (i = 0; i < h; i++) {
1297  line = data + i * wpl;
1298  if (addc == 0.0) {
1299  for (j = 0; j < w; j++)
1300  line[j] *= multc;
1301  } else if (multc == 1.0) {
1302  for (j = 0; j < w; j++)
1303  line[j] += addc;
1304  } else {
1305  for (j = 0; j < w; j++)
1306  line[j] = multc * line[j] + addc;
1307  }
1308  }
1309 
1310  return 0;
1311 }
1312 
1313 
1314 /*--------------------------------------------------------------------*
1315  * Set all *
1316  *--------------------------------------------------------------------*/
1324 l_ok
1326  l_float32 inval)
1327 {
1328 l_int32 i, j, w, h;
1329 l_float32 *data, *line;
1330 
1331  PROCNAME("fpixSetAllArbitrary");
1332 
1333  if (!fpix)
1334  return ERROR_INT("fpix not defined", procName, 1);
1335 
1336  fpixGetDimensions(fpix, &w, &h);
1337  data = fpixGetData(fpix);
1338  for (i = 0; i < h; i++) {
1339  line = data + i * w;
1340  for (j = 0; j < w; j++)
1341  *(line + j) = inval;
1342  }
1343 
1344  return 0;
1345 }
1346 
1347 
1355 l_ok
1357  l_float64 inval)
1358 {
1359 l_int32 i, j, w, h;
1360 l_float64 *data, *line;
1361 
1362  PROCNAME("dpixSetAllArbitrary");
1363 
1364  if (!dpix)
1365  return ERROR_INT("dpix not defined", procName, 1);
1366 
1367  dpixGetDimensions(dpix, &w, &h);
1368  data = dpixGetData(dpix);
1369  for (i = 0; i < h; i++) {
1370  line = data + i * w;
1371  for (j = 0; j < w; j++)
1372  *(line + j) = inval;
1373  }
1374 
1375  return 0;
1376 }
1377 
1378 
1379 /*--------------------------------------------------------------------*
1380  * Border functions *
1381  *--------------------------------------------------------------------*/
1394 FPIX *
1396  l_int32 left,
1397  l_int32 right,
1398  l_int32 top,
1399  l_int32 bot)
1400 {
1401 l_int32 ws, hs, wd, hd;
1402 FPIX *fpixd;
1403 
1404  PROCNAME("fpixAddBorder");
1405 
1406  if (!fpixs)
1407  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1408 
1409  if (left <= 0 && right <= 0 && top <= 0 && bot <= 0)
1410  return fpixCopy(fpixs);
1411  fpixGetDimensions(fpixs, &ws, &hs);
1412  wd = ws + left + right;
1413  hd = hs + top + bot;
1414  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1415  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1416 
1417  fpixCopyResolution(fpixd, fpixs);
1418  fpixRasterop(fpixd, left, top, ws, hs, fpixs, 0, 0);
1419  return fpixd;
1420 }
1421 
1422 
1430 FPIX *
1432  l_int32 left,
1433  l_int32 right,
1434  l_int32 top,
1435  l_int32 bot)
1436 {
1437 l_int32 ws, hs, wd, hd;
1438 FPIX *fpixd;
1439 
1440  PROCNAME("fpixRemoveBorder");
1441 
1442  if (!fpixs)
1443  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1444 
1445  if (left <= 0 && right <= 0 && top <= 0 && bot <= 0)
1446  return fpixCopy(fpixs);
1447  fpixGetDimensions(fpixs, &ws, &hs);
1448  wd = ws - left - right;
1449  hd = hs - top - bot;
1450  if (wd <= 0 || hd <= 0)
1451  return (FPIX *)ERROR_PTR("width & height not both > 0", procName, NULL);
1452  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1453  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1454 
1455  fpixCopyResolution(fpixd, fpixs);
1456  fpixRasterop(fpixd, 0, 0, wd, hd, fpixs, left, top);
1457  return fpixd;
1458 }
1459 
1460 
1461 
1474 FPIX *
1476  l_int32 left,
1477  l_int32 right,
1478  l_int32 top,
1479  l_int32 bot)
1480 {
1481 l_int32 i, j, w, h;
1482 FPIX *fpixd;
1483 
1484  PROCNAME("fpixAddMirroredBorder");
1485 
1486  if (!fpixs)
1487  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1488 
1489  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1490  fpixGetDimensions(fpixs, &w, &h);
1491  for (j = 0; j < left; j++)
1492  fpixRasterop(fpixd, left - 1 - j, top, 1, h,
1493  fpixd, left + j, top);
1494  for (j = 0; j < right; j++)
1495  fpixRasterop(fpixd, left + w + j, top, 1, h,
1496  fpixd, left + w - 1 - j, top);
1497  for (i = 0; i < top; i++)
1498  fpixRasterop(fpixd, 0, top - 1 - i, left + w + right, 1,
1499  fpixd, 0, top + i);
1500  for (i = 0; i < bot; i++)
1501  fpixRasterop(fpixd, 0, top + h + i, left + w + right, 1,
1502  fpixd, 0, top + h - 1 - i);
1503 
1504  return fpixd;
1505 }
1506 
1507 
1521 FPIX *
1523  l_int32 left,
1524  l_int32 right,
1525  l_int32 top,
1526  l_int32 bot)
1527 {
1528 l_int32 i, j, w, h;
1529 FPIX *fpixd;
1530 
1531  PROCNAME("fpixAddContinuedBorder");
1532 
1533  if (!fpixs)
1534  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1535 
1536  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1537  fpixGetDimensions(fpixs, &w, &h);
1538  for (j = 0; j < left; j++)
1539  fpixRasterop(fpixd, j, top, 1, h, fpixd, left, top);
1540  for (j = 0; j < right; j++)
1541  fpixRasterop(fpixd, left + w + j, top, 1, h, fpixd, left + w - 1, top);
1542  for (i = 0; i < top; i++)
1543  fpixRasterop(fpixd, 0, i, left + w + right, 1, fpixd, 0, top);
1544  for (i = 0; i < bot; i++)
1545  fpixRasterop(fpixd, 0, top + h + i, left + w + right, 1,
1546  fpixd, 0, top + h - 1);
1547 
1548  return fpixd;
1549 }
1550 
1551 
1566 FPIX *
1568  l_int32 left,
1569  l_int32 right,
1570  l_int32 top,
1571  l_int32 bot)
1572 {
1573 l_int32 i, j, w, h, fullw, fullh;
1574 l_float32 val1, val2, del;
1575 FPIX *fpixd;
1576 
1577  PROCNAME("fpixAddSlopeBorder");
1578 
1579  if (!fpixs)
1580  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1581 
1582  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1583  fpixGetDimensions(fpixs, &w, &h);
1584 
1585  /* Left */
1586  for (i = top; i < top + h; i++) {
1587  fpixGetPixel(fpixd, left, i, &val1);
1588  fpixGetPixel(fpixd, left + 1, i, &val2);
1589  del = val1 - val2;
1590  for (j = 0; j < left; j++)
1591  fpixSetPixel(fpixd, j, i, val1 + del * (left - j));
1592  }
1593 
1594  /* Right */
1595  fullw = left + w + right;
1596  for (i = top; i < top + h; i++) {
1597  fpixGetPixel(fpixd, left + w - 1, i, &val1);
1598  fpixGetPixel(fpixd, left + w - 2, i, &val2);
1599  del = val1 - val2;
1600  for (j = left + w; j < fullw; j++)
1601  fpixSetPixel(fpixd, j, i, val1 + del * (j - left - w + 1));
1602  }
1603 
1604  /* Top */
1605  for (j = 0; j < fullw; j++) {
1606  fpixGetPixel(fpixd, j, top, &val1);
1607  fpixGetPixel(fpixd, j, top + 1, &val2);
1608  del = val1 - val2;
1609  for (i = 0; i < top; i++)
1610  fpixSetPixel(fpixd, j, i, val1 + del * (top - i));
1611  }
1612 
1613  /* Bottom */
1614  fullh = top + h + bot;
1615  for (j = 0; j < fullw; j++) {
1616  fpixGetPixel(fpixd, j, top + h - 1, &val1);
1617  fpixGetPixel(fpixd, j, top + h - 2, &val2);
1618  del = val1 - val2;
1619  for (i = top + h; i < fullh; i++)
1620  fpixSetPixel(fpixd, j, i, val1 + del * (i - top - h + 1));
1621  }
1622 
1623  return fpixd;
1624 }
1625 
1626 
1627 /*--------------------------------------------------------------------*
1628  * Simple rasterop *
1629  *--------------------------------------------------------------------*/
1655 l_ok
1657  l_int32 dx,
1658  l_int32 dy,
1659  l_int32 dw,
1660  l_int32 dh,
1661  FPIX *fpixs,
1662  l_int32 sx,
1663  l_int32 sy)
1664 {
1665 l_int32 fsw, fsh, fdw, fdh, dhangw, shangw, dhangh, shangh;
1666 l_int32 i, j, wpls, wpld;
1667 l_float32 *datas, *datad, *lines, *lined;
1668 
1669  PROCNAME("fpixRasterop");
1670 
1671  if (!fpixs)
1672  return ERROR_INT("fpixs not defined", procName, 1);
1673  if (!fpixd)
1674  return ERROR_INT("fpixd not defined", procName, 1);
1675 
1676  /* -------------------------------------------------------- *
1677  * Clip to maximum rectangle with both src and dest *
1678  * -------------------------------------------------------- */
1679  fpixGetDimensions(fpixs, &fsw, &fsh);
1680  fpixGetDimensions(fpixd, &fdw, &fdh);
1681 
1682  /* First clip horizontally (sx, dx, dw) */
1683  if (dx < 0) {
1684  sx -= dx; /* increase sx */
1685  dw += dx; /* reduce dw */
1686  dx = 0;
1687  }
1688  if (sx < 0) {
1689  dx -= sx; /* increase dx */
1690  dw += sx; /* reduce dw */
1691  sx = 0;
1692  }
1693  dhangw = dx + dw - fdw; /* rect overhang of dest to right */
1694  if (dhangw > 0)
1695  dw -= dhangw; /* reduce dw */
1696  shangw = sx + dw - fsw; /* rect overhang of src to right */
1697  if (shangw > 0)
1698  dw -= shangw; /* reduce dw */
1699 
1700  /* Then clip vertically (sy, dy, dh) */
1701  if (dy < 0) {
1702  sy -= dy; /* increase sy */
1703  dh += dy; /* reduce dh */
1704  dy = 0;
1705  }
1706  if (sy < 0) {
1707  dy -= sy; /* increase dy */
1708  dh += sy; /* reduce dh */
1709  sy = 0;
1710  }
1711  dhangh = dy + dh - fdh; /* rect overhang of dest below */
1712  if (dhangh > 0)
1713  dh -= dhangh; /* reduce dh */
1714  shangh = sy + dh - fsh; /* rect overhang of src below */
1715  if (shangh > 0)
1716  dh -= shangh; /* reduce dh */
1717 
1718  /* if clipped entirely, quit */
1719  if ((dw <= 0) || (dh <= 0))
1720  return 0;
1721 
1722  /* -------------------------------------------------------- *
1723  * Copy block of data *
1724  * -------------------------------------------------------- */
1725  datas = fpixGetData(fpixs);
1726  datad = fpixGetData(fpixd);
1727  wpls = fpixGetWpl(fpixs);
1728  wpld = fpixGetWpl(fpixd);
1729  datas += sy * wpls + sx; /* at UL corner of block */
1730  datad += dy * wpld + dx; /* at UL corner of block */
1731  for (i = 0; i < dh; i++) {
1732  lines = datas + i * wpls;
1733  lined = datad + i * wpld;
1734  for (j = 0; j < dw; j++) {
1735  *lined = *lines;
1736  lines++;
1737  lined++;
1738  }
1739  }
1740 
1741  return 0;
1742 }
1743 
1744 
1745 /*--------------------------------------------------------------------*
1746  * Rotation by multiples of 90 degrees *
1747  *--------------------------------------------------------------------*/
1755 FPIX *
1757  l_int32 quads)
1758 {
1759  PROCNAME("fpixRotateOrth");
1760 
1761  if (!fpixs)
1762  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1763  if (quads < 0 || quads > 3)
1764  return (FPIX *)ERROR_PTR("quads not in {0,1,2,3}", procName, NULL);
1765 
1766  if (quads == 0)
1767  return fpixCopy(fpixs);
1768  else if (quads == 1)
1769  return fpixRotate90(fpixs, 1);
1770  else if (quads == 2)
1771  return fpixRotate180(NULL, fpixs);
1772  else /* quads == 3 */
1773  return fpixRotate90(fpixs, -1);
1774 }
1775 
1776 
1798 FPIX *
1800  FPIX *fpixs)
1801 {
1802  PROCNAME("fpixRotate180");
1803 
1804  if (!fpixs)
1805  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1806 
1807  /* Prepare pixd for in-place operation */
1808  if (!fpixd)
1809  fpixd = fpixCopy(fpixs);
1810 
1811  fpixFlipLR(fpixd, fpixd);
1812  fpixFlipTB(fpixd, fpixd);
1813  return fpixd;
1814 }
1815 
1816 
1831 FPIX *
1833  l_int32 direction)
1834 {
1835 l_int32 i, j, wd, hd, wpls, wpld;
1836 l_float32 *datas, *datad, *lines, *lined;
1837 FPIX *fpixd;
1838 
1839  PROCNAME("fpixRotate90");
1840 
1841  if (!fpixs)
1842  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1843  if (direction != 1 && direction != -1)
1844  return (FPIX *)ERROR_PTR("invalid direction", procName, NULL);
1845 
1846  fpixGetDimensions(fpixs, &hd, &wd);
1847  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1848  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1849  fpixCopyResolution(fpixd, fpixs);
1850 
1851  datas = fpixGetData(fpixs);
1852  wpls = fpixGetWpl(fpixs);
1853  datad = fpixGetData(fpixd);
1854  wpld = fpixGetWpl(fpixd);
1855  if (direction == 1) { /* clockwise */
1856  for (i = 0; i < hd; i++) {
1857  lined = datad + i * wpld;
1858  lines = datas + (wd - 1) * wpls;
1859  for (j = 0; j < wd; j++) {
1860  lined[j] = lines[i];
1861  lines -= wpls;
1862  }
1863  }
1864  } else { /* ccw */
1865  for (i = 0; i < hd; i++) {
1866  lined = datad + i * wpld;
1867  lines = datas;
1868  for (j = 0; j < wd; j++) {
1869  lined[j] = lines[hd - 1 - i];
1870  lines += wpls;
1871  }
1872  }
1873  }
1874 
1875  return fpixd;
1876 }
1877 
1878 
1899 FPIX *
1901  FPIX *fpixs)
1902 {
1903 l_int32 i, j, w, h, wpl, bpl;
1904 l_float32 *line, *data, *buffer;
1905 
1906  PROCNAME("fpixFlipLR");
1907 
1908  if (!fpixs)
1909  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1910 
1911  /* Prepare fpixd for in-place operation */
1912  if (!fpixd)
1913  fpixd = fpixCopy(fpixs);
1914 
1915  fpixGetDimensions(fpixd, &w, &h);
1916  data = fpixGetData(fpixd);
1917  wpl = fpixGetWpl(fpixd); /* 4-byte words */
1918  bpl = 4 * wpl;
1919  buffer = (l_float32 *)LEPT_CALLOC(wpl, sizeof(l_float32));
1920  for (i = 0; i < h; i++) {
1921  line = data + i * wpl;
1922  memcpy(buffer, line, bpl);
1923  for (j = 0; j < w; j++)
1924  line[j] = buffer[w - 1 - j];
1925  }
1926  LEPT_FREE(buffer);
1927  return fpixd;
1928 }
1929 
1930 
1951 FPIX *
1953  FPIX *fpixs)
1954 {
1955 l_int32 i, k, h, h2, wpl, bpl;
1956 l_float32 *linet, *lineb, *data, *buffer;
1957 
1958  PROCNAME("fpixFlipTB");
1959 
1960  if (!fpixs)
1961  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1962 
1963  /* Prepare fpixd for in-place operation */
1964  if (!fpixd)
1965  fpixd = fpixCopy(fpixs);
1966 
1967  data = fpixGetData(fpixd);
1968  wpl = fpixGetWpl(fpixd);
1969  fpixGetDimensions(fpixd, NULL, &h);
1970  buffer = (l_float32 *)LEPT_CALLOC(wpl, sizeof(l_float32));
1971  h2 = h / 2;
1972  bpl = 4 * wpl;
1973  for (i = 0, k = h - 1; i < h2; i++, k--) {
1974  linet = data + i * wpl;
1975  lineb = data + k * wpl;
1976  memcpy(buffer, linet, bpl);
1977  memcpy(linet, lineb, bpl);
1978  memcpy(lineb, buffer, bpl);
1979  }
1980  LEPT_FREE(buffer);
1981  return fpixd;
1982 }
1983 
1984 
1985 /*--------------------------------------------------------------------*
1986  * Affine and projective interpolated transforms *
1987  *--------------------------------------------------------------------*/
2010 FPIX *
2012  PTA *ptad,
2013  PTA *ptas,
2014  l_int32 border,
2015  l_float32 inval)
2016 {
2017 l_float32 *vc;
2018 PTA *ptas2, *ptad2;
2019 FPIX *fpixs2, *fpixd, *fpixd2;
2020 
2021  PROCNAME("fpixAffinePta");
2022 
2023  if (!fpixs)
2024  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2025  if (!ptas)
2026  return (FPIX *)ERROR_PTR("ptas not defined", procName, NULL);
2027  if (!ptad)
2028  return (FPIX *)ERROR_PTR("ptad not defined", procName, NULL);
2029 
2030  /* If a border is to be added, also translate the ptas */
2031  if (border > 0) {
2032  ptas2 = ptaTransform(ptas, border, border, 1.0, 1.0);
2033  ptad2 = ptaTransform(ptad, border, border, 1.0, 1.0);
2034  fpixs2 = fpixAddSlopeBorder(fpixs, border, border, border, border);
2035  } else {
2036  ptas2 = ptaClone(ptas);
2037  ptad2 = ptaClone(ptad);
2038  fpixs2 = fpixClone(fpixs);
2039  }
2040 
2041  /* Get backwards transform from dest to src, and apply it */
2042  getAffineXformCoeffs(ptad2, ptas2, &vc);
2043  fpixd2 = fpixAffine(fpixs2, vc, inval);
2044  fpixDestroy(&fpixs2);
2045  ptaDestroy(&ptas2);
2046  ptaDestroy(&ptad2);
2047  LEPT_FREE(vc);
2048 
2049  if (border == 0)
2050  return fpixd2;
2051 
2052  /* Remove the added border */
2053  fpixd = fpixRemoveBorder(fpixd2, border, border, border, border);
2054  fpixDestroy(&fpixd2);
2055  return fpixd;
2056 }
2057 
2058 
2067 FPIX *
2069  l_float32 *vc,
2070  l_float32 inval)
2071 {
2072 l_int32 i, j, w, h, wpld;
2073 l_float32 val;
2074 l_float32 *datas, *datad, *lined;
2075 l_float32 x, y;
2076 FPIX *fpixd;
2077 
2078  PROCNAME("fpixAffine");
2079 
2080  if (!fpixs)
2081  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2082  fpixGetDimensions(fpixs, &w, &h);
2083  if (!vc)
2084  return (FPIX *)ERROR_PTR("vc not defined", procName, NULL);
2085 
2086  datas = fpixGetData(fpixs);
2087  fpixd = fpixCreateTemplate(fpixs);
2088  fpixSetAllArbitrary(fpixd, inval);
2089  datad = fpixGetData(fpixd);
2090  wpld = fpixGetWpl(fpixd);
2091 
2092  /* Iterate over destination pixels */
2093  for (i = 0; i < h; i++) {
2094  lined = datad + i * wpld;
2095  for (j = 0; j < w; j++) {
2096  /* Compute float src pixel location corresponding to (i,j) */
2097  affineXformPt(vc, j, i, &x, &y);
2098  linearInterpolatePixelFloat(datas, w, h, x, y, inval, &val);
2099  *(lined + j) = val;
2100  }
2101  }
2102 
2103  return fpixd;
2104 }
2105 
2106 
2129 FPIX *
2131  PTA *ptad,
2132  PTA *ptas,
2133  l_int32 border,
2134  l_float32 inval)
2135 {
2136 l_float32 *vc;
2137 PTA *ptas2, *ptad2;
2138 FPIX *fpixs2, *fpixd, *fpixd2;
2139 
2140  PROCNAME("fpixProjectivePta");
2141 
2142  if (!fpixs)
2143  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2144  if (!ptas)
2145  return (FPIX *)ERROR_PTR("ptas not defined", procName, NULL);
2146  if (!ptad)
2147  return (FPIX *)ERROR_PTR("ptad not defined", procName, NULL);
2148 
2149  /* If a border is to be added, also translate the ptas */
2150  if (border > 0) {
2151  ptas2 = ptaTransform(ptas, border, border, 1.0, 1.0);
2152  ptad2 = ptaTransform(ptad, border, border, 1.0, 1.0);
2153  fpixs2 = fpixAddSlopeBorder(fpixs, border, border, border, border);
2154  } else {
2155  ptas2 = ptaClone(ptas);
2156  ptad2 = ptaClone(ptad);
2157  fpixs2 = fpixClone(fpixs);
2158  }
2159 
2160  /* Get backwards transform from dest to src, and apply it */
2161  getProjectiveXformCoeffs(ptad2, ptas2, &vc);
2162  fpixd2 = fpixProjective(fpixs2, vc, inval);
2163  fpixDestroy(&fpixs2);
2164  ptaDestroy(&ptas2);
2165  ptaDestroy(&ptad2);
2166  LEPT_FREE(vc);
2167 
2168  if (border == 0)
2169  return fpixd2;
2170 
2171  /* Remove the added border */
2172  fpixd = fpixRemoveBorder(fpixd2, border, border, border, border);
2173  fpixDestroy(&fpixd2);
2174  return fpixd;
2175 }
2176 
2177 
2186 FPIX *
2188  l_float32 *vc,
2189  l_float32 inval)
2190 {
2191 l_int32 i, j, w, h, wpld;
2192 l_float32 val;
2193 l_float32 *datas, *datad, *lined;
2194 l_float32 x, y;
2195 FPIX *fpixd;
2196 
2197  PROCNAME("fpixProjective");
2198 
2199  if (!fpixs)
2200  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2201  fpixGetDimensions(fpixs, &w, &h);
2202  if (!vc)
2203  return (FPIX *)ERROR_PTR("vc not defined", procName, NULL);
2204 
2205  datas = fpixGetData(fpixs);
2206  fpixd = fpixCreateTemplate(fpixs);
2207  fpixSetAllArbitrary(fpixd, inval);
2208  datad = fpixGetData(fpixd);
2209  wpld = fpixGetWpl(fpixd);
2210 
2211  /* Iterate over destination pixels */
2212  for (i = 0; i < h; i++) {
2213  lined = datad + i * wpld;
2214  for (j = 0; j < w; j++) {
2215  /* Compute float src pixel location corresponding to (i,j) */
2216  projectiveXformPt(vc, j, i, &x, &y);
2217  linearInterpolatePixelFloat(datas, w, h, x, y, inval, &val);
2218  *(lined + j) = val;
2219  }
2220  }
2221 
2222  return fpixd;
2223 }
2224 
2225 
2244 l_ok
2246  l_int32 w,
2247  l_int32 h,
2248  l_float32 x,
2249  l_float32 y,
2250  l_float32 inval,
2251  l_float32 *pval)
2252 {
2253 l_int32 xpm, ypm, xp, yp, xf, yf;
2254 l_float32 v00, v01, v10, v11;
2255 l_float32 *lines;
2256 
2257  PROCNAME("linearInterpolatePixelFloat");
2258 
2259  if (!pval)
2260  return ERROR_INT("&val not defined", procName, 1);
2261  *pval = inval;
2262  if (!datas)
2263  return ERROR_INT("datas not defined", procName, 1);
2264 
2265  /* Skip if off the edge */
2266  if (x < 0.0 || y < 0.0 || x > w - 2.0 || y > h - 2.0)
2267  return 0;
2268 
2269  xpm = (l_int32)(16.0 * x + 0.5);
2270  ypm = (l_int32)(16.0 * y + 0.5);
2271  xp = xpm >> 4;
2272  yp = ypm >> 4;
2273  xf = xpm & 0x0f;
2274  yf = ypm & 0x0f;
2275 
2276 #if DEBUG
2277  if (xf < 0 || yf < 0)
2278  lept_stderr("xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
2279 #endif /* DEBUG */
2280 
2281  /* Interpolate by area weighting. */
2282  lines = datas + yp * w;
2283  v00 = (16.0 - xf) * (16.0 - yf) * (*(lines + xp));
2284  v10 = xf * (16.0 - yf) * (*(lines + xp + 1));
2285  v01 = (16.0 - xf) * yf * (*(lines + w + xp));
2286  v11 = (l_float32)(xf) * yf * (*(lines + w + xp + 1));
2287  *pval = (v00 + v01 + v10 + v11) / 256.0;
2288  return 0;
2289 }
2290 
2291 
2292 /*--------------------------------------------------------------------*
2293  * Thresholding to 1 bpp Pix *
2294  *--------------------------------------------------------------------*/
2308 PIX *
2310  l_float32 thresh)
2311 {
2312 l_int32 i, j, w, h, wpls, wpld;
2313 l_float32 *datas, *lines;
2314 l_uint32 *datad, *lined;
2315 PIX *pixd;
2316 
2317  PROCNAME("fpixThresholdToPix");
2318 
2319  if (!fpix)
2320  return (PIX *)ERROR_PTR("fpix not defined", procName, NULL);
2321 
2322  fpixGetDimensions(fpix, &w, &h);
2323  datas = fpixGetData(fpix);
2324  wpls = fpixGetWpl(fpix);
2325  pixd = pixCreate(w, h, 1);
2326  datad = pixGetData(pixd);
2327  wpld = pixGetWpl(pixd);
2328  for (i = 0; i < h; i++) {
2329  lines = datas + i * wpls;
2330  lined = datad + i * wpld;
2331  for (j = 0; j < w; j++) {
2332  if (lines[j] <= thresh)
2333  SET_DATA_BIT(lined, j);
2334  }
2335  }
2336 
2337  return pixd;
2338 }
2339 
2340 
2341 /*--------------------------------------------------------------------*
2342  * Generate function from components *
2343  *--------------------------------------------------------------------*/
2366 FPIX *
2368  l_float32 rnum,
2369  l_float32 gnum,
2370  l_float32 bnum,
2371  l_float32 rdenom,
2372  l_float32 gdenom,
2373  l_float32 bdenom)
2374 {
2375 l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, zerodenom, onedenom;
2376 l_float32 fnum, fdenom;
2377 l_uint32 *datas, *lines;
2378 l_float32 *datad, *lined, *recip;
2379 FPIX *fpixd;
2380 
2381  PROCNAME("pixComponentFunction");
2382 
2383  if (!pix || pixGetDepth(pix) != 32)
2384  return (FPIX *)ERROR_PTR("pix undefined or not 32 bpp", procName, NULL);
2385 
2386  pixGetDimensions(pix, &w, &h, NULL);
2387  datas = pixGetData(pix);
2388  wpls = pixGetWpl(pix);
2389  fpixd = fpixCreate(w, h);
2390  datad = fpixGetData(fpixd);
2391  wpld = fpixGetWpl(fpixd);
2392  zerodenom = (rdenom == 0.0 && gdenom == 0.0 && bdenom == 0.0) ? 1: 0;
2393  onedenom = ((rdenom == 1.0 && gdenom == 0.0 && bdenom == 0.0) ||
2394  (rdenom == 0.0 && gdenom == 1.0 && bdenom == 0.0) ||
2395  (rdenom == 0.0 && gdenom == 0.0 && bdenom == 1.0)) ? 1 : 0;
2396  recip = NULL;
2397  if (onedenom) {
2398  recip = (l_float32 *)LEPT_CALLOC(256, sizeof(l_float32));
2399  recip[0] = 256; /* arbitrary large number */
2400  for (i = 1; i < 256; i++)
2401  recip[i] = 1.0 / (l_float32)i;
2402  }
2403  for (i = 0; i < h; i++) {
2404  lines = datas + i * wpls;
2405  lined = datad + i * wpld;
2406  if (zerodenom) {
2407  for (j = 0; j < w; j++) {
2408  extractRGBValues(lines[j], &rval, &gval, &bval);
2409  lined[j] = rnum * rval + gnum * gval + bnum * bval;
2410  }
2411  } else if (onedenom && rdenom == 1.0) {
2412  for (j = 0; j < w; j++) {
2413  extractRGBValues(lines[j], &rval, &gval, &bval);
2414  lined[j]
2415  = recip[rval] * (rnum * rval + gnum * gval + bnum * bval);
2416  }
2417  } else if (onedenom && gdenom == 1.0) {
2418  for (j = 0; j < w; j++) {
2419  extractRGBValues(lines[j], &rval, &gval, &bval);
2420  lined[j]
2421  = recip[gval] * (rnum * rval + gnum * gval + bnum * bval);
2422  }
2423  } else if (onedenom && bdenom == 1.0) {
2424  for (j = 0; j < w; j++) {
2425  extractRGBValues(lines[j], &rval, &gval, &bval);
2426  lined[j]
2427  = recip[bval] * (rnum * rval + gnum * gval + bnum * bval);
2428  }
2429  } else { /* general case */
2430  for (j = 0; j < w; j++) {
2431  extractRGBValues(lines[j], &rval, &gval, &bval);
2432  fnum = rnum * rval + gnum * gval + bnum * bval;
2433  fdenom = rdenom * rval + gdenom * gval + bdenom * bval;
2434  lined[j] = (fdenom == 0) ? 256.0 * fnum : fnum / fdenom;
2435  }
2436  }
2437  }
2438 
2439  LEPT_FREE(recip);
2440  return fpixd;
2441 }
l_ok fpixGetMax(FPIX *fpix, l_float32 *pmaxval, l_int32 *pxmaxloc, l_int32 *pymaxloc)
fpixGetMax()
Definition: fpix2.c:748
l_ok fpixCopyResolution(FPIX *fpixd, FPIX *fpixs)
fpixCopyResolution()
Definition: fpix1.c:497
DPIX * pixConvertToDPix(PIX *pixs, l_int32 ncomps)
pixConvertToDPix()
Definition: fpix2.c:223
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
Definition: pixconv.c:742
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
Definition: pixconv.c:328
l_ok dpixGetMax(DPIX *dpix, l_float64 *pmaxval, l_int32 *pxmaxloc, l_int32 *pymaxloc)
dpixGetMax()
Definition: fpix2.c:854
PIX * fpixThresholdToPix(FPIX *fpix, l_float32 thresh)
fpixThresholdToPix()
Definition: fpix2.c:2309
l_ok fpixGetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 *pval)
fpixGetPixel()
Definition: fpix1.c:563
DPIX * dpixCreate(l_int32 width, l_int32 height)
dpixCreate()
Definition: fpix1.c:1080
DPIX * dpixScaleByInteger(DPIX *dpixs, l_int32 factor)
dpixScaleByInteger()
Definition: fpix2.c:1013
l_ok affineXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
affineXformPt()
Definition: affine.c:1138
l_float64 * dpixGetData(DPIX *dpix)
dpixGetData()
Definition: fpix1.c:1441
FPIX * fpixAddContinuedBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddContinuedBorder()
Definition: fpix2.c:1522
PIX * dpixConvertToPix(DPIX *dpixs, l_int32 outdepth, l_int32 negvals, l_int32 errorflag)
dpixConvertToPix()
Definition: fpix2.c:543
FPIX * fpixAddMirroredBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddMirroredBorder()
Definition: fpix2.c:1475
l_int32 dpixGetWpl(DPIX *dpix)
dpixGetWpl()
Definition: fpix1.c:1298
DPIX * fpixConvertToDPix(FPIX *fpix)
fpixConvertToDPix()
Definition: fpix2.c:485
l_ok dpixSetAllArbitrary(DPIX *dpix, l_float64 inval)
dpixSetAllArbitrary()
Definition: fpix2.c:1356
void lept_stderr(const char *fmt,...)
lept_stderr()
Definition: utils1.c:306
#define GET_DATA_FOUR_BYTES(pdata, n)
Definition: arrayaccess.h:231
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
Definition: pix1.c:315
FPIX * fpixProjectivePta(FPIX *fpixs, PTA *ptad, PTA *ptas, l_int32 border, l_float32 inval)
fpixProjectivePta()
Definition: fpix2.c:2130
l_ok fpixAddMultConstant(FPIX *fpix, l_float32 addc, l_float32 multc)
fpixAddMultConstant()
Definition: fpix2.c:1164
l_ok fpixGetDimensions(FPIX *fpix, l_int32 *pw, l_int32 *ph)
fpixGetDimensions()
Definition: fpix1.c:329
l_uint32 * pixGetData(PIX *pix)
pixGetData()
Definition: pix1.c:1763
PIX * fpixConvertToPix(FPIX *fpixs, l_int32 outdepth, l_int32 negvals, l_int32 errorflag)
fpixConvertToPix()
Definition: fpix2.c:324
FPIX * fpixCopy(FPIX *fpixs)
fpixCopy()
Definition: fpix1.c:255
#define GET_DATA_BIT(pdata, n)
Definition: arrayaccess.h:123
l_ok fpixRasterop(FPIX *fpixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, FPIX *fpixs, l_int32 sx, l_int32 sy)
fpixRasterop()
Definition: fpix2.c:1656
l_ok fpixSetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 val)
fpixSetPixel()
Definition: fpix1.c:600
FPIX * fpixAffinePta(FPIX *fpixs, PTA *ptad, PTA *ptas, l_int32 border, l_float32 inval)
fpixAffinePta()
Definition: fpix2.c:2011
PIX * fpixDisplayMaxDynamicRange(FPIX *fpixs)
fpixDisplayMaxDynamicRange()
Definition: fpix2.c:428
FPIX * fpixAddSlopeBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddSlopeBorder()
Definition: fpix2.c:1567
FPIX * fpixAffine(FPIX *fpixs, l_float32 *vc, l_float32 inval)
fpixAffine()
Definition: fpix2.c:2068
l_ok fpixGetMin(FPIX *fpix, l_float32 *pminval, l_int32 *pxminloc, l_int32 *pyminloc)
fpixGetMin()
Definition: fpix2.c:695
FPIX * pixComponentFunction(PIX *pix, l_float32 rnum, l_float32 gnum, l_float32 bnum, l_float32 rdenom, l_float32 gdenom, l_float32 bdenom)
pixComponentFunction()
Definition: fpix2.c:2367
FPIX * fpixLinearCombination(FPIX *fpixd, FPIX *fpixs1, FPIX *fpixs2, l_float32 a, l_float32 b)
fpixLinearCombination()
Definition: fpix2.c:1108
PTA * ptaClone(PTA *pta)
ptaClone()
Definition: ptabasic.c:297
FPIX * fpixFlipTB(FPIX *fpixd, FPIX *fpixs)
fpixFlipTB()
Definition: fpix2.c:1952
DPIX * dpixLinearCombination(DPIX *dpixd, DPIX *dpixs1, DPIX *dpixs2, l_float32 a, l_float32 b)
dpixLinearCombination()
Definition: fpix2.c:1222
l_ok projectiveXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
projectiveXformPt()
Definition: projective.c:912
FPIX * fpixRotateOrth(FPIX *fpixs, l_int32 quads)
fpixRotateOrth()
Definition: fpix2.c:1756
#define SET_DATA_BYTE(pdata, n, val)
Definition: arrayaccess.h:198
DPIX * dpixCopy(DPIX *dpixs)
dpixCopy()
Definition: fpix1.c:1177
#define GET_DATA_QBIT(pdata, n)
Definition: arrayaccess.h:164
l_ok dpixGetMin(DPIX *dpix, l_float64 *pminval, l_int32 *pxminloc, l_int32 *pyminloc)
dpixGetMin()
Definition: fpix2.c:801
l_ok dpixAddMultConstant(DPIX *dpix, l_float64 addc, l_float64 multc)
dpixAddMultConstant()
Definition: fpix2.c:1278
#define GET_DATA_BYTE(pdata, n)
Definition: arrayaccess.h:188
l_int32 fpixGetWpl(FPIX *fpix)
fpixGetWpl()
Definition: fpix1.c:376
FPIX * fpixClone(FPIX *fpix)
fpixClone()
Definition: fpix1.c:236
PIX * pixClone(PIX *pixs)
pixClone()
Definition: pix1.c:593
FPIX * fpixRotate90(FPIX *fpixs, l_int32 direction)
fpixRotate90()
Definition: fpix2.c:1832
l_ok getAffineXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getAffineXformCoeffs()
Definition: affine.c:933
void pixDestroy(PIX **ppix)
pixDestroy()
Definition: pix1.c:621
FPIX * fpixScaleByInteger(FPIX *fpixs, l_int32 factor)
fpixScaleByInteger()
Definition: fpix2.c:921
l_float32 * fpixGetData(FPIX *fpix)
fpixGetData()
Definition: fpix1.c:519
FPIX * fpixRotate180(FPIX *fpixd, FPIX *fpixs)
fpixRotate180()
Definition: fpix2.c:1799
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
Definition: pix1.c:1113
FPIX * pixConvertToFPix(PIX *pixs, l_int32 ncomps)
pixConvertToFPix()
Definition: fpix2.c:130
FPIX * dpixConvertToFPix(DPIX *dpix)
dpixConvertToFPix()
Definition: fpix2.c:647
l_ok getProjectiveXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getProjectiveXformCoeffs()
Definition: projective.c:778
l_ok dpixGetDimensions(DPIX *dpix, l_int32 *pw, l_int32 *ph)
dpixGetDimensions()
Definition: fpix1.c:1251
#define SET_DATA_FOUR_BYTES(pdata, n, val)
Definition: arrayaccess.h:235
FPIX * fpixCreateTemplate(FPIX *fpixs)
fpixCreateTemplate()
Definition: fpix1.c:206
FPIX * fpixCreate(l_int32 width, l_int32 height)
fpixCreate()
Definition: fpix1.c:156
#define GET_DATA_TWO_BYTES(pdata, n)
Definition: arrayaccess.h:212
#define GET_DATA_DIBIT(pdata, n)
Definition: arrayaccess.h:145
FPIX * fpixFlipLR(FPIX *fpixd, FPIX *fpixs)
pixFlipLR()
Definition: fpix2.c:1900
Definition: pix.h:138
void ptaDestroy(PTA **ppta)
ptaDestroy()
Definition: ptabasic.c:195
FPIX * fpixRemoveBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixRemoveBorder()
Definition: fpix2.c:1431
FPIX * fpixAddBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddBorder()
Definition: fpix2.c:1395
PTA * ptaTransform(PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
ptaTransform()
Definition: ptafunc1.c:740
l_ok fpixSetAllArbitrary(FPIX *fpix, l_float32 inval)
fpixSetAllArbitrary()
Definition: fpix2.c:1325
void fpixDestroy(FPIX **pfpix)
fpixDestroy()
Definition: fpix1.c:292
#define SET_DATA_TWO_BYTES(pdata, n, val)
Definition: arrayaccess.h:222
Definition: pix.h:609
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
Definition: pix2.c:2820
l_ok linearInterpolatePixelFloat(l_float32 *datas, l_int32 w, l_int32 h, l_float32 x, l_float32 y, l_float32 inval, l_float32 *pval)
linearInterpolatePixelFloat()
Definition: fpix2.c:2245
FPIX * fpixProjective(FPIX *fpixs, l_float32 *vc, l_float32 inval)
fpixProjective()
Definition: fpix2.c:2187
#define SET_DATA_BIT(pdata, n)
Definition: arrayaccess.h:127
Definition: pix.h:516
Definition: pix.h:578