Leptonica  1.73
Image processing and image analysis suite
boxbasic.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 
132 #include <string.h>
133 #include "allheaders.h"
134 
135 static const l_int32 INITIAL_PTR_ARRAYSIZE = 20;
138 /*---------------------------------------------------------------------*
139  * Box creation, destruction and copy *
140  *---------------------------------------------------------------------*/
163 BOX *
164 boxCreate(l_int32 x,
165  l_int32 y,
166  l_int32 w,
167  l_int32 h)
168 {
169 BOX *box;
170 
171  PROCNAME("boxCreate");
172 
173  if (w < 0 || h < 0)
174  return (BOX *)ERROR_PTR("w and h not both >= 0", procName, NULL);
175  if (x < 0) { /* take part in +quad */
176  w = w + x;
177  x = 0;
178  if (w <= 0)
179  return (BOX *)ERROR_PTR("x < 0 and box off +quad", procName, NULL);
180  }
181  if (y < 0) { /* take part in +quad */
182  h = h + y;
183  y = 0;
184  if (h <= 0)
185  return (BOX *)ERROR_PTR("y < 0 and box off +quad", procName, NULL);
186  }
187 
188  if ((box = (BOX *)LEPT_CALLOC(1, sizeof(BOX))) == NULL)
189  return (BOX *)ERROR_PTR("box not made", procName, NULL);
190  boxSetGeometry(box, x, y, w, h);
191  box->refcount = 1;
192 
193  return box;
194 }
195 
196 
208 BOX *
209 boxCreateValid(l_int32 x,
210  l_int32 y,
211  l_int32 w,
212  l_int32 h)
213 {
214  PROCNAME("boxCreateValid");
215 
216  if (w <= 0 || h <= 0)
217  return (BOX *)ERROR_PTR("w and h not both > 0", procName, NULL);
218  return boxCreate(x, y, w, h);
219 }
220 
221 
228 BOX *
230 {
231 BOX *boxc;
232 
233  PROCNAME("boxCopy");
234 
235  if (!box)
236  return (BOX *)ERROR_PTR("box not defined", procName, NULL);
237 
238  boxc = boxCreate(box->x, box->y, box->w, box->h);
239 
240  return boxc;
241 }
242 
243 
250 BOX *
252 {
253 
254  PROCNAME("boxClone");
255 
256  if (!box)
257  return (BOX *)ERROR_PTR("box not defined", procName, NULL);
258 
259  boxChangeRefcount(box, 1);
260  return box;
261 }
262 
263 
276 void
278 {
279 BOX *box;
280 
281  PROCNAME("boxDestroy");
282 
283  if (pbox == NULL) {
284  L_WARNING("ptr address is null!\n", procName);
285  return;
286  }
287  if ((box = *pbox) == NULL)
288  return;
289 
290  boxChangeRefcount(box, -1);
291  if (boxGetRefcount(box) <= 0)
292  LEPT_FREE(box);
293  *pbox = NULL;
294  return;
295 }
296 
297 
298 /*---------------------------------------------------------------------*
299  * Box accessors *
300  *---------------------------------------------------------------------*/
308 l_int32
310  l_int32 *px,
311  l_int32 *py,
312  l_int32 *pw,
313  l_int32 *ph)
314 {
315  PROCNAME("boxGetGeometry");
316 
317  if (px) *px = 0;
318  if (py) *py = 0;
319  if (pw) *pw = 0;
320  if (ph) *ph = 0;
321  if (!box)
322  return ERROR_INT("box not defined", procName, 1);
323  if (px) *px = box->x;
324  if (py) *py = box->y;
325  if (pw) *pw = box->w;
326  if (ph) *ph = box->h;
327  return 0;
328 }
329 
330 
338 l_int32
340  l_int32 x,
341  l_int32 y,
342  l_int32 w,
343  l_int32 h)
344 {
345  PROCNAME("boxSetGeometry");
346 
347  if (!box)
348  return ERROR_INT("box not defined", procName, 1);
349  if (x != -1) box->x = x;
350  if (y != -1) box->y = y;
351  if (w != -1) box->w = w;
352  if (h != -1) box->h = h;
353  return 0;
354 }
355 
356 
369 l_int32
371  l_int32 *pl,
372  l_int32 *pr,
373  l_int32 *pt,
374  l_int32 *pb)
375 {
376 l_int32 x, y, w, h;
377 
378  PROCNAME("boxGetSideLocations");
379 
380  if (pl) *pl = 0;
381  if (pr) *pr = 0;
382  if (pt) *pt = 0;
383  if (pb) *pb = 0;
384  if (!box)
385  return ERROR_INT("box not defined", procName, 1);
386 
387  boxGetGeometry(box, &x, &y, &w, &h);
388  if (pl) *pl = x;
389  if (pr) *pr = x + w - 1;
390  if (pt) *pt = y;
391  if (pb) *pb = y + h - 1;
392  return 0;
393 }
394 
395 
403 l_int32
405  l_int32 l,
406  l_int32 r,
407  l_int32 t,
408  l_int32 b)
409 {
410 l_int32 x, y, w, h;
411 
412  PROCNAME("boxSetSideLocations");
413 
414  if (!box)
415  return ERROR_INT("box not defined", procName, 1);
416  x = (l != -1) ? l : box->x;
417  w = (r != -1) ? r - x + 1 : box->x + box->w - x;
418  y = (t != -1) ? t : box->y;
419  h = (b != -1) ? b - y + 1 : box->y + box->h - y;
420  boxSetGeometry(box, x, y, w, h);
421  return 0;
422 }
423 
424 
430 l_int32
432 {
433  PROCNAME("boxGetRefcount");
434 
435  if (!box)
436  return ERROR_INT("box not defined", procName, UNDEF);
437 
438  return box->refcount;
439 }
440 
447 l_int32
449  l_int32 delta)
450 {
451  PROCNAME("boxChangeRefcount");
452 
453  if (!box)
454  return ERROR_INT("box not defined", procName, 1);
455 
456  box->refcount += delta;
457  return 0;
458 }
459 
460 
468 l_int32
470  l_int32 *pvalid)
471 {
472  PROCNAME("boxIsValid");
473 
474  if (!pvalid)
475  return ERROR_INT("&valid not defined", procName, 1);
476  *pvalid = 0;
477  if (!box)
478  return ERROR_INT("box not defined", procName, 1);
479 
480  if (box->w > 0 && box->h > 0)
481  *pvalid = 1;
482  return 0;
483 }
484 
485 
486 /*---------------------------------------------------------------------*
487  * Boxa creation, destruction, copy, extension *
488  *---------------------------------------------------------------------*/
495 BOXA *
496 boxaCreate(l_int32 n)
497 {
498 BOXA *boxa;
499 
500  PROCNAME("boxaCreate");
501 
502  if (n <= 0)
504 
505  boxa = (BOXA *)LEPT_CALLOC(1, sizeof(BOXA));
506  boxa->n = 0;
507  boxa->nalloc = n;
508  boxa->refcount = 1;
509  if ((boxa->box = (BOX **)LEPT_CALLOC(n, sizeof(BOX *))) == NULL) {
510  boxaDestroy(&boxa);
511  return (BOXA *)ERROR_PTR("boxa ptrs not made", procName, NULL);
512  }
513  return boxa;
514 }
515 
516 
530 BOXA *
532  l_int32 copyflag)
533 {
534 l_int32 i;
535 BOX *boxc;
536 BOXA *boxac;
537 
538  PROCNAME("boxaCopy");
539 
540  if (!boxa)
541  return (BOXA *)ERROR_PTR("boxa not defined", procName, NULL);
542 
543  if (copyflag == L_CLONE) {
544  boxa->refcount++;
545  return boxa;
546  }
547 
548  if (copyflag != L_COPY && copyflag != L_COPY_CLONE)
549  return (BOXA *)ERROR_PTR("invalid copyflag", procName, NULL);
550 
551  if ((boxac = boxaCreate(boxa->nalloc)) == NULL)
552  return (BOXA *)ERROR_PTR("boxac not made", procName, NULL);
553  for (i = 0; i < boxa->n; i++) {
554  if (copyflag == L_COPY)
555  boxc = boxaGetBox(boxa, i, L_COPY);
556  else /* copy-clone */
557  boxc = boxaGetBox(boxa, i, L_CLONE);
558  boxaAddBox(boxac, boxc, L_INSERT);
559  }
560  return boxac;
561 }
562 
563 
576 void
578 {
579 l_int32 i;
580 BOXA *boxa;
581 
582  PROCNAME("boxaDestroy");
583 
584  if (pboxa == NULL) {
585  L_WARNING("ptr address is null!\n", procName);
586  return;
587  }
588 
589  if ((boxa = *pboxa) == NULL)
590  return;
591 
592  /* Decrement the ref count. If it is 0, destroy the boxa. */
593  boxa->refcount--;
594  if (boxa->refcount <= 0) {
595  for (i = 0; i < boxa->n; i++)
596  boxDestroy(&boxa->box[i]);
597  LEPT_FREE(boxa->box);
598  LEPT_FREE(boxa);
599  }
600 
601  *pboxa = NULL;
602  return;
603 }
604 
605 
614 l_int32
616  BOX *box,
617  l_int32 copyflag)
618 {
619 l_int32 n;
620 BOX *boxc;
621 
622  PROCNAME("boxaAddBox");
623 
624  if (!boxa)
625  return ERROR_INT("boxa not defined", procName, 1);
626  if (!box)
627  return ERROR_INT("box not defined", procName, 1);
628 
629  if (copyflag == L_INSERT)
630  boxc = box;
631  else if (copyflag == L_COPY)
632  boxc = boxCopy(box);
633  else if (copyflag == L_CLONE)
634  boxc = boxClone(box);
635  else
636  return ERROR_INT("invalid copyflag", procName, 1);
637  if (!boxc)
638  return ERROR_INT("boxc not made", procName, 1);
639 
640  n = boxaGetCount(boxa);
641  if (n >= boxa->nalloc)
642  boxaExtendArray(boxa);
643  boxa->box[n] = boxc;
644  boxa->n++;
645 
646  return 0;
647 }
648 
649 
661 l_int32
663 {
664  PROCNAME("boxaExtendArray");
665 
666  if (!boxa)
667  return ERROR_INT("boxa not defined", procName, 1);
668 
669  return boxaExtendArrayToSize(boxa, 2 * boxa->nalloc);
670 }
671 
672 
685 l_int32
687  l_int32 size)
688 {
689  PROCNAME("boxaExtendArrayToSize");
690 
691  if (!boxa)
692  return ERROR_INT("boxa not defined", procName, 1);
693 
694  if (size > boxa->nalloc) {
695  if ((boxa->box = (BOX **)reallocNew((void **)&boxa->box,
696  sizeof(BOX *) * boxa->nalloc,
697  size * sizeof(BOX *))) == NULL)
698  return ERROR_INT("new ptr array not returned", procName, 1);
699  boxa->nalloc = size;
700  }
701  return 0;
702 }
703 
704 
705 /*---------------------------------------------------------------------*
706  * Boxa accessors *
707  *---------------------------------------------------------------------*/
714 l_int32
716 {
717  PROCNAME("boxaGetCount");
718 
719  if (!boxa)
720  return ERROR_INT("boxa not defined", procName, 0);
721  return boxa->n;
722 }
723 
724 
731 l_int32
733 {
734 l_int32 n, i, w, h, count;
735 
736  PROCNAME("boxaGetValidCount");
737 
738  if (!boxa)
739  return ERROR_INT("boxa not defined", procName, 0);
740 
741  n = boxaGetCount(boxa);
742  for (i = 0, count = 0; i < n; i++) {
743  boxaGetBoxGeometry(boxa, i, NULL, NULL, &w, &h);
744  if (w > 0 && h > 0)
745  count++;
746  }
747  return count;
748 }
749 
750 
759 BOX *
761  l_int32 index,
762  l_int32 accessflag)
763 {
764  PROCNAME("boxaGetBox");
765 
766  if (!boxa)
767  return (BOX *)ERROR_PTR("boxa not defined", procName, NULL);
768  if (index < 0 || index >= boxa->n)
769  return (BOX *)ERROR_PTR("index not valid", procName, NULL);
770 
771  if (accessflag == L_COPY)
772  return boxCopy(boxa->box[index]);
773  else if (accessflag == L_CLONE)
774  return boxClone(boxa->box[index]);
775  else
776  return (BOX *)ERROR_PTR("invalid accessflag", procName, NULL);
777 }
778 
779 
798 BOX *
800  l_int32 index,
801  l_int32 accessflag)
802 {
803 l_int32 w, h;
804 BOX *box;
805 
806  PROCNAME("boxaGetValidBox");
807 
808  if (!boxa)
809  return (BOX *)ERROR_PTR("boxa not defined", procName, NULL);
810 
811  if ((box = boxaGetBox(boxa, index, accessflag)) == NULL)
812  return (BOX *)ERROR_PTR("box not returned", procName, NULL);
813  boxGetGeometry(box, NULL, NULL, &w, &h);
814  if (w <= 0 || h <= 0) /* not valid, but not necessarily an error */
815  boxDestroy(&box);
816  return box;
817 }
818 
819 
826 NUMA *
828 {
829 l_int32 i, n, w, h;
830 NUMA *na;
831 
832  PROCNAME("boxaFindInvalidBoxes");
833 
834  if (!boxa)
835  return (NUMA *)ERROR_PTR("boxa not defined", procName, NULL);
836 
837  n = boxaGetCount(boxa);
838  if (boxaGetValidCount(boxa) == n)
839  return NULL;
840 
841  na = numaMakeConstant(0, n);
842  for (i = 0; i < n; i++) {
843  boxaGetBoxGeometry(boxa, i, NULL, NULL, &w, &h);
844  if (w == 0 || h == 0)
845  numaSetValue(na, i, 1);
846  }
847  return na;
848 }
849 
850 
859 l_int32
861  l_int32 index,
862  l_int32 *px,
863  l_int32 *py,
864  l_int32 *pw,
865  l_int32 *ph)
866 {
867 BOX *box;
868 
869  PROCNAME("boxaGetBoxGeometry");
870 
871  if (px) *px = 0;
872  if (py) *py = 0;
873  if (pw) *pw = 0;
874  if (ph) *ph = 0;
875  if (!boxa)
876  return ERROR_INT("boxa not defined", procName, 1);
877  if (index < 0 || index >= boxa->n)
878  return ERROR_INT("index not valid", procName, 1);
879 
880  if ((box = boxaGetBox(boxa, index, L_CLONE)) == NULL)
881  return ERROR_INT("box not found!", procName, 1);
882  boxGetGeometry(box, px, py, pw, ph);
883  boxDestroy(&box);
884  return 0;
885 }
886 
887 
895 l_int32
897  l_int32 *pfull)
898 {
899 l_int32 i, n, full;
900 BOX *box;
901 
902  PROCNAME("boxaIsFull");
903 
904  if (!pfull)
905  return ERROR_INT("&full not defined", procName, 1);
906  *pfull = 0;
907  if (!boxa)
908  return ERROR_INT("boxa not defined", procName, 1);
909 
910  n = boxaGetCount(boxa);
911  full = 1;
912  for (i = 0; i < n; i++) {
913  if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL) {
914  full = 0;
915  break;
916  }
917  boxDestroy(&box);
918  }
919  *pfull = full;
920  return 0;
921 }
922 
923 
924 /*---------------------------------------------------------------------*
925  * Boxa array modifiers *
926  *---------------------------------------------------------------------*/
941 l_int32
943  l_int32 index,
944  BOX *box)
945 {
946  PROCNAME("boxaReplaceBox");
947 
948  if (!boxa)
949  return ERROR_INT("boxa not defined", procName, 1);
950  if (index < 0 || index >= boxa->n)
951  return ERROR_INT("index not valid", procName, 1);
952  if (!box)
953  return ERROR_INT("box not defined", procName, 1);
954 
955  boxDestroy(&(boxa->box[index]));
956  boxa->box[index] = box;
957  return 0;
958 }
959 
960 
979 l_int32
981  l_int32 index,
982  BOX *box)
983 {
984 l_int32 i, n;
985 BOX **array;
986 
987  PROCNAME("boxaInsertBox");
988 
989  if (!boxa)
990  return ERROR_INT("boxa not defined", procName, 1);
991  n = boxaGetCount(boxa);
992  if (index < 0 || index > n)
993  return ERROR_INT("index not in {0...n}", procName, 1);
994  if (!box)
995  return ERROR_INT("box not defined", procName, 1);
996 
997  if (n >= boxa->nalloc)
998  boxaExtendArray(boxa);
999  array = boxa->box;
1000  boxa->n++;
1001  for (i = n; i > index; i--)
1002  array[i] = array[i - 1];
1003  array[index] = box;
1004 
1005  return 0;
1006 }
1007 
1008 
1024 l_int32
1026  l_int32 index)
1027 {
1028 l_int32 i, n;
1029 BOX **array;
1030 
1031  PROCNAME("boxaRemoveBox");
1032 
1033  if (!boxa)
1034  return ERROR_INT("boxa not defined", procName, 1);
1035  n = boxaGetCount(boxa);
1036  if (index < 0 || index >= n)
1037  return ERROR_INT("index not in {0...n - 1}", procName, 1);
1038 
1039  array = boxa->box;
1040  boxDestroy(&array[index]);
1041  for (i = index + 1; i < n; i++)
1042  array[i - 1] = array[i];
1043  array[n - 1] = NULL;
1044  boxa->n--;
1045 
1046  return 0;
1047 }
1048 
1049 
1066 l_int32
1068  l_int32 index,
1069  BOX **pbox)
1070 {
1071 l_int32 i, n;
1072 BOX **array;
1073 
1074  PROCNAME("boxaRemoveBoxAndSave");
1075 
1076  if (pbox) *pbox = NULL;
1077  if (!boxa)
1078  return ERROR_INT("boxa not defined", procName, 1);
1079  n = boxaGetCount(boxa);
1080  if (index < 0 || index >= n)
1081  return ERROR_INT("index not in {0...n - 1}", procName, 1);
1082 
1083  if (pbox)
1084  *pbox = boxaGetBox(boxa, index, L_CLONE);
1085  array = boxa->box;
1086  boxDestroy(&array[index]);
1087  for (i = index + 1; i < n; i++)
1088  array[i - 1] = array[i];
1089  array[n - 1] = NULL;
1090  boxa->n--;
1091 
1092  return 0;
1093 }
1094 
1095 
1108 BOXA *
1110  l_int32 copyflag)
1111 {
1112 l_int32 i, n;
1113 BOX *box;
1114 BOXA *boxad;
1115 
1116  PROCNAME("boxaSaveValid");
1117 
1118  if (!boxas)
1119  return (BOXA *)ERROR_PTR("boxas not defined", procName, NULL);
1120  if (copyflag != L_COPY && copyflag != L_CLONE)
1121  return (BOXA *)ERROR_PTR("invalid copyflag", procName, NULL);
1122 
1123  n = boxaGetCount(boxas);
1124  boxad = boxaCreate(n);
1125  for (i = 0; i < n; i++) {
1126  if ((box = boxaGetValidBox(boxas, i, copyflag)) != NULL)
1127  boxaAddBox(boxad, box, L_INSERT);
1128  }
1129 
1130  return boxad;
1131 }
1132 
1133 
1172 l_int32
1174  BOX *box)
1175 {
1176 l_int32 i, n;
1177 BOX *boxt;
1178 
1179  PROCNAME("boxaInitFull");
1180 
1181  if (!boxa)
1182  return ERROR_INT("boxa not defined", procName, 1);
1183 
1184  n = boxa->nalloc;
1185  boxa->n = n;
1186  for (i = 0; i < n; i++) {
1187  if (box)
1188  boxt = boxCopy(box);
1189  else
1190  boxt = boxCreate(0, 0, 0, 0);
1191  boxaReplaceBox(boxa, i, boxt);
1192  }
1193  return 0;
1194 }
1195 
1196 
1209 l_int32
1211 {
1212 l_int32 i, n;
1213 
1214  PROCNAME("boxaClear");
1215 
1216  if (!boxa)
1217  return ERROR_INT("boxa not defined", procName, 1);
1218 
1219  n = boxaGetCount(boxa);
1220  for (i = 0; i < n; i++)
1221  boxDestroy(&boxa->box[i]);
1222  boxa->n = 0;
1223  return 0;
1224 }
1225 
1226 
1227 /*--------------------------------------------------------------------------*
1228  * Boxaa creation, destruction *
1229  *--------------------------------------------------------------------------*/
1236 BOXAA *
1237 boxaaCreate(l_int32 n)
1238 {
1239 BOXAA *baa;
1240 
1241  PROCNAME("boxaaCreate");
1242 
1243  if (n <= 0)
1245 
1246  baa = (BOXAA *)LEPT_CALLOC(1, sizeof(BOXAA));
1247  if ((baa->boxa = (BOXA **)LEPT_CALLOC(n, sizeof(BOXA *))) == NULL) {
1248  boxaaDestroy(&baa);
1249  return (BOXAA *)ERROR_PTR("boxa ptr array not made", procName, NULL);
1250  }
1251  baa->nalloc = n;
1252  baa->n = 0;
1253  return baa;
1254 }
1255 
1256 
1271 BOXAA *
1273  l_int32 copyflag)
1274 {
1275 l_int32 i, n;
1276 BOXA *boxa;
1277 BOXAA *baad;
1278 
1279  PROCNAME("boxaaCopy");
1280 
1281  if (!baas)
1282  return (BOXAA *)ERROR_PTR("baas not defined", procName, NULL);
1283  if (copyflag != L_COPY && copyflag != L_CLONE)
1284  return (BOXAA *)ERROR_PTR("invalid copyflag", procName, NULL);
1285 
1286  n = boxaaGetCount(baas);
1287  baad = boxaaCreate(n);
1288  for (i = 0; i < n; i++) {
1289  boxa = boxaaGetBoxa(baas, i, copyflag);
1290  boxaaAddBoxa(baad, boxa, L_INSERT);
1291  }
1292 
1293  return baad;
1294 }
1295 
1296 
1302 void
1304 {
1305 l_int32 i;
1306 BOXAA *baa;
1307 
1308  PROCNAME("boxaaDestroy");
1309 
1310  if (pbaa == NULL) {
1311  L_WARNING("ptr address is NULL!\n", procName);
1312  return;
1313  }
1314 
1315  if ((baa = *pbaa) == NULL)
1316  return;
1317 
1318  for (i = 0; i < baa->n; i++)
1319  boxaDestroy(&baa->boxa[i]);
1320  LEPT_FREE(baa->boxa);
1321  LEPT_FREE(baa);
1322  *pbaa = NULL;
1323 
1324  return;
1325 }
1326 
1327 
1328 
1329 /*--------------------------------------------------------------------------*
1330  * Add Boxa to Boxaa *
1331  *--------------------------------------------------------------------------*/
1340 l_int32
1342  BOXA *ba,
1343  l_int32 copyflag)
1344 {
1345 l_int32 n;
1346 BOXA *bac;
1347 
1348  PROCNAME("boxaaAddBoxa");
1349 
1350  if (!baa)
1351  return ERROR_INT("baa not defined", procName, 1);
1352  if (!ba)
1353  return ERROR_INT("ba not defined", procName, 1);
1354  if (copyflag != L_INSERT && copyflag != L_COPY && copyflag != L_CLONE)
1355  return ERROR_INT("invalid copyflag", procName, 1);
1356 
1357  if (copyflag == L_INSERT)
1358  bac = ba;
1359  else
1360  bac = boxaCopy(ba, copyflag);
1361 
1362  n = boxaaGetCount(baa);
1363  if (n >= baa->nalloc)
1364  boxaaExtendArray(baa);
1365  baa->boxa[n] = bac;
1366  baa->n++;
1367  return 0;
1368 }
1369 
1370 
1377 l_int32
1379 {
1380 
1381  PROCNAME("boxaaExtendArray");
1382 
1383  if (!baa)
1384  return ERROR_INT("baa not defined", procName, 1);
1385 
1386  if ((baa->boxa = (BOXA **)reallocNew((void **)&baa->boxa,
1387  sizeof(BOXA *) * baa->nalloc,
1388  2 * sizeof(BOXA *) * baa->nalloc)) == NULL)
1389  return ERROR_INT("new ptr array not returned", procName, 1);
1390 
1391  baa->nalloc *= 2;
1392  return 0;
1393 }
1394 
1395 
1408 l_int32
1410  l_int32 size)
1411 {
1412  PROCNAME("boxaaExtendArrayToSize");
1413 
1414  if (!baa)
1415  return ERROR_INT("baa not defined", procName, 1);
1416 
1417  if (size > baa->nalloc) {
1418  if ((baa->boxa = (BOXA **)reallocNew((void **)&baa->boxa,
1419  sizeof(BOXA *) * baa->nalloc,
1420  size * sizeof(BOXA *))) == NULL)
1421  return ERROR_INT("new ptr array not returned", procName, 1);
1422  baa->nalloc = size;
1423  }
1424  return 0;
1425 }
1426 
1427 
1428 /*----------------------------------------------------------------------*
1429  * Boxaa accessors *
1430  *----------------------------------------------------------------------*/
1437 l_int32
1439 {
1440  PROCNAME("boxaaGetCount");
1441 
1442  if (!baa)
1443  return ERROR_INT("baa not defined", procName, 0);
1444  return baa->n;
1445 }
1446 
1447 
1454 l_int32
1456 {
1457 BOXA *boxa;
1458 l_int32 n, sum, i;
1459 
1460  PROCNAME("boxaaGetBoxCount");
1461 
1462  if (!baa)
1463  return ERROR_INT("baa not defined", procName, 0);
1464 
1465  n = boxaaGetCount(baa);
1466  for (sum = 0, i = 0; i < n; i++) {
1467  boxa = boxaaGetBoxa(baa, i, L_CLONE);
1468  sum += boxaGetCount(boxa);
1469  boxaDestroy(&boxa);
1470  }
1471 
1472  return sum;
1473 }
1474 
1475 
1484 BOXA *
1486  l_int32 index,
1487  l_int32 accessflag)
1488 {
1489 l_int32 n;
1490 
1491  PROCNAME("boxaaGetBoxa");
1492 
1493  if (!baa)
1494  return (BOXA *)ERROR_PTR("baa not defined", procName, NULL);
1495  n = boxaaGetCount(baa);
1496  if (index < 0 || index >= n)
1497  return (BOXA *)ERROR_PTR("index not valid", procName, NULL);
1498  if (accessflag != L_COPY && accessflag != L_CLONE)
1499  return (BOXA *)ERROR_PTR("invalid accessflag", procName, NULL);
1500 
1501  return boxaCopy(baa->boxa[index], accessflag);
1502 }
1503 
1504 
1514 BOX *
1516  l_int32 iboxa,
1517  l_int32 ibox,
1518  l_int32 accessflag)
1519 {
1520 BOX *box;
1521 BOXA *boxa;
1522 
1523  PROCNAME("boxaaGetBox");
1524 
1525  if ((boxa = boxaaGetBoxa(baa, iboxa, L_CLONE)) == NULL)
1526  return (BOX *)ERROR_PTR("boxa not retrieved", procName, NULL);
1527  if ((box = boxaGetBox(boxa, ibox, accessflag)) == NULL)
1528  L_ERROR("box not retrieved\n", procName);
1529  boxaDestroy(&boxa);
1530  return box;
1531 }
1532 
1533 
1534 /*----------------------------------------------------------------------*
1535  * Boxaa array modifiers *
1536  *----------------------------------------------------------------------*/
1566 l_int32
1568  BOXA *boxa)
1569 {
1570 l_int32 i, n;
1571 BOXA *boxat;
1572 
1573  PROCNAME("boxaaInitFull");
1574 
1575  if (!baa)
1576  return ERROR_INT("baa not defined", procName, 1);
1577  if (!boxa)
1578  return ERROR_INT("boxa not defined", procName, 1);
1579 
1580  n = baa->nalloc;
1581  baa->n = n;
1582  for (i = 0; i < n; i++) {
1583  boxat = boxaCopy(boxa, L_COPY);
1584  boxaaReplaceBoxa(baa, i, boxat);
1585  }
1586  return 0;
1587 }
1588 
1589 
1606 l_int32
1608  l_int32 maxindex,
1609  BOXA *boxa)
1610 {
1611 l_int32 i, n;
1612 
1613  PROCNAME("boxaaExtendWithInit");
1614 
1615  if (!baa)
1616  return ERROR_INT("baa not defined", procName, 1);
1617  if (!boxa)
1618  return ERROR_INT("boxa not defined", procName, 1);
1619 
1620  /* Extend the ptr array if necessary */
1621  n = boxaaGetCount(baa);
1622  if (maxindex < n) return 0;
1623  boxaaExtendArrayToSize(baa, maxindex + 1);
1624 
1625  /* Fill the new entries with copies of boxa */
1626  for (i = n; i <= maxindex; i++)
1627  boxaaAddBoxa(baa, boxa, L_COPY);
1628  return 0;
1629 }
1630 
1631 
1647 l_int32
1649  l_int32 index,
1650  BOXA *boxa)
1651 {
1652 l_int32 n;
1653 
1654  PROCNAME("boxaaReplaceBoxa");
1655 
1656  if (!baa)
1657  return ERROR_INT("baa not defined", procName, 1);
1658  if (!boxa)
1659  return ERROR_INT("boxa not defined", procName, 1);
1660  n = boxaaGetCount(baa);
1661  if (index < 0 || index >= n)
1662  return ERROR_INT("index not valid", procName, 1);
1663 
1664  boxaDestroy(&baa->boxa[index]);
1665  baa->boxa[index] = boxa;
1666  return 0;
1667 }
1668 
1669 
1688 l_int32
1690  l_int32 index,
1691  BOXA *boxa)
1692 {
1693 l_int32 i, n;
1694 BOXA **array;
1695 
1696  PROCNAME("boxaaInsertBoxa");
1697 
1698  if (!baa)
1699  return ERROR_INT("baa not defined", procName, 1);
1700  n = boxaaGetCount(baa);
1701  if (index < 0 || index > n)
1702  return ERROR_INT("index not in {0...n}", procName, 1);
1703  if (!boxa)
1704  return ERROR_INT("boxa not defined", procName, 1);
1705 
1706  if (n >= baa->nalloc)
1707  boxaaExtendArray(baa);
1708  array = baa->boxa;
1709  baa->n++;
1710  for (i = n; i > index; i--)
1711  array[i] = array[i - 1];
1712  array[index] = boxa;
1713 
1714  return 0;
1715 }
1716 
1717 
1734 l_int32
1736  l_int32 index)
1737 {
1738 l_int32 i, n;
1739 BOXA **array;
1740 
1741  PROCNAME("boxaaRemoveBox");
1742 
1743  if (!baa)
1744  return ERROR_INT("baa not defined", procName, 1);
1745  n = boxaaGetCount(baa);
1746  if (index < 0 || index >= n)
1747  return ERROR_INT("index not valid", procName, 1);
1748 
1749  array = baa->boxa;
1750  boxaDestroy(&array[index]);
1751  for (i = index + 1; i < n; i++)
1752  array[i - 1] = array[i];
1753  array[n - 1] = NULL;
1754  baa->n--;
1755 
1756  return 0;
1757 }
1758 
1759 
1774 l_int32
1776  l_int32 index,
1777  BOX *box,
1778  l_int32 accessflag)
1779 {
1780 l_int32 n;
1781 BOXA *boxa;
1782  PROCNAME("boxaaAddBox");
1783 
1784  if (!baa)
1785  return ERROR_INT("baa not defined", procName, 1);
1786  n = boxaaGetCount(baa);
1787  if (index < 0 || index >= n)
1788  return ERROR_INT("index not valid", procName, 1);
1789  if (accessflag != L_INSERT && accessflag != L_COPY && accessflag != L_CLONE)
1790  return ERROR_INT("invalid accessflag", procName, 1);
1791 
1792  boxa = boxaaGetBoxa(baa, index, L_CLONE);
1793  boxaAddBox(boxa, box, accessflag);
1794  boxaDestroy(&boxa);
1795  return 0;
1796 }
1797 
1798 
1799 /*---------------------------------------------------------------------*
1800  * Boxaa serialized I/O *
1801  *---------------------------------------------------------------------*/
1822 BOXAA *
1823 boxaaReadFromFiles(const char *dirname,
1824  const char *substr,
1825  l_int32 first,
1826  l_int32 nfiles)
1827 {
1828 char *fname;
1829 l_int32 i, n;
1830 BOXA *boxa;
1831 BOXAA *baa;
1832 SARRAY *sa;
1833 
1834  PROCNAME("boxaaReadFromFiles");
1835 
1836  if (!dirname)
1837  return (BOXAA *)ERROR_PTR("dirname not defined", procName, NULL);
1838 
1839  sa = getSortedPathnamesInDirectory(dirname, substr, first, nfiles);
1840  if (!sa || ((n = sarrayGetCount(sa)) == 0)) {
1841  sarrayDestroy(&sa);
1842  return (BOXAA *)ERROR_PTR("no pixa files found", procName, NULL);
1843  }
1844 
1845  baa = boxaaCreate(n);
1846  for (i = 0; i < n; i++) {
1847  fname = sarrayGetString(sa, i, L_NOCOPY);
1848  if ((boxa = boxaRead(fname)) == NULL) {
1849  L_ERROR("boxa not read for %d-th file", procName, i);
1850  continue;
1851  }
1852  boxaaAddBoxa(baa, boxa, L_INSERT);
1853  }
1854 
1855  sarrayDestroy(&sa);
1856  return baa;
1857 }
1858 
1859 
1866 BOXAA *
1867 boxaaRead(const char *filename)
1868 {
1869 FILE *fp;
1870 BOXAA *baa;
1871 
1872  PROCNAME("boxaaRead");
1873 
1874  if (!filename)
1875  return (BOXAA *)ERROR_PTR("filename not defined", procName, NULL);
1876 
1877  if ((fp = fopenReadStream(filename)) == NULL)
1878  return (BOXAA *)ERROR_PTR("stream not opened", procName, NULL);
1879  baa = boxaaReadStream(fp);
1880  fclose(fp);
1881  if (!baa)
1882  return (BOXAA *)ERROR_PTR("boxaa not read", procName, NULL);
1883  return baa;
1884 }
1885 
1886 
1893 BOXAA *
1895 {
1896 l_int32 n, i, x, y, w, h, version;
1897 l_int32 ignore;
1898 BOXA *boxa;
1899 BOXAA *baa;
1900 
1901  PROCNAME("boxaaReadStream");
1902 
1903  if (!fp)
1904  return (BOXAA *)ERROR_PTR("stream not defined", procName, NULL);
1905 
1906  if (fscanf(fp, "\nBoxaa Version %d\n", &version) != 1)
1907  return (BOXAA *)ERROR_PTR("not a boxaa file", procName, NULL);
1908  if (version != BOXAA_VERSION_NUMBER)
1909  return (BOXAA *)ERROR_PTR("invalid boxa version", procName, NULL);
1910  if (fscanf(fp, "Number of boxa = %d\n", &n) != 1)
1911  return (BOXAA *)ERROR_PTR("not a boxaa file", procName, NULL);
1912 
1913  if ((baa = boxaaCreate(n)) == NULL)
1914  return (BOXAA *)ERROR_PTR("boxaa not made", procName, NULL);
1915  for (i = 0; i < n; i++) {
1916  if (fscanf(fp, "\nBoxa[%d] extent: x = %d, y = %d, w = %d, h = %d",
1917  &ignore, &x, &y, &w, &h) != 5) {
1918  boxaaDestroy(&baa);
1919  return (BOXAA *)ERROR_PTR("boxa descr not valid", procName, NULL);
1920  }
1921  if ((boxa = boxaReadStream(fp)) == NULL) {
1922  boxaaDestroy(&baa);
1923  return (BOXAA *)ERROR_PTR("boxa not made", procName, NULL);
1924  }
1925  boxaaAddBoxa(baa, boxa, L_INSERT);
1926  }
1927  return baa;
1928 }
1929 
1930 
1938 BOXAA *
1939 boxaaReadMem(const l_uint8 *data,
1940  size_t size)
1941 {
1942 FILE *fp;
1943 BOXAA *baa;
1944 
1945  PROCNAME("boxaaReadMem");
1946 
1947  if (!data)
1948  return (BOXAA *)ERROR_PTR("data not defined", procName, NULL);
1949  if ((fp = fopenReadFromMemory(data, size)) == NULL)
1950  return (BOXAA *)ERROR_PTR("stream not opened", procName, NULL);
1951 
1952  baa = boxaaReadStream(fp);
1953  fclose(fp);
1954  if (!baa) L_ERROR("baa not read\n", procName);
1955  return baa;
1956 }
1957 
1958 
1966 l_int32
1967 boxaaWrite(const char *filename,
1968  BOXAA *baa)
1969 {
1970 l_int32 ret;
1971 FILE *fp;
1972 
1973  PROCNAME("boxaaWrite");
1974 
1975  if (!filename)
1976  return ERROR_INT("filename not defined", procName, 1);
1977  if (!baa)
1978  return ERROR_INT("baa not defined", procName, 1);
1979 
1980  if ((fp = fopenWriteStream(filename, "w")) == NULL)
1981  return ERROR_INT("stream not opened", procName, 1);
1982  ret = boxaaWriteStream(fp, baa);
1983  fclose(fp);
1984  if (ret)
1985  return ERROR_INT("baa not written to stream", procName, 1);
1986  return 0;
1987 }
1988 
1989 
1997 l_int32
1999  BOXAA *baa)
2000 {
2001 l_int32 n, i, x, y, w, h;
2002 BOX *box;
2003 BOXA *boxa;
2004 
2005  PROCNAME("boxaaWriteStream");
2006 
2007  if (!fp)
2008  return ERROR_INT("stream not defined", procName, 1);
2009  if (!baa)
2010  return ERROR_INT("baa not defined", procName, 1);
2011 
2012  n = boxaaGetCount(baa);
2013  fprintf(fp, "\nBoxaa Version %d\n", BOXAA_VERSION_NUMBER);
2014  fprintf(fp, "Number of boxa = %d\n", n);
2015 
2016  for (i = 0; i < n; i++) {
2017  if ((boxa = boxaaGetBoxa(baa, i, L_CLONE)) == NULL)
2018  return ERROR_INT("boxa not found", procName, 1);
2019  boxaGetExtent(boxa, NULL, NULL, &box);
2020  boxGetGeometry(box, &x, &y, &w, &h);
2021  fprintf(fp, "\nBoxa[%d] extent: x = %d, y = %d, w = %d, h = %d",
2022  i, x, y, w, h);
2023  boxaWriteStream(fp, boxa);
2024  boxDestroy(&box);
2025  boxaDestroy(&boxa);
2026  }
2027  return 0;
2028 }
2029 
2030 
2044 l_int32
2045 boxaaWriteMem(l_uint8 **pdata,
2046  size_t *psize,
2047  BOXAA *baa)
2048 {
2049 l_int32 ret;
2050 FILE *fp;
2051 
2052  PROCNAME("boxaaWriteMem");
2053 
2054  if (pdata) *pdata = NULL;
2055  if (psize) *psize = 0;
2056  if (!pdata)
2057  return ERROR_INT("&data not defined", procName, 1);
2058  if (!psize)
2059  return ERROR_INT("&size not defined", procName, 1);
2060  if (!baa)
2061  return ERROR_INT("baa not defined", procName, 1);
2062 
2063 #if HAVE_FMEMOPEN
2064  if ((fp = open_memstream((char **)pdata, psize)) == NULL)
2065  return ERROR_INT("stream not opened", procName, 1);
2066  ret = boxaaWriteStream(fp, baa);
2067 #else
2068  L_INFO("work-around: writing to a temp file\n", procName);
2069  #ifdef _WIN32
2070  if ((fp = fopenWriteWinTempfile()) == NULL)
2071  return ERROR_INT("tmpfile stream not opened", procName, 1);
2072  #else
2073  if ((fp = tmpfile()) == NULL)
2074  return ERROR_INT("tmpfile stream not opened", procName, 1);
2075  #endif /* _WIN32 */
2076  ret = boxaaWriteStream(fp, baa);
2077  rewind(fp);
2078  *pdata = l_binaryReadStream(fp, psize);
2079 #endif /* HAVE_FMEMOPEN */
2080  fclose(fp);
2081  return ret;
2082 }
2083 
2084 
2085 /*---------------------------------------------------------------------*
2086  * Boxa serialized I/O *
2087  *---------------------------------------------------------------------*/
2094 BOXA *
2095 boxaRead(const char *filename)
2096 {
2097 FILE *fp;
2098 BOXA *boxa;
2099 
2100  PROCNAME("boxaRead");
2101 
2102  if (!filename)
2103  return (BOXA *)ERROR_PTR("filename not defined", procName, NULL);
2104 
2105  if ((fp = fopenReadStream(filename)) == NULL)
2106  return (BOXA *)ERROR_PTR("stream not opened", procName, NULL);
2107  boxa = boxaReadStream(fp);
2108  fclose(fp);
2109  if (!boxa)
2110  return (BOXA *)ERROR_PTR("boxa not read", procName, NULL);
2111  return boxa;
2112 }
2113 
2114 
2121 BOXA *
2123 {
2124 l_int32 n, i, x, y, w, h, version;
2125 l_int32 ignore;
2126 BOX *box;
2127 BOXA *boxa;
2128 
2129  PROCNAME("boxaReadStream");
2130 
2131  if (!fp)
2132  return (BOXA *)ERROR_PTR("stream not defined", procName, NULL);
2133 
2134  if (fscanf(fp, "\nBoxa Version %d\n", &version) != 1)
2135  return (BOXA *)ERROR_PTR("not a boxa file", procName, NULL);
2136  if (version != BOXA_VERSION_NUMBER)
2137  return (BOXA *)ERROR_PTR("invalid boxa version", procName, NULL);
2138  if (fscanf(fp, "Number of boxes = %d\n", &n) != 1)
2139  return (BOXA *)ERROR_PTR("not a boxa file", procName, NULL);
2140 
2141  if ((boxa = boxaCreate(n)) == NULL)
2142  return (BOXA *)ERROR_PTR("boxa not made", procName, NULL);
2143  for (i = 0; i < n; i++) {
2144  if (fscanf(fp, " Box[%d]: x = %d, y = %d, w = %d, h = %d\n",
2145  &ignore, &x, &y, &w, &h) != 5) {
2146  boxaDestroy(&boxa);
2147  return (BOXA *)ERROR_PTR("box descr not valid", procName, NULL);
2148  }
2149  box = boxCreate(x, y, w, h);
2150  boxaAddBox(boxa, box, L_INSERT);
2151  }
2152 
2153  return boxa;
2154 }
2155 
2156 
2164 BOXA *
2165 boxaReadMem(const l_uint8 *data,
2166  size_t size)
2167 {
2168 FILE *fp;
2169 BOXA *boxa;
2170 
2171  PROCNAME("boxaReadMem");
2172 
2173  if (!data)
2174  return (BOXA *)ERROR_PTR("data not defined", procName, NULL);
2175  if ((fp = fopenReadFromMemory(data, size)) == NULL)
2176  return (BOXA *)ERROR_PTR("stream not opened", procName, NULL);
2177 
2178  boxa = boxaReadStream(fp);
2179  fclose(fp);
2180  if (!boxa) L_ERROR("boxa not read\n", procName);
2181  return boxa;
2182 }
2183 
2184 
2192 l_int32
2193 boxaWrite(const char *filename,
2194  BOXA *boxa)
2195 {
2196 l_int32 ret;
2197 FILE *fp;
2198 
2199  PROCNAME("boxaWrite");
2200 
2201  if (!filename)
2202  return ERROR_INT("filename not defined", procName, 1);
2203  if (!boxa)
2204  return ERROR_INT("boxa not defined", procName, 1);
2205 
2206  if ((fp = fopenWriteStream(filename, "w")) == NULL)
2207  return ERROR_INT("stream not opened", procName, 1);
2208  ret = boxaWriteStream(fp, boxa);
2209  fclose(fp);
2210  if (ret)
2211  return ERROR_INT("boxa not written to stream", procName, 1);
2212 
2213  return 0;
2214 }
2215 
2216 
2224 l_int32
2226  BOXA *boxa)
2227 {
2228 l_int32 n, i;
2229 BOX *box;
2230 
2231  PROCNAME("boxaWriteStream");
2232 
2233  if (!fp)
2234  return ERROR_INT("stream not defined", procName, 1);
2235  if (!boxa)
2236  return ERROR_INT("boxa not defined", procName, 1);
2237 
2238  n = boxaGetCount(boxa);
2239  fprintf(fp, "\nBoxa Version %d\n", BOXA_VERSION_NUMBER);
2240  fprintf(fp, "Number of boxes = %d\n", n);
2241  for (i = 0; i < n; i++) {
2242  if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL)
2243  return ERROR_INT("box not found", procName, 1);
2244  fprintf(fp, " Box[%d]: x = %d, y = %d, w = %d, h = %d\n",
2245  i, box->x, box->y, box->w, box->h);
2246  boxDestroy(&box);
2247  }
2248  return 0;
2249 }
2250 
2251 
2265 l_int32
2266 boxaWriteMem(l_uint8 **pdata,
2267  size_t *psize,
2268  BOXA *boxa)
2269 {
2270 l_int32 ret;
2271 FILE *fp;
2272 
2273  PROCNAME("boxaWriteMem");
2274 
2275  if (pdata) *pdata = NULL;
2276  if (psize) *psize = 0;
2277  if (!pdata)
2278  return ERROR_INT("&data not defined", procName, 1);
2279  if (!psize)
2280  return ERROR_INT("&size not defined", procName, 1);
2281  if (!boxa)
2282  return ERROR_INT("boxa not defined", procName, 1);
2283 
2284 #if HAVE_FMEMOPEN
2285  if ((fp = open_memstream((char **)pdata, psize)) == NULL)
2286  return ERROR_INT("stream not opened", procName, 1);
2287  ret = boxaWriteStream(fp, boxa);
2288 #else
2289  L_INFO("work-around: writing to a temp file\n", procName);
2290  #ifdef _WIN32
2291  if ((fp = fopenWriteWinTempfile()) == NULL)
2292  return ERROR_INT("tmpfile stream not opened", procName, 1);
2293  #else
2294  if ((fp = tmpfile()) == NULL)
2295  return ERROR_INT("tmpfile stream not opened", procName, 1);
2296  #endif /* _WIN32 */
2297  ret = boxaWriteStream(fp, boxa);
2298  rewind(fp);
2299  *pdata = l_binaryReadStream(fp, psize);
2300 #endif /* HAVE_FMEMOPEN */
2301  fclose(fp);
2302  return ret;
2303 }
2304 
2305 
2306 /*---------------------------------------------------------------------*
2307  * Debug printing *
2308  *---------------------------------------------------------------------*/
2322 l_int32
2324  BOX *box)
2325 {
2326  PROCNAME("boxPrintStreamInfo");
2327 
2328  if (!fp)
2329  return ERROR_INT("stream not defined", procName, 1);
2330  if (!box)
2331  return ERROR_INT("box not defined", procName, 1);
2332 
2333  fprintf(fp, " Box: x = %d, y = %d, w = %d, h = %d\n",
2334  box->x, box->y, box->w, box->h);
2335  return 0;
2336 }
#define BOXAA_VERSION_NUMBER
Definition: pix.h:451
BOXA * boxaReadStream(FILE *fp)
boxaReadStream()
Definition: boxbasic.c:2122
l_int32 boxaExtendArray(BOXA *boxa)
boxaExtendArray()
Definition: boxbasic.c:662
BOXAA * boxaaReadStream(FILE *fp)
boxaaReadStream()
Definition: boxbasic.c:1894
BOX * boxaGetValidBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetValidBox()
Definition: boxbasic.c:799
l_int32 n
Definition: pix.h:494
l_uint32 refcount
Definition: pix.h:496
l_int32 boxaaRemoveBoxa(BOXAA *baa, l_int32 index)
boxaaRemoveBoxa()
Definition: boxbasic.c:1735
l_int32 boxaWriteStream(FILE *fp, BOXA *boxa)
boxaWriteStream()
Definition: boxbasic.c:2225
l_int32 boxaWrite(const char *filename, BOXA *boxa)
boxaWrite()
Definition: boxbasic.c:2193
static const l_int32 INITIAL_PTR_ARRAYSIZE
Definition: boxbasic.c:135
l_int32 boxaaGetCount(BOXAA *baa)
boxaaGetCount()
Definition: boxbasic.c:1438
l_int32 boxaExtendArrayToSize(BOXA *boxa, l_int32 size)
boxaExtendArrayToSize()
Definition: boxbasic.c:686
l_uint32 refcount
Definition: pix.h:486
Definition: pix.h:704
BOXAA * boxaaReadMem(const l_uint8 *data, size_t size)
boxaaReadMem()
Definition: boxbasic.c:1939
l_int32 boxaaWriteMem(l_uint8 **pdata, size_t *psize, BOXAA *baa)
boxaaWriteMem()
Definition: boxbasic.c:2045
l_int32 y
Definition: pix.h:483
l_int32 boxaRemoveBox(BOXA *boxa, l_int32 index)
boxaRemoveBox()
Definition: boxbasic.c:1025
NUMA * numaMakeConstant(l_float32 val, l_int32 size)
numaMakeConstant()
Definition: numafunc1.c:768
l_int32 boxSetGeometry(BOX *box, l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxSetGeometry()
Definition: boxbasic.c:339
struct Boxa ** boxa
Definition: pix.h:506
l_int32 boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
Definition: boxbasic.c:615
FILE * fopenReadFromMemory(const l_uint8 *data, size_t size)
fopenReadFromMemory()
Definition: utils2.c:1670
l_int32 boxIsValid(BOX *box, l_int32 *pvalid)
boxIsValid()
Definition: boxbasic.c:469
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
Definition: boxbasic.c:531
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
Definition: boxbasic.c:577
l_int32 boxPrintStreamInfo(FILE *fp, BOX *box)
boxPrintStreamInfo()
Definition: boxbasic.c:2323
l_int32 boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
Definition: boxbasic.c:860
Definition: pix.h:492
void * reallocNew(void **pindata, l_int32 oldsize, l_int32 newsize)
reallocNew()
Definition: utils2.c:1102
l_int32 boxaClear(BOXA *boxa)
boxaClear()
Definition: boxbasic.c:1210
l_int32 boxaaWrite(const char *filename, BOXAA *baa)
boxaaWrite()
Definition: boxbasic.c:1967
Definition: array.h:116
Definition: pix.h:502
BOX * boxClone(BOX *box)
boxClone()
Definition: boxbasic.c:251
l_int32 nalloc
Definition: pix.h:505
BOXAA * boxaaReadFromFiles(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
boxaaReadFromFiles()
Definition: boxbasic.c:1823
l_int32 boxaIsFull(BOXA *boxa, l_int32 *pfull)
boxaIsFull()
Definition: boxbasic.c:896
Definition: array.h:59
void boxaaDestroy(BOXAA **pbaa)
boxaaDestroy()
Definition: boxbasic.c:1303
static const l_int32 L_INSERT
Definition: pix.h:710
l_int32 boxaaAddBox(BOXAA *baa, l_int32 index, BOX *box, l_int32 accessflag)
boxaaAddBox()
Definition: boxbasic.c:1775
BOX * boxCreateValid(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreateValid()
Definition: boxbasic.c:209
l_int32 boxaaExtendWithInit(BOXAA *baa, l_int32 maxindex, BOXA *boxa)
boxaaExtendWithInit()
Definition: boxbasic.c:1607
l_int32 nalloc
Definition: pix.h:495
l_int32 w
Definition: pix.h:484
l_int32 boxaInsertBox(BOXA *boxa, l_int32 index, BOX *box)
boxaInsertBox()
Definition: boxbasic.c:980
BOXA * boxaReadMem(const l_uint8 *data, size_t size)
boxaReadMem()
Definition: boxbasic.c:2165
l_int32 boxaaInitFull(BOXAA *baa, BOXA *boxa)
boxaaInitFull()
Definition: boxbasic.c:1567
BOXA * boxaSaveValid(BOXA *boxas, l_int32 copyflag)
boxaSaveValid()
Definition: boxbasic.c:1109
l_int32 boxaaExtendArrayToSize(BOXAA *baa, l_int32 size)
boxaaExtendArrayToSize()
Definition: boxbasic.c:1409
l_int32 boxSetSideLocations(BOX *box, l_int32 l, l_int32 r, l_int32 t, l_int32 b)
boxSetSideLocations()
Definition: boxbasic.c:404
l_int32 boxaInitFull(BOXA *boxa, BOX *box)
boxaInitFull()
Definition: boxbasic.c:1173
l_int32 boxGetSideLocations(BOX *box, l_int32 *pl, l_int32 *pr, l_int32 *pt, l_int32 *pb)
boxGetSideLocations()
Definition: boxbasic.c:370
l_int32 boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
Definition: boxbasic.c:309
FILE * fopenWriteWinTempfile()
fopenWriteWinTempfile()
Definition: utils2.c:1716
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:675
NUMA * boxaFindInvalidBoxes(BOXA *boxa)
boxaFindInvalidBoxes()
Definition: boxbasic.c:827
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
Definition: boxbasic.c:760
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
Definition: sarray1.c:1710
l_int32 x
Definition: pix.h:482
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1636
l_int32 boxaaExtendArray(BOXAA *baa)
boxaaExtendArray()
Definition: boxbasic.c:1378
BOXAA * boxaaCreate(l_int32 n)
boxaaCreate()
Definition: boxbasic.c:1237
l_int32 boxaaReplaceBoxa(BOXAA *baa, l_int32 index, BOXA *boxa)
boxaaReplaceBoxa()
Definition: boxbasic.c:1648
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1593
l_int32 boxGetRefcount(BOX *box)
Return the current reference count of box.
Definition: boxbasic.c:431
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
Definition: utils2.c:1200
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:615
l_int32 boxChangeRefcount(BOX *box, l_int32 delta)
Adjust the current references count of box by delta.
Definition: boxbasic.c:448
BOXAA * boxaaRead(const char *filename)
boxaaRead()
Definition: boxbasic.c:1867
l_int32 n
Definition: pix.h:504
l_int32 boxaGetValidCount(BOXA *boxa)
boxaGetValidCount()
Definition: boxbasic.c:732
l_int32 boxaaAddBoxa(BOXAA *baa, BOXA *ba, l_int32 copyflag)
boxaaAddBoxa()
Definition: boxbasic.c:1341
l_int32 boxaWriteMem(l_uint8 **pdata, size_t *psize, BOXA *boxa)
boxaWriteMem()
Definition: boxbasic.c:2266
Definition: pix.h:705
l_int32 h
Definition: pix.h:485
#define BOXA_VERSION_NUMBER
Definition: pix.h:450
BOX * boxCopy(BOX *box)
boxCopy()
Definition: boxbasic.c:229
l_int32 numaSetValue(NUMA *na, l_int32 index, l_float32 val)
numaSetValue()
Definition: numabasic.c:758
l_int32 boxaaInsertBoxa(BOXAA *baa, l_int32 index, BOXA *boxa)
boxaaInsertBoxa()
Definition: boxbasic.c:1689
Definition: pix.h:706
l_int32 boxaaGetBoxCount(BOXAA *baa)
boxaaGetBoxCount()
Definition: boxbasic.c:1455
l_int32 boxaaWriteStream(FILE *fp, BOXAA *baa)
boxaaWriteStream()
Definition: boxbasic.c:1998
BOX * boxaaGetBox(BOXAA *baa, l_int32 iboxa, l_int32 ibox, l_int32 accessflag)
boxaaGetBox()
Definition: boxbasic.c:1515
BOXA * boxaCreate(l_int32 n)
boxaCreate()
Definition: boxbasic.c:496
void boxDestroy(BOX **pbox)
boxDestroy()
Definition: boxbasic.c:277
l_int32 boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
Definition: boxfunc4.c:2321
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
Definition: boxbasic.c:715
struct Box ** box
Definition: pix.h:497
l_int32 boxaRemoveBoxAndSave(BOXA *boxa, l_int32 index, BOX **pbox)
boxaRemoveBoxAndSave()
Definition: boxbasic.c:1067
BOXAA * boxaaCopy(BOXAA *baas, l_int32 copyflag)
boxaaCopy()
Definition: boxbasic.c:1272
Definition: pix.h:480
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
Definition: boxbasic.c:164
BOXA * boxaRead(const char *filename)
boxaRead()
Definition: boxbasic.c:2095
l_int32 boxaReplaceBox(BOXA *boxa, l_int32 index, BOX *box)
boxaReplaceBox()
Definition: boxbasic.c:942
BOXA * boxaaGetBoxa(BOXAA *baa, l_int32 index, l_int32 accessflag)
boxaaGetBoxa()
Definition: boxbasic.c:1485
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:349