void nojpegsupport( void ) { char *s[6] = { "Warning!", "You need libjpeg (http://www.ijg.org) and enable", "jpeg support in the GRX lib (edit makedefs.grx)", "to run this demo", " ", "Press any key to continue..." }; int i; grx_clear_screen( grx_color_get( 0,0,100 ) ); for( i=0; i<6; i++ ) grx_draw_text( s[i],90,160+i*18,text_opt ); GrKeyRead(); }
void drawellip(int xc,int yc,int rx,int ry,GrxColor c1,GrxColor c2,GrxColor c3) { double ddx = (double)rx; double ddy = (double)ry; double R2 = ddx*ddx*ddy*ddy; double SQ; int x1,x2,y1,y2; int dx,dy; int *wdt, idx; GrxLineOptions *l; for (idx = 0, l = *Patterns; l != NULL; l = Patterns[++idx]) for (wdt=widths; *wdt != 0; ++wdt) { grx_clear_screen(GRX_COLOR_BLACK); grx_draw_filled_box(xc-rx,yc-ry,xc+rx,yc+ry,c1); dx = rx; dy = 0; grx_draw_pixel(xc-dx,yc,c3); grx_draw_pixel(xc+dx,yc,c3); while(++dy <= ry) { SQ = R2 - (double)dy * (double)dy * ddx * ddx; dx = (int)(sqrt(SQ)/ddy + 0.5); x1 = xc - dx; x2 = xc + dx; y1 = yc - dy; y2 = yc + dy; grx_draw_pixel(x1,y1,c3); grx_draw_pixel(x2,y1,c3); grx_draw_pixel(x1,y2,c3); grx_draw_pixel(x2,y2,c3); } l->color = c2; l->width = *wdt; grx_draw_ellipse_with_options(xc,yc,rx,ry,l); if(GrKeyRead() == 'q') { stop = 1; return; } } }
void imagen( char *nf, int scale ) { GrxContext *grc; int wide, high; char s[81]; int w, h; grx_query_jpeg_file( nf,&w,&h ); sprintf( s,"%s %dx%d scale 1/%d",nf,w,h,scale ); wide = (w/scale > 600) ? 600 : w/scale; high = (h/scale > 400) ? 400 : h/scale; grx_clear_screen( grx_color_get( 0,0,200 ) ); grx_draw_box( 10,40,10+wide+1,40+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 11,41,11+wide-1,41+high-1,NULL,NULL ); grx_context_load_from_jpeg( grc,nf,scale,NULL ); grx_context_unref( grc ); grx_draw_text( s,10,10,text_opt ); grx_draw_text( "Press any key to continue",10,50+high,text_opt ); GrKeyRead(); }
int main(void) { GrxTextOptions *text_opt; GrxContext *grc; GrxPnmFormat format; int wide, high, maxval; char s[81]; GError *error = NULL; { GrxFont *font; font = grx_font_load(NULL, -1, &error); if (!font) { g_error("%s", error->message); } text_opt = grx_text_options_new_full(font, GRX_COLOR_BLACK, GRX_COLOR_WHITE, GRX_TEXT_HALIGN_LEFT, GRX_TEXT_VALIGN_TOP); grx_font_unref(font); } if (!grx_set_mode(GRX_GRAPHICS_MODE_GRAPHICS_WIDTH_HEIGHT_COLOR,&error,640,480,32768)) { g_error("%s", error->message); } grx_query_pnm_file( FIMAGEPPM, &format, &wide, &high, &maxval ); sprintf( s,"%s %d x %d pixels",FIMAGEPPM,wide,high ); grx_draw_text(s, 10, 20, text_opt); grx_draw_box( 10,40,10+wide+1,40+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 11,41,11+wide-1,41+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPPM,NULL ); grx_context_save_to_pgm( grc,FIMAGEPGM,"TestPnm",NULL ); grx_context_unref( grc ); grx_draw_text("Press any key to continue", 10, 50+high, text_opt); GrKeyRead(); grx_clear_screen( GRX_COLOR_BLACK ); grx_query_pnm_file( FIMAGEPGM, &format, &wide, &high, &maxval ); sprintf( s,"%s %d x %d pixels",FIMAGEPGM,wide,high ); grx_draw_text(s, 10, 20, text_opt); grx_draw_box( 10,40,10+wide+1,40+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 11,41,11+wide-1,41+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPGM,NULL ); grx_context_unref( grc ); grx_draw_text("Press any key to continue", 10, 50+high, text_opt); GrKeyRead(); grx_clear_screen( GRX_COLOR_BLACK ); grx_query_pnm_file( FIMAGEPBM, &format, &wide, &high, &maxval ); sprintf( s,"%s %d x %d pixels",FIMAGEPBM,wide,high ); grx_draw_text(s, 10, 20, text_opt); grx_draw_box( 10,40,10+wide+1,40+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 11,41,11+wide-1,41+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPBM,NULL ); grx_context_save_to_pbm( grc,FIMAGEPBM2,"TestPnm",NULL ); grx_context_unref( grc ); grx_draw_text("Press any key to continue", 10, 50+high, text_opt); GrKeyRead(); grx_clear_screen( GRX_COLOR_BLACK ); grx_query_pnm_file( FIMAGEPPM, &format, &wide, &high, &maxval ); grx_draw_box( 10,40,10+wide+1,40+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 11,41,11+wide-1,41+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPPM,NULL ); grx_context_unref( grc ); grx_query_pnm_file( FIMAGEPGM, &format, &wide, &high, &maxval ); grx_draw_box( 110,140,110+wide+1,140+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 111,141,111+wide-1,141+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPGM,NULL ); grx_context_unref( grc ); grx_query_pnm_file( FIMAGEPBM, &format, &wide, &high, &maxval ); grx_draw_box( 210,240,210+wide+1,240+high+1,GRX_COLOR_WHITE ); grc = grx_context_new_subcontext( 211,241,211+wide-1,241+high-1,NULL,NULL ); grx_context_load_from_pnm( grc,FIMAGEPBM2,NULL ); grx_context_unref( grc ); grx_draw_text("Press any key to save screen", 10, 20, text_opt); GrKeyRead(); grx_context_save_to_ppm( NULL,FSCREEN,"TestPnm",NULL ); grx_clear_screen( GRX_COLOR_WHITE ); grx_draw_text("Press any key to reload screen", 10, 20, text_opt); GrKeyRead(); grx_context_load_from_pnm( NULL,FSCREEN,NULL ); grx_draw_text("Press any key to end ", 10, 20, text_opt); GrKeyRead(); grx_set_mode(GRX_GRAPHICS_MODE_TEXT_DEFAULT, NULL); grx_text_options_unref(text_opt); return 0; }
int main() { GrxContext *grc; GError *error = NULL; { GrxFont *font; font = grx_font_load(NULL, -1, &error); if (!font) { g_error("%s", error->message); } text_opt = grx_text_options_new_full(font, GRX_COLOR_BLACK, GRX_COLOR_WHITE, GRX_TEXT_HALIGN_LEFT, GRX_TEXT_VALIGN_TOP); grx_font_unref(font); } if (!grx_set_mode(GRX_GRAPHICS_MODE_GRAPHICS_WIDTH_HEIGHT_BPP,&error,640,480,24)) { g_error("%s", error->message); } imagen( "jpeg1.jpg",1 ); imagen( "jpeg1.jpg",2 ); imagen( "jpeg1.jpg",4 ); imagen( "jpeg1.jpg",8 ); imagen( "jpeg2.jpg",1 ); imagen( "jpeg2.jpg",2 ); imagen( "jpeg2.jpg",4 ); imagen( "jpeg2.jpg",8 ); grx_clear_screen( grx_color_get( 0,100,0 ) ); grc = grx_context_new_subcontext( 10,40,10+400-1,40+300-1,NULL,NULL ); grx_context_load_from_jpeg( grc,"jpeg1.jpg",2,NULL ); grx_context_unref( grc ); grc = grx_context_new_subcontext( 210,150,210+400-1,150+300-1,NULL,NULL ); grx_context_load_from_jpeg( grc,"jpeg2.jpg",2,NULL ); grx_context_unref( grc ); grx_draw_text( "Press any key to save color and gray screen",10,10,text_opt ); GrKeyRead(); grx_context_save_to_jpeg( NULL,"p.jpg",75,NULL ); grx_context_save_to_jpeg_grayscale( NULL,"pgray.jpg",75,NULL ); grx_clear_screen( GRX_COLOR_BLACK ); grx_draw_text( "Press any key to reload color screen ",10,10,text_opt ); GrKeyRead(); grx_context_load_from_jpeg( NULL,"p.jpg",1,NULL ); grx_draw_text( "Press any key to reload gray screen ",10,10,text_opt ); GrKeyRead(); grx_clear_screen( GRX_COLOR_BLACK ); grx_context_load_from_jpeg( NULL,"pgray.jpg",1,NULL ); grx_draw_text( "Press any key to end ",10,10,text_opt ); GrKeyRead(); grx_text_options_unref(text_opt); grx_set_mode(GRX_GRAPHICS_MODE_TEXT_DEFAULT, NULL); return 0; }
GrKeyType ws_waitforkey() { return GrKeyRead(); }