diff --git a/uppsrc/Draw/ImageOp.h b/uppsrc/Draw/ImageOp.h index 4afdd0869..c7ef2b785 100644 --- a/uppsrc/Draw/ImageOp.h +++ b/uppsrc/Draw/ImageOp.h @@ -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 progress = false); Image RescaleBicubic(const Image& img, Size sz, Gate2 progress = false); diff --git a/uppsrc/Draw/MakeCache.cpp b/uppsrc/Draw/MakeCache.cpp index 245b0ef74..7aa810da5 100644 --- a/uppsrc/Draw/MakeCache.cpp +++ b/uppsrc/Draw/MakeCache.cpp @@ -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 diff --git a/uppsrc/Draw/SDrawPut.cpp b/uppsrc/Draw/SDrawPut.cpp index 7d5ee89a7..4917f25fb 100644 --- a/uppsrc/Draw/SDrawPut.cpp +++ b/uppsrc/Draw/SDrawPut.cpp @@ -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) diff --git a/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp b/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp index d9cfcd54c..92afbbbf2 100644 --- a/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp +++ b/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp @@ -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;%% ]] \ No newline at end of file diff --git a/uppsrc/PdfDraw/PdfDraw.cpp b/uppsrc/PdfDraw/PdfDraw.cpp index 9bb9e17b5..66c070d47 100644 --- a/uppsrc/PdfDraw/PdfDraw.cpp +++ b/uppsrc/PdfDraw/PdfDraw.cpp @@ -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 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 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) { diff --git a/uppsrc/PdfDraw/PdfDraw.h b/uppsrc/PdfDraw/PdfDraw.h index 10b37c7dc..fd984f08d 100644 --- a/uppsrc/PdfDraw/PdfDraw.h +++ b/uppsrc/PdfDraw/PdfDraw.h @@ -270,9 +270,8 @@ private: VectorMap outline_info; VectorMap > pdffont; VectorMap > fontchars; - Vector image; - Vector imagerect; Index patterns; + VectorMap< Tuple2, Image> images; Vector offset; StringBuffer out;