/**
* Finds matching node in the list referenced by <node>. Returns -1 if no matching node were found.
*	node - node to examine
*	search_str - pointer to UTF16 string
*	str_len - length (in words) of UTF16 string
*	match_count - output variable, returns number of matched characters
*	returns index of the matching node, or -1 if none can be matched
*/
int find_matching_child (Node node, uint16_t* search_str, int str_len, int& matched_count, bool normalize = false, int starting_idx = -1) {
	uint16_t* pchildren = &(node.children_names[0]);
	
	// Skip pchildren to starting idx
	for (int i = 0; i < starting_idx + 1; i++) {
		while (*pchildren++ != 0);
	}

	for (int i = starting_idx + 1, n = node.nchildren; i < n; i++) {
		// Compare
		int j;

		bool mismatch = false;
		for (j = 0; j < str_len; j++) {
			// Reached end of string
			if (pchildren[j] == 0) {
				matched_count = j;
				return i;
			}

			// Reached mismatching character
			if (normalize) {
				if ( desaturate(pchildren[j]) != desaturate(search_str[j]) ) {
					mismatch = true;
					break;
				}
			} else {
				if (pchildren[j] != search_str[j]) {
					mismatch = true;
					break;
				}
			}
		}

		// node's string longer than search string?
		if (str_len == j && pchildren[j] != 0) {
			mismatch = true;
		}

		if (mismatch) {
			// Skip to next 0
			while (*pchildren++ != 0);
			continue;
		}

		matched_count = j;
		return i;
	}
	matched_count = 0;
	return -1;
}
QPixmap ApplicationDescription::miniIcon() const
{
    QPixmap pix(m_miniIconName.c_str());
    if (!pix.isNull()) {
        return pix;
    }

    // if there is no mini-icon, we will scale and desaturate the regular app icon
    // to get one

#ifndef FIX_FOR_QT
    m_miniIconName = std::string("*default");	//invalid filename so it'll never be confused with a "real" icon file
#endif
    int miniIconSize = Settings::LunaSettings()->positiveSpaceBottomPadding;

    const LaunchPoint* lp = m_launchPoints.front();

    QImage img = QImage(qFromUtf8Stl(lp->iconPath())).scaled(miniIconSize, miniIconSize,
                 Qt::IgnoreAspectRatio,
                 Qt::SmoothTransformation);
    desaturate(img);
    pix = QPixmap::fromImage(img);

    return pix;
}
Beispiel #3
0
ttip_result_t ttip_threshold(ttip_image_t* output, ttip_image_t source, int value) {
	if (source->format != TTIP_GRAY && source->format != TTIP_RGB)
		return TTIP_BAD_PIXEL_FORMAT;

	/* allocate tile */
	int ret;
	struct ttip_image* destination;
   	if ((ret = ttip_create(&destination, source->width, source->height, TTIP_GRAY)) != TTIP_OK)
		return ret;

	/* process */
	unsigned char *srcrow, *dstrow, *src, *dst;

	if (source->format == TTIP_GRAY) {
		for (srcrow = source->data, dstrow = destination->data;
				srcrow < source->data + source->height * source->stride;
				srcrow += source->stride, dstrow += destination->stride) {
			for (src = srcrow, dst = dstrow; src < srcrow + source->width; src++, dst++) {
				dst[0] = (src[0] > value) ? 255 : 0;
			}
		}
	} else if (source->format == TTIP_RGB) {
		for (srcrow = source->data, dstrow = destination->data;
				srcrow < source->data + source->height * source->stride;
				srcrow += source->stride, dstrow += destination->stride) {
			for (src = srcrow, dst = dstrow; src < srcrow + source->width * 3; src += 3, dst++) {
				dst[0] = (desaturate(src[0], src[1], src[2]) > value) ? 255 : 0;
			}
		}
	}

	*output = destination;

	return TTIP_OK;
}
Beispiel #4
0
ttip_result_t ttip_desaturate(ttip_image_t* output, ttip_image_t source) {
	ttip_format_t dstformat;
	int srcstep, dststep;

	switch (source->format) {
	case TTIP_GRAY:
	case TTIP_GRAY_ALPHA:
		return ttip_clone(output, source);
	case TTIP_RGB:
		dstformat = TTIP_GRAY;
		srcstep = 3;
		dststep = 1;
		break;
	case TTIP_RGB_ALPHA:
		dstformat = TTIP_GRAY_ALPHA;
		srcstep = 4;
		dststep = 2;
		break;
	default:
		return TTIP_BAD_PIXEL_FORMAT;
	}

	/* allocate tile */
	int ret;
	struct ttip_image* destination;
	if ((ret = ttip_create(&destination, source->width, source->height, dstformat)) != TTIP_OK)
		return ret;

	/* process */
	unsigned char *srcrow, *dstrow, *src, *dst;
	for (srcrow = source->data, dstrow = destination->data;
			srcrow < source->data + source->height * source->stride;
			srcrow += source->stride, dstrow += destination->stride) {
		for (src = srcrow, dst = dstrow; src < srcrow + source->width * srcstep; src += srcstep, dst += dststep) {
			*dst = desaturate(src[0], src[1], src[2]);
		}
	}

	*output = destination;

	return TTIP_OK;
}
int HostRender::run(RaytracingContext& context,
                    PixelFunc const& render_pixel,
                    int kill_timeout_seconds,
                    std::function<void()> const& render_overlay)
{
    auto render_pixel_wrapper = [&](int x, int y, RaytracingContext const &ctx, ThreadLocalData *tld)
                                -> glm::vec3
    {
        RenderData data(context, tld);

        switch(context.params.render_mode) {

        case RaytracingParameters::RECURSIVE:
            if (context.params.stereo)
            {
                data.camera_mode = Camera::StereoLeft;
                auto const left = render_pixel(x, y, ctx, data);
                data.camera_mode = Camera::StereoRight;
                auto const right = render_pixel(x, y, ctx, data);
                return combine_stereo(left, right);
            }
            else
            {
                return render_pixel(x, y, ctx, data);
            }

        case RaytracingParameters::DESATURATE:
            if (context.params.stereo)
            {
                data.camera_mode = Camera::StereoLeft;
                auto const left = render_pixel(x, y, ctx, data);
                data.camera_mode = Camera::StereoRight;
                auto const right = render_pixel(x, y, ctx, data);
                return combine_stereo(desaturate(left), desaturate(right));
            }
            else
            {
                return desaturate(render_pixel(x, y, ctx, data));
            }

        case RaytracingParameters::NUM_RAYS:
            render_pixel(x, y, ctx, data);
            return heatmap(float(data.num_cast_rays - 1) / 64.0f);
        case RaytracingParameters::NORMAL:
            render_pixel(x, y, ctx, data);
            return glm::normalize(data.isect.normal) * 0.5f + glm::vec3(0.5f);
        case RaytracingParameters::TIME: {
            Timer timer;
            timer.start();
            if(context.params.render_mode == RaytracingParameters::TIME) {
                auto const color = render_pixel(x, y, ctx, data);
                (void) color;
            }
            timer.stop();
            return heatmap(static_cast<float>(timer.getElapsedTimeInMilliSec()) * context.params.scale_render_time);
        }
        default: /* should never happen */
            return glm::vec3(1, 0, 1);
        }
    };

    if (context.params.interactive)
    {
        return run_interactive(context, render_pixel_wrapper, render_overlay);
    }
    else
    {
        return run_noninteractive(context, render_pixel_wrapper,
                                  kill_timeout_seconds);
    }
}
int HostRender::run(RaytracingContext& context, 
			   PixelFunc const& render_pixel, 
			   int kill_timeout_seconds,
			   std::function<void()> const& render_overlay)
{
	auto render_pixel_wrapper = [&](int x, int y, RaytracingContext const &ctx, ThreadLocalData *tld)
		-> glm::vec3
	{
		RenderData data(context, tld);

		switch(context.params.render_mode) {

		case RaytracingParameters::RECURSIVE:
			if (context.params.stereo)
			{
				data.camera_mode = Camera::StereoLeft;
				auto const left = render_pixel(x, y, ctx, data);
				data.camera_mode = Camera::StereoRight;
				auto const right = render_pixel(x, y, ctx, data);
				return combine_stereo(left, right);
			}
			else
			{
				return render_pixel(x, y, ctx, data);
			}

		case RaytracingParameters::DESATURATE:
			if (context.params.stereo)
			{
				data.camera_mode = Camera::StereoLeft;
				auto const left = render_pixel(x, y, ctx, data);
				data.camera_mode = Camera::StereoRight;
				auto const right = render_pixel(x, y, ctx, data);
				return combine_stereo(desaturate(left), desaturate(right));
			}
			else
			{
				return desaturate(render_pixel(x, y, ctx, data));
			}

		case RaytracingParameters::NUM_RAYS:
			render_pixel(x, y, ctx, data);
			return heatmap(float(data.num_cast_rays - 1) / 64.0f);
		case RaytracingParameters::NORMAL:
			render_pixel(x, y, ctx, data);
			if (context.params.normal_mapping)
				return glm::normalize(data.isect.shading_normal) * 0.5f + glm::vec3(0.5f);
			else
				return glm::normalize(data.isect.normal) * 0.5f + glm::vec3(0.5f);
		case RaytracingParameters::BVH_TIME:
		case RaytracingParameters::TIME: {
			Timer timer;
			timer.start();
			if(context.params.render_mode == RaytracingParameters::TIME) {
				auto const color = render_pixel(x, y, ctx, data);
				(void) color;
			}
			else {
				Ray ray = createPrimaryRay(data, float(x) + 0.5f, float(y) + 0.5f);
				for(auto& o: context.scene->objects) {
					BVH *bvh = dynamic_cast<BVH *>(o.get());
					if(bvh) {
						bvh->intersect(ray, nullptr);
					}
				}
			}
			timer.stop();
			return heatmap(static_cast<float>(timer.getElapsedTimeInMilliSec()) * context.params.scale_render_time);
		}
		case RaytracingParameters::DUDV: {
			auto const color = render_pixel(x, y, ctx, data);
			(void) color;
			if(!data.isect.isValid())
				return glm::vec3(0.0);
			return heatmap(std::log(1.0f + 5.0f * glm::length(data.isect.dudv)));
		}
		case RaytracingParameters::AABB_INTERSECT_COUNT: {
        	Ray ray = createPrimaryRay(data, float(x) + 0.5f, float(y) + 0.5f);
			glm::vec3 accum(0.0f);
			for(auto& o: context.scene->objects) {
				auto *bvh = dynamic_cast<BVH *>(o.get());
				if(bvh) {
					accum += bvh->intersect_count(ray, 0, 0) * 0.02f;
				}
			}
			return accum;
		}
		default: /* should never happen */
			return glm::vec3(1, 0, 1);
		}
	};

	if (context.params.interactive)
	{
		return run_interactive(context, render_pixel_wrapper, render_overlay);
	}
	else
	{
		return run_noninteractive(context, render_pixel_wrapper, 
			kill_timeout_seconds);
	}
}
Beispiel #7
0
int main(int argc,char *argv[]) {

    png::rgb_pixel black = png::rgb_pixel(0,0,0);

    //default resolution
    int xres=1920;
    int yres=1080;
    //default size of the pixel
    int pixsize=10;
    // 0 - Original colors, 100 - Complete desaturation
    int saturation=0;
    //Color multiplier value
    int colormult=1;
    //seed
    int seed=time(NULL);

    //if wallstrue equals zero then there will be no walls, else there will be walls
    int wallstrue=1;
    char * name="maze.png";
    //true if user picks the colors
    bool setColor=false;
    std::string userColor;

    for (int i=1;i<argc;i++)
    {
	std::string flag=argv[i];
	if (flag=="-w"||flag=="--width")
	    xres=std::stoi(argv[i+1]);
	if (flag=="-h"||flag=="--height")
	    yres=std::stoi(argv[i+1]);
	if (flag=="-p"||flag=="--pixel-size")
	    pixsize=std::stoi(argv[i+1]);
	if (flag=="-b"||flag=="--walls")
	    wallstrue=std::stoi(argv[i+1]);
	if (flag=="-n"||flag=="--file-name")
	    name=argv[i+1];
	if (flag=="-d"||flag=="--desaturation")
	    saturation=std::stoi(argv[i+1]);
	if (flag=="-t"||flag=="--color-multiplier")
	    colormult=std::stoi(argv[i+1]);
	if (flag=="-s"||flag=="--seed")
	    seed=std::stoi(argv[i+1]);
	if (flag=="-c"||flag=="--set-color")
	    {
		setColor=true;
		userColor=argv[i+1];
	    }


    }

    //ignores drawing walls if pixel size is 1
    if (pixsize==1)
	wallstrue=0;

    Draw xwin(pixsize,xres,yres);

    int xblocks=xwin.screenwidth/xwin.pixwidth-1;
    int yblocks=xwin.screenheight/xwin.pixwidth-1;

    Maze maze(xblocks,yblocks);

    maze.startCreation(seed);

    maze.nextStep();

    int colors[6];

    if (setColor==false)
    {

    for (int i=0;i<6;i++) {
	colors[i]=rand()%256;
    }

    double distance =sqrt(  pow((colors[0]-colors[3]),2) + pow((colors[1]-colors[4]),2) + pow((colors[3]-colors[5]),2));

    while (distance<200|distance>300) {
	for (int i=0;i<6;i++)
	    colors[i]=rand()%256;
	distance =sqrt(  pow((colors[0]-colors[3]),2) + pow((colors[1]-colors[4]),2) + pow((colors[3]-colors[5]),2));
    }

    desaturate(saturation / 100.0, &colors[0], &colors[1], &colors[2]);
    desaturate(saturation / 100.0, &colors[3], &colors[4], &colors[5]);

    }
    else
    {
	for (int i=0;i<12;i+=2)
	{
	    unsigned int col;
	    std::stringstream ss;
	    ss << std::hex << std::string(userColor.begin()+i,userColor.begin()+i+2);
	    ss >> col;
	    colors[i/2]=col;
	}
	
    }

    maze.drawValues(&xwin,colors[0],colors[1],colors[2],colors[3],colors[4],colors[5],colormult);

    if (wallstrue!=0) {
	//horizontal
	drawWall(maze.wall.horwalls,maze.wall.width,maze.wall.height,&xwin,black,1.0,1.0/2.0,0);
	//verticle
	drawWall(maze.wall.vertwalls,maze.wall.width+1,maze.wall.height-1,&xwin,black,1.0/2.0,1.0,1);

    }

    xwin.writePng(name);

    return 0;
}
Beispiel #8
0
void flowField(Field &field, ofImage &edges, ofPixels pix)
{
    desaturate(pix);
    blur(pix);
    sobel(field, edges, pix);
}