Example #1
0
bool DisplayImage::show(Image image) {
  SDL_LockSurface(screen_);

  u8* screen_ptr = (u8*)screen_->pixels;
  u8* image_ptr(&image.image_data[0]);

  for (u32 y(0); y < image.h; ++y) {
    for (u32 x(0); x < image.w; ++x) {

      u8 r(*image_ptr++);
      u8 g(*image_ptr++);
      u8 b(*image_ptr++);

      screen_ptr[x * 3 + 0 + y * screen_->pitch] = b;
      screen_ptr[x * 3 + 1 + y * screen_->pitch] = g;
      screen_ptr[x * 3 + 2 + y * screen_->pitch] = r;
    }
  }

  SDL_UnlockSurface(screen_);
  SDL_Flip(screen_);

  SDL_Event event;
  if (SDL_PollEvent(&event)) {
    switch (event.type) {
    case SDL_QUIT:
      return false;
    }
  }
  return true;
}
void DoMode4(const std::vector<Image16Bpp>& images)
{
    // Set Mode
    header.SetMode(4);
    implementation.SetMode(4);

    // Do the work of mode 4 conversion.
    // If split then get vector of 8 bit images
    // If !split then cause a scene.
    // Add appropriate object to header/implementation.
    if (params.split)
    {
        bool first = true;
        for (const auto& image : images)
        {
            std::shared_ptr<Image8Bpp> image_ptr(new Image8Bpp(image));
            header.AddImage(image_ptr);
            implementation.AddImage(image_ptr);
            if (first)
            {
                header.SetPalette(image_ptr->palette);
                implementation.SetPalette(image_ptr->palette);
            }
        }
    }
    else
    {
        std::shared_ptr<Image8BppScene> scene(new Image8BppScene(images, params.symbol_base_name));
        header.SetPalette(scene->palette);
        implementation.SetPalette(scene->palette);
        header.AddScene(scene);
        implementation.AddScene(scene);
    }
}
Example #3
0
void DoMode3Export(const std::vector<Image16Bpp>& images)
{
    for (const auto& image : images)
    {
        std::shared_ptr<Exportable> image_ptr(new Image16Bpp(image));
        header.Add(image_ptr);
        implementation.Add(image_ptr);
    }
}
 static std::shared_ptr<image_t> mat_to_image(cv::Mat img_src)
 {
     cv::Mat img;
     cv::cvtColor(img_src, img, cv::COLOR_RGB2BGR);
     std::shared_ptr<image_t> image_ptr(new image_t, [](image_t *img) { free_image(*img); delete img; });
     std::shared_ptr<IplImage> ipl_small = std::make_shared<IplImage>(img);
     *image_ptr = ipl_to_image(ipl_small.get());
     return image_ptr;
 }
