示例#1
0
void backconvert(int x1, int y1, int x2, int y2)
{
    int x, y;
    for (y = y1; y < y2; y++)
	for (x = x1; x < x2; x++) {
	    int n = context->textbuffer[x + y * aa_scrwidth(context)] + 256 * context->attrbuffer[x + y * aa_scrwidth(context)];
	    aa_putpixel(context, x * 2, y * 2, context->parameters[n].p[1]);
	    aa_putpixel(context, x * 2 + 1, y * 2, context->parameters[n].p[0]);
	    aa_putpixel(context, x * 2, y * 2 + 1, context->parameters[n].p[3]);
	    aa_putpixel(context, x * 2 + 1, y * 2 + 1, context->parameters[n].p[2]);
	}
}
示例#2
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);            
 }
示例#3
0
/*
 * Draws 8 of the points on the circle radius
 * For internal use, Use aa_drawcircle instead.
 */
void aa_plot8circlepoints(aa_context *context, int x, int y,
				int cx, int cy, int color, int fillcolor) {
	aa_putpixel(context, cx+x, cy+y, color);
	aa_putpixel(context, cx-x, cy+y, color);
	aa_putpixel(context, cx-x, cy-y, color);
	aa_putpixel(context, cx+x, cy-y, color);
	aa_putpixel(context, cx+y, cy+x, color);
	aa_putpixel(context, cx-y, cy+x, color);
	aa_putpixel(context, cx-y, cy-x, color);
	aa_putpixel(context, cx+y, cy-x, color);
	if(fillcolor != -1) {
		aa_drawline(context, cx-x+1, cy+y, cx+x-1, cy+y, fillcolor);
		aa_drawline(context, cx-x+1, cy-y, cx+x-1, cy-y, fillcolor);
		aa_drawline(context, cx-y+1, cy+x, cx+y-1, cy+x, fillcolor);
		aa_drawline(context, cx-y+1, cy-x, cx+y-1, cy-x, fillcolor);
	}
}
示例#4
0
文件: messager.c 项目: fourks/bb.js
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);
}
示例#5
0
文件: aatest.c 项目: dgeelen/tmvp
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;
}
示例#6
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;
}
status_t
AalibTranslator::DerivedTranslate(BPositionIO *source,
	const translator_info *info, BMessage *ioExtension,
	uint32 outType, BPositionIO *target, int32 baseType)
{
	if(baseType == 1 && outType == AALIB_TEXT_FORMAT) {
		BBitmap *originalbmp, *greyscalebmp;
		BRect bounds;
		
		int imgWidth;
		int imgHeight;
		int imgHalfWidth;
		int imgHalfHeight;
		aa_context *context;
		aa_renderparams *params;
		aa_palette palette;
		struct aa_hardware_params hwparams;
		
		// get the image
		originalbmp = BTranslationUtils::GetBitmap(source);
		if(originalbmp == NULL) {
			return B_ERROR;
		}
		
		// get the image size
		bounds = originalbmp->Bounds();
		imgWidth = bounds.IntegerWidth()+1;
		imgHeight = bounds.IntegerHeight()+1;
		
		// convert the bitmap to greyscale
		greyscalebmp = new BBitmap(bounds, B_GRAY8);
		if(greyscalebmp->ImportBits(originalbmp) != B_OK) {
			return B_ERROR;
		}
		
		// get half the height and width, rounded up
		//   aalib outputs half the height and width of the original
		if(imgWidth%2 == 1)
			imgHalfWidth = (imgWidth+1)/2;
		else
			imgHalfWidth = imgWidth/2;
		
		if(imgHeight%2 == 1)
			imgHalfHeight = (imgHeight+1)/2;
		else
			imgHalfHeight = imgHeight/2;
		
		// use some custom settings
		memcpy(&hwparams, &aa_defparams, sizeof(struct aa_hardware_params));
		hwparams.font = NULL; // default font
		// output is half of original width and height
		hwparams.width = imgHalfWidth;
		hwparams.height = imgHalfHeight;
		
		// new aalib context
		//   use mem_d (memory drive) as we will get the output ourselves
		context = aa_init(&mem_d, &hwparams, NULL);
		if(context == NULL)
			return B_ERROR;
		
		// we can't use memcpy, as the image width
		//   might not be equal to the bytes per row
		/*memcpy(context->imagebuffer,
				greyscalebmp->Bits(),
				imgWidth*imgHeight);*/
		
		// get the location of the bitmap bits, and the bytes per row
		unsigned char *bitsLocation = (unsigned char*)greyscalebmp->Bits();
		int bytesPerRow = greyscalebmp->BytesPerRow();
		for(int y=0; y<imgHeight; y++) { // for each row and column
			for(int x=0; x<imgWidth; x++) {
				// set the pixel
				//   255- is to invert the greyscale image
				aa_putpixel(context, x, y,
								255-(bitsLocation[y*bytesPerRow+x]));
			}
		}
		
		// render the image
		params = aa_getrenderparams();
		aa_render(context, params, 0, 0, imgWidth, imgHeight);
		
		for(int i=0; i<imgHalfHeight; i++) { // for each row
			if(i != 0) { // after first line, write newline
				target->Write("\n",1);
			}
			// output that line
			target->Write(context->textbuffer+i*imgHalfWidth,imgHalfWidth);
		}
		
		aa_close(context);
		free(originalbmp);
		delete greyscalebmp;
		delete originalbmp;
		return B_OK;
	}
	return B_NO_TRANSLATOR;
}