Пример #1
0
/* FIXME: How is this done with AAlib? */
static int AA_FlipHWSurface(_THIS, SDL_Surface *surface)
{
	SDL_mutexP(AA_mutex);
	aa_flush(AA_context);
	SDL_mutexV(AA_mutex);
	return(0);
}
Пример #2
0
void aa_editkey(struct aa_edit *e, int c)
{
    if (c < 127 && (isgraph(c) || c == ' ')) {
	if (e->clearafterpress)
	    e->data[0] = 0,
		e->cursor = 0;
	e->clearafterpress = 0;
	aa_insert(e, c);
	aa_editdisplay(e);
    } else if (c == AA_BACKSPACE) {
	e->clearafterpress = 0;
	aa_delete(e);
	aa_editdisplay(e);
    } else if (c == AA_LEFT) {
	e->cursor--;
	e->clearafterpress = 0;
	if (e->cursor < 0)
	    e->cursor = 0;
	aa_editdisplay(e);
    } else if (c == AA_RIGHT) {
	e->cursor++;
	e->clearafterpress = 0;
	if (e->cursor > strlen(e->data))
	    e->cursor = strlen(e->data);
	aa_editdisplay(e);
    }
    aa_flush(e->c);
}
static void
flip_page(void) {

   /* do we have to put *our* (messages, progbar) osd to aa's txtbuf ? */
    if (showosdmessage)
      {
	if (time(NULL)>=stoposd ) {
	  showosdmessage=0;
	  if(*osdmessagetext) {
	    memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',strlen(osdmessagetext));
	    memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx ,0,strlen(osdmessagetext));
	    osdmessagetext[0] = '\0';
	  }
	  if(*posbar) {
	    memset(c->textbuffer + (osdy+1) * aa_scrwidth(c),' ',strlen(posbar));
	    memset(c->attrbuffer + (osdy+1) * aa_scrwidth(c),0,strlen(posbar));
	  }
	} else {
	  /* update osd */
	  aa_puts(c, osdx, osdy, AA_SPECIAL, osdmessagetext);
	  /* posbar? */
	  if (posbar[0]!='\0')
	    aa_puts(c, 0, osdy + 1, AA_SPECIAL, posbar);
	}
      }
    /* OSD time & playmode , subtitles */
    printosdtext();


    /* print out */
    aa_flush(c);
}
Пример #4
0
static void 
drawfire (void)
{
  unsigned int i, last1, i1, i2;
  static int loop = 0, sloop = 0, height = 0;
  register unsigned char *p;
  height++;
  loop--;
  if (loop < 0)
    loop = rand () % 3, sloop++;;
  i1 = 1;
  i2 = 4 * XSIZ + 1;
  for (p = (char *) bitmap + XSIZ * (YSIZ + 0); p < ((unsigned char *) bitmap + XSIZ * (YSIZ + 1)); p++, i1 += 4, i2 -= 4)
    {
      last1 = rand () % min (i1, min (i2, height));
      i = rand () % 6;
      for (; p < (unsigned char *) bitmap + XSIZ * (YSIZ + 1) && i != 0; p++, i--, i1 += 4, i2 -= 4)
	*p = last1, last1 += rand () % 6 - 2,
	  *(p + XSIZ) = last1, last1 += rand () % 6 - 2;
      *(p + 2 * XSIZ) = last1, last1 += rand () % 6 - 2;
    }
  /*
     for(p=bitmap+XSIZ*YSIZ;p<bitmap+(YSIZ+2)*XSIZ;p++)
     {
     *p=rand();
     } */
  i = 0;
  firemain ();
  aa_renderpalette (context, palette, params, 0, 0, aa_scrwidth (context), aa_scrheight (context));
  aa_flush (context);
}
Пример #5
0
/**
 * Display a picture
 */
static void Display(vout_display_t *vd, picture_t *picture)
{
    vout_display_sys_t *sys = vd->sys;

    aa_flush(sys->aa_context);
    picture_Release(picture);
}
Пример #6
0
/**
 * Display a picture
 */
