1 /* im_mask2vips
2  *
3  * Author: J.Cupitt
4  * Written on: 6/6/94
5  * Modified on:
6  * 7/10/94 JC
7  *	- new IM_ARRAY()
8  * 1/2/10
9  * 	- gtkdoc
10  */
11 
12 /*
13 
14     This file is part of VIPS.
15 
16     VIPS is free software; you can redistribute it and/or modify
17     it under the terms of the GNU Lesser General Public License as published by
18     the Free Software Foundation; either version 2 of the License, or
19     (at your option) any later version.
20 
21     This program is distributed in the hope that it will be useful,
22     but WITHOUT ANY WARRANTY; without even the implied warranty of
23     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24     GNU Lesser General Public License for more details.
25 
26     You should have received a copy of the GNU Lesser General Public License
27     along with this program; if not, write to the Free Software
28     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29     02110-1301  USA
30 
31  */
32 
33 /*
34 
35     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
36 
37  */
38 
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif /*HAVE_CONFIG_H*/
42 #include <vips/intl.h>
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 
47 #include <vips/vips.h>
48 #include <vips/vips7compat.h>
49 
50 /**
51  * im_mask2vips:
52  * @in: input mask
53  * @out: output image
54  *
55  * Write a one-band, %IM_BANDFMT_DOUBLE image to @out based on mask @in.
56  *
57  * See also: im_vips2mask().
58  *
59  * Returns: 0 on success, -1 on error
60  */
61 int
im_mask2vips(DOUBLEMASK * in,IMAGE * out)62 im_mask2vips( DOUBLEMASK *in, IMAGE *out )
63 {
64 	int x, y;
65 	double *buf, *p, *q;
66 
67 	/* Check the mask.
68 	 */
69 	if( !in ||
70 		!in->coeff ) {
71 		im_error( "im_mask2vips", "%s", _( "bad input mask" ) );
72 		return( -1 );
73 	}
74 
75 	/* Make the output image.
76 	 */
77 	im_initdesc( out, in->xsize, in->ysize, 1,
78 		IM_BBITS_DOUBLE, IM_BANDFMT_DOUBLE,
79 		IM_CODING_NONE,
80 		IM_TYPE_B_W,
81 		1.0, 1.0,
82 		0, 0 );
83 	if( im_setupout( out ) )
84 		return( -1 );
85 
86 	/* Make an output buffer.
87 	 */
88 	if( !(buf = IM_ARRAY( out, in->xsize, double )) )
89 		return( -1 );
90 
91 	/* Write!
92 	 */
93 	for( p = in->coeff, y = 0; y < out->Ysize; y++ ) {
94 		q = buf;
95 
96 		for( x = 0; x < out->Xsize; x++ )
97 			*q++ = *p++;
98 
99 		if( im_writeline( y, out, (void *) buf ) )
100 			return( -1 );
101 	}
102 
103 	vips_image_set_double( out, "scale", in->scale );
104 	vips_image_set_double( out, "offset", in->offset );
105 
106 	return( 0 );
107 }
108 
109 int
im_imask2vips(INTMASK * in,IMAGE * out)110 im_imask2vips( INTMASK *in, IMAGE *out )
111 {
112 	DOUBLEMASK *d;
113 	int result;
114 
115 	if( !(d = im_imask2dmask( in, in->filename )) )
116 		return( -1 );
117 	result = im_mask2vips( d, out );
118 	im_free_dmask( d );
119 
120 	return( result );
121 }
122 
123