Leptonica  1.83.1
Image processing and image analysis suite
fpix1.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 
119 #ifdef HAVE_CONFIG_H
120 #include <config_auto.h>
121 #endif /* HAVE_CONFIG_H */
122 
123 #include <string.h>
124 #include "allheaders.h"
125 #include "pix_internal.h"
126 
127  /* Bounds on array sizes */
128 static const size_t MaxPtrArraySize = 100000;
129 static const size_t InitialPtrArraySize = 20;
131  /* Static functions */
132 static l_int32 fpixaExtendArray(FPIXA *fpixa);
133 static l_int32 fpixaExtendArrayToSize(FPIXA *fpixa, l_int32 size);
134 
135 /*--------------------------------------------------------------------*
136  * FPix Create/copy/destroy *
137  *--------------------------------------------------------------------*/
151 FPIX *
152 fpixCreate(l_int32 width,
153  l_int32 height)
154 {
155 l_float32 *data;
156 l_uint64 npix64;
157 FPIX *fpixd;
158 
159  if (width <= 0)
160  return (FPIX *)ERROR_PTR("width must be > 0", __func__, NULL);
161  if (height <= 0)
162  return (FPIX *)ERROR_PTR("height must be > 0", __func__, NULL);
163 
164  /* Avoid overflow in malloc arg, malicious or otherwise */
165  npix64 = (l_uint64)width * (l_uint64)height; /* # of 4-byte pixels */
166  if (npix64 >= (1LL << 29)) {
167  L_ERROR("requested w = %d, h = %d\n", __func__, width, height);
168  return (FPIX *)ERROR_PTR("requested bytes >= 2^31", __func__, NULL);
169  }
170 
171  fpixd = (FPIX *)LEPT_CALLOC(1, sizeof(FPIX));
172  fpixSetDimensions(fpixd, width, height);
173  fpixSetWpl(fpixd, width); /* 4-byte words */
174  fpixd->refcount = 1;
175 
176  data = (l_float32 *)LEPT_CALLOC((size_t)width * height, sizeof(l_float32));
177  if (!data) {
178  fpixDestroy(&fpixd);
179  return (FPIX *)ERROR_PTR("calloc fail for data", __func__, NULL);
180  }
181  fpixSetData(fpixd, data);
182  return fpixd;
183 }
184 
185 
199 FPIX *
201 {
202 l_int32 w, h;
203 FPIX *fpixd;
204 
205  if (!fpixs)
206  return (FPIX *)ERROR_PTR("fpixs not defined", __func__, NULL);
207 
208  fpixGetDimensions(fpixs, &w, &h);
209  if ((fpixd = fpixCreate(w, h)) == NULL)
210  return (FPIX *)ERROR_PTR("fpixd not made", __func__, NULL);
211  fpixCopyResolution(fpixd, fpixs);
212  return fpixd;
213 }
214 
215 
227 FPIX *
229 {
230  if (!fpix)
231  return (FPIX *)ERROR_PTR("fpix not defined", __func__, NULL);
232  ++fpix->refcount;
233 
234  return fpix;
235 }
236 
237 
244 FPIX *
245 fpixCopy(FPIX *fpixs)
246 {
247 l_int32 w, h, bytes;
248 l_float32 *datas, *datad;
249 FPIX *fpixd;
250 
251  if (!fpixs)
252  return (FPIX *)ERROR_PTR("fpixs not defined", __func__, NULL);
253 
254  /* Total bytes in image data */
255  fpixGetDimensions(fpixs, &w, &h);
256  bytes = 4 * w * h;
257 
258  if ((fpixd = fpixCreateTemplate(fpixs)) == NULL)
259  return (FPIX *)ERROR_PTR("fpixd not made", __func__, NULL);
260  datas = fpixGetData(fpixs);
261  datad = fpixGetData(fpixd);
262  memcpy(datad, datas, bytes);
263  return fpixd;
264 }
265 
266 
279 void
281 {
282 l_float32 *data;
283 FPIX *fpix;
284 
285  if (!pfpix) {
286  L_WARNING("ptr address is null!\n", __func__);
287  return;
288  }
289 
290  if ((fpix = *pfpix) == NULL)
291  return;
292 
293  /* Decrement the ref count. If it is 0, destroy the fpix. */
294  if (--fpix->refcount == 0) {
295  if ((data = fpixGetData(fpix)) != NULL)
296  LEPT_FREE(data);
297  LEPT_FREE(fpix);
298  }
299  *pfpix = NULL;
300 }
301 
302 
303 /*--------------------------------------------------------------------*
304  * FPix Accessors *
305  *--------------------------------------------------------------------*/
313 l_ok
315  l_int32 *pw,
316  l_int32 *ph)
317 {
318  if (!pw && !ph)
319  return ERROR_INT("no return val requested", __func__, 1);
320  if (pw) *pw = 0;
321  if (ph) *ph = 0;
322  if (!fpix)
323  return ERROR_INT("fpix not defined", __func__, 1);
324  if (pw) *pw = fpix->w;
325  if (ph) *ph = fpix->h;
326  return 0;
327 }
328 
329 
337 l_ok
339  l_int32 w,
340  l_int32 h)
341 {
342  if (!fpix)
343  return ERROR_INT("fpix not defined", __func__, 1);
344  fpix->w = w;
345  fpix->h = h;
346  return 0;
347 }
348 
349 
356 l_int32
358 {
359  if (!fpix)
360  return ERROR_INT("fpix not defined", __func__, 0);
361  return fpix->wpl;
362 }
363 
364 
372 l_ok
374  l_int32 wpl)
375 {
376  if (!fpix)
377  return ERROR_INT("fpix not defined", __func__, 1);
378 
379  fpix->wpl = wpl;
380  return 0;
381 }
382 
383 
391 l_ok
393  l_int32 *pxres,
394  l_int32 *pyres)
395 {
396  if (!fpix)
397  return ERROR_INT("fpix not defined", __func__, 1);
398  if (pxres) *pxres = fpix->xres;
399  if (pyres) *pyres = fpix->yres;
400  return 0;
401 }
402 
403 
411 l_ok
413  l_int32 xres,
414  l_int32 yres)
415 {
416  if (!fpix)
417  return ERROR_INT("fpix not defined", __func__, 1);
418 
419  fpix->xres = xres;
420  fpix->yres = yres;
421  return 0;
422 }
423 
424 
431 l_ok
433  FPIX *fpixs)
434 {
435 l_int32 xres, yres;
436  if (!fpixs || !fpixd)
437  return ERROR_INT("fpixs and fpixd not both defined", __func__, 1);
438 
439  fpixGetResolution(fpixs, &xres, &yres);
440  fpixSetResolution(fpixd, xres, yres);
441  return 0;
442 }
443 
444 
451 l_float32 *
453 {
454  if (!fpix)
455  return (l_float32 *)ERROR_PTR("fpix not defined", __func__, NULL);
456  return fpix->data;
457 }
458 
459 
467 l_ok
469  l_float32 *data)
470 {
471  if (!fpix)
472  return ERROR_INT("fpix not defined", __func__, 1);
473 
474  fpix->data = data;
475  return 0;
476 }
477 
478 
491 l_ok
493  l_int32 x,
494  l_int32 y,
495  l_float32 *pval)
496 {
497 l_int32 w, h;
498 
499  if (!pval)
500  return ERROR_INT("pval not defined", __func__, 1);
501  *pval = 0.0;
502  if (!fpix)
503  return ERROR_INT("fpix not defined", __func__, 1);
504 
505  fpixGetDimensions(fpix, &w, &h);
506  if (x < 0 || x >= w || y < 0 || y >= h)
507  return 2;
508 
509  *pval = *(fpix->data + y * w + x);
510  return 0;
511 }
512 
513 
526 l_ok
528  l_int32 x,
529  l_int32 y,
530  l_float32 val)
531 {
532 l_int32 w, h;
533 
534  if (!fpix)
535  return ERROR_INT("fpix not defined", __func__, 1);
536 
537  fpixGetDimensions(fpix, &w, &h);
538  if (x < 0 || x >= w || y < 0 || y >= h)
539  return 2;
540 
541  *(fpix->data + y * w + x) = val;
542  return 0;
543 }
544 
545 
546 /*--------------------------------------------------------------------*
547  * FPixa Create/copy/destroy *
548  *--------------------------------------------------------------------*/
555 FPIXA *
556 fpixaCreate(l_int32 n)
557 {
558 FPIXA *fpixa;
559 
560  if (n <= 0 || n > MaxPtrArraySize)
562 
563  fpixa = (FPIXA *)LEPT_CALLOC(1, sizeof(FPIXA));
564  fpixa->n = 0;
565  fpixa->nalloc = n;
566  fpixa->refcount = 1;
567  fpixa->fpix = (FPIX **)LEPT_CALLOC(n, sizeof(FPIX *));
568  return fpixa;
569 }
570 
571 
587 FPIXA *
589  l_int32 copyflag)
590 {
591 l_int32 i;
592 FPIX *fpixc;
593 FPIXA *fpixac;
594 
595  if (!fpixa)
596  return (FPIXA *)ERROR_PTR("fpixa not defined", __func__, NULL);
597 
598  if (copyflag == L_CLONE) {
599  ++fpixa->refcount;
600  return fpixa;
601  }
602 
603  if (copyflag != L_COPY && copyflag != L_COPY_CLONE)
604  return (FPIXA *)ERROR_PTR("invalid copyflag", __func__, NULL);
605 
606  if ((fpixac = fpixaCreate(fpixa->n)) == NULL)
607  return (FPIXA *)ERROR_PTR("fpixac not made", __func__, NULL);
608  for (i = 0; i < fpixa->n; i++) {
609  if (copyflag == L_COPY)
610  fpixc = fpixaGetFPix(fpixa, i, L_COPY);
611  else /* copy-clone */
612  fpixc = fpixaGetFPix(fpixa, i, L_CLONE);
613  fpixaAddFPix(fpixac, fpixc, L_INSERT);
614  }
615 
616  return fpixac;
617 }
618 
619 
632 void
634 {
635 l_int32 i;
636 FPIXA *fpixa;
637 
638  if (pfpixa == NULL) {
639  L_WARNING("ptr address is NULL!\n", __func__);
640  return;
641  }
642 
643  if ((fpixa = *pfpixa) == NULL)
644  return;
645 
646  /* Decrement the refcount. If it is 0, destroy the pixa. */
647  if (--fpixa->refcount == 0) {
648  for (i = 0; i < fpixa->n; i++)
649  fpixDestroy(&fpixa->fpix[i]);
650  LEPT_FREE(fpixa->fpix);
651  LEPT_FREE(fpixa);
652  }
653  *pfpixa = NULL;
654 }
655 
656 
657 /*--------------------------------------------------------------------*
658  * FPixa addition *
659  *--------------------------------------------------------------------*/
668 l_ok
670  FPIX *fpix,
671  l_int32 copyflag)
672 {
673 l_int32 n;
674 FPIX *fpixc;
675 
676  if (!fpixa)
677  return ERROR_INT("fpixa not defined", __func__, 1);
678  if (!fpix)
679  return ERROR_INT("fpix not defined", __func__, 1);
680 
681  if (copyflag == L_INSERT)
682  fpixc = fpix;
683  else if (copyflag == L_COPY)
684  fpixc = fpixCopy(fpix);
685  else if (copyflag == L_CLONE)
686  fpixc = fpixClone(fpix);
687  else
688  return ERROR_INT("invalid copyflag", __func__, 1);
689  if (!fpixc)
690  return ERROR_INT("fpixc not made", __func__, 1);
691 
692  n = fpixaGetCount(fpixa);
693  if (n >= fpixa->nalloc) {
694  if (fpixaExtendArray(fpixa)) {
695  if (copyflag != L_INSERT)
696  fpixDestroy(&fpixc);
697  return ERROR_INT("extension failed", __func__, 1);
698  }
699  }
700  fpixa->fpix[n] = fpixc;
701  fpixa->n++;
702  return 0;
703 }
704 
705 
718 static l_int32
720 {
721  if (!fpixa)
722  return ERROR_INT("fpixa not defined", __func__, 1);
723 
724  return fpixaExtendArrayToSize(fpixa, 2 * fpixa->nalloc);
725 }
726 
727 
741 static l_int32
743  l_int32 size)
744 {
745 size_t oldsize, newsize;
746 
747  if (!fpixa)
748  return ERROR_INT("fpixa not defined", __func__, 1);
749  if (fpixa->nalloc > MaxPtrArraySize) /* belt & suspenders */
750  return ERROR_INT("fpixa has too many ptrs", __func__, 1);
751  if (size > MaxPtrArraySize)
752  return ERROR_INT("size > 100K ptrs; too large", __func__, 1);
753  if (size <= fpixa->nalloc) {
754  L_INFO("size too small; no extension\n", __func__);
755  return 0;
756  }
757 
758  oldsize = fpixa->nalloc * sizeof(FPIX *);
759  newsize = size * sizeof(FPIX *);
760  if ((fpixa->fpix = (FPIX **)reallocNew((void **)&fpixa->fpix,
761  oldsize, newsize)) == NULL)
762  return ERROR_INT("new ptr array not returned", __func__, 1);
763  fpixa->nalloc = size;
764  return 0;
765 }
766 
767 
768 /*--------------------------------------------------------------------*
769  * FPixa accessors *
770  *--------------------------------------------------------------------*/
777 l_int32
779 {
780  if (!fpixa)
781  return ERROR_INT("fpixa not defined", __func__, 0);
782 
783  return fpixa->n;
784 }
785 
786 
795 FPIX *
797  l_int32 index,
798  l_int32 accesstype)
799 {
800  if (!fpixa)
801  return (FPIX *)ERROR_PTR("fpixa not defined", __func__, NULL);
802  if (index < 0 || index >= fpixa->n)
803  return (FPIX *)ERROR_PTR("index not valid", __func__, NULL);
804 
805  if (accesstype == L_COPY)
806  return fpixCopy(fpixa->fpix[index]);
807  else if (accesstype == L_CLONE)
808  return fpixClone(fpixa->fpix[index]);
809  else
810  return (FPIX *)ERROR_PTR("invalid accesstype", __func__, NULL);
811 }
812 
813 
822 l_ok
824  l_int32 index,
825  l_int32 *pw,
826  l_int32 *ph)
827 {
828 FPIX *fpix;
829 
830  if (!pw && !ph)
831  return ERROR_INT("no return val requested", __func__, 1);
832  if (pw) *pw = 0;
833  if (ph) *ph = 0;
834  if (!fpixa)
835  return ERROR_INT("fpixa not defined", __func__, 1);
836  if (index < 0 || index >= fpixa->n)
837  return ERROR_INT("index not valid", __func__, 1);
838 
839  if ((fpix = fpixaGetFPix(fpixa, index, L_CLONE)) == NULL)
840  return ERROR_INT("fpix not found!", __func__, 1);
841  fpixGetDimensions(fpix, pw, ph);
842  fpixDestroy(&fpix);
843  return 0;
844 }
845 
846 
854 l_float32 *
856  l_int32 index)
857 {
858 l_int32 n;
859 l_float32 *data;
860 FPIX *fpix;
861 
862  if (!fpixa)
863  return (l_float32 *)ERROR_PTR("fpixa not defined", __func__, NULL);
864  n = fpixaGetCount(fpixa);
865  if (index < 0 || index >= n)
866  return (l_float32 *)ERROR_PTR("invalid index", __func__, NULL);
867 
868  fpix = fpixaGetFPix(fpixa, index, L_CLONE);
869  data = fpixGetData(fpix);
870  fpixDestroy(&fpix);
871  return data;
872 }
873 
874 
884 l_ok
886  l_int32 index,
887  l_int32 x,
888  l_int32 y,
889  l_float32 *pval)
890 {
891 l_int32 n, ret;
892 FPIX *fpix;
893 
894  if (!pval)
895  return ERROR_INT("pval not defined", __func__, 1);
896  *pval = 0.0;
897  if (!fpixa)
898  return ERROR_INT("fpixa not defined", __func__, 1);
899  n = fpixaGetCount(fpixa);
900  if (index < 0 || index >= n)
901  return ERROR_INT("invalid index into fpixa", __func__, 1);
902 
903  fpix = fpixaGetFPix(fpixa, index, L_CLONE);
904  ret = fpixGetPixel(fpix, x, y, pval);
905  fpixDestroy(&fpix);
906  return ret;
907 }
908 
909 
919 l_ok
921  l_int32 index,
922  l_int32 x,
923  l_int32 y,
924  l_float32 val)
925 {
926 l_int32 n, ret;
927 FPIX *fpix;
928 
929  if (!fpixa)
930  return ERROR_INT("fpixa not defined", __func__, 1);
931  n = fpixaGetCount(fpixa);
932  if (index < 0 || index >= n)
933  return ERROR_INT("invalid index into fpixa", __func__, 1);
934 
935  fpix = fpixaGetFPix(fpixa, index, L_CLONE);
936  ret = fpixSetPixel(fpix, x, y, val);
937  fpixDestroy(&fpix);
938  return ret;
939 }
940 
941 
942 /*--------------------------------------------------------------------*
943  * DPix Create/copy/destroy *
944  *--------------------------------------------------------------------*/
958 DPIX *
959 dpixCreate(l_int32 width,
960  l_int32 height)
961 {
962 l_float64 *data;
963 l_uint64 npix64;
964 DPIX *dpix;
965 
966  if (width <= 0)
967  return (DPIX *)ERROR_PTR("width must be > 0", __func__, NULL);
968  if (height <= 0)
969  return (DPIX *)ERROR_PTR("height must be > 0", __func__, NULL);
970 
971  /* Avoid overflow in malloc arg, malicious or otherwise */
972  npix64 = (l_uint64)width * (l_uint64)height; /* # of 8 byte pixels */
973  if (npix64 >= (1LL << 28)) {
974  L_ERROR("requested w = %d, h = %d\n", __func__, width, height);
975  return (DPIX *)ERROR_PTR("requested bytes >= 2^31", __func__, NULL);
976  }
977 
978  dpix = (DPIX *)LEPT_CALLOC(1, sizeof(DPIX));
979  dpixSetDimensions(dpix, width, height);
980  dpixSetWpl(dpix, width); /* 8 byte words */
981  dpix->refcount = 1;
982 
983  data = (l_float64 *)LEPT_CALLOC((size_t)width * height, sizeof(l_float64));
984  if (!data) {
985  dpixDestroy(&dpix);
986  return (DPIX *)ERROR_PTR("calloc fail for data", __func__, NULL);
987  }
988  dpixSetData(dpix, data);
989  return dpix;
990 }
991 
992 
1006 DPIX *
1008 {
1009 l_int32 w, h;
1010 DPIX *dpixd;
1011 
1012  if (!dpixs)
1013  return (DPIX *)ERROR_PTR("dpixs not defined", __func__, NULL);
1014 
1015  dpixGetDimensions(dpixs, &w, &h);
1016  dpixd = dpixCreate(w, h);
1017  dpixCopyResolution(dpixd, dpixs);
1018  return dpixd;
1019 }
1020 
1021 
1033 DPIX *
1035 {
1036  if (!dpix)
1037  return (DPIX *)ERROR_PTR("dpix not defined", __func__, NULL);
1038  ++dpix->refcount;
1039  return dpix;
1040 }
1041 
1042 
1049 DPIX *
1051 {
1052 l_int32 w, h, bytes;
1053 l_float64 *datas, *datad;
1054 DPIX *dpixd;
1055 
1056  if (!dpixs)
1057  return (DPIX *)ERROR_PTR("dpixs not defined", __func__, NULL);
1058 
1059  /* Total bytes in image data */
1060  dpixGetDimensions(dpixs, &w, &h);
1061  bytes = 8 * w * h;
1062 
1063  if ((dpixd = dpixCreateTemplate(dpixs)) == NULL)
1064  return (DPIX *)ERROR_PTR("dpixd not made", __func__, NULL);
1065  datas = dpixGetData(dpixs);
1066  datad = dpixGetData(dpixd);
1067  memcpy(datad, datas, bytes);
1068  return dpixd;
1069 }
1070 
1071 
1084 void
1086 {
1087 l_float64 *data;
1088 DPIX *dpix;
1089 
1090  if (!pdpix) {
1091  L_WARNING("ptr address is null!\n", __func__);
1092  return;
1093  }
1094 
1095  if ((dpix = *pdpix) == NULL)
1096  return;
1097 
1098  /* Decrement the ref count. If it is 0, destroy the dpix. */
1099  if (--dpix->refcount == 0) {
1100  if ((data = dpixGetData(dpix)) != NULL)
1101  LEPT_FREE(data);
1102  LEPT_FREE(dpix);
1103  }
1104  *pdpix = NULL;
1105 }
1106 
1107 
1108 /*--------------------------------------------------------------------*
1109  * DPix Accessors *
1110  *--------------------------------------------------------------------*/
1118 l_ok
1120  l_int32 *pw,
1121  l_int32 *ph)
1122 {
1123  if (!pw && !ph)
1124  return ERROR_INT("no return val requested", __func__, 1);
1125  if (pw) *pw = 0;
1126  if (ph) *ph = 0;
1127  if (!dpix)
1128  return ERROR_INT("dpix not defined", __func__, 1);
1129  if (pw) *pw = dpix->w;
1130  if (ph) *ph = dpix->h;
1131  return 0;
1132 }
1133 
1134 
1142 l_ok
1144  l_int32 w,
1145  l_int32 h)
1146 {
1147  if (!dpix)
1148  return ERROR_INT("dpix not defined", __func__, 1);
1149  dpix->w = w;
1150  dpix->h = h;
1151  return 0;
1152 }
1153 
1154 
1161 l_int32
1163 {
1164  if (!dpix)
1165  return ERROR_INT("dpix not defined", __func__, 0);
1166  return dpix->wpl;
1167 }
1168 
1169 
1177 l_ok
1179  l_int32 wpl)
1180 {
1181  if (!dpix)
1182  return ERROR_INT("dpix not defined", __func__, 1);
1183 
1184  dpix->wpl = wpl;
1185  return 0;
1186 }
1187 
1188 
1196 l_ok
1198  l_int32 *pxres,
1199  l_int32 *pyres)
1200 {
1201  if (!dpix)
1202  return ERROR_INT("dpix not defined", __func__, 1);
1203  if (pxres) *pxres = dpix->xres;
1204  if (pyres) *pyres = dpix->yres;
1205  return 0;
1206 }
1207 
1208 
1216 l_ok
1218  l_int32 xres,
1219  l_int32 yres)
1220 {
1221  if (!dpix)
1222  return ERROR_INT("dpix not defined", __func__, 1);
1223 
1224  dpix->xres = xres;
1225  dpix->yres = yres;
1226  return 0;
1227 }
1228 
1229 
1236 l_ok
1238  DPIX *dpixs)
1239 {
1240 l_int32 xres, yres;
1241  if (!dpixs || !dpixd)
1242  return ERROR_INT("dpixs and dpixd not both defined", __func__, 1);
1243 
1244  dpixGetResolution(dpixs, &xres, &yres);
1245  dpixSetResolution(dpixd, xres, yres);
1246  return 0;
1247 }
1248 
1249 
1256 l_float64 *
1258 {
1259  if (!dpix)
1260  return (l_float64 *)ERROR_PTR("dpix not defined", __func__, NULL);
1261  return dpix->data;
1262 }
1263 
1264 
1272 l_ok
1274  l_float64 *data)
1275 {
1276  if (!dpix)
1277  return ERROR_INT("dpix not defined", __func__, 1);
1278 
1279  dpix->data = data;
1280  return 0;
1281 }
1282 
1283 
1296 l_ok
1298  l_int32 x,
1299  l_int32 y,
1300  l_float64 *pval)
1301 {
1302 l_int32 w, h;
1303 
1304  if (!pval)
1305  return ERROR_INT("pval not defined", __func__, 1);
1306  *pval = 0.0;
1307  if (!dpix)
1308  return ERROR_INT("dpix not defined", __func__, 1);
1309 
1310  dpixGetDimensions(dpix, &w, &h);
1311  if (x < 0 || x >= w || y < 0 || y >= h)
1312  return 2;
1313 
1314  *pval = *(dpix->data + y * w + x);
1315  return 0;
1316 }
1317 
1318 
1331 l_ok
1333  l_int32 x,
1334  l_int32 y,
1335  l_float64 val)
1336 {
1337 l_int32 w, h;
1338 
1339  if (!dpix)
1340  return ERROR_INT("dpix not defined", __func__, 1);
1341 
1342  dpixGetDimensions(dpix, &w, &h);
1343  if (x < 0 || x >= w || y < 0 || y >= h)
1344  return 2;
1345 
1346  *(dpix->data + y * w + x) = val;
1347  return 0;
1348 }
1349 
1350 
1351 /*--------------------------------------------------------------------*
1352  * FPix serialized I/O *
1353  *--------------------------------------------------------------------*/
1360 FPIX *
1361 fpixRead(const char *filename)
1362 {
1363 FILE *fp;
1364 FPIX *fpix;
1365 
1366  if (!filename)
1367  return (FPIX *)ERROR_PTR("filename not defined", __func__, NULL);
1368 
1369  if ((fp = fopenReadStream(filename)) == NULL)
1370  return (FPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1371  fpix = fpixReadStream(fp);
1372  fclose(fp);
1373  if (!fpix)
1374  return (FPIX *)ERROR_PTR("fpix not read", __func__, NULL);
1375  return fpix;
1376 }
1377 
1378 
1385 FPIX *
1387 {
1388 char buf[256];
1389 l_int32 w, h, nbytes, xres, yres, version;
1390 l_float32 *data;
1391 FPIX *fpix;
1392 
1393  if (!fp)
1394  return (FPIX *)ERROR_PTR("stream not defined", __func__, NULL);
1395 
1396  if (fscanf(fp, "\nFPix Version %d\n", &version) != 1)
1397  return (FPIX *)ERROR_PTR("not a fpix file", __func__, NULL);
1398  if (version != FPIX_VERSION_NUMBER)
1399  return (FPIX *)ERROR_PTR("invalid fpix version", __func__, NULL);
1400  if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1401  return (FPIX *)ERROR_PTR("read fail for data size", __func__, NULL);
1402 
1403  /* Use fgets() and sscanf(); not fscanf(), for the last
1404  * bit of header data before the float data. The reason is
1405  * that fscanf throws away white space, and if the float data
1406  * happens to begin with ascii character(s) that are white
1407  * space, it will swallow them and all will be lost! */
1408  if (fgets(buf, sizeof(buf), fp) == NULL)
1409  return (FPIX *)ERROR_PTR("fgets read fail", __func__, NULL);
1410  if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1411  return (FPIX *)ERROR_PTR("read fail for xres, yres", __func__, NULL);
1412 
1413  if ((fpix = fpixCreate(w, h)) == NULL)
1414  return (FPIX *)ERROR_PTR("fpix not made", __func__, NULL);
1415  fpixSetResolution(fpix, xres, yres);
1416  data = fpixGetData(fpix);
1417  if (fread(data, 1, nbytes, fp) != nbytes) {
1418  fpixDestroy(&fpix);
1419  return (FPIX *)ERROR_PTR("read error for nbytes", __func__, NULL);
1420  }
1421  fgetc(fp); /* ending nl */
1422 
1423  /* Convert to little-endian if necessary */
1424  fpixEndianByteSwap(fpix, fpix);
1425  return fpix;
1426 }
1427 
1428 
1436 FPIX *
1437 fpixReadMem(const l_uint8 *data,
1438  size_t size)
1439 {
1440 FILE *fp;
1441 FPIX *fpix;
1442 
1443  if (!data)
1444  return (FPIX *)ERROR_PTR("data not defined", __func__, NULL);
1445  if ((fp = fopenReadFromMemory(data, size)) == NULL)
1446  return (FPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1447 
1448  fpix = fpixReadStream(fp);
1449  fclose(fp);
1450  if (!fpix) L_ERROR("fpix not read\n", __func__);
1451  return fpix;
1452 }
1453 
1454 
1462 l_ok
1463 fpixWrite(const char *filename,
1464  FPIX *fpix)
1465 {
1466 l_int32 ret;
1467 FILE *fp;
1468 
1469  if (!filename)
1470  return ERROR_INT("filename not defined", __func__, 1);
1471  if (!fpix)
1472  return ERROR_INT("fpix not defined", __func__, 1);
1473 
1474  if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1475  return ERROR_INT("stream not opened", __func__, 1);
1476  ret = fpixWriteStream(fp, fpix);
1477  fclose(fp);
1478  if (ret)
1479  return ERROR_INT("fpix not written to stream", __func__, 1);
1480  return 0;
1481 }
1482 
1483 
1491 l_ok
1493  FPIX *fpix)
1494 {
1495 l_int32 w, h, xres, yres;
1496 l_uint32 nbytes;
1497 l_float32 *data;
1498 FPIX *fpixt;
1499 
1500  if (!fp)
1501  return ERROR_INT("stream not defined", __func__, 1);
1502  if (!fpix)
1503  return ERROR_INT("fpix not defined", __func__, 1);
1504 
1505  /* Convert to little-endian if necessary */
1506  fpixt = fpixEndianByteSwap(NULL, fpix);
1507 
1508  fpixGetDimensions(fpixt, &w, &h);
1509  data = fpixGetData(fpixt);
1510  nbytes = sizeof(l_float32) * w * h;
1511  fpixGetResolution(fpixt, &xres, &yres);
1512  fprintf(fp, "\nFPix Version %d\n", FPIX_VERSION_NUMBER);
1513  fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
1514  fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
1515  fwrite(data, 1, nbytes, fp);
1516  fprintf(fp, "\n");
1517 
1518  fpixDestroy(&fpixt);
1519  return 0;
1520 }
1521 
1522 
1536 l_ok
1537 fpixWriteMem(l_uint8 **pdata,
1538  size_t *psize,
1539  FPIX *fpix)
1540 {
1541 l_int32 ret;
1542 FILE *fp;
1543 
1544  if (pdata) *pdata = NULL;
1545  if (psize) *psize = 0;
1546  if (!pdata)
1547  return ERROR_INT("&data not defined", __func__, 1);
1548  if (!psize)
1549  return ERROR_INT("&size not defined", __func__, 1);
1550  if (!fpix)
1551  return ERROR_INT("fpix not defined", __func__, 1);
1552 
1553 #if HAVE_FMEMOPEN
1554  if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1555  return ERROR_INT("stream not opened", __func__, 1);
1556  ret = fpixWriteStream(fp, fpix);
1557  fputc('\0', fp);
1558  fclose(fp);
1559  *psize = *psize - 1;
1560 #else
1561  L_INFO("work-around: writing to a temp file\n", __func__);
1562  #ifdef _WIN32
1563  if ((fp = fopenWriteWinTempfile()) == NULL)
1564  return ERROR_INT("tmpfile stream not opened", __func__, 1);
1565  #else
1566  if ((fp = tmpfile()) == NULL)
1567  return ERROR_INT("tmpfile stream not opened", __func__, 1);
1568  #endif /* _WIN32 */
1569  ret = fpixWriteStream(fp, fpix);
1570  rewind(fp);
1571  *pdata = l_binaryReadStream(fp, psize);
1572  fclose(fp);
1573 #endif /* HAVE_FMEMOPEN */
1574  return ret;
1575 }
1576 
1577 
1597 FPIX *
1599  FPIX *fpixs)
1600 {
1601  if (!fpixs)
1602  return (FPIX *)ERROR_PTR("fpixs not defined", __func__, fpixd);
1603  if (fpixd && (fpixs != fpixd))
1604  return (FPIX *)ERROR_PTR("fpixd != fpixs", __func__, fpixd);
1605 
1606 #ifdef L_BIG_ENDIAN
1607  {
1608  l_uint32 *data;
1609  l_int32 i, j, w, h;
1610  l_uint32 word;
1611 
1612  fpixGetDimensions(fpixs, &w, &h);
1613  if (!fpixd)
1614  fpixd = fpixCopy(fpixs);
1615 
1616  data = (l_uint32 *)fpixGetData(fpixd);
1617  for (i = 0; i < h; i++) {
1618  for (j = 0; j < w; j++, data++) {
1619  word = *data;
1620  *data = (word >> 24) |
1621  ((word >> 8) & 0x0000ff00) |
1622  ((word << 8) & 0x00ff0000) |
1623  (word << 24);
1624  }
1625  }
1626  return fpixd;
1627  }
1628 #else /* L_LITTLE_ENDIAN */
1629 
1630  if (fpixd)
1631  return fpixd; /* no-op */
1632  else
1633  return fpixClone(fpixs);
1634 
1635 #endif /* L_BIG_ENDIAN */
1636 }
1637 
1638 
1639 /*--------------------------------------------------------------------*
1640  * DPix serialized I/O *
1641  *--------------------------------------------------------------------*/
1648 DPIX *
1649 dpixRead(const char *filename)
1650 {
1651 FILE *fp;
1652 DPIX *dpix;
1653 
1654  if (!filename)
1655  return (DPIX *)ERROR_PTR("filename not defined", __func__, NULL);
1656 
1657  if ((fp = fopenReadStream(filename)) == NULL)
1658  return (DPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1659  dpix = dpixReadStream(fp);
1660  fclose(fp);
1661  if (!dpix)
1662  return (DPIX *)ERROR_PTR("dpix not read", __func__, NULL);
1663  return dpix;
1664 }
1665 
1666 
1673 DPIX *
1675 {
1676 char buf[256];
1677 l_int32 w, h, nbytes, version, xres, yres;
1678 l_float64 *data;
1679 DPIX *dpix;
1680 
1681  if (!fp)
1682  return (DPIX *)ERROR_PTR("stream not defined", __func__, NULL);
1683 
1684  if (fscanf(fp, "\nDPix Version %d\n", &version) != 1)
1685  return (DPIX *)ERROR_PTR("not a dpix file", __func__, NULL);
1686  if (version != DPIX_VERSION_NUMBER)
1687  return (DPIX *)ERROR_PTR("invalid dpix version", __func__, NULL);
1688  if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1689  return (DPIX *)ERROR_PTR("read fail for data size", __func__, NULL);
1690 
1691  /* Use fgets() and sscanf(); not fscanf(), for the last
1692  * bit of header data before the float data. The reason is
1693  * that fscanf throws away white space, and if the float data
1694  * happens to begin with ascii character(s) that are white
1695  * space, it will swallow them and all will be lost! */
1696  if (fgets(buf, sizeof(buf), fp) == NULL)
1697  return (DPIX *)ERROR_PTR("fgets read fail", __func__, NULL);
1698  if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1699  return (DPIX *)ERROR_PTR("read fail for xres, yres", __func__, NULL);
1700 
1701  if ((dpix = dpixCreate(w, h)) == NULL)
1702  return (DPIX *)ERROR_PTR("dpix not made", __func__, NULL);
1703  dpixSetResolution(dpix, xres, yres);
1704  data = dpixGetData(dpix);
1705  if (fread(data, 1, nbytes, fp) != nbytes) {
1706  dpixDestroy(&dpix);
1707  return (DPIX *)ERROR_PTR("read error for nbytes", __func__, NULL);
1708  }
1709  fgetc(fp); /* ending nl */
1710 
1711  /* Convert to little-endian if necessary */
1712  dpixEndianByteSwap(dpix, dpix);
1713  return dpix;
1714 }
1715 
1716 
1724 DPIX *
1725 dpixReadMem(const l_uint8 *data,
1726  size_t size)
1727 {
1728 FILE *fp;
1729 DPIX *dpix;
1730 
1731  if (!data)
1732  return (DPIX *)ERROR_PTR("data not defined", __func__, NULL);
1733  if ((fp = fopenReadFromMemory(data, size)) == NULL)
1734  return (DPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1735 
1736  dpix = dpixReadStream(fp);
1737  fclose(fp);
1738  if (!dpix) L_ERROR("dpix not read\n", __func__);
1739  return dpix;
1740 }
1741 
1742 
1750 l_ok
1751 dpixWrite(const char *filename,
1752  DPIX *dpix)
1753 {
1754 l_int32 ret;
1755 FILE *fp;
1756 
1757  if (!filename)
1758  return ERROR_INT("filename not defined", __func__, 1);
1759  if (!dpix)
1760  return ERROR_INT("dpix not defined", __func__, 1);
1761 
1762  if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1763  return ERROR_INT("stream not opened", __func__, 1);
1764  ret = dpixWriteStream(fp, dpix);
1765  fclose(fp);
1766  if (ret)
1767  return ERROR_INT("dpix not written to stream", __func__, 1);
1768  return 0;
1769 }
1770 
1771 
1779 l_ok
1781  DPIX *dpix)
1782 {
1783 l_int32 w, h, xres, yres;
1784 l_uint32 nbytes;
1785 l_float64 *data;
1786 DPIX *dpixt;
1787 
1788  if (!fp)
1789  return ERROR_INT("stream not defined", __func__, 1);
1790  if (!dpix)
1791  return ERROR_INT("dpix not defined", __func__, 1);
1792 
1793  /* Convert to little-endian if necessary */
1794  dpixt = dpixEndianByteSwap(NULL, dpix);
1795 
1796  dpixGetDimensions(dpixt, &w, &h);
1797  dpixGetResolution(dpixt, &xres, &yres);
1798  data = dpixGetData(dpixt);
1799  nbytes = sizeof(l_float64) * w * h;
1800  fprintf(fp, "\nDPix Version %d\n", DPIX_VERSION_NUMBER);
1801  fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
1802  fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
1803  fwrite(data, 1, nbytes, fp);
1804  fprintf(fp, "\n");
1805 
1806  dpixDestroy(&dpixt);
1807  return 0;
1808 }
1809 
1810 
1824 l_ok
1825 dpixWriteMem(l_uint8 **pdata,
1826  size_t *psize,
1827  DPIX *dpix)
1828 {
1829 l_int32 ret;
1830 FILE *fp;
1831 
1832  if (pdata) *pdata = NULL;
1833  if (psize) *psize = 0;
1834  if (!pdata)
1835  return ERROR_INT("&data not defined", __func__, 1);
1836  if (!psize)
1837  return ERROR_INT("&size not defined", __func__, 1);
1838  if (!dpix)
1839  return ERROR_INT("dpix not defined", __func__, 1);
1840 
1841 #if HAVE_FMEMOPEN
1842  if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1843  return ERROR_INT("stream not opened", __func__, 1);
1844  ret = dpixWriteStream(fp, dpix);
1845  fputc('\0', fp);
1846  fclose(fp);
1847  *psize = *psize - 1;
1848 #else
1849  L_INFO("work-around: writing to a temp file\n", __func__);
1850  #ifdef _WIN32
1851  if ((fp = fopenWriteWinTempfile()) == NULL)
1852  return ERROR_INT("tmpfile stream not opened", __func__, 1);
1853  #else
1854  if ((fp = tmpfile()) == NULL)
1855  return ERROR_INT("tmpfile stream not opened", __func__, 1);
1856  #endif /* _WIN32 */
1857  ret = dpixWriteStream(fp, dpix);
1858  rewind(fp);
1859  *pdata = l_binaryReadStream(fp, psize);
1860  fclose(fp);
1861 #endif /* HAVE_FMEMOPEN */
1862  return ret;
1863 }
1864 
1865 
1885 DPIX *
1887  DPIX *dpixs)
1888 {
1889  if (!dpixs)
1890  return (DPIX *)ERROR_PTR("dpixs not defined", __func__, dpixd);
1891  if (dpixd && (dpixs != dpixd))
1892  return (DPIX *)ERROR_PTR("dpixd != dpixs", __func__, dpixd);
1893 
1894 #ifdef L_BIG_ENDIAN
1895  {
1896  l_uint32 *data;
1897  l_int32 i, j, w, h;
1898  l_uint32 word;
1899 
1900  dpixGetDimensions(dpixs, &w, &h);
1901  if (!dpixd)
1902  dpixd = dpixCopy(dpixs);
1903 
1904  data = (l_uint32 *)dpixGetData(dpixd);
1905  for (i = 0; i < h; i++) {
1906  for (j = 0; j < 2 * w; j++, data++) {
1907  word = *data;
1908  *data = (word >> 24) |
1909  ((word >> 8) & 0x0000ff00) |
1910  ((word << 8) & 0x00ff0000) |
1911  (word << 24);
1912  }
1913  }
1914  return dpixd;
1915  }
1916 #else /* L_LITTLE_ENDIAN */
1917 
1918  if (dpixd)
1919  return dpixd; /* no-op */
1920  else
1921  return dpixClone(dpixs);
1922 
1923 #endif /* L_BIG_ENDIAN */
1924 }
1925 
1926 
1927 /*--------------------------------------------------------------------*
1928  * Print FPix (subsampled, for debugging) *
1929  *--------------------------------------------------------------------*/
1943 l_ok
1945  FPIX *fpix,
1946  l_int32 factor)
1947 {
1948 l_int32 i, j, w, h, count;
1949 l_float32 val;
1950 
1951  if (!fp)
1952  return ERROR_INT("stream not defined", __func__, 1);
1953  if (!fpix)
1954  return ERROR_INT("fpix not defined", __func__, 1);
1955  if (factor < 1)
1956  return ERROR_INT("sampling factor < 1f", __func__, 1);
1957 
1958  fpixGetDimensions(fpix, &w, &h);
1959  fprintf(fp, "\nFPix: w = %d, h = %d\n", w, h);
1960  for (i = 0; i < h; i += factor) {
1961  for (count = 0, j = 0; j < w; j += factor, count++) {
1962  fpixGetPixel(fpix, j, i, &val);
1963  fprintf(fp, "val[%d, %d] = %f ", i, j, val);
1964  if ((count + 1) % 3 == 0) fprintf(fp, "\n");
1965  }
1966  if (count % 3) fprintf(fp, "\n");
1967  }
1968  fprintf(fp, "\n");
1969  return 0;
1970 }
DPIX * dpixCopy(DPIX *dpixs)
dpixCopy()
Definition: fpix1.c:1050
l_ok fpixCopyResolution(FPIX *fpixd, FPIX *fpixs)
fpixCopyResolution()
Definition: fpix1.c:432
FPIX * fpixCreateTemplate(FPIX *fpixs)
fpixCreateTemplate()
Definition: fpix1.c:200
l_ok dpixSetWpl(DPIX *dpix, l_int32 wpl)
dpixSetWpl()
Definition: fpix1.c:1178
l_ok dpixWrite(const char *filename, DPIX *dpix)
dpixWrite()
Definition: fpix1.c:1751
l_ok fpixaAddFPix(FPIXA *fpixa, FPIX *fpix, l_int32 copyflag)
fpixaAddFPix()
Definition: fpix1.c:669
FPIXA * fpixaCopy(FPIXA *fpixa, l_int32 copyflag)
fpixaCopy()
Definition: fpix1.c:588
l_ok dpixGetDimensions(DPIX *dpix, l_int32 *pw, l_int32 *ph)
dpixGetDimensions()
Definition: fpix1.c:1119
void dpixDestroy(DPIX **pdpix)
dpixDestroy()
Definition: fpix1.c:1085
void fpixaDestroy(FPIXA **pfpixa)
fpixaDestroy()
Definition: fpix1.c:633
DPIX * dpixEndianByteSwap(DPIX *dpixd, DPIX *dpixs)
dpixEndianByteSwap()
Definition: fpix1.c:1886
DPIX * dpixReadMem(const l_uint8 *data, size_t size)
dpixReadMem()
Definition: fpix1.c:1725
l_ok dpixSetPixel(DPIX *dpix, l_int32 x, l_int32 y, l_float64 val)
dpixSetPixel()
Definition: fpix1.c:1332
FPIX * fpixReadMem(const l_uint8 *data, size_t size)
fpixReadMem()
Definition: fpix1.c:1437
l_int32 dpixGetWpl(DPIX *dpix)
dpixGetWpl()
Definition: fpix1.c:1162
DPIX * dpixCreate(l_int32 width, l_int32 height)
dpixCreate()
Definition: fpix1.c:959
l_ok fpixWriteStream(FILE *fp, FPIX *fpix)
fpixWriteStream()
Definition: fpix1.c:1492
l_ok fpixaGetPixel(FPIXA *fpixa, l_int32 index, l_int32 x, l_int32 y, l_float32 *pval)
fpixaGetPixel()
Definition: fpix1.c:885
l_ok fpixWriteMem(l_uint8 **pdata, size_t *psize, FPIX *fpix)
fpixWriteMem()
Definition: fpix1.c:1537
l_ok dpixWriteMem(l_uint8 **pdata, size_t *psize, DPIX *dpix)
dpixWriteMem()
Definition: fpix1.c:1825
l_ok fpixaSetPixel(FPIXA *fpixa, l_int32 index, l_int32 x, l_int32 y, l_float32 val)
fpixaSetPixel()
Definition: fpix1.c:920
l_ok dpixSetData(DPIX *dpix, l_float64 *data)
dpixSetData()
Definition: fpix1.c:1273
l_ok dpixWriteStream(FILE *fp, DPIX *dpix)
dpixWriteStream()
Definition: fpix1.c:1780
DPIX * dpixReadStream(FILE *fp)
dpixReadStream()
Definition: fpix1.c:1674
static l_int32 fpixaExtendArray(FPIXA *fpixa)
fpixaExtendArray()
Definition: fpix1.c:719
DPIX * dpixClone(DPIX *dpix)
dpixClone()
Definition: fpix1.c:1034
DPIX * dpixRead(const char *filename)
dpixRead()
Definition: fpix1.c:1649
l_float64 * dpixGetData(DPIX *dpix)
dpixGetData()
Definition: fpix1.c:1257
static l_int32 fpixaExtendArrayToSize(FPIXA *fpixa, l_int32 size)
fpixaExtendArrayToSize()
Definition: fpix1.c:742
l_ok fpixGetDimensions(FPIX *fpix, l_int32 *pw, l_int32 *ph)
fpixGetDimensions()
Definition: fpix1.c:314
l_ok fpixSetDimensions(FPIX *fpix, l_int32 w, l_int32 h)
fpixSetDimensions()
Definition: fpix1.c:338
l_ok fpixWrite(const char *filename, FPIX *fpix)
fpixWrite()
Definition: fpix1.c:1463
l_ok dpixGetPixel(DPIX *dpix, l_int32 x, l_int32 y, l_float64 *pval)
dpixGetPixel()
Definition: fpix1.c:1297
static const size_t InitialPtrArraySize
Definition: fpix1.c:129
l_ok fpixSetWpl(FPIX *fpix, l_int32 wpl)
fpixSetWpl()
Definition: fpix1.c:373
l_float32 * fpixaGetData(FPIXA *fpixa, l_int32 index)
fpixaGetData()
Definition: fpix1.c:855
l_ok dpixSetResolution(DPIX *dpix, l_int32 xres, l_int32 yres)
dpixSetResolution()
Definition: fpix1.c:1217
FPIX * fpixRead(const char *filename)
fpixRead()
Definition: fpix1.c:1361
FPIX * fpixEndianByteSwap(FPIX *fpixd, FPIX *fpixs)
fpixEndianByteSwap()
Definition: fpix1.c:1598
l_ok dpixCopyResolution(DPIX *dpixd, DPIX *dpixs)
dpixCopyResolution()
Definition: fpix1.c:1237
FPIX * fpixaGetFPix(FPIXA *fpixa, l_int32 index, l_int32 accesstype)
fpixaGetFPix()
Definition: fpix1.c:796
l_int32 fpixGetWpl(FPIX *fpix)
fpixGetWpl()
Definition: fpix1.c:357
FPIXA * fpixaCreate(l_int32 n)
fpixaCreate()
Definition: fpix1.c:556
l_ok fpixGetResolution(FPIX *fpix, l_int32 *pxres, l_int32 *pyres)
fpixGetResolution()
Definition: fpix1.c:392
DPIX * dpixCreateTemplate(DPIX *dpixs)
dpixCreateTemplate()
Definition: fpix1.c:1007
l_ok fpixSetData(FPIX *fpix, l_float32 *data)
fpixSetData()
Definition: fpix1.c:468
l_ok fpixSetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 val)
fpixSetPixel()
Definition: fpix1.c:527
void fpixDestroy(FPIX **pfpix)
fpixDestroy()
Definition: fpix1.c:280
l_ok fpixSetResolution(FPIX *fpix, l_int32 xres, l_int32 yres)
fpixSetResolution()
Definition: fpix1.c:412
l_int32 fpixaGetCount(FPIXA *fpixa)
fpixaGetCount()
Definition: fpix1.c:778
FPIX * fpixCreate(l_int32 width, l_int32 height)
fpixCreate()
Definition: fpix1.c:152
FPIX * fpixReadStream(FILE *fp)
fpixReadStream()
Definition: fpix1.c:1386
l_ok dpixGetResolution(DPIX *dpix, l_int32 *pxres, l_int32 *pyres)
dpixGetResolution()
Definition: fpix1.c:1197
l_ok fpixGetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 *pval)
fpixGetPixel()
Definition: fpix1.c:492
l_ok dpixSetDimensions(DPIX *dpix, l_int32 w, l_int32 h)
dpixSetDimensions()
Definition: fpix1.c:1143
FPIX * fpixClone(FPIX *fpix)
fpixClone()
Definition: fpix1.c:228
l_ok fpixaGetFPixDimensions(FPIXA *fpixa, l_int32 index, l_int32 *pw, l_int32 *ph)
fpixaGetFPixDimensions()
Definition: fpix1.c:823
l_float32 * fpixGetData(FPIX *fpix)
fpixGetData()
Definition: fpix1.c:452
l_ok fpixPrintStream(FILE *fp, FPIX *fpix, l_int32 factor)
fpixPrintStream()
Definition: fpix1.c:1944
FPIX * fpixCopy(FPIX *fpixs)
fpixCopy()
Definition: fpix1.c:245
@ L_COPY
Definition: pix.h:505
@ L_CLONE
Definition: pix.h:506
@ L_COPY_CLONE
Definition: pix.h:507
@ L_INSERT
Definition: pix.h:504
#define FPIX_VERSION_NUMBER
Definition: pix_internal.h:343
#define DPIX_VERSION_NUMBER
Definition: pix_internal.h:372
l_int32 h
Definition: pix_internal.h:378
l_int32 yres
Definition: pix_internal.h:383
l_float64 * data
Definition: pix_internal.h:385
l_int32 w
Definition: pix_internal.h:377
l_int32 xres
Definition: pix_internal.h:381
l_atomic refcount
Definition: pix_internal.h:380
l_int32 wpl
Definition: pix_internal.h:379
l_int32 w
Definition: pix_internal.h:348
l_atomic refcount
Definition: pix_internal.h:351
l_int32 wpl
Definition: pix_internal.h:350
l_int32 xres
Definition: pix_internal.h:352
l_int32 h
Definition: pix_internal.h:349
l_float32 * data
Definition: pix_internal.h:356
l_int32 yres
Definition: pix_internal.h:354
l_int32 nalloc
Definition: pix_internal.h:363
struct FPix ** fpix
Definition: pix_internal.h:365
l_atomic refcount
Definition: pix_internal.h:364
l_int32 n
Definition: pix_internal.h:362
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
Definition: utils2.c:1358
FILE * fopenReadFromMemory(const l_uint8 *data, size_t size)
fopenReadFromMemory()
Definition: utils2.c:1937
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1905
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
Definition: utils2.c:1262
FILE * fopenWriteWinTempfile(void)
fopenWriteWinTempfile()
Definition: utils2.c:1981
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1864