void Do3DSExport(const std::vector<Image32Bpp>& images, const std::vector<Image32Bpp>& tilesets)
{
    // Add images to header and implementation files
    for (const auto& image : images)
    {
        std::shared_ptr<Exportable> image_ptr(new Image32Bpp(image));
        header.Add(image_ptr);
        implementation.Add(image_ptr);
    }
}
Example #6
0
void DoMode4Export(const std::vector<Image16Bpp>& images, const std::shared_ptr<Palette>& palette)
{
    // If split then get vector of 8 bit images
    // If !split then cause a scene.
    // Add appropriate object to header/implementation.
    if (params.split)
    {
        for (const auto& image : images)
        {
            std::shared_ptr<Exportable> image_ptr(new Image8Bpp(image, palette));
            header.Add(image_ptr);
            implementation.Add(image_ptr);
        }
    }
    else
    {
        std::shared_ptr<Exportable> scene(new Image8BppScene(images, params.symbol_base_name, palette));
        header.Add(scene);
        implementation.Add(scene);
    }
}
Example #7
0
Handle<Value> Image::open(const Arguments& args)
{
    HandleScope scope;

    if (!args[0]->IsString()) {
        return ThrowException(Exception::TypeError(String::New(
                                                       "Argument must be a string")));
    }

    try {
        std::string filename = TOSTR(args[0]);
        boost::optional<std::string> type = mapnik::type_from_filename(filename);
        if (type)
        {
            std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,*type));
            if (reader.get())
            {
                boost::shared_ptr<mapnik::image_32> image_ptr(new mapnik::image_32(reader->width(),reader->height()));
                reader->read(0,0,image_ptr->data());
                Image* im = new Image(image_ptr);
                Handle<Value> ext = External::New(im);
                Handle<Object> obj = constructor->GetFunction()->NewInstance(1, &ext);
                return scope.Close(obj);
            }
            return ThrowException(Exception::TypeError(String::New(
                                                           ("Failed to load: " + filename).c_str())));
        }
        return ThrowException(Exception::TypeError(String::New(
                                                       ("Unsupported image format:" + filename).c_str())));
    }
    catch (std::exception & ex)
    {
        return ThrowException(Exception::Error(
                                  String::New(ex.what())));
    }

}
void cairo_container::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg )
{
	cairo_t* cr = (cairo_t*) hdc;
	cairo_save(cr);
	apply_clip(cr);

	rounded_rectangle(cr, bg.border_box, bg.border_radius);
	cairo_clip(cr);

	cairo_rectangle(cr, bg.clip_box.x, bg.clip_box.y, bg.clip_box.width, bg.clip_box.height);
	cairo_clip(cr);

	if(bg.color.alpha)
	{
		set_color(cr, bg.color);
		cairo_paint(cr);
	}

	std::wstring url;
	t_make_url(bg.image.c_str(), bg.baseurl.c_str(), url);

	lock_images_cache();
	images_map::iterator img_i = m_images.find(url.c_str());
	if(img_i != m_images.end() && img_i->second)
	{
		image_ptr bgbmp = img_i->second;
		
		image_ptr new_img;
		if(bg.image_size.width != bgbmp->getWidth() || bg.image_size.height != bgbmp->getHeight())
		{
			new_img = image_ptr(new CTxDIB);
			bgbmp->resample(bg.image_size.width, bg.image_size.height, new_img.get());
			bgbmp = new_img;
		}


		cairo_surface_t* img = cairo_image_surface_create_for_data((unsigned char*) bgbmp->getBits(), CAIRO_FORMAT_ARGB32, bgbmp->getWidth(), bgbmp->getHeight(), bgbmp->getWidth() * 4);
		cairo_pattern_t *pattern = cairo_pattern_create_for_surface(img);
		cairo_matrix_t flib_m;
		cairo_matrix_init(&flib_m, 1, 0, 0, -1, 0, 0);
		cairo_matrix_translate(&flib_m, -bg.position_x, -bg.position_y);
		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
		cairo_pattern_set_matrix (pattern, &flib_m);

		switch(bg.repeat)
		{
		case litehtml::background_repeat_no_repeat:
			draw_txdib(cr, bgbmp.get(), bg.position_x, bg.position_y, bgbmp->getWidth(), bgbmp->getHeight());
			break;

		case litehtml::background_repeat_repeat_x:
			cairo_set_source(cr, pattern);
			cairo_rectangle(cr, bg.clip_box.left(), bg.position_y, bg.clip_box.width, bgbmp->getHeight());
			cairo_fill(cr);
			break;

		case litehtml::background_repeat_repeat_y:
			cairo_set_source(cr, pattern);
			cairo_rectangle(cr, bg.position_x, bg.clip_box.top(), bgbmp->getWidth(), bg.clip_box.height);
			cairo_fill(cr);
			break;

		case litehtml::background_repeat_repeat:
			cairo_set_source(cr, pattern);
			cairo_rectangle(cr, bg.clip_box.left(), bg.clip_box.top(), bg.clip_box.width, bg.clip_box.height);
			cairo_fill(cr);
			break;
		}

		cairo_pattern_destroy(pattern);
		cairo_surface_destroy(img);
	}
	unlock_images_cache();
	cairo_restore(cr);
}
Example #9
0
static int image_load_internal(mess_image *image, const char *path,
	int is_create, int create_format, option_resolution *create_args)
{
	image_error_t err;
	const char *software_path;
	char *software_path_list = NULL;
	const void *buffer;
	const game_driver *gamedrv;
	UINT32 open_plan[4];
	int i;

	/* sanity checks */
	assert_always(image, "image_load(): image is NULL");
	assert_always(path, "image_load(): path is NULL");

	/* we are now loading */
	image->is_loading = 1;

	/* first unload the image */
	image_unload(image);

	/* record the filename */
	image->err = set_image_filename(image, path, NULL);
	if (image->err)
		goto done;

	/* tell the OSD layer that this is changing */
	osd_image_load_status_changed(image, 0);

	/* do we need to reset the CPU? */
	if ((timer_get_time() > 0) && image->dev->reset_on_load)
		mame_schedule_soft_reset(Machine);

	/* determine open plan */
	determine_open_plan(image, is_create, open_plan);

	/* attempt to open the file in various ways */
	for (i = 0; !image->file && open_plan[i]; i++)
	{
		software_path = software_path_list;
		do
		{
			gamedrv = Machine->gamedrv;
			while(!is_loaded(image) && gamedrv)
			{
				/* open the file */
				image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path);
				if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND))
					goto done;

				/* move on to the next driver */
				gamedrv = mess_next_compatible_driver(gamedrv);
			}

			/* move on to the next entry in the software path; if we can */
			if (software_path)
				software_path += strlen(software_path) + 1;
		}
		while(!is_loaded(image) && software_path && *software_path);
	}

	/* did we fail to find the file? */
	if (!is_loaded(image))
	{
		image->err = IMAGE_ERROR_FILENOTFOUND;
		goto done;
	}

	/* if applicable, call device verify */
	if (image->dev->imgverify && !image_has_been_created(image))
	{
		/* access the memory */
		buffer = image_ptr(image);
		if (!buffer)
		{
			image->err = IMAGE_ERROR_OUTOFMEMORY;
			goto done;
		}

		/* verify the file */
		err = image->dev->imgverify(buffer, (size_t) image->length);
		if (err)
		{
			image->err = IMAGE_ERROR_INVALIDIMAGE;
			goto done;
		}
	}

	/* call device load or create */
	if (image_has_been_created(image) && image->dev->create)
	{
		err = image->dev->create(image, create_format, create_args);
		if (err)
		{
			if (!image->err)
				image->err = IMAGE_ERROR_UNSPECIFIED;
			goto done;
		}
	}
	else if (image->dev->load)
	{
		/* using device load */
		err = image->dev->load(image);
		if (err)
		{
			if (!image->err)
				image->err = IMAGE_ERROR_UNSPECIFIED;
			goto done;
		}
	}

	/* success! */

done:
	if (software_path_list)
		free(software_path_list);
	if (image->err)
		image_clear(image);
	image->is_loading = 1;
	return image->err ? INIT_FAIL : INIT_PASS;
}
Example #10
0
Texture::Texture()
{
  std::unique_ptr<Image> image_ptr(new Image());
  image = std::move(image_ptr);
  gl_texture = 0;
}