Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
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#ifdef HAVE_CONFIG_H
133#include <config_auto.h>
134#endif /* HAVE_CONFIG_H */
135
136#include <string.h>
137#include "allheaders.h"
138#include "pix_internal.h"
139
140 /* Bounds on array sizes */
141static const size_t MaxBoxaPtrArraySize = 10000000;
142static const size_t MaxBoxaaPtrArraySize = 1000000;
143static const size_t InitialPtrArraySize = 20;
145/*---------------------------------------------------------------------*
146 * Box creation, destruction and copy *
147 *---------------------------------------------------------------------*/
170BOX *
171boxCreate(l_int32 x,
172 l_int32 y,
173 l_int32 w,
174 l_int32 h)
175{
176BOX *box;
177
178 if (w < 0 || h < 0)
179 return (BOX *)ERROR_PTR("w and h not both >= 0", __func__, NULL);
180 if (x < 0) { /* take part in +quad */
181 w = w + x;
182 x = 0;
183 if (w <= 0)
184 return (BOX *)ERROR_PTR("x < 0 and box off +quad", __func__, NULL);
185 }
186 if (y < 0) { /* take part in +quad */
187 h = h + y;
188 y = 0;
189 if (h <= 0)
190 return (BOX *)ERROR_PTR("y < 0 and box off +quad", __func__, NULL);
191 }
192
193 box = (BOX *)LEPT_CALLOC(1, sizeof(BOX));
194 boxSetGeometry(box, x, y, w, h);
195 box->refcount = 1;
196 return box;
197}
198
199
211BOX *
213 l_int32 y,
214 l_int32 w,
215 l_int32 h)
216{
217 if (w <= 0 || h <= 0)
218 return (BOX *)ERROR_PTR("w and h not both > 0", __func__, NULL);
219 return boxCreate(x, y, w, h);
220}
221
222
229BOX *
231{
232BOX *boxc;
233
234 if (!box)
235 return (BOX *)ERROR_PTR("box not defined", __func__, NULL);
236
237 boxc = boxCreate(box->x, box->y, box->w, box->h);
238 return boxc;
239}
240
241
248BOX *
250{
251
252 if (!box)
253 return (BOX *)ERROR_PTR("box not defined", __func__, NULL);
254
255 ++box->refcount;
256 return box;
257}
258
259
272void
274{
275BOX *box;
276
277 if (pbox == NULL) {
278 L_WARNING("ptr address is null!\n", __func__);
279 return;
280 }
281 if ((box = *pbox) == NULL)
282 return;
283
284 if (--box->refcount == 0)
285 LEPT_FREE(box);
286 *pbox = NULL;
287}
288
289
290/*---------------------------------------------------------------------*
291 * Box accessors *
292 *---------------------------------------------------------------------*/
300l_ok
302 l_int32 *px,
303 l_int32 *py,
304 l_int32 *pw,
305 l_int32 *ph)
306{
307 if (px) *px = 0;
308 if (py) *py = 0;
309 if (pw) *pw = 0;
310 if (ph) *ph = 0;
311 if (!box)
312 return ERROR_INT("box not defined", __func__, 1);
313 if (px) *px = box->x;
314 if (py) *py = box->y;
315 if (pw) *pw = box->w;
316 if (ph) *ph = box->h;
317 return 0;
318}
319
320
328l_ok
330 l_int32 x,
331 l_int32 y,
332 l_int32 w,
333 l_int32 h)
334{
335 if (!box)
336 return ERROR_INT("box not defined", __func__, 1);
337 if (x != -1) box->x = x;
338 if (y != -1) box->y = y;
339 if (w != -1) box->w = w;
340 if (h != -1) box->h = h;
341 return 0;
342}
343
344
357l_ok
359 l_int32 *pl,
360 l_int32 *pr,
361 l_int32 *pt,
362 l_int32 *pb)
363{
364l_int32 x, y, w, h;
365
366 if (pl) *pl = 0;
367 if (pr) *pr = 0;
368 if (pt) *pt = 0;
369 if (pb) *pb = 0;
370 if (!box)
371 return ERROR_INT("box not defined", __func__, 1);
372
373 boxGetGeometry(box, &x, &y, &w, &h);
374 if (pl) *pl = x;
375 if (pr) *pr = x + w - 1;
376 if (pt) *pt = y;
377 if (pb) *pb = y + h - 1;
378 return 0;
379}
380
381
389l_ok
391 l_int32 l,
392 l_int32 r,
393 l_int32 t,
394 l_int32 b)
395{
396l_int32 x, y, w, h;
397
398 if (!box)
399 return ERROR_INT("box not defined", __func__, 1);
400 x = (l != -1) ? l : box->x;
401 w = (r != -1) ? r - x + 1 : box->x + box->w - x;
402 y = (t != -1) ? t : box->y;
403 h = (b != -1) ? b - y + 1 : box->y + box->h - y;
404 boxSetGeometry(box, x, y, w, h);
405 return 0;
406}
407
408
416l_ok
418 l_int32 *pvalid)
419{
420 if (!pvalid)
421 return ERROR_INT("&valid not defined", __func__, 1);
422 *pvalid = 0;
423 if (!box)
424 return ERROR_INT("box not defined", __func__, 1);
425
426 if (box->w > 0 && box->h > 0)
427 *pvalid = 1;
428 return 0;
429}
430
431
432/*---------------------------------------------------------------------*
433 * Boxa creation, destruction, copy, extension *
434 *---------------------------------------------------------------------*/
441BOXA *
442boxaCreate(l_int32 n)
443{
444BOXA *boxa;
445
446 if (n <= 0 || n > MaxBoxaPtrArraySize)
448
449 boxa = (BOXA *)LEPT_CALLOC(1, sizeof(BOXA));
450 boxa->n = 0;
451 boxa->nalloc = n;
452 boxa->refcount = 1;
453 if ((boxa->box = (BOX **)LEPT_CALLOC(n, sizeof(BOX *))) == NULL) {
454 boxaDestroy(&boxa);
455 return (BOXA *)ERROR_PTR("boxa ptrs not made", __func__, NULL);
456 }
457 return boxa;
458}
459
460
474BOXA *
476 l_int32 copyflag)
477{
478l_int32 i;
479BOX *boxc;
480BOXA *boxac;
481
482 if (!boxa)
483 return (BOXA *)ERROR_PTR("boxa not defined", __func__, NULL);
484
485 if (copyflag == L_CLONE) {
486 boxa->refcount++;
487 return boxa;
488 }
489
490 if (copyflag != L_COPY && copyflag != L_COPY_CLONE)
491 return (BOXA *)ERROR_PTR("invalid copyflag", __func__, NULL);
492
493 if ((boxac = boxaCreate(boxa->nalloc)) == NULL)
494 return (BOXA *)ERROR_PTR("boxac not made", __func__, NULL);
495 for (i = 0; i < boxa->n; i++) {
496 if (copyflag == L_COPY)
497 boxc = boxaGetBox(boxa, i, L_COPY);
498 else /* copy-clone */
499 boxc = boxaGetBox(boxa, i, L_CLONE);
500 boxaAddBox(boxac, boxc, L_INSERT);
501 }
502 return boxac;
503}
504
505
518void
520{
521l_int32 i;
522BOXA *boxa;
523
524 if (pboxa == NULL) {
525 L_WARNING("ptr address is null!\n", __func__);
526 return;
527 }
528
529 if ((boxa = *pboxa) == NULL)
530 return;
531
532 /* Decrement the ref count. If it is 0, destroy the boxa. */
533 if (--boxa->refcount == 0) {
534 for (i = 0; i < boxa->n; i++)
535 boxDestroy(&boxa->box[i]);
536 LEPT_FREE(boxa->box);
537 LEPT_FREE(boxa);
538 }
539
540 *pboxa = NULL;
541}
542
543
552l_ok
554 BOX *box,
555 l_int32 copyflag)
556{
557l_int32 n;
558BOX *boxc;
559
560 if (!boxa)
561 return ERROR_INT("boxa not defined", __func__, 1);
562 if (!box)
563 return ERROR_INT("box not defined", __func__, 1);
564
565 if (copyflag == L_INSERT)
566 boxc = box;
567 else if (copyflag == L_COPY)
568 boxc = boxCopy(box);
569 else if (copyflag == L_CLONE)
570 boxc = boxClone(box);
571 else
572 return ERROR_INT("invalid copyflag", __func__, 1);
573 if (!boxc)
574 return ERROR_INT("boxc not made", __func__, 1);
575
576 n = boxaGetCount(boxa);
577 if (n >= boxa->nalloc) {
578 if (boxaExtendArray(boxa)) {
579 if (copyflag != L_INSERT)
580 boxDestroy(&boxc);
581 return ERROR_INT("extension failed", __func__, 1);
582 }
583 }
584 boxa->box[n] = boxc;
585 boxa->n++;
586 return 0;
587}
588
589
601l_ok
603{
604 if (!boxa)
605 return ERROR_INT("boxa not defined", __func__, 1);
606
607 return boxaExtendArrayToSize(boxa, 2 * boxa->nalloc);
608}
609
610
624l_ok
626 size_t size)
627{
628size_t oldsize, newsize;
629
630 if (!boxa)
631 return ERROR_INT("boxa not defined", __func__, 1);
632 if (boxa->nalloc > MaxBoxaPtrArraySize) /* belt & suspenders */
633 return ERROR_INT("boxa has too many ptrs", __func__, 1);
634 if (size > MaxBoxaPtrArraySize)
635 return ERROR_INT("size > 10M box ptrs; too large", __func__, 1);
636 if (size <= boxa->nalloc) {
637 L_INFO("size too small; no extension\n", __func__);
638 return 0;
639 }
640
641 oldsize = boxa->nalloc * sizeof(BOX *);
642 newsize = size * sizeof(BOX *);
643 if ((boxa->box = (BOX **)reallocNew((void **)&boxa->box,
644 oldsize, newsize)) == NULL)
645 return ERROR_INT("new ptr array not returned", __func__, 1);
646 boxa->nalloc = size;
647 return 0;
648}
649
650
651/*---------------------------------------------------------------------*
652 * Boxa accessors *
653 *---------------------------------------------------------------------*/
660l_int32
661boxaGetCount(const BOXA *boxa)
662{
663 if (!boxa)
664 return ERROR_INT("boxa not defined", __func__, 0);
665 return boxa->n;
666}
667
668
675l_int32
677{
678l_int32 n, i, w, h, count;
679
680 if (!boxa)
681 return ERROR_INT("boxa not defined", __func__, 0);
682
683 n = boxaGetCount(boxa);
684 for (i = 0, count = 0; i < n; i++) {
685 boxaGetBoxGeometry(boxa, i, NULL, NULL, &w, &h);
686 if (w > 0 && h > 0)
687 count++;
688 }
689 return count;
690}
691
692
701BOX *
703 l_int32 index,
704 l_int32 accessflag)
705{
706 if (!boxa)
707 return (BOX *)ERROR_PTR("boxa not defined", __func__, NULL);
708 if (index < 0 || index >= boxa->n)
709 return (BOX *)ERROR_PTR("index not valid", __func__, NULL);
710
711 if (accessflag == L_COPY)
712 return boxCopy(boxa->box[index]);
713 else if (accessflag == L_CLONE)
714 return boxClone(boxa->box[index]);
715 else
716 return (BOX *)ERROR_PTR("invalid accessflag", __func__, NULL);
717}
718
719
738BOX *
740 l_int32 index,
741 l_int32 accessflag)
742{
743l_int32 w, h;
744BOX *box;
745
746 if (!boxa)
747 return (BOX *)ERROR_PTR("boxa not defined", __func__, NULL);
748
749 if ((box = boxaGetBox(boxa, index, accessflag)) == NULL)
750 return (BOX *)ERROR_PTR("box not returned", __func__, NULL);
751 boxGetGeometry(box, NULL, NULL, &w, &h);
752 if (w <= 0 || h <= 0) /* not valid, but not necessarily an error */
753 boxDestroy(&box);
754 return box;
755}
756
757
764NUMA *
766{
767l_int32 i, n, w, h;
768NUMA *na;
769
770 if (!boxa)
771 return (NUMA *)ERROR_PTR("boxa not defined", __func__, NULL);
772
773 n = boxaGetCount(boxa);
774 if (boxaGetValidCount(boxa) == n)
775 return NULL;
776
777 na = numaMakeConstant(0, n);
778 for (i = 0; i < n; i++) {
779 boxaGetBoxGeometry(boxa, i, NULL, NULL, &w, &h);
780 if (w == 0 || h == 0)
781 numaSetValue(na, i, 1);
782 }
783 return na;
784}
785
786
795l_ok
797 l_int32 index,
798 l_int32 *px,
799 l_int32 *py,
800 l_int32 *pw,
801 l_int32 *ph)
802{
803BOX *box;
804
805 if (px) *px = 0;
806 if (py) *py = 0;
807 if (pw) *pw = 0;
808 if (ph) *ph = 0;
809 if (!boxa)
810 return ERROR_INT("boxa not defined", __func__, 1);
811 if (index < 0 || index >= boxa->n)
812 return ERROR_INT("index not valid", __func__, 1);
813
814 if ((box = boxaGetBox(boxa, index, L_CLONE)) == NULL)
815 return ERROR_INT("box not found!", __func__, 1);
816 boxGetGeometry(box, px, py, pw, ph);
817 boxDestroy(&box);
818 return 0;
819}
820
821
829l_ok
831 l_int32 *pfull)
832{
833l_int32 i, n, full;
834BOX *box;
835
836 if (!pfull)
837 return ERROR_INT("&full not defined", __func__, 1);
838 *pfull = 0;
839 if (!boxa)
840 return ERROR_INT("boxa not defined", __func__, 1);
841
842 n = boxaGetCount(boxa);
843 full = 1;
844 for (i = 0; i < n; i++) {
845 if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL) {
846 full = 0;
847 break;
848 }
849 boxDestroy(&box);
850 }
851 *pfull = full;
852 return 0;
853}
854
855
856/*---------------------------------------------------------------------*
857 * Boxa array modifiers *
858 *---------------------------------------------------------------------*/
874l_ok
876 l_int32 index,
877 BOX *box)
878{
879 if (!boxa)
880 return ERROR_INT("boxa not defined", __func__, 1);
881 if (index < 0 || index >= boxa->n)
882 return ERROR_INT("index not valid", __func__, 1);
883 if (!box)
884 return ERROR_INT("box not defined", __func__, 1);
885
886 boxDestroy(&(boxa->box[index]));
887 boxa->box[index] = box;
888 return 0;
889}
890
891
910l_ok
912 l_int32 index,
913 BOX *box)
914{
915l_int32 i, n;
916BOX **array;
917
918 if (!boxa)
919 return ERROR_INT("boxa not defined", __func__, 1);
920 n = boxaGetCount(boxa);
921 if (index < 0 || index > n) {
922 L_ERROR("index %d not in [0,...,%d]\n", __func__, index, n);
923 return 1;
924 }
925 if (!box)
926 return ERROR_INT("box not defined", __func__, 1);
927
928 if (n >= boxa->nalloc) {
929 if (boxaExtendArray(boxa))
930 return ERROR_INT("extension failed", __func__, 1);
931 }
932 array = boxa->box;
933 boxa->n++;
934 for (i = n; i > index; i--)
935 array[i] = array[i - 1];
936 array[index] = box;
937 return 0;
938}
939
940
956l_ok
958 l_int32 index)
959{
960 return boxaRemoveBoxAndSave(boxa, index, NULL);
961}
962
963
980l_ok
982 l_int32 index,
983 BOX **pbox)
984{
985l_int32 i, n;
986BOX **array;
987
988 if (pbox) *pbox = NULL;
989 if (!boxa)
990 return ERROR_INT("boxa not defined", __func__, 1);
991 n = boxaGetCount(boxa);
992 if (index < 0 || index >= n) {
993 L_ERROR("index %d not in [0,...,%d]\n", __func__, index, n - 1);
994 return 1;
995 }
996
997 if (pbox)
998 *pbox = boxaGetBox(boxa, index, L_CLONE);
999 array = boxa->box;
1000 boxDestroy(&array[index]);
1001 for (i = index + 1; i < n; i++)
1002 array[i - 1] = array[i];
1003 array[n - 1] = NULL;
1004 boxa->n--;
1005
1006 return 0;
1007}
1008
1009
1022BOXA *
1024 l_int32 copyflag)
1025{
1026l_int32 i, n;
1027BOX *box;
1028BOXA *boxad;
1029
1030 if (!boxas)
1031 return (BOXA *)ERROR_PTR("boxas not defined", __func__, NULL);
1032 if (copyflag != L_COPY && copyflag != L_CLONE)
1033 return (BOXA *)ERROR_PTR("invalid copyflag", __func__, NULL);
1034
1035 n = boxaGetCount(boxas);
1036 boxad = boxaCreate(n);
1037 for (i = 0; i < n; i++) {
1038 if ((box = boxaGetValidBox(boxas, i, copyflag)) != NULL)
1039 boxaAddBox(boxad, box, L_INSERT);
1040 }
1041
1042 return boxad;
1043}
1044
1045
1084l_ok
1086 BOX *box)
1087{
1088l_int32 i, n;
1089BOX *boxt;
1090
1091 if (!boxa)
1092 return ERROR_INT("boxa not defined", __func__, 1);
1093
1094 n = boxa->nalloc;
1095 boxa->n = n;
1096 for (i = 0; i < n; i++) {
1097 if (box)
1098 boxt = boxCopy(box);
1099 else
1100 boxt = boxCreate(0, 0, 0, 0);
1101 boxaReplaceBox(boxa, i, boxt);
1102 }
1103 return 0;
1104}
1105
1106
1119l_ok
1121{
1122l_int32 i, n;
1123
1124 if (!boxa)
1125 return ERROR_INT("boxa not defined", __func__, 1);
1126
1127 n = boxaGetCount(boxa);
1128 for (i = 0; i < n; i++)
1129 boxDestroy(&boxa->box[i]);
1130 boxa->n = 0;
1131 return 0;
1132}
1133
1134
1135/*--------------------------------------------------------------------------*
1136 * Boxaa creation, destruction *
1137 *--------------------------------------------------------------------------*/
1144BOXAA *
1145boxaaCreate(l_int32 n)
1146{
1147BOXAA *baa;
1148
1149 if (n <= 0 || n > MaxBoxaaPtrArraySize)
1151
1152 baa = (BOXAA *)LEPT_CALLOC(1, sizeof(BOXAA));
1153 if ((baa->boxa = (BOXA **)LEPT_CALLOC(n, sizeof(BOXA *))) == NULL) {
1154 boxaaDestroy(&baa);
1155 return (BOXAA *)ERROR_PTR("boxa ptr array not made", __func__, NULL);
1156 }
1157 baa->nalloc = n;
1158 baa->n = 0;
1159 return baa;
1160}
1161
1162
1177BOXAA *
1179 l_int32 copyflag)
1180{
1181l_int32 i, n;
1182BOXA *boxa;
1183BOXAA *baad;
1184
1185 if (!baas)
1186 return (BOXAA *)ERROR_PTR("baas not defined", __func__, NULL);
1187 if (copyflag != L_COPY && copyflag != L_CLONE)
1188 return (BOXAA *)ERROR_PTR("invalid copyflag", __func__, NULL);
1189
1190 n = boxaaGetCount(baas);
1191 baad = boxaaCreate(n);
1192 for (i = 0; i < n; i++) {
1193 boxa = boxaaGetBoxa(baas, i, copyflag);
1194 boxaaAddBoxa(baad, boxa, L_INSERT);
1195 }
1196
1197 return baad;
1198}
1199
1200
1206void
1208{
1209l_int32 i;
1210BOXAA *baa;
1211
1212 if (pbaa == NULL) {
1213 L_WARNING("ptr address is NULL!\n", __func__);
1214 return;
1215 }
1216
1217 if ((baa = *pbaa) == NULL)
1218 return;
1219
1220 for (i = 0; i < baa->n; i++)
1221 boxaDestroy(&baa->boxa[i]);
1222 LEPT_FREE(baa->boxa);
1223 LEPT_FREE(baa);
1224 *pbaa = NULL;
1225}
1226
1227
1228
1229/*--------------------------------------------------------------------------*
1230 * Add Boxa to Boxaa *
1231 *--------------------------------------------------------------------------*/
1240l_ok
1242 BOXA *ba,
1243 l_int32 copyflag)
1244{
1245l_int32 n;
1246BOXA *bac;
1247
1248 if (!baa)
1249 return ERROR_INT("baa not defined", __func__, 1);
1250 if (!ba)
1251 return ERROR_INT("ba not defined", __func__, 1);
1252 if (copyflag != L_INSERT && copyflag != L_COPY && copyflag != L_CLONE)
1253 return ERROR_INT("invalid copyflag", __func__, 1);
1254
1255 if (copyflag == L_INSERT)
1256 bac = ba;
1257 else
1258 bac = boxaCopy(ba, copyflag);
1259
1260 n = boxaaGetCount(baa);
1261 if (n >= baa->nalloc) {
1262 if (boxaaExtendArray(baa))
1263 return ERROR_INT("extension failed", __func__, 1);
1264 }
1265 baa->boxa[n] = bac;
1266 baa->n++;
1267 return 0;
1268}
1269
1270
1283l_ok
1285{
1286 if (!baa)
1287 return ERROR_INT("baa not defined", __func__, 1);
1288
1289 return boxaaExtendArrayToSize(baa, 2 * baa->nalloc);
1290}
1291
1292
1306l_ok
1308 l_int32 size)
1309{
1310size_t oldsize, newsize;
1311
1312 if (!baa)
1313 return ERROR_INT("baa not defined", __func__, 1);
1314 if (baa->nalloc > MaxBoxaaPtrArraySize) /* belt & suspenders */
1315 return ERROR_INT("baa has too many ptrs", __func__, 1);
1316 if (size > MaxBoxaaPtrArraySize)
1317 return ERROR_INT("size > 1M boxa ptrs; too large", __func__, 1);
1318 if (size <= baa->nalloc) {
1319 L_INFO("size too small; no extension\n", __func__);
1320 return 0;
1321 }
1322
1323 oldsize = baa->nalloc * sizeof(BOXA *);
1324 newsize = size * sizeof(BOXA *);
1325 if ((baa->boxa = (BOXA **)reallocNew((void **)&baa->boxa,
1326 oldsize, newsize)) == NULL)
1327 return ERROR_INT("new ptr array not returned", __func__, 1);
1328 baa->nalloc = size;
1329 return 0;
1330}
1331
1332
1333/*----------------------------------------------------------------------*
1334 * Boxaa accessors *
1335 *----------------------------------------------------------------------*/
1342l_int32
1344{
1345 if (!baa)
1346 return ERROR_INT("baa not defined", __func__, 0);
1347 return baa->n;
1348}
1349
1350
1357l_int32
1359{
1360BOXA *boxa;
1361l_int32 n, sum, i;
1362
1363 if (!baa)
1364 return ERROR_INT("baa not defined", __func__, 0);
1365
1366 n = boxaaGetCount(baa);
1367 for (sum = 0, i = 0; i < n; i++) {
1368 boxa = boxaaGetBoxa(baa, i, L_CLONE);
1369 sum += boxaGetCount(boxa);
1370 boxaDestroy(&boxa);
1371 }
1372
1373 return sum;
1374}
1375
1376
1385BOXA *
1387 l_int32 index,
1388 l_int32 accessflag)
1389{
1390l_int32 n;
1391
1392 if (!baa)
1393 return (BOXA *)ERROR_PTR("baa not defined", __func__, NULL);
1394 n = boxaaGetCount(baa);
1395 if (index < 0 || index >= n)
1396 return (BOXA *)ERROR_PTR("index not valid", __func__, NULL);
1397 if (accessflag != L_COPY && accessflag != L_CLONE)
1398 return (BOXA *)ERROR_PTR("invalid accessflag", __func__, NULL);
1399
1400 return boxaCopy(baa->boxa[index], accessflag);
1401}
1402
1403
1413BOX *
1415 l_int32 iboxa,
1416 l_int32 ibox,
1417 l_int32 accessflag)
1418{
1419BOX *box;
1420BOXA *boxa;
1421
1422 if ((boxa = boxaaGetBoxa(baa, iboxa, L_CLONE)) == NULL)
1423 return (BOX *)ERROR_PTR("boxa not retrieved", __func__, NULL);
1424 if ((box = boxaGetBox(boxa, ibox, accessflag)) == NULL)
1425 L_ERROR("box not retrieved\n", __func__);
1426 boxaDestroy(&boxa);
1427 return box;
1428}
1429
1430
1431/*----------------------------------------------------------------------*
1432 * Boxaa array modifiers *
1433 *----------------------------------------------------------------------*/
1463l_ok
1465 BOXA *boxa)
1466{
1467l_int32 i, n;
1468BOXA *boxat;
1469
1470 if (!baa)
1471 return ERROR_INT("baa not defined", __func__, 1);
1472 if (!boxa)
1473 return ERROR_INT("boxa not defined", __func__, 1);
1474
1475 n = baa->nalloc;
1476 baa->n = n;
1477 for (i = 0; i < n; i++) {
1478 boxat = boxaCopy(boxa, L_COPY);
1479 boxaaReplaceBoxa(baa, i, boxat);
1480 }
1481 return 0;
1482}
1483
1484
1501l_ok
1503 l_int32 maxindex,
1504 BOXA *boxa)
1505{
1506l_int32 i, n;
1507
1508 if (!baa)
1509 return ERROR_INT("baa not defined", __func__, 1);
1510 if (!boxa)
1511 return ERROR_INT("boxa not defined", __func__, 1);
1512
1513 /* Extend the ptr array if necessary */
1514 n = boxaaGetCount(baa);
1515 if (maxindex < n) return 0;
1516 if (boxaaExtendArrayToSize(baa, maxindex + 1))
1517 return ERROR_INT("extension failed", __func__, 1);
1518
1519 /* Fill the new entries with copies of boxa */
1520 for (i = n; i <= maxindex; i++)
1521 boxaaAddBoxa(baa, boxa, L_COPY);
1522 return 0;
1523}
1524
1525
1541l_ok
1543 l_int32 index,
1544 BOXA *boxa)
1545{
1546l_int32 n;
1547
1548 if (!baa)
1549 return ERROR_INT("baa not defined", __func__, 1);
1550 if (!boxa)
1551 return ERROR_INT("boxa not defined", __func__, 1);
1552 n = boxaaGetCount(baa);
1553 if (index < 0 || index >= n)
1554 return ERROR_INT("index not valid", __func__, 1);
1555
1556 boxaDestroy(&baa->boxa[index]);
1557 baa->boxa[index] = boxa;
1558 return 0;
1559}
1560
1561
1581l_ok
1583 l_int32 index,
1584 BOXA *boxa)
1585{
1586l_int32 i, n;
1587BOXA **array;
1588
1589 if (!baa)
1590 return ERROR_INT("baa not defined", __func__, 1);
1591 n = boxaaGetCount(baa);
1592 if (index < 0 || index > n) {
1593 L_ERROR("index %d not in [0,...,%d]\n", __func__, index, n);
1594 return 1;
1595 }
1596 if (!boxa)
1597 return ERROR_INT("boxa not defined", __func__, 1);
1598
1599 if (n >= baa->nalloc) {
1600 if (boxaaExtendArray(baa))
1601 return ERROR_INT("extension failed", __func__, 1);
1602 }
1603 array = baa->boxa;
1604 baa->n++;
1605 for (i = n; i > index; i--)
1606 array[i] = array[i - 1];
1607 array[index] = boxa;
1608 return 0;
1609}
1610
1611
1628l_ok
1630 l_int32 index)
1631{
1632l_int32 i, n;
1633BOXA **array;
1634
1635 if (!baa)
1636 return ERROR_INT("baa not defined", __func__, 1);
1637 n = boxaaGetCount(baa);
1638 if (index < 0 || index >= n)
1639 return ERROR_INT("index not valid", __func__, 1);
1640
1641 array = baa->boxa;
1642 boxaDestroy(&array[index]);
1643 for (i = index + 1; i < n; i++)
1644 array[i - 1] = array[i];
1645 array[n - 1] = NULL;
1646 baa->n--;
1647
1648 return 0;
1649}
1650
1651
1666l_ok
1668 l_int32 index,
1669 BOX *box,
1670 l_int32 accessflag)
1671{
1672l_int32 n;
1673BOXA *boxa;
1674 if (!baa)
1675 return ERROR_INT("baa not defined", __func__, 1);
1676 n = boxaaGetCount(baa);
1677 if (index < 0 || index >= n)
1678 return ERROR_INT("index not valid", __func__, 1);
1679 if (accessflag != L_INSERT && accessflag != L_COPY && accessflag != L_CLONE)
1680 return ERROR_INT("invalid accessflag", __func__, 1);
1681
1682 boxa = boxaaGetBoxa(baa, index, L_CLONE);
1683 boxaAddBox(boxa, box, accessflag);
1684 boxaDestroy(&boxa);
1685 return 0;
1686}
1687
1688
1689/*---------------------------------------------------------------------*
1690 * Boxaa serialized I/O *
1691 *---------------------------------------------------------------------*/
1712BOXAA *
1713boxaaReadFromFiles(const char *dirname,
1714 const char *substr,
1715 l_int32 first,
1716 l_int32 nfiles)
1717{
1718char *fname;
1719l_int32 i, n;
1720BOXA *boxa;
1721BOXAA *baa;
1722SARRAY *sa;
1723
1724 if (!dirname)
1725 return (BOXAA *)ERROR_PTR("dirname not defined", __func__, NULL);
1726
1727 sa = getSortedPathnamesInDirectory(dirname, substr, first, nfiles);
1728 if (!sa || ((n = sarrayGetCount(sa)) == 0)) {
1729 sarrayDestroy(&sa);
1730 return (BOXAA *)ERROR_PTR("no pixa files found", __func__, NULL);
1731 }
1732
1733 baa = boxaaCreate(n);
1734 for (i = 0; i < n; i++) {
1735 fname = sarrayGetString(sa, i, L_NOCOPY);
1736 if ((boxa = boxaRead(fname)) == NULL) {
1737 L_ERROR("boxa not read for %d-th file", __func__, i);
1738 continue;
1739 }
1740 boxaaAddBoxa(baa, boxa, L_INSERT);
1741 }
1742
1743 sarrayDestroy(&sa);
1744 return baa;
1745}
1746
1747
1754BOXAA *
1755boxaaRead(const char *filename)
1756{
1757FILE *fp;
1758BOXAA *baa;
1759
1760 if (!filename)
1761 return (BOXAA *)ERROR_PTR("filename not defined", __func__, NULL);
1762
1763 if ((fp = fopenReadStream(filename)) == NULL)
1764 return (BOXAA *)ERROR_PTR_1("stream not opened",
1765 filename, __func__, NULL);
1766 baa = boxaaReadStream(fp);
1767 fclose(fp);
1768 if (!baa)
1769 return (BOXAA *)ERROR_PTR_1("boxaa not read",
1770 filename, __func__, NULL);
1771 return baa;
1772}
1773
1774
1786BOXAA *
1788{
1789l_int32 n, i, x, y, w, h, version;
1790l_int32 ignore;
1791BOXA *boxa;
1792BOXAA *baa;
1793
1794 if (!fp)
1795 return (BOXAA *)ERROR_PTR("stream not defined", __func__, NULL);
1796
1797 if (fscanf(fp, "\nBoxaa Version %d\n", &version) != 1)
1798 return (BOXAA *)ERROR_PTR("not a boxaa file", __func__, NULL);
1799 if (version != BOXAA_VERSION_NUMBER)
1800 return (BOXAA *)ERROR_PTR("invalid boxa version", __func__, NULL);
1801 if (fscanf(fp, "Number of boxa = %d\n", &n) != 1)
1802 return (BOXAA *)ERROR_PTR("not a boxaa file", __func__, NULL);
1803 if (n < 0)
1804 return (BOXAA *)ERROR_PTR("num boxa ptrs < 0", __func__, NULL);
1805 if (n > MaxBoxaaPtrArraySize)
1806 return (BOXAA *)ERROR_PTR("too many boxa ptrs", __func__, NULL);
1807 if (n == 0) L_INFO("the boxaa is empty\n", __func__);
1808
1809 if ((baa = boxaaCreate(n)) == NULL)
1810 return (BOXAA *)ERROR_PTR("boxaa not made", __func__, NULL);
1811 for (i = 0; i < n; i++) {
1812 if (fscanf(fp, "\nBoxa[%d] extent: x = %d, y = %d, w = %d, h = %d",
1813 &ignore, &x, &y, &w, &h) != 5) {
1814 boxaaDestroy(&baa);
1815 return (BOXAA *)ERROR_PTR("boxa descr not valid", __func__, NULL);
1816 }
1817 if ((boxa = boxaReadStream(fp)) == NULL) {
1818 boxaaDestroy(&baa);
1819 return (BOXAA *)ERROR_PTR("boxa not made", __func__, NULL);
1820 }
1821 boxaaAddBoxa(baa, boxa, L_INSERT);
1822 }
1823 return baa;
1824}
1825
1826
1834BOXAA *
1835boxaaReadMem(const l_uint8 *data,
1836 size_t size)
1837{
1838FILE *fp;
1839BOXAA *baa;
1840
1841 if (!data)
1842 return (BOXAA *)ERROR_PTR("data not defined", __func__, NULL);
1843 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1844 return (BOXAA *)ERROR_PTR("stream not opened", __func__, NULL);
1845
1846 baa = boxaaReadStream(fp);
1847 fclose(fp);
1848 if (!baa) L_ERROR("baa not read\n", __func__);
1849 return baa;
1850}
1851
1852
1860l_ok
1861boxaaWrite(const char *filename,
1862 BOXAA *baa)
1863{
1864l_int32 ret;
1865FILE *fp;
1866
1867 if (!filename)
1868 return ERROR_INT("filename not defined", __func__, 1);
1869 if (!baa)
1870 return ERROR_INT("baa not defined", __func__, 1);
1871
1872 if ((fp = fopenWriteStream(filename, "w")) == NULL)
1873 return ERROR_INT_1("stream not opened", filename, __func__, 1);
1874 ret = boxaaWriteStream(fp, baa);
1875 fclose(fp);
1876 if (ret)
1877 return ERROR_INT_1("baa not written to stream", filename, __func__, 1);
1878 return 0;
1879}
1880
1881
1889l_ok
1891 BOXAA *baa)
1892{
1893l_int32 n, i, x, y, w, h;
1894BOX *box;
1895BOXA *boxa;
1896
1897 if (!fp)
1898 return ERROR_INT("stream not defined", __func__, 1);
1899 if (!baa)
1900 return ERROR_INT("baa not defined", __func__, 1);
1901
1902 n = boxaaGetCount(baa);
1903 fprintf(fp, "\nBoxaa Version %d\n", BOXAA_VERSION_NUMBER);
1904 fprintf(fp, "Number of boxa = %d\n", n);
1905
1906 for (i = 0; i < n; i++) {
1907 if ((boxa = boxaaGetBoxa(baa, i, L_CLONE)) == NULL)
1908 return ERROR_INT("boxa not found", __func__, 1);
1909 boxaGetExtent(boxa, NULL, NULL, &box);
1910 boxGetGeometry(box, &x, &y, &w, &h);
1911 fprintf(fp, "\nBoxa[%d] extent: x = %d, y = %d, w = %d, h = %d",
1912 i, x, y, w, h);
1913 boxaWriteStream(fp, boxa);
1914 boxDestroy(&box);
1915 boxaDestroy(&boxa);
1916 }
1917 return 0;
1918}
1919
1920
1934l_ok
1935boxaaWriteMem(l_uint8 **pdata,
1936 size_t *psize,
1937 BOXAA *baa)
1938{
1939l_int32 ret;
1940FILE *fp;
1941
1942 if (pdata) *pdata = NULL;
1943 if (psize) *psize = 0;
1944 if (!pdata)
1945 return ERROR_INT("&data not defined", __func__, 1);
1946 if (!psize)
1947 return ERROR_INT("&size not defined", __func__, 1);
1948 if (!baa)
1949 return ERROR_INT("baa not defined", __func__, 1);
1950
1951#if HAVE_FMEMOPEN
1952 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1953 return ERROR_INT("stream not opened", __func__, 1);
1954 ret = boxaaWriteStream(fp, baa);
1955 fputc('\0', fp);
1956 fclose(fp);
1957 if (*psize > 0) *psize = *psize - 1;
1958#else
1959 L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
1960 #ifdef _WIN32
1961 if ((fp = fopenWriteWinTempfile()) == NULL)
1962 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1963 #else
1964 if ((fp = tmpfile()) == NULL)
1965 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1966 #endif /* _WIN32 */
1967 ret = boxaaWriteStream(fp, baa);
1968 rewind(fp);
1969 *pdata = l_binaryReadStream(fp, psize);
1970 fclose(fp);
1971#endif /* HAVE_FMEMOPEN */
1972 return ret;
1973}
1974
1975
1976/*---------------------------------------------------------------------*
1977 * Boxa serialized I/O *
1978 *---------------------------------------------------------------------*/
1985BOXA *
1986boxaRead(const char *filename)
1987{
1988FILE *fp;
1989BOXA *boxa;
1990
1991 if (!filename)
1992 return (BOXA *)ERROR_PTR("filename not defined", __func__, NULL);
1993
1994 if ((fp = fopenReadStream(filename)) == NULL)
1995 return (BOXA *)ERROR_PTR_1("stream not opened",
1996 filename, __func__, NULL);
1997 boxa = boxaReadStream(fp);
1998 fclose(fp);
1999 if (!boxa)
2000 return (BOXA *)ERROR_PTR_1("boxa not read",
2001 filename, __func__, NULL);
2002 return boxa;
2003}
2004
2005
2017BOXA *
2019{
2020l_int32 n, i, x, y, w, h, version;
2021l_int32 ignore;
2022BOX *box;
2023BOXA *boxa;
2024
2025 if (!fp)
2026 return (BOXA *)ERROR_PTR("stream not defined", __func__, NULL);
2027
2028 if (fscanf(fp, "\nBoxa Version %d\n", &version) != 1)
2029 return (BOXA *)ERROR_PTR("not a boxa file", __func__, NULL);
2030 if (version != BOXA_VERSION_NUMBER)
2031 return (BOXA *)ERROR_PTR("invalid boxa version", __func__, NULL);
2032 if (fscanf(fp, "Number of boxes = %d\n", &n) != 1)
2033 return (BOXA *)ERROR_PTR("not a boxa file", __func__, NULL);
2034 if (n < 0)
2035 return (BOXA *)ERROR_PTR("num box ptrs < 0", __func__, NULL);
2036 if (n > MaxBoxaPtrArraySize)
2037 return (BOXA *)ERROR_PTR("too many box ptrs", __func__, NULL);
2038 if (n == 0) L_INFO("the boxa is empty\n", __func__);
2039
2040 if ((boxa = boxaCreate(n)) == NULL)
2041 return (BOXA *)ERROR_PTR("boxa not made", __func__, NULL);
2042 for (i = 0; i < n; i++) {
2043 if (fscanf(fp, " Box[%d]: x = %d, y = %d, w = %d, h = %d\n",
2044 &ignore, &x, &y, &w, &h) != 5) {
2045 boxaDestroy(&boxa);
2046 return (BOXA *)ERROR_PTR("box descr not valid", __func__, NULL);
2047 }
2048 box = boxCreate(x, y, w, h);
2049 boxaAddBox(boxa, box, L_INSERT);
2050 }
2051 return boxa;
2052}
2053
2054
2062BOXA *
2063boxaReadMem(const l_uint8 *data,
2064 size_t size)
2065{
2066FILE *fp;
2067BOXA *boxa;
2068
2069 if (!data)
2070 return (BOXA *)ERROR_PTR("data not defined", __func__, NULL);
2071 if ((fp = fopenReadFromMemory(data, size)) == NULL)
2072 return (BOXA *)ERROR_PTR("stream not opened", __func__, NULL);
2073
2074 boxa = boxaReadStream(fp);
2075 fclose(fp);
2076 if (!boxa) L_ERROR("boxa not read\n", __func__);
2077 return boxa;
2078}
2079
2080
2097l_ok
2098boxaWriteDebug(const char *filename,
2099 BOXA *boxa)
2100{
2101 if (LeptDebugOK) {
2102 return boxaWrite(filename, boxa);
2103 } else {
2104 L_INFO("write to named temp file %s is disabled\n", __func__, filename);
2105 return 0;
2106 }
2107}
2108
2109
2117l_ok
2118boxaWrite(const char *filename,
2119 BOXA *boxa)
2120{
2121l_int32 ret;
2122FILE *fp;
2123
2124 if (!filename)
2125 return ERROR_INT("filename not defined", __func__, 1);
2126 if (!boxa)
2127 return ERROR_INT("boxa not defined", __func__, 1);
2128
2129 if ((fp = fopenWriteStream(filename, "w")) == NULL)
2130 return ERROR_INT_1("stream not opened", filename, __func__, 1);
2131 ret = boxaWriteStream(fp, boxa);
2132 fclose(fp);
2133 if (ret)
2134 return ERROR_INT_1("boxa not written to stream", filename, __func__, 1);
2135
2136 return 0;
2137}
2138
2139
2147l_ok
2149 BOXA *boxa)
2150{
2151l_int32 n, i;
2152BOX *box;
2153
2154 if (!boxa)
2155 return ERROR_INT("boxa not defined", __func__, 1);
2156 if (!fp)
2157 return boxaWriteStderr(boxa);
2158
2159 n = boxaGetCount(boxa);
2160 fprintf(fp, "\nBoxa Version %d\n", BOXA_VERSION_NUMBER);
2161 fprintf(fp, "Number of boxes = %d\n", n);
2162 for (i = 0; i < n; i++) {
2163 if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL)
2164 return ERROR_INT("box not found", __func__, 1);
2165 fprintf(fp, " Box[%d]: x = %d, y = %d, w = %d, h = %d\n",
2166 i, box->x, box->y, box->w, box->h);
2167 boxDestroy(&box);
2168 }
2169 return 0;
2170}
2171
2172
2179l_ok
2181{
2182l_int32 n, i;
2183BOX *box;
2184
2185 if (!boxa)
2186 return ERROR_INT("boxa not defined", __func__, 1);
2187
2188 n = boxaGetCount(boxa);
2189 lept_stderr("\nBoxa Version %d\n", BOXA_VERSION_NUMBER);
2190 lept_stderr("Number of boxes = %d\n", n);
2191 for (i = 0; i < n; i++) {
2192 if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL)
2193 return ERROR_INT("box not found", __func__, 1);
2194 lept_stderr(" Box[%d]: x = %d, y = %d, w = %d, h = %d\n",
2195 i, box->x, box->y, box->w, box->h);
2196 boxDestroy(&box);
2197 }
2198 return 0;
2199}
2200
2201
2215l_ok
2216boxaWriteMem(l_uint8 **pdata,
2217 size_t *psize,
2218 BOXA *boxa)
2219{
2220l_int32 ret;
2221FILE *fp;
2222
2223 if (pdata) *pdata = NULL;
2224 if (psize) *psize = 0;
2225 if (!pdata)
2226 return ERROR_INT("&data not defined", __func__, 1);
2227 if (!psize)
2228 return ERROR_INT("&size not defined", __func__, 1);
2229 if (!boxa)
2230 return ERROR_INT("boxa not defined", __func__, 1);
2231
2232#if HAVE_FMEMOPEN
2233 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
2234 return ERROR_INT("stream not opened", __func__, 1);
2235 ret = boxaWriteStream(fp, boxa);
2236 fputc('\0', fp);
2237 fclose(fp);
2238 if (*psize > 0) *psize = *psize - 1;
2239#else
2240 L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
2241 #ifdef _WIN32
2242 if ((fp = fopenWriteWinTempfile()) == NULL)
2243 return ERROR_INT("tmpfile stream not opened", __func__, 1);
2244 #else
2245 if ((fp = tmpfile()) == NULL)
2246 return ERROR_INT("tmpfile stream not opened", __func__, 1);
2247 #endif /* _WIN32 */
2248 ret = boxaWriteStream(fp, boxa);
2249 rewind(fp);
2250 *pdata = l_binaryReadStream(fp, psize);
2251 fclose(fp);
2252#endif /* HAVE_FMEMOPEN */
2253 return ret;
2254}
2255
2256
2257/*---------------------------------------------------------------------*
2258 * Debug printing *
2259 *---------------------------------------------------------------------*/
2273l_ok
2275 BOX *box)
2276{
2277 if (!box)
2278 return ERROR_INT("box not defined", __func__, 1);
2279
2280 if (!fp) { /* output to stderr */
2281 lept_stderr(" Box: x = %d, y = %d, w = %d, h = %d\n",
2282 box->x, box->y, box->w, box->h);
2283 } else {
2284 fprintf(fp, " Box: x = %d, y = %d, w = %d, h = %d\n",
2285 box->x, box->y, box->w, box->h);
2286 }
2287 return 0;
2288}
BOXA * boxaReadStream(FILE *fp)
boxaReadStream()
Definition boxbasic.c:2018
l_ok boxaWriteMem(l_uint8 **pdata, size_t *psize, BOXA *boxa)
boxaWriteMem()
Definition boxbasic.c:2216
l_ok boxaaInitFull(BOXAA *baa, BOXA *boxa)
boxaaInitFull()
Definition boxbasic.c:1464
BOX * boxaGetValidBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetValidBox()
Definition boxbasic.c:739
l_int32 boxaGetValidCount(BOXA *boxa)
boxaGetValidCount()
Definition boxbasic.c:676
BOX * boxCopy(BOX *box)
boxCopy()
Definition boxbasic.c:230
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
Definition boxbasic.c:301
l_ok boxaaReplaceBoxa(BOXAA *baa, l_int32 index, BOXA *boxa)
boxaaReplaceBoxa()
Definition boxbasic.c:1542
BOXAA * boxaaRead(const char *filename)
boxaaRead()
Definition boxbasic.c:1755
l_ok boxaClear(BOXA *boxa)
boxaClear()
Definition boxbasic.c:1120
l_ok boxaaWrite(const char *filename, BOXAA *baa)
boxaaWrite()
Definition boxbasic.c:1861
BOXAA * boxaaReadMem(const l_uint8 *data, size_t size)
boxaaReadMem()
Definition boxbasic.c:1835
BOXA * boxaaGetBoxa(BOXAA *baa, l_int32 index, l_int32 accessflag)
boxaaGetBoxa()
Definition boxbasic.c:1386
BOXA * boxaRead(const char *filename)
boxaRead()
Definition boxbasic.c:1986
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
Definition boxbasic.c:702
l_ok boxaaExtendArray(BOXAA *baa)
boxaaExtendArray()
Definition boxbasic.c:1284
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
Definition boxbasic.c:475
l_ok boxaInitFull(BOXA *boxa, BOX *box)
boxaInitFull()
Definition boxbasic.c:1085
l_ok boxaIsFull(BOXA *boxa, l_int32 *pfull)
boxaIsFull()
Definition boxbasic.c:830
l_ok boxaInsertBox(BOXA *boxa, l_int32 index, BOX *box)
boxaInsertBox()
Definition boxbasic.c:911
BOXA * boxaSaveValid(BOXA *boxas, l_int32 copyflag)
boxaSaveValid()
Definition boxbasic.c:1023
void boxDestroy(BOX **pbox)
boxDestroy()
Definition boxbasic.c:273
BOX * boxClone(BOX *box)
boxClone()
Definition boxbasic.c:249
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
Definition boxbasic.c:171
l_ok boxaaRemoveBoxa(BOXAA *baa, l_int32 index)
boxaaRemoveBoxa()
Definition boxbasic.c:1629
BOXA * boxaReadMem(const l_uint8 *data, size_t size)
boxaReadMem()
Definition boxbasic.c:2063
l_ok boxaRemoveBoxAndSave(BOXA *boxa, l_int32 index, BOX **pbox)
boxaRemoveBoxAndSave()
Definition boxbasic.c:981
BOX * boxCreateValid(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreateValid()
Definition boxbasic.c:212
l_ok boxaRemoveBox(BOXA *boxa, l_int32 index)
boxaRemoveBox()
Definition boxbasic.c:957
l_ok boxaReplaceBox(BOXA *boxa, l_int32 index, BOX *box)
boxaReplaceBox()
Definition boxbasic.c:875
l_ok boxGetSideLocations(const BOX *box, l_int32 *pl, l_int32 *pr, l_int32 *pt, l_int32 *pb)
boxGetSideLocations()
Definition boxbasic.c:358
l_int32 boxaaGetCount(BOXAA *baa)
boxaaGetCount()
Definition boxbasic.c:1343
BOXAA * boxaaCreate(l_int32 n)
boxaaCreate()
Definition boxbasic.c:1145
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
Definition boxbasic.c:796
l_ok boxaWriteDebug(const char *filename, BOXA *boxa)
boxaWriteDebug()
Definition boxbasic.c:2098
BOX * boxaaGetBox(BOXAA *baa, l_int32 iboxa, l_int32 ibox, l_int32 accessflag)
boxaaGetBox()
Definition boxbasic.c:1414
l_ok boxaaExtendWithInit(BOXAA *baa, l_int32 maxindex, BOXA *boxa)
boxaaExtendWithInit()
Definition boxbasic.c:1502
static const size_t InitialPtrArraySize
Definition boxbasic.c:143
l_ok boxaWriteStderr(BOXA *boxa)
boxaWriteStderr()
Definition boxbasic.c:2180
l_ok boxaaAddBoxa(BOXAA *baa, BOXA *ba, l_int32 copyflag)
boxaaAddBoxa()
Definition boxbasic.c:1241
l_ok boxaaWriteStream(FILE *fp, BOXAA *baa)
boxaaWriteStream()
Definition boxbasic.c:1890
BOXAA * boxaaCopy(BOXAA *baas, l_int32 copyflag)
boxaaCopy()
Definition boxbasic.c:1178
l_ok boxaExtendArrayToSize(BOXA *boxa, size_t size)
boxaExtendArrayToSize()
Definition boxbasic.c:625
l_ok boxaWrite(const char *filename, BOXA *boxa)
boxaWrite()
Definition boxbasic.c:2118
BOXA * boxaCreate(l_int32 n)
boxaCreate()
Definition boxbasic.c:442
BOXAA * boxaaReadStream(FILE *fp)
boxaaReadStream()
Definition boxbasic.c:1787
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
Definition boxbasic.c:553
l_ok boxaExtendArray(BOXA *boxa)
boxaExtendArray()
Definition boxbasic.c:602
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
Definition boxbasic.c:519
l_int32 boxaGetCount(const BOXA *boxa)
boxaGetCount()
Definition boxbasic.c:661
l_ok boxIsValid(BOX *box, l_int32 *pvalid)
boxIsValid()
Definition boxbasic.c:417
l_ok boxSetGeometry(BOX *box, l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxSetGeometry()
Definition boxbasic.c:329
void boxaaDestroy(BOXAA **pbaa)
boxaaDestroy()
Definition boxbasic.c:1207
l_int32 boxaaGetBoxCount(BOXAA *baa)
boxaaGetBoxCount()
Definition boxbasic.c:1358
l_ok boxaaExtendArrayToSize(BOXAA *baa, l_int32 size)
boxaaExtendArrayToSize()
Definition boxbasic.c:1307
l_ok boxaaInsertBoxa(BOXAA *baa, l_int32 index, BOXA *boxa)
boxaaInsertBoxa()
Definition boxbasic.c:1582
l_ok boxSetSideLocations(BOX *box, l_int32 l, l_int32 r, l_int32 t, l_int32 b)
boxSetSideLocations()
Definition boxbasic.c:390
l_ok boxaWriteStream(FILE *fp, BOXA *boxa)
boxaWriteStream()
Definition boxbasic.c:2148
l_ok boxPrintStreamInfo(FILE *fp, BOX *box)
boxPrintStreamInfo()
Definition boxbasic.c:2274
BOXAA * boxaaReadFromFiles(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
boxaaReadFromFiles()
Definition boxbasic.c:1713
l_ok boxaaAddBox(BOXAA *baa, l_int32 index, BOX *box, l_int32 accessflag)
boxaaAddBox()
Definition boxbasic.c:1667
l_ok boxaaWriteMem(l_uint8 **pdata, size_t *psize, BOXAA *baa)
boxaaWriteMem()
Definition boxbasic.c:1935
NUMA * boxaFindInvalidBoxes(BOXA *boxa)
boxaFindInvalidBoxes()
Definition boxbasic.c:765
@ L_COPY
Definition pix.h:505
@ L_CLONE
Definition pix.h:506
@ L_COPY_CLONE
Definition pix.h:507
@ L_NOCOPY
Definition pix.h:503
@ L_INSERT
Definition pix.h:504
#define BOXAA_VERSION_NUMBER
#define BOXA_VERSION_NUMBER
l_int32 y
l_int32 x
l_int32 w
l_int32 h
l_atomic refcount
l_int32 nalloc
l_int32 n
l_atomic refcount
struct Box ** box
l_int32 nalloc
struct Boxa ** boxa
l_int32 n