Draw: CachedSetColorKeepAlpha, PdfDraw: compresion of repeated images

git-svn-id: svn://ultimatepp.org/upp/trunk@6594 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-21 09:54:19 +00:00
parent 28c32db988
commit 29cdccef55
6 changed files with 50 additions and 32 deletions

View file

@ -189,6 +189,8 @@ Image CachedRescale(const Image& m, Size sz, int filter = Null);
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src, int filter = Null);
Image CachedRescalePaintOnly(const Image& m, Size sz, int filter = Null);
Image CachedSetColorKeepAlpha(const Image& img, Color color);
// Obsolete, replace with RescaleFilter!
Image RescaleBicubic(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> progress = false);
Image RescaleBicubic(const Image& img, Size sz, Gate2<int, int> progress = false);

View file

@ -228,5 +228,30 @@ Image CachedRescalePaintOnly(const Image& m, Size sz, int filter)
return CachedRescalePaintOnly(m, sz, m.GetSize(), filter);
}
struct sColorize : public ImageMaker
{
Image img;
Color color;
virtual String Key() const {
StringBuffer h;
RawCat(h, color);
RawCat(h, img.GetSerialId());
return h;
}
virtual Image Make() const {
return SetColorKeepAlpha(img, color);
}
};
Image CachedSetColorKeepAlpha(const Image& img, Color color)
{
sColorize m;
m.img = img;
m.color = color;
return MakeImage(m);
}
END_UPP_NAMESPACE

View file

@ -2,30 +2,9 @@
NAMESPACE_UPP
struct sColorize : public ImageMaker
{
Image img;
Color color;
virtual String Key() const {
StringBuffer h;
RawCat(h, color);
RawCat(h, img.GetSerialId());
return h;
}
virtual Image Make() const {
return SetColorKeepAlpha(img, color);
}
};
void SDraw::PutImage(Point p, const Image& img, const Rect& src, Color color)
{
sColorize m;
m.img = img;
m.color = color;
PutImage(p, MakeImage(m), src);
PutImage(p, CachedSetColorKeepAlpha(img, color), src);
}
void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color)

View file

@ -115,4 +115,11 @@ can save some memory in certain situations). [%-*@3 filter] can
be one of predefined filters for RescaleFilter function (e.g.
FILTER`_BILINEAR), if Null, standard speed optimized custom algorithm
is used.&]
[s3;%% &]
[s4; &]
[s5;:CachedSetColorKeepAlpha`(const Image`&`,Color`): [_^Image^ Image]_[* CachedSetColorK
eepAlpha]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 img],
[_^Color^ Color]_[*@3 color])&]
[s2;%% Cached variant of SetColorKeepAlpha. Replaces all pixel colors
in Image with [%-*@3 color] while not changing the alpha value.&]
[s0;%% ]]

View file

@ -406,13 +406,19 @@ void PdfDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& _img, const
{
Image img = _img;
if(!IsNull(c))
img = SetColorKeepAlpha(img, c);
image.Add(img);
imagerect.Add(src);
img = CachedSetColorKeepAlpha(img, c);
Tuple2<int64, Rect> key = MakeTuple(img.GetSerialId(), src);
int q = images.Find(key);
if(q < 0) {
q = images.GetCount();
images.Add(key, img);
}
page << "q "
<< Pt(cx) << " 0 0 " << Pt(cy) << ' '
<< Pt(x) << ' ' << Pt(pgsz.cy - y - cy)
<< " cm /Image" << image.GetCount() << " Do Q\n";
<< " cm /Image" << q + 1 << " Do Q\n";
}
void PdfDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count,
@ -546,13 +552,13 @@ String PdfDraw::Finish()
int pagecount = offset.GetCount();
Vector<int> imageobj;
for(int i = 0; i < image.GetCount(); i++) {
Size sz = image[i].GetSize();
Rect sr = sz & imagerect[i];
for(int i = 0; i < images.GetCount(); i++) {
Size sz = images[i].GetSize();
Rect sr = images.GetKey(i).b & sz;
String data;
String wh;
wh << " /Width " << sr.Width() << " /Height " << sr.Height();
const Image& m = image[i];
const Image& m = images[i];
int mask = -1;
int smask = -1;
if(m.GetKind() == IMAGE_MASK) {

View file

@ -270,9 +270,8 @@ private:
VectorMap<Font, OutlineInfo> outline_info;
VectorMap<Font, Vector<wchar> > pdffont;
VectorMap<Font, VectorMap<wchar, CharPos> > fontchars;
Vector<Image> image;
Vector<Rect> imagerect;
Index<uint64> patterns;
VectorMap< Tuple2<int64, Rect>, Image> images;
Vector<int> offset;
StringBuffer out;