Leptonica  1.73
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 
102 #include <string.h>
103 #include "allheaders.h"
104 
105 /*--------------------------------------------------------------------*
106  * FPix <--> Pix conversions *
107  *--------------------------------------------------------------------*/
123 FPIX *
125  l_int32 ncomps)
126 {
127 l_int32 w, h, d, i, j, val, wplt, wpld;
128 l_uint32 uval;
129 l_uint32 *datat, *linet;
130 l_float32 *datad, *lined;
131 PIX *pixt;
132 FPIX *fpixd;
133 
134  PROCNAME("pixConvertToFPix");
135 
136  if (!pixs)
137  return (FPIX *)ERROR_PTR("pixs not defined", procName, NULL);
138 
139  /* Convert to a single component */
140  if (pixGetColormap(pixs))
142  else if (pixGetDepth(pixs) == 32 && ncomps == 3)
143  pixt = pixConvertRGBToLuminance(pixs);
144  else
145  pixt = pixClone(pixs);
146  pixGetDimensions(pixt, &w, &h, &d);
147  if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32) {
148  pixDestroy(&pixt);
149  return (FPIX *)ERROR_PTR("invalid depth", procName, NULL);
150  }
151 
152  if ((fpixd = fpixCreate(w, h)) == NULL) {
153  pixDestroy(&pixt);
154  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
155  }
156  datat = pixGetData(pixt);
157  wplt = pixGetWpl(pixt);
158  datad = fpixGetData(fpixd);
159  wpld = fpixGetWpl(fpixd);
160  for (i = 0; i < h; i++) {
161  linet = datat + i * wplt;
162  lined = datad + i * wpld;
163  if (d == 1) {
164  for (j = 0; j < w; j++) {
165  val = GET_DATA_BIT(linet, j);
166  lined[j] = (l_float32)val;
167  }
168  } else if (d == 2) {
169  for (j = 0; j < w; j++) {
170  val = GET_DATA_DIBIT(linet, j);
171  lined[j] = (l_float32)val;
172  }
173  } else if (d == 4) {
174  for (j = 0; j < w; j++) {
175  val = GET_DATA_QBIT(linet, j);
176  lined[j] = (l_float32)val;
177  }
178  } else if (d == 8) {
179  for (j = 0; j < w; j++) {
180  val = GET_DATA_BYTE(linet, j);
181  lined[j] = (l_float32)val;
182  }
183  } else if (d == 16) {
184  for (j = 0; j < w; j++) {
185  val = GET_DATA_TWO_BYTES(linet, j);
186  lined[j] = (l_float32)val;
187  }
188  } else { /* d == 32 */
189  for (j = 0; j < w; j++) {
190  uval = GET_DATA_FOUR_BYTES(linet, j);
191  lined[j] = (l_float32)uval;
192  }
193  }
194  }
195 
196  pixDestroy(&pixt);
197  return fpixd;
198 }
199 
200 
216 DPIX *
218  l_int32 ncomps)
219 {
220 l_int32 w, h, d, i, j, val, wplt, wpld;
221 l_uint32 uval;
222 l_uint32 *datat, *linet;
223 l_float64 *datad, *lined;
224 PIX *pixt;
225 DPIX *dpixd;
226 
227  PROCNAME("pixConvertToDPix");
228 
229  if (!pixs)
230  return (DPIX *)ERROR_PTR("pixs not defined", procName, NULL);
231 
232  /* Convert to a single component */
233  if (pixGetColormap(pixs))
235  else if (pixGetDepth(pixs) == 32 && ncomps == 3)
236  pixt = pixConvertRGBToLuminance(pixs);
237  else
238  pixt = pixClone(pixs);
239  pixGetDimensions(pixt, &w, &h, &d);
240  if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32) {
241  pixDestroy(&pixt);
242  return (DPIX *)ERROR_PTR("invalid depth", procName, NULL);
243  }
244 
245  if ((dpixd = dpixCreate(w, h)) == NULL) {
246  pixDestroy(&pixt);
247  return (DPIX *)ERROR_PTR("dpixd not made", procName, NULL);
248  }
249  datat = pixGetData(pixt);
250  wplt = pixGetWpl(pixt);
251  datad = dpixGetData(dpixd);
252  wpld = dpixGetWpl(dpixd);
253  for (i = 0; i < h; i++) {
254  linet = datat + i * wplt;
255  lined = datad + i * wpld;
256  if (d == 1) {
257  for (j = 0; j < w; j++) {
258  val = GET_DATA_BIT(linet, j);
259  lined[j] = (l_float64)val;
260  }
261  } else if (d == 2) {
262  for (j = 0; j < w; j++) {
263  val = GET_DATA_DIBIT(linet, j);
264  lined[j] = (l_float64)val;
265  }
266  } else if (d == 4) {
267  for (j = 0; j < w; j++) {
268  val = GET_DATA_QBIT(linet, j);
269  lined[j] = (l_float64)val;
270  }
271  } else if (d == 8) {
272  for (j = 0; j < w; j++) {
273  val = GET_DATA_BYTE(linet, j);
274  lined[j] = (l_float64)val;
275  }
276  } else if (d == 16) {
277  for (j = 0; j < w; j++) {
278  val = GET_DATA_TWO_BYTES(linet, j);
279  lined[j] = (l_float64)val;
280  }
281  } else { /* d == 32 */
282  for (j = 0; j < w; j++) {
283  uval = GET_DATA_FOUR_BYTES(linet, j);
284  lined[j] = (l_float64)uval;
285  }
286  }
287  }
288 
289  pixDestroy(&pixt);
290  return dpixd;
291 }
292 
293 
317 PIX *
319  l_int32 outdepth,
320  l_int32 negvals,
321  l_int32 errorflag)
322 {
323 l_int32 w, h, i, j, wpls, wpld;
324 l_uint32 vald, maxval;
325 l_float32 val;
326 l_float32 *datas, *lines;
327 l_uint32 *datad, *lined;
328 PIX *pixd;
329 
330  PROCNAME("fpixConvertToPix");
331 
332  if (!fpixs)
333  return (PIX *)ERROR_PTR("fpixs not defined", procName, NULL);
334  if (negvals != L_CLIP_TO_ZERO && negvals != L_TAKE_ABSVAL)
335  return (PIX *)ERROR_PTR("invalid negvals", procName, NULL);
336  if (outdepth != 0 && outdepth != 8 && outdepth != 16 && outdepth != 32)
337  return (PIX *)ERROR_PTR("outdepth not in {0,8,16,32}", procName, NULL);
338 
339  fpixGetDimensions(fpixs, &w, &h);
340  datas = fpixGetData(fpixs);
341  wpls = fpixGetWpl(fpixs);
342 
343  /* Adaptive determination of output depth */
344  if (outdepth == 0) {
345  outdepth = 8;
346  for (i = 0; i < h && outdepth < 32; i++) {
347  lines = datas + i * wpls;
348  for (j = 0; j < w && outdepth < 32; j++) {
349  if (lines[j] > 65535.5)
350  outdepth = 32;
351  else if (lines[j] > 255.5)
352  outdepth = 16;
353  }
354  }
355  }
356  if (outdepth == 8)
357  maxval = 0xff;
358  else if (outdepth == 16)
359  maxval = 0xffff;
360  else /* outdepth == 32 */
361  maxval = 0xffffffff;
362 
363  /* Gather statistics if %errorflag = TRUE */
364  if (errorflag) {
365  l_int32 negs = 0;
366  l_int32 overvals = 0;
367  for (i = 0; i < h; i++) {
368  lines = datas + i * wpls;
369  for (j = 0; j < w; j++) {
370  val = lines[j];
371  if (val < 0.0)
372  negs++;
373  else if (val > maxval)
374  overvals++;
375  }
376  }
377  if (negs > 0)
378  L_ERROR("Number of negative values: %d\n", procName, negs);
379  if (overvals > 0)
380  L_ERROR("Number of too-large values: %d\n", procName, overvals);
381  }
382 
383  /* Make the pix and convert the data */
384  if ((pixd = pixCreate(w, h, outdepth)) == NULL)
385  return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
386  datad = pixGetData(pixd);
387  wpld = pixGetWpl(pixd);
388  for (i = 0; i < h; i++) {
389  lines = datas + i * wpls;
390  lined = datad + i * wpld;
391  for (j = 0; j < w; j++) {
392  val = lines[j];
393  if (val >= 0.0)
394  vald = (l_uint32)(val + 0.5);
395  else if (negvals == L_CLIP_TO_ZERO) /* and val < 0.0 */
396  vald = 0;
397  else
398  vald = (l_uint32)(-val + 0.5);
399  if (vald > maxval)
400  vald = maxval;
401 
402  if (outdepth == 8)
403  SET_DATA_BYTE(lined, j, vald);
404  else if (outdepth == 16)
405  SET_DATA_TWO_BYTES(lined, j, vald);
406  else /* outdepth == 32 */
407  SET_DATA_FOUR_BYTES(lined, j, vald);
408  }
409  }
410 
411  return pixd;
412 }
413 
414 
421 PIX *
423 {
424 l_uint8 dval;
425 l_int32 i, j, w, h, wpls, wpld;
426 l_float32 factor, sval, maxval;
427 l_float32 *lines, *datas;
428 l_uint32 *lined, *datad;
429 PIX *pixd;
430 
431  PROCNAME("fpixDisplayMaxDynamicRange");
432 
433  if (!fpixs)
434  return (PIX *)ERROR_PTR("fpixs not defined", procName, NULL);
435 
436  fpixGetDimensions(fpixs, &w, &h);
437  datas = fpixGetData(fpixs);
438  wpls = fpixGetWpl(fpixs);
439 
440  maxval = 0.0;
441  for (i = 0; i < h; i++) {
442  lines = datas + i * wpls;
443  for (j = 0; j < w; j++) {
444  sval = *(lines + j);
445  if (sval > maxval)
446  maxval = sval;
447  }
448  }
449 
450  pixd = pixCreate(w, h, 8);
451  if (maxval == 0.0)
452  return pixd; /* all pixels are 0 */
453 
454  datad = pixGetData(pixd);
455  wpld = pixGetWpl(pixd);
456  factor = 255. / maxval;
457  for (i = 0; i < h; i++) {
458  lines = datas + i * wpls;
459  lined = datad + i * wpld;
460  for (j = 0; j < w; j++) {
461  sval = *(lines + j);
462  if (sval < 0.0) sval = 0.0;
463  dval = (l_uint8)(factor * sval + 0.5);
464  SET_DATA_BYTE(lined, j, dval);
465  }
466  }
467 
468  return pixd;
469 }
470 
471 
478 DPIX *
480 {
481 l_int32 w, h, i, j, wpls, wpld;
482 l_float32 val;
483 l_float32 *datas, *lines;
484 l_float64 *datad, *lined;
485 DPIX *dpix;
486 
487  PROCNAME("fpixConvertToDPix");
488 
489  if (!fpix)
490  return (DPIX *)ERROR_PTR("fpix not defined", procName, NULL);
491 
492  fpixGetDimensions(fpix, &w, &h);
493  if ((dpix = dpixCreate(w, h)) == NULL)
494  return (DPIX *)ERROR_PTR("dpix not made", procName, NULL);
495 
496  datas = fpixGetData(fpix);
497  datad = dpixGetData(dpix);
498  wpls = fpixGetWpl(fpix);
499  wpld = dpixGetWpl(dpix); /* 8 byte words */
500  for (i = 0; i < h; i++) {
501  lines = datas + i * wpls;
502  lined = datad + i * wpld;
503  for (j = 0; j < w; j++) {
504  val = lines[j];
505  lined[j] = val;
506  }
507  }
508 
509  return dpix;
510 }
511 
512 
536 PIX *
538  l_int32 outdepth,
539  l_int32 negvals,
540  l_int32 errorflag)
541 {
542 l_int32 w, h, i, j, wpls, wpld, maxval;
543 l_uint32 vald;
544 l_float64 val;
545 l_float64 *datas, *lines;
546 l_uint32 *datad, *lined;
547 PIX *pixd;
548 
549  PROCNAME("dpixConvertToPix");
550 
551  if (!dpixs)
552  return (PIX *)ERROR_PTR("dpixs not defined", procName, NULL);
553  if (negvals != L_CLIP_TO_ZERO && negvals != L_TAKE_ABSVAL)
554  return (PIX *)ERROR_PTR("invalid negvals", procName, NULL);
555  if (outdepth != 0 && outdepth != 8 && outdepth != 16 && outdepth != 32)
556  return (PIX *)ERROR_PTR("outdepth not in {0,8,16,32}", procName, NULL);
557 
558  dpixGetDimensions(dpixs, &w, &h);
559  datas = dpixGetData(dpixs);
560  wpls = dpixGetWpl(dpixs);
561 
562  /* Adaptive determination of output depth */
563  if (outdepth == 0) {
564  outdepth = 8;
565  for (i = 0; i < h && outdepth < 32; i++) {
566  lines = datas + i * wpls;
567  for (j = 0; j < w && outdepth < 32; j++) {
568  if (lines[j] > 65535.5)
569  outdepth = 32;
570  else if (lines[j] > 255.5)
571  outdepth = 16;
572  }
573  }
574  }
575  maxval = 0xff;
576  if (outdepth == 16)
577  maxval = 0xffff;
578  else /* outdepth == 32 */
579  maxval = 0xffffffff;
580 
581  /* Gather statistics if %errorflag = TRUE */
582  if (errorflag) {
583  l_int32 negs = 0;
584  l_int32 overvals = 0;
585  for (i = 0; i < h; i++) {
586  lines = datas + i * wpls;
587  for (j = 0; j < w; j++) {
588  val = lines[j];
589  if (val < 0.0)
590  negs++;
591  else if (val > maxval)
592  overvals++;
593  }
594  }
595  if (negs > 0)
596  L_ERROR("Number of negative values: %d\n", procName, negs);
597  if (overvals > 0)
598  L_ERROR("Number of too-large values: %d\n", procName, overvals);
599  }
600 
601  /* Make the pix and convert the data */
602  if ((pixd = pixCreate(w, h, outdepth)) == NULL)
603  return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
604  datad = pixGetData(pixd);
605  wpld = pixGetWpl(pixd);
606  for (i = 0; i < h; i++) {
607  lines = datas + i * wpls;
608  lined = datad + i * wpld;
609  for (j = 0; j < w; j++) {
610  val = lines[j];
611  if (val >= 0.0) {
612  vald = (l_uint32)(val + 0.5);
613  } else { /* val < 0.0 */
614  if (negvals == L_CLIP_TO_ZERO)
615  vald = 0;
616  else
617  vald = (l_uint32)(-val + 0.5);
618  }
619  if (vald > maxval)
620  vald = maxval;
621  if (outdepth == 8)
622  SET_DATA_BYTE(lined, j, vald);
623  else if (outdepth == 16)
624  SET_DATA_TWO_BYTES(lined, j, vald);
625  else /* outdepth == 32 */
626  SET_DATA_FOUR_BYTES(lined, j, vald);
627  }
628  }
629 
630  return pixd;
631 }
632 
633 
640 FPIX *
642 {
643 l_int32 w, h, i, j, wpls, wpld;
644 l_float64 val;
645 l_float32 *datad, *lined;
646 l_float64 *datas, *lines;
647 FPIX *fpix;
648 
649  PROCNAME("dpixConvertToFPix");
650 
651  if (!dpix)
652  return (FPIX *)ERROR_PTR("dpix not defined", procName, NULL);
653 
654  dpixGetDimensions(dpix, &w, &h);
655  if ((fpix = fpixCreate(w, h)) == NULL)
656  return (FPIX *)ERROR_PTR("fpix not made", procName, NULL);
657 
658  datas = dpixGetData(dpix);
659  datad = fpixGetData(fpix);
660  wpls = dpixGetWpl(dpix); /* 8 byte words */
661  wpld = fpixGetWpl(fpix);
662  for (i = 0; i < h; i++) {
663  lines = datas + i * wpls;
664  lined = datad + i * wpld;
665  for (j = 0; j < w; j++) {
666  val = lines[j];
667  lined[j] = (l_float32)val;
668  }
669  }
670 
671  return fpix;
672 }
673 
674 
675 
676 /*--------------------------------------------------------------------*
677  * Min/max value *
678  *--------------------------------------------------------------------*/
688 l_int32
690  l_float32 *pminval,
691  l_int32 *pxminloc,
692  l_int32 *pyminloc)
693 {
694 l_int32 i, j, w, h, wpl, xminloc, yminloc;
695 l_float32 *data, *line;
696 l_float32 minval;
697 
698  PROCNAME("fpixGetMin");
699 
700  if (!pminval && !pxminloc && !pyminloc)
701  return ERROR_INT("no return val requested", procName, 1);
702  if (pminval) *pminval = 0.0;
703  if (pxminloc) *pxminloc = 0;
704  if (pyminloc) *pyminloc = 0;
705  if (!fpix)
706  return ERROR_INT("fpix not defined", procName, 1);
707 
708  minval = +1.0e20;
709  xminloc = 0;
710  yminloc = 0;
711  fpixGetDimensions(fpix, &w, &h);
712  data = fpixGetData(fpix);
713  wpl = fpixGetWpl(fpix);
714  for (i = 0; i < h; i++) {
715  line = data + i * wpl;
716  for (j = 0; j < w; j++) {
717  if (line[j] < minval) {
718  minval = line[j];
719  xminloc = j;
720  yminloc = i;
721  }
722  }
723  }
724 
725  if (pminval) *pminval = minval;
726  if (pxminloc) *pxminloc = xminloc;
727  if (pyminloc) *pyminloc = yminloc;
728  return 0;
729 }
730 
731 
741 l_int32
743  l_float32 *pmaxval,
744  l_int32 *pxmaxloc,
745  l_int32 *pymaxloc)
746 {
747 l_int32 i, j, w, h, wpl, xmaxloc, ymaxloc;
748 l_float32 *data, *line;
749 l_float32 maxval;
750 
751  PROCNAME("fpixGetMax");
752 
753  if (!pmaxval && !pxmaxloc && !pymaxloc)
754  return ERROR_INT("no return val requested", procName, 1);
755  if (pmaxval) *pmaxval = 0.0;
756  if (pxmaxloc) *pxmaxloc = 0;
757  if (pymaxloc) *pymaxloc = 0;
758  if (!fpix)
759  return ERROR_INT("fpix not defined", procName, 1);
760 
761  maxval = -1.0e20;
762  xmaxloc = 0;
763  ymaxloc = 0;
764  fpixGetDimensions(fpix, &w, &h);
765  data = fpixGetData(fpix);
766  wpl = fpixGetWpl(fpix);
767  for (i = 0; i < h; i++) {
768  line = data + i * wpl;
769  for (j = 0; j < w; j++) {
770  if (line[j] > maxval) {
771  maxval = line[j];
772  xmaxloc = j;
773  ymaxloc = i;
774  }
775  }
776  }
777 
778  if (pmaxval) *pmaxval = maxval;
779  if (pxmaxloc) *pxmaxloc = xmaxloc;
780  if (pymaxloc) *pymaxloc = ymaxloc;
781  return 0;
782 }
783 
784 
794 l_int32
796  l_float64 *pminval,
797  l_int32 *pxminloc,
798  l_int32 *pyminloc)
799 {
800 l_int32 i, j, w, h, wpl, xminloc, yminloc;
801 l_float64 *data, *line;
802 l_float64 minval;
803 
804  PROCNAME("dpixGetMin");
805 
806  if (!pminval && !pxminloc && !pyminloc)
807  return ERROR_INT("no return val requested", procName, 1);
808  if (pminval) *pminval = 0.0;
809  if (pxminloc) *pxminloc = 0;
810  if (pyminloc) *pyminloc = 0;
811  if (!dpix)
812  return ERROR_INT("dpix not defined", procName, 1);
813 
814  minval = +1.0e300;
815  xminloc = 0;
816  yminloc = 0;
817  dpixGetDimensions(dpix, &w, &h);
818  data = dpixGetData(dpix);
819  wpl = dpixGetWpl(dpix);
820  for (i = 0; i < h; i++) {
821  line = data + i * wpl;
822  for (j = 0; j < w; j++) {
823  if (line[j] < minval) {
824  minval = line[j];
825  xminloc = j;
826  yminloc = i;
827  }
828  }
829  }
830 
831  if (pminval) *pminval = minval;
832  if (pxminloc) *pxminloc = xminloc;
833  if (pyminloc) *pyminloc = yminloc;
834  return 0;
835 }
836 
837 
847 l_int32
849  l_float64 *pmaxval,
850  l_int32 *pxmaxloc,
851  l_int32 *pymaxloc)
852 {
853 l_int32 i, j, w, h, wpl, xmaxloc, ymaxloc;
854 l_float64 *data, *line;
855 l_float64 maxval;
856 
857  PROCNAME("dpixGetMax");
858 
859  if (!pmaxval && !pxmaxloc && !pymaxloc)
860  return ERROR_INT("no return val requested", procName, 1);
861  if (pmaxval) *pmaxval = 0.0;
862  if (pxmaxloc) *pxmaxloc = 0;
863  if (pymaxloc) *pymaxloc = 0;
864  if (!dpix)
865  return ERROR_INT("dpix not defined", procName, 1);
866 
867  maxval = -1.0e20;
868  xmaxloc = 0;
869  ymaxloc = 0;
870  dpixGetDimensions(dpix, &w, &h);
871  data = dpixGetData(dpix);
872  wpl = dpixGetWpl(dpix);
873  for (i = 0; i < h; i++) {
874  line = data + i * wpl;
875  for (j = 0; j < w; j++) {
876  if (line[j] > maxval) {
877  maxval = line[j];
878  xmaxloc = j;
879  ymaxloc = i;
880  }
881  }
882  }
883 
884  if (pmaxval) *pmaxval = maxval;
885  if (pxmaxloc) *pxmaxloc = xmaxloc;
886  if (pymaxloc) *pymaxloc = ymaxloc;
887  return 0;
888 }
889 
890 
891 /*--------------------------------------------------------------------*
892  * Special integer scaling *
893  *--------------------------------------------------------------------*/
914 FPIX *
916  l_int32 factor)
917 {
918 l_int32 i, j, k, m, ws, hs, wd, hd, wpls, wpld;
919 l_float32 val0, val1, val2, val3;
920 l_float32 *datas, *datad, *lines, *lined, *fract;
921 FPIX *fpixd;
922 
923  PROCNAME("fpixScaleByInteger");
924 
925  if (!fpixs)
926  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
927 
928  fpixGetDimensions(fpixs, &ws, &hs);
929  wd = factor * (ws - 1) + 1;
930  hd = factor * (hs - 1) + 1;
931  fpixd = fpixCreate(wd, hd);
932  datas = fpixGetData(fpixs);
933  datad = fpixGetData(fpixd);
934  wpls = fpixGetWpl(fpixs);
935  wpld = fpixGetWpl(fpixd);
936  fract = (l_float32 *)LEPT_CALLOC(factor, sizeof(l_float32));
937  for (i = 0; i < factor; i++)
938  fract[i] = i / (l_float32)factor;
939  for (i = 0; i < hs - 1; i++) {
940  lines = datas + i * wpls;
941  for (j = 0; j < ws - 1; j++) {
942  val0 = lines[j];
943  val1 = lines[j + 1];
944  val2 = lines[wpls + j];
945  val3 = lines[wpls + j + 1];
946  for (k = 0; k < factor; k++) { /* rows of sub-block */
947  lined = datad + (i * factor + k) * wpld;
948  for (m = 0; m < factor; m++) { /* cols of sub-block */
949  lined[j * factor + m] =
950  val0 * (1.0 - fract[m]) * (1.0 - fract[k]) +
951  val1 * fract[m] * (1.0 - fract[k]) +
952  val2 * (1.0 - fract[m]) * fract[k] +
953  val3 * fract[m] * fract[k];
954  }
955  }
956  }
957  }
958 
959  /* Do the right-most column of fpixd, skipping LR corner */
960  for (i = 0; i < hs - 1; i++) {
961  lines = datas + i * wpls;
962  val0 = lines[ws - 1];
963  val1 = lines[wpls + ws - 1];
964  for (k = 0; k < factor; k++) {
965  lined = datad + (i * factor + k) * wpld;
966  lined[wd - 1] = val0 * (1.0 - fract[k]) + val1 * fract[k];
967  }
968  }
969 
970  /* Do the bottom-most row of fpixd */
971  lines = datas + (hs - 1) * wpls;
972  lined = datad + (hd - 1) * wpld;
973  for (j = 0; j < ws - 1; j++) {
974  val0 = lines[j];
975  val1 = lines[j + 1];
976  for (m = 0; m < factor; m++)
977  lined[j * factor + m] = val0 * (1.0 - fract[m]) + val1 * fract[m];
978  lined[wd - 1] = lines[ws - 1]; /* LR corner */
979  }
980 
981  LEPT_FREE(fract);
982  return fpixd;
983 }
984 
985 
1006 DPIX *
1008  l_int32 factor)
1009 {
1010 l_int32 i, j, k, m, ws, hs, wd, hd, wpls, wpld;
1011 l_float64 val0, val1, val2, val3;
1012 l_float64 *datas, *datad, *lines, *lined, *fract;
1013 DPIX *dpixd;
1014 
1015  PROCNAME("dpixScaleByInteger");
1016 
1017  if (!dpixs)
1018  return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
1019 
1020  dpixGetDimensions(dpixs, &ws, &hs);
1021  wd = factor * (ws - 1) + 1;
1022  hd = factor * (hs - 1) + 1;
1023  dpixd = dpixCreate(wd, hd);
1024  datas = dpixGetData(dpixs);
1025  datad = dpixGetData(dpixd);
1026  wpls = dpixGetWpl(dpixs);
1027  wpld = dpixGetWpl(dpixd);
1028  fract = (l_float64 *)LEPT_CALLOC(factor, sizeof(l_float64));
1029  for (i = 0; i < factor; i++)
1030  fract[i] = i / (l_float64)factor;
1031  for (i = 0; i < hs - 1; i++) {
1032  lines = datas + i * wpls;
1033  for (j = 0; j < ws - 1; j++) {
1034  val0 = lines[j];
1035  val1 = lines[j + 1];
1036  val2 = lines[wpls + j];
1037  val3 = lines[wpls + j + 1];
1038  for (k = 0; k < factor; k++) { /* rows of sub-block */
1039  lined = datad + (i * factor + k) * wpld;
1040  for (m = 0; m < factor; m++) { /* cols of sub-block */
1041  lined[j * factor + m] =
1042  val0 * (1.0 - fract[m]) * (1.0 - fract[k]) +
1043  val1 * fract[m] * (1.0 - fract[k]) +
1044  val2 * (1.0 - fract[m]) * fract[k] +
1045  val3 * fract[m] * fract[k];
1046  }
1047  }
1048  }
1049  }
1050 
1051  /* Do the right-most column of dpixd, skipping LR corner */
1052  for (i = 0; i < hs - 1; i++) {
1053  lines = datas + i * wpls;
1054  val0 = lines[ws - 1];
1055  val1 = lines[wpls + ws - 1];
1056  for (k = 0; k < factor; k++) {
1057  lined = datad + (i * factor + k) * wpld;
1058  lined[wd - 1] = val0 * (1.0 - fract[k]) + val1 * fract[k];
1059  }
1060  }
1061 
1062  /* Do the bottom-most row of dpixd */
1063  lines = datas + (hs - 1) * wpls;
1064  lined = datad + (hd - 1) * wpld;
1065  for (j = 0; j < ws - 1; j++) {
1066  val0 = lines[j];
1067  val1 = lines[j + 1];
1068  for (m = 0; m < factor; m++)
1069  lined[j * factor + m] = val0 * (1.0 - fract[m]) + val1 * fract[m];
1070  lined[wd - 1] = lines[ws - 1]; /* LR corner */
1071  }
1072 
1073  LEPT_FREE(fract);
1074  return dpixd;
1075 }
1076 
1077 
1078 /*--------------------------------------------------------------------*
1079  * Arithmetic operations *
1080  *--------------------------------------------------------------------*/
1103 FPIX *
1105  FPIX *fpixs1,
1106  FPIX *fpixs2,
1107  l_float32 a,
1108  l_float32 b)
1109 {
1110 l_int32 i, j, ws, hs, w, h, wpls, wpld;
1111 l_float32 *datas, *datad, *lines, *lined;
1112 
1113  PROCNAME("fpixLinearCombination");
1114 
1115  if (!fpixs1)
1116  return (FPIX *)ERROR_PTR("fpixs1 not defined", procName, fpixd);
1117  if (!fpixs2)
1118  return (FPIX *)ERROR_PTR("fpixs2 not defined", procName, fpixd);
1119  if (fpixs1 == fpixs2)
1120  return (FPIX *)ERROR_PTR("fpixs1 == fpixs2", procName, fpixd);
1121  if (fpixs2 == fpixd)
1122  return (FPIX *)ERROR_PTR("fpixs2 == fpixd", procName, fpixd);
1123 
1124  if (fpixs1 != fpixd)
1125  fpixd = fpixCopy(fpixd, fpixs1);
1126 
1127  datas = fpixGetData(fpixs2);
1128  datad = fpixGetData(fpixd);
1129  wpls = fpixGetWpl(fpixs2);
1130  wpld = fpixGetWpl(fpixd);
1131  fpixGetDimensions(fpixs2, &ws, &hs);
1132  fpixGetDimensions(fpixd, &w, &h);
1133  w = L_MIN(ws, w);
1134  h = L_MIN(hs, h);
1135  for (i = 0; i < h; i++) {
1136  lines = datas + i * wpls;
1137  lined = datad + i * wpld;
1138  for (j = 0; j < w; j++)
1139  lined[j] = a * lined[j] + b * lines[j];
1140  }
1141 
1142  return fpixd;
1143 }
1144 
1145 
1162 l_int32
1164  l_float32 addc,
1165  l_float32 multc)
1166 {
1167 l_int32 i, j, w, h, wpl;
1168 l_float32 *line, *data;
1169 
1170  PROCNAME("fpixAddMultConstant");
1171 
1172  if (!fpix)
1173  return ERROR_INT("fpix not defined", procName, 1);
1174 
1175  if (addc == 0.0 && multc == 1.0)
1176  return 0;
1177 
1178  fpixGetDimensions(fpix, &w, &h);
1179  data = fpixGetData(fpix);
1180  wpl = fpixGetWpl(fpix);
1181  for (i = 0; i < h; i++) {
1182  line = data + i * wpl;
1183  if (addc == 0.0) {
1184  for (j = 0; j < w; j++)
1185  line[j] *= multc;
1186  } else if (multc == 1.0) {
1187  for (j = 0; j < w; j++)
1188  line[j] += addc;
1189  } else {
1190  for (j = 0; j < w; j++) {
1191  line[j] = multc * line[j] + addc;
1192  }
1193  }
1194  }
1195 
1196  return 0;
1197 }
1198 
1199 
1222 DPIX *
1224  DPIX *dpixs1,
1225  DPIX *dpixs2,
1226  l_float32 a,
1227  l_float32 b)
1228 {
1229 l_int32 i, j, ws, hs, w, h, wpls, wpld;
1230 l_float64 *datas, *datad, *lines, *lined;
1231 
1232  PROCNAME("dpixLinearCombination");
1233 
1234  if (!dpixs1)
1235  return (DPIX *)ERROR_PTR("dpixs1 not defined", procName, dpixd);
1236  if (!dpixs2)
1237  return (DPIX *)ERROR_PTR("dpixs2 not defined", procName, dpixd);
1238  if (dpixs1 == dpixs2)
1239  return (DPIX *)ERROR_PTR("dpixs1 == dpixs2", procName, dpixd);
1240  if (dpixs2 == dpixd)
1241  return (DPIX *)ERROR_PTR("dpixs2 == dpixd", procName, dpixd);
1242 
1243  if (dpixs1 != dpixd)
1244  dpixd = dpixCopy(dpixd, dpixs1);
1245 
1246  datas = dpixGetData(dpixs2);
1247  datad = dpixGetData(dpixd);
1248  wpls = dpixGetWpl(dpixs2);
1249  wpld = dpixGetWpl(dpixd);
1250  dpixGetDimensions(dpixs2, &ws, &hs);
1251  dpixGetDimensions(dpixd, &w, &h);
1252  w = L_MIN(ws, w);
1253  h = L_MIN(hs, h);
1254  for (i = 0; i < h; i++) {
1255  lines = datas + i * wpls;
1256  lined = datad + i * wpld;
1257  for (j = 0; j < w; j++)
1258  lined[j] = a * lined[j] + b * lines[j];
1259  }
1260 
1261  return dpixd;
1262 }
1263 
1264 
1281 l_int32
1283  l_float64 addc,
1284  l_float64 multc)
1285 {
1286 l_int32 i, j, w, h, wpl;
1287 l_float64 *line, *data;
1288 
1289  PROCNAME("dpixAddMultConstant");
1290 
1291  if (!dpix)
1292  return ERROR_INT("dpix not defined", procName, 1);
1293 
1294  if (addc == 0.0 && multc == 1.0)
1295  return 0;
1296 
1297  dpixGetDimensions(dpix, &w, &h);
1298  data = dpixGetData(dpix);
1299  wpl = dpixGetWpl(dpix);
1300  for (i = 0; i < h; i++) {
1301  line = data + i * wpl;
1302  if (addc == 0.0) {
1303  for (j = 0; j < w; j++)
1304  line[j] *= multc;
1305  } else if (multc == 1.0) {
1306  for (j = 0; j < w; j++)
1307  line[j] += addc;
1308  } else {
1309  for (j = 0; j < w; j++)
1310  line[j] = multc * line[j] + addc;
1311  }
1312  }
1313 
1314  return 0;
1315 }
1316 
1317 
1318 /*--------------------------------------------------------------------*
1319  * Set all *
1320  *--------------------------------------------------------------------*/
1328 l_int32
1330  l_float32 inval)
1331 {
1332 l_int32 i, j, w, h;
1333 l_float32 *data, *line;
1334 
1335  PROCNAME("fpixSetAllArbitrary");
1336 
1337  if (!fpix)
1338  return ERROR_INT("fpix not defined", procName, 1);
1339 
1340  fpixGetDimensions(fpix, &w, &h);
1341  data = fpixGetData(fpix);
1342  for (i = 0; i < h; i++) {
1343  line = data + i * w;
1344  for (j = 0; j < w; j++)
1345  *(line + j) = inval;
1346  }
1347 
1348  return 0;
1349 }
1350 
1351 
1359 l_int32
1361  l_float64 inval)
1362 {
1363 l_int32 i, j, w, h;
1364 l_float64 *data, *line;
1365 
1366  PROCNAME("dpixSetAllArbitrary");
1367 
1368  if (!dpix)
1369  return ERROR_INT("dpix not defined", procName, 1);
1370 
1371  dpixGetDimensions(dpix, &w, &h);
1372  data = dpixGetData(dpix);
1373  for (i = 0; i < h; i++) {
1374  line = data + i * w;
1375  for (j = 0; j < w; j++)
1376  *(line + j) = inval;
1377  }
1378 
1379  return 0;
1380 }
1381 
1382 
1383 /*--------------------------------------------------------------------*
1384  * Border functions *
1385  *--------------------------------------------------------------------*/
1398 FPIX *
1400  l_int32 left,
1401  l_int32 right,
1402  l_int32 top,
1403  l_int32 bot)
1404 {
1405 l_int32 ws, hs, wd, hd;
1406 FPIX *fpixd;
1407 
1408  PROCNAME("fpixAddBorder");
1409 
1410  if (!fpixs)
1411  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1412 
1413  if (left <= 0 && right <= 0 && top <= 0 && bot <= 0)
1414  return fpixCopy(NULL, fpixs);
1415  fpixGetDimensions(fpixs, &ws, &hs);
1416  wd = ws + left + right;
1417  hd = hs + top + bot;
1418  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1419  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1420 
1421  fpixCopyResolution(fpixd, fpixs);
1422  fpixRasterop(fpixd, left, top, ws, hs, fpixs, 0, 0);
1423  return fpixd;
1424 }
1425 
1426 
1434 FPIX *
1436  l_int32 left,
1437  l_int32 right,
1438  l_int32 top,
1439  l_int32 bot)
1440 {
1441 l_int32 ws, hs, wd, hd;
1442 FPIX *fpixd;
1443 
1444  PROCNAME("fpixRemoveBorder");
1445 
1446  if (!fpixs)
1447  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1448 
1449  if (left <= 0 && right <= 0 && top <= 0 && bot <= 0)
1450  return fpixCopy(NULL, fpixs);
1451  fpixGetDimensions(fpixs, &ws, &hs);
1452  wd = ws - left - right;
1453  hd = hs - top - bot;
1454  if (wd <= 0 || hd <= 0)
1455  return (FPIX *)ERROR_PTR("width & height not both > 0", procName, NULL);
1456  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1457  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1458 
1459  fpixCopyResolution(fpixd, fpixs);
1460  fpixRasterop(fpixd, 0, 0, wd, hd, fpixs, left, top);
1461  return fpixd;
1462 }
1463 
1464 
1465 
1478 FPIX *
1480  l_int32 left,
1481  l_int32 right,
1482  l_int32 top,
1483  l_int32 bot)
1484 {
1485 l_int32 i, j, w, h;
1486 FPIX *fpixd;
1487 
1488  PROCNAME("fpixAddMirroredBorder");
1489 
1490  if (!fpixs)
1491  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1492 
1493  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1494  fpixGetDimensions(fpixs, &w, &h);
1495  for (j = 0; j < left; j++)
1496  fpixRasterop(fpixd, left - 1 - j, top, 1, h,
1497  fpixd, left + j, top);
1498  for (j = 0; j < right; j++)
1499  fpixRasterop(fpixd, left + w + j, top, 1, h,
1500  fpixd, left + w - 1 - j, top);
1501  for (i = 0; i < top; i++)
1502  fpixRasterop(fpixd, 0, top - 1 - i, left + w + right, 1,
1503  fpixd, 0, top + i);
1504  for (i = 0; i < bot; i++)
1505  fpixRasterop(fpixd, 0, top + h + i, left + w + right, 1,
1506  fpixd, 0, top + h - 1 - i);
1507 
1508  return fpixd;
1509 }
1510 
1511 
1525 FPIX *
1527  l_int32 left,
1528  l_int32 right,
1529  l_int32 top,
1530  l_int32 bot)
1531 {
1532 l_int32 i, j, w, h;
1533 FPIX *fpixd;
1534 
1535  PROCNAME("fpixAddContinuedBorder");
1536 
1537  if (!fpixs)
1538  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1539 
1540  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1541  fpixGetDimensions(fpixs, &w, &h);
1542  for (j = 0; j < left; j++)
1543  fpixRasterop(fpixd, j, top, 1, h, fpixd, left, top);
1544  for (j = 0; j < right; j++)
1545  fpixRasterop(fpixd, left + w + j, top, 1, h, fpixd, left + w - 1, top);
1546  for (i = 0; i < top; i++)
1547  fpixRasterop(fpixd, 0, i, left + w + right, 1, fpixd, 0, top);
1548  for (i = 0; i < bot; i++)
1549  fpixRasterop(fpixd, 0, top + h + i, left + w + right, 1,
1550  fpixd, 0, top + h - 1);
1551 
1552  return fpixd;
1553 }
1554 
1555 
1570 FPIX *
1572  l_int32 left,
1573  l_int32 right,
1574  l_int32 top,
1575  l_int32 bot)
1576 {
1577 l_int32 i, j, w, h, fullw, fullh;
1578 l_float32 val1, val2, del;
1579 FPIX *fpixd;
1580 
1581  PROCNAME("fpixAddSlopeBorder");
1582 
1583  if (!fpixs)
1584  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1585 
1586  fpixd = fpixAddBorder(fpixs, left, right, top, bot);
1587  fpixGetDimensions(fpixs, &w, &h);
1588 
1589  /* Left */
1590  for (i = top; i < top + h; i++) {
1591  fpixGetPixel(fpixd, left, i, &val1);
1592  fpixGetPixel(fpixd, left + 1, i, &val2);
1593  del = val1 - val2;
1594  for (j = 0; j < left; j++)
1595  fpixSetPixel(fpixd, j, i, val1 + del * (left - j));
1596  }
1597 
1598  /* Right */
1599  fullw = left + w + right;
1600  for (i = top; i < top + h; i++) {
1601  fpixGetPixel(fpixd, left + w - 1, i, &val1);
1602  fpixGetPixel(fpixd, left + w - 2, i, &val2);
1603  del = val1 - val2;
1604  for (j = left + w; j < fullw; j++)
1605  fpixSetPixel(fpixd, j, i, val1 + del * (j - left - w + 1));
1606  }
1607 
1608  /* Top */
1609  for (j = 0; j < fullw; j++) {
1610  fpixGetPixel(fpixd, j, top, &val1);
1611  fpixGetPixel(fpixd, j, top + 1, &val2);
1612  del = val1 - val2;
1613  for (i = 0; i < top; i++)
1614  fpixSetPixel(fpixd, j, i, val1 + del * (top - i));
1615  }
1616 
1617  /* Bottom */
1618  fullh = top + h + bot;
1619  for (j = 0; j < fullw; j++) {
1620  fpixGetPixel(fpixd, j, top + h - 1, &val1);
1621  fpixGetPixel(fpixd, j, top + h - 2, &val2);
1622  del = val1 - val2;
1623  for (i = top + h; i < fullh; i++)
1624  fpixSetPixel(fpixd, j, i, val1 + del * (i - top - h + 1));
1625  }
1626 
1627  return fpixd;
1628 }
1629 
1630 
1631 /*--------------------------------------------------------------------*
1632  * Simple rasterop *
1633  *--------------------------------------------------------------------*/
1659 l_int32
1661  l_int32 dx,
1662  l_int32 dy,
1663  l_int32 dw,
1664  l_int32 dh,
1665  FPIX *fpixs,
1666  l_int32 sx,
1667  l_int32 sy)
1668 {
1669 l_int32 fsw, fsh, fdw, fdh, dhangw, shangw, dhangh, shangh;
1670 l_int32 i, j, wpls, wpld;
1671 l_float32 *datas, *datad, *lines, *lined;
1672 
1673  PROCNAME("fpixRasterop");
1674 
1675  if (!fpixs)
1676  return ERROR_INT("fpixs not defined", procName, 1);
1677  if (!fpixd)
1678  return ERROR_INT("fpixd not defined", procName, 1);
1679 
1680  /* -------------------------------------------------------- *
1681  * Clip to maximum rectangle with both src and dest *
1682  * -------------------------------------------------------- */
1683  fpixGetDimensions(fpixs, &fsw, &fsh);
1684  fpixGetDimensions(fpixd, &fdw, &fdh);
1685 
1686  /* First clip horizontally (sx, dx, dw) */
1687  if (dx < 0) {
1688  sx -= dx; /* increase sx */
1689  dw += dx; /* reduce dw */
1690  dx = 0;
1691  }
1692  if (sx < 0) {
1693  dx -= sx; /* increase dx */
1694  dw += sx; /* reduce dw */
1695  sx = 0;
1696  }
1697  dhangw = dx + dw - fdw; /* rect overhang of dest to right */
1698  if (dhangw > 0)
1699  dw -= dhangw; /* reduce dw */
1700  shangw = sx + dw - fsw; /* rect overhang of src to right */
1701  if (shangw > 0)
1702  dw -= shangw; /* reduce dw */
1703 
1704  /* Then clip vertically (sy, dy, dh) */
1705  if (dy < 0) {
1706  sy -= dy; /* increase sy */
1707  dh += dy; /* reduce dh */
1708  dy = 0;
1709  }
1710  if (sy < 0) {
1711  dy -= sy; /* increase dy */
1712  dh += sy; /* reduce dh */
1713  sy = 0;
1714  }
1715  dhangh = dy + dh - fdh; /* rect overhang of dest below */
1716  if (dhangh > 0)
1717  dh -= dhangh; /* reduce dh */
1718  shangh = sy + dh - fsh; /* rect overhang of src below */
1719  if (shangh > 0)
1720  dh -= shangh; /* reduce dh */
1721 
1722  /* if clipped entirely, quit */
1723  if ((dw <= 0) || (dh <= 0))
1724  return 0;
1725 
1726  /* -------------------------------------------------------- *
1727  * Copy block of data *
1728  * -------------------------------------------------------- */
1729  datas = fpixGetData(fpixs);
1730  datad = fpixGetData(fpixd);
1731  wpls = fpixGetWpl(fpixs);
1732  wpld = fpixGetWpl(fpixd);
1733  datas += sy * wpls + sx; /* at UL corner of block */
1734  datad += dy * wpld + dx; /* at UL corner of block */
1735  for (i = 0; i < dh; i++) {
1736  lines = datas + i * wpls;
1737  lined = datad + i * wpld;
1738  for (j = 0; j < dw; j++) {
1739  *lined = *lines;
1740  lines++;
1741  lined++;
1742  }
1743  }
1744 
1745  return 0;
1746 }
1747 
1748 
1749 /*--------------------------------------------------------------------*
1750  * Rotation by multiples of 90 degrees *
1751  *--------------------------------------------------------------------*/
1759 FPIX *
1761  l_int32 quads)
1762 {
1763  PROCNAME("fpixRotateOrth");
1764 
1765  if (!fpixs)
1766  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1767  if (quads < 0 || quads > 3)
1768  return (FPIX *)ERROR_PTR("quads not in {0,1,2,3}", procName, NULL);
1769 
1770  if (quads == 0)
1771  return fpixCopy(NULL, fpixs);
1772  else if (quads == 1)
1773  return fpixRotate90(fpixs, 1);
1774  else if (quads == 2)
1775  return fpixRotate180(NULL, fpixs);
1776  else /* quads == 3 */
1777  return fpixRotate90(fpixs, -1);
1778 }
1779 
1780 
1805 FPIX *
1807  FPIX *fpixs)
1808 {
1809  PROCNAME("fpixRotate180");
1810 
1811  if (!fpixs)
1812  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1813 
1814  /* Prepare pixd for in-place operation */
1815  if ((fpixd = fpixCopy(fpixd, fpixs)) == NULL)
1816  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1817 
1818  fpixFlipLR(fpixd, fpixd);
1819  fpixFlipTB(fpixd, fpixd);
1820  return fpixd;
1821 }
1822 
1823 
1838 FPIX *
1840  l_int32 direction)
1841 {
1842 l_int32 i, j, wd, hd, wpls, wpld;
1843 l_float32 *datas, *datad, *lines, *lined;
1844 FPIX *fpixd;
1845 
1846  PROCNAME("fpixRotate90");
1847 
1848  if (!fpixs)
1849  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1850  if (direction != 1 && direction != -1)
1851  return (FPIX *)ERROR_PTR("invalid direction", procName, NULL);
1852 
1853  fpixGetDimensions(fpixs, &hd, &wd);
1854  if ((fpixd = fpixCreate(wd, hd)) == NULL)
1855  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1856  fpixCopyResolution(fpixd, fpixs);
1857 
1858  datas = fpixGetData(fpixs);
1859  wpls = fpixGetWpl(fpixs);
1860  datad = fpixGetData(fpixd);
1861  wpld = fpixGetWpl(fpixd);
1862  if (direction == 1) { /* clockwise */
1863  for (i = 0; i < hd; i++) {
1864  lined = datad + i * wpld;
1865  lines = datas + (wd - 1) * wpls;
1866  for (j = 0; j < wd; j++) {
1867  lined[j] = lines[i];
1868  lines -= wpls;
1869  }
1870  }
1871  } else { /* ccw */
1872  for (i = 0; i < hd; i++) {
1873  lined = datad + i * wpld;
1874  lines = datas;
1875  for (j = 0; j < wd; j++) {
1876  lined[j] = lines[hd - 1 - i];
1877  lines += wpls;
1878  }
1879  }
1880  }
1881 
1882  return fpixd;
1883 }
1884 
1885 
1911 FPIX *
1913  FPIX *fpixs)
1914 {
1915 l_int32 i, j, w, h, wpl, bpl;
1916 l_float32 *line, *data, *buffer;
1917 
1918  PROCNAME("fpixFlipLR");
1919 
1920  if (!fpixs)
1921  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1922 
1923  fpixGetDimensions(fpixs, &w, &h);
1924 
1925  /* Prepare fpixd for in-place operation */
1926  if ((fpixd = fpixCopy(fpixd, fpixs)) == NULL)
1927  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1928 
1929  data = fpixGetData(fpixd);
1930  wpl = fpixGetWpl(fpixd); /* 4-byte words */
1931  bpl = 4 * wpl;
1932  if ((buffer = (l_float32 *)LEPT_CALLOC(wpl, sizeof(l_float32))) == NULL) {
1933  fpixDestroy(&fpixd);
1934  return (FPIX *)ERROR_PTR("buffer not made", procName, NULL);
1935  }
1936  for (i = 0; i < h; i++) {
1937  line = data + i * wpl;
1938  memcpy(buffer, line, bpl);
1939  for (j = 0; j < w; j++)
1940  line[j] = buffer[w - 1 - j];
1941  }
1942  LEPT_FREE(buffer);
1943  return fpixd;
1944 }
1945 
1946 
1972 FPIX *
1974  FPIX *fpixs)
1975 {
1976 l_int32 i, k, h, h2, wpl, bpl;
1977 l_float32 *linet, *lineb, *data, *buffer;
1978 
1979  PROCNAME("fpixFlipTB");
1980 
1981  if (!fpixs)
1982  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
1983 
1984  /* Prepare fpixd for in-place operation */
1985  if ((fpixd = fpixCopy(fpixd, fpixs)) == NULL)
1986  return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
1987 
1988  data = fpixGetData(fpixd);
1989  wpl = fpixGetWpl(fpixd);
1990  fpixGetDimensions(fpixd, NULL, &h);
1991  if ((buffer = (l_float32 *)LEPT_CALLOC(wpl, sizeof(l_float32))) == NULL) {
1992  fpixDestroy(&fpixd);
1993  return (FPIX *)ERROR_PTR("buffer not made", procName, NULL);
1994  }
1995  h2 = h / 2;
1996  bpl = 4 * wpl;
1997  for (i = 0, k = h - 1; i < h2; i++, k--) {
1998  linet = data + i * wpl;
1999  lineb = data + k * wpl;
2000  memcpy(buffer, linet, bpl);
2001  memcpy(linet, lineb, bpl);
2002  memcpy(lineb, buffer, bpl);
2003  }
2004  LEPT_FREE(buffer);
2005  return fpixd;
2006 }
2007 
2008 
2009 /*--------------------------------------------------------------------*
2010  * Affine and projective interpolated transforms *
2011  *--------------------------------------------------------------------*/
2034 FPIX *
2036  PTA *ptad,
2037  PTA *ptas,
2038  l_int32 border,
2039  l_float32 inval)
2040 {
2041 l_float32 *vc;
2042 PTA *ptas2, *ptad2;
2043 FPIX *fpixs2, *fpixd, *fpixd2;
2044 
2045  PROCNAME("fpixAffinePta");
2046 
2047  if (!fpixs)
2048  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2049  if (!ptas)
2050  return (FPIX *)ERROR_PTR("ptas not defined", procName, NULL);
2051  if (!ptad)
2052  return (FPIX *)ERROR_PTR("ptad not defined", procName, NULL);
2053 
2054  /* If a border is to be added, also translate the ptas */
2055  if (border > 0) {
2056  ptas2 = ptaTransform(ptas, border, border, 1.0, 1.0);
2057  ptad2 = ptaTransform(ptad, border, border, 1.0, 1.0);
2058  fpixs2 = fpixAddSlopeBorder(fpixs, border, border, border, border);
2059  } else {
2060  ptas2 = ptaClone(ptas);
2061  ptad2 = ptaClone(ptad);
2062  fpixs2 = fpixClone(fpixs);
2063  }
2064 
2065  /* Get backwards transform from dest to src, and apply it */
2066  getAffineXformCoeffs(ptad2, ptas2, &vc);
2067  fpixd2 = fpixAffine(fpixs2, vc, inval);
2068  fpixDestroy(&fpixs2);
2069  ptaDestroy(&ptas2);
2070  ptaDestroy(&ptad2);
2071  LEPT_FREE(vc);
2072 
2073  if (border == 0)
2074  return fpixd2;
2075 
2076  /* Remove the added border */
2077  fpixd = fpixRemoveBorder(fpixd2, border, border, border, border);
2078  fpixDestroy(&fpixd2);
2079  return fpixd;
2080 }
2081 
2082 
2091 FPIX *
2093  l_float32 *vc,
2094  l_float32 inval)
2095 {
2096 l_int32 i, j, w, h, wpld;
2097 l_float32 val;
2098 l_float32 *datas, *datad, *lined;
2099 l_float32 x, y;
2100 FPIX *fpixd;
2101 
2102  PROCNAME("fpixAffine");
2103 
2104  if (!fpixs)
2105  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2106  fpixGetDimensions(fpixs, &w, &h);
2107  if (!vc)
2108  return (FPIX *)ERROR_PTR("vc not defined", procName, NULL);
2109 
2110  datas = fpixGetData(fpixs);
2111  fpixd = fpixCreateTemplate(fpixs);
2112  fpixSetAllArbitrary(fpixd, inval);
2113  datad = fpixGetData(fpixd);
2114  wpld = fpixGetWpl(fpixd);
2115 
2116  /* Iterate over destination pixels */
2117  for (i = 0; i < h; i++) {
2118  lined = datad + i * wpld;
2119  for (j = 0; j < w; j++) {
2120  /* Compute float src pixel location corresponding to (i,j) */
2121  affineXformPt(vc, j, i, &x, &y);
2122  linearInterpolatePixelFloat(datas, w, h, x, y, inval, &val);
2123  *(lined + j) = val;
2124  }
2125  }
2126 
2127  return fpixd;
2128 }
2129 
2130 
2153 FPIX *
2155  PTA *ptad,
2156  PTA *ptas,
2157  l_int32 border,
2158  l_float32 inval)
2159 {
2160 l_float32 *vc;
2161 PTA *ptas2, *ptad2;
2162 FPIX *fpixs2, *fpixd, *fpixd2;
2163 
2164  PROCNAME("fpixProjectivePta");
2165 
2166  if (!fpixs)
2167  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2168  if (!ptas)
2169  return (FPIX *)ERROR_PTR("ptas not defined", procName, NULL);
2170  if (!ptad)
2171  return (FPIX *)ERROR_PTR("ptad not defined", procName, NULL);
2172 
2173  /* If a border is to be added, also translate the ptas */
2174  if (border > 0) {
2175  ptas2 = ptaTransform(ptas, border, border, 1.0, 1.0);
2176  ptad2 = ptaTransform(ptad, border, border, 1.0, 1.0);
2177  fpixs2 = fpixAddSlopeBorder(fpixs, border, border, border, border);
2178  } else {
2179  ptas2 = ptaClone(ptas);
2180  ptad2 = ptaClone(ptad);
2181  fpixs2 = fpixClone(fpixs);
2182  }
2183 
2184  /* Get backwards transform from dest to src, and apply it */
2185  getProjectiveXformCoeffs(ptad2, ptas2, &vc);
2186  fpixd2 = fpixProjective(fpixs2, vc, inval);
2187  fpixDestroy(&fpixs2);
2188  ptaDestroy(&ptas2);
2189  ptaDestroy(&ptad2);
2190  LEPT_FREE(vc);
2191 
2192  if (border == 0)
2193  return fpixd2;
2194 
2195  /* Remove the added border */
2196  fpixd = fpixRemoveBorder(fpixd2, border, border, border, border);
2197  fpixDestroy(&fpixd2);
2198  return fpixd;
2199 }
2200 
2201 
2210 FPIX *
2212  l_float32 *vc,
2213  l_float32 inval)
2214 {
2215 l_int32 i, j, w, h, wpld;
2216 l_float32 val;
2217 l_float32 *datas, *datad, *lined;
2218 l_float32 x, y;
2219 FPIX *fpixd;
2220 
2221  PROCNAME("fpixProjective");
2222 
2223  if (!fpixs)
2224  return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
2225  fpixGetDimensions(fpixs, &w, &h);
2226  if (!vc)
2227  return (FPIX *)ERROR_PTR("vc not defined", procName, NULL);
2228 
2229  datas = fpixGetData(fpixs);
2230  fpixd = fpixCreateTemplate(fpixs);
2231  fpixSetAllArbitrary(fpixd, inval);
2232  datad = fpixGetData(fpixd);
2233  wpld = fpixGetWpl(fpixd);
2234 
2235  /* Iterate over destination pixels */
2236  for (i = 0; i < h; i++) {
2237  lined = datad + i * wpld;
2238  for (j = 0; j < w; j++) {
2239  /* Compute float src pixel location corresponding to (i,j) */
2240  projectiveXformPt(vc, j, i, &x, &y);
2241  linearInterpolatePixelFloat(datas, w, h, x, y, inval, &val);
2242  *(lined + j) = val;
2243  }
2244  }
2245 
2246  return fpixd;
2247 }
2248 
2249 
2268 l_int32
2270  l_int32 w,
2271  l_int32 h,
2272  l_float32 x,
2273  l_float32 y,
2274  l_float32 inval,
2275  l_float32 *pval)
2276 {
2277 l_int32 xpm, ypm, xp, yp, xf, yf;
2278 l_float32 v00, v01, v10, v11;
2279 l_float32 *lines;
2280 
2281  PROCNAME("linearInterpolatePixelFloat");
2282 
2283  if (!pval)
2284  return ERROR_INT("&val not defined", procName, 1);
2285  *pval = inval;
2286  if (!datas)
2287  return ERROR_INT("datas not defined", procName, 1);
2288 
2289  /* Skip if off the edge */
2290  if (x < 0.0 || y < 0.0 || x > w - 2.0 || y > h - 2.0)
2291  return 0;
2292 
2293  xpm = (l_int32)(16.0 * x + 0.5);
2294  ypm = (l_int32)(16.0 * y + 0.5);
2295  xp = xpm >> 4;
2296  yp = ypm >> 4;
2297  xf = xpm & 0x0f;
2298  yf = ypm & 0x0f;
2299 
2300 #if DEBUG
2301  if (xf < 0 || yf < 0)
2302  fprintf(stderr, "xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
2303 #endif /* DEBUG */
2304 
2305  /* Interpolate by area weighting. */
2306  lines = datas + yp * w;
2307  v00 = (16.0 - xf) * (16.0 - yf) * (*(lines + xp));
2308  v10 = xf * (16.0 - yf) * (*(lines + xp + 1));
2309  v01 = (16.0 - xf) * yf * (*(lines + w + xp));
2310  v11 = (l_float32)(xf) * yf * (*(lines + w + xp + 1));
2311  *pval = (v00 + v01 + v10 + v11) / 256.0;
2312  return 0;
2313 }
2314 
2315 
2316 /*--------------------------------------------------------------------*
2317  * Thresholding to 1 bpp Pix *
2318  *--------------------------------------------------------------------*/
2332 PIX *
2334  l_float32 thresh)
2335 {
2336 l_int32 i, j, w, h, wpls, wpld;
2337 l_float32 *datas, *lines;
2338 l_uint32 *datad, *lined;
2339 PIX *pixd;
2340 
2341  PROCNAME("fpixThresholdToPix");
2342 
2343  if (!fpix)
2344  return (PIX *)ERROR_PTR("fpix not defined", procName, NULL);
2345 
2346  fpixGetDimensions(fpix, &w, &h);
2347  datas = fpixGetData(fpix);
2348  wpls = fpixGetWpl(fpix);
2349  pixd = pixCreate(w, h, 1);
2350  datad = pixGetData(pixd);
2351  wpld = pixGetWpl(pixd);
2352  for (i = 0; i < h; i++) {
2353  lines = datas + i * wpls;
2354  lined = datad + i * wpld;
2355  for (j = 0; j < w; j++) {
2356  if (lines[j] <= thresh)
2357  SET_DATA_BIT(lined, j);
2358  }
2359  }
2360 
2361  return pixd;
2362 }
2363 
2364 
2365 /*--------------------------------------------------------------------*
2366  * Generate function from components *
2367  *--------------------------------------------------------------------*/
2390 FPIX *
2392  l_float32 rnum,
2393  l_float32 gnum,
2394  l_float32 bnum,
2395  l_float32 rdenom,
2396  l_float32 gdenom,
2397  l_float32 bdenom)
2398 {
2399 l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, zerodenom, onedenom;
2400 l_float32 fnum, fdenom;
2401 l_uint32 *datas, *lines;
2402 l_float32 *datad, *lined, *recip;
2403 FPIX *fpixd;
2404 
2405  PROCNAME("pixComponentFunction");
2406 
2407  if (!pix || pixGetDepth(pix) != 32)
2408  return (FPIX *)ERROR_PTR("pix undefined or not 32 bpp", procName, NULL);
2409 
2410  pixGetDimensions(pix, &w, &h, NULL);
2411  datas = pixGetData(pix);
2412  wpls = pixGetWpl(pix);
2413  fpixd = fpixCreate(w, h);
2414  datad = fpixGetData(fpixd);
2415  wpld = fpixGetWpl(fpixd);
2416  zerodenom = (rdenom == 0.0 && gdenom == 0.0 && bdenom == 0.0) ? 1: 0;
2417  onedenom = ((rdenom == 1.0 && gdenom == 0.0 && bdenom == 0.0) ||
2418  (rdenom == 0.0 && gdenom == 1.0 && bdenom == 0.0) ||
2419  (rdenom == 0.0 && gdenom == 0.0 && bdenom == 1.0)) ? 1 : 0;
2420  recip = NULL;
2421  if (onedenom) {
2422  recip = (l_float32 *)LEPT_CALLOC(256, sizeof(l_float32));
2423  recip[0] = 256; /* arbitrary large number */
2424  for (i = 1; i < 256; i++)
2425  recip[i] = 1.0 / (l_float32)i;
2426  }
2427  for (i = 0; i < h; i++) {
2428  lines = datas + i * wpls;
2429  lined = datad + i * wpld;
2430  if (zerodenom) {
2431  for (j = 0; j < w; j++) {
2432  extractRGBValues(lines[j], &rval, &gval, &bval);
2433  lined[j] = rnum * rval + gnum * gval + bnum * bval;
2434  }
2435  } else if (onedenom && rdenom == 1.0) {
2436  for (j = 0; j < w; j++) {
2437  extractRGBValues(lines[j], &rval, &gval, &bval);
2438  lined[j]
2439  = recip[rval] * (rnum * rval + gnum * gval + bnum * bval);
2440  }
2441  } else if (onedenom && gdenom == 1.0) {
2442  for (j = 0; j < w; j++) {
2443  extractRGBValues(lines[j], &rval, &gval, &bval);
2444  lined[j]
2445  = recip[gval] * (rnum * rval + gnum * gval + bnum * bval);
2446  }
2447  } else if (onedenom && bdenom == 1.0) {
2448  for (j = 0; j < w; j++) {
2449  extractRGBValues(lines[j], &rval, &gval, &bval);
2450  lined[j]
2451  = recip[bval] * (rnum * rval + gnum * gval + bnum * bval);
2452  }
2453  } else { /* general case */
2454  for (j = 0; j < w; j++) {
2455  extractRGBValues(lines[j], &rval, &gval, &bval);
2456  fnum = rnum * rval + gnum * gval + bnum * bval;
2457  fdenom = rdenom * rval + gdenom * gval + bdenom * bval;
2458  lined[j] = (fdenom == 0) ? 256.0 * fnum : fnum / fdenom;
2459  }
2460  }
2461  }
2462 
2463  LEPT_FREE(recip);
2464  return fpixd;
2465 }
DPIX * pixConvertToDPix(PIX *pixs, l_int32 ncomps)
pixConvertToDPix()
Definition: fpix2.c:217
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
Definition: pixconv.c:733
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
Definition: pixconv.c:322
PIX * fpixThresholdToPix(FPIX *fpix, l_float32 thresh)
fpixThresholdToPix()
Definition: fpix2.c:2333
DPIX * dpixCreate(l_int32 width, l_int32 height)
dpixCreate()
Definition: fpix1.c:1149
l_int32 fpixGetMax(FPIX *fpix, l_float32 *pmaxval, l_int32 *pxmaxloc, l_int32 *pymaxloc)
fpixGetMax()
Definition: fpix2.c:742
DPIX * dpixScaleByInteger(DPIX *dpixs, l_int32 factor)
dpixScaleByInteger()
Definition: fpix2.c:1007
l_int32 fpixAddMultConstant(FPIX *fpix, l_float32 addc, l_float32 multc)
fpixAddMultConstant()
Definition: fpix2.c:1163
l_int32 fpixGetMin(FPIX *fpix, l_float32 *pminval, l_int32 *pxminloc, l_int32 *pyminloc)
fpixGetMin()
Definition: fpix2.c:689
l_int32 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:1660
l_float64 * dpixGetData(DPIX *dpix)
dpixGetData()
Definition: fpix1.c:1591
FPIX * fpixAddContinuedBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddContinuedBorder()
Definition: fpix2.c:1526
PIX * dpixConvertToPix(DPIX *dpixs, l_int32 outdepth, l_int32 negvals, l_int32 errorflag)
dpixConvertToPix()
Definition: fpix2.c:537
l_int32 dpixGetMin(DPIX *dpix, l_float64 *pminval, l_int32 *pxminloc, l_int32 *pyminloc)
dpixGetMin()
Definition: fpix2.c:795
FPIX * fpixAddMirroredBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddMirroredBorder()
Definition: fpix2.c:1479
l_int32 dpixGetWpl(DPIX *dpix)
dpixGetWpl()
Definition: fpix1.c:1448
DPIX * fpixConvertToDPix(FPIX *fpix)
fpixConvertToDPix()
Definition: fpix2.c:479
l_int32 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:2269
#define GET_DATA_FOUR_BYTES(pdata, n)
Definition: arrayaccess.h:225
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
Definition: pix1.c:302
FPIX * fpixProjectivePta(FPIX *fpixs, PTA *ptad, PTA *ptas, l_int32 border, l_float32 inval)
fpixProjectivePta()
Definition: fpix2.c:2154
l_uint32 * pixGetData(PIX *pix)
pixGetData()
Definition: pix1.c:1602
l_int32 dpixGetMax(DPIX *dpix, l_float64 *pmaxval, l_int32 *pxmaxloc, l_int32 *pymaxloc)
dpixGetMax()
Definition: fpix2.c:848
PIX * fpixConvertToPix(FPIX *fpixs, l_int32 outdepth, l_int32 negvals, l_int32 errorflag)
fpixConvertToPix()
Definition: fpix2.c:318
DPIX * dpixCopy(DPIX *dpixd, DPIX *dpixs)
dpixCopy()
Definition: fpix1.c:1273
#define GET_DATA_BIT(pdata, n)
Definition: arrayaccess.h:117
l_int32 fpixGetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 *pval)
fpixGetPixel()
Definition: fpix1.c:639
FPIX * fpixAffinePta(FPIX *fpixs, PTA *ptad, PTA *ptas, l_int32 border, l_float32 inval)
fpixAffinePta()
Definition: fpix2.c:2035
PIX * fpixDisplayMaxDynamicRange(FPIX *fpixs)
fpixDisplayMaxDynamicRange()
Definition: fpix2.c:422
FPIX * fpixAddSlopeBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddSlopeBorder()
Definition: fpix2.c:1571
FPIX * fpixAffine(FPIX *fpixs, l_float32 *vc, l_float32 inval)
fpixAffine()
Definition: fpix2.c:2092
l_int32 dpixGetDimensions(DPIX *dpix, l_int32 *pw, l_int32 *ph)
dpixGetDimensions()
Definition: fpix1.c:1401
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:2391
FPIX * fpixLinearCombination(FPIX *fpixd, FPIX *fpixs1, FPIX *fpixs2, l_float32 a, l_float32 b)
fpixLinearCombination()
Definition: fpix2.c:1104
PTA * ptaClone(PTA *pta)
ptaClone()
Definition: ptabasic.c:295
FPIX * fpixFlipTB(FPIX *fpixd, FPIX *fpixs)
fpixFlipTB()
Definition: fpix2.c:1973
DPIX * dpixLinearCombination(DPIX *dpixd, DPIX *dpixs1, DPIX *dpixs2, l_float32 a, l_float32 b)
dpixLinearCombination()
Definition: fpix2.c:1223
l_int32 getAffineXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getAffineXformCoeffs()
Definition: affine.c:931
FPIX * fpixRotateOrth(FPIX *fpixs, l_int32 quads)
fpixRotateOrth()
Definition: fpix2.c:1760
l_int32 fpixSetAllArbitrary(FPIX *fpix, l_float32 inval)
fpixSetAllArbitrary()
Definition: fpix2.c:1329
#define SET_DATA_BYTE(pdata, n, val)
Definition: arrayaccess.h:192
#define GET_DATA_QBIT(pdata, n)
Definition: arrayaccess.h:158
#define GET_DATA_BYTE(pdata, n)
Definition: arrayaccess.h:182
l_int32 fpixGetWpl(FPIX *fpix)
fpixGetWpl()
Definition: fpix1.c:456
FPIX * fpixClone(FPIX *fpix)
fpixClone()
Definition: fpix1.c:230
PIX * pixClone(PIX *pixs)
pixClone()
Definition: pix1.c:517
FPIX * fpixRotate90(FPIX *fpixs, l_int32 direction)
fpixRotate90()
Definition: fpix2.c:1839
void pixDestroy(PIX **ppix)
pixDestroy()
Definition: pix1.c:545
FPIX * fpixScaleByInteger(FPIX *fpixs, l_int32 factor)
fpixScaleByInteger()
Definition: fpix2.c:915
l_float32 * fpixGetData(FPIX *fpix)
fpixGetData()
Definition: fpix1.c:599
FPIX * fpixRotate180(FPIX *fpixd, FPIX *fpixs)
fpixRotate180()
Definition: fpix2.c:1806
l_int32 fpixCopyResolution(FPIX *fpixd, FPIX *fpixs)
fpixCopyResolution()
Definition: fpix1.c:577
l_int32 fpixGetDimensions(FPIX *fpix, l_int32 *pw, l_int32 *ph)
fpixGetDimensions()
Definition: fpix1.c:409
FPIX * pixConvertToFPix(PIX *pixs, l_int32 ncomps)
pixConvertToFPix()
Definition: fpix2.c:124
FPIX * dpixConvertToFPix(DPIX *dpix)
dpixConvertToFPix()
Definition: fpix2.c:641
l_int32 affineXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
affineXformPt()
Definition: affine.c:1139
#define SET_DATA_FOUR_BYTES(pdata, n, val)
Definition: arrayaccess.h:229
FPIX * fpixCreateTemplate(FPIX *fpixs)
fpixCreateTemplate()
Definition: fpix1.c:201
FPIX * fpixCreate(l_int32 width, l_int32 height)
fpixCreate()
Definition: fpix1.c:149
#define GET_DATA_TWO_BYTES(pdata, n)
Definition: arrayaccess.h:206
#define GET_DATA_DIBIT(pdata, n)
Definition: arrayaccess.h:139
l_int32 dpixSetAllArbitrary(DPIX *dpix, l_float64 inval)
dpixSetAllArbitrary()
Definition: fpix2.c:1360
FPIX * fpixFlipLR(FPIX *fpixd, FPIX *fpixs)
pixFlipLR()
Definition: fpix2.c:1912
Definition: pix.h:134
void ptaDestroy(PTA **ppta)
ptaDestroy()
Definition: ptabasic.c:191
FPIX * fpixRemoveBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixRemoveBorder()
Definition: fpix2.c:1435
FPIX * fpixCopy(FPIX *fpixd, FPIX *fpixs)
fpixCopy()
Definition: fpix1.c:273
FPIX * fpixAddBorder(FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
fpixAddBorder()
Definition: fpix2.c:1399
PTA * ptaTransform(PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
ptaTransform()
Definition: ptafunc1.c:720
l_int32 fpixSetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 val)
fpixSetPixel()
Definition: fpix1.c:674
l_int32 pixGetDimensions(PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
Definition: pix1.c:1052
l_int32 projectiveXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
projectiveXformPt()
Definition: projective.c:911
l_int32 getProjectiveXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getProjectiveXformCoeffs()
Definition: projective.c:775
void fpixDestroy(FPIX **pfpix)
fpixDestroy()
Definition: fpix1.c:370
l_int32 dpixAddMultConstant(DPIX *dpix, l_float64 addc, l_float64 multc)
dpixAddMultConstant()
Definition: fpix2.c:1282
#define SET_DATA_TWO_BYTES(pdata, n, val)
Definition: arrayaccess.h:216
Definition: pix.h:613
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
Definition: pix2.c:2725
FPIX * fpixProjective(FPIX *fpixs, l_float32 *vc, l_float32 inval)
fpixProjective()
Definition: fpix2.c:2211
#define SET_DATA_BIT(pdata, n)
Definition: arrayaccess.h:121
Definition: pix.h:517
Definition: pix.h:582