Leptonica 1.82.0
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
124#ifdef HAVE_CONFIG_H
125#include <config_auto.h>
126#endif /* HAVE_CONFIG_H */
127
128#include <string.h>
129#include "allheaders.h"
130
131 /* Bounds on array sizes */
132static const size_t MaxPtrArraySize = 100000;
133static const size_t InitialPtrArraySize = 20;
135 /* Static functions */
136static l_int32 fpixaExtendArray(FPIXA *fpixa);
137static l_int32 fpixaExtendArrayToSize(FPIXA *fpixa, l_int32 size);
138
139/*--------------------------------------------------------------------*
140 * FPix Create/copy/destroy *
141 *--------------------------------------------------------------------*/
155FPIX *
156fpixCreate(l_int32 width,
157 l_int32 height)
158{
159l_float32 *data;
160l_uint64 npix64;
161FPIX *fpixd;
162
163 PROCNAME("fpixCreate");
164
165 if (width <= 0)
166 return (FPIX *)ERROR_PTR("width must be > 0", procName, NULL);
167 if (height <= 0)
168 return (FPIX *)ERROR_PTR("height must be > 0", procName, NULL);
169
170 /* Avoid overflow in malloc arg, malicious or otherwise */
171 npix64 = (l_uint64)width * (l_uint64)height; /* # of 4-byte pixels */
172 if (npix64 >= (1LL << 29)) {
173 L_ERROR("requested w = %d, h = %d\n", procName, width, height);
174 return (FPIX *)ERROR_PTR("requested bytes >= 2^31", procName, NULL);
175 }
176
177 fpixd = (FPIX *)LEPT_CALLOC(1, sizeof(FPIX));
178 fpixSetDimensions(fpixd, width, height);
179 fpixSetWpl(fpixd, width); /* 4-byte words */
180 fpixd->refcount = 1;
181
182 data = (l_float32 *)LEPT_CALLOC((size_t)width * height, sizeof(l_float32));
183 if (!data) {
184 fpixDestroy(&fpixd);
185 return (FPIX *)ERROR_PTR("calloc fail for data", procName, NULL);
186 }
187 fpixSetData(fpixd, data);
188 return fpixd;
189}
190
191
205FPIX *
207{
208l_int32 w, h;
209FPIX *fpixd;
210
211 PROCNAME("fpixCreateTemplate");
212
213 if (!fpixs)
214 return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
215
216 fpixGetDimensions(fpixs, &w, &h);
217 if ((fpixd = fpixCreate(w, h)) == NULL)
218 return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
219 fpixCopyResolution(fpixd, fpixs);
220 return fpixd;
221}
222
223
235FPIX *
237{
238 PROCNAME("fpixClone");
239
240 if (!fpix)
241 return (FPIX *)ERROR_PTR("fpix not defined", procName, NULL);
242 fpixChangeRefcount(fpix, 1);
243
244 return fpix;
245}
246
247
254FPIX *
256{
257l_int32 w, h, bytes;
258l_float32 *datas, *datad;
259FPIX *fpixd;
260
261 PROCNAME("fpixCopy");
262
263 if (!fpixs)
264 return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
265
266 /* Total bytes in image data */
267 fpixGetDimensions(fpixs, &w, &h);
268 bytes = 4 * w * h;
269
270 if ((fpixd = fpixCreateTemplate(fpixs)) == NULL)
271 return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
272 datas = fpixGetData(fpixs);
273 datad = fpixGetData(fpixd);
274 memcpy(datad, datas, bytes);
275 return fpixd;
276}
277
278
291void
293{
294l_float32 *data;
295FPIX *fpix;
296
297 PROCNAME("fpixDestroy");
298
299 if (!pfpix) {
300 L_WARNING("ptr address is null!\n", procName);
301 return;
302 }
303
304 if ((fpix = *pfpix) == NULL)
305 return;
306
307 /* Decrement the ref count. If it is 0, destroy the fpix. */
308 fpixChangeRefcount(fpix, -1);
309 if (fpixGetRefcount(fpix) <= 0) {
310 if ((data = fpixGetData(fpix)) != NULL)
311 LEPT_FREE(data);
312 LEPT_FREE(fpix);
313 }
314 *pfpix = NULL;
315}
316
317
318/*--------------------------------------------------------------------*
319 * FPix Accessors *
320 *--------------------------------------------------------------------*/
328l_ok
330 l_int32 *pw,
331 l_int32 *ph)
332{
333 PROCNAME("fpixGetDimensions");
334
335 if (!pw && !ph)
336 return ERROR_INT("no return val requested", procName, 1);
337 if (pw) *pw = 0;
338 if (ph) *ph = 0;
339 if (!fpix)
340 return ERROR_INT("fpix not defined", procName, 1);
341 if (pw) *pw = fpix->w;
342 if (ph) *ph = fpix->h;
343 return 0;
344}
345
346
354l_ok
356 l_int32 w,
357 l_int32 h)
358{
359 PROCNAME("fpixSetDimensions");
360
361 if (!fpix)
362 return ERROR_INT("fpix not defined", procName, 1);
363 fpix->w = w;
364 fpix->h = h;
365 return 0;
366}
367
368
375l_int32
377{
378 PROCNAME("fpixGetWpl");
379
380 if (!fpix)
381 return ERROR_INT("fpix not defined", procName, 0);
382 return fpix->wpl;
383}
384
385
393l_ok
395 l_int32 wpl)
396{
397 PROCNAME("fpixSetWpl");
398
399 if (!fpix)
400 return ERROR_INT("fpix not defined", procName, 1);
401
402 fpix->wpl = wpl;
403 return 0;
404}
405
406
413l_int32
415{
416 PROCNAME("fpixGetRefcount");
417
418 if (!fpix)
419 return ERROR_INT("fpix not defined", procName, UNDEF);
420 return fpix->refcount;
421}
422
423
431l_ok
433 l_int32 delta)
434{
435 PROCNAME("fpixChangeRefcount");
436
437 if (!fpix)
438 return ERROR_INT("fpix not defined", procName, 1);
439
440 fpix->refcount += delta;
441 return 0;
442}
443
444
452l_ok
454 l_int32 *pxres,
455 l_int32 *pyres)
456{
457 PROCNAME("fpixGetResolution");
458
459 if (!fpix)
460 return ERROR_INT("fpix not defined", procName, 1);
461 if (pxres) *pxres = fpix->xres;
462 if (pyres) *pyres = fpix->yres;
463 return 0;
464}
465
466
474l_ok
476 l_int32 xres,
477 l_int32 yres)
478{
479 PROCNAME("fpixSetResolution");
480
481 if (!fpix)
482 return ERROR_INT("fpix not defined", procName, 1);
483
484 fpix->xres = xres;
485 fpix->yres = yres;
486 return 0;
487}
488
489
496l_ok
498 FPIX *fpixs)
499{
500l_int32 xres, yres;
501 PROCNAME("fpixCopyResolution");
502
503 if (!fpixs || !fpixd)
504 return ERROR_INT("fpixs and fpixd not both defined", procName, 1);
505
506 fpixGetResolution(fpixs, &xres, &yres);
507 fpixSetResolution(fpixd, xres, yres);
508 return 0;
509}
510
511
518l_float32 *
520{
521 PROCNAME("fpixGetData");
522
523 if (!fpix)
524 return (l_float32 *)ERROR_PTR("fpix not defined", procName, NULL);
525 return fpix->data;
526}
527
528
536l_ok
538 l_float32 *data)
539{
540 PROCNAME("fpixSetData");
541
542 if (!fpix)
543 return ERROR_INT("fpix not defined", procName, 1);
544
545 fpix->data = data;
546 return 0;
547}
548
549
562l_ok
564 l_int32 x,
565 l_int32 y,
566 l_float32 *pval)
567{
568l_int32 w, h;
569
570 PROCNAME("fpixGetPixel");
571
572 if (!pval)
573 return ERROR_INT("pval not defined", procName, 1);
574 *pval = 0.0;
575 if (!fpix)
576 return ERROR_INT("fpix not defined", procName, 1);
577
578 fpixGetDimensions(fpix, &w, &h);
579 if (x < 0 || x >= w || y < 0 || y >= h)
580 return 2;
581
582 *pval = *(fpix->data + y * w + x);
583 return 0;
584}
585
586
599l_ok
601 l_int32 x,
602 l_int32 y,
603 l_float32 val)
604{
605l_int32 w, h;
606
607 PROCNAME("fpixSetPixel");
608
609 if (!fpix)
610 return ERROR_INT("fpix not defined", procName, 1);
611
612 fpixGetDimensions(fpix, &w, &h);
613 if (x < 0 || x >= w || y < 0 || y >= h)
614 return 2;
615
616 *(fpix->data + y * w + x) = val;
617 return 0;
618}
619
620
621/*--------------------------------------------------------------------*
622 * FPixa Create/copy/destroy *
623 *--------------------------------------------------------------------*/
630FPIXA *
631fpixaCreate(l_int32 n)
632{
633FPIXA *fpixa;
634
635 PROCNAME("fpixaCreate");
636
637 if (n <= 0 || n > MaxPtrArraySize)
639
640 fpixa = (FPIXA *)LEPT_CALLOC(1, sizeof(FPIXA));
641 fpixa->n = 0;
642 fpixa->nalloc = n;
643 fpixa->refcount = 1;
644 fpixa->fpix = (FPIX **)LEPT_CALLOC(n, sizeof(FPIX *));
645 return fpixa;
646}
647
648
664FPIXA *
666 l_int32 copyflag)
667{
668l_int32 i;
669FPIX *fpixc;
670FPIXA *fpixac;
671
672 PROCNAME("fpixaCopy");
673
674 if (!fpixa)
675 return (FPIXA *)ERROR_PTR("fpixa not defined", procName, NULL);
676
677 if (copyflag == L_CLONE) {
678 fpixaChangeRefcount(fpixa, 1);
679 return fpixa;
680 }
681
682 if (copyflag != L_COPY && copyflag != L_COPY_CLONE)
683 return (FPIXA *)ERROR_PTR("invalid copyflag", procName, NULL);
684
685 if ((fpixac = fpixaCreate(fpixa->n)) == NULL)
686 return (FPIXA *)ERROR_PTR("fpixac not made", procName, NULL);
687 for (i = 0; i < fpixa->n; i++) {
688 if (copyflag == L_COPY)
689 fpixc = fpixaGetFPix(fpixa, i, L_COPY);
690 else /* copy-clone */
691 fpixc = fpixaGetFPix(fpixa, i, L_CLONE);
692 fpixaAddFPix(fpixac, fpixc, L_INSERT);
693 }
694
695 return fpixac;
696}
697
698
711void
713{
714l_int32 i;
715FPIXA *fpixa;
716
717 PROCNAME("fpixaDestroy");
718
719 if (pfpixa == NULL) {
720 L_WARNING("ptr address is NULL!\n", procName);
721 return;
722 }
723
724 if ((fpixa = *pfpixa) == NULL)
725 return;
726
727 /* Decrement the refcount. If it is 0, destroy the pixa. */
728 fpixaChangeRefcount(fpixa, -1);
729 if (fpixa->refcount <= 0) {
730 for (i = 0; i < fpixa->n; i++)
731 fpixDestroy(&fpixa->fpix[i]);
732 LEPT_FREE(fpixa->fpix);
733 LEPT_FREE(fpixa);
734 }
735 *pfpixa = NULL;
736}
737
738
739/*--------------------------------------------------------------------*
740 * FPixa addition *
741 *--------------------------------------------------------------------*/
750l_ok
752 FPIX *fpix,
753 l_int32 copyflag)
754{
755l_int32 n;
756FPIX *fpixc;
757
758 PROCNAME("fpixaAddFPix");
759
760 if (!fpixa)
761 return ERROR_INT("fpixa not defined", procName, 1);
762 if (!fpix)
763 return ERROR_INT("fpix not defined", procName, 1);
764
765 if (copyflag == L_INSERT)
766 fpixc = fpix;
767 else if (copyflag == L_COPY)
768 fpixc = fpixCopy(fpix);
769 else if (copyflag == L_CLONE)
770 fpixc = fpixClone(fpix);
771 else
772 return ERROR_INT("invalid copyflag", procName, 1);
773 if (!fpixc)
774 return ERROR_INT("fpixc not made", procName, 1);
775
776 n = fpixaGetCount(fpixa);
777 if (n >= fpixa->nalloc) {
778 if (fpixaExtendArray(fpixa)) {
779 if (copyflag != L_INSERT)
780 fpixDestroy(&fpixc);
781 return ERROR_INT("extension failed", procName, 1);
782 }
783 }
784 fpixa->fpix[n] = fpixc;
785 fpixa->n++;
786 return 0;
787}
788
789
802static l_int32
804{
805 PROCNAME("fpixaExtendArray");
806
807 if (!fpixa)
808 return ERROR_INT("fpixa not defined", procName, 1);
809
810 return fpixaExtendArrayToSize(fpixa, 2 * fpixa->nalloc);
811}
812
813
827static l_int32
829 l_int32 size)
830{
831size_t oldsize, newsize;
832
833 PROCNAME("fpixaExtendArrayToSize");
834
835 if (!fpixa)
836 return ERROR_INT("fpixa not defined", procName, 1);
837 if (fpixa->nalloc > MaxPtrArraySize) /* belt & suspenders */
838 return ERROR_INT("fpixa has too many ptrs", procName, 1);
839 if (size > MaxPtrArraySize)
840 return ERROR_INT("size > 100K ptrs; too large", procName, 1);
841 if (size <= fpixa->nalloc) {
842 L_INFO("size too small; no extension\n", procName);
843 return 0;
844 }
845
846 oldsize = fpixa->nalloc * sizeof(FPIX *);
847 newsize = size * sizeof(FPIX *);
848 if ((fpixa->fpix = (FPIX **)reallocNew((void **)&fpixa->fpix,
849 oldsize, newsize)) == NULL)
850 return ERROR_INT("new ptr array not returned", procName, 1);
851 fpixa->nalloc = size;
852 return 0;
853}
854
855
856/*--------------------------------------------------------------------*
857 * FPixa accessors *
858 *--------------------------------------------------------------------*/
865l_int32
867{
868 PROCNAME("fpixaGetCount");
869
870 if (!fpixa)
871 return ERROR_INT("fpixa not defined", procName, 0);
872
873 return fpixa->n;
874}
875
876
884l_ok
886 l_int32 delta)
887{
888 PROCNAME("fpixaChangeRefcount");
889
890 if (!fpixa)
891 return ERROR_INT("fpixa not defined", procName, 1);
892
893 fpixa->refcount += delta;
894 return 0;
895}
896
897
906FPIX *
908 l_int32 index,
909 l_int32 accesstype)
910{
911 PROCNAME("fpixaGetFPix");
912
913 if (!fpixa)
914 return (FPIX *)ERROR_PTR("fpixa not defined", procName, NULL);
915 if (index < 0 || index >= fpixa->n)
916 return (FPIX *)ERROR_PTR("index not valid", procName, NULL);
917
918 if (accesstype == L_COPY)
919 return fpixCopy(fpixa->fpix[index]);
920 else if (accesstype == L_CLONE)
921 return fpixClone(fpixa->fpix[index]);
922 else
923 return (FPIX *)ERROR_PTR("invalid accesstype", procName, NULL);
924}
925
926
935l_ok
937 l_int32 index,
938 l_int32 *pw,
939 l_int32 *ph)
940{
941FPIX *fpix;
942
943 PROCNAME("fpixaGetFPixDimensions");
944
945 if (!pw && !ph)
946 return ERROR_INT("no return val requested", procName, 1);
947 if (pw) *pw = 0;
948 if (ph) *ph = 0;
949 if (!fpixa)
950 return ERROR_INT("fpixa not defined", procName, 1);
951 if (index < 0 || index >= fpixa->n)
952 return ERROR_INT("index not valid", procName, 1);
953
954 if ((fpix = fpixaGetFPix(fpixa, index, L_CLONE)) == NULL)
955 return ERROR_INT("fpix not found!", procName, 1);
956 fpixGetDimensions(fpix, pw, ph);
957 fpixDestroy(&fpix);
958 return 0;
959}
960
961
969l_float32 *
971 l_int32 index)
972{
973l_int32 n;
974l_float32 *data;
975FPIX *fpix;
976
977 PROCNAME("fpixaGetData");
978
979 if (!fpixa)
980 return (l_float32 *)ERROR_PTR("fpixa not defined", procName, NULL);
981 n = fpixaGetCount(fpixa);
982 if (index < 0 || index >= n)
983 return (l_float32 *)ERROR_PTR("invalid index", procName, NULL);
984
985 fpix = fpixaGetFPix(fpixa, index, L_CLONE);
986 data = fpixGetData(fpix);
987 fpixDestroy(&fpix);
988 return data;
989}
990
991
1001l_ok
1003 l_int32 index,
1004 l_int32 x,
1005 l_int32 y,
1006 l_float32 *pval)
1007{
1008l_int32 n, ret;
1009FPIX *fpix;
1010
1011 PROCNAME("fpixaGetPixel");
1012
1013 if (!pval)
1014 return ERROR_INT("pval not defined", procName, 1);
1015 *pval = 0.0;
1016 if (!fpixa)
1017 return ERROR_INT("fpixa not defined", procName, 1);
1018 n = fpixaGetCount(fpixa);
1019 if (index < 0 || index >= n)
1020 return ERROR_INT("invalid index into fpixa", procName, 1);
1021
1022 fpix = fpixaGetFPix(fpixa, index, L_CLONE);
1023 ret = fpixGetPixel(fpix, x, y, pval);
1024 fpixDestroy(&fpix);
1025 return ret;
1026}
1027
1028
1038l_ok
1040 l_int32 index,
1041 l_int32 x,
1042 l_int32 y,
1043 l_float32 val)
1044{
1045l_int32 n, ret;
1046FPIX *fpix;
1047
1048 PROCNAME("fpixaSetPixel");
1049
1050 if (!fpixa)
1051 return ERROR_INT("fpixa not defined", procName, 1);
1052 n = fpixaGetCount(fpixa);
1053 if (index < 0 || index >= n)
1054 return ERROR_INT("invalid index into fpixa", procName, 1);
1055
1056 fpix = fpixaGetFPix(fpixa, index, L_CLONE);
1057 ret = fpixSetPixel(fpix, x, y, val);
1058 fpixDestroy(&fpix);
1059 return ret;
1060}
1061
1062
1063/*--------------------------------------------------------------------*
1064 * DPix Create/copy/destroy *
1065 *--------------------------------------------------------------------*/
1079DPIX *
1080dpixCreate(l_int32 width,
1081 l_int32 height)
1082{
1083l_float64 *data;
1084l_uint64 npix64;
1085DPIX *dpix;
1086
1087 PROCNAME("dpixCreate");
1088
1089 if (width <= 0)
1090 return (DPIX *)ERROR_PTR("width must be > 0", procName, NULL);
1091 if (height <= 0)
1092 return (DPIX *)ERROR_PTR("height must be > 0", procName, NULL);
1093
1094 /* Avoid overflow in malloc arg, malicious or otherwise */
1095 npix64 = (l_uint64)width * (l_uint64)height; /* # of 8 byte pixels */
1096 if (npix64 >= (1LL << 28)) {
1097 L_ERROR("requested w = %d, h = %d\n", procName, width, height);
1098 return (DPIX *)ERROR_PTR("requested bytes >= 2^31", procName, NULL);
1099 }
1100
1101 dpix = (DPIX *)LEPT_CALLOC(1, sizeof(DPIX));
1102 dpixSetDimensions(dpix, width, height);
1103 dpixSetWpl(dpix, width); /* 8 byte words */
1104 dpix->refcount = 1;
1105
1106 data = (l_float64 *)LEPT_CALLOC((size_t)width * height, sizeof(l_float64));
1107 if (!data) {
1108 dpixDestroy(&dpix);
1109 return (DPIX *)ERROR_PTR("calloc fail for data", procName, NULL);
1110 }
1111 dpixSetData(dpix, data);
1112 return dpix;
1113}
1114
1115
1129DPIX *
1131{
1132l_int32 w, h;
1133DPIX *dpixd;
1134
1135 PROCNAME("dpixCreateTemplate");
1136
1137 if (!dpixs)
1138 return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
1139
1140 dpixGetDimensions(dpixs, &w, &h);
1141 dpixd = dpixCreate(w, h);
1142 dpixCopyResolution(dpixd, dpixs);
1143 return dpixd;
1144}
1145
1146
1158DPIX *
1160{
1161 PROCNAME("dpixClone");
1162
1163 if (!dpix)
1164 return (DPIX *)ERROR_PTR("dpix not defined", procName, NULL);
1165 dpixChangeRefcount(dpix, 1);
1166 return dpix;
1167}
1168
1169
1176DPIX *
1178{
1179l_int32 w, h, bytes;
1180l_float64 *datas, *datad;
1181DPIX *dpixd;
1182
1183 PROCNAME("dpixCopy");
1184
1185 if (!dpixs)
1186 return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
1187
1188 /* Total bytes in image data */
1189 dpixGetDimensions(dpixs, &w, &h);
1190 bytes = 8 * w * h;
1191
1192 if ((dpixd = dpixCreateTemplate(dpixs)) == NULL)
1193 return (DPIX *)ERROR_PTR("dpixd not made", procName, NULL);
1194 datas = dpixGetData(dpixs);
1195 datad = dpixGetData(dpixd);
1196 memcpy(datad, datas, bytes);
1197 return dpixd;
1198}
1199
1200
1213void
1215{
1216l_float64 *data;
1217DPIX *dpix;
1218
1219 PROCNAME("dpixDestroy");
1220
1221 if (!pdpix) {
1222 L_WARNING("ptr address is null!\n", procName);
1223 return;
1224 }
1225
1226 if ((dpix = *pdpix) == NULL)
1227 return;
1228
1229 /* Decrement the ref count. If it is 0, destroy the dpix. */
1230 dpixChangeRefcount(dpix, -1);
1231 if (dpixGetRefcount(dpix) <= 0) {
1232 if ((data = dpixGetData(dpix)) != NULL)
1233 LEPT_FREE(data);
1234 LEPT_FREE(dpix);
1235 }
1236 *pdpix = NULL;
1237}
1238
1239
1240/*--------------------------------------------------------------------*
1241 * DPix Accessors *
1242 *--------------------------------------------------------------------*/
1250l_ok
1252 l_int32 *pw,
1253 l_int32 *ph)
1254{
1255 PROCNAME("dpixGetDimensions");
1256
1257 if (!pw && !ph)
1258 return ERROR_INT("no return val requested", procName, 1);
1259 if (pw) *pw = 0;
1260 if (ph) *ph = 0;
1261 if (!dpix)
1262 return ERROR_INT("dpix not defined", procName, 1);
1263 if (pw) *pw = dpix->w;
1264 if (ph) *ph = dpix->h;
1265 return 0;
1266}
1267
1268
1276l_ok
1278 l_int32 w,
1279 l_int32 h)
1280{
1281 PROCNAME("dpixSetDimensions");
1282
1283 if (!dpix)
1284 return ERROR_INT("dpix not defined", procName, 1);
1285 dpix->w = w;
1286 dpix->h = h;
1287 return 0;
1288}
1289
1290
1297l_int32
1299{
1300 PROCNAME("dpixGetWpl");
1301
1302 if (!dpix)
1303 return ERROR_INT("dpix not defined", procName, 0);
1304 return dpix->wpl;
1305}
1306
1307
1315l_ok
1317 l_int32 wpl)
1318{
1319 PROCNAME("dpixSetWpl");
1320
1321 if (!dpix)
1322 return ERROR_INT("dpix not defined", procName, 1);
1323
1324 dpix->wpl = wpl;
1325 return 0;
1326}
1327
1328
1335l_int32
1337{
1338 PROCNAME("dpixGetRefcount");
1339
1340 if (!dpix)
1341 return ERROR_INT("dpix not defined", procName, UNDEF);
1342 return dpix->refcount;
1343}
1344
1345
1353l_ok
1355 l_int32 delta)
1356{
1357 PROCNAME("dpixChangeRefcount");
1358
1359 if (!dpix)
1360 return ERROR_INT("dpix not defined", procName, 1);
1361
1362 dpix->refcount += delta;
1363 return 0;
1364}
1365
1366
1374l_ok
1376 l_int32 *pxres,
1377 l_int32 *pyres)
1378{
1379 PROCNAME("dpixGetResolution");
1380
1381 if (!dpix)
1382 return ERROR_INT("dpix not defined", procName, 1);
1383 if (pxres) *pxres = dpix->xres;
1384 if (pyres) *pyres = dpix->yres;
1385 return 0;
1386}
1387
1388
1396l_ok
1398 l_int32 xres,
1399 l_int32 yres)
1400{
1401 PROCNAME("dpixSetResolution");
1402
1403 if (!dpix)
1404 return ERROR_INT("dpix not defined", procName, 1);
1405
1406 dpix->xres = xres;
1407 dpix->yres = yres;
1408 return 0;
1409}
1410
1411
1418l_ok
1420 DPIX *dpixs)
1421{
1422l_int32 xres, yres;
1423 PROCNAME("dpixCopyResolution");
1424
1425 if (!dpixs || !dpixd)
1426 return ERROR_INT("dpixs and dpixd not both defined", procName, 1);
1427
1428 dpixGetResolution(dpixs, &xres, &yres);
1429 dpixSetResolution(dpixd, xres, yres);
1430 return 0;
1431}
1432
1433
1440l_float64 *
1442{
1443 PROCNAME("dpixGetData");
1444
1445 if (!dpix)
1446 return (l_float64 *)ERROR_PTR("dpix not defined", procName, NULL);
1447 return dpix->data;
1448}
1449
1450
1458l_ok
1460 l_float64 *data)
1461{
1462 PROCNAME("dpixSetData");
1463
1464 if (!dpix)
1465 return ERROR_INT("dpix not defined", procName, 1);
1466
1467 dpix->data = data;
1468 return 0;
1469}
1470
1471
1484l_ok
1486 l_int32 x,
1487 l_int32 y,
1488 l_float64 *pval)
1489{
1490l_int32 w, h;
1491
1492 PROCNAME("dpixGetPixel");
1493
1494 if (!pval)
1495 return ERROR_INT("pval not defined", procName, 1);
1496 *pval = 0.0;
1497 if (!dpix)
1498 return ERROR_INT("dpix not defined", procName, 1);
1499
1500 dpixGetDimensions(dpix, &w, &h);
1501 if (x < 0 || x >= w || y < 0 || y >= h)
1502 return 2;
1503
1504 *pval = *(dpix->data + y * w + x);
1505 return 0;
1506}
1507
1508
1521l_ok
1523 l_int32 x,
1524 l_int32 y,
1525 l_float64 val)
1526{
1527l_int32 w, h;
1528
1529 PROCNAME("dpixSetPixel");
1530
1531 if (!dpix)
1532 return ERROR_INT("dpix not defined", procName, 1);
1533
1534 dpixGetDimensions(dpix, &w, &h);
1535 if (x < 0 || x >= w || y < 0 || y >= h)
1536 return 2;
1537
1538 *(dpix->data + y * w + x) = val;
1539 return 0;
1540}
1541
1542
1543/*--------------------------------------------------------------------*
1544 * FPix serialized I/O *
1545 *--------------------------------------------------------------------*/
1552FPIX *
1553fpixRead(const char *filename)
1554{
1555FILE *fp;
1556FPIX *fpix;
1557
1558 PROCNAME("fpixRead");
1559
1560 if (!filename)
1561 return (FPIX *)ERROR_PTR("filename not defined", procName, NULL);
1562
1563 if ((fp = fopenReadStream(filename)) == NULL)
1564 return (FPIX *)ERROR_PTR("stream not opened", procName, NULL);
1565 fpix = fpixReadStream(fp);
1566 fclose(fp);
1567 if (!fpix)
1568 return (FPIX *)ERROR_PTR("fpix not read", procName, NULL);
1569 return fpix;
1570}
1571
1572
1579FPIX *
1581{
1582char buf[256];
1583l_int32 w, h, nbytes, xres, yres, version;
1584l_float32 *data;
1585FPIX *fpix;
1586
1587 PROCNAME("fpixReadStream");
1588
1589 if (!fp)
1590 return (FPIX *)ERROR_PTR("stream not defined", procName, NULL);
1591
1592 if (fscanf(fp, "\nFPix Version %d\n", &version) != 1)
1593 return (FPIX *)ERROR_PTR("not a fpix file", procName, NULL);
1594 if (version != FPIX_VERSION_NUMBER)
1595 return (FPIX *)ERROR_PTR("invalid fpix version", procName, NULL);
1596 if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1597 return (FPIX *)ERROR_PTR("read fail for data size", procName, NULL);
1598
1599 /* Use fgets() and sscanf(); not fscanf(), for the last
1600 * bit of header data before the float data. The reason is
1601 * that fscanf throws away white space, and if the float data
1602 * happens to begin with ascii character(s) that are white
1603 * space, it will swallow them and all will be lost! */
1604 if (fgets(buf, sizeof(buf), fp) == NULL)
1605 return (FPIX *)ERROR_PTR("fgets read fail", procName, NULL);
1606 if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1607 return (FPIX *)ERROR_PTR("read fail for xres, yres", procName, NULL);
1608
1609 if ((fpix = fpixCreate(w, h)) == NULL)
1610 return (FPIX *)ERROR_PTR("fpix not made", procName, NULL);
1611 fpixSetResolution(fpix, xres, yres);
1612 data = fpixGetData(fpix);
1613 if (fread(data, 1, nbytes, fp) != nbytes) {
1614 fpixDestroy(&fpix);
1615 return (FPIX *)ERROR_PTR("read error for nbytes", procName, NULL);
1616 }
1617 fgetc(fp); /* ending nl */
1618
1619 /* Convert to little-endian if necessary */
1620 fpixEndianByteSwap(fpix, fpix);
1621 return fpix;
1622}
1623
1624
1632FPIX *
1633fpixReadMem(const l_uint8 *data,
1634 size_t size)
1635{
1636FILE *fp;
1637FPIX *fpix;
1638
1639 PROCNAME("fpixReadMem");
1640
1641 if (!data)
1642 return (FPIX *)ERROR_PTR("data not defined", procName, NULL);
1643 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1644 return (FPIX *)ERROR_PTR("stream not opened", procName, NULL);
1645
1646 fpix = fpixReadStream(fp);
1647 fclose(fp);
1648 if (!fpix) L_ERROR("fpix not read\n", procName);
1649 return fpix;
1650}
1651
1652
1660l_ok
1661fpixWrite(const char *filename,
1662 FPIX *fpix)
1663{
1664l_int32 ret;
1665FILE *fp;
1666
1667 PROCNAME("fpixWrite");
1668
1669 if (!filename)
1670 return ERROR_INT("filename not defined", procName, 1);
1671 if (!fpix)
1672 return ERROR_INT("fpix not defined", procName, 1);
1673
1674 if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1675 return ERROR_INT("stream not opened", procName, 1);
1676 ret = fpixWriteStream(fp, fpix);
1677 fclose(fp);
1678 if (ret)
1679 return ERROR_INT("fpix not written to stream", procName, 1);
1680 return 0;
1681}
1682
1683
1691l_ok
1693 FPIX *fpix)
1694{
1695l_int32 w, h, xres, yres;
1696l_uint32 nbytes;
1697l_float32 *data;
1698FPIX *fpixt;
1699
1700 PROCNAME("fpixWriteStream");
1701
1702 if (!fp)
1703 return ERROR_INT("stream not defined", procName, 1);
1704 if (!fpix)
1705 return ERROR_INT("fpix not defined", procName, 1);
1706
1707 /* Convert to little-endian if necessary */
1708 fpixt = fpixEndianByteSwap(NULL, fpix);
1709
1710 fpixGetDimensions(fpixt, &w, &h);
1711 data = fpixGetData(fpixt);
1712 nbytes = sizeof(l_float32) * w * h;
1713 fpixGetResolution(fpixt, &xres, &yres);
1714 fprintf(fp, "\nFPix Version %d\n", FPIX_VERSION_NUMBER);
1715 fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
1716 fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
1717 fwrite(data, 1, nbytes, fp);
1718 fprintf(fp, "\n");
1719
1720 fpixDestroy(&fpixt);
1721 return 0;
1722}
1723
1724
1738l_ok
1739fpixWriteMem(l_uint8 **pdata,
1740 size_t *psize,
1741 FPIX *fpix)
1742{
1743l_int32 ret;
1744FILE *fp;
1745
1746 PROCNAME("fpixWriteMem");
1747
1748 if (pdata) *pdata = NULL;
1749 if (psize) *psize = 0;
1750 if (!pdata)
1751 return ERROR_INT("&data not defined", procName, 1);
1752 if (!psize)
1753 return ERROR_INT("&size not defined", procName, 1);
1754 if (!fpix)
1755 return ERROR_INT("fpix not defined", procName, 1);
1756
1757#if HAVE_FMEMOPEN
1758 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1759 return ERROR_INT("stream not opened", procName, 1);
1760 ret = fpixWriteStream(fp, fpix);
1761 fputc('\0', fp);
1762 fclose(fp);
1763 *psize = *psize - 1;
1764#else
1765 L_INFO("work-around: writing to a temp file\n", procName);
1766 #ifdef _WIN32
1767 if ((fp = fopenWriteWinTempfile()) == NULL)
1768 return ERROR_INT("tmpfile stream not opened", procName, 1);
1769 #else
1770 if ((fp = tmpfile()) == NULL)
1771 return ERROR_INT("tmpfile stream not opened", procName, 1);
1772 #endif /* _WIN32 */
1773 ret = fpixWriteStream(fp, fpix);
1774 rewind(fp);
1775 *pdata = l_binaryReadStream(fp, psize);
1776 fclose(fp);
1777#endif /* HAVE_FMEMOPEN */
1778 return ret;
1779}
1780
1781
1801FPIX *
1803 FPIX *fpixs)
1804{
1805 PROCNAME("fpixEndianByteSwap");
1806
1807 if (!fpixs)
1808 return (FPIX *)ERROR_PTR("fpixs not defined", procName, fpixd);
1809 if (fpixd && (fpixs != fpixd))
1810 return (FPIX *)ERROR_PTR("fpixd != fpixs", procName, fpixd);
1811
1812#ifdef L_BIG_ENDIAN
1813 {
1814 l_uint32 *data;
1815 l_int32 i, j, w, h;
1816 l_uint32 word;
1817
1818 fpixGetDimensions(fpixs, &w, &h);
1819 if (!fpixd)
1820 fpixd = fpixCopy(fpixs);
1821
1822 data = (l_uint32 *)fpixGetData(fpixd);
1823 for (i = 0; i < h; i++) {
1824 for (j = 0; j < w; j++, data++) {
1825 word = *data;
1826 *data = (word >> 24) |
1827 ((word >> 8) & 0x0000ff00) |
1828 ((word << 8) & 0x00ff0000) |
1829 (word << 24);
1830 }
1831 }
1832 return fpixd;
1833 }
1834#else /* L_LITTLE_ENDIAN */
1835
1836 if (fpixd)
1837 return fpixd; /* no-op */
1838 else
1839 return fpixClone(fpixs);
1840
1841#endif /* L_BIG_ENDIAN */
1842}
1843
1844
1845/*--------------------------------------------------------------------*
1846 * DPix serialized I/O *
1847 *--------------------------------------------------------------------*/
1854DPIX *
1855dpixRead(const char *filename)
1856{
1857FILE *fp;
1858DPIX *dpix;
1859
1860 PROCNAME("dpixRead");
1861
1862 if (!filename)
1863 return (DPIX *)ERROR_PTR("filename not defined", procName, NULL);
1864
1865 if ((fp = fopenReadStream(filename)) == NULL)
1866 return (DPIX *)ERROR_PTR("stream not opened", procName, NULL);
1867 dpix = dpixReadStream(fp);
1868 fclose(fp);
1869 if (!dpix)
1870 return (DPIX *)ERROR_PTR("dpix not read", procName, NULL);
1871 return dpix;
1872}
1873
1874
1881DPIX *
1883{
1884char buf[256];
1885l_int32 w, h, nbytes, version, xres, yres;
1886l_float64 *data;
1887DPIX *dpix;
1888
1889 PROCNAME("dpixReadStream");
1890
1891 if (!fp)
1892 return (DPIX *)ERROR_PTR("stream not defined", procName, NULL);
1893
1894 if (fscanf(fp, "\nDPix Version %d\n", &version) != 1)
1895 return (DPIX *)ERROR_PTR("not a dpix file", procName, NULL);
1896 if (version != DPIX_VERSION_NUMBER)
1897 return (DPIX *)ERROR_PTR("invalid dpix version", procName, NULL);
1898 if (fscanf(fp, "w = %d, h = %d, nbytes = %d\n", &w, &h, &nbytes) != 3)
1899 return (DPIX *)ERROR_PTR("read fail for data size", procName, NULL);
1900
1901 /* Use fgets() and sscanf(); not fscanf(), for the last
1902 * bit of header data before the float data. The reason is
1903 * that fscanf throws away white space, and if the float data
1904 * happens to begin with ascii character(s) that are white
1905 * space, it will swallow them and all will be lost! */
1906 if (fgets(buf, sizeof(buf), fp) == NULL)
1907 return (DPIX *)ERROR_PTR("fgets read fail", procName, NULL);
1908 if (sscanf(buf, "xres = %d, yres = %d\n", &xres, &yres) != 2)
1909 return (DPIX *)ERROR_PTR("read fail for xres, yres", procName, NULL);
1910
1911 if ((dpix = dpixCreate(w, h)) == NULL)
1912 return (DPIX *)ERROR_PTR("dpix not made", procName, NULL);
1913 dpixSetResolution(dpix, xres, yres);
1914 data = dpixGetData(dpix);
1915 if (fread(data, 1, nbytes, fp) != nbytes) {
1916 dpixDestroy(&dpix);
1917 return (DPIX *)ERROR_PTR("read error for nbytes", procName, NULL);
1918 }
1919 fgetc(fp); /* ending nl */
1920
1921 /* Convert to little-endian if necessary */
1922 dpixEndianByteSwap(dpix, dpix);
1923 return dpix;
1924}
1925
1926
1934DPIX *
1935dpixReadMem(const l_uint8 *data,
1936 size_t size)
1937{
1938FILE *fp;
1939DPIX *dpix;
1940
1941 PROCNAME("dpixReadMem");
1942
1943 if (!data)
1944 return (DPIX *)ERROR_PTR("data not defined", procName, NULL);
1945 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1946 return (DPIX *)ERROR_PTR("stream not opened", procName, NULL);
1947
1948 dpix = dpixReadStream(fp);
1949 fclose(fp);
1950 if (!dpix) L_ERROR("dpix not read\n", procName);
1951 return dpix;
1952}
1953
1954
1962l_ok
1963dpixWrite(const char *filename,
1964 DPIX *dpix)
1965{
1966l_int32 ret;
1967FILE *fp;
1968
1969 PROCNAME("dpixWrite");
1970
1971 if (!filename)
1972 return ERROR_INT("filename not defined", procName, 1);
1973 if (!dpix)
1974 return ERROR_INT("dpix not defined", procName, 1);
1975
1976 if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1977 return ERROR_INT("stream not opened", procName, 1);
1978 ret = dpixWriteStream(fp, dpix);
1979 fclose(fp);
1980 if (ret)
1981 return ERROR_INT("dpix not written to stream", procName, 1);
1982 return 0;
1983}
1984
1985
1993l_ok
1995 DPIX *dpix)
1996{
1997l_int32 w, h, xres, yres;
1998l_uint32 nbytes;
1999l_float64 *data;
2000DPIX *dpixt;
2001
2002 PROCNAME("dpixWriteStream");
2003
2004 if (!fp)
2005 return ERROR_INT("stream not defined", procName, 1);
2006 if (!dpix)
2007 return ERROR_INT("dpix not defined", procName, 1);
2008
2009 /* Convert to little-endian if necessary */
2010 dpixt = dpixEndianByteSwap(NULL, dpix);
2011
2012 dpixGetDimensions(dpixt, &w, &h);
2013 dpixGetResolution(dpixt, &xres, &yres);
2014 data = dpixGetData(dpixt);
2015 nbytes = sizeof(l_float64) * w * h;
2016 fprintf(fp, "\nDPix Version %d\n", DPIX_VERSION_NUMBER);
2017 fprintf(fp, "w = %d, h = %d, nbytes = %u\n", w, h, nbytes);
2018 fprintf(fp, "xres = %d, yres = %d\n", xres, yres);
2019 fwrite(data, 1, nbytes, fp);
2020 fprintf(fp, "\n");
2021
2022 dpixDestroy(&dpixt);
2023 return 0;
2024}
2025
2026
2040l_ok
2041dpixWriteMem(l_uint8 **pdata,
2042 size_t *psize,
2043 DPIX *dpix)
2044{
2045l_int32 ret;
2046FILE *fp;
2047
2048 PROCNAME("dpixWriteMem");
2049
2050 if (pdata) *pdata = NULL;
2051 if (psize) *psize = 0;
2052 if (!pdata)
2053 return ERROR_INT("&data not defined", procName, 1);
2054 if (!psize)
2055 return ERROR_INT("&size not defined", procName, 1);
2056 if (!dpix)
2057 return ERROR_INT("dpix not defined", procName, 1);
2058
2059#if HAVE_FMEMOPEN
2060 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
2061 return ERROR_INT("stream not opened", procName, 1);
2062 ret = dpixWriteStream(fp, dpix);
2063 fputc('\0', fp);
2064 fclose(fp);
2065 *psize = *psize - 1;
2066#else
2067 L_INFO("work-around: writing to a temp file\n", procName);
2068 #ifdef _WIN32
2069 if ((fp = fopenWriteWinTempfile()) == NULL)
2070 return ERROR_INT("tmpfile stream not opened", procName, 1);
2071 #else
2072 if ((fp = tmpfile()) == NULL)
2073 return ERROR_INT("tmpfile stream not opened", procName, 1);
2074 #endif /* _WIN32 */
2075 ret = dpixWriteStream(fp, dpix);
2076 rewind(fp);
2077 *pdata = l_binaryReadStream(fp, psize);
2078 fclose(fp);
2079#endif /* HAVE_FMEMOPEN */
2080 return ret;
2081}
2082
2083
2103DPIX *
2105 DPIX *dpixs)
2106{
2107 PROCNAME("dpixEndianByteSwap");
2108
2109 if (!dpixs)
2110 return (DPIX *)ERROR_PTR("dpixs not defined", procName, dpixd);
2111 if (dpixd && (dpixs != dpixd))
2112 return (DPIX *)ERROR_PTR("dpixd != dpixs", procName, dpixd);
2113
2114#ifdef L_BIG_ENDIAN
2115 {
2116 l_uint32 *data;
2117 l_int32 i, j, w, h;
2118 l_uint32 word;
2119
2120 dpixGetDimensions(dpixs, &w, &h);
2121 if (!dpixd)
2122 dpixd = dpixCopy(dpixs);
2123
2124 data = (l_uint32 *)dpixGetData(dpixd);
2125 for (i = 0; i < h; i++) {
2126 for (j = 0; j < 2 * w; j++, data++) {
2127 word = *data;
2128 *data = (word >> 24) |
2129 ((word >> 8) & 0x0000ff00) |
2130 ((word << 8) & 0x00ff0000) |
2131 (word << 24);
2132 }
2133 }
2134 return dpixd;
2135 }
2136#else /* L_LITTLE_ENDIAN */
2137
2138 if (dpixd)
2139 return dpixd; /* no-op */
2140 else
2141 return dpixClone(dpixs);
2142
2143#endif /* L_BIG_ENDIAN */
2144}
2145
2146
2147/*--------------------------------------------------------------------*
2148 * Print FPix (subsampled, for debugging) *
2149 *--------------------------------------------------------------------*/
2163l_ok
2165 FPIX *fpix,
2166 l_int32 factor)
2167{
2168l_int32 i, j, w, h, count;
2169l_float32 val;
2170
2171 PROCNAME("fpixPrintStream");
2172
2173 if (!fp)
2174 return ERROR_INT("stream not defined", procName, 1);
2175 if (!fpix)
2176 return ERROR_INT("fpix not defined", procName, 1);
2177 if (factor < 1)
2178 return ERROR_INT("sampling factor < 1f", procName, 1);
2179
2180 fpixGetDimensions(fpix, &w, &h);
2181 fprintf(fp, "\nFPix: w = %d, h = %d\n", w, h);
2182 for (i = 0; i < h; i += factor) {
2183 for (count = 0, j = 0; j < w; j += factor, count++) {
2184 fpixGetPixel(fpix, j, i, &val);
2185 fprintf(fp, "val[%d, %d] = %f ", i, j, val);
2186 if ((count + 1) % 3 == 0) fprintf(fp, "\n");
2187 }
2188 if (count % 3) fprintf(fp, "\n");
2189 }
2190 fprintf(fp, "\n");
2191 return 0;
2192}
DPIX * dpixClone(DPIX *dpix)
dpixClone()
Definition: fpix1.c:1159
FPIX * fpixReadStream(FILE *fp)
fpixReadStream()
Definition: fpix1.c:1580
l_float32 * fpixaGetData(FPIXA *fpixa, l_int32 index)
fpixaGetData()
Definition: fpix1.c:970
l_ok fpixCopyResolution(FPIX *fpixd, FPIX *fpixs)
fpixCopyResolution()
Definition: fpix1.c:497
l_ok dpixSetWpl(DPIX *dpix, l_int32 wpl)
dpixSetWpl()
Definition: fpix1.c:1316
l_float64 * dpixGetData(DPIX *dpix)
dpixGetData()
Definition: fpix1.c:1441
l_ok dpixWrite(const char *filename, DPIX *dpix)
dpixWrite()
Definition: fpix1.c:1963
FPIX * fpixCreate(l_int32 width, l_int32 height)
fpixCreate()
Definition: fpix1.c:156
l_ok fpixaAddFPix(FPIXA *fpixa, FPIX *fpix, l_int32 copyflag)
fpixaAddFPix()
Definition: fpix1.c:751
l_ok dpixGetDimensions(DPIX *dpix, l_int32 *pw, l_int32 *ph)
dpixGetDimensions()
Definition: fpix1.c:1251
void dpixDestroy(DPIX **pdpix)
dpixDestroy()
Definition: fpix1.c:1214
void fpixaDestroy(FPIXA **pfpixa)
fpixaDestroy()
Definition: fpix1.c:712
FPIXA * fpixaCopy(FPIXA *fpixa, l_int32 copyflag)
fpixaCopy()
Definition: fpix1.c:665
l_ok dpixSetPixel(DPIX *dpix, l_int32 x, l_int32 y, l_float64 val)
dpixSetPixel()
Definition: fpix1.c:1522
l_float32 * fpixGetData(FPIX *fpix)
fpixGetData()
Definition: fpix1.c:519
l_int32 dpixGetWpl(DPIX *dpix)
dpixGetWpl()
Definition: fpix1.c:1298
FPIX * fpixReadMem(const l_uint8 *data, size_t size)
fpixReadMem()
Definition: fpix1.c:1633
l_ok fpixWriteStream(FILE *fp, FPIX *fpix)
fpixWriteStream()
Definition: fpix1.c:1692
l_ok fpixChangeRefcount(FPIX *fpix, l_int32 delta)
fpixChangeRefcount()
Definition: fpix1.c:432
l_ok fpixaGetPixel(FPIXA *fpixa, l_int32 index, l_int32 x, l_int32 y, l_float32 *pval)
fpixaGetPixel()
Definition: fpix1.c:1002
l_ok fpixWriteMem(l_uint8 **pdata, size_t *psize, FPIX *fpix)
fpixWriteMem()
Definition: fpix1.c:1739
l_ok dpixWriteMem(l_uint8 **pdata, size_t *psize, DPIX *dpix)
dpixWriteMem()
Definition: fpix1.c:2041
l_ok fpixaSetPixel(FPIXA *fpixa, l_int32 index, l_int32 x, l_int32 y, l_float32 val)
fpixaSetPixel()
Definition: fpix1.c:1039
l_ok dpixSetData(DPIX *dpix, l_float64 *data)
dpixSetData()
Definition: fpix1.c:1459
FPIX * fpixaGetFPix(FPIXA *fpixa, l_int32 index, l_int32 accesstype)
fpixaGetFPix()
Definition: fpix1.c:907
l_ok dpixWriteStream(FILE *fp, DPIX *dpix)
dpixWriteStream()
Definition: fpix1.c:1994
l_ok fpixaChangeRefcount(FPIXA *fpixa, l_int32 delta)
fpixaChangeRefcount()
Definition: fpix1.c:885
static l_int32 fpixaExtendArray(FPIXA *fpixa)
fpixaExtendArray()
Definition: fpix1.c:803
l_int32 dpixGetRefcount(DPIX *dpix)
dpixGetRefcount()
Definition: fpix1.c:1336
static l_int32 fpixaExtendArrayToSize(FPIXA *fpixa, l_int32 size)
fpixaExtendArrayToSize()
Definition: fpix1.c:828
l_ok fpixGetDimensions(FPIX *fpix, l_int32 *pw, l_int32 *ph)
fpixGetDimensions()
Definition: fpix1.c:329
l_ok fpixSetDimensions(FPIX *fpix, l_int32 w, l_int32 h)
fpixSetDimensions()
Definition: fpix1.c:355
FPIX * fpixEndianByteSwap(FPIX *fpixd, FPIX *fpixs)
fpixEndianByteSwap()
Definition: fpix1.c:1802
DPIX * dpixReadMem(const l_uint8 *data, size_t size)
dpixReadMem()
Definition: fpix1.c:1935
l_ok fpixWrite(const char *filename, FPIX *fpix)
fpixWrite()
Definition: fpix1.c:1661
DPIX * dpixReadStream(FILE *fp)
dpixReadStream()
Definition: fpix1.c:1882
l_ok dpixGetPixel(DPIX *dpix, l_int32 x, l_int32 y, l_float64 *pval)
dpixGetPixel()
Definition: fpix1.c:1485
static const size_t InitialPtrArraySize
Definition: fpix1.c:133
l_ok fpixSetWpl(FPIX *fpix, l_int32 wpl)
fpixSetWpl()
Definition: fpix1.c:394
l_ok dpixSetResolution(DPIX *dpix, l_int32 xres, l_int32 yres)
dpixSetResolution()
Definition: fpix1.c:1397
DPIX * dpixRead(const char *filename)
dpixRead()
Definition: fpix1.c:1855
FPIX * fpixCopy(FPIX *fpixs)
fpixCopy()
Definition: fpix1.c:255
l_ok dpixChangeRefcount(DPIX *dpix, l_int32 delta)
dpixChangeRefcount()
Definition: fpix1.c:1354
FPIXA * fpixaCreate(l_int32 n)
fpixaCreate()
Definition: fpix1.c:631
l_ok dpixCopyResolution(DPIX *dpixd, DPIX *dpixs)
dpixCopyResolution()
Definition: fpix1.c:1419
l_int32 fpixGetWpl(FPIX *fpix)
fpixGetWpl()
Definition: fpix1.c:376
DPIX * dpixCreateTemplate(DPIX *dpixs)
dpixCreateTemplate()
Definition: fpix1.c:1130
DPIX * dpixCreate(l_int32 width, l_int32 height)
dpixCreate()
Definition: fpix1.c:1080
l_ok fpixGetResolution(FPIX *fpix, l_int32 *pxres, l_int32 *pyres)
fpixGetResolution()
Definition: fpix1.c:453
DPIX * dpixEndianByteSwap(DPIX *dpixd, DPIX *dpixs)
dpixEndianByteSwap()
Definition: fpix1.c:2104
l_ok fpixSetData(FPIX *fpix, l_float32 *data)
fpixSetData()
Definition: fpix1.c:537
l_ok fpixSetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 val)
fpixSetPixel()
Definition: fpix1.c:600
FPIX * fpixClone(FPIX *fpix)
fpixClone()
Definition: fpix1.c:236
void fpixDestroy(FPIX **pfpix)
fpixDestroy()
Definition: fpix1.c:292
DPIX * dpixCopy(DPIX *dpixs)
dpixCopy()
Definition: fpix1.c:1177
l_ok fpixSetResolution(FPIX *fpix, l_int32 xres, l_int32 yres)
fpixSetResolution()
Definition: fpix1.c:475
l_int32 fpixaGetCount(FPIXA *fpixa)
fpixaGetCount()
Definition: fpix1.c:866
FPIX * fpixRead(const char *filename)
fpixRead()
Definition: fpix1.c:1553
l_ok dpixGetResolution(DPIX *dpix, l_int32 *pxres, l_int32 *pyres)
dpixGetResolution()
Definition: fpix1.c:1375
l_ok fpixGetPixel(FPIX *fpix, l_int32 x, l_int32 y, l_float32 *pval)
fpixGetPixel()
Definition: fpix1.c:563
l_ok dpixSetDimensions(DPIX *dpix, l_int32 w, l_int32 h)
dpixSetDimensions()
Definition: fpix1.c:1277
l_ok fpixaGetFPixDimensions(FPIXA *fpixa, l_int32 index, l_int32 *pw, l_int32 *ph)
fpixaGetFPixDimensions()
Definition: fpix1.c:936
FPIX * fpixCreateTemplate(FPIX *fpixs)
fpixCreateTemplate()
Definition: fpix1.c:206
l_ok fpixPrintStream(FILE *fp, FPIX *fpix, l_int32 factor)
fpixPrintStream()
Definition: fpix1.c:2164
l_int32 fpixGetRefcount(FPIX *fpix)
fpixGetRefcount()
Definition: fpix1.c:414
#define FPIX_VERSION_NUMBER
Definition: pix.h:575
@ L_COPY
Definition: pix.h:712
@ L_CLONE
Definition: pix.h:713
@ L_COPY_CLONE
Definition: pix.h:714
@ L_INSERT
Definition: pix.h:711
#define DPIX_VERSION_NUMBER
Definition: pix.h:606
Definition: pix.h:610
l_int32 h
Definition: pix.h:612
l_int32 yres
Definition: pix.h:617
l_float64 * data
Definition: pix.h:619
l_int32 w
Definition: pix.h:611
l_uint32 refcount
Definition: pix.h:614
l_int32 xres
Definition: pix.h:615
l_int32 wpl
Definition: pix.h:613
Definition: pix.h:579
l_int32 w
Definition: pix.h:580
l_int32 wpl
Definition: pix.h:582
l_int32 xres
Definition: pix.h:584
l_uint32 refcount
Definition: pix.h:583
l_int32 h
Definition: pix.h:581
l_float32 * data
Definition: pix.h:588
l_int32 yres
Definition: pix.h:586
Definition: pix.h:594
l_int32 nalloc
Definition: pix.h:596
struct FPix ** fpix
Definition: pix.h:598
l_int32 n
Definition: pix.h:595
l_uint32 refcount
Definition: pix.h:597
FILE * fopenWriteWinTempfile(void)
fopenWriteWinTempfile()
Definition: utils2.c:2055
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1975
FILE * fopenReadFromMemory(const l_uint8 *data, size_t size)
fopenReadFromMemory()
Definition: utils2.c:2009
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1932
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
Definition: utils2.c:1402
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
Definition: utils2.c:1302