示例#1
0
文件: window.cpp 项目: bhelyer/Yume
	YUMEALIGN16 void window::draw_triangle(const triangle& src) {
		triangle t = src;
		t.points[0] = translate(t.points[0]);
		t.points[1] = translate(t.points[1]);
		t.points[2] = translate(t.points[2]);
		std::sort(t.points.begin(), t.points.end(), ysort);

		float dP1P2 = 0.0f, dP1P3 = 0.0f;  // Inverse slopes.
		if (t.points[1].y() - t.points[0].y() > 0.0f)
			dP1P2 = (t.points[1].x() - t.points[0].x()) / (t.points[1].y() - t.points[0].y());
		if (t.points[2].y() - t.points[0].y() > 0.0f)
			dP1P3 = (t.points[2].x() - t.points[0].x()) / (t.points[2].y() - t.points[0].y());

		if (dP1P2 > dP1P3) {
			for (auto y = static_cast<int>(t.points[0].y()); y <= static_cast<int>(t.points[2].y()); ++y) {
				if (y < t.points[1].y()) {
					process_scanline(y, t.points[0], t.points[2], t.points[0], t.points[1]);
				} else {
					process_scanline(y, t.points[0], t.points[2], t.points[1], t.points[2]);
				}
			}
		} else {
			for (auto y = static_cast<int>(t.points[0].y()); y <= static_cast<int>(t.points[2].y()); ++y) {
				if (y < t.points[1].y()) {
					process_scanline(y, t.points[0], t.points[1], t.points[0], t.points[2]);
				} else {
					process_scanline(y, t.points[1], t.points[2], t.points[0], t.points[2]);
				}
			}
		}
	}
示例#2
0
/*
 * Collects extents from all scanlines in a frame and stores them in
 * the extent_line array el.
 */
static void process_frame(uint8_t *lines, int width, int height,
			  struct extent_line *el, struct blobservation *ob)
{
	struct extent_line *last_el;
	int index = 0;
	int y;

	ob->num_blobs = 0;

	index = process_scanline(lines, width, height, 0, el, NULL, 0, ob);

	for (y = 1; y < height; y++) {
		last_el = el++;
		lines += width;
		index = process_scanline(lines, width, height, y, el, last_el,
					 index, ob);
	}

	ob->num_blobs = min(MAX_BLOBS_PER_FRAME, index);
}
示例#3
0
文件: image.c 项目: cslarsen/jp2a
void decompress(FILE *fp, FILE *fout) {
	int row_stride;
	struct jpeg_error_mgr jerr;
	struct jpeg_decompress_struct jpg;
	JSAMPARRAY buffer;
	Image image;

	jpg.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&jpg);
	jpeg_stdio_src(&jpg, fp);
	jpeg_read_header(&jpg, TRUE);
	jpeg_start_decompress(&jpg);

	if ( jpg.data_precision != 8 ) {
		fprintf(stderr,
			"Image has %d bits color channels, we only support 8-bit.\n",
			jpg.data_precision);
		exit(1);
	}

	row_stride = jpg.output_width * jpg.output_components;

	buffer = (*jpg.mem->alloc_sarray)((j_common_ptr) &jpg, JPOOL_IMAGE, row_stride, 1);

	aspect_ratio(jpg.output_width, jpg.output_height);

	malloc_image(&image);
	clear(&image);

	if ( verbose ) print_info(&jpg);

	init_image(&image, &jpg);

	while ( jpg.output_scanline < jpg.output_height ) {
		jpeg_read_scanlines(&jpg, buffer, 1);
		process_scanline(&jpg, buffer[0], &image);
		if ( verbose ) print_progress(&jpg);
	}

	if ( verbose ) {
		fprintf(stderr, "\n");
		fflush(stderr);
	}

	normalize(&image);

	if ( clearscr ) {
		fprintf(fout, "%c[2J", 27); // ansi code for clear
		fprintf(fout, "%c[0;0H", 27); // move to upper left
	}

	if ( html && !html_rawoutput ) print_html_start(html_fontsize, fout);
	if ( use_border ) print_border(image.width);

	(!usecolors? print_image : print_image_colors) (&image, (int) strlen(ascii_palette) - 1, fout);

	if ( use_border ) print_border(image.width);
	if ( html && !html_rawoutput ) print_html_end(fout);

	free_image(&image);

	jpeg_finish_decompress(&jpg);
	jpeg_destroy_decompress(&jpg);
}