StdDefine.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. //=============================================================================
  89. // avoid memory big/little endian
  90. //=============================================================================
  91. #define PCL_R(p) (((RGBQUAD*)(p))->rgbRed)
  92. #define PCL_G(p) (((RGBQUAD*)(p))->rgbGreen)
  93. #define PCL_B(p) (((RGBQUAD*)(p))->rgbBlue)
  94. #define PCL_A(p) (((RGBQUAD*)(p))->rgbReserved)
  95. template<class T> inline RGBQUAD PCL_RGBA (T r, T g, T b, T a=0xFF)
  96. {
  97. RGBQUAD cr ;
  98. PCL_R(&cr)=r ; PCL_G(&cr)=g ; PCL_B(&cr)=b ; PCL_A(&cr)=a ;
  99. return cr ;
  100. }
  101. //=============================================================================
  102. // 结构
  103. //=============================================================================
  104. struct POINT_F // 浮点数POINT
  105. {
  106. double x ;
  107. double y ;
  108. };
  109. //=============================================================================
  110. inline long RECTWIDTH(const RECT & fRect) {return fRect.right - fRect.left;}
  111. inline long RECTHEIGHT(const RECT & fRect) {return fRect.bottom - fRect.top;}
  112. // 两点距离的平方
  113. inline int FSquarePointDistance (const POINT& pt1, const POINT& pt2) {
  114. return FSquare(pt1.x - pt2.x) + FSquare(pt1.y - pt2.y) ;
  115. }
  116. // 三点夹角 [0,n]
  117. inline double FPointAngle (const POINT& pt1, const POINT& pt2, const POINT& ptCenter) {
  118. const int nPt1 = FSquarePointDistance (pt1, ptCenter),
  119. nPt2 = FSquarePointDistance (pt2, ptCenter) ;
  120. if ((nPt1 == 0) || (nPt2 == 0))
  121. return -LIB_2PI ; // pt1/pt2 == center
  122. const int nTemp = nPt1 + nPt2 - FSquarePointDistance (pt1, pt2) ;
  123. return acos (nTemp / (2.0*sqrt((double)nPt1)*sqrt((double)nPt2))) ;
  124. }
  125. // 三点夹角 [0,2n],pt1 --> pt2 的顺时针方向
  126. inline double FPointAngleClockwise (const POINT &pt1, const POINT &pt2, const POINT &ptCenter) {
  127. const double fAngle = FPointAngle (pt1, pt2, ptCenter) ;
  128. if (fAngle < 0.0) // 有一点和center重合
  129. return fAngle ;
  130. if (pt1.x == ptCenter.x) // 垂直情况
  131. return (pt2.x >= ptCenter.x) ? fAngle : (LIB_PI - fAngle) ;
  132. // 判断在直线上还是下
  133. const double yLine = ptCenter.y + (pt2.x - ptCenter.x) * (ptCenter.y - pt1.y) / (double)(ptCenter.x - pt1.x) ;
  134. if (pt2.y > yLine)
  135. return (pt1.x >= ptCenter.x) ? fAngle : (LIB_2PI - fAngle) ;
  136. return (pt1.x >= ptCenter.x) ? (LIB_2PI - fAngle) : fAngle ;
  137. }
  138. // pt1绕ptCenter顺时针旋转 [0, 2n] 后的坐标
  139. inline POINT FClockwisePoint (POINT pt1, POINT_F ptCenter, double fAngle)
  140. {
  141. double dx = pt1.x - ptCenter.x, dy = -pt1.y + ptCenter.y,
  142. cost = cos(fAngle), sint = sin(fAngle) ;
  143. POINT pt = {FRound(ptCenter.x + (dx*cost + dy*sint)),
  144. FRound(ptCenter.y - (dy*cost - dx*sint))} ;
  145. return pt ;
  146. }
  147. // pt1绕ptCenter顺时针旋转 [0, 2n] 后的坐标
  148. inline POINT FClockwisePoint (POINT pt1, POINT ptCenter, double fAngle) {
  149. POINT_F ptCen = {ptCenter.x, ptCenter.y} ;
  150. return FClockwisePoint (pt1, ptCen, fAngle) ;
  151. }
  152. inline bool IsRectInRect (const RECT & rcOut, const RECT & rcIn) {
  153. return (rcIn.left >= rcOut.left) && (rcIn.top >= rcOut.top) && (rcIn.right <= rcOut.right) && (rcIn.bottom <= rcOut.bottom) ;
  154. }
  155. //=============================================================================
  156. // 坐标系统
  157. //=============================================================================
  158. enum AXIS_SYS
  159. {
  160. AXIS_X,
  161. AXIS_Y,
  162. AXIS_Z,
  163. };
  164. //=============================================================================
  165. // 平面8个方向
  166. //=============================================================================
  167. enum DIRECT_SYS
  168. {
  169. DIRECT_TOP_LEFT,
  170. DIRECT_TOP,
  171. DIRECT_TOP_RIGHT,
  172. DIRECT_LEFT,
  173. DIRECT_RIGHT,
  174. DIRECT_BOTTOM_LEFT,
  175. DIRECT_BOTTOM,
  176. DIRECT_BOTTOM_RIGHT,
  177. };
  178. //=============================================================================
  179. // 渐变过渡类型
  180. //=============================================================================
  181. enum REPEAT_MODE
  182. {
  183. REPEAT_NONE = 0,
  184. REPEAT_SAWTOOTH = 1, // 锯齿波重复
  185. REPEAT_TRIANGULAR = 2, // 三角波重复
  186. };
  187. //=============================================================================
  188. // 插值模式
  189. //=============================================================================
  190. enum INTERPOLATION_TYPE
  191. {
  192. INTERPOLATION_NONE,
  193. INTERPOLATION_BILINEAR,
  194. };
  195. //=============================================================================
  196. // 逻辑操作
  197. //=============================================================================
  198. enum LOGICAL_OP
  199. {
  200. LOGI_AND, // c = a & b
  201. LOGI_OR, // c = a | b
  202. LOGI_XOR, // c = a ^ b
  203. LOGI_ADD, // c = a + b
  204. LOGI_SUB, // c = a - b
  205. LOGI_MUL, // c = a * b
  206. LOGI_DIV, // c = a / b
  207. LOGI_LOG, // c = log(a)
  208. LOGI_EXP, // c = exp(a)
  209. LOGI_SQRT, // c = sqrt(a)
  210. LOGI_TRIG, // c = sin/cos/tan(a)
  211. LOGI_INVERT,// c = (2B - 1) - a
  212. LOGI_SEL_ADD, // 用在区域处理里
  213. LOGI_SEL_SUB, // 用在区域处理里
  214. };
  215. //=============================================================================
  216. // 16 位色的掩码
  217. //=============================================================================
  218. #define MASK16_RED_565 0xF800
  219. #define MASK16_GREEN_565 0x07E0
  220. #define MASK16_BLUE_565 0x001F
  221. #define MASK16_RED_555 0x7C00
  222. #define MASK16_GREEN_555 0x03E0
  223. #define MASK16_BLUE_555 0x001F
  224. //=============================================================================
  225. // image format
  226. //=============================================================================
  227. enum IMAGE_TYPE
  228. {
  229. IMG_UNKNOW,
  230. IMG_BMP,
  231. IMG_PCX,
  232. IMG_JPG,
  233. IMG_GIF,
  234. IMG_TGA,
  235. IMG_TIF,
  236. IMG_PNG,
  237. IMG_PSD,
  238. IMG_ICO,
  239. IMG_XPM,
  240. IMG_PHOXO,
  241. IMG_CUSTOM,
  242. };
  243. //=============================================================================
  244. // RGBA通道,这样的定义值是为了mask
  245. //=============================================================================
  246. enum IMAGE_CHANNEL
  247. {
  248. CHANNEL_RED = 1 << 0,// 0x01,
  249. CHANNEL_GREEN = 1 << 1,// 0x02,
  250. CHANNEL_BLUE = 1 << 2,// 0x04,
  251. CHANNEL_ALPHA = 1 << 3,// 0x08,
  252. CHANNEL_RGB = CHANNEL_RED|CHANNEL_GREEN|CHANNEL_BLUE,// 0x07,
  253. CHANNEL_RGBA = CHANNEL_RGB|CHANNEL_ALPHA,// 0x0F,
  254. CHANNEL_GRAY = 1 << 4,// 0x10
  255. };
  256. //=============================================================================
  257. // 线样式
  258. //=============================================================================
  259. enum LINE_STYLE
  260. {
  261. LINE_STYLE_SOLID = 0,
  262. LINE_STYLE_DASH = 1,
  263. LINE_STYLE_DOT = 2,
  264. };
  265. //=============================================================================
  266. // 色调区域(这三个值的顺序一定不能变)
  267. //=============================================================================
  268. enum TONE_REGION
  269. {
  270. /// shadow region of image.
  271. TONE_SHADOWS = 0,
  272. /// midtone region of image.
  273. TONE_MIDTONES = 1,
  274. /// highlight region of image.
  275. TONE_HIGHLIGHTS = 2,
  276. };
  277. //=============================================================================
  278. // 阴影数据结构
  279. //=============================================================================
  280. struct SHADOWDATA
  281. {
  282. int nSmooth ; // 模糊度
  283. RGBQUAD crShadow ; // 颜色/硬度
  284. int nAlpha ; // 透明度
  285. int nOffsetX ; // X偏移
  286. int nOffsetY ; // Y偏移
  287. SHADOWDATA()
  288. {
  289. nOffsetX = nOffsetY = 5 ;
  290. crShadow = PCL_RGBA(75,75,75) ;
  291. nAlpha = 75 ;
  292. nSmooth = 5 ;
  293. }
  294. };
  295. //=============================================================================
  296. #endif