2 * luma.c -- image generator for transition_luma
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 void luma_init( luma *this )
49 memset( this, 0, sizeof( luma ) );
67 static inline int sqrti( int n )
92 uint16_t *luma_render( luma *this )
111 int max = ( 1 << 16 ) - 1;
112 uint16_t *image = malloc( this->w * this->h * sizeof( uint16_t ) );
113 uint16_t *end = image + this->w * this->h;
117 int lpb = this->h / this->bands;
118 int rpb = max / this->bands;
121 int half_w = this->w / 2;
122 int half_h = this->h / 2;
124 if ( !this->dmirror && ( this->hmirror || this->vmirror ) )
127 for ( i = 0; i < this->bands; i ++ )
132 if ( this->rband && i % 2 == 1 )
142 int length = sqrti( half_w * half_w + lpb * lpb / 4 );
146 for ( j = 0; j < lpb; j ++ )
149 for ( k = 0; k < this->w; k ++ )
152 value = sqrti( x * x + y * y );
153 *p ++ = lower + ( direction * rpb * ( ( max * value ) / length ) / max ) + ( j * this->offset * 2 / lpb ) + ( j * this->offset / lpb );
161 for ( j = 0; j < lpb; j ++ )
163 int value = ( ( j * this->w ) / lpb ) - half_w;
166 for ( k = - half_w; k < value; k ++ )
167 *p ++ = lower + ( direction * rpb * ( ( max * abs( k ) ) / half_w ) / max );
168 for ( k = value; k < abs( value ); k ++ )
169 *p ++ = lower + ( direction * rpb * ( ( max * abs( value ) ) / half_w ) / max ) + ( j * this->offset * 2 / lpb ) + ( j * this->offset / lpb );
170 for ( k = abs( value ); k < half_w; k ++ )
171 *p ++ = lower + ( direction * rpb * ( ( max * abs( k ) ) / half_w ) / max );
179 for ( j = -half_h; j < half_h; j ++ )
183 for ( k = - half_w; k < half_w; k ++ )
185 length = sqrti( k * k + j * j );
186 *p ++ = ( max / 4 * k ) / ( length + 1 );
191 for ( k = half_w; k > - half_w; k -- )
193 length = sqrti( k * k + j * j );
194 *p ++ = ( max / 2 ) + ( max / 4 * k ) / ( length + 1 );
202 for ( j = 0; j < lpb; j ++ )
203 for ( k = 0; k < this->w; k ++ )
204 *p ++ = lower + ( direction * ( rpb * ( ( k * max ) / this->w ) / max ) ) + ( j * this->offset * 2 / lpb );
213 for ( i = 1; i < this->h; i ++ )
215 p = image + i * this->w;
216 r = image + i * 2 * this->w;
225 for ( i = 0; i < this->h; i ++ )
227 p = image + i * this->w;
228 r = end - i * this->w;
229 j = ( this->w * ( this->h - i ) ) / this->h;
238 for ( i = 0; i < this->h; i ++ )
240 p = image + i * this->w;
255 for ( i = 1; i < this->h / 2; i ++ )
257 p = image + i * this->w;
299 for ( i = 0; i < this->h; i ++ )
301 p = image + i * this->w;
315 end = image + this->w * this->h;
317 for ( i = 1; i < this->h / 2; i ++ )
319 p = image + i * this->w;
332 uint16_t *image2 = malloc( this->w * this->h * sizeof( uint16_t ) );
333 for ( i = 0; i < this->h; i ++ )
335 p = image + i * this->w;
336 r = image2 + this->h - i - 1;
337 for ( j = 0; j < this->w; j ++ )
353 int main( int argc, char **argv )
359 uint16_t *image = NULL;
363 for ( arg = 1; arg < argc - 1; arg ++ )
365 if ( !strcmp( argv[ arg ], "-bpp" ) )
366 bpp = atoi( argv[ ++ arg ] );
367 else if ( !strcmp( argv[ arg ], "-type" ) )
368 this.type = atoi( argv[ ++ arg ] );
369 else if ( !strcmp( argv[ arg ], "-w" ) )
371 int tmp = atoi( argv[ ++ arg ] );
372 // TODO: is there an upper bound?
378 else if ( !strcmp( argv[ arg ], "-h" ) )
380 int tmp = atoi( argv[ ++ arg ] );
381 // TODO: is there an upper bound?
386 else if ( !strcmp( argv[ arg ], "-bands" ) )
388 int tmp = atoi( argv[ ++ arg ] );
389 // TODO: is there an upper bound?
395 else if ( !strcmp( argv[ arg ], "-rband" ) )
396 this.rband = atoi( argv[ ++ arg ] );
397 else if ( !strcmp( argv[ arg ], "-hmirror" ) )
398 this.hmirror = atoi( argv[ ++ arg ] );
399 else if ( !strcmp( argv[ arg ], "-vmirror" ) )
400 this.vmirror = atoi( argv[ ++ arg ] );
401 else if ( !strcmp( argv[ arg ], "-dmirror" ) )
402 this.dmirror = atoi( argv[ ++ arg ] );
403 else if ( !strcmp( argv[ arg ], "-offset" ) )
404 this.offset = atoi( argv[ ++ arg ] );
405 else if ( !strcmp( argv[ arg ], "-invert" ) )
406 this.invert = atoi( argv[ ++ arg ] );
407 else if ( !strcmp( argv[ arg ], "-flip" ) )
408 this.flip = atoi( argv[ ++ arg ] );
409 else if ( !strcmp( argv[ arg ], "-flop" ) )
410 this.flop = atoi( argv[ ++ arg ] );
411 else if ( !strcmp( argv[ arg ], "-pflip" ) )
412 this.pflip = atoi( argv[ ++ arg ] );
413 else if ( !strcmp( argv[ arg ], "-pflop" ) )
414 this.pflop = atoi( argv[ ++ arg ] );
415 else if ( !strcmp( argv[ arg ], "-quart" ) )
416 this.quart = atoi( argv[ ++ arg ] );
417 else if ( !strcmp( argv[ arg ], "-rotate" ) )
418 this.rotate = atoi( argv[ ++ arg ] );
420 fprintf( stderr, "ignoring %s\n", argv[ arg ] );
423 if ( bpp != 8 && bpp != 16 )
425 fprintf( stderr, "Invalid bpp %d\n", bpp );
429 image = luma_render( &this );
433 uint16_t *end = image + this.w * this.h;
435 uint8_t *q = ( uint8_t * )image;
438 *p ++ = ( *q << 8 ) + *( q + 1 );
442 printf( "%d %d\n", this.w, this.h );
444 fwrite( image, this.w * this.h * sizeof( uint16_t ), 1, stdout );
448 uint16_t *end = image + this.w * this.h;
450 uint8_t *q = ( uint8_t * )image;
452 *q ++ = ( uint8_t )( *p ++ >> 8 );
454 printf( "%d %d\n", this.w, this.h );
456 fwrite( image, this.w * this.h, 1, stdout );