1 /**
2 ** pnmtest.c ---- test the ctx2pnm routines
3 **
4 ** Copyright (c) 2000 Mariano Alvarez Fernandez
5 ** [e-mail: malfer@teleline.es]
6 **
7 ** This is a test/demo file of the GRX graphics library.
8 ** You can use GRX test/demo files as you want.
9 **
10 ** The GRX graphics library is free software; you can redistribute it
11 ** and/or modify it under some conditions; see the "copying.grx" file
12 ** for details.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 **/
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include "grx20.h"
22 #include "grxkeys.h"
23
24 #define FIMAGEPPM "pnmtest.ppm"
25 #define FIMAGEPBM "pnmtest.pbm"
26
27 #define FIMAGEPGM "prueba.pgm"
28 #define FIMAGEPBM2 "prueba.pbm"
29 #define FSCREEN "output.ppm"
30
main(void)31 int main(void)
32 {
33 GrContext *grc;
34 int wide, high, maxval;
35 char s[81];
36
37 /* GrSetMode( GR_default_graphics ); */
38 GrSetMode( GR_width_height_color_graphics,640,480,32768 );
39 GrQueryPnm( FIMAGEPPM, &wide, &high, &maxval );
40 sprintf( s,"%s %d x %d pixels",FIMAGEPPM,wide,high );
41 GrTextXY( 10,20,s,GrBlack(),GrWhite() );
42 GrBox( 10,40,10+wide+1,40+high+1,GrWhite() );
43 grc = GrCreateSubContext( 11,41,11+wide-1,41+high-1,NULL,NULL );
44 GrLoadContextFromPnm( grc,FIMAGEPPM );
45 GrSaveContextToPgm( grc,FIMAGEPGM,"TestPnm" );
46 GrDestroyContext( grc );
47 GrTextXY( 10,50+high,"Press any key to continue",GrBlack(),GrWhite() );
48 GrKeyRead();
49
50 GrClearScreen( GrBlack() );
51 GrQueryPnm( FIMAGEPGM, &wide, &high, &maxval );
52 sprintf( s,"%s %d x %d pixels",FIMAGEPGM,wide,high );
53 GrTextXY( 10,20,s,GrBlack(),GrWhite() );
54 GrBox( 10,40,10+wide+1,40+high+1,GrWhite() );
55 grc = GrCreateSubContext( 11,41,11+wide-1,41+high-1,NULL,NULL );
56 GrLoadContextFromPnm( grc,FIMAGEPGM );
57 GrDestroyContext( grc );
58 GrTextXY( 10,50+high,"Press any key to continue",GrBlack(),GrWhite() );
59 GrKeyRead();
60
61 GrClearScreen( GrBlack() );
62 GrQueryPnm( FIMAGEPBM, &wide, &high, &maxval );
63 sprintf( s,"%s %d x %d pixels",FIMAGEPBM,wide,high );
64 GrTextXY( 10,20,s,GrBlack(),GrWhite() );
65 GrBox( 10,40,10+wide+1,40+high+1,GrWhite() );
66 grc = GrCreateSubContext( 11,41,11+wide-1,41+high-1,NULL,NULL );
67 GrLoadContextFromPnm( grc,FIMAGEPBM );
68 GrSaveContextToPbm( grc,FIMAGEPBM2,"TestPnm" );
69 GrDestroyContext( grc );
70 GrTextXY( 10,50+high,"Press any key to continue",GrBlack(),GrWhite() );
71 GrKeyRead();
72
73 GrClearScreen( GrBlack() );
74 GrQueryPnm( FIMAGEPPM, &wide, &high, &maxval );
75 GrBox( 10,40,10+wide+1,40+high+1,GrWhite() );
76 grc = GrCreateSubContext( 11,41,11+wide-1,41+high-1,NULL,NULL );
77 GrLoadContextFromPnm( grc,FIMAGEPPM );
78 GrDestroyContext( grc );
79 GrQueryPnm( FIMAGEPGM, &wide, &high, &maxval );
80 GrBox( 110,140,110+wide+1,140+high+1,GrWhite() );
81 grc = GrCreateSubContext( 111,141,111+wide-1,141+high-1,NULL,NULL );
82 GrLoadContextFromPnm( grc,FIMAGEPGM );
83 GrDestroyContext( grc );
84 GrQueryPnm( FIMAGEPBM, &wide, &high, &maxval );
85 GrBox( 210,240,210+wide+1,240+high+1,GrWhite() );
86 grc = GrCreateSubContext( 211,241,211+wide-1,241+high-1,NULL,NULL );
87 GrLoadContextFromPnm( grc,FIMAGEPBM2 );
88 GrDestroyContext( grc );
89 GrTextXY( 10,20,"Press any key to save screen",GrBlack(),GrWhite() );
90 GrKeyRead();
91
92 GrSaveContextToPpm( NULL,FSCREEN,"TestPnm" );
93 GrClearScreen( GrWhite() );
94 GrTextXY( 10,20,"Press any key to reload screen",GrWhite(),GrBlack() );
95 GrKeyRead();
96
97 GrLoadContextFromPnm( NULL,FSCREEN );
98 GrTextXY( 10,20,"Press any key to end ",GrBlack(),GrWhite() );
99 GrKeyRead();
100
101 GrSetMode(GR_default_text);
102 return 0;
103 }
104