27 void luma_init( luma *this )
29 memset( this, 0, sizeof( luma ) );
47 static inline int sqrti( int n )
72 uint16_t *luma_render( luma *this )
91 int max = ( 1 << 16 ) - 1;
92 uint16_t *image = malloc( this->w * this->h * sizeof( uint16_t ) );
93 uint16_t *end = image + this->w * this->h;
97 int lpb = this->h / this->bands;
98 int rpb = max / this->bands;
101 int half_w = this->w / 2;
102 int half_h = this->h / 2;
104 if ( !this->dmirror && ( this->hmirror || this->vmirror ) )
107 for ( i = 0; i < this->bands; i ++ )
112 if ( this->rband && i % 2 == 1 )
122 int length = sqrti( half_w * half_w + lpb * lpb / 4 );
126 for ( j = 0; j < lpb; j ++ )
129 for ( k = 0; k < this->w; k ++ )
132 value = sqrti( x * x + y * y );
133 *p ++ = lower + ( direction * rpb * ( ( max * value ) / length ) / max ) + ( j * this->offset * 2 / lpb ) + ( j * this->offset / lpb );
141 for ( j = 0; j < lpb; j ++ )
143 int value = ( ( j * this->w ) / lpb ) - half_w;
146 for ( k = - half_w; k < value; k ++ )
147 *p ++ = lower + ( direction * rpb * ( ( max * abs( k ) ) / half_w ) / max );
148 for ( k = value; k < abs( value ); k ++ )
149 *p ++ = lower + ( direction * rpb * ( ( max * abs( value ) ) / half_w ) / max ) + ( j * this->offset * 2 / lpb ) + ( j * this->offset / lpb );
150 for ( k = abs( value ); k < half_w; k ++ )
151 *p ++ = lower + ( direction * rpb * ( ( max * abs( k ) ) / half_w ) / max );
159 for ( j = -half_h; j < half_h; j ++ )
163 for ( k = - half_w; k < half_w; k ++ )
165 length = sqrti( k * k + j * j );
166 *p ++ = ( max / 4 * k ) / ( length + 1 );
171 for ( k = half_w; k > - half_w; k -- )
173 length = sqrti( k * k + j * j );
174 *p ++ = ( max / 2 ) + ( max / 4 * k ) / ( length + 1 );
182 for ( j = 0; j < lpb; j ++ )
183 for ( k = 0; k < this->w; k ++ )
184 *p ++ = lower + ( direction * ( rpb * ( ( k * max ) / this->w ) / max ) ) + ( j * this->offset * 2 / lpb );
193 for ( i = 1; i < this->h; i ++ )
195 p = image + i * this->w;
196 r = image + i * 2 * this->w;
205 for ( i = 0; i < this->h; i ++ )
207 p = image + i * this->w;
208 r = end - i * this->w;
209 j = ( this->w * ( this->h - i ) ) / this->h;
218 for ( i = 0; i < this->h; i ++ )
220 p = image + i * this->w;
235 for ( i = 1; i < this->h / 2; i ++ )
237 p = image + i * this->w;
279 for ( i = 0; i < this->h; i ++ )
281 p = image + i * this->w;
295 end = image + this->w * this->h;
297 for ( i = 1; i < this->h / 2; i ++ )
299 p = image + i * this->w;
312 uint16_t *image2 = malloc( this->w * this->h * sizeof( uint16_t ) );
313 for ( i = 0; i < this->h; i ++ )
315 p = image + i * this->w;
316 r = image2 + this->h - i - 1;
317 for ( j = 0; j < this->w; j ++ )
333 int main( int argc, char **argv )
339 uint16_t *image = NULL;
343 for ( arg = 1; arg < argc - 1; arg ++ )
345 if ( !strcmp( argv[ arg ], "-bpp" ) )
346 bpp = atoi( argv[ ++ arg ] );
347 else if ( !strcmp( argv[ arg ], "-type" ) )
348 this.type = atoi( argv[ ++ arg ] );
349 else if ( !strcmp( argv[ arg ], "-w" ) )
350 this.w = atoi( argv[ ++ arg ] );
351 else if ( !strcmp( argv[ arg ], "-h" ) )
352 this.h = atoi( argv[ ++ arg ] );
353 else if ( !strcmp( argv[ arg ], "-bands" ) )
354 this.bands = atoi( argv[ ++ arg ] );
355 else if ( !strcmp( argv[ arg ], "-rband" ) )
356 this.rband = atoi( argv[ ++ arg ] );
357 else if ( !strcmp( argv[ arg ], "-hmirror" ) )
358 this.hmirror = atoi( argv[ ++ arg ] );
359 else if ( !strcmp( argv[ arg ], "-vmirror" ) )
360 this.vmirror = atoi( argv[ ++ arg ] );
361 else if ( !strcmp( argv[ arg ], "-dmirror" ) )
362 this.dmirror = atoi( argv[ ++ arg ] );
363 else if ( !strcmp( argv[ arg ], "-offset" ) )
364 this.offset = atoi( argv[ ++ arg ] );
365 else if ( !strcmp( argv[ arg ], "-invert" ) )
366 this.invert = atoi( argv[ ++ arg ] );
367 else if ( !strcmp( argv[ arg ], "-flip" ) )
368 this.flip = atoi( argv[ ++ arg ] );
369 else if ( !strcmp( argv[ arg ], "-flop" ) )
370 this.flop = atoi( argv[ ++ arg ] );
371 else if ( !strcmp( argv[ arg ], "-pflip" ) )
372 this.pflip = atoi( argv[ ++ arg ] );
373 else if ( !strcmp( argv[ arg ], "-pflop" ) )
374 this.pflop = atoi( argv[ ++ arg ] );
375 else if ( !strcmp( argv[ arg ], "-quart" ) )
376 this.quart = atoi( argv[ ++ arg ] );
377 else if ( !strcmp( argv[ arg ], "-rotate" ) )
378 this.rotate = atoi( argv[ ++ arg ] );
380 fprintf( stderr, "ignoring %s\n", argv[ arg ] );
383 if ( bpp != 8 && bpp != 16 )
385 fprintf( stderr, "Invalid bpp %d\n", bpp );
389 image = luma_render( &this );
393 uint16_t *end = image + this.w * this.h;
395 uint8_t *q = ( uint8_t * )image;
398 *p ++ = ( *q << 8 ) + *( q + 1 );
402 printf( "%d %d\n", this.w, this.h );
404 fwrite( image, this.w * this.h * sizeof( uint16_t ), 1, stdout );
408 uint16_t *end = image + this.w * this.h;
410 uint8_t *q = ( uint8_t * )image;
412 *q ++ = ( uint8_t )( *p ++ >> 8 );
414 printf( "%d %d\n", this.w, this.h );
416 fwrite( image, this.w * this.h, 1, stdout );