1
2 /*
3 * This software is copyrighted as noted below. It may be freely copied,
4 * modified, and redistributed, provided that the copyright notice is
5 * preserved on all copies.
6 *
7 * There is no warranty or other guarantee of fitness for this software,
8 * it is provided solely "as is". Bug reports or fixes may be sent
9 * to the author, who may or may not act on them as he desires.
10 *
11 * You may not include this software in a program or other software product
12 * without supplying the source, or without informing the end-user that the
13 * source is available for no extra charge.
14 *
15 * If you modify this software, you should include a notice giving the
16 * name of the person performing the modification, the date of modification,
17 * and the reason for such modification.
18 */
19 /*
20 * cabezon.c - create a set of images with a left to rigth pull
21 *
22 * Author: Raul Rivero
23 * Vicerrectorado de Estudiantes
24 * University of Oviedo
25 * Date: Thu Jan 06 1993
26 * Copyright (c) 1993, Raul Rivero
27 *
28 */
29 /*
30 * Dedicated to Enrique Marcos :-).
31 */
32
33 #include <lug.h>
34 #include <lugfnts.h>
35
36 extern int LUGverbose;
37 extern char *MY_NAME;
38
main(argc,argv)39 main( argc, argv )
40 int argc;
41 char **argv;
42 {
43 int i;
44 bitmap_hdr in;
45
46 MY_NAME = argv[0];
47
48 /*
49 * Get options ( some day I'll build a procedure ).
50 */
51 if ( argc > 1 ) { /* else core on SGI */
52 while ( argv[1][0] == '-' ) {
53 for ( i = 1; argv[1][i]; i++ ) {
54 switch ( argv[1][i] ) {
55 case 'v':
56 LUGverbose++;
57 break;
58 default :
59 fprintf( stderr, "Usage: %s [-v] <input_image> <output_base_name> <#_of_frames>\n",
60 MY_NAME );
61 exit( 0 );
62 break;
63 }
64 }
65 argv++;
66 argc--;
67 }
68 }
69
70 if ( argc < 4 ) {
71 fprintf( stderr, "Usage: %s [-v] <input_image> <output_base_name> <#_of_frames>\n",
72 MY_NAME );
73 exit( 0 );
74 }
75
76 /* Read the input file */
77 read_lug_file( argv[1], &in );
78
79 /* We wanna a true color image. Why?. Ok, it's my program! :-) */
80 if ( in.depth < 24 )
81 error( 7 );
82
83 /* Calculate the images */
84 displacement( &in, Atoi(argv[3]), argv[2] );
85 }
86
displacement(in,no_frames,base_name)87 displacement( in, no_frames, base_name )
88 bitmap_hdr *in;
89 int no_frames;
90 char *base_name;
91 {
92 bitmap_hdr base_image;
93 bitmap_hdr cutted;
94 int i, j;
95 char name[132];
96 double inc_x;
97
98 if ( no_frames < 2 ) {
99 fprintf( stderr, "%s: a # of frames lower than 2?. Try again!", MY_NAME );
100 exit( 0 );
101 }
102
103 /* Create the first/base image ... */
104 create_solid_image( &base_image, in->xsize, in->ysize, 0, 0, 0 );
105 /* ... and write it. */
106 sprintf( name, "%s.%d", base_name, 1 );
107 write_lug_file( name, &base_image );
108
109 /* The step per frame */
110 inc_x = ((double)in->xsize) / ((double)(no_frames-1));
111
112 /* The loop! */
113 for ( i = 1; i < no_frames-1; i++ ) {
114 /* Set the current border, ... */
115 j = (int) (((double)i)*inc_x);
116 /* ... cut it, ... */
117 cut_bitmap( in, &cutted, 0, 0, j, in->ysize );
118 /* ... and paste it. */
119 paste( &base_image, &cutted, 0, 0 );
120 /* What now?. Write it! */
121 sprintf( name, "%s.%d", base_name, i+1 );
122 write_lug_file( name, &base_image );
123 /* Free the cutted image */
124 freebitmap( &cutted );
125 }
126
127 /* Write the last image */
128 sprintf( name, "%s.%d", base_name, no_frames );
129 write_lug_file( name, in );
130
131 /* Free the base image */
132 freebitmap( &base_image );
133
134 }
135