• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*====================================================================*
2  -  Copyright (C) 2001 Leptonica.  All rights reserved.
3  -  This software is distributed in the hope that it will be
4  -  useful, but with NO WARRANTY OF ANY KIND.
5  -  No author or distributor accepts responsibility to anyone for the
6  -  consequences of using this software, or for whether it serves any
7  -  particular purpose or works at all, unless he or she says so in
8  -  writing.  Everyone is granted permission to copy, modify and
9  -  redistribute this source code, for commercial or non-commercial
10  -  purposes, with the following restrictions: (1) the origin of this
11  -  source code must not be misrepresented; (2) modified versions must
12  -  be plainly marked as such; and (3) this notice may not be removed
13  -  or altered from any source or modified source distribution.
14  *====================================================================*/
15 
16 /*
17  *  fpix1.c
18  *
19  *    This file has basic constructors, destructors and field accessors
20  *    for FPix and DPix.
21  *
22  *    FPix Create/copy/destroy
23  *          FPIX          *fpixCreate()
24  *          FPIX          *fpixCreateTemplate()
25  *          FPIX          *fpixClone()
26  *          FPIX          *fpixCopy()
27  *          l_int32        fpixResizeImageData()
28  *          void           fpixDestroy()
29  *
30  *    FPix accessors
31  *          l_int32        fpixGetDimensions()
32  *          l_int32        fpixSetDimensions()
33  *          l_int32        fpixGetWpl()
34  *          l_int32        fpixSetWpl()
35  *          l_int32        fpixGetRefcount()
36  *          l_int32        fpixChangeRefcount()
37  *          l_int32        fpixGetResolution()
38  *          l_int32        fpixSetResolution()
39  *          l_int32        fpixCopyResolution()
40  *          l_float32     *fpixGetData()
41  *          l_int32        fpixSetData()
42  *
43  *    DPix Create/copy/destroy
44  *          DPIX          *dpixCreate()
45  *          DPIX          *dpixCreateTemplate()
46  *          DPIX          *dpixClone()
47  *          DPIX          *dpixCopy()
48  *          l_int32        dpixResizeImageData()
49  *          void           dpixDestroy()
50  *
51  *    DPix accessors
52  *          l_int32        dpixGetDimensions()
53  *          l_int32        dpixSetDimensions()
54  *          l_int32        dpixGetWpl()
55  *          l_int32        dpixSetWpl()
56  *          l_int32        dpixGetRefcount()
57  *          l_int32        dpixChangeRefcount()
58  *          l_int32        dpixGetResolution()
59  *          l_int32        dpixSetResolution()
60  *          l_int32        dpixCopyResolution()
61  *          l_float64     *dpixGetData()
62  *          l_int32        dpixSetData()
63  */
64 
65 #include <stdio.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #include "allheaders.h"
69 
70 
71 /*--------------------------------------------------------------------*
72  *                     FPix Create/copy/destroy                       *
73  *--------------------------------------------------------------------*/
74 /*!
75  *  fpixCreate()
76  *
77  *      Input:  width, height
78  *      Return: fpixd (with data allocated and initialized to 0),
79  *                     or null on error
80  *
81  *  Notes:
82  *      (1) Makes a FPix of specified size, with the data array
83  *          allocated and initialized to 0.
84  */
85 FPIX *
fpixCreate(l_int32 width,l_int32 height)86 fpixCreate(l_int32  width,
87            l_int32  height)
88 {
89 l_float32  *data;
90 FPIX       *fpixd;
91 
92     PROCNAME("fpixCreate");
93 
94     if (width <= 0)
95         return (FPIX *)ERROR_PTR("width must be > 0", procName, NULL);
96     if (height <= 0)
97         return (FPIX *)ERROR_PTR("height must be > 0", procName, NULL);
98 
99     if ((fpixd = (FPIX *)CALLOC(1, sizeof(FPIX))) == NULL)
100         return (FPIX *)ERROR_PTR("CALLOC fail for fpixd", procName, NULL);
101     fpixSetDimensions(fpixd, width, height);
102     fpixSetWpl(fpixd, width);
103     fpixd->refcount = 1;
104 
105     data = (l_float32 *)CALLOC(width * height, sizeof(l_float32));
106     if (!data)
107         return (FPIX *)ERROR_PTR("CALLOC fail for data", procName, NULL);
108     fpixSetData(fpixd, data);
109 
110     return fpixd;
111 }
112 
113 
114 /*!
115  *  fpixCreateTemplate()
116  *
117  *      Input:  fpixs
118  *      Return: fpixd, or null on error
119  *
120  *  Notes:
121  *      (1) Makes a FPix of the same size as the input FPix, with the
122  *          data array allocated and initialized to 0.
123  *      (2) Copies the resolution.
124  */
125 FPIX *
fpixCreateTemplate(FPIX * fpixs)126 fpixCreateTemplate(FPIX  *fpixs)
127 {
128 l_int32  w, h;
129 FPIX    *fpixd;
130 
131     PROCNAME("fpixCreateTemplate");
132 
133     if (!fpixs)
134         return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
135 
136     fpixGetDimensions(fpixs, &w, &h);
137     fpixd = fpixCreate(w, h);
138     fpixCopyResolution(fpixd, fpixs);
139     return fpixd;
140 }
141 
142 
143 /*!
144  *  fpixClone()
145  *
146  *      Input:  fpix
147  *      Return: same fpix (ptr), or null on error
148  *
149  *  Notes:
150  *      (1) See pixClone() for definition and usage.
151  */
152 FPIX *
fpixClone(FPIX * fpix)153 fpixClone(FPIX  *fpix)
154 {
155     PROCNAME("fpixClone");
156 
157     if (!fpix)
158         return (FPIX *)ERROR_PTR("fpix not defined", procName, NULL);
159     fpixChangeRefcount(fpix, 1);
160 
161     return fpix;
162 }
163 
164 
165 /*!
166  *  fpixCopy()
167  *
168  *      Input:  fpixd (<optional>; can be null, or equal to fpixs,
169  *                    or different from fpixs)
170  *              fpixs
171  *      Return: fpixd, or null on error
172  *
173  *  Notes:
174  *      (1) There are three cases:
175  *            (a) fpixd == null  (makes a new fpix; refcount = 1)
176  *            (b) fpixd == fpixs  (no-op)
177  *            (c) fpixd != fpixs  (data copy; no change in refcount)
178  *          If the refcount of fpixd > 1, case (c) will side-effect
179  *          these handles.
180  *      (2) The general pattern of use is:
181  *             fpixd = fpixCopy(fpixd, fpixs);
182  *          This will work for all three cases.
183  *          For clarity when the case is known, you can use:
184  *            (a) fpixd = fpixCopy(NULL, fpixs);
185  *            (c) fpixCopy(fpixd, fpixs);
186  *      (3) For case (c), we check if fpixs and fpixd are the same size.
187  *          If so, the data is copied directly.
188  *          Otherwise, the data is reallocated to the correct size
189  *          and the copy proceeds.  The refcount of fpixd is unchanged.
190  *      (4) This operation, like all others that may involve a pre-existing
191  *          fpixd, will side-effect any existing clones of fpixd.
192  */
193 FPIX *
fpixCopy(FPIX * fpixd,FPIX * fpixs)194 fpixCopy(FPIX  *fpixd,   /* can be null */
195          FPIX  *fpixs)
196 {
197 l_int32     w, h, bytes;
198 l_float32  *datas, *datad;
199 
200     PROCNAME("fpixCopy");
201 
202     if (!fpixs)
203         return (FPIX *)ERROR_PTR("fpixs not defined", procName, NULL);
204     if (fpixs == fpixd)
205         return fpixd;
206 
207         /* Total bytes in image data */
208     fpixGetDimensions(fpixs, &w, &h);
209     bytes = 4 * w * h;
210 
211         /* If we're making a new fpix ... */
212     if (!fpixd) {
213         if ((fpixd = fpixCreateTemplate(fpixs)) == NULL)
214             return (FPIX *)ERROR_PTR("fpixd not made", procName, NULL);
215         datas = fpixGetData(fpixs);
216         datad = fpixGetData(fpixd);
217         memcpy((char *)datad, (char *)datas, bytes);
218         return fpixd;
219     }
220 
221         /* Reallocate image data if sizes are different */
222     fpixResizeImageData(fpixd, fpixs);
223 
224         /* Copy data */
225     fpixCopyResolution(fpixd, fpixs);
226     datas = fpixGetData(fpixs);
227     datad = fpixGetData(fpixd);
228     memcpy((char*)datad, (char*)datas, bytes);
229     return fpixd;
230 }
231 
232 
233 /*!
234  *  fpixResizeImageData()
235  *
236  *      Input:  fpixd, fpixs
237  *      Return: 0 if OK, 1 on error
238  */
239 l_int32
fpixResizeImageData(FPIX * fpixd,FPIX * fpixs)240 fpixResizeImageData(FPIX  *fpixd,
241                     FPIX  *fpixs)
242 {
243 l_int32     ws, hs, wd, hd, bytes;
244 l_float32  *data;
245 
246     PROCNAME("fpixResizeImageData");
247 
248     if (!fpixs)
249         return ERROR_INT("fpixs not defined", procName, 1);
250     if (!fpixd)
251         return ERROR_INT("fpixd not defined", procName, 1);
252 
253     fpixGetDimensions(fpixs, &ws, &hs);
254     fpixGetDimensions(fpixd, &wd, &hd);
255     if (ws == wd && hs == hd)  /* nothing to do */
256         return 0;
257 
258     fpixSetDimensions(fpixd, ws, hs);
259     fpixSetWpl(fpixd, ws);
260     bytes = 4 * ws * hs;
261     data = fpixGetData(fpixd);
262     if (data) FREE(data);
263     if ((data = (l_float32 *)MALLOC(bytes)) == NULL)
264         return ERROR_INT("MALLOC fail for data", procName, 1);
265     fpixSetData(fpixd, data);
266     return 0;
267 }
268 
269 
270 /*!
271  *  fpixDestroy()
272  *
273  *      Input:  &fpix <will be nulled>
274  *      Return: void
275  *
276  *  Notes:
277  *      (1) Decrements the ref count and, if 0, destroys the fpix.
278  *      (2) Always nulls the input ptr.
279  */
280 void
fpixDestroy(FPIX ** pfpix)281 fpixDestroy(FPIX  **pfpix)
282 {
283 l_float32  *data;
284 FPIX       *fpix;
285 
286     PROCNAME("fpixDestroy");
287 
288     if (!pfpix) {
289         L_WARNING("ptr address is null!", procName);
290         return;
291     }
292 
293     if ((fpix = *pfpix) == NULL)
294         return;
295 
296         /* Decrement the ref count.  If it is 0, destroy the fpix. */
297     fpixChangeRefcount(fpix, -1);
298     if (fpixGetRefcount(fpix) <= 0) {
299         if ((data = fpixGetData(fpix)) != NULL)
300             FREE(data);
301         FREE(fpix);
302     }
303 
304     *pfpix = NULL;
305     return;
306 }
307 
308 
309 /*--------------------------------------------------------------------*
310  *                          FPix  Accessors                           *
311  *--------------------------------------------------------------------*/
312 /*!
313  *  fpixGetDimensions()
314  *
315  *      Input:  fpix
316  *              &w, &h (<optional return>; each can be null)
317  *      Return: 0 if OK, 1 on error
318  */
319 l_int32
fpixGetDimensions(FPIX * fpix,l_int32 * pw,l_int32 * ph)320 fpixGetDimensions(FPIX     *fpix,
321                   l_int32  *pw,
322                   l_int32  *ph)
323 {
324     PROCNAME("fpixGetDimensions");
325 
326     if (!fpix)
327         return ERROR_INT("fpix not defined", procName, 1);
328     if (pw) *pw = fpix->w;
329     if (ph) *ph = fpix->h;
330     return 0;
331 }
332 
333 
334 /*!
335  *  fpixSetDimensions()
336  *
337  *      Input:  fpix
338  *              w, h
339  *      Return: 0 if OK, 1 on error
340  */
341 l_int32
fpixSetDimensions(FPIX * fpix,l_int32 w,l_int32 h)342 fpixSetDimensions(FPIX     *fpix,
343                   l_int32   w,
344                   l_int32   h)
345 {
346     PROCNAME("fpixSetDimensions");
347 
348     if (!fpix)
349         return ERROR_INT("fpix not defined", procName, 1);
350     fpix->w = w;
351     fpix->h = h;
352     return 0;
353 }
354 
355 
356 l_int32
fpixGetWpl(FPIX * fpix)357 fpixGetWpl(FPIX  *fpix)
358 {
359     PROCNAME("fpixGetWpl");
360 
361     if (!fpix)
362         return ERROR_INT("fpix not defined", procName, 1);
363     return fpix->wpl;
364 }
365 
366 
367 l_int32
fpixSetWpl(FPIX * fpix,l_int32 wpl)368 fpixSetWpl(FPIX    *fpix,
369            l_int32  wpl)
370 {
371     PROCNAME("fpixSetWpl");
372 
373     if (!fpix)
374         return ERROR_INT("fpix not defined", procName, 1);
375 
376     fpix->wpl = wpl;
377     return 0;
378 }
379 
380 
381 l_int32
fpixGetRefcount(FPIX * fpix)382 fpixGetRefcount(FPIX  *fpix)
383 {
384     PROCNAME("fpixGetRefcount");
385 
386     if (!fpix)
387         return ERROR_INT("fpix not defined", procName, UNDEF);
388     return fpix->refcount;
389 }
390 
391 
392 l_int32
fpixChangeRefcount(FPIX * fpix,l_int32 delta)393 fpixChangeRefcount(FPIX    *fpix,
394                    l_int32  delta)
395 {
396     PROCNAME("fpixChangeRefcount");
397 
398     if (!fpix)
399         return ERROR_INT("fpix not defined", procName, 1);
400 
401     fpix->refcount += delta;
402     return 0;
403 }
404 
405 
406 l_int32
fpixGetResolution(FPIX * fpix,l_int32 * pxres,l_int32 * pyres)407 fpixGetResolution(FPIX     *fpix,
408                   l_int32  *pxres,
409                   l_int32  *pyres)
410 {
411     PROCNAME("fpixGetResolution");
412 
413     if (!fpix)
414         return ERROR_INT("fpix not defined", procName, 1);
415     if (pxres) *pxres = fpix->xres;
416     if (pyres) *pyres = fpix->yres;
417     return 0;
418 }
419 
420 
421 l_int32
fpixSetResolution(FPIX * fpix,l_int32 xres,l_int32 yres)422 fpixSetResolution(FPIX    *fpix,
423                   l_int32  xres,
424                   l_int32  yres)
425 {
426     PROCNAME("fpixSetResolution");
427 
428     if (!fpix)
429         return ERROR_INT("fpix not defined", procName, 1);
430 
431     fpix->xres = xres;
432     fpix->yres = yres;
433     return 0;
434 }
435 
436 
437 l_int32
fpixCopyResolution(FPIX * fpixd,FPIX * fpixs)438 fpixCopyResolution(FPIX  *fpixd,
439                    FPIX  *fpixs)
440 {
441 l_int32  xres, yres;
442     PROCNAME("fpixCopyResolution");
443 
444     if (!fpixs || !fpixd)
445         return ERROR_INT("fpixs and fpixd not both defined", procName, 1);
446 
447     fpixGetResolution(fpixs, &xres, &yres);
448     fpixSetResolution(fpixd, xres, yres);
449     return 0;
450 }
451 
452 
453 l_float32 *
fpixGetData(FPIX * fpix)454 fpixGetData(FPIX  *fpix)
455 {
456     PROCNAME("fpixGetData");
457 
458     if (!fpix)
459         return (l_float32 *)ERROR_PTR("fpix not defined", procName, NULL);
460     return fpix->data;
461 }
462 
463 
464 l_int32
fpixSetData(FPIX * fpix,l_float32 * data)465 fpixSetData(FPIX       *fpix,
466             l_float32  *data)
467 {
468     PROCNAME("fpixSetData");
469 
470     if (!fpix)
471         return ERROR_INT("fpix not defined", procName, 1);
472 
473     fpix->data = data;
474     return 0;
475 }
476 
477 
478 /*--------------------------------------------------------------------*
479  *                     DPix Create/copy/destroy                       *
480  *--------------------------------------------------------------------*/
481 /*!
482  *  dpixCreate()
483  *
484  *      Input:  width, height
485  *      Return: dpix (with data allocated and initialized to 0),
486  *                     or null on error
487  *
488  *  Notes:
489  *      (1) Makes a DPix of specified size, with the data array
490  *          allocated and initialized to 0.
491  */
492 DPIX *
dpixCreate(l_int32 width,l_int32 height)493 dpixCreate(l_int32  width,
494            l_int32  height)
495 {
496 l_float64  *data;
497 DPIX       *dpix;
498 
499     PROCNAME("dpixCreate");
500 
501     if (width <= 0)
502         return (DPIX *)ERROR_PTR("width must be > 0", procName, NULL);
503     if (height <= 0)
504         return (DPIX *)ERROR_PTR("height must be > 0", procName, NULL);
505 
506     if ((dpix = (DPIX *)CALLOC(1, sizeof(DPIX))) == NULL)
507         return (DPIX *)ERROR_PTR("CALLOC fail for dpix", procName, NULL);
508     dpixSetDimensions(dpix, width, height);
509     dpixSetWpl(dpix, width);
510     dpix->refcount = 1;
511 
512     data = (l_float64 *)CALLOC(width * height, sizeof(l_float64));
513     if (!data)
514         return (DPIX *)ERROR_PTR("CALLOC fail for data", procName, NULL);
515     dpixSetData(dpix, data);
516 
517     return dpix;
518 }
519 
520 
521 /*!
522  *  dpixCreateTemplate()
523  *
524  *      Input:  dpixs
525  *      Return: dpixd, or null on error
526  *
527  *  Notes:
528  *      (1) Makes a DPix of the same size as the input DPix, with the
529  *          data array allocated and initialized to 0.
530  *      (2) Copies the resolution.
531  */
532 DPIX *
dpixCreateTemplate(DPIX * dpixs)533 dpixCreateTemplate(DPIX  *dpixs)
534 {
535 l_int32  w, h;
536 DPIX    *dpixd;
537 
538     PROCNAME("dpixCreateTemplate");
539 
540     if (!dpixs)
541         return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
542 
543     dpixGetDimensions(dpixs, &w, &h);
544     dpixd = dpixCreate(w, h);
545     dpixCopyResolution(dpixd, dpixs);
546     return dpixd;
547 }
548 
549 
550 /*!
551  *  dpixClone()
552  *
553  *      Input:  dpix
554  *      Return: same dpix (ptr), or null on error
555  *
556  *  Notes:
557  *      (1) See pixClone() for definition and usage.
558  */
559 DPIX *
dpixClone(DPIX * dpix)560 dpixClone(DPIX  *dpix)
561 {
562     PROCNAME("dpixClone");
563 
564     if (!dpix)
565         return (DPIX *)ERROR_PTR("dpix not defined", procName, NULL);
566     dpixChangeRefcount(dpix, 1);
567 
568     return dpix;
569 }
570 
571 
572 /*!
573  *  dpixCopy()
574  *
575  *      Input:  dpixd (<optional>; can be null, or equal to dpixs,
576  *                    or different from dpixs)
577  *              dpixs
578  *      Return: dpixd, or null on error
579  *
580  *  Notes:
581  *      (1) There are three cases:
582  *            (a) dpixd == null  (makes a new dpix; refcount = 1)
583  *            (b) dpixd == dpixs  (no-op)
584  *            (c) dpixd != dpixs  (data copy; no change in refcount)
585  *          If the refcount of dpixd > 1, case (c) will side-effect
586  *          these handles.
587  *      (2) The general pattern of use is:
588  *             dpixd = dpixCopy(dpixd, dpixs);
589  *          This will work for all three cases.
590  *          For clarity when the case is known, you can use:
591  *            (a) dpixd = dpixCopy(NULL, dpixs);
592  *            (c) dpixCopy(dpixd, dpixs);
593  *      (3) For case (c), we check if dpixs and dpixd are the same size.
594  *          If so, the data is copied directly.
595  *          Otherwise, the data is reallocated to the correct size
596  *          and the copy proceeds.  The refcount of dpixd is unchanged.
597  *      (4) This operation, like all others that may involve a pre-existing
598  *          dpixd, will side-effect any existing clones of dpixd.
599  */
600 DPIX *
dpixCopy(DPIX * dpixd,DPIX * dpixs)601 dpixCopy(DPIX  *dpixd,   /* can be null */
602          DPIX  *dpixs)
603 {
604 l_int32     w, h, bytes;
605 l_float64  *datas, *datad;
606 
607     PROCNAME("dpixCopy");
608 
609     if (!dpixs)
610         return (DPIX *)ERROR_PTR("dpixs not defined", procName, NULL);
611     if (dpixs == dpixd)
612         return dpixd;
613 
614         /* Total bytes in image data */
615     dpixGetDimensions(dpixs, &w, &h);
616     bytes = 8 * w * h;
617 
618         /* If we're making a new dpix ... */
619     if (!dpixd) {
620         if ((dpixd = dpixCreateTemplate(dpixs)) == NULL)
621             return (DPIX *)ERROR_PTR("dpixd not made", procName, NULL);
622         datas = dpixGetData(dpixs);
623         datad = dpixGetData(dpixd);
624         memcpy((char *)datad, (char *)datas, bytes);
625         return dpixd;
626     }
627 
628         /* Reallocate image data if sizes are different */
629     dpixResizeImageData(dpixd, dpixs);
630 
631         /* Copy data */
632     dpixCopyResolution(dpixd, dpixs);
633     datas = dpixGetData(dpixs);
634     datad = dpixGetData(dpixd);
635     memcpy((char*)datad, (char*)datas, bytes);
636     return dpixd;
637 }
638 
639 
640 /*!
641  *  dpixResizeImageData()
642  *
643  *      Input:  dpixd, dpixs
644  *      Return: 0 if OK, 1 on error
645  */
646 l_int32
dpixResizeImageData(DPIX * dpixd,DPIX * dpixs)647 dpixResizeImageData(DPIX  *dpixd,
648                     DPIX  *dpixs)
649 {
650 l_int32     ws, hs, wd, hd, bytes;
651 l_float64  *data;
652 
653     PROCNAME("dpixResizeImageData");
654 
655     if (!dpixs)
656         return ERROR_INT("dpixs not defined", procName, 1);
657     if (!dpixd)
658         return ERROR_INT("dpixd not defined", procName, 1);
659 
660     dpixGetDimensions(dpixs, &ws, &hs);
661     dpixGetDimensions(dpixd, &wd, &hd);
662     if (ws == wd && hs == hd)  /* nothing to do */
663         return 0;
664 
665     dpixSetDimensions(dpixd, ws, hs);
666     dpixSetWpl(dpixd, ws);
667     bytes = 8 * ws * hs;
668     data = dpixGetData(dpixd);
669     if (data) FREE(data);
670     if ((data = (l_float64 *)MALLOC(bytes)) == NULL)
671         return ERROR_INT("MALLOC fail for data", procName, 1);
672     dpixSetData(dpixd, data);
673     return 0;
674 }
675 
676 
677 /*!
678  *  dpixDestroy()
679  *
680  *      Input:  &dpix <will be nulled>
681  *      Return: void
682  *
683  *  Notes:
684  *      (1) Decrements the ref count and, if 0, destroys the dpix.
685  *      (2) Always nulls the input ptr.
686  */
687 void
dpixDestroy(DPIX ** pdpix)688 dpixDestroy(DPIX  **pdpix)
689 {
690 l_float64  *data;
691 DPIX       *dpix;
692 
693     PROCNAME("dpixDestroy");
694 
695     if (!pdpix) {
696         L_WARNING("ptr address is null!", procName);
697         return;
698     }
699 
700     if ((dpix = *pdpix) == NULL)
701         return;
702 
703         /* Decrement the ref count.  If it is 0, destroy the dpix. */
704     dpixChangeRefcount(dpix, -1);
705     if (dpixGetRefcount(dpix) <= 0) {
706         if ((data = dpixGetData(dpix)) != NULL)
707             FREE(data);
708         FREE(dpix);
709     }
710 
711     *pdpix = NULL;
712     return;
713 }
714 
715 
716 /*--------------------------------------------------------------------*
717  *                          DPix  Accessors                           *
718  *--------------------------------------------------------------------*/
719 /*!
720  *  dpixGetDimensions()
721  *
722  *      Input:  dpix
723  *              &w, &h (<optional return>; each can be null)
724  *      Return: 0 if OK, 1 on error
725  */
726 l_int32
dpixGetDimensions(DPIX * dpix,l_int32 * pw,l_int32 * ph)727 dpixGetDimensions(DPIX     *dpix,
728                   l_int32  *pw,
729                   l_int32  *ph)
730 {
731     PROCNAME("dpixGetDimensions");
732 
733     if (!dpix)
734         return ERROR_INT("dpix not defined", procName, 1);
735     if (pw) *pw = dpix->w;
736     if (ph) *ph = dpix->h;
737     return 0;
738 }
739 
740 
741 /*!
742  *  dpixSetDimensions()
743  *
744  *      Input:  dpix
745  *              w, h
746  *      Return: 0 if OK, 1 on error
747  */
748 l_int32
dpixSetDimensions(DPIX * dpix,l_int32 w,l_int32 h)749 dpixSetDimensions(DPIX     *dpix,
750                   l_int32   w,
751                   l_int32   h)
752 {
753     PROCNAME("dpixSetDimensions");
754 
755     if (!dpix)
756         return ERROR_INT("dpix not defined", procName, 1);
757     dpix->w = w;
758     dpix->h = h;
759     return 0;
760 }
761 
762 
763 l_int32
dpixGetWpl(DPIX * dpix)764 dpixGetWpl(DPIX  *dpix)
765 {
766     PROCNAME("dpixGetWpl");
767 
768     if (!dpix)
769         return ERROR_INT("dpix not defined", procName, 1);
770     return dpix->wpl;
771 }
772 
773 
774 l_int32
dpixSetWpl(DPIX * dpix,l_int32 wpl)775 dpixSetWpl(DPIX    *dpix,
776            l_int32  wpl)
777 {
778     PROCNAME("dpixSetWpl");
779 
780     if (!dpix)
781         return ERROR_INT("dpix not defined", procName, 1);
782 
783     dpix->wpl = wpl;
784     return 0;
785 }
786 
787 
788 l_int32
dpixGetRefcount(DPIX * dpix)789 dpixGetRefcount(DPIX  *dpix)
790 {
791     PROCNAME("dpixGetRefcount");
792 
793     if (!dpix)
794         return ERROR_INT("dpix not defined", procName, UNDEF);
795     return dpix->refcount;
796 }
797 
798 
799 l_int32
dpixChangeRefcount(DPIX * dpix,l_int32 delta)800 dpixChangeRefcount(DPIX    *dpix,
801                    l_int32  delta)
802 {
803     PROCNAME("dpixChangeRefcount");
804 
805     if (!dpix)
806         return ERROR_INT("dpix not defined", procName, 1);
807 
808     dpix->refcount += delta;
809     return 0;
810 }
811 
812 
813 l_int32
dpixGetResolution(DPIX * dpix,l_int32 * pxres,l_int32 * pyres)814 dpixGetResolution(DPIX     *dpix,
815                   l_int32  *pxres,
816                   l_int32  *pyres)
817 {
818     PROCNAME("dpixGetResolution");
819 
820     if (!dpix)
821         return ERROR_INT("dpix not defined", procName, 1);
822     if (pxres) *pxres = dpix->xres;
823     if (pyres) *pyres = dpix->yres;
824     return 0;
825 }
826 
827 
828 l_int32
dpixSetResolution(DPIX * dpix,l_int32 xres,l_int32 yres)829 dpixSetResolution(DPIX    *dpix,
830                   l_int32  xres,
831                   l_int32  yres)
832 {
833     PROCNAME("dpixSetResolution");
834 
835     if (!dpix)
836         return ERROR_INT("dpix not defined", procName, 1);
837 
838     dpix->xres = xres;
839     dpix->yres = yres;
840     return 0;
841 }
842 
843 
844 l_int32
dpixCopyResolution(DPIX * dpixd,DPIX * dpixs)845 dpixCopyResolution(DPIX  *dpixd,
846                    DPIX  *dpixs)
847 {
848 l_int32  xres, yres;
849     PROCNAME("dpixCopyResolution");
850 
851     if (!dpixs || !dpixd)
852         return ERROR_INT("dpixs and dpixd not both defined", procName, 1);
853 
854     dpixGetResolution(dpixs, &xres, &yres);
855     dpixSetResolution(dpixd, xres, yres);
856     return 0;
857 }
858 
859 
860 l_float64 *
dpixGetData(DPIX * dpix)861 dpixGetData(DPIX  *dpix)
862 {
863     PROCNAME("dpixGetData");
864 
865     if (!dpix)
866         return (l_float64 *)ERROR_PTR("dpix not defined", procName, NULL);
867     return dpix->data;
868 }
869 
870 
871 l_int32
dpixSetData(DPIX * dpix,l_float64 * data)872 dpixSetData(DPIX       *dpix,
873             l_float64  *data)
874 {
875     PROCNAME("dpixSetData");
876 
877     if (!dpix)
878         return ERROR_INT("dpix not defined", procName, 1);
879 
880     dpix->data = data;
881     return 0;
882 }
883 
884 
885