source: trunk/packages/vizservers/nanovis/glui/ppm2array.cpp @ 1358

Last change on this file since 1358 was 1358, checked in by gah, 15 years ago

temporarily add glui to build

File size: 1.3 KB
Line 
1#include "imagetype.h"
2#include <stdio.h>
3
4void main( int argc, char *argv[] )
5{
6  int        i;
7  ImagePPM   img;
8  FILE      *output;
9  char       basename[200];
10
11  if ( argc != 3 ) {
12    fprintf( stderr, "USAGE: %s input.ppm output.cpp\n", argv[0] );
13    return;
14  }
15
16  img.read( argv[1] );
17
18  if ( img.valid ) {
19    strcpy( basename, argv[1] );
20    basename[ strlen(basename)-4 ] = '\0';
21   
22    output = fopen( argv[2], "w" );
23    if ( NOT output ) {
24      fprintf( stderr, "ERROR: File '%s' could not be opened for writing\n",
25               argv[2] );
26      return;
27    }
28
29    img.flip_v(); /* Opengl bitmaps are specified bottom-to-top */
30
31    fprintf( output, "\n\n");
32    fprintf( output, "int %s[] = {", basename );
33    fprintf( output, "    %d, %d,   /* width, height */\n",
34             img.x_size, img.y_size );
35
36    fprintf( output, "    " ); 
37    for( i=0; i<img.x_size * img.y_size; i++ ) {
38      fprintf( output, "%3d,%3d,%3d,  ",
39               img.pixels[i*3+0],
40               img.pixels[i*3+1],
41               img.pixels[i*3+2] );
42      if ( (i%5) == 4 ) {
43        fprintf( output, "\n    " );
44      }
45    }
46
47    fprintf( output, "\n};\n" );
48    fclose( output );
49  }
50  else {
51    fprintf( stderr, "ERROR: Image '%s' invalid\n", argv[1] );
52  }
53 
54}
55
56
Note: See TracBrowser for help on using the repository browser.