示例#1
0
void ppm_export(const image& r, const image& g, const image& b, const boost::filesystem::path& path)
{
  if(exists(path))
  {
    std::cerr << "Error exporting to PPM! File "
	      << path << " already exists." << std::endl;
    exit(1);
  }

  boost::filesystem::ofstream ppm(path);

  ppm << "P3\n"
      << r.width() << ' ' << r.height() << '\n'
      << 255 << '\n';

  for(int y = 0; y < r.height(); ++y)
  {
    for(int x = 0; x < r.width(); ++x){
      ppm << static_cast<int>(r.pixel(x, y)) << ' ';
      ppm << static_cast<int>(g.pixel(x, y)) << ' ';
      ppm << static_cast<int>(b.pixel(x, y)) << ' ';
    }
    ppm << '\n';
  }
}
示例#2
0
 void save_ppm(char const* filename) const
 {
     std::ofstream ppm(filename);
     ppm << "P6" << std::endl;
     ppm << width << std::endl << height << std::endl << 255 << std::endl;
     ppm.write((char const*)&*pixels.begin(),width*height*3);
     ppm.close();
 }
void
elfmain(
	ZoogDispatchTable_v1 *zdt,
	uint32_t elfbase,
	uint32_t rel_offset,
	uint32_t rel_count)
{
	relocate_this(elfbase, rel_offset, rel_count);

	PerfMeasure pm(zdt);
	pm.mark_time("start");

	ZoogMallocFactory zmf;
	zoog_malloc_factory_init(&zmf, zdt);
	ambient_malloc_init(zmf_get_mf(&zmf));

	debug_create_toplevel_window_f* dctw = (debug_create_toplevel_window_f*)
		(zdt->zoog_lookup_extension)(DEBUG_CREATE_TOPLEVEL_WINDOW_NAME);

//	pm.mark_time("a");
	ZCertChain *zcc = new ZCertChain((uint8_t*) vendor_a_chain, sizeof(vendor_a_chain));
	(zdt->zoog_verify_label)(zcc);
//	pm.mark_time("verify");

	ViewportID viewport = (dctw)();

	PixelFormat pf[1] = {zoog_pixel_format_truecolor24};
	ZCanvas canvas;
	(zdt->zoog_map_canvas)(viewport, pf, 1, &canvas);
	
//	pm.mark_time("g");
	TinyPPM ppm(splash_image);
//	pm.mark_time("parse_splash");
	ppm.paint_on(&canvas);
//	pm.mark_time("paint");
	ZRectangle zr = NewZRectangle(0, 0, canvas.width, canvas.height);
	(zdt->zoog_update_canvas)(canvas.canvas_id, &zr);

	pm.mark_time("done");

	uint32_t stall_zutex = 0;
	ZutexWaitSpec spec = { &stall_zutex, 0 };
	while (true)
	{
		(zdt->zoog_zutex_wait)(&spec, 1);
	}
}
示例#4
0
void QDeclarativeTextPrivate::drawOutline(int yOffset)
{
    QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2);
    img.fill(Qt::transparent);

    QPainter ppm(&img);

    QPoint pos(imgCache.rect().topLeft());
    pos += QPoint(0, yOffset);
    ppm.drawPixmap(pos, imgStyleCache);

    pos += QPoint(0, -yOffset);
    ppm.drawPixmap(pos, imgCache);
    ppm.end();

    imgCache = img;
}
示例#5
0
void SettingsButton::paintEvent(QPaintEvent *event)
{
	QPushButton::paintEvent(event);
	QStyleOptionButton option;
	option.initFrom(this);
	QRect r = this->rect();

	// Prepare miage in pixmap using mask
	QPixmap pm(r.size());
	pm.fill(Qt::transparent);
	pm.fill(option.palette.windowText().color());
	QIcon w(":cogwheel");
	QPainter ppm(&pm);
	ppm.setCompositionMode(QPainter::CompositionMode_DestinationIn);
	ppm.drawPixmap(0,0,w.pixmap(r.size()));

	// Draw pixmap on button
	QPainter p(this);
	p.setRenderHint(QPainter::Antialiasing, true);
	p.drawPixmap(0,0,pm);
}
示例#6
0
std::string special_effect_t::to_string() const
{
  std::ostringstream s;

  s << name();
  s << " type=" << util::special_effect_string( type );
  s << " source=" << util::special_effect_source_string( source );

  if ( ! trigger_str.empty() )
    s << " proc=" << trigger_str;

  if ( spell_id > 0 )
    s << " driver=" << spell_id;

  if ( trigger() -> ok() )
    s << " trigger=" << trigger() -> id();

  if ( is_stat_buff() )
  {
    s << " stat=" << util::stat_type_abbrev( stat );
    s << " amount=" << stat_amount;
    s << " duration=" << duration().total_seconds();
    if ( tick_time() != timespan_t::zero() )
      s << " tick=" << tick_time().total_seconds();
    if ( reverse )
      s << " Reverse";
  }

  if ( school != SCHOOL_NONE )
  {
    s << " school=" << util::school_type_string( school );
    s << " amount=" << discharge_amount;
    if ( discharge_scaling > 0 )
      s << " coeff=" << discharge_scaling;
  }

  if ( max_stacks > 0 )
    s << " max_stack=" << max_stacks;

  if ( proc_chance() > 0 )
    s << " proc_chance=" << proc_chance() * 100.0 << "%";

  if ( ppm() > 0 )
    s << " ppm=" << ppm();

  if ( rppm() > 0 )
  {
    s << " rppm=" << rppm();
    switch ( rppm_scale )
    {
      case RPPM_HASTE:
        s << " (Haste)";
        break;
      case RPPM_ATTACK_CRIT:
        s << " (AttackCrit)";
        break;
      case RPPM_SPELL_CRIT:
        s << " (SpellCrit)";
        break;
      default:
        break;
    }
  }

  if ( cooldown() > timespan_t::zero() )
  {
    if ( type == SPECIAL_EFFECT_EQUIP )
      s << " icd=";
    else if ( type == SPECIAL_EFFECT_USE )
      s << " cd=";
    else
      s << " (i)cd=";
    s << cooldown().total_seconds();
  }

  if ( weapon_proc )
    s << " weaponproc";

  return s.str();
}
示例#7
0
int
main (int argc, char **argv)
{
	char *endptr;
	int opt, packetsize, ip_int, coarse_ip, normal_ip, big_ip, ib;
	int il_normal, il_big;
	int bufsize, buffers;
	double bitrate, ip, ip_frac, ft_jitter, il_jitter;
	double testrate, tolerance;

	tolerance = 0;
	while ((opt = getopt (argc, argv, "ht:V")) != -1) {
		switch (opt) {
		case 'h':
			printf ("Usage: %s [OPTION]... BITRATE PACKETSIZE\n",
				argv[0]);
			printf ("Calculate DVB ASI stuffing parameters "
				"for a given BITRATE and PACKETSIZE.\n\n");
			printf ("  -h\t\tdisplay this help and exit\n");
			printf ("  -t TOLERANCE\tstop optimizing the bitrate "
				"at an error of\n"
				"\t\tTOLERANCE parts per million "
				"(default 0)\n");
			printf ("  -V\t\toutput version information "
				"and exit\n\n");
			printf ("Report bugs to <*****@*****.**>.\n");
			return 0;
		case 't':
			tolerance = strtod (optarg, &endptr);
			if (*endptr != '\0' || tolerance > 30) {
				fprintf (stderr,
					"%s: invalid bitrate tolerance: %s\n",
					argv[0], optarg);
				return -1;
			}
			break;
		case 'V':
			printf ("%s from master-%s (%s)\n", progname,
				MASTER_DRIVER_VERSION,
				MASTER_DRIVER_DATE);
			printf ("\nCopyright (C) 2000-2004 "
				"Linear Systems Ltd.\n"
				"This is free software; "
				"see the source for copying conditions.  "
				"There is NO\n"
				"warranty; not even for MERCHANTABILITY "
				"or FITNESS FOR A PARTICULAR PURPOSE.\n");
			return 0;
		case '?':
			goto USAGE;
		}
	}

	/* Check the number of arguments */
	if ((argc - optind) < 2) {
		fprintf (stderr, "%s: missing arguments\n", argv[0]);
		goto USAGE;
	} else if ((argc - optind) > 2) {
		fprintf (stderr, "%s: extra operand\n", argv[0]);
		goto USAGE;
	}

	/* Read the packet size */
	packetsize = strtol (argv[optind + 1], &endptr, 0);
	if ((*endptr != '\0') ||
		((packetsize != 188) && (packetsize != 204))) {
		fprintf (stderr, "%s: invalid packet size: %s\n",
			argv[0], argv[optind + 1]);
		return -1;
	}

	/* Read the bitrate */
	bitrate = strtod (argv[optind], &endptr);
	if ((*endptr != '\0') || (bitrate > br (packetsize, 0, 1, 0)) ||
		(bitrate < br (packetsize, 16777215, 1, 255))) {
		fprintf (stderr, "%s: invalid bitrate: %s\n",
			argv[0], argv[optind]);
		return -1;
	}

	/* Assume no interbyte stuffing.
	 * This will allow bitrates down to about 2400 bps,
	 * which is probably good enough! */
	ip = 270000000 * 0.8 * packetsize / bitrate - packetsize - 2;
	printf ("\n%f bytes of stuffing required per packet.\n", ip);
	ip_int = ip;
	ip_frac = ip - ip_int;
	if (ip_frac > 0.5) {
		coarse_ip = ip_int + 1;
	} else {
		coarse_ip = ip_int;
	}
	testrate = br (packetsize, coarse_ip, 1, 0);
	printf ("ib = 0, ip = %i  =>  bitrate = %f bps, err = %.0f ppm\n",
		coarse_ip, testrate, ppm (testrate, bitrate));
	normal_ip = 0;
	big_ip = 0;
	il_normal = 0;
	il_big = 0;
	if ((ip_frac > (double)1 / 256 / 2) &&
		(ip_frac < (1 - (double)1 / 256 / 2)) &&
		(fabs (ppm (testrate, bitrate)) > tolerance)) {
		int n = 1, b = 1, il0, il1, il_normal_max, il_big_max;
		double best_error = 1.0, error, jit = 0.1;

		/* Find the finetuning parameters which
		 * best approximate the desired bitrate.
		 * Break at 1 us p-p network jitter or
		 * the desired bitrate accuracy, whichever
		 * gives less network jitter */
		printf ("\nFinetuning ib = 0, ip = %i:\n", ip_int);
		while ((b < 256) && (n < 256) &&
			(((double)(n * b) / (n + b)) <= 27)) {
			error = (double)b / (n + b) - ip_frac;
			if (fabs (error) < fabs (best_error)) {
				best_error = error;
				normal_ip = n;
				big_ip = b;
				testrate = br (packetsize, ip_int, n, b);
				printf ("normal_ip = %i, big_ip = %i"
					"  =>  bitrate = %f bps, "
					"err = %.0f ppm\n",
					n, b,
					testrate, ppm (testrate, bitrate));
				if (fabs (ppm (testrate, bitrate)) < tolerance) {
					break;
				}
			}
			if (error < 0) {
				b++;
			} else {
				n++;
			}
		}

		/* Calculate the network jitter produced by finetuning */
		ft_jitter = jitter (normal_ip, big_ip,
			normal_ip, big_ip,
			(double)big_ip / (normal_ip + big_ip));

		/* Find the interleaving parameters which
		 * produce the least network jitter */
		if ((normal_ip == 1) || (big_ip == 1)) {
			il_jitter = jitter (normal_ip, big_ip,
				normal_ip, big_ip,
				(double)big_ip / (normal_ip + big_ip));
		} else {
			il_jitter = 0.1;
			il_normal_max = (normal_ip > 14) ? 14 : normal_ip;
			for (il0 = 1; il0 <= il_normal_max; il0++) {
				il_big_max = (big_ip > 14) ? 14 : big_ip;
				il1 = 1;
				while ((il1 <= il_big_max) &&
					(il0 + il1 <= 15)) {
					jit = jitter (normal_ip, big_ip,
						il0, il1,
						(double)big_ip / (normal_ip + big_ip));
					if (jit < il_jitter) {
						il_jitter = jit;
						il_normal = il0;
						il_big = il1;
					}
					il1++;
				}
			}
		}
	} else {
		ip_int = coarse_ip;
		ft_jitter = 0;
		il_jitter = 0;
	}

	/* Print the best stuffing parameters
	 * for transmitters with interleaved finetuning */
	printf ("\nRecommended stuffing parameters with "
		"interleaved finetuning:\n");
	printf ("ib = 0, ip = %i, normal_ip = %i, big_ip = %i,\n"
		"\til_normal = %i, il_big = %i (burst mode) OR\n",
		ip_int, normal_ip, big_ip, il_normal, il_big);
	ib = ip_int / (packetsize - 1);
	while ((ib - smooth_ip (ip_int, ib, packetsize)) >
		(packetsize + 2) / 2) {
		ib--;
	}
	if (ib > 255) {
		if (ib > 65535) {
			ib = 65535;
		}
		printf ("ib = %i, ip = %i, normal_ip = %i, big_ip = %i,\n"
			"\til_normal = %i, il_big = %i (large ib) OR\n",
			ib, smooth_ip (ip_int, ib, packetsize),
			normal_ip, big_ip, il_normal, il_big);
		ib = 255;
	}
	printf ("ib = %i, ip = %i, normal_ip = %i, big_ip = %i,\n"
		"\til_normal = %i, il_big = %i\n",
		ib, smooth_ip (ip_int, ib, packetsize),
		normal_ip, big_ip, il_normal, il_big);
	testrate = br (packetsize, ip_int, normal_ip, big_ip);
	printf ("Bitrate = %f bps; "
		"err = %.0f ppm, network jitter = %.0f ns p-p\n",
		testrate, ppm (testrate, bitrate), il_jitter * 1E+09);

	/* Print the best stuffing parameters
	 * for transmitters with ordinary finetuning */
	printf ("\nRecommended stuffing parameters with finetuning:\n");
	printf ("ib = 0, ip = %i, "
		"normal_ip = %i, big_ip = %i (burst mode) OR\n",
		ip_int, normal_ip, big_ip);
	ib = ip_int / (packetsize - 1);
	while ((ib - smooth_ip (ip_int, ib, packetsize)) >
		(packetsize + 2) / 2) {
		ib--;
	}
	if (ib > 255) {
		if (ib > 65535) {
			ib = 65535;
		}
		printf ("ib = %i, ip = %i, "
			"normal_ip = %i, big_ip = %i (large ib) OR\n",
			ib, smooth_ip (ip_int, ib, packetsize),
			normal_ip, big_ip);
		ib = 255;
	}
	printf ("ib = %i, ip = %i, normal_ip = %i, big_ip = %i\n",
		ib, smooth_ip (ip_int, ib, packetsize),
		normal_ip, big_ip);
	testrate = br (packetsize, ip_int, normal_ip, big_ip);
	printf ("Bitrate = %f bps; "
		"err = %.0f ppm, network jitter = %.0f ns p-p\n",
		testrate, ppm (testrate, bitrate), ft_jitter * 1E+09);

	/* Print the best stuffing parameters
	 * for transmitters without finetuning */
	printf ("\nRecommended stuffing parameters without finetuning:\n");
	printf ("ib = 0, ip = %i (burst mode) OR\n", coarse_ip);
	ib = coarse_ip / (packetsize - 1);
	while ((ib - smooth_ip (coarse_ip, ib, packetsize)) >
		(packetsize + 2) / 2) {
		ib--;
	}
	if (ib > 255) {
		ib = 255;
	}
	printf ("ib = %i, ip = %i\n",
		ib, smooth_ip (coarse_ip, ib, packetsize));
	testrate = br (packetsize, coarse_ip, 1, 0);
	printf ("Bitrate = %f bps; err = %.0f ppm, network jitter = 0 ns p-p\n",
		testrate, ppm (testrate, bitrate));

	/* Print a sample calculation of the interrupt rate and buffer time
	 * based on a reasonable number and size of driver buffers
	 * and the bitrate */
	bufsize = bitrate / (8 * 500);
	if (bufsize < 4) {
		bufsize = 4;
	}
	bufsize = (bufsize / 19176 + ((bufsize % 19176) ? 1 : 0)) * 19176;
	buffers = bitrate * 0.25 / (8 * bufsize);
	if (buffers < 2) {
		buffers = 2;
	}
	printf ("\nSample buffer parameter calculation:\n");
	printf ("At %f bps, %i x %i-byte buffers gives\n",
		bitrate, buffers, bufsize);
	printf ("%.0f interrupt(s) per second "
		"and up to %.3f seconds of buffering.\n",
		bitrate / (8 * bufsize), 8 * buffers * bufsize / bitrate);
	return 0;

USAGE:
	fprintf (stderr, "Try '%s -h' for more information.\n", argv[0]);
	return -1;
}