StdDefine.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #ifndef __IMAGESTONE_STANDARD_DEFINE_HEADER_H__
  2. #define __IMAGESTONE_STANDARD_DEFINE_HEADER_H__
  3. //=============================================================================
  4. // compiler interrelated
  5. //=============================================================================
  6. #ifdef _MSC_VER
  7. #pragma once
  8. #pragma warning (disable : 4786) // identifier was truncated to '255' characters in the browser information
  9. #endif
  10. //=============================================================================
  11. // namespace macro
  12. //=============================================================================
  13. #ifdef IMAGESTONE_USE_NAMESPACE
  14. #define IMAGESTONE_NAMESPACE_START namespace IMAGESTONE{
  15. #define IMAGESTONE_NAMESPACE_END } // end of namespace
  16. #else
  17. #define IMAGESTONE_NAMESPACE_START
  18. #define IMAGESTONE_NAMESPACE_END
  19. #endif
  20. //=============================================================================
  21. // basic function
  22. //=============================================================================
  23. template<class T> inline const T& FMax (const T& _X, const T& _Y) {return (_X < _Y ? _Y : _X);}
  24. template<class T> inline const T& FMin (const T& _X, const T& _Y) {return (_Y < _X ? _Y : _X);}
  25. template<class T> inline void FSwap (T& t1, T& t2) { const T tmp=t1 ; t1=t2 ; t2=tmp ;}
  26. template<class T> inline T FSquare (const T& nValue) {return nValue*nValue ;}
  27. // bound in [tLow, tHigh]
  28. template<class T> inline T FClamp (const T& tValue, const T& tLow, const T& tHigh) {return FMax (tLow, FMin (tHigh, tValue)) ;}
  29. inline int FClamp0255 (int nValue) {return FClamp (nValue, 0, 0xFF) ;}
  30. // round double to int
  31. inline int FRound (const double& x)
  32. {
  33. if (x > 0.0)
  34. return (int)(x + 0.5) ;
  35. else
  36. return (int)(x - 0.5) ;
  37. }
  38. #define LIB_PI 3.1415926535897932384626433832795
  39. #define LIB_2PI (2.0*LIB_PI)
  40. /// angle ==> radian
  41. inline double AngleToRadian (int nAngle) {return LIB_PI * nAngle / 180.0;}
  42. /// radian ==> angle
  43. inline int RadianToAngle (double dRadian) {return (int)(180.0 * dRadian / LIB_PI);}
  44. // hypotenuse, c2 = a2 + b2
  45. template<class T> inline T FHypot (const T& x, const T& y) {
  46. return (T)sqrt (double(x*x) + double(y*y)) ;
  47. }
  48. //=============================================================================
  49. // include header
  50. //=============================================================================
  51. #ifdef WIN32
  52. #include <windows.h>
  53. #include <comdef.h>
  54. #include <TCHAR.H>
  55. #ifdef PCL_3RD_LIBRARY_USE_GDIPLUS
  56. // define for GDI+
  57. #if _MSC_VER > 1200
  58. // for VC7 and latter
  59. #include <GdiPlus.h>
  60. #pragma comment (lib, "GdiPlus.lib")
  61. #else
  62. // for VC6
  63. #define ULONG_PTR ULONG
  64. #include "../lib/gdiplus/Include/gdiplus.h"
  65. #endif
  66. #endif // PCL_3RD_LIBRARY_USE_GDIPLUS
  67. #else
  68. #include "FLib_Macro.h"
  69. #endif // WIN32
  70. #ifdef PCL_3RD_LIBRARY_USE_FREEIMAGE
  71. #include "../lib/FreeImage/Dist/FreeImage.h"
  72. #endif // PCL_3RD_LIBRARY_USE_FREEIMAGE
  73. #include <stdlib.h>
  74. #include <stdio.h>
  75. #include <math.h>
  76. #include <float.h>
  77. #include <memory.h>
  78. #include <string.h>
  79. #include <string>
  80. #include <sstream>
  81. #include "PCL_array.h"
  82. #include "PCL_TT_Convertor.h"
  83. #include "PCL_interface_composite.h"
  84. #include "PCL_interface_lazyobj.h"
  85. #include "PCL_interface_undo.h"
  86. #include "FTimeCount.h"
  87. #include "ObjProgress.h"
  88. #ifndef VC60 // error C2039: “auto_ptr”: 不是“std”的成员
  89. #include <memory>
  90. using namespace std;
  91. #endif
  92. //=============================================================================
  93. // avoid memory big/little endian
  94. //=============================================================================
  95. #define PCL_R(p) (((RGBQUAD*)(p))->rgbRed)
  96. #define PCL_G(p) (((RGBQUAD*)(p))->rgbGreen)
  97. #define PCL_B(p) (((RGBQUAD*)(p))->rgbBlue)
  98. #define PCL_A(p) (((RGBQUAD*)(p))->rgbReserved)
  99. template<class T> inline RGBQUAD PCL_RGBA (T r, T g, T b, T a=0xFF)
  100. {
  101. RGBQUAD cr ;
  102. PCL_R(&cr)=r ; PCL_G(&cr)=g ; PCL_B(&cr)=b ; PCL_A(&cr)=a ;
  103. return cr ;
  104. }
  105. //=============================================================================
  106. // 结构
  107. //=============================================================================
  108. struct POINT_F // 浮点数POINT
  109. {
  110. double x ;
  111. double y ;
  112. };
  113. //=============================================================================
  114. inline long RECTWIDTH(const RECT & fRect) {return fRect.right - fRect.left;}
  115. inline long RECTHEIGHT(const RECT & fRect) {return fRect.bottom - fRect.top;}
  116. // 两点距离的平方
  117. inline int FSquarePointDistance (const POINT& pt1, const POINT& pt2) {
  118. return FSquare(pt1.x - pt2.x) + FSquare(pt1.y - pt2.y) ;
  119. }
  120. // 三点夹角 [0,n]
  121. inline double FPointAngle (const POINT& pt1, const POINT& pt2, const POINT& ptCenter) {
  122. const int nPt1 = FSquarePointDistance (pt1, ptCenter),
  123. nPt2 = FSquarePointDistance (pt2, ptCenter) ;
  124. if ((nPt1 == 0) || (nPt2 == 0))
  125. return -LIB_2PI ; // pt1/pt2 == center
  126. const int nTemp = nPt1 + nPt2 - FSquarePointDistance (pt1, pt2) ;
  127. return acos (nTemp / (2.0*sqrt((double)nPt1)*sqrt((double)nPt2))) ;
  128. }
  129. // 三点夹角 [0,2n],pt1 --> pt2 的顺时针方向
  130. inline double FPointAngleClockwise (const POINT &pt1, const POINT &pt2, const POINT &ptCenter) {
  131. const double fAngle = FPointAngle (pt1, pt2, ptCenter) ;
  132. if (fAngle < 0.0) // 有一点和center重合
  133. return fAngle ;
  134. if (pt1.x == ptCenter.x) // 垂直情况
  135. return (pt2.x >= ptCenter.x) ? fAngle : (LIB_PI - fAngle) ;
  136. // 判断在直线上还是下
  137. const double yLine = ptCenter.y + (pt2.x - ptCenter.x) * (ptCenter.y - pt1.y) / (double)(ptCenter.x - pt1.x) ;
  138. if (pt2.y > yLine)
  139. return (pt1.x >= ptCenter.x) ? fAngle : (LIB_2PI - fAngle) ;
  140. return (pt1.x >= ptCenter.x) ? (LIB_2PI - fAngle) : fAngle ;
  141. }
  142. // pt1绕ptCenter顺时针旋转 [0, 2n] 后的坐标
  143. inline POINT FClockwisePoint (POINT pt1, POINT_F ptCenter, double fAngle)
  144. {
  145. double dx = pt1.x - ptCenter.x, dy = -pt1.y + ptCenter.y,
  146. cost = cos(fAngle), sint = sin(fAngle) ;
  147. POINT pt = {FRound(ptCenter.x + (dx*cost + dy*sint)),
  148. FRound(ptCenter.y - (dy*cost - dx*sint))} ;
  149. return pt ;
  150. }
  151. // pt1绕ptCenter顺时针旋转 [0, 2n] 后的坐标
  152. inline POINT FClockwisePoint (POINT pt1, POINT ptCenter, double fAngle) {
  153. POINT_F ptCen = {ptCenter.x, ptCenter.y} ;
  154. return FClockwisePoint (pt1, ptCen, fAngle) ;
  155. }
  156. inline bool IsRectInRect (const RECT & rcOut, const RECT & rcIn) {
  157. return (rcIn.left >= rcOut.left) && (rcIn.top >= rcOut.top) && (rcIn.right <= rcOut.right) && (rcIn.bottom <= rcOut.bottom) ;
  158. }
  159. //=============================================================================
  160. // 坐标系统
  161. //=============================================================================
  162. enum AXIS_SYS
  163. {
  164. AXIS_X,
  165. AXIS_Y,
  166. AXIS_Z,
  167. };
  168. //=============================================================================
  169. // 平面8个方向
  170. //=============================================================================
  171. enum DIRECT_SYS
  172. {
  173. DIRECT_TOP_LEFT,
  174. DIRECT_TOP,
  175. DIRECT_TOP_RIGHT,
  176. DIRECT_LEFT,
  177. DIRECT_RIGHT,
  178. DIRECT_BOTTOM_LEFT,
  179. DIRECT_BOTTOM,
  180. DIRECT_BOTTOM_RIGHT,
  181. };
  182. //=============================================================================
  183. // 渐变过渡类型
  184. //=============================================================================
  185. enum REPEAT_MODE
  186. {
  187. REPEAT_NONE = 0,
  188. REPEAT_SAWTOOTH = 1, // 锯齿波重复
  189. REPEAT_TRIANGULAR = 2, // 三角波重复
  190. };
  191. //=============================================================================
  192. // 插值模式
  193. //=============================================================================
  194. enum INTERPOLATION_TYPE
  195. {
  196. INTERPOLATION_NONE,
  197. INTERPOLATION_BILINEAR,
  198. };
  199. //=============================================================================
  200. // 逻辑操作
  201. //=============================================================================
  202. enum LOGICAL_OP
  203. {
  204. LOGI_AND, // c = a & b
  205. LOGI_OR, // c = a | b
  206. LOGI_XOR, // c = a ^ b
  207. LOGI_ADD, // c = a + b
  208. LOGI_SUB, // c = a - b
  209. LOGI_MUL, // c = a * b
  210. LOGI_DIV, // c = a / b
  211. LOGI_LOG, // c = log(a)
  212. LOGI_EXP, // c = exp(a)
  213. LOGI_SQRT, // c = sqrt(a)
  214. LOGI_TRIG, // c = sin/cos/tan(a)
  215. LOGI_INVERT,// c = (2B - 1) - a
  216. LOGI_SEL_ADD, // 用在区域处理里
  217. LOGI_SEL_SUB, // 用在区域处理里
  218. };
  219. //=============================================================================
  220. // 16 位色的掩码
  221. //=============================================================================
  222. #define MASK16_RED_565 0xF800
  223. #define MASK16_GREEN_565 0x07E0
  224. #define MASK16_BLUE_565 0x001F
  225. #define MASK16_RED_555 0x7C00
  226. #define MASK16_GREEN_555 0x03E0
  227. #define MASK16_BLUE_555 0x001F
  228. //=============================================================================
  229. // image format
  230. //=============================================================================
  231. enum IMAGE_TYPE
  232. {
  233. IMG_UNKNOW,
  234. IMG_BMP,
  235. IMG_PCX,
  236. IMG_JPG,
  237. IMG_GIF,
  238. IMG_TGA,
  239. IMG_TIF,
  240. IMG_PNG,
  241. IMG_PSD,
  242. IMG_ICO,
  243. IMG_XPM,
  244. IMG_PHOXO,
  245. IMG_CUSTOM,
  246. };
  247. //=============================================================================
  248. // RGBA通道,这样的定义值是为了mask
  249. //=============================================================================
  250. enum IMAGE_CHANNEL
  251. {
  252. CHANNEL_RED = 1 << 0,// 0x01,
  253. CHANNEL_GREEN = 1 << 1,// 0x02,
  254. CHANNEL_BLUE = 1 << 2,// 0x04,
  255. CHANNEL_ALPHA = 1 << 3,// 0x08,
  256. CHANNEL_RGB = CHANNEL_RED|CHANNEL_GREEN|CHANNEL_BLUE,// 0x07,
  257. CHANNEL_RGBA = CHANNEL_RGB|CHANNEL_ALPHA,// 0x0F,
  258. CHANNEL_GRAY = 1 << 4,// 0x10
  259. };
  260. //=============================================================================
  261. // 线样式
  262. //=============================================================================
  263. enum LINE_STYLE
  264. {
  265. LINE_STYLE_SOLID = 0,
  266. LINE_STYLE_DASH = 1,
  267. LINE_STYLE_DOT = 2,
  268. };
  269. //=============================================================================
  270. // 色调区域(这三个值的顺序一定不能变)
  271. //=============================================================================
  272. enum TONE_REGION
  273. {
  274. /// shadow region of image.
  275. TONE_SHADOWS = 0,
  276. /// midtone region of image.
  277. TONE_MIDTONES = 1,
  278. /// highlight region of image.
  279. TONE_HIGHLIGHTS = 2,
  280. };
  281. //=============================================================================
  282. // 阴影数据结构
  283. //=============================================================================
  284. struct SHADOWDATA
  285. {
  286. int nSmooth ; // 模糊度
  287. RGBQUAD crShadow ; // 颜色/硬度
  288. int nAlpha ; // 透明度
  289. int nOffsetX ; // X偏移
  290. int nOffsetY ; // Y偏移
  291. SHADOWDATA()
  292. {
  293. nOffsetX = nOffsetY = 5 ;
  294. crShadow = PCL_RGBA(75,75,75) ;
  295. nAlpha = 75 ;
  296. nSmooth = 5 ;
  297. }
  298. };
  299. //=============================================================================
  300. #endif