26 void luma_init( luma
*this )
45 static inline int sqrti( int n
)
70 uint16_t *luma_render( luma
*this )
82 int max
= ( 1 << 16 ) - 1;
83 uint16_t *image
= malloc( this->w
* this->h
* sizeof( uint16_t ) );
84 uint16_t *end
= image
+ this->w
* this->h
;
88 int lpb
= this->h
/ this->bands
;
89 int rpb
= max
/ this->bands
;
92 int half_w
= this->w
/ 2;
93 int half_h
= this->h
/ 2;
95 if ( !this->dmirror
&& ( this->hmirror
|| this->vmirror
) )
98 for ( i
= 0; i
< this->bands
; i
++ )
103 if ( this->rband
&& i
% 2 == 1 )
113 int length
= sqrti( half_w
* half_w
+ lpb
* lpb
/ 4 );
117 for ( j
= 0; j
< lpb
; j
++ )
120 for ( k
= 0; k
< this->w
; k
++ )
123 value
= sqrti( x
* x
+ y
* y
);
124 *p
++ = lower
+ ( direction
* rpb
* ( ( max
* value
) / length
) / max
) + ( j
* this->offset
* 2 / lpb
) + ( j
* this->offset
/ lpb
);
132 for ( j
= 0; j
< lpb
; j
++ )
134 int value
= ( ( j
* this->w
) / lpb
) - half_w
;
137 for ( k
= - half_w
; k
< value
; k
++ )
138 *p
++ = lower
+ ( direction
* rpb
* ( ( max
* abs( k
) ) / half_w
) / max
);
139 for ( k
= value
; k
< abs( value
); k
++ )
140 *p
++ = lower
+ ( direction
* rpb
* ( ( max
* abs( value
) ) / half_w
) / max
) + ( j
* this->offset
* 2 / lpb
) + ( j
* this->offset
/ lpb
);
141 for ( k
= abs( value
); k
< half_w
; k
++ )
142 *p
++ = lower
+ ( direction
* rpb
* ( ( max
* abs( k
) ) / half_w
) / max
);
150 for ( j
= -half_h
; j
< half_h
; j
++ )
154 for ( k
= - half_w
; k
< half_w
; k
++ )
156 length
= sqrti( k
* k
+ j
* j
);
157 *p
++ = ( max
/ 4 * k
) / ( length
+ 1 );
162 for ( k
= half_w
; k
> - half_w
; k
-- )
164 length
= sqrti( k
* k
+ j
* j
);
165 *p
++ = ( max
/ 2 ) + ( max
/ 4 * k
) / ( length
+ 1 );
173 for ( j
= 0; j
< lpb
; j
++ )
174 for ( k
= 0; k
< this->w
; k
++ )
175 *p
++ = lower
+ ( direction
* ( rpb
* ( ( k
* max
) / this->w
) / max
) ) + ( j
* this->offset
* 2 / lpb
);
184 for ( i
= 1; i
< this->h
; i
++ )
186 p
= image
+ i
* this->w
;
187 r
= image
+ i
* 2 * this->w
;
196 for ( i
= 0; i
< this->h
; i
++ )
198 p
= image
+ i
* this->w
;
199 r
= end
- i
* this->w
;
200 j
= ( this->w
* ( this->h
- i
) ) / this->h
;
209 for ( i
= 0; i
< this->h
; i
++ )
211 p
= image
+ i
* this->w
;
226 for ( i
= 1; i
< this->h
/ 2; i
++ )
228 p
= image
+ i
* this->w
;
270 for ( i
= 0; i
< this->h
; i
++ )
272 p
= image
+ i
* this->w
;
286 end
= image
+ this->w
* this->h
;
288 for ( i
= 1; i
< this->h
/ 2; i
++ )
290 p
= image
+ i
* this->w
;
304 int main( int argc
, char **argv
)
310 uint16_t *image
= NULL
;
314 for ( arg
= 1; arg
< argc
- 1; arg
++ )
316 if ( !strcmp( argv
[ arg
], "-bpp" ) )
317 bpp
= atoi( argv
[ ++ arg
] );
318 else if ( !strcmp( argv
[ arg
], "-type" ) )
319 this.type
= atoi( argv
[ ++ arg
] );
320 else if ( !strcmp( argv
[ arg
], "-w" ) )
321 this.w
= atoi( argv
[ ++ arg
] );
322 else if ( !strcmp( argv
[ arg
], "-h" ) )
323 this.h
= atoi( argv
[ ++ arg
] );
324 else if ( !strcmp( argv
[ arg
], "-bands" ) )
325 this.bands
= atoi( argv
[ ++ arg
] );
326 else if ( !strcmp( argv
[ arg
], "-rband" ) )
327 this.rband
= atoi( argv
[ ++ arg
] );
328 else if ( !strcmp( argv
[ arg
], "-hmirror" ) )
329 this.hmirror
= atoi( argv
[ ++ arg
] );
330 else if ( !strcmp( argv
[ arg
], "-vmirror" ) )
331 this.vmirror
= atoi( argv
[ ++ arg
] );
332 else if ( !strcmp( argv
[ arg
], "-dmirror" ) )
333 this.dmirror
= atoi( argv
[ ++ arg
] );
334 else if ( !strcmp( argv
[ arg
], "-offset" ) )
335 this.offset
= atoi( argv
[ ++ arg
] );
336 else if ( !strcmp( argv
[ arg
], "-invert" ) )
337 this.invert
= atoi( argv
[ ++ arg
] );
338 else if ( !strcmp( argv
[ arg
], "-flip" ) )
339 this.flip
= atoi( argv
[ ++ arg
] );
340 else if ( !strcmp( argv
[ arg
], "-flop" ) )
341 this.flop
= atoi( argv
[ ++ arg
] );
342 else if ( !strcmp( argv
[ arg
], "-pflip" ) )
343 this.pflip
= atoi( argv
[ ++ arg
] );
344 else if ( !strcmp( argv
[ arg
], "-pflop" ) )
345 this.pflop
= atoi( argv
[ ++ arg
] );
346 else if ( !strcmp( argv
[ arg
], "-quart" ) )
347 this.quart
= atoi( argv
[ ++ arg
] );
349 fprintf( stderr
, "ignoring %s\n", argv
[ arg
] );
352 if ( bpp
!= 8 && bpp
!= 16 )
354 fprintf( stderr
, "Invalid bpp %d\n", bpp
);
358 image
= luma_render( &this );
362 uint16_t *end
= image
+ this.w
* this.h
;
364 uint8_t *q
= ( uint8_t * )image
;
367 *p
++ = ( *q
<< 8 ) + *( q
+ 1 );
371 printf( "%d %d\n", this.w
, this.h
);
373 fwrite( image
, this.w
* this.h
* sizeof( uint16_t ), 1, stdout
);
377 uint16_t *end
= image
+ this.w
* this.h
;
379 uint8_t *q
= ( uint8_t * )image
;
381 *q
++ = ( uint8_t )( *p
++ >> 8 );
383 printf( "%d %d\n", this.w
, this.h
);
385 fwrite( image
, this.w
* this.h
, 1, stdout
);