Exemple #1
0
static void
linux_flush (aa_context * c)
{
  int i;
  int x, y, xstart = 0, xend, end = aa_scrwidth (c) * aa_scrheight (c);
  unsigned char data[] = { 0x07, 0x08, 0x0f, 0x0f, 0x70, 0x17 };
  for (i = 0; i < nvcs; i++)
    {
      fseek (vc[i], 4, 0);
      for (y = 0; y < aa_scrheight (c); y++)
	{
	  int start = y * aa_scrwidth (c);
	  for (x = xstart; x < xstart + sizes[0][i]; x++)
	    {
	      putc (c->textbuffer[x + start], vc[i]);
	      if (c->attrbuffer[x + start] < 7)
		putc (data[c->attrbuffer[x + start]], vc[i]);
	      else
		putc (0x27, vc[i]);
	    }
	}
      xstart += sizes[0][i];
      fflush (vc[i]);
    }
}
Exemple #2
0
static void displaytext(int p)
{
    int i;
    int x, x1, a = AA_NORMAL;
    char s[2] =
    {0, 0};
    textclrscr();
    displogo(1);
    for (i = 0; i < aa_scrwidth(context); i++) {
	context->textbuffer[aa_scrwidth(context) * (YSTART - 2) + i] = '_';
    }
    for (i = p; i < p + aa_scrheight(context) - YSTART; i++) {
	if (i < textsize) {
	    x = 0;
	    x1 = 0;
	    for (x1 = x = 0; x < strlen(line[i]); x++, x1++) {
		while (((unsigned char) line[i][x]) < 20)
		    a = line[i][x] - 1, x++;
		if (x < strlen(line[i])) {
		    s[0] = line[i][x];
		    aa_puts(context, x1, i - p + YSTART, a, s);
		}
	    }
	}
	else {
	    x = 0;
	    aa_puts(context, x, i - p + YSTART, AA_NORMAL, "~");
	}
    }
    if (dual) {
	int sh = aa_scrheight(context) - YSTART;
	for (i = p; i < p + (aa_scrheight(context) - YSTART); i++) {
	    if (i + sh < textsize) {
		x = 0;
		x1 = 0;
		for (x1 = x = 0; x < strlen(line[i + sh]); x++, x1++) {
		    while (((unsigned char) line[i + sh][x]) < 20)
			a = line[i + sh][x] - 1, x++;
		    if (x < strlen(line[i + sh])) {
			s[0] = line[i + sh][x];
			aa_puts(context, x1 + aa_scrwidth(context) / 2, i - p + YSTART, a, s);
		    }
		}
	    }
	    else {
		x = 0;
		aa_puts(context, x + aa_scrwidth(context) / 2, i - p + YSTART, AA_NORMAL, "~");
	    }
	}
    }


}
static void
draw_osd(void){
    char * vo_osd_text_save;
    int vo_osd_progbar_type_save;

    printosdprogbar();
    /* let vo_draw_text only write subtitle */
    vo_osd_text_save=vo_osd_text; /* we have to save the osd_text */
    vo_osd_text=NULL;
    vo_osd_progbar_type_save=vo_osd_progbar_type;
    vo_osd_progbar_type=-1;
    vo_remove_text(aa_scrwidth(c), aa_scrheight(c),clear_alpha);
    vo_draw_text(aa_scrwidth(c), aa_scrheight(c), draw_alpha);
    vo_osd_text=vo_osd_text_save;
    vo_osd_progbar_type=vo_osd_progbar_type_save;
}
Exemple #4
0
void aa_gotoxy(aa_context * c, int x, int y)
{
    if (c->cursorstate >= 0) {
	if (x < 0)
	    x = 0;
	if (y < 0)
	    y = 0;
	if (x >= aa_scrwidth(c))
	    x = aa_scrwidth(c) - 1;
	if (y >= aa_scrheight(c))
	    y = aa_scrheight(c) - 1;
	c->driver->gotoxy(c, x, y);
	c->cursorx = x;
	c->cursory = y;
    }
}
Exemple #5
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);
}
Exemple #6
0
static void newline()
{
    while (cursor_x < aa_scrwidth(context)) {
	context->textbuffer[cursor_x + cursor_y * aa_scrwidth(context)] = ' ';
	context->attrbuffer[cursor_x + cursor_y * aa_scrwidth(context)] = AA_NORMAL;
	cursor_x++;
    }
    start--;
    if (start < 0)
	start = 0;
    cursor_y++, cursor_x = 0;
    if (cursor_y >= aa_scrheight(context)) {
	memcpy(context->textbuffer + start * aa_scrwidth(context), context->textbuffer + (start + 1) * aa_scrwidth(context), aa_scrwidth(context) * (aa_scrheight(context) - start - 1));
	memcpy(context->attrbuffer + start * aa_scrwidth(context), context->attrbuffer + (start + 1) * aa_scrwidth(context), aa_scrwidth(context) * (aa_scrheight(context) - start - 1));
	memset(context->textbuffer + aa_scrwidth(context) * (aa_scrheight(context) - 1), ' ', aa_scrwidth(context));
	memset(context->attrbuffer + aa_scrwidth(context) * (aa_scrheight(context) - 1), 0, aa_scrwidth(context));
	cursor_y--;
    }
}
Exemple #7
0
static void aa_display(aa_context * c, int x1, int y1, int x2, int y2)
{
    int x, y, pos, attr, p;
    unsigned char str[80];
    int cursor=c->mousemode,hidden=0;
    if (x2 < 0 || y2 < 0 || x1 > aa_scrwidth(c) || y1 > aa_scrheight(c))
	return;
    if (x2 >= aa_scrwidth(c))
	x2 = aa_scrwidth(c);
    if (y2 >= aa_scrheight(c))
	y2 = aa_scrheight(c);
    if (x1 < 0)
	x1 = 0;
    if (y1 < 0)
	y1 = 0;
	if (c->driver->print == NULL)
	    return;
	pos = 0;
	for (y = y1; y < y2; y++) {
	    pos = y * aa_scrwidth(c) + x1;
	    c->driver->gotoxy(c, x1, y);
	    for (x = x1; x < x2;) {
		p = 0;
		attr = c->attrbuffer[pos];
		while (p < 79 && x < x2 && c->attrbuffer[pos] == attr) {
		    str[p] = c->textbuffer[pos];
		    pos++;
		    p++;
		    x++;
		}
		str[p] = 0;
		HIDEMOUSE
		c->driver->setattr(c, attr);
		c->driver->print(c, str);
	    }
	c->driver->gotoxy(c, c->cursorx, c->cursory);
    }
        if(hidden&&cursor)
	   aa_showmouse(c);
}
Exemple #8
0
void messager(char *c)
{
    int i, s = strlen(c);
    start = cursor_y = aa_scrheight(context) - 1;
    cursor_x = 0;
    for (i = 0; i < s; i++) {
	put(c[i]);
	putcursor();
	bbflushwait(0.03 * 1000000);
    }
    bbflushwait(1000000);
    aa_gotoxy(context, 0, 0);
}
Exemple #9
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);            
 }
