From ec60e904eb7cf2e8eb49543fa25a0a5558465341 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 1 Feb 2014 16:35:48 +0000 Subject: [PATCH] Draw: SDraw now using PaintOnly when possible git-svn-id: svn://ultimatepp.org/upp/trunk@6845 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Draw/ImageOp.h | 1 + uppsrc/Draw/MakeCache.cpp | 8 +++++++ uppsrc/Draw/SDrawPut.cpp | 2 +- uppsrc/Draw/SDrawText.cpp | 27 ++++++++++++++++-------- uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp | 10 +++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/uppsrc/Draw/ImageOp.h b/uppsrc/Draw/ImageOp.h index c7ef2b785..0cd9e74fc 100644 --- a/uppsrc/Draw/ImageOp.h +++ b/uppsrc/Draw/ImageOp.h @@ -190,6 +190,7 @@ Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src, int filte Image CachedRescalePaintOnly(const Image& m, Size sz, int filter = Null); Image CachedSetColorKeepAlpha(const Image& img, Color color); +Image CachedSetColorKeepAlphaPaintOnly(const Image& img, Color color); // Obsolete, replace with RescaleFilter! Image RescaleBicubic(const Image& src, Size sz, const Rect& src_rc, Gate2 progress = false); diff --git a/uppsrc/Draw/MakeCache.cpp b/uppsrc/Draw/MakeCache.cpp index 7aa810da5..c3eb6239e 100644 --- a/uppsrc/Draw/MakeCache.cpp +++ b/uppsrc/Draw/MakeCache.cpp @@ -254,4 +254,12 @@ Image CachedSetColorKeepAlpha(const Image& img, Color color) return MakeImage(m); } +Image CachedSetColorKeepAlphaPaintOnly(const Image& img, Color color) +{ + sColorize m; + m.img = img; + m.color = color; + return MakeImagePaintOnly(m); +} + END_UPP_NAMESPACE diff --git a/uppsrc/Draw/SDrawPut.cpp b/uppsrc/Draw/SDrawPut.cpp index 4917f25fb..8448de04b 100644 --- a/uppsrc/Draw/SDrawPut.cpp +++ b/uppsrc/Draw/SDrawPut.cpp @@ -4,7 +4,7 @@ NAMESPACE_UPP void SDraw::PutImage(Point p, const Image& img, const Rect& src, Color color) { - PutImage(p, CachedSetColorKeepAlpha(img, color), src); + PutImage(p, CachedSetColorKeepAlphaPaintOnly(img, color), src); } void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) diff --git a/uppsrc/Draw/SDrawText.cpp b/uppsrc/Draw/SDrawText.cpp index 7a96d9fed..d56bb2fae 100644 --- a/uppsrc/Draw/SDrawText.cpp +++ b/uppsrc/Draw/SDrawText.cpp @@ -19,6 +19,7 @@ struct sMakeTextGlyph : public ImageMaker int angle; Color color; SDraw *draw; + int yy; virtual String Key() const { StringBuffer h; @@ -26,14 +27,22 @@ struct sMakeTextGlyph : public ImageMaker RawCat(h, font); RawCat(h, angle); RawCat(h, color); + RawCat(h, yy); return h; } virtual Image Make() const { LTIMING("Render glyph"); Point at(font[chr], font.GetLineHeight()); - int n = 2 * (at.x + at.y); - return AutoCrop(WithHotSpot(draw->RenderGlyph(at, angle, chr, font, color, Size(n, n)), at.x, at.y), RGBAZero()); + if(IsNull(yy)) { + int n = 2 * (at.x + at.y); + return AutoCrop(WithHotSpot(draw->RenderGlyph(at, angle, chr, font, color, Size(n, n)), at.x, at.y), RGBAZero()); + } + else { + int n = at.x + at.y; + Size bandsz(2 * n, 32); + return AutoCrop(WithHotSpot(draw->RenderGlyph(Point(0, -yy), angle, chr, font, color, bandsz), 0, 0), RGBAZero()); + } } }; @@ -48,16 +57,16 @@ void SDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Co g.chr = text[i]; LTIMING("Paint glyph"); if(font.GetHeight() > 200) { - Point at(font[g.chr], font.GetLineHeight()); - int n = at.x + at.y; - Size bandsz(2 * n, 32); - for(int yy = 0; yy < n; yy += bandsz.cy) { - Image m = RenderGlyph(Point(0, -yy), angle, g.chr, font, White(), bandsz); - SysDrawImageOp(x, y + yy, m, m.GetSize(), ink); + int bn = font[g.chr] + font.GetLineHeight(); + for(g.yy = 0; g.yy < bn; g.yy += 32) { + Image m = MakeImagePaintOnly(g); + Point h = m.GetHotSpot(); + SysDrawImageOp(x - h.x, y + g.yy - h.y, m, m.GetSize(), ink); } } else { - Image m = MakeImage(g); + g.yy = Null; + Image m = MakeImagePaintOnly(g); Point h = m.GetHotSpot(); SysDrawImageOp(x - h.x, y - h.y, m, m.GetSize(), ink); } diff --git a/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp b/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp index 92afbbbf2..009e7c7c5 100644 --- a/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp +++ b/uppsrc/Draw/src.tpp/ImageMaker$en-us.tpp @@ -122,4 +122,14 @@ 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.&] +[s3;%% &] +[s4; &] +[s5;:CachedSetColorKeepAlphaPaintOnly`(const Image`&`,Color`): [_^Image^ Image]_[* Cached +SetColorKeepAlphaPaintOnly]([@(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, +with results being cached, that can only be used with Draw`::DrawImage(this +is optimization hint that can save some memory in certain situations).&] +[s3;%% &] [s0;%% ]] \ No newline at end of file