Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
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 */
128static const size_t MaxPtrArraySize = 100000;
129static const size_t InitialPtrArraySize = 20;
131 /* Static functions */
132static l_int32 fpixaExtendArray(FPIXA *fpixa);
133static l_int32 fpixaExtendArrayToSize(FPIXA *fpixa, l_int32 size);
134
135/*--------------------------------------------------------------------*
136 * FPix Create/copy/destroy *
137 *--------------------------------------------------------------------*/
151FPIX *
152fpixCreate(l_int32 width,
153 l_int32 height)
154{
155l_float32 *data;
156l_uint64 npix64;
157FPIX *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
199FPIX *
201{
202l_int32 w, h;
203FPIX *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
227FPIX *
229{
230 if (!fpix)
231 return (FPIX *)ERROR_PTR("fpix not defined", __func__, NULL);
232 ++fpix->refcount;
233
234 return fpix;
235}
236
237
244FPIX *
246{
247l_int32 w, h, bytes;
248l_float32 *datas, *datad;
249FPIX *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
279void
281{
282l_float32 *data;
283FPIX *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 *--------------------------------------------------------------------*/
313l_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
337l_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
356l_int32
358{
359 if (!fpix)
360 return ERROR_INT("fpix not defined", __func__, 0);
361 return fpix->wpl;
362}
363
364
372l_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
391l_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
411l_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
431l_ok
433 FPIX *fpixs)
434{
435l_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
451l_float32 *
453{
454 if (!fpix)
455 return (l_float32 *)ERROR_PTR("fpix not defined", __func__, NULL);
456 return fpix->data;
457}
458
459
467l_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
491l_ok
493 l_int32 x,
494 l_int32 y,
495 l_float32 *pval)
496{
497l_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
526l_ok
528 l_int32 x,
529 l_int32 y,
530 l_float32 val)
531{
532l_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 *--------------------------------------------------------------------*/
555FPIXA *
556fpixaCreate(l_int32 n)
557{
558FPIXA *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
587FPIXA *
589 l_int32 copyflag)
590{
591l_int32 i;
592FPIX *fpixc;
593FPIXA *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
632void
634{
635l_int32 i;
636FPIXA *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 *--------------------------------------------------------------------*/
668l_ok
670 FPIX *fpix,
671 l_int32 copyflag)
672{
673l_int32 n;
674FPIX *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
718static 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
741static l_int32
743 l_int32 size)
744{
745size_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 *--------------------------------------------------------------------*/
777l_int32
779{
780 if (!fpixa)
781 return ERROR_INT("fpixa not defined", __func__, 0);
782
783 return fpixa->n;
784}
785
786
795FPIX *
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
822l_ok
824 l_int32 index,
825 l_int32 *pw,
826 l_int32 *ph)
827{
828FPIX *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
854l_float32 *
856 l_int32 index)
857{
858l_int32 n;
859l_float32 *data;
860FPIX *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
884l_ok
886 l_int32 index,
887 l_int32 x,
888 l_int32 y,
889 l_float32 *pval)
890{
891l_int32 n, ret;
892FPIX *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
919l_ok
921 l_int32 index,
922 l_int32 x,
923 l_int32 y,
924 l_float32 val)
925{
926l_int32 n, ret;
927FPIX *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 *--------------------------------------------------------------------*/
958DPIX *
959dpixCreate(l_int32 width,
960 l_int32 height)
961{
962l_float64 *data;
963l_uint64 npix64;
964DPIX *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
1006DPIX *
1008{
1009l_int32 w, h;
1010DPIX *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
1033DPIX *
1035{
1036 if (!dpix)
1037 return (DPIX *)ERROR_PTR("dpix not defined", __func__, NULL);
1038 ++dpix->refcount;
1039 return dpix;
1040}
1041
1042
1049DPIX *
1051{
1052l_int32 w, h, bytes;
1053l_float64 *datas, *datad;
1054DPIX *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
1084void
1086{
1087l_float64 *data;
1088DPIX *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 *--------------------------------------------------------------------*/
1118l_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
1142l_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
1161l_int32
1163{
1164 if (!dpix)
1165 return ERROR_INT("dpix not defined", __func__, 0);
1166 return dpix->wpl;
1167}
1168
1169
1177l_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
1196l_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
1216l_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
1236l_ok
1238 DPIX *dpixs)
1239{
1240l_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
1256l_float64 *
1258{
1259 if (!dpix)
1260 return (l_float64 *)ERROR_PTR("dpix not defined", __func__, NULL);
1261 return dpix->data;
1262}
1263
1264
1272l_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
1296l_ok
1298 l_int32 x,
1299 l_int32 y,
1300 l_float64 *pval)
1301{
1302l_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
1331l_ok
1333 l_int32 x,
1334 l_int32 y,
1335 l_float64 val)
1336{
1337l_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 *--------------------------------------------------------------------*/
1360FPIX *
1361fpixRead(const char *filename)
1362{
1363FILE *fp;
1364FPIX *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_1("stream not opened",
1371 filename, __func__, NULL);
1372 fpix = fpixReadStream(fp);
1373 fclose(fp);
1374 if (!fpix)
1375 return (FPIX *)ERROR_PTR_1("fpix not read", filename, __func__, NULL);
1376 return fpix;
1377}
1378
1379
1386FPIX *
1388{
1389char buf[256];
1390l_int32 w, h, nbytes, xres, yres, version;
1391l_float32 *data;
1392FPIX *fpix;
1393
1394 if (!fp)
1395 return (FPIX *)ERROR_PTR("stream not defined", __func__, NULL);
1396
1397 if (fscanf(fp, "\nFPix Version %d\n", &version) != 1)
1398 return (FPIX *)ERROR_PTR("not a fpix file", __func__, NULL);
1399 if (version != FPIX_VERSION_NUMBER)
1400 return (FPIX *)ERROR_PTR("invalid fpix version", __func__, NULL);
1401 if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1402 return (FPIX *)ERROR_PTR("read fail for data size", __func__, NULL);
1403
1404 /* Use fgets() and sscanf(); not fscanf(), for the last
1405 * bit of header data before the float data. The reason is
1406 * that fscanf throws away white space, and if the float data
1407 * happens to begin with ascii character(s) that are white
1408 * space, it will swallow them and all will be lost! */
1409 if (fgets(buf, sizeof(buf), fp) == NULL)
1410 return (FPIX *)ERROR_PTR("fgets read fail", __func__, NULL);
1411 if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1412 return (FPIX *)ERROR_PTR("read fail for xres, yres", __func__, NULL);
1413
1414 if ((fpix = fpixCreate(w, h)) == NULL)
1415 return (FPIX *)ERROR_PTR("fpix not made", __func__, NULL);
1416 fpixSetResolution(fpix, xres, yres);
1417 data = fpixGetData(fpix);
1418 if (fread(data, 1, nbytes, fp) != nbytes) {
1419 fpixDestroy(&fpix);
1420 return (FPIX *)ERROR_PTR("read error for nbytes", __func__, NULL);
1421 }
1422 fgetc(fp); /* ending nl */
1423
1424 /* Convert to little-endian if necessary */
1425 fpixEndianByteSwap(fpix, fpix);
1426 return fpix;
1427}
1428
1429
1437FPIX *
1438fpixReadMem(const l_uint8 *data,
1439 size_t size)
1440{
1441FILE *fp;
1442FPIX *fpix;
1443
1444 if (!data)
1445 return (FPIX *)ERROR_PTR("data not defined", __func__, NULL);
1446 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1447 return (FPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1448
1449 fpix = fpixReadStream(fp);
1450 fclose(fp);
1451 if (!fpix) L_ERROR("fpix not read\n", __func__);
1452 return fpix;
1453}
1454
1455
1463l_ok
1464fpixWrite(const char *filename,
1465 FPIX *fpix)
1466{
1467l_int32 ret;
1468FILE *fp;
1469
1470 if (!filename)
1471 return ERROR_INT("filename not defined", __func__, 1);
1472 if (!fpix)
1473 return ERROR_INT("fpix not defined", __func__, 1);
1474
1475 if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1476 return ERROR_INT_1("stream not opened", filename, __func__, 1);
1477 ret = fpixWriteStream(fp, fpix);
1478 fclose(fp);
1479 if (ret)
1480 return ERROR_INT_1("fpix not written to stream", filename, __func__, 1);
1481 return 0;
1482}
1483
1484
1492l_ok
1494 FPIX *fpix)
1495{
1496l_int32 w, h, xres, yres;
1497l_uint32 nbytes;
1498l_float32 *data;
1499FPIX *fpixt;
1500
1501 if (!fp)
1502 return ERROR_INT("stream not defined", __func__, 1);
1503 if (!fpix)
1504 return ERROR_INT("fpix not defined", __func__, 1);
1505
1506 /* Convert to little-endian if necessary */
1507 fpixt = fpixEndianByteSwap(NULL, fpix);
1508
1509 fpixGetDimensions(fpixt, &w, &h);
1510 data = fpixGetData(fpixt);
1511 nbytes = sizeof(l_float32) * w * h;
1512 fpixGetResolution(fpixt, &xres, &yres);
1513 fprintf(fp, "\nFPix Version %d\n", FPIX_VERSION_NUMBER);
1514 fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
1515 fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
1516 fwrite(data, 1, nbytes, fp);
1517 fprintf(fp, "\n");
1518
1519 fpixDestroy(&fpixt);
1520 return 0;
1521}
1522
1523
1537l_ok
1538fpixWriteMem(l_uint8 **pdata,
1539 size_t *psize,
1540 FPIX *fpix)
1541{
1542l_int32 ret;
1543FILE *fp;
1544
1545 if (pdata) *pdata = NULL;
1546 if (psize) *psize = 0;
1547 if (!pdata)
1548 return ERROR_INT("&data not defined", __func__, 1);
1549 if (!psize)
1550 return ERROR_INT("&size not defined", __func__, 1);
1551 if (!fpix)
1552 return ERROR_INT("fpix not defined", __func__, 1);
1553
1554#if HAVE_FMEMOPEN
1555 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1556 return ERROR_INT("stream not opened", __func__, 1);
1557 ret = fpixWriteStream(fp, fpix);
1558 fputc('\0', fp);
1559 fclose(fp);
1560 if (*psize > 0) *psize = *psize - 1;
1561#else
1562 L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
1563 #ifdef _WIN32
1564 if ((fp = fopenWriteWinTempfile()) == NULL)
1565 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1566 #else
1567 if ((fp = tmpfile()) == NULL)
1568 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1569 #endif /* _WIN32 */
1570 ret = fpixWriteStream(fp, fpix);
1571 rewind(fp);
1572 *pdata = l_binaryReadStream(fp, psize);
1573 fclose(fp);
1574#endif /* HAVE_FMEMOPEN */
1575 return ret;
1576}
1577
1578
1598FPIX *
1600 FPIX *fpixs)
1601{
1602 if (!fpixs)
1603 return (FPIX *)ERROR_PTR("fpixs not defined", __func__, fpixd);
1604 if (fpixd && (fpixs != fpixd))
1605 return (FPIX *)ERROR_PTR("fpixd != fpixs", __func__, fpixd);
1606
1607#ifdef L_BIG_ENDIAN
1608 {
1609 l_uint32 *data;
1610 l_int32 i, j, w, h;
1611 l_uint32 word;
1612
1613 fpixGetDimensions(fpixs, &w, &h);
1614 if (!fpixd)
1615 fpixd = fpixCopy(fpixs);
1616
1617 data = (l_uint32 *)fpixGetData(fpixd);
1618 for (i = 0; i < h; i++) {
1619 for (j = 0; j < w; j++, data++) {
1620 word = *data;
1621 *data = (word >> 24) |
1622 ((word >> 8) & 0x0000ff00) |
1623 ((word << 8) & 0x00ff0000) |
1624 (word << 24);
1625 }
1626 }
1627 return fpixd;
1628 }
1629#else /* L_LITTLE_ENDIAN */
1630
1631 if (fpixd)
1632 return fpixd; /* no-op */
1633 else
1634 return fpixClone(fpixs);
1635
1636#endif /* L_BIG_ENDIAN */
1637}
1638
1639
1640/*--------------------------------------------------------------------*
1641 * DPix serialized I/O *
1642 *--------------------------------------------------------------------*/
1649DPIX *
1650dpixRead(const char *filename)
1651{
1652FILE *fp;
1653DPIX *dpix;
1654
1655 if (!filename)
1656 return (DPIX *)ERROR_PTR("filename not defined", __func__, NULL);
1657
1658 if ((fp = fopenReadStream(filename)) == NULL)
1659 return (DPIX *)ERROR_PTR_1("stream not opened",
1660 filename, __func__, NULL);
1661 dpix = dpixReadStream(fp);
1662 fclose(fp);
1663 if (!dpix)
1664 return (DPIX *)ERROR_PTR_1("dpix not read", filename, __func__, NULL);
1665 return dpix;
1666}
1667
1668
1675DPIX *
1677{
1678char buf[256];
1679l_int32 w, h, nbytes, version, xres, yres;
1680l_float64 *data;
1681DPIX *dpix;
1682
1683 if (!fp)
1684 return (DPIX *)ERROR_PTR("stream not defined", __func__, NULL);
1685
1686 if (fscanf(fp, "\nDPix Version %d\n", &version) != 1)
1687 return (DPIX *)ERROR_PTR("not a dpix file", __func__, NULL);
1688 if (version != DPIX_VERSION_NUMBER)
1689 return (DPIX *)ERROR_PTR("invalid dpix version", __func__, NULL);
1690 if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1691 return (DPIX *)ERROR_PTR("read fail for data size", __func__, NULL);
1692
1693 /* Use fgets() and sscanf(); not fscanf(), for the last
1694 * bit of header data before the float data. The reason is
1695 * that fscanf throws away white space, and if the float data
1696 * happens to begin with ascii character(s) that are white
1697 * space, it will swallow them and all will be lost! */
1698 if (fgets(buf, sizeof(buf), fp) == NULL)
1699 return (DPIX *)ERROR_PTR("fgets read fail", __func__, NULL);
1700 if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1701 return (DPIX *)ERROR_PTR("read fail for xres, yres", __func__, NULL);
1702
1703 if ((dpix = dpixCreate(w, h)) == NULL)
1704 return (DPIX *)ERROR_PTR("dpix not made", __func__, NULL);
1705 dpixSetResolution(dpix, xres, yres);
1706 data = dpixGetData(dpix);
1707 if (fread(data, 1, nbytes, fp) != nbytes) {
1708 dpixDestroy(&dpix);
1709 return (DPIX *)ERROR_PTR("read error for nbytes", __func__, NULL);
1710 }
1711 fgetc(fp); /* ending nl */
1712
1713 /* Convert to little-endian if necessary */
1714 dpixEndianByteSwap(dpix, dpix);
1715 return dpix;
1716}
1717
1718
1726DPIX *
1727dpixReadMem(const l_uint8 *data,
1728 size_t size)
1729{
1730FILE *fp;
1731DPIX *dpix;
1732
1733 if (!data)
1734 return (DPIX *)ERROR_PTR("data not defined", __func__, NULL);
1735 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1736 return (DPIX *)ERROR_PTR("stream not opened", __func__, NULL);
1737
1738 dpix = dpixReadStream(fp);
1739 fclose(fp);
1740 if (!dpix) L_ERROR("dpix not read\n", __func__);
1741 return dpix;
1742}
1743
1744
1752l_ok
1753dpixWrite(const char *filename,
1754 DPIX *dpix)
1755{
1756l_int32 ret;
1757FILE *fp;
1758
1759 if (!filename)
1760 return ERROR_INT("filename not defined", __func__, 1);
1761 if (!dpix)
1762 return ERROR_INT("dpix not defined", __func__, 1);
1763
1764 if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1765 return ERROR_INT_1("stream not opened", filename, __func__, 1);
1766 ret = dpixWriteStream(fp, dpix);
1767 fclose(fp);
1768 if (ret)
1769 return ERROR_INT_1("dpix not written to stream", filename, __func__, 1);
1770 return 0;
1771}
1772
1773
1781l_ok
1783 DPIX *dpix)
1784{
1785l_int32 w, h, xres, yres;
1786l_uint32 nbytes;
1787l_float64 *data;
1788DPIX *dpixt;
1789
1790 if (!fp)
1791 return ERROR_INT("stream not defined", __func__, 1);
1792 if (!dpix)
1793 return ERROR_INT("dpix not defined", __func__, 1);
1794
1795 /* Convert to little-endian if necessary */
1796 dpixt = dpixEndianByteSwap(NULL, dpix);
1797
1798 dpixGetDimensions(dpixt, &w, &h);
1799 dpixGetResolution(dpixt, &xres, &yres);
1800 data = dpixGetData(dpixt);
1801 nbytes = sizeof(l_float64) * w * h;
1802 fprintf(fp, "\nDPix Version %d\n", DPIX_VERSION_NUMBER);
1803 fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
1804 fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
1805 fwrite(data, 1, nbytes, fp);
1806 fprintf(fp, "\n");
1807
1808 dpixDestroy(&dpixt);
1809 return 0;
1810}
1811
1812
1826l_ok
1827dpixWriteMem(l_uint8 **pdata,
1828 size_t *psize,
1829 DPIX *dpix)
1830{
1831l_int32 ret;
1832FILE *fp;
1833
1834 if (pdata) *pdata = NULL;
1835 if (psize) *psize = 0;
1836 if (!pdata)
1837 return ERROR_INT("&data not defined", __func__, 1);
1838 if (!psize)
1839 return ERROR_INT("&size not defined", __func__, 1);
1840 if (!dpix)
1841 return ERROR_INT("dpix not defined", __func__, 1);
1842
1843#if HAVE_FMEMOPEN
1844 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1845 return ERROR_INT("stream not opened", __func__, 1);
1846 ret = dpixWriteStream(fp, dpix);
1847 fputc('\0', fp);
1848 fclose(fp);
1849 *psize = *psize - 1;
1850#else
1851 L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
1852 #ifdef _WIN32
1853 if ((fp = fopenWriteWinTempfile()) == NULL)
1854 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1855 #else
1856 if ((fp = tmpfile()) == NULL)
1857 return ERROR_INT("tmpfile stream not opened", __func__, 1);
1858 #endif /* _WIN32 */
1859 ret = dpixWriteStream(fp, dpix);
1860 rewind(fp);
1861 *pdata = l_binaryReadStream(fp, psize);
1862 fclose(fp);
1863#endif /* HAVE_FMEMOPEN */
1864 return ret;
1865}
1866
1867
1887DPIX *
1889 DPIX *dpixs)
1890{
1891 if (!dpixs)
1892 return (DPIX *)ERROR_PTR("dpixs not defined", __func__, dpixd);
1893 if (dpixd && (dpixs != dpixd))
1894 return (DPIX *)ERROR_PTR("dpixd != dpixs", __func__, dpixd);
1895
1896#ifdef L_BIG_ENDIAN
1897 {
1898 l_uint32 *data;
1899 l_int32 i, j, w, h;
1900 l_uint32 word;
1901
1902 dpixGetDimensions(dpixs, &w, &h);
1903 if (!dpixd)
1904 dpixd = dpixCopy(dpixs);
1905
1906 data = (l_uint32 *)dpixGetData(dpixd);
1907 for (i = 0; i < h; i++) {
1908 for (j = 0; j < 2 * w; j++, data++) {
1909 word = *data;
1910 *data = (word >> 24) |
1911 ((word >> 8) & 0x0000ff00) |
1912 ((word << 8) & 0x00ff0000) |
1913 (word << 24);
1914 }
1915 }
1916 return dpixd;
1917 }
1918#else /* L_LITTLE_ENDIAN */
1919
1920 if (dpixd)
1921 return dpixd; /* no-op */
1922 else
1923 return dpixClone(dpixs);
1924
1925#endif /* L_BIG_ENDIAN */
1926}
1927
1928
1929/*--------------------------------------------------------------------*
1930 * Print FPix (subsampled, for debugging) *
1931 *--------------------------------------------------------------------*/
1945l_ok
1947 FPIX *fpix,
1948 l_int32 factor)
1949{
1950l_int32 i, j, w, h, count;
1951l_float32 val;
1952
1953 if (!fp)
1954 return ERROR_INT("stream not defined", __func__, 1);
1955 if (!fpix)
1956 return ERROR_INT("fpix not defined", __func__, 1);
1957 if (factor < 1)
1958 return ERROR_INT("sampling factor < 1f", __func__, 1);
1959
1960 fpixGetDimensions(fpix, &w, &h);
1961 fprintf(fp, "\nFPix: w = %d, h = %d\n", w, h);
1962 for (i = 0; i < h; i += factor) {
1963 for (count = 0, j = 0; j < w; j += factor, count++) {
1964 fpixGetPixel(fpix, j, i, &val);
1965 fprintf(fp, "val[%d, %d] = %f ", i, j, val);
1966 if ((count + 1) % 3 == 0) fprintf(fp, "\n");
1967 }
1968 if (count % 3) fprintf(fp, "\n");
1969 }
1970 fprintf(fp, "\n");
1971 return 0;
1972}
DPIX * dpixClone(DPIX *dpix)
dpixClone()
Definition fpix1.c:1034
FPIX * fpixReadStream(FILE *fp)
fpixReadStream()
Definition fpix1.c:1387
l_float32 * fpixaGetData(FPIXA *fpixa, l_int32 index)
fpixaGetData()
Definition fpix1.c:855
l_ok fpixCopyResolution(FPIX *fpixd, FPIX *fpixs)
fpixCopyResolution()
Definition fpix1.c:432
l_ok dpixSetWpl(DPIX *dpix, l_int32 wpl)
dpixSetWpl()
Definition fpix1.c:1178
l_float64 * dpixGetData(DPIX *dpix)
dpixGetData()
Definition fpix1.c:1257
l_ok dpixWrite(const char *filename, DPIX *dpix)
dpixWrite()
Definition fpix1.c:1753
FPIX * fpixCreate(l_int32 width, l_int32 height)
fpixCreate()
Definition fpix1.c:152
l_ok fpixaAddFPix(FPIXA *fpixa, FPIX *fpix, l_int32 copyflag)
fpixaAddFPix()
Definition fpix1.c:669
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
FPIXA * fpixaCopy(FPIXA *fpixa, l_int32 copyflag)
fpixaCopy()
Definition fpix1.c:588
l_ok dpixSetPixel(DPIX *dpix, l_int32 x, l_int32 y, l_float64 val)
dpixSetPixel()
Definition fpix1.c:1332
l_float32 * fpixGetData(FPIX *fpix)
fpixGetData()
Definition fpix1.c:452
l_int32 dpixGetWpl(DPIX *dpix)
dpixGetWpl()
Definition fpix1.c:1162
FPIX * fpixReadMem(const l_uint8 *data, size_t size)
fpixReadMem()
Definition fpix1.c:1438
l_ok fpixWriteStream(FILE *fp, FPIX *fpix)
fpixWriteStream()
Definition fpix1.c:1493
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:1538
l_ok dpixWriteMem(l_uint8 **pdata, size_t *psize, DPIX *dpix)
dpixWriteMem()
Definition fpix1.c:1827
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
FPIX * fpixaGetFPix(FPIXA *fpixa, l_int32 index, l_int32 accesstype)
fpixaGetFPix()
Definition fpix1.c:796
l_ok dpixWriteStream(FILE *fp, DPIX *dpix)
dpixWriteStream()
Definition fpix1.c:1782
static l_int32 fpixaExtendArray(FPIXA *fpixa)
fpixaExtendArray()
Definition fpix1.c:719
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
FPIX * fpixEndianByteSwap(FPIX *fpixd, FPIX *fpixs)
fpixEndianByteSwap()
Definition fpix1.c:1599
DPIX * dpixReadMem(const l_uint8 *data, size_t size)
dpixReadMem()
Definition fpix1.c:1727
l_ok fpixWrite(const char *filename, FPIX *fpix)
fpixWrite()
Definition fpix1.c:1464
DPIX * dpixReadStream(FILE *fp)
dpixReadStream()
Definition fpix1.c:1676
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_ok dpixSetResolution(DPIX *dpix, l_int32 xres, l_int32 yres)
dpixSetResolution()
Definition fpix1.c:1217
DPIX * dpixRead(const char *filename)
dpixRead()
Definition fpix1.c:1650
FPIX * fpixCopy(FPIX *fpixs)
fpixCopy()
Definition fpix1.c:245
FPIXA * fpixaCreate(l_int32 n)
fpixaCreate()
Definition fpix1.c:556
l_ok dpixCopyResolution(DPIX *dpixd, DPIX *dpixs)
dpixCopyResolution()
Definition fpix1.c:1237
l_int32 fpixGetWpl(FPIX *fpix)
fpixGetWpl()
Definition fpix1.c:357
DPIX * dpixCreateTemplate(DPIX *dpixs)
dpixCreateTemplate()
Definition fpix1.c:1007
DPIX * dpixCreate(l_int32 width, l_int32 height)
dpixCreate()
Definition fpix1.c:959
l_ok fpixGetResolution(FPIX *fpix, l_int32 *pxres, l_int32 *pyres)
fpixGetResolution()
Definition fpix1.c:392
DPIX * dpixEndianByteSwap(DPIX *dpixd, DPIX *dpixs)
dpixEndianByteSwap()
Definition fpix1.c:1888
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
FPIX * fpixClone(FPIX *fpix)
fpixClone()
Definition fpix1.c:228
void fpixDestroy(FPIX **pfpix)
fpixDestroy()
Definition fpix1.c:280
DPIX * dpixCopy(DPIX *dpixs)
dpixCopy()
Definition fpix1.c:1050
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 * fpixRead(const char *filename)
fpixRead()
Definition fpix1.c:1361
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
l_ok fpixaGetFPixDimensions(FPIXA *fpixa, l_int32 index, l_int32 *pw, l_int32 *ph)
fpixaGetFPixDimensions()
Definition fpix1.c:823
FPIX * fpixCreateTemplate(FPIX *fpixs)
fpixCreateTemplate()
Definition fpix1.c:200
l_ok fpixPrintStream(FILE *fp, FPIX *fpix, l_int32 factor)
fpixPrintStream()
Definition fpix1.c:1946
@ 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
#define DPIX_VERSION_NUMBER
l_int32 h
l_int32 yres
l_float64 * data
l_int32 w
l_int32 xres
l_atomic refcount
l_int32 wpl
l_int32 w
l_atomic refcount
l_int32 wpl
l_int32 xres
l_int32 h
l_float32 * data
l_int32 yres
l_int32 nalloc
struct FPix ** fpix
l_atomic refcount
l_int32 n