17 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_pbm =
"pbm:PDB (PPM) Driver:0:pbm:38:pbm\n";
23 void plD_line_pbm(
PLStream *,
short,
short,
short,
short );
40 #define MAX( a, b ) ( ( a > b ) ? a : b )
41 #define ABS( a ) ( ( a < 0 ) ? -a : a )
43 #define MAX_INTENSITY 255
47 #ifndef ENABLE_DYNDRIVERS
108 plD_line_pbm(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
110 int steps, i,
dx,
dy;
111 double x_off, y_off, dx_step, dy_step;
120 dx_step = dx / steps;
121 dy_step = dy / steps;
125 for ( i = 0; i < steps; i++ )
127 cmap[(int) y_off][(
int) x_off][0] = pls->curcolor.r;
128 cmap[(
int) y_off][(
int) x_off][1] = pls->curcolor.g;
129 cmap[(
int) y_off][(
int) x_off][2] = pls->curcolor.b;
134 cmap[(
int) y_off][(
int) x_off][0] = pls->curcolor.r;
135 cmap[(
int) y_off][(
int) x_off][1] = pls->curcolor.g;
136 cmap[(
int) y_off][(
int) x_off][2] = pls->curcolor.b;
142 #define sign( a ) ( ( a < 0 ) ? -1 : ( ( a == 0 ) ? 0 : 1 ) )
145 #define plot( x, y, c ) { cmap[y - 1][x - 1][0] = ( c )->curcolor.r; \
146 cmap[y - 1][x - 1][1] = ( c )->curcolor.g; \
147 cmap[y - 1][x - 1][2] = ( c )->curcolor.b; }
152 plD_line_pbm(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
159 dx =
ABS( x2a - x1a );
160 dy =
ABS( y2a - y1a );
161 s1 = sign( x2a - x1a );
162 s2 = sign( y2a - y1a );
177 for ( i = 1; i <
dx; i++ )
196 #define plot( x, y, c ) { int i = 3 * ( ( y ) * ( c )->xlength + ( x ) ); \
197 cmap[i + 0] = ( c )->curcolor.r; \
198 cmap[i + 1] = ( c )->curcolor.g; \
199 cmap[i + 2] = ( c )->curcolor.b; }
203 plD_line_pbm(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
206 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
207 PLINT x1b, y1b, x2b, y2b;
212 y1 = pls->
ylength - ( y1 - 0 );
213 y2 = pls->
ylength - ( y2 - 0 );
215 x1b = x1, x2b = x2, y1b = y1, y2b = y2;
216 length = (
PLFLT) sqrt( (
double)
217 ( ( x2b - x1b ) * ( x2b - x1b ) + ( y2b - y1b ) * ( y2b - y1b ) ) );
221 dx = ( x2 - x1 ) / length;
222 dy = ( y2 - y1 ) / length;
229 for ( i = 1; i <= (int) length; i++ )
238 plD_polyline_pbm(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
241 for ( i = 0; i < npts - 1; i++ )
242 plD_line_pbm( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
249 size_t im_size, nwrite;
253 fprintf( fp,
"%s\n",
"P6" );
255 fprintf( fp,
"%d\n", MAX_INTENSITY );
266 nwrite = fwrite( cmap, 1, im_size, fp );
267 if ( nwrite != im_size )
268 plabort(
"pbm driver: Error writing pbm file" );
281 for ( i = 0; i < pls->
ylength; i++ )
282 for ( j = 0; j < pls->
xlength; j++ )
284 k = ( i * pls->
xlength + j ) * 3;
285 cmap[k + 0] = pls->
cmap0[0].
r;
286 cmap[k + 1] = pls->
cmap0[0].
g;
287 cmap[k + 2] = pls->
cmap0[0].
b;