Example #1
0
void IconDes::Undo()
{
	if(!IsCurrent())
		return;
	Slot& c = Current();
	Vector<Image> undo = UnpackImlData(c.undo);
	if(undo.GetCount() == 0)
		return;
	Vector<Image> redo = UnpackImlData(c.redo);
	redo.Add(c.image);
	c.image = undo.Pop();
	c.supersampling = sRemoveSsFlag(c.image);
	c.undo = PackImlData(undo);
	c.redo = PackImlData(redo);
	SyncImage();
	SetBar();
}
Example #2
0
void IconDes::SaveUndo()
{
	if(!IsCurrent())
		return;
	Slot& c = Current();
	Vector<Image> undo = UnpackImlData(c.undo);
	int maxn = minmax((single_mode ? 4000000 : 400000) / max(c.image.GetLength(), 1), 4, 128);
	while(undo.GetCount() > maxn)
		undo.Remove(0);
	if(undo.GetCount() && undo.Top() == c.image)
		return;
	sSetSsFlag(c.image, c.supersampling);
	undo.Add(c.image);
	c.undo = PackImlData(undo);
	c.redo.Clear();
	SetBar();
	undo.Clear();
	sRemoveSsFlag(c.image);
}
Example #3
0
bool LoadIml(const String& data, Array<ImlImage>& img, int& format)
{
	CParser p(data);
	format = 0;
	try {
		bool premultiply = !p.Id("PREMULTIPLIED");
		Vector<String> name;
		Vector<bool> exp;
		while(p.Id("IMAGE_ID")) {
			p.PassChar('(');
			String n;
			if(p.IsId()) {
				n = p.ReadId();
				if(n.StartsWith("im__", 4))
					n = Null;
				p.PassChar(')');
			}
			else
				while(!p.IsEof()) {
					if(p.Char(')'))
						break;
					p.SkipTerm();
				}
			name.Add(n);
			bool e = false;
			if(p.Id("IMAGE_META")) {
				p.PassChar('(');
				e = p.ReadString() == "exp";
				if(p.Char(',') && p.IsString())
					p.ReadString();
				p.PassChar(')');
			}
			exp.Add(e);
		}
		int ii = 0;
		while(p.Id("IMAGE_BEGIN_DATA")) {
			String data;
			while(p.Id("IMAGE_DATA")) {
				p.PassChar('(');
				for(int j = 0; j < 32; j++) {
					if(j) p.PassChar(',');
					data.Cat(p.ReadInt());
				}
				p.PassChar(')');
			}
			p.PassId("IMAGE_END_DATA");
			p.PassChar('(');
			int zlen = p.ReadInt();
			p.PassChar(',');
			int count = p.ReadInt();
			p.PassChar(')');

			data.Trim(zlen);
			Vector<Image> m = UnpackImlData(data, data.GetCount());
			if(m.GetCount() != count || ii + count > name.GetCount())
				p.ThrowError("");
			for(int i = 0; i < count; i++) {
				ImlImage& c = img.Add();
				c.name = name[ii];
				c.exp = exp[ii++];
				c.image = m[i];
				if(premultiply)
					c.image = Premultiply(c.image);
			}
		}
		if(!p.IsEof())
			p.ThrowError("");
	}
	catch(CParser::Error) {
		try {
			CParser p(data);
			Array<ImlImage> m;
			VectorMap<String, String> s;
			ScanIML(p, img, s);
			if(img.GetCount())
				format = 1;
		}
		catch(...) {
			return false;
		}
	}
	return true;
}