예제 #1
0
int main(void)
{
	int i;
	map *m;
	int lastcap;
	stats s;
	stat_list *l1, *l2;
	stat_list_iterator iter;
	double _max_load[] = {0.2, 0.3, 0.5, 0.7, 0.85, 1.0, 1.15, 1.3, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 6.0, 9.0, 12.0, 15.0, 20.0, 0.0};
	double *max_load = _max_load;

	l1 = stat_list_new();
	l2 = stat_list_new();
	while (*max_load > 0) {
		m = map_new();
		m->max_load = *max_load;
		++max_load;
		lastcap = m->cap;
		s = map_stats(m);
		srand(0);
		for (i=0; i<=N; ++i) {
			while (m->cap == lastcap) {
				if ((m->len+1.0)/m->cap > m->max_load) {
					s = map_stats(m);
				}
				map_set(m, randt(), randt());
			}
			lastcap = m->cap;
		}
		stat_list_insert(l1, s, -1);
		stat_list_insert(l2, map_stats(m), -1);
		map_free(m);
	}

	print_header();
	print_hr();
	for (iter=stat_list_iterate(l1); stat_list_next(l1, &iter); ) {
		print_stats(stat_list_get_at(l1, iter));
	}
	print_hr();
	print_header();
	print_hr();
	for (iter=stat_list_iterate(l2); stat_list_next(l2, &iter); ) {
		print_stats(stat_list_get_at(l2, iter));
	}

	stat_list_free(l1);
	stat_list_free(l2);

	return 0;
}
예제 #2
0
void KisFilterNoise::processImpl(KisPaintDeviceSP device,
                                 const QRect& applyRect,
                                 const KisFilterConfiguration* config,
                                 KoUpdater* progressUpdater
                                ) const
{
    Q_ASSERT(!device.isNull());

    if (progressUpdater) {
        progressUpdater->setRange(0, applyRect.width() * applyRect.height());
    }
    int count = 0;

    const KoColorSpace * cs = device->colorSpace();

    QVariant value;
    int level = (config && config->getProperty("level", value)) ? value.toInt() : 50;
    int opacity = (config && config->getProperty("opacity", value)) ? value.toInt() : 100;

    KisSequentialIterator it(device, applyRect);

    quint8* interm = new quint8[cs->pixelSize()];
    double threshold = (100.0 - level) * 0.01;

    qint16 weights[2];
    weights[0] = (255 * opacity) / 100;
    weights[1] = 255 - weights[0];

    const quint8* pixels[2];
    pixels[0] = interm;

    KoMixColorsOp * mixOp = cs->mixColorsOp();

    int seedThreshold = rand();
    int seedRed = rand();
    int seedGreen = rand();
    int seedBlue = rand();

    if (config) {
        seedThreshold = config->getInt("seedThreshold", seedThreshold);
        seedRed = config->getInt("seedRed", seedRed);
        seedGreen = config->getInt("seedGreen", seedGreen);
        seedBlue = config->getInt("seedBlue", seedBlue);
    }

    KisRandomGenerator randt(seedThreshold);
    KisRandomGenerator randr(seedRed);
    KisRandomGenerator randg(seedGreen);
    KisRandomGenerator randb(seedBlue);

    do {
        if (randt.doubleRandomAt(it.x(), it.y()) > threshold) {
            // XXX: Added static_cast to get rid of warnings
            QColor c = qRgb(static_cast<int>((double)randr.doubleRandomAt(it.x(), it.y()) * 255),
                            static_cast<int>((double)randg.doubleRandomAt(it.x(), it.y()) * 255),
                            static_cast<int>((double)randb.doubleRandomAt(it.x(), it.y()) * 255));
            cs->fromQColor(c, interm, 0);
            pixels[1] = it.oldRawData();
            mixOp->mixColors(pixels, weights, 2, it.rawData());
        }
        if (progressUpdater) progressUpdater->setValue(++count);
    } while (it.nextPixel() && !(progressUpdater && progressUpdater->interrupted()));

    delete [] interm;
}