YSTest: ImageProcessing.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ImageProcessing.h
浏览该文件的文档.
1 /*
2 © 2014-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_Service_ImageProcessing_h_
29 #define YSL_INC_Service_ImageProcessing_h_ 1
30
31 #include "YModules.h"
32 #include <ystdex/rational.hpp> // for ystdex::fixed_point;
33 #include YFM_YSLib_Service_YGDI // for Drawing::CompactPimap;
34 #include YFM_YSLib_Service_YBrush // for Drawing::Image, Drawing::ImageCodec,
35 // Drawing::ImageBrush;
36 #include YFM_YSLib_Adaptor_Image // for Drawing::HBitmap;
37 #include <ystdex/hash.hpp> // for ystdex::hash_combine_seq;
38 #include <ystdex/cache.hpp>
39
40 namespace YSLib
41 {
42
43 namespace Drawing
44 {
45
47
48 using ImageScale = ystdex::fixed_point<yimpl(std::uint32_t, 12U)>;
50
55 YF_API CompactPixmap
56 Zoom(const HBitmap&, ImageScale);
58
59
64 class YF_API ZoomedImageCache
65 {
66 public:
67 using Container = vector<HBitmap>;
68 using CacheKey = pair<ImageScale, size_t>;
69 struct CacheHash
70 {
71 PDefHOp(size_t, (), const CacheKey& key) const ynothrow
72 ImplRet(ystdex::hash_combine_seq(size_t(key.first), key.second))
73 };
75 using BitmapCache = ystdex::used_list_cache<CacheKey, shared_ptr<Image>,
76 CacheHash>;
77
78 private:
79 Container bitmaps;
80 BitmapCache cache;
81
82 public:
84 template<typename _type,
85 yimpl(typename = ystdex::exclude_self_t<ZoomedImageCache, _type>)>
86 explicit
87 ZoomedImageCache(const _type& path)
88 : bitmaps(ImageCodec::LoadSequence<Container>(path)),
89 cache(bitmaps.size() * 2)
90 {}
92 DefDeMoveCtor(ZoomedImageCache)
93
94
95 DefDeMoveAssignment(ZoomedImageCache)
96
97 DefGetter(const ynothrow, const Container&, Bitmaps, bitmaps)
98
100 shared_ptr<Image>
101 Lookup(ImageScale, size_t);
102 };
103
104
112 class YF_API ImagePages
113 {
114 public:
115 ImageScale MinScale{.1F};
116 ImageScale MaxScale{16.F};
117
118 private:
120 size_t index = 0;
121 ZoomedImageCache cache;
126 Size base_size;
131 ImageScale scale;
133 Size view_size{};
134
135 public:
137 ImageBrush Brush{};
138
145 template<typename _type,
147 yimpl(typename = ystdex::exclude_self_t<ImagePages, _type>)>
148 ImagePages(const _type& path, const Size& min_size, const Size& max_size,
149 ImageScale init_scale = {})
150 : ImagePages(ZoomedImageCache(path), min_size, max_size, init_scale)
151 {}
153 ImagePages(ZoomedImageCache&&, const Size&, const Size&, ImageScale);
155 DefDeMoveCtor(ImagePages)
156
157 DefDeMoveAssignment(ImagePages)
158
159
160 DefGetterMem(const ynothrow, const vector<HBitmap>&, Bitmaps, cache)
162
163 DefGetter(const ynothrow, size_t, Count, cache.GetBitmaps().size())
164 DefGetter(const ynothrow, size_t, Index, index)
166 DefGetter(const ynothrow, ImageScale, Scale, scale)
168 DefGetter(const ynothrow, const Size&, ViewSize, view_size)
169
171 void
172 AdjustOffset(const Size&);
173
174 private:
176 void
177 LoadContent();
178
179 public:
184 void
185 Resize(const Size&);
186
191 bool
192 SwitchPage(size_t);
193
195 PDefH(bool, SwitchPageDiff, ptrdiff_t diff)
196 ImplRet(SwitchPage(size_t(ptrdiff_t(index) + diff) % GetCount()))
197
209 bool
210 Zoom(float, const Point&);
211
218 bool
219 ZoomByRatio(float, const Point&, float = 0.F);
220
227 bool
228 ZoomTo(float, const Point&);
230 };
231
232 } // namespace Drawing;
233
234 } // namespace YSLib;
235
236 #endif
237
rational.hpp
有理数运算。
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::Drawing::ImagePages::base_size
Size base_size
图像基础大小。
Definition: ImageProcessing.h:126
size
size_t size
Definition: memory_resource.cpp:295
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::ImplRet
YB_ATTR_nodiscard YB_STATELESS yconstfn Rotation rot ImplRet(Rotation((size_t(rot)+1) % 4)) YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation
YSLib::Drawing::ImagePages::ImagePages
ImagePages(const _type &path, const Size &min_size, const Size &max_size, ImageScale init_scale={})
构造：使用指定路径、显示区域下限、显示区域上限和起始缩放比例。
Definition: ImageProcessing.h:148
YSLib::Drawing::Zoom
YF_API CompactPixmap Zoom(const HBitmap &, ImageScale)
缩放位图。
Definition: ImageProcessing.cpp:39
hash.hpp
散列接口。
YSLib::Drawing::ImagePages::DefDeMoveCtor
DefDeMoveCtor(ImagePages) DefDeMoveAssignment(ImagePages) DefGetterMem(const ynothrow
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::ImageScale
ystdex::fixed_point< yimpl(std::uint32_t, 12U)> ImageScale
图像缩放类型。
Definition: ImageProcessing.h:49
YSLib::Drawing::ImagePages::scale
ImageScale scale
缩放比例。
Definition: ImageProcessing.h:131
YSLib::Drawing::ZoomedImageCache::cache
BitmapCache cache
Definition: ImageProcessing.h:80
ystdex::used_list_cache< CacheKey, shared_ptr< Image >, CacheHash >
ystdex::hash_combine_seq
size_t hash_combine_seq(size_t seed, const _type &val)
重复计算序列散列。
Definition: hash.hpp:67
YSLib::Drawing::PDefH
YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:763
YSLib::Drawing::ZoomedImageCache::CacheHash
Definition: ImageProcessing.h:70
YSLib::Drawing::HBitmap
位图句柄：指向位图数据。
Definition: Image.h:302
YSLib::Drawing::ZoomedImageCache::ZoomedImageCache
ZoomedImageCache(const _type &path)
Definition: ImageProcessing.h:87
ystdex::fixed_point
通用定点数。
Definition: rational.hpp:164
cache.hpp
高速缓冲容器模板。
YSLib::Drawing::ZoomedImageCache::DefDeMoveCtor
DefDeMoveCtor(ZoomedImageCache) DefDeMoveAssignment(ZoomedImageCache) DefGetter(const ynothrow
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::ZoomedImageCache
缩放图像缓冲。
Definition: ImageProcessing.h:65
YSLib::UI::Resize
@ Resize
大小调整。
Definition: YWidgetEvent.h:383
platform::containers::vector
std::vector< _type, _tAlloc > vector
Definition: Container.h:102
YSLib::path
YB_ATTR_nodiscard YF_API const char * path
Definition: Initialization.h:116
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::Drawing::PDefHOp
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE PDefHOp(Padding,+, const Padding &x, const Padding &y) ynothrow ImplRet(Padding(x.Left+y.Left
加法：对应分量调用 operator+ 。
YModules.h
YSLib 用户界面模块配置文件。
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
YSLib::Drawing::ynothrow
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE const Padding & ynothrow
Definition: YGDI.h:132
YSLib::Drawing::ZoomedImageCache::CacheKey
pair< ImageScale, size_t > CacheKey
Definition: ImageProcessing.h:68
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Drawing::ZoomedImageCache::Container
vector< HBitmap > Container
Definition: ImageProcessing.h:67
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
YSLib::Drawing::ZoomedImageCache::bitmaps
Container bitmaps
Definition: ImageProcessing.h:79
YSLib::Drawing::ImagePages
图像页面集。
Definition: ImageProcessing.h:113
YSLib::Drawing::ImageCodec
Definition: Image.h:952
YSLib::Drawing::ImageBrush
图像画刷。
Definition: YBrush.h:129
YSLib::Drawing::ImagePages::cache
ZoomedImageCache cache
Definition: ImageProcessing.h:121