Exemple #10
0
static void stderr_flush(aa_context * c)
{
    int x, y;
    for (y = 0; y < aa_scrheight(c); y++) {
	for (x = 0; x < aa_scrwidth(c); x++) {
	    putc(c->textbuffer[x + y * aa_scrwidth(c)], stderr);
	}
	putc('\n', stderr);
    }
    putc('', stderr);
    putc('\n', stderr);
    fflush(stderr);
}
Exemple #11
0
void aa_puts(aa_context * c, int x, int y, enum aa_attribute attr, __AA_CONST char *s)
{
    char s1[10000];
    int pos, pos1;
    int x1, y1;
    if (x < 0 || y < 0 || x >= aa_scrwidth(c) || y >= aa_scrheight(c))
	return;
    x1 = x;
    y1 = y;
    for (pos = 0; s[pos] != 0 && pos < 10000; pos++) {
	s1[pos] = s[pos];
	pos1 = x1 + y1 * aa_scrwidth(c);
	c->textbuffer[pos1] = s[pos];
	c->attrbuffer[pos1] = attr;
	x1++;
	if (x1 >= aa_scrwidth(c)) {
	    x1 = 0;
	    y1++;
	    if (y1 >= aa_scrheight(c))
		break;
	}
    }
}
Exemple #12
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);
}
static void
resize(void){
    /*
     * this function is called by aa lib if windows resizes
     * further during init, because here we have to calculate
     * a little bit
     */

    aa_resize(c);

    aspect_save_screenres(aa_imgwidth(c),aa_imgheight(c));
    image_height =  aa_imgheight(c); //src_height;
    image_width = aa_imgwidth(c); //src_width;

    aspect(&image_width,&image_height,A_ZOOM);

    image_x = (aa_imgwidth(c) - image_width) / 2;
    image_y = (aa_imgheight(c) - image_height) / 2;
    screen_w = image_width * aa_scrwidth(c) / aa_imgwidth(c);
    screen_h = image_height * aa_scrheight(c) / aa_imgheight(c);
    screen_x = (aa_scrwidth(c) - screen_w) / 2;
    screen_y = (aa_scrheight(c) - screen_h) / 2;

    if(sws) sws_freeContext(sws);
    sws = sws_getContextFromCmdLine(src_width,src_height,image_format,
				   image_width,image_height,IMGFMT_Y8);

    memset(image, 0, sizeof(image));
    image[0] = aa_image(c) + image_y * aa_imgwidth(c) + image_x;

    memset(image_stride, 0, sizeof(image_stride));
    image_stride[0] = aa_imgwidth(c);

    showosdmessage=0;

}
Exemple #14
0
static void os2vio_flush(aa_context * c)
{
  char data[] = {
    (WM_BLACK << 4) + WM_PALEGRAY,    /* NORMAL?   0 */
    (WM_BLACK << 4) + WM_DKGREY,      /* DIM?      1 */
    (WM_BLACK << 4) + WM_WHITE,       /* BOLD?     2 */
    (WM_RED << 4) + WM_PALEGRAY,      /* BOLDFONT? 3 */
    (WM_PALEGRAY << 4) + WM_BLACK,    /* REVERSE?  4 */
    (WM_BLUE << 4) + WM_WHITE         /* SPECIAL?  5 */
  };

  int x, y;
  for (y = 0; y < aa_scrheight(c); y++) {
    for (x = 0; x < aa_scrwidth(c); x++) {
      if(c->attrbuffer[x + y * aa_scrwidth(c)] < 7)
	RowStr[x*2+1] = data[c->attrbuffer[x + y * aa_scrwidth(c)]];
      else
	RowStr[x*2+1] = (WM_BLACK << 4) + WM_PALEGRAY;
      RowStr[x*2] = c->textbuffer[x + y * aa_scrwidth(c)];
    }
    VioWrtCellStr(RowStr, 2*width, y, 0, (HVIO)0);
  }
}
Exemple #15
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;
}
Exemple #16
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);
}
Exemple #17
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);
}
Exemple #18
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;
}
Exemple #19
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;
    }
}
Exemple #20
0
static void X_flush(aa_context * c)
{
    struct xdriverdata *d=c->driverdata;
    int x, y, attr;
    int xs = 0, ys = 0;
    int l, same;
    int s = 0;
    int pos;
    attr = AA_NORMAL;
    alloctables(d);
    drawed = 0;
    area = 0;
    nrectangles[0] = 0;
    nrectangles[1] = 0;
    nrectangles[2] = 0;
    nrectangles[3] = 0;
    if (d->previoust == NULL) {
	d->previoust = malloc(d->width * d->height);
	d->previousa = calloc(d->width * d->height, 1);
	memset(d->previoust, ' ', d->width * d->height);
    }
    for (y = 0; y < aa_scrheight(c); y++) {
	s = l = 0;
	xs = 0;
	ys = y;
	for (x = 0; x < aa_scrwidth(c); x++) {
	    pos = x + y * aa_scrwidth(c);
	    if (s > 5 || (c->attrbuffer[pos] != attr && (c->textbuffer[pos] != ' ' || Black[c->attrbuffer[pos]] || Black[attr]))) {
		if (l - s)
		    MyDrawString(d,attr, xs, ys,
			&c->textbuffer[xs + ys * aa_scrwidth(c)], l - s);
		attr = c->attrbuffer[pos];
		s = l = 0;
		xs = x;
		ys = y;
	    }
	    if ((d->previoust[pos] == c->textbuffer[pos] && d->previousa[pos] == c->attrbuffer[pos]) || (!Black[attr] && d->previoust[pos] == ' ' && c->textbuffer[pos] == ' ' && !Black[d->previousa[pos]]))
		same = 1;
	    else
		same = 0;
	    if (xs == x && same)
		xs++;
	    else {
		if (same)
		    s++;
		else
		    s = 0;
		l++;
	    }
	}
	if (l - s)
	    MyDrawString(d,attr, xs, ys,
			 &c->textbuffer[xs + ys * aa_scrwidth(c)], l - s);
    }
    if (drawed) {
	memcpy(d->previousa, c->attrbuffer, d->width * d->height);
	memcpy(d->previoust, c->textbuffer, d->width * d->height);
	if (nrectangles[0])
	    XFillRectangles(d->dp, dr, d->blackGC, &rectangles(0, 0), nrectangles[0]);
	if (nrectangles[1])
	    XFillRectangles(d->dp, dr, d->normalGC, &rectangles(1, 0), nrectangles[1]);
	if (nrectangles[2])
	    XFillRectangles(d->dp, dr, d->specialGC, &rectangles(2, 0), nrectangles[2]);
	if (d->cvisible)
	    XDrawLine(d->dp, dr, d->normalGC, d->Xpos * d->realfontwidth, (d->Ypos + 1) * d->fontheight - 1, (d->Xpos + 1) * d->realfontwidth - 1, (d->Ypos + 1) * d->fontheight - 1);

	for (y = 0; y < d->height; y++) {
	    for (x = 0; x < NATT; x++) {
		if (nitem[y][x]) {
		    X_setattr(d,x);
		    XDrawText(d->dp, dr, d->currGC, 0, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]);
		    if (x == 4)
			XDrawText(d->dp, dr, d->currGC, 1, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]);
		}
	    }
	}
	if (d->pixmapmode) {
	    if (nrectangles[3] && area < d->width*d->height/2 && nrectangles[3] < 5)
	      {
		int i;
	        /*fprintf (stderr, "%i %i\n",nrectangles[3], area);*/
		for (i = 0; i < nrectangles[3]; i++)
		  XClearArea (d->dp, d->wi, rectangles(3, i).x, rectangles(3,i).y,
			      rectangles(3,i).width, rectangles(3,i).height, 0);
	      }
	    else
	      XClearWindow(d->dp, d->wi);
	}
	/*if(!d->pixmapmode) */
	XSync(d->dp, 0);
    }
    freetables();
}
Exemple #21
0
static void gettarget()
{
    backconvert(0, YSTART, aa_scrwidth(context), aa_scrheight(context));
    memcpy(target, context->imagebuffer + aa_imgwidth(context) * 2 * YSTART, aa_imgwidth(context) * (aa_imgheight(context) - YSTART * 2));
}
Exemple #22
0
void scene10()
{
    salpha = sbeta = sgamma = scenterx = scentery = scenterz;
    szoom = 0;
    ealpha = ebeta = egamma = ecenterx = ecentery = ecenterz = 0;
    ezoom = 0;
    poww = 1;
    drawptr = NULL;
    patnikconstructor();
    params->gamma = 1;
    centery = -40;
    strobikstart();
    zoom = 3;
    alfa = 90;
    beta = 0;
    gama = 180;
    disp3d();
    aa_render(context, params, 0, 0, aa_scrwidth(context), aa_scrheight(context));
    strobikend();
    bbwait(500000);

    strobikstart();
    alfa = 0;
    disp3d();
    aa_render(context, params, 0, 0, aa_scrwidth(context), aa_scrheight(context));
    strobikend();
    bbwait(500000);

    strobikstart();
    alfa = 180;
    disp3d();
    aa_render(context, params, 0, 0, aa_scrwidth(context), aa_scrheight(context));
    strobikend();
    bbwait(500000);

    strobikstart();
    alfa = 270;
    disp3d();
    aa_render(context, params, 0, 0, aa_scrwidth(context), aa_scrheight(context));
    strobikend();

    salpha = 270;
    sbeta = 0;
    sgamma = 180;
    szoom = 3;
    scentery = -40;
    ealpha = 360 + 90;
    ebeta = 0;
    egamma = 180;
    ezoom = 3;
    ecentery = -40;
    do3d(4 * 1000000);
    poww = 3;
    ezoom = 2;
    ebeta = 90;
    ecenterz = 60;
    ecentery = 50;
    do3d(3 * 1000000);
    poww = 0.4;
    ebeta = 60;
    do3d(0.5 * 1000000);
    poww = 5;
    ebeta = 90;
    do3d(0.5 * 1000000);
    poww = 2;
    ecenterz = 0;
    ecenterx = 60;
    ebeta = 0;
    egamma = 180 * 5;
    ezoom = 0.1;
    do3d(11.5 * 1000000);
    params->gamma = 1;

}
void AA_PumpEvents(_THIS)
{
	int posted = 0;
	int mouse_button, mouse_x, mouse_y;
	int evt;
	SDL_keysym keysym;

	static int prev_button = -1, prev_x = -1, prev_y = -1;

	if( ! this->screen ) /* Wait till we got the screen initialized */
	  return;

	do {
		posted = 0;
		/* Gather events */

		/* Get mouse status */
		SDL_mutexP(AA_mutex);
		aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button);
		SDL_mutexV(AA_mutex);
		mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context);
		mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context);

		/* Compare against previous state and generate events */
		if( prev_button != mouse_button ) {
			if( mouse_button & AA_BUTTON1 ) {
				if ( ! (prev_button & AA_BUTTON1) ) {
					posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
				}
			} else {
				if ( prev_button & AA_BUTTON1 ) {
					posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
				}
			}
			if( mouse_button & AA_BUTTON2 ) {
				if ( ! (prev_button & AA_BUTTON2) ) {
					posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0);
				}
			} else {
				if ( prev_button & AA_BUTTON2 ) {
					posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0);
				}
			}
			if( mouse_button & AA_BUTTON3 ) {
				if ( ! (prev_button & AA_BUTTON3) ) {
					posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0);
				}
			} else {
				if ( prev_button & AA_BUTTON3 ) {
					posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0);
				}
			}
		}
		if ( prev_x != mouse_x || prev_y != mouse_y ) {
			posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y);
		}

		prev_button = mouse_button;
		prev_x = mouse_x; prev_y = mouse_y;

		/* Get keyboard event */
		SDL_mutexP(AA_mutex);
		evt = aa_getevent(AA_context, 0);
		SDL_mutexV(AA_mutex);
		if ( (evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) && (evt != AA_RESIZE) ) {
			/* Key pressed */
/*    			printf("Key pressed: %d (%c)\n", evt, evt); */
			posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym));
		} else if ( evt >= AA_RELEASE ) {
			/* Key released */
			evt &= ~AA_RELEASE;
/*  			printf("Key released: %d (%c)\n", evt, evt); */
			posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym));
		}
	} while ( posted );
}
Exemple #24
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);
}
Exemple #25
0
void aa_renderpalette(aa_context * c, aa_palette palette, aa_renderparams * p, int x1, int y1, int x2, int y2)
{
    static int state;
    int x, y;
    int val;
    int wi = c->imgwidth;
    int pos;
    int i;
    int pos1;
    int i1, i2, i3, i4, esum;
    int *errors[2];
    int cur = 0;
    int mval;
    int gamma = p->gamma != 1.0;
    aa_palette table;
    if (x2 < 0 || y2 < 0 || x1 > aa_scrwidth(c) || y1 > aa_scrheight(c))
	return;
    if (x2 >= aa_scrwidth(c))
	x2 = aa_scrwidth(c);
    if (y2 >= aa_scrheight(c))
	y2 = aa_scrheight(c);
    if (x1 < 0)
	x1 = 0;
    if (y1 < 0)
	y1 = 0;
    if (c->table == NULL)
	aa_mktable(c);
    if (p->dither == AA_FLOYD_S) {
	errors[0] = calloc(1, (x2 + 5) * sizeof(int));
	if (errors[0] == NULL)
	    p->dither = AA_ERRORDISTRIB;
	errors[0] += 3;
	errors[1] = calloc(1, (x2 + 5) * sizeof(int));
	if (errors[1] == NULL)
	    free(errors[0]), p->dither = AA_ERRORDISTRIB;
	errors[1] += 3;
	cur = 0;
    }
    for (i = 0; i < 256; i++) {
	y = palette[i] + p->bright;
	if (y > 255)
	    y = 255;
	if (y < 0)
	    y = 0;
	if (p->contrast)
	    y = DO_CONTRAST(y, p->contrast);
	if (gamma) {
	    y = pow(y / 255.0, p->gamma) * 255 + 0.5;
	}
	if (p->inversion)
	    y = 255 - y;
	if (y > 255)
	    y = 255;
	else if (y < 0)
	    y = 0;
	table[i] = y;
    }
    gamma = 0;
    if (p->randomval)
	gamma = p->randomval / 2;
    mval = (c->parameters[c->filltable[255]].p[4]);
    for (y = y1; y < y2; y++) {
	pos = 2 * y * wi;
	pos1 = y * aa_scrwidth(c);
	esum = 0;
	for (x = x1; x < x2; x++) {
	    i1 = table[((((int) c->imagebuffer[pos])))];
	    i2 = table[((((int) c->imagebuffer[pos + 1])))];
	    i3 = table[((((int) c->imagebuffer[pos + wi])))];
	    i4 = table[((((int) c->imagebuffer[pos + 1 + wi])))];
	    if (gamma) {
		i = myrand();
		i1 += (i) % p->randomval - gamma;
		i2 += (i >> 8) % p->randomval - gamma;
		i3 += (i >> 16) % p->randomval - gamma;
		i4 += (i >> 24) % p->randomval - gamma;
		if ((i1 | i2 | i3 | i4) & (~255)) {
		    if (i1 < 0)
			i1 = 0;
		    else if (i1 > 255)
			i1 = 255;
		    if (i2 < 0)
			i2 = 0;
		    else if (i2 > 255)
			i2 = 255;
		    if (i3 < 0)
			i3 = 0;
		    else if (i3 > 255)
			i3 = 255;
		    if (i4 < 0)
			i4 = 0;
		    else if (i4 > 255)
			i4 = 255;
		}
	    }
	    switch (p->dither) {
	    case AA_ERRORDISTRIB:
		esum = (esum + 2) >> 2;
		i1 += esum;
		i2 += esum;
		i3 += esum;
		i4 += esum;
		break;
	    case AA_FLOYD_S:
		if (i1 | i2 | i3 | i4) {
		    errors[cur][x - 2] += esum >> 4;
		    errors[cur][x - 1] += (5 * esum) >> 4;
		    errors[cur][x] = (3 * esum) >> 4;
		    esum = (7 * esum) >> 4;
		    esum += errors[cur ^ 1][x];
		    i1 += (esum + 1) >> 2;
		    i2 += (esum) >> 2;
		    i3 += (esum + 3) >> 2;
		    i4 += (esum + 2) >> 2;
		}
		break;
	    }
	    if (p->dither) {
		esum = i1 + i2 + i3 + i4;
		val = (esum) >> 2;
		if ((abs(i1 - val) < VAL &&
		     abs(i2 - val) < VAL &&
		     abs(i3 - val) < VAL &&
		     abs(i4 - val) < VAL)) {
		    if (esum >= 4 * 256)
			val = 255, esum = 4 * 256 - 1;
		    if (val < 0)
			val = 0;
		    val = c->filltable[val];
		} else {
		    if ((i1 | i2 | i3 | i4) & (~255)) {
			if (i1 < 0)
			    i1 = 0;
			else if (i1 > 255)
			    i1 = 255;
			if (i2 < 0)
			    i2 = 0;
			else if (i2 > 255)
			    i2 = 255;
			if (i3 < 0)
			    i3 = 0;
			else if (i3 > 255)
			    i3 = 255;
			if (i4 < 0)
			    i4 = 0;
			else if (i4 > 255)
			    i4 = 255;
		    }
		    esum = i1 + i2 + i3 + i4;
		    i1 >>= 4;
		    i2 >>= 4;
		    i3 >>= 4;
		    i4 >>= 4;
		    val = c->table[pos(i2, i1, i4, i3)];
		}
		esum = (esum - (c->parameters[val].p[4]) * 1020 / mval);
	    } else {
Exemple #26
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;
}
Exemple #27
0
void tographics()
{
    backconvert(0, start, aa_scrwidth(context), aa_scrheight(context));
}