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" ) )
370 this.w = atoi( argv[ ++ arg ] );
371 else if ( !strcmp( argv[ arg ], "-h" ) )
372 this.h = atoi( argv[ ++ arg ] );
373 else if ( !strcmp( argv[ arg ], "-bands" ) )
374 this.bands = atoi( argv[ ++ arg ] );
375 else if ( !strcmp( argv[ arg ], "-rband" ) )
376 this.rband = atoi( argv[ ++ arg ] );
377 else if ( !strcmp( argv[ arg ], "-hmirror" ) )
378 this.hmirror = atoi( argv[ ++ arg ] );
379 else if ( !strcmp( argv[ arg ], "-vmirror" ) )
380 this.vmirror = atoi( argv[ ++ arg ] );
381 else if ( !strcmp( argv[ arg ], "-dmirror" ) )
382 this.dmirror = atoi( argv[ ++ arg ] );
383 else if ( !strcmp( argv[ arg ], "-offset" ) )
384 this.offset = atoi( argv[ ++ arg ] );
385 else if ( !strcmp( argv[ arg ], "-invert" ) )
386 this.invert = atoi( argv[ ++ arg ] );
387 else if ( !strcmp( argv[ arg ], "-flip" ) )
388 this.flip = atoi( argv[ ++ arg ] );
389 else if ( !strcmp( argv[ arg ], "-flop" ) )
390 this.flop = atoi( argv[ ++ arg ] );
391 else if ( !strcmp( argv[ arg ], "-pflip" ) )
392 this.pflip = atoi( argv[ ++ arg ] );
393 else if ( !strcmp( argv[ arg ], "-pflop" ) )
394 this.pflop = atoi( argv[ ++ arg ] );
395 else if ( !strcmp( argv[ arg ], "-quart" ) )
396 this.quart = atoi( argv[ ++ arg ] );
397 else if ( !strcmp( argv[ arg ], "-rotate" ) )
398 this.rotate = atoi( argv[ ++ arg ] );
400 fprintf( stderr, "ignoring %s\n", argv[ arg ] );
403 if ( bpp != 8 && bpp != 16 )
405 fprintf( stderr, "Invalid bpp %d\n", bpp );
409 image = luma_render( &this );
413 uint16_t *end = image + this.w * this.h;
415 uint8_t *q = ( uint8_t * )image;
418 *p ++ = ( *q << 8 ) + *( q + 1 );
422 printf( "%d %d\n", this.w, this.h );
424 fwrite( image, this.w * this.h * sizeof( uint16_t ), 1, stdout );
428 uint16_t *end = image + this.w * this.h;
430 uint8_t *q = ( uint8_t * )image;
432 *q ++ = ( uint8_t )( *p ++ >> 8 );
434 printf( "%d %d\n", this.w, this.h );
436 fwrite( image, this.w * this.h, 1, stdout );