Exemple #1
0
cairo_png_mptr::cairo_png_mptr(const synfig::FileSystem::Identifier &identifier):
	CairoImporter(identifier)
{
	FileSystem::ReadStreamHandle stream = identifier.get_read_stream();
	csurface_=cairo_image_surface_create_from_png_stream(read_callback, stream.get());
	stream.reset();
	if(cairo_surface_status(csurface_))
	{
		throw strprintf("Unable to physically open %s",identifier.filename.c_str());
		cairo_surface_destroy(csurface_);
		csurface_=NULL;
		return;
	}
	CairoSurface cairo_s;
	cairo_s.set_cairo_surface(csurface_);
	if(!cairo_s.map_cairo_image())
	   return;
	int w=cairo_s.get_w();
	int h=cairo_s.get_h();
	for(int y=0; y<h; y++)
		for(int x=0; x<w; x++)
		{
			CairoColor c=cairo_s[y][x];
			float a=c.get_alpha();
			unsigned char r=(unsigned char)(a*gamma().r_F32_to_F32(c.get_r()/a));
			unsigned char g=(unsigned char)(a*gamma().g_F32_to_F32(c.get_g()/a));
			unsigned char b=(unsigned char)(a*gamma().b_F32_to_F32(c.get_b()/a));
			c.set_r(r);
			c.set_g(g);
			c.set_b(b);
			cairo_s[y][x]=c;
		}
	cairo_s.unmap_cairo_image();
}
bool FileContainerTemporary::open_temporary(const std::string &filename_base)
{
	if (is_opened()) return false;

	FileSystem::ReadStreamHandle stream =
		file_system_->get_read_stream(
			get_temporary_directory()
		  + filename_base);
	if (!stream) return false;
	stream = new ZReadStream(stream);

	xmlpp::DomParser parser;
	parser.parse_stream(*stream);
	stream.reset();
	if (!parser) return false;

	xmlpp::Element *root = parser.get_document()->get_root_node();
	if (root->get_name() != "temporary-container") return false;

	xmlpp::Element::NodeList list = root->get_children();
	for(xmlpp::Element::NodeList::iterator i = list.begin(); i != list.end(); i++)
	{
		if ((*i)->get_name() == "container-filename")
			container_filename_ = get_xml_node_text(*i);
		if ((*i)->get_name() == "files")
		{
			xmlpp::Element::NodeList files_list = (*i)->get_children();
			for(xmlpp::Element::NodeList::iterator j = files_list.begin(); j != files_list.end(); j++)
			{
				if ((*j)->get_name() == "entry")
				{
					FileInfo info;
					xmlpp::Element::NodeList fields_list = (*j)->get_children();
					for(xmlpp::Element::NodeList::iterator k = fields_list.begin(); k != fields_list.end(); k++)
					{
						if ((*k)->get_name() == "name")
							info.name = get_xml_node_text(*k);
						if ((*k)->get_name() == "tmp-basename")
							info.tmp_filename = get_xml_node_text(*k);
						if ((*k)->get_name() == "is-directory")
							info.is_directory = get_xml_node_text(*k) == "true";
						if ((*k)->get_name() == "is-removed")
							info.is_removed = get_xml_node_text(*k) == "true";
					}
					if (!info.tmp_filename.empty())
						info.tmp_filename = get_temporary_directory() + info.tmp_filename;
					info.split_name();
					files_[info.name] = info;
				}
			}
		}
	}

	if (!container_filename_.empty() && !container_->open(container_filename_))
	{
		container_filename_.clear();
		files_.clear();
		return false;
	}

	temporary_filename_base_ = filename_base;
	is_opened_ = true;
	return true;
}