static void PictureDisplay(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
{
    vout_display_sys_t *sys = vd->sys;

    aa_flush(sys->aa_context);
    picture_Release(picture);
    VLC_UNUSED(subpicture);
}
Пример #7
0
static void AA_ResizeHandler(aa_context *context)
{
	aa_resize(context);
	local_this->hidden->x_ratio = ((double)aa_imgwidth(context)) / ((double)local_this->screen->w);
	local_this->hidden->y_ratio = ((double)aa_imgheight(context)) / ((double)local_this->screen->h);

	fastscale (local_this->hidden->buffer, aa_image(context), local_this->hidden->w, aa_imgwidth (context), local_this->hidden->h, aa_imgheight (context));
	aa_renderpalette(context, local_this->hidden->palette, local_this->hidden->rparams, 0, 0, aa_scrwidth(context), aa_scrheight(context));
	aa_flush(context);
}
Пример #8
0
/*****************************************************************************
 * Display: displays previously rendered output
 *****************************************************************************/
static void Display( vout_thread_t *p_vout, picture_t *p_pic )
{
    /* No need to do anything, the fake direct buffers stay as they are */
    int i_width, i_height, i_x, i_y;

    vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
                       &i_x, &i_y, &i_width, &i_height );

    aa_flush(p_vout->p_sys->aa_context);
}
Пример #9
0
static void ui_display(void)
{
    displayed = 1;
    aa_render(context, params, 0, 0, aa_imgwidth(context), aa_imgheight(context));
    aa_flush(context);

#if 0
    if (numbertype != FORMULA)
	rotate_continue();
#endif
}
Пример #10
0
Файл: bb.c Проект: stroucki/bb
void bbflushwait(int maxtime)
{
    int wait;
    if (finish_stuff)
	return;
    wait = maxtime + starttime - TIME;
    if (wait > 0) {
	aa_flush(context);
    }
    bbwait(maxtime);
}
Пример #11
0
void aa_edit(aa_context * c, int x, int y, int size, char *s, int maxsize)
{
    struct aa_edit *e;
    int ch;
    aa_showcursor(c);
    e = aa_createedit(c, x, y, size, s, maxsize);
    aa_flush(c);
    while ((ch = aa_getkey(c, 1)) != 13 && ch != '\n') {
	aa_editkey(e, ch);
    }
    aa_hidecursor(c);
    free(e);
}
Пример #12
0
 void Paddle::draw() {
     Resource *resource=Resource::getResource();
     for(int i = x1; i< x2; i++ ) {
         for(int j = y1; j< y2 ; j++ ) {
             aa_putpixel(context, 
                         i, j,
                         resource->fetch(ResourceKey::PADDLE_COLOR));
         }
     }
     aa_fastrender(context, 0, 0, aa_scrwidth(context),
                   aa_scrheight(context) );
     aa_flush(context);            
 }
