void RichRawImage::Paint(const Value& data, Draw& w, Size sz, void *) const { String s = data; StringStream ss(s); One<StreamRaster> r = StreamRaster::OpenAny(ss); if(r) { Size isz = r->GetSize(); if(isz.cx * isz.cy > sz.cx * sz.cy) { // conserve memory by scaling down from source ImageEncoder m; Rescale(m, sz, *r, r->GetSize()); w.DrawImage(0, 0, sz.cx, sz.cy, m); } else w.DrawImage(0, 0, sz.cx, sz.cy, r->GetImage()); // scale up by Draw to give e.g. PDF chance to store unscaled } }
void cDrawRasterData::Open(const String& data, int _cx, int cy) { cx = _cx; ss.Open(data); raster = StreamRaster::OpenAny(ss); if(raster) si.Create(Size(cx, cy), *raster, raster->GetSize()); }
Size RichRawImage::GetPixelSize(const Value& data) const { String s = data; StringStream ss(s); One<StreamRaster> r = StreamRaster::OpenAny(ss); if(r) return r->GetSize(); return Size(0, 0); }
bool RasterPlayer::LoadBuffer(const String &buffer) { if (buffer.IsEmpty()) return false; StringStream str(buffer); One<StreamRaster> raster = StreamRaster::OpenAny(str); if(!raster) return false; Stop(); images.Clear(); delays.Clear(); Size sz = raster->GetSize(); ImageDraw iw(sz); Image previous; Rect r; for (int i = 0; i < raster->GetPageCount(); ++i) { if (previous) { iw.Alpha().DrawImage(r, previous, GrayColor(255)); iw.DrawImage(r, previous); previous = Null; } raster->SeekPage(i); r = raster->GetPageRect(i); switch (raster->GetPageDisposal(i)) { case 1: case 2: iw.DrawRect(r, SColorFace()); break; //case 2: iw.DrawRect(sz, White()); // It seems gif files do not comply with standard // break; case 4: if (i > 0) previous = GetRect_(images[i-1], r); iw.DrawRect(sz, SColorFace()); break; } iw.Alpha().DrawImage(r.left, r.top, raster->GetImage(0, 0, r.right-r.left, r.bottom-r.top), GrayColor(255)); iw.DrawImage(r.left, r.top, raster->GetImage(0, 0, r.right-r.left, r.bottom-r.top)); images.Add(iw); delays.Add(max(50, 10*raster->GetPageDelay(i))); } ind = 0; return true; }
virtual IdeDesigner *CreateDesigner(const char *path, byte) { if(IsImgFile(path)) { FileIn in(path); One<StreamRaster> o = StreamRaster::OpenAny(in); if(o) { Size sz = o->GetSize(); if(ToLower(GetFileExt(path)) == ".png" && sz.cx <= 768 && sz.cy <= 512) { IdePngDes *d = new IdePngDes; d->Load(path); d->RestoreEditPos(); return d; } else { IdeImgView *d = new IdeImgView; d->img_sz = sz; d->filename = path; if(sz.cx <= 1024 && sz.cy <= 768) d->img = o->GetImage(); else { ImageEncoder m; Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz); d->img = m; } return d; } } else if(ToLower(GetFileExt(path)) == ".png" && GetFileLength(path) <= 0) { IdePngDes *d = new IdePngDes; d->Create(path); d->RestoreEditPos(); return d; } } return NULL; }