DxLibEx
texture2d.hpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2015-2017 DxLibEx project
3  https://github.com/Nagarei/DxLibEx/
4 
5  Distributed under the Boost Software License, Version 1.0.
6  (See http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #ifndef DXLE_INC_TEXTURE_TEXTURE2D_TEXTURE2D_HPP_
9 #define DXLE_INC_TEXTURE_TEXTURE2D_TEXTURE2D_HPP_
10 
12 #if defined(__c2__) && __clang_major__ == 3 && __clang_minor__ == 8
13 //To avoid compile error
14 //C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error : unknown type name 'IUnknown'
15 // static_cast<IUnknown*>(*pp); // make sure everyone derives from IUnknown
16 struct IUnknown;
17 #endif
18 #include "DxLib.h"
19 #include <cstdint>
20 #include "../texture2d.hpp"
21 #include "dxlibex/basic_types.hpp"
22 
23 //--------------------実装--------------------//
24 
25 namespace dxle
26 {
28  namespace graph2d
29  {
30 
31  namespace gr_impl
32  {
33  template<typename BuffT, typename OutFunc>
35  inline void LoadDivGraph_impl(OutFunc&& out_func, BuffT* HandleBuf, const TCHAR *FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
36  {
37  DxLib::LoadDivGraph(FileName, AllNum, Num.width, Num.height, Size.width, Size.height, HandleBuf, NotUse3DFlag);
38  try{
39  std::for_each(HandleBuf, HandleBuf + AllNum, [&out_func, &NotUse3DFlag](int& handle){
40  texture2d temp{ handle, NotUse3DFlag };
41  handle = -1;
42  out_func(std::move(temp));
43  });
44  return;
45  }
46  catch (...){
47  std::for_each(HandleBuf, HandleBuf + AllNum, [](int handle){
48  ::DxLib::DeleteGraph(handle);
49  });
50  throw;
51  }
52  }
54  {
55  return texture.GetHandle();
56  }
57  }
58 
59 
60  //--------------------texture2d--------------------//
61 
62  inline std::unique_ptr<texture2d> texture2d::clone()const
63  {
64  return std::make_unique<texture2d>(this->DerivationGraph({ 0, 0 }, size()));
65  }
66 
69  tstring buf;
70  buf.resize(2048);
71  if (this->GetGraphFilePath(&buf[0]) == -1) {
72  return{};
73  }
74  buf.resize(dxle::tstrlen(buf.c_str()));
75  buf.shrink_to_fit();
76  return buf;
77  }
78  inline int texture2d::filter_mono(int16_t Cb, int16_t Cr)
79  {
80  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_MONO, Cb, Cr);
81  }
82  inline int texture2d::filter_gaussian(uint16_t PixelWidth, int Param)
83  {
84  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_GAUSS, PixelWidth, Param);
85  }
86  inline int texture2d::filter_down_scale(uint8_t DivNum)
87  {
88  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_DOWN_SCALE, DivNum);
89  }
90  inline int texture2d::filter_bright_clip(bright_clip_mode clipmode, uint8_t clip_pram, unsigned int fillcolor, uint8_t fillalpha)
91  {
92  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_BRIGHT_CLIP, clipmode, clip_pram, fillcolor, fillalpha);
93  }
94  inline int texture2d::filter_HSB(bool HueType, int16_t Hue, int Saturation, int16_t Bright)
95  {
96  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_HSB, HueType, Hue, Saturation, Bright);
97  }
99  {
100  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_INVERT);
101  }
102  inline int texture2d::filter_level(uint8_t min, uint8_t max, int Gamma, uint8_t Aftermin, uint8_t Aftermax)
103  {
104  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_LEVEL, min, max, Gamma, Aftermin, Aftermax);
105  }
106  inline int texture2d::filter_two_color(uint8_t threshold, unsigned int LowColor, uint8_t LowAlpha, unsigned int HighColor, uint8_t HighAlpha)
107  {
108  return DxLib::GraphFilter(GetHandle(), DX_GRAPH_FILTER_LEVEL, threshold, LowColor, LowAlpha, HighColor, HighAlpha);
109  }
110 
111 
112  //--------------------screen--------------------//
113 
114  template<typename Func_T>
115  screen& screen::draw_on_this(Func_T&& draw_func) {
116  DXLE_GET_LOCK(screen_mutex_c::mtx);
117  struct Finary_ {
118  int old_draw_screen;
119  int old_is_setting_reset;
120  Finary_()
121  : old_draw_screen(DxLib::GetDrawScreen())
122  , old_is_setting_reset(DxLib::GetUseSetDrawScreenSettingReset())
123  {}
124  ~Finary_()
125  {
126  DxLib::SetDrawScreen(old_draw_screen);
127  DxLib::SetUseSetDrawScreenSettingReset(old_is_setting_reset);
128  }
129  }finally_;
130 
131  DxLib::SetUseSetDrawScreenSettingReset(FALSE);
132  this->SetDrawScreen();
133  draw_func();
134 
135  return *this;
136  }
137  inline std::unique_ptr<screen> screen::cloneSc()const
138  {
139  auto graph_size = GetGraphSize();
140 
141  screen new_screen = screen::MakeScreen(graph_size, static_cast<gr_impl::screen_handle_manager&>(*handle_manager).UseAlphaChannel);
142  this->BltDrawValidGraph({ 0, 0 }, graph_size, { 0, 0 }, new_screen);
143  return std::make_unique<screen>(std::move(new_screen));
144  }
145 
146 
147  //--------------------static_derivative_texture2d--------------------//
148 
149  template<size_t N>
151  //: textures(std::move(other.textures))//VS2013はmoveコンストラクタの暗黙の定義に対応していない
152  {
153  std::move(std::begin(other.textures), std::end(other.textures), std::begin(textures));
154  }
155  template<size_t N>
157  {
158  //textures = std::move(other.textures);//VS2013はmove代入演算子の暗黙の定義に対応していない
159  std::move(std::begin(other.textures), std::end(other.textures), std::begin(textures));
160  }
161  template<size_t N>
162  inline static_derivative_texture2d<N>::static_derivative_texture2d(const TCHAR *FileName, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
163  {
164  load(FileName, Num, Size, NotUse3DFlag);
165  }
166  template<size_t N>
167  inline static_derivative_texture2d<N>::static_derivative_texture2d(const tstring& FileName, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
168  {
169  load(FileName, Num, Size, NotUse3DFlag);
170  }
171  template<size_t N>
172  inline void static_derivative_texture2d<N>::load(const TCHAR *FileName, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
173  {
174  int HandleBuf[N];
175  auto iter = textures.begin();
176  gr_impl::LoadDivGraph_impl([&iter](texture2d&& new_obj){ *iter++ = std::move(new_obj); }, HandleBuf, FileName, N, Num, Size, NotUse3DFlag);
177  return;
178  }
179  template<size_t N>
180  inline void static_derivative_texture2d<N>::load(const tstring& FileName, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
181  {
182  load(FileName.c_str(), Num, Size, NotUse3DFlag);
183  }
184  template<size_t N>
186  {
187  for (auto& i : textures)
188  {
189  i.delete_this();
190  }
191  }
192 
193 
194  //--------------------derivative_texture2d--------------------//
195 
196  inline derivative_texture2d::derivative_texture2d(derivative_texture2d&& other)DXLE_NOEXCEPT_IF((std::is_nothrow_move_constructible<cont_type>::value))
197  : textures(std::move(other.textures))
198  {}
199  inline derivative_texture2d& derivative_texture2d::operator=(derivative_texture2d&& other)DXLE_NOEXCEPT_IF((std::is_nothrow_move_assignable<cont_type>::value))
200  {
201  textures = std::move(other.textures);
202  return *this;
203  }
204  inline derivative_texture2d::derivative_texture2d(const TCHAR *FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
205  {
206  load(FileName, AllNum, Num, Size, NotUse3DFlag);
207  }
208  inline derivative_texture2d::derivative_texture2d(const tstring& FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
209  {
210  load(FileName, AllNum, Num, Size, NotUse3DFlag);
211  }
212  inline void derivative_texture2d::load(const TCHAR *FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
213  {
214  auto HandleBuf = std::make_unique<int[]>(AllNum);
215  gr_impl::LoadDivGraph_impl([this](texture2d&& new_obj){ this->textures.emplace_back(std::move(new_obj)); }, HandleBuf.get(), FileName, AllNum, Num, Size, NotUse3DFlag);
216  return;
217  }
218  inline void derivative_texture2d::load(const tstring& FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
219  {
220  load(FileName.c_str(), AllNum, Num, Size, NotUse3DFlag);
221  }
222  inline derivative_texture2d derivative_texture2d::LoadDivGraph(const TCHAR *FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
223  {
224  return derivative_texture2d(FileName, AllNum, Num, Size, NotUse3DFlag);
225  }
226  inline derivative_texture2d derivative_texture2d::LoadDivGraph(const tstring& FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
227  {
228  return derivative_texture2d(FileName, AllNum, Num, Size, NotUse3DFlag);
229  }
231  {
232  textures.clear();
233  }
234 
235 
236  //--------------------生成用関数--------------------//
237 
238  inline derivative_texture2d LoadDivGraph(const TCHAR *FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
239  {
240  return derivative_texture2d(FileName, AllNum, Num, Size, NotUse3DFlag);
241  }
242  inline derivative_texture2d LoadDivGraph(const tstring& FileName, int AllNum, const dxle::sizei& Num, const dxle::sizei& Size, bool NotUse3DFlag)
243  {
244  return derivative_texture2d(FileName, AllNum, Num, Size, NotUse3DFlag);
245  }
246 
247  }
248  using namespace graph2d;
249 }
250 #endif
int filter_two_color(uint8_t threshold, unsigned int LowColor, uint8_t LowAlpha, unsigned int HighColor, uint8_t HighAlpha)
Definition: texture2d.hpp:106
derivative_texture2d() DXLE_NOEXCEPT_OR_NOTHROW
Definition: texture2d.hpp:511
static derivative_texture2d LoadDivGraph(const TCHAR *FileName, int AllNum, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag=false)
Definition: texture2d.hpp:222
std::basic_string< TCHAR > tstring
Definition: tchar.hpp:27
size_c< std::size_t > size
Definition: size.hpp:616
int filter_level(uint8_t min, uint8_t max, int Gamma, uint8_t Aftermin, uint8_t Aftermax)
Definition: texture2d.hpp:102
texture2d DerivationGraph(int SrcX, int SrcY, int Width, int Height, const texture2d &SrcGraphHandle) DXLE_NOEXCEPT_OR_NOTHROW
指定のグラフィックの指定部分だけを抜き出して新たなグラフィックを作成する
Definition: texture2d.hpp:591
derivative_texture2d LoadDivGraph(const TCHAR *FileName, int AllNum, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag)
画像ファイルを分割してグラフィックハンドルを作成する
Definition: texture2d.hpp:238
std::unique_ptr< screen > cloneSc() const
画像を複製する
Definition: texture2d.hpp:137
derivative_texture2d(derivative_texture2d &&) DXLE_NOEXCEPT_IF((std derivative_texture2d & operator=(const derivative_texture2d &)=delete
Definition: texture2d.hpp:514
size_t tstrlen(const char *s)
Definition: tchar.hpp:29
static_derivative_texture2d & operator=(const static_derivative_texture2d &)=delete
Definition: cast_if.hpp:12
static screen MakeScreen(int SizeX, int SizeY, bool UseAlphaChannel=false) DXLE_NOEXCEPT_OR_NOTHROW
SetDrawScreen で描画対象にできるグラフィックを作成する
Definition: texture2d.hpp:345
void LoadDivGraph_impl(OutFunc &&out_func, BuffT *HandleBuf, const TCHAR *FileName, int AllNum, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag)
画像ファイルを分割してグラフィックハンドルを作成する
Definition: texture2d.hpp:35
void load(const TCHAR *FileName, int AllNum, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag=false)
Definition: texture2d.hpp:212
int filter_mono(int16_t Cb, int16_t Cr)
Definition: texture2d.hpp:78
描画可能画像クラス
Definition: texture2d.hpp:334
int filter_HSB(bool HueType, int16_t Hue, int Saturation, int16_t Bright)
Definition: texture2d.hpp:94
void load(const TCHAR *FileName, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag=false)
Definition: texture2d.hpp:172
#define DXLE_GET_LOCK(mtx)
Definition: thread.hpp:26
screen & draw_on_this(Func_T &&draw_func)
Definition: texture2d.hpp:115
static int GetTextureRawHandle(const texture2d &)
Definition: texture2d.hpp:53
#define DXLE_NOEXCEPT_IF(COND)
Definition: suffix.hpp:107
int filter_bright_clip(bright_clip_mode clipmode, uint8_t clip_pram, unsigned int fillcolor, uint8_t fillalpha)
Definition: texture2d.hpp:90
int filter_down_scale(uint8_t DivNum)
Definition: texture2d.hpp:86
tstring GetGraphFilePath() const
グラフィックが画像ファイルから読み込まれていた場合、その画像のファイルパスを取得する ...
Definition: texture2d.hpp:68
DXLE_CONSTEXPR static_derivative_texture2d() DXLE_NOEXCEPT_OR_NOTHROW
Definition: texture2d.hpp:439
#define DXLE_NOEXCEPT_OR_NOTHROW
Definition: suffix.hpp:94
derivative_texture2d LoadDivGraph(const tstring &FileName, int AllNum, const dxle::sizei &Num, const dxle::sizei &Size, bool NotUse3DFlag)
画像ファイルを分割してグラフィックハンドルを作成する
Definition: texture2d.hpp:242
int filter_gaussian(uint16_t PixelWidth, int Param)
Definition: texture2d.hpp:82
bright_clip_mode
for filter_bright_clip(texture2d and screen_c )
Definition: texture2d.hpp:54
virtual std::unique_ptr< texture2d > clone() const
画像を複製する
Definition: texture2d.hpp:62