Пример #13
0
static void morphdraw()
{
    int s = STATE > 0 ? (STATE < MTIME ? STATE : MTIME) : 0;
    int mul = s * 256 / MTIME;
    int mul1 = 256 - mul;
    int i;
    int size = aa_imgwidth(context) * (aa_imgheight(context) - YSTART * 2);
    char *c = context->imagebuffer + aa_imgwidth(context) * 2 * YSTART;
    for (i = 0; i < size; i++, c++) {
	*c = (source[i] * mul1 + target[i] * mul) >> 8;
    }
    aa_fastrender(context, 0, YSTART, aa_scrwidth(context), aa_scrheight(context));
    aa_flush(context);
    emscripten_sleep(1);
}
Пример #14
0
void AaScreen::show() {
    int c;
    // make screen_buffer RGBA to grey
    uint8_t *aa_buf = (uint8_t*)aa_image(ascii_context);
    uint32_t *rgb_buf = (uint32_t*) screen_buffer;

    for(c = 0; c < geo.pixelsize; c++)
        aa_buf[c] = .30 * rgba_to_r(rgb_buf[c])
                    + .59 * rgba_to_g(rgb_buf[c])
                    + .11 * rgba_to_b(rgb_buf[c]);


    aa_render(ascii_context, ascii_rndparms, 0, 0, geo.w, geo.h);
    aa_flush(ascii_context);

}
Пример #15
0
int main()
{
  context = aa_autoinit(&aa_defparams);
  if(context == NULL) {
    fprintf(stderr,"Cannot initialize AA-lib. Sorry\n");
    return 1;
  }
  
while(true) {
 aa_puts(context, 0, 10, AA_BOLDFONT, "Azerty is cooler dan qwerty");
aa_putpixel(context,50,50, );
aa_render(context, 50, 50, 100, 100);
aa_flush(context);
}


  aa_close(context);
return 0;
}
Пример #16
0
static void toblack1()
{
    int x, y, mul1, mul2 = 0, pos;
    int minpos = 0;
    unsigned char *b1 = bckup, *b2 = bckup1;
    pos = STAGE * (aa_imgheight(context) + aa_imgheight(context)) / (endtime - starttime) - aa_imgheight(context);
    for (y = 0; y < aa_imgheight(context); y++) {
	mul1 = (y - pos);
	if (mul1 < 0)
	    mul1 = 0;
	else
	    mul1 = mul1 * 256 * 4 / aa_imgheight(context);
	if (mul1 > 256)
	    mul1 = 256;
	mul2 = (y - pos - aa_imgheight(context));
	if (mul2 < 0)
	    mul2 = 0;
	else
	    mul2 = mul2 * 256 * 8 / aa_imgheight(context);
	if (mul2 > 256)
	    mul2 = 256;
	if (mul2 == 0)
	    minpos = y;
	mul1 -= mul2;
	for (x = 0; x < aa_imgwidth(context); x++) {
	    aa_putpixel(context, x, y,
			(mul1 * (int) (*b1) + mul2 * (int) (*b2)) / 256);
	    b1++;
	    b2++;
	}
    }
    minpos = pos + 3 * aa_imgheight(context) / 4;
    if (minpos < 0)
	minpos = 0;
    if (minpos > aa_imgheight(context))
	minpos = aa_imgheight(context);
    aa_render(context, params, 0, 0, aa_imgwidth(context), minpos);
    aa_flush(context);
    emscripten_sleep(1);
}
Пример #17
0
static GstFlowReturn
gst_aasink_render (GstBaseSink * basesink, GstBuffer * buffer)
{
  GstAASink *aasink;

  aasink = GST_AASINK (basesink);

  GST_DEBUG ("render");

  gst_aasink_scale (aasink, GST_BUFFER_DATA (buffer),   /* src */
      aa_image (aasink->context),       /* dest */
      aasink->width,            /* sw */
      aasink->height,           /* sh */
      aa_imgwidth (aasink->context),    /* dw */
      aa_imgheight (aasink->context));  /* dh */

  aa_render (aasink->context, &aasink->ascii_parms,
      0, 0, aa_imgwidth (aasink->context), aa_imgheight (aasink->context));
  aa_flush (aasink->context);
  aa_getevent (aasink->context, FALSE);

  return GST_FLOW_OK;
}
Пример #18
0
static void AA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
{
	int i;
	SDL_Rect *rect;

	fastscale (AA_buffer, aa_image(AA_context), AA_w, aa_imgwidth (AA_context), AA_h, aa_imgheight (AA_context));
#if 1
	aa_renderpalette(AA_context, AA_palette, AA_rparams, 0, 0, aa_scrwidth(AA_context), aa_scrheight(AA_context));
#else
	/* Render only the rectangles in the list */
	printf("Update rects : ");
	for ( i=0; i < numrects; ++i ) {
		rect = &rects[i];
		printf("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h);
		aa_renderpalette(AA_context, AA_palette, AA_rparams, rect->x * AA_x_ratio, rect->y * AA_y_ratio, rect->w * AA_x_ratio, rect->h * AA_y_ratio);
	}
	printf("\n");
#endif
	SDL_mutexP(AA_mutex);
	aa_flush(AA_context);
	SDL_mutexV(AA_mutex);
	return;
}
Пример #19
0
static GstFlowReturn
gst_aasink_show_frame (GstVideoSink * videosink, GstBuffer * buffer)
{
  GstAASink *aasink;
  GstVideoFrame frame;

  aasink = GST_AASINK (videosink);

  GST_DEBUG ("show frame");

  if (!gst_video_frame_map (&frame, &aasink->info, buffer, GST_MAP_READ))
    goto invalid_frame;

  gst_aasink_scale (aasink, GST_VIDEO_FRAME_PLANE_DATA (&frame, 0),     /* src */
      aa_image (aasink->context),       /* dest */
      GST_VIDEO_INFO_WIDTH (&aasink->info),     /* sw */
      GST_VIDEO_INFO_HEIGHT (&aasink->info),    /* sh */
      GST_VIDEO_FRAME_PLANE_STRIDE (&frame, 0), /* ss */
      aa_imgwidth (aasink->context),    /* dw */
      aa_imgheight (aasink->context));  /* dh */

  aa_render (aasink->context, &aasink->ascii_parms,
      0, 0, aa_imgwidth (aasink->context), aa_imgheight (aasink->context));
  aa_flush (aasink->context);
  aa_getevent (aasink->context, FALSE);
  gst_video_frame_unmap (&frame);

  return GST_FLOW_OK;

  /* ERRORS */
invalid_frame:
  {
    GST_DEBUG_OBJECT (aasink, "invalid frame");
    return GST_FLOW_ERROR;
  }
}
Пример #20
0
static void aarenderer_tick(int gt, int delta) {
    const client_world_info_t *worldsize = infon->get_world_info();
    if (!worldsize) return;
    const client_maptile_t *world = infon->get_world();
    unsigned char *p = bitmap;
    int x;
    int y;
    p--;
    for (y = 0; y < aa_imgheight(context); y++) {
        for (x = 0; x < aa_imgwidth(context); x++) {
            int terrainx = (x - ox) / SCALE;
            int terrainy = (y - oy) / SCALE;
            p++;
            if (terrainx < 0 || terrainx >= worldsize->width || 
                terrainy < 0 || terrainy >= worldsize->height)
                continue;
            const client_maptile_t *tile = &world[terrainy * worldsize->width + terrainx];
            switch (tile->type) {
                case TILE_SOLID:
                    *p = 90;
                    break;
                case TILE_PLAIN:
                    *p = 0;
                    break;
                default:
                    *p = 50;
                    break;
            }
        }
    }

    infon->each_creature(draw_creature, NULL);
    aa_renderpalette (context, palette, params, 0, 0, aa_scrwidth (context), aa_scrheight (context));
    aa_printf(context, 0, 0, AA_SPECIAL, infon->version);
    aa_flush(context);
}
Пример #21
0
static void draw3d(void)
{
    int time = TIME;
    double mul1, mul2, div = (double) (endtime - starttime);
    if (time < starttime - 1)
	time = starttime + 1;
    if (time > endtime)
	time = endtime;
    mul1 = pow((double) (time - starttime) / div, poww), mul2 = 1 - mul1;
    if (mul2 < 0)
	mul1 = 1, mul2 = 0;
    if (mul1 < 0)
	mul2 = 1, mul1 = 0;
    alfa = ((int) IN(salpha, ealpha)) % 360;
    beta = ((int) IN(sbeta, ebeta)) % 360;
    gama = ((int) IN(sgamma, egamma)) % 360;
    centerx = IN(scenterx, ecenterx);
    centery = IN(scentery, ecentery);
    centerz = IN(scenterz, ecenterz);
    zoom = IN(szoom, ezoom);
    disp3d();
    aa_render(context, params, 0, 0, aa_scrwidth(context), aa_scrheight(context));
    aa_flush(context);
}
Пример #22
0
int main(int argc, char **argv)
{
	aa_context *c;
	int i, y;
	char s[256];
	aa_renderparams *p;
	strcpy(s, "line editor.");
	if (!aa_parseoptions(NULL, NULL, &argc, argv) || argc != 1) {
		printf("%s\n", aa_help);
		exit(1);
	}
	c = aa_autoinit(&aa_defparams);
	if (c == NULL) {
		printf("Can not intialize aalib\n");
		exit(2);
	}
	if (!aa_autoinitkbd(c, 0)) {
		printf("Can not intialize keyboard\n");
		aa_close(c);
		exit(3);
	}
	for (i = 0; i < aa_imgwidth(c); i++)
		for (y = 0; y < aa_imgheight(c); y++)
			aa_putpixel(c, i, y, i + y < 80 ? i : ((i + y) < 100 ? (i + y == 89 ? 150 : 0) : y * 8));
	aa_hidecursor(c);
	aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c));
	aa_printf(c, 0, 0, AA_SPECIAL, "Fast rendering routine %i",1);
	aa_flush(c);
	aa_getkey(c, 1);
	aa_edit(c, 0, 1, 20, s, 256);
	aa_puts(c, 0, 0, AA_SPECIAL, "Key lookup test        ");
	aa_flush(c);
	int ch;
	while ((ch = aa_getevent(c, 1)) != ' ') {
		char s[80];
		sprintf(s, "Key event test-space to exit. c:%i", ch);
		aa_puts(c, 0, 0, AA_SPECIAL, s);
		aa_flush(c);
	}
	if (aa_autoinitmouse(c, AA_MOUSEALLMASK)) {
		int co = 0;
		sprintf(s, "Mouse test-space to exit");
		aa_puts(c, 0, 0, AA_SPECIAL, s);
		aa_flush(c);
		while (aa_getevent(c, 1) != ' ') {
			int x, y, b;
			char s[80];
			co++;
			aa_getmouse(c, &x, &y, &b);
			sprintf(s, "Mouse test-space to exit. x:%i y:%i b:%i event #%i  ", x, y, b, co);
			aa_puts(c, 0, 0, AA_SPECIAL, s);
			aa_flush(c);
		}
		aa_hidemouse(c);
		while (aa_getevent(c, 1) != ' ') {
			int x, y, b;
			char s[80];
			co++;
			aa_getmouse(c, &x, &y, &b);
			sprintf(s, "Hidden mouse test-space to exit. x:%i y:%i b:%i event #%i  ", x, y, b, co);
			aa_puts(c, 0, 0, AA_SPECIAL, s);
			aa_flush(c);
		}
		aa_uninitmouse(c);
	}
	p = aa_getrenderparams();
	for (i = 0; i < AA_DITHERTYPES; i++) {
		p->dither = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, aa_dithernames[i]);
		aa_flush(c);
		aa_getkey(c, 1);
	}
	for (i = 0; i < 255; i += 32) {
		p->bright = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - bright changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->bright = 0;
	for (i = 0; i < 128; i += 16) {
		p->contrast = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - contrast changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->contrast = 0;
	for (i = 0; i < 255; i += 32) {
		p->gamma = 1 + i / 32.0;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - gamma changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->gamma = 1.0;
	for (i = 0; i < 255; i += 32) {
		p->randomval = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - randomval changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	aa_close(c);
	return 0;
}
Пример #23
0
void main_loop(int max_iterations, int delay,
		int loadavg_flag, int normal_load, int socket_fd,
		float randomizestyletime, float randomizesitetime) {
	struct timeval starttime, endtime, selecttime;
	struct timeval lastrandomizestyletime={0,0};
	struct timeval lastrandomizesitetime ={0,0};
	struct aajm_loadavg load;
	long speed = DEFSPEED; /* microseconds between frames */
	long load_speed = 0; /* Speed adjustment, based on load */
	int loop_forever = 0;
	char c;
	int i;
	int tmp;
	char newsite[JML_MAX_SITELEN];
	char newstyle[2];

	int accepted_sock = 0; /* FD for accept()ed socket */
	int amount_read = 0; /* Amount read into buffer so far */
	int r; /* Num bytes read in last read() */
	char socket_buffer[MAX_SOCKET_BUFFER]; /* Buffer */
	char command[MAX_SOCKET_BUFFER];
	char data[MAX_SOCKET_BUFFER];
	fd_set socket_set; /* Used for select() */
	socklen_t sin_size; /* Used by accept() */
	struct sockaddr their_addr; /* Used by accept() */
	JML_CHAR **possible_styles;

	int newstyle_index;

	possible_styles = jmlib->getStyles();

	load.one = -1;
	load.five = -1;
	load.fifteen = -1;

	if(delay > 0) {
		speed = delay * 1000;
	}

	if(max_iterations <= 0) {
		loop_forever = 1;
	}

	memset((void *)socket_buffer,0,MAX_SOCKET_BUFFER);
	memset((void *)command,0,MAX_SOCKET_BUFFER);
	memset((void *)data,0,MAX_SOCKET_BUFFER);

	while (1) {
		gettimeofday(&starttime,NULL);
                if (randomizesitetime > 0 &&
                           (starttime.tv_sec -lastrandomizesitetime.tv_sec ) +
                    (float)(starttime.tv_usec-lastrandomizesitetime.tv_usec)/1000000
                     >= randomizesitetime) {
                        randompattern();
                        lastrandomizesitetime.tv_sec  = starttime.tv_sec;
                        lastrandomizesitetime.tv_usec = starttime.tv_usec;
                }
                if (randomizestyletime > 0 &&
                           (starttime.tv_sec -lastrandomizestyletime.tv_sec ) +
                    (float)(starttime.tv_usec-lastrandomizestyletime.tv_usec)/1000000
                      >= randomizestyletime) {
                        jmlib->setStyle("Random");
                        lastrandomizestyletime.tv_sec  = starttime.tv_sec;
                        lastrandomizestyletime.tv_usec = starttime.tv_usec;
                }

		jmlib->doJuggle();
		draw_juggler(loadavg_flag, context, jmlib);

		if(loadavg_flag) {
			loadaverage(&load);
			if(load.one != -1) {
				tmp = (int)(load.one*100 - normal_load);
				load_speed = 5000 * tmp;
			}
		}

		c=aa_getkey(context,0);
		if(c=='s' || c=='S') {
			/* Change SiteSwap */
			memset(newsite,0,JML_MAX_SITELEN);
			strncpy(newsite, jmlib->getSite(), JML_MAX_SITELEN);
			aa_puts(context, 1, 4, AA_SPECIAL,
				gettext("Enter New SiteSwap..."));
			aa_edit(context, 1, 5, 20,
				newsite, JML_MAX_SITELEN);
			if(newsite[0]!=0) {
				jmlib->setPattern(newsite,newsite,
					HR_DEF, DR_DEF);
				jmlib->setStyleDefault();
				jmlib->startJuggle();
			}
		} else if(c=='r' || c=='R') {
                        randompattern();
		} else if(c=='q' || c=='Q' || c==27) {
			/* Quit */
			/* 27 == Escape
			Don't complain. This was a hack before it started */
			return;
		} else if(c==' ' || c=='p' || c=='P') {
			/* Toggle Pause */
			jmlib->togglePause();
		} else if(c=='t' || c=='T') {
			/* Change Style */
			aa_puts(context, 3, 4, AA_SPECIAL,
				gettext("Choose New Style..."));
			for (i=0;i<jmlib->numStyles();i++) {
				aa_printf(context, 3, 5+i, AA_SPECIAL,
					"%i: %s",i+1,possible_styles[i]);
			}
			aa_flush(context);
			memset(newstyle,0,JML_MAX_SITELEN);
			aa_edit(context, 3, 5+i, 2, newstyle, 2);
			if(newstyle[0]!=0) {
				newstyle_index=atoi(newstyle)-1;
				if(newstyle_index>=0
				  && newstyle_index<jmlib->numStyles()) {
					jmlib->setStyle(possible_styles[newstyle_index]);
				}
			}
		} else if(c=='h' || c=='H') {
			/* Help */
			int curr_height = 4;
			aa_puts(context, 3, curr_height, AA_SPECIAL,
				gettext("Key Help"));
			++curr_height;
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("h - This screen"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("s - Change Siteswap"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("r - Random Pattern"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("t - Change Style"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("l - Toggle Load Monitoring"));
#ifdef HAVE_AVCODEC_H
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("m - Dump MPEG"));
#endif
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("q - Quit"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("space - Pause"));
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("+, -, enter - Speed up, down, reset"));
			++curr_height;
			aa_puts(context, 3, ++curr_height, AA_SPECIAL,
				gettext("Press any key to remove this menu"));
			aa_flush(context);
			aa_getkey(context, 1);
		} else if(c=='+' || c=='=' || c=='k') {
			/* Speed Up */
			speed -= 1500;
			if(speed < 0) { speed = 0; }
		} else if(c=='-' || c=='j') {
			/* Speed Down */
			speed += 1500;
#ifdef HAVE_AVCODEC_H
		} else if(c=='m') {
			/* Dump MPEG */
			char mpegname[20];
			memset(mpegname,0,20);
			aa_puts(context, 1, 4, AA_SPECIAL,
				gettext("Enter MPEG Name..."));
			aa_edit(context, 1, 5, 20,
				mpegname, JML_MAX_SITELEN);
			if(mpegname[0]!=0) {
				creatempeg(jmlib, mpegname);
			}
#endif
		} else if(c=='l') {
			/* Toggle Load Monitoring */
			if(loadavg_flag == 1) {
				loadavg_flag = 0;
				load_speed = 0;
			} else {
				loadavg_flag = 1;
			}
		} else if(c==13) {
			/* Speed Reset */
			/* 13 == Enter */
			speed = DEFSPEED;
		}
		gettimeofday(&endtime,NULL);

		selecttime.tv_sec = endtime.tv_sec - starttime.tv_sec;
		if (selecttime.tv_sec != 0) {
			endtime.tv_usec += 1000000*selecttime.tv_sec;
			selecttime.tv_sec = 0;
		}
		selecttime.tv_usec = (speed + load_speed) - 
					(endtime.tv_usec - starttime.tv_usec);
		if(selecttime.tv_usec < 0) {
			selecttime.tv_usec = 1;
		}

		/* IPC Code begins here */
		if(socket_fd <= 0) {
			select(0,NULL,NULL,NULL,&selecttime);
		} else {

		FD_ZERO(&socket_set);
		FD_SET(socket_fd,&socket_set);
		/* accepted_sock is the fd we get
			from accept()ing the socket */
		if(accepted_sock > 0) {
			/* read just one byte */
			r = read(accepted_sock,
				(void *)&socket_buffer[amount_read],1);
			if(r == -1 && errno != EAGAIN) {
			/* EAGAIN means we need to try reading again,
			there wasn't an error, the descriptor just had
			nothing waiting in it
			Else, close the handle reset the other data stuff */
				memset((void *)socket_buffer,0,MAX_SOCKET_BUFFER-amount_read-1);
				close(accepted_sock);
				amount_read = 0;
				accepted_sock = 0;
				memset((void *)data,0,MAX_SOCKET_BUFFER);
				memset((void *)command,0,MAX_SOCKET_BUFFER);
			} else if(r > 0) {
			/* transfer stuff: command=data; If we see an
			'=', everything before it was a command. If we
			see a ';', the stuff before it was data */
				amount_read+=r;
				if(socket_buffer[amount_read-1] == '=') {
					memset((void *)command,0,MAX_SOCKET_BUFFER);
					memcpy((void *)command,(void *)socket_buffer, amount_read-1);
					memset((void *)socket_buffer,0,MAX_SOCKET_BUFFER);
					amount_read = 0;
				} else if(socket_buffer[amount_read-1] == ';') {
					memset((void *)data,0,MAX_SOCKET_BUFFER);
					memcpy((void *)data,(void *)socket_buffer, amount_read-1);
					memset((void *)socket_buffer,0,MAX_SOCKET_BUFFER);
					close(accepted_sock);
					amount_read = 0;
					accepted_sock = 0;
				}
			}
			if(amount_read >= MAX_SOCKET_BUFFER-1) {
			/* Too late, F**k 'em, they're trying
			to overflow us anyway */
				write(accepted_sock,OVERFLOW_ERROR,strlen(OVERFLOW_ERROR));
				memset((void *)socket_buffer,0,MAX_SOCKET_BUFFER);
				close(accepted_sock);
				amount_read = 0;
				accepted_sock = 0;
			}
		}

		if(command[0] != '\0' && data[0] != '\0') {
			if(!strcmp(command,"Style")) {
				jmlib->setStyle(data);
			} else if(!strcmp(command,"Site")) {
				jmlib->setPattern("Something",data,
					HR_DEF, DR_DEF);
				jmlib->setStyleDefault();
				jmlib->startJuggle();
			} else if(!strcmp(command,"Speed")) {
				if(!strcmp(data,"Up")) {
					speed -= 1500;
					if(speed < 0) speed = 0;
				} else if(!strcmp(data,"Down")) {
					speed += 1500;
				} else if(!strcmp(data,"Reset")) {
					speed = DEFSPEED;
				}
			}

			memset((void *)data,0,MAX_SOCKET_BUFFER);
			memset((void *)command,0,MAX_SOCKET_BUFFER);
		}
		if(!strcmp(command,"Quit")) {
			return;
		}
				
		if(select(socket_fd+1, &socket_set,
			NULL, NULL, &selecttime) > 0) {
			if(FD_ISSET(socket_fd,&socket_set) && accepted_sock) {
			/* Just close any subsequent conenctions until
				this one's done */
				close(accept(socket_fd,&their_addr,&sin_size));
			} else if(FD_ISSET(socket_fd,&socket_set) && !accepted_sock) {
			/* Else accept() the socket, and set it to not block */
				sin_size = sizeof(sockaddr);
				accepted_sock = accept(socket_fd,&their_addr, &sin_size);
				fcntl(accepted_sock, F_SETFL, O_NONBLOCK);
			}
		}
		}

		if(!loop_forever && max_iterations-- <= 0) {
			break;
		}
	}
}
Пример #24
0
void errorCB(char* msg) {
	aa_printf(context, 1, 1, AA_NORMAL, "%s", msg);
	aa_flush(context);
	sleep(2);
}
Пример #25
0
void draw_juggler(int show_loadavg, aa_context *c, JMLib *j) {
	int color;
	int i;
	struct aajm_loadavg load;

	arm* ap = &(j->ap);
	ball* rhand = &(j->rhand);
	ball* lhand = &(j->lhand);
	hand* handp = &(j->handpoly);

	color = 64;
	// draw head
	aa_drawcircle(c,ap->hx, ap->hy,
			ap->hr, color, -1);

	// draw juggler
	for (i=0;i<5;i++) {
		aa_drawline(c, ap->rx[i], ap->ry[i],
			ap->rx[i+1], ap->ry[i+1], color);
		aa_drawline(c, ap->lx[i], ap->ly[i],
			ap->lx[i+1], ap->ly[i+1], color);
	}

	// hands
	for (i=0; i <= 8; i++) {
		aa_drawline(c, rhand->gx + handp->rx[i],
			rhand->gy + handp->ry[i],
			rhand->gx + handp->rx[i+1],
			rhand->gy + handp->ry[i+1], color);
		aa_drawline(c, lhand->gx + handp->lx[i],
			lhand->gy + handp->ly[i],
			lhand->gx + handp->lx[i+1],
			lhand->gy + handp->ly[i+1], color);
	}
	aa_drawline(c, rhand->gx + handp->rx[9],
		rhand->gy + handp->ry[9],
		rhand->gx + handp->rx[0],
		rhand->gy + handp->ry[0], color);
	aa_drawline(c, lhand->gx + handp->lx[9],
		lhand->gy + handp->ly[9],
		lhand->gx + handp->lx[0],
		lhand->gy + handp->ly[0], color);

	color = 255;
	// draw balls
	int diam = (11*j->dpm/DW);
	for(i=j->numBalls()-1;i>=0;i--) {
		aa_drawcircle(c, j->b[i].gx + diam,
				j->b[i].gy + diam,
				diam, color, color);
	}


	aa_render(c, params, 0, 0,
		aa_imgwidth(c), aa_imgheight(c));

	aa_printf(c, 0, 0, AA_SPECIAL,
		gettext("Site: %s    Style: %s    Balls: %i"),
		j->getSite(), j->getStyle(), j->numBalls());

	if(show_loadavg) {
		loadaverage(&load);
		aa_printf(c, 0, 1, AA_SPECIAL,
			"LoadAvg: %2.2f %2.2f %2.2f",
			load.one, load.five, load.fifteen);
	}
	if(j->getStatus() == ST_PAUSE) {
		aa_puts(c, 1, 3, AA_SPECIAL, gettext("Paused"));
	}
	aa_flush(c);

	memset(c->imagebuffer,0,aa_imgwidth(c)*aa_imgheight(c));
}
Пример #26
0
void credits2(void)
{
    int i, ch;
    int p;
    int plast = -1;
    clrscr();

    centerprint(aa_imgwidth(context) / 2, aa_imgheight(context) / 3, 3, 128, "The", 0);
    centerprint(aa_imgwidth(context) / 2, 2 * aa_imgheight(context) / 3, 3, 128, "END", 0);
    drawptr = decrand;
    params->randomval = 50;
    timestuff(0, NULL, draw, 5000000);
    drawptr = NULL;
    params->randomval = 0;
    drawptr = pryc;
    timestuff(0, NULL, draw, MAXTIME);
    drawptr = NULL;
    clrscr();
    draw();
    load_song("bb3.s3m");
    bbupdate();
    starttime = endtime = TIME;
    play();
    bbwait(1);
    for (i = 0; i < LOGOHEIGHT; i++) {
	aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i, AA_BOLD, "8  8");
	if (i)
	    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");
	bbflushwait(100000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");

#define LWIDTH

    for (i = aa_scrwidth(context) / 2; i; i--) {
	display8();
	displaya(i);
	bbflushwait(10000);
    }
    for (; i < 100; i++) {
	textclrscr();
	displaya(10 * sin(i * M_PI / 100));
	display8();
	bbflushwait(10000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_DIM, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_BOLD, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    bbwait(1000000);
    for (i = LOGOY; i > 1; i--) {
	textclrscr();
	displogo(i);
	bbflushwait(30000);
    }

    source = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    target = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    params->dither = AA_NONE;
    format(dual ? aa_scrwidth(context) / 2 : aa_scrwidth(context));
    p = 0;
    while (1) {
	if (p != plast) {
	    getsource();
	    displaytext(p);
	    gettarget();
	    morph();
	    displaytext(p);
	    aa_flush(context);
        emscripten_sleep(1);
	    plast = p;
	}
      again:
    emscripten_sleep(100);
#ifndef __DJGPP__
	//ch = aa_getkey(context, 100);
    ch = AA_NONE;
#else
	while ((ch = bbupdate()) == AA_NONE) ;
#endif

	switch (ch) {
	case '1':
	    load_song("bb.s3m");
	    bbupdate();
	    play();
	    break;
	case '2':
	    load_song("bb2.s3m");
	    bbupdate();
	    play();
	    break;
	case '3':
	    load_song("bb3.s3m");
	    bbupdate();
	    play();
	    break;

	case 'b':
	case 'k':
	case 'B':
	case 'K':
	case AA_BACKSPACE:
	case AA_UP:
	    p -= (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p < 0)
		p = 0;
	    break;
	case AA_DOWN:
	case AA_LEFT:
	case 'f':
	case 'F':
	case ' ':
	case 'j':
	case 'J':
	    p += (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p > textsize)
		p = textsize;
	    break;
	case 'q':
	case 'Q':
	case AA_ESC:
	    finish_stuff = 0;
	    backconvert(0, 0, aa_scrwidth(context), aa_scrheight(context));
	    bbupdate();
	    starttime = endtime = TIME;
	    drawptr = decbright;
	    timestuff(0, NULL, draw, 1000000);
	    textclrscr();
	    drawptr = NULL;
	    aa_flush(context);
        emscripten_sleep(1);
	    free(source);
	    free(target);
	    return;
	default:
	    goto again;
	}
	bbupdate();
	starttime = endtime = TIME;
    }
}
Пример #27
0
int main(int argc, char* argv[]) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s IN_FILE OUT_FILE", argv[0]);
    exit(1);
  }

  MagickWand* m_wand;

  // Initialize
  MagickWandGenesis();
  m_wand = NewMagickWand();

  // read image
  if (MagickReadImage(m_wand, argv[1]) == MagickFalse) {
    fprintf(stderr, "Cannot read image: %s\n", argv[1]);
    exit(1);
  }

  // resize
  MagickResizeImage(m_wand, WIDTH, HEIGHT, LanczosFilter, 1.0);

  // ready for using AAlib
  aa_context* c;
  aa_savedata save_data = {
    argv[2],
    &aa_text_format,
    NULL
  };
  // Initialize AAlib
  c = aa_init(&save_d, &aa_defparams, (const void*) &save_data);
  if (c == NULL) {
    fprintf(stderr, "Cannot initialize AA-lib\n");
    exit(1);
  }

  // record image data to AAlib image buffer
  PixelIterator* iter = NewPixelIterator(m_wand);
  PixelWand** pix;
  unsigned long num_wands;
  double h, s, l;
  int x, y;

  y = 0;
  while ((pix = PixelGetNextIteratorRow(iter, &num_wands)) != NULL) {
    for (x = 0; x < num_wands; ++x) {
      PixelGetHSL(pix[x], &h, &s, &l);
      aa_putpixel(c, x, y, 256*l);
    }
    y++;
  }

  // rendering ascii and print file
  aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c));
  aa_flush(c);

  // terminate
  aa_close(c);

  // finalize to finish
  if (m_wand) {
    m_wand = DestroyMagickWand(m_wand);
  }
  MagickWandTerminus();
  return 0;
}