ScaleFlat.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // This is the scaling module for uncompressed 8-bit images
  19. // It will hopefully be a strong candidate forthe RSPiX inliner.
  20. //
  21. // Anticipating this, it will do ROW blitting as separate inline
  22. // functions. Whatcha gonna do, man?
  23. //
  24. #ifdef PATHS_IN_INCLUDES
  25. #include "GREEN/BLiT/BLIT.H"
  26. #include "GREEN/BLiT/_BlitInt.H"
  27. // #include "GREEN/BLiT/_ic.h"
  28. #else
  29. #include "BLIT.H"
  30. #include "_BlitInt.H"
  31. // #include "_ic.h"
  32. #endif
  33. // For now, do the shrink case only...
  34. // This algorithm is based entirely on 15-bit unsigned fractions, allowing
  35. // scaling by 30,000 times without overflow! A bit of overkil, but hey.
  36. // I am leaving in the possibility of mirroring...
  37. //-------- These macros could by inlined once the inliner is on line:
  38. //=========================================== SHRINK, DEST BASED....
  39. // This is pixel size independent:
  40. // pSrc always increments rightwards...
  41. //
  42. #define INC_FRAC_H(pSrc,sDel,sInc,sNum,sDen) \
  43. pSrc+=sDel; sNum+=sInc; if (sNum >= sDen) { sNum -= sDen; pSrc++; }
  44. #define INC_FRAC_V(pSrc,sDel,sInc,sNum,lSrcP,sDen) \
  45. pSrc+=sDel; sNum+=sInc; if (sNum >= sDen) { sNum -= sDen; pSrc+=lSrcP; }
  46. #define SET_PIX_OPAQUE(pSrc,pDst) \
  47. *pDst = *pSrc;
  48. #define SET_PIX_CLEAR(pSrc,pDst,chroma,tempPix) \
  49. if ( (tempPix = *pSrc) != chroma) *pDst = *pSrc;
  50. // sSmall is the denominator..
  51. #define INIT_IMPROPER_FRACTION_H(sSmall,sLarge,sDel,sInc,sNumi) \
  52. sDel = sLarge / sSmall; sInc = sLarge - sSmall * sDel; sNumi = (sSmall>>1);
  53. // sSmall is the denominator..
  54. #define INIT_IMPROPER_FRACTION_V(sSmall,sLarge,lDel,sInc,sNumi,lSrcP) \
  55. lDel = (sLarge / sSmall); sInc = sLarge - sSmall * lDel; sNumi = (sSmall>>1); lDel *= lSrcP;
  56. // The left show value is the # of pixels from sCount to show right...
  57. // It may only be followed with a single command!
  58. // It assumes sCound has ALREADY been decremented!
  59. //
  60. #define LCLIP_PIX(sCount,sShow) \
  61. if (sCount < sShow)
  62. //=========================================== MAGNIFY, DEST BASED....=================
  63. // (Source based magnify is faster, but also harder...)
  64. //
  65. // In this rare configuration, there is no del!
  66. //
  67. // sLarge is the denominator.... DO NOT USE FOR 1 to 1!
  68. // sSmall is the incrementor (sInc!)
  69. //
  70. #define INIT_PROPER_FRACTION(sLarge,sNumi) \
  71. sNumi = (sLarge >> 1);
  72. // sLarge = denominator, sSmall = sInc
  73. #define INC_PFRAC_H(pSrc,sInc,sNum,sDen) \
  74. sNum += sInc; if (sNum >= sDen) { sNum -= sDen; pSrc++; }
  75. // sLarge = denominator, sSmall = sInc
  76. #define INC_PFRAC_V(pSrc,sInc,sNum,sDen,lSrcP) \
  77. sNum += sInc; if (sNum >= sDen) { sNum -= sDen; pSrc+=lSrcP; }
  78. //====================================================================================
  79. // If we break out a million little blit's, than we can combine all the if's into one
  80. // bit switch statement.
  81. // I believe the memptrs are to the UNCLIPPED rects...
  82. //
  83. inline void _Blit_HS_VS_C(
  84. UCHAR* pSrc,long lSrcP,short sSrcW,short sSrcH,
  85. UCHAR* pDst,long lDstP,short sDstW,short sDstH,
  86. short sClipL,short sClipT,short sClipR,short sClipB,
  87. short sMirrorH,short sMirrorV)
  88. {
  89. //-------------------------------------------------------------------------
  90. // Set up vertical variables:
  91. //
  92. UCHAR* pSrcLine = pSrc,*pDstLine = pDst;
  93. long lDelMemY;
  94. short sIncY,sNumY,sClipH;
  95. if (sMirrorV == -1) lDstP = -lDstP; // make sure pDst is correctly positioned
  96. // ASSUME SHRINKING FOR NOW:
  97. //************ THIS CHANGES FOR MAGNIFY!
  98. INIT_IMPROPER_FRACTION_V(sDstH,sSrcH,lDelMemY,sIncY,sNumY,lSrcP) // sDstH is the numerator
  99. sClipH = sDstH - sClipB - sClipT; // Fully clipped...
  100. //-------------------------------------------------------------------------
  101. // Set up horizontal variables:
  102. //
  103. short sDelX,sIncX,sNumX,sClipW,sShowW;
  104. // ASSUME SHRINKING FOR NOW:
  105. INIT_IMPROPER_FRACTION_H(sDstW,sSrcW,sDelX,sIncX,sNumX) // sDstW is the numerator
  106. sClipW = sDstW - sClipR; // right clip...
  107. sShowW = sClipW - sClipL;
  108. short i;
  109. //-------------------------------------------------------------------------
  110. // Do vertical clipping:
  111. if (sClipT)
  112. while (sClipT--)
  113. {
  114. // Do a vertical move:
  115. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  116. pDstLine += lDstP; // allow for vertical mirroring..
  117. }
  118. //-------------------------------------------------------------------------
  119. // Do horizontal clipping...
  120. if (sClipL)
  121. {
  122. while (sClipH--)
  123. {
  124. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  125. sNumX = (sDstW>>1);
  126. UCHAR ucPix;
  127. i = sClipW;
  128. while (i--)
  129. {
  130. if (i < sShowW)
  131. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  132. INC_FRAC_H(pSrc,sDelX,sIncX,sNumX,sDstW)
  133. pDst += sMirrorH;
  134. }
  135. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  136. pDstLine += lDstP; // allow for vertical mirroring..
  137. }
  138. }
  139. else // no horizontal clipping:
  140. {
  141. while (sClipH--)
  142. {
  143. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  144. sNumX = (sDstW>>1);
  145. i = sClipW;
  146. UCHAR ucPix;
  147. while (i--)
  148. {
  149. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  150. INC_FRAC_H(pSrc,sDelX,sIncX,sNumX,sDstW)
  151. pDst += sMirrorH;
  152. }
  153. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  154. pDstLine += lDstP; // allow for vertical mirroring..
  155. }
  156. }
  157. }
  158. //====================================================================================
  159. // If we break out a million little blit's, than we can combine all the if's into one
  160. // bit switch statement.
  161. // I believe the memptrs are to the UNCLIPPED rects...
  162. //
  163. inline void _Blit_HM_VM_C(
  164. UCHAR* pSrc,long lSrcP,short sSrcW,short sSrcH,
  165. UCHAR* pDst,long lDstP,short sDstW,short sDstH,
  166. short sClipL,short sClipT,short sClipR,short sClipB,
  167. short sMirrorH,short sMirrorV)
  168. {
  169. //-------------------------------------------------------------------------
  170. // Set up vertical variables:
  171. //
  172. UCHAR* pSrcLine = pSrc,*pDstLine = pDst;
  173. short sNumY,sClipH;
  174. if (sMirrorV == -1) lDstP = -lDstP; // make sure pDst is correctly positioned
  175. // ASSUME ENLARGING FOR NOW:
  176. //************ THIS CHANGES FOR SHRINK!
  177. INIT_PROPER_FRACTION(sDstH,sNumY) // sDstH is the denominator
  178. sClipH = sDstH - sClipB - sClipT; // Fully clipped...
  179. //-------------------------------------------------------------------------
  180. // Set up horizontal variables:
  181. //
  182. short sNumX,sClipW,sShowW;
  183. // ASSUME ENLARGING FOR NOW:
  184. INIT_PROPER_FRACTION(sDstW,sNumX) // sDstW is the denominator
  185. sClipW = sDstW - sClipR; // right clip...
  186. sShowW = sClipW - sClipL;
  187. short i;
  188. //-------------------------------------------------------------------------
  189. // Do vertical clipping:
  190. if (sClipT)
  191. while (sClipT--)
  192. {
  193. // Do a vertical move:
  194. // sIncY = sSrcH, sDstY = denominator
  195. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  196. pDstLine += lDstP; // allow for vertical mirroring..
  197. }
  198. //-------------------------------------------------------------------------
  199. // Do horizontal clipping...
  200. if (sClipL)
  201. {
  202. while (sClipH--)
  203. {
  204. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  205. sNumX = (sDstW>>1);
  206. UCHAR ucPix;
  207. i = sClipW;
  208. while (i--)
  209. {
  210. if (i < sShowW)
  211. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  212. INC_PFRAC_H(pSrc,sSrcW,sNumX,sDstW)
  213. pDst += sMirrorH;
  214. }
  215. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  216. pDstLine += lDstP; // allow for vertical mirroring..
  217. }
  218. }
  219. else // no horizontal clipping:
  220. {
  221. while (sClipH--)
  222. {
  223. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  224. sNumX = (sDstW>>1);
  225. i = sClipW;
  226. UCHAR ucPix;
  227. while (i--)
  228. {
  229. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  230. INC_PFRAC_H(pSrc,sSrcW,sNumX,sDstW)
  231. pDst += sMirrorH;
  232. }
  233. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  234. pDstLine += lDstP; // allow for vertical mirroring..
  235. }
  236. }
  237. }
  238. //====================================================================================
  239. // If we break out a million little blit's, than we can combine all the if's into one
  240. // bit switch statement.
  241. // I believe the memptrs are to the UNCLIPPED rects...
  242. //
  243. inline void _Blit_HS_VM_C(
  244. UCHAR* pSrc,long lSrcP,short sSrcW,short sSrcH,
  245. UCHAR* pDst,long lDstP,short sDstW,short sDstH,
  246. short sClipL,short sClipT,short sClipR,short sClipB,
  247. short sMirrorH,short sMirrorV)
  248. {
  249. //-------------------------------------------------------------------------
  250. // Set up vertical variables:
  251. //
  252. UCHAR* pSrcLine = pSrc,*pDstLine = pDst;
  253. short sNumY,sClipH;
  254. if (sMirrorV == -1) lDstP = -lDstP; // make sure pDst is correctly positioned
  255. // ASSUME ENLARGING FOR NOW:
  256. //************ THIS CHANGES FOR SHRINK!
  257. INIT_PROPER_FRACTION(sDstH,sNumY) // sDstH is the denominator
  258. sClipH = sDstH - sClipB - sClipT; // Fully clipped...
  259. //-------------------------------------------------------------------------
  260. // Set up horizontal variables:
  261. //
  262. short sDelX,sIncX,sNumX,sClipW,sShowW;
  263. // ASSUME SHRINKING FOR NOW:
  264. INIT_IMPROPER_FRACTION_H(sDstW,sSrcW,sDelX,sIncX,sNumX) // sDstW is the numerator
  265. sClipW = sDstW - sClipR; // right clip...
  266. sShowW = sClipW - sClipL;
  267. short i;
  268. //-------------------------------------------------------------------------
  269. // Do vertical clipping:
  270. if (sClipT)
  271. while (sClipT--)
  272. {
  273. // Do a vertical move:
  274. // sIncY = sSrcH, sDstY = denominator
  275. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  276. pDstLine += lDstP; // allow for vertical mirroring..
  277. }
  278. //-------------------------------------------------------------------------
  279. // Do horizontal clipping...
  280. if (sClipL)
  281. {
  282. while (sClipH--)
  283. {
  284. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  285. sNumX = (sDstW>>1);
  286. UCHAR ucPix;
  287. i = sClipW;
  288. while (i--)
  289. {
  290. if (i < sShowW)
  291. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  292. INC_FRAC_H(pSrc,sDelX,sIncX,sNumX,sDstW)
  293. pDst += sMirrorH;
  294. }
  295. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  296. pDstLine += lDstP; // allow for vertical mirroring..
  297. }
  298. }
  299. else // no horizontal clipping:
  300. {
  301. while (sClipH--)
  302. {
  303. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  304. sNumX = (sDstW>>1);
  305. i = sClipW;
  306. UCHAR ucPix;
  307. while (i--)
  308. {
  309. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  310. INC_FRAC_H(pSrc,sDelX,sIncX,sNumX,sDstW)
  311. pDst += sMirrorH;
  312. }
  313. INC_PFRAC_V(pSrcLine,sSrcH,sNumY,sDstH,lSrcP)
  314. pDstLine += lDstP; // allow for vertical mirroring..
  315. }
  316. }
  317. }
  318. //====================================================================================
  319. // If we break out a million little blit's, than we can combine all the if's into one
  320. // bit switch statement.
  321. // I believe the memptrs are to the UNCLIPPED rects...
  322. //
  323. inline void _Blit_HM_VS_C(
  324. UCHAR* pSrc,long lSrcP,short sSrcW,short sSrcH,
  325. UCHAR* pDst,long lDstP,short sDstW,short sDstH,
  326. short sClipL,short sClipT,short sClipR,short sClipB,
  327. short sMirrorH,short sMirrorV)
  328. {
  329. //-------------------------------------------------------------------------
  330. // Set up vertical variables:
  331. //
  332. UCHAR* pSrcLine = pSrc,*pDstLine = pDst;
  333. long lDelMemY;
  334. short sIncY,sNumY,sClipH;
  335. if (sMirrorV == -1) lDstP = -lDstP; // make sure pDst is correctly positioned
  336. // ASSUME SHRINKING FOR NOW:
  337. //************ THIS CHANGES FOR MAGNIFY!
  338. INIT_IMPROPER_FRACTION_V(sDstH,sSrcH,lDelMemY,sIncY,sNumY,lSrcP) // sDstH is the numerator
  339. sClipH = sDstH - sClipB - sClipT; // Fully clipped...
  340. //-------------------------------------------------------------------------
  341. // Set up horizontal variables:
  342. //
  343. short sNumX,sClipW,sShowW;
  344. // ASSUME ENLARGING FOR NOW:
  345. INIT_PROPER_FRACTION(sDstW,sNumX) // sDstW is the denominator
  346. sClipW = sDstW - sClipR; // right clip...
  347. sShowW = sClipW - sClipL;
  348. short i;
  349. //-------------------------------------------------------------------------
  350. // Do vertical clipping:
  351. if (sClipT)
  352. while (sClipT--)
  353. {
  354. // Do a vertical move:
  355. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  356. pDstLine += lDstP; // allow for vertical mirroring..
  357. }
  358. //-------------------------------------------------------------------------
  359. // Do horizontal clipping...
  360. if (sClipL)
  361. {
  362. while (sClipH--)
  363. {
  364. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  365. sNumX = (sDstW>>1);
  366. UCHAR ucPix;
  367. i = sClipW;
  368. while (i--)
  369. {
  370. if (i < sShowW)
  371. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  372. INC_PFRAC_H(pSrc,sSrcW,sNumX,sDstW)
  373. pDst += sMirrorH;
  374. }
  375. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  376. pDstLine += lDstP; // allow for vertical mirroring..
  377. }
  378. }
  379. else // no horizontal clipping:
  380. {
  381. while (sClipH--)
  382. {
  383. pSrc = pSrcLine; pDst = pDstLine; // synch position:
  384. sNumX = (sDstW>>1);
  385. i = sClipW;
  386. UCHAR ucPix;
  387. while (i--)
  388. {
  389. SET_PIX_CLEAR(pSrc,pDst,UCHAR(0),ucPix)
  390. INC_PFRAC_H(pSrc,sSrcW,sNumX,sDstW)
  391. pDst += sMirrorH;
  392. }
  393. INC_FRAC_V(pSrcLine,lDelMemY,sIncY,sNumY,lSrcP,sDstH)
  394. pDstLine += lDstP; // allow for vertical mirroring..
  395. }
  396. }
  397. }
  398. //-----------------------------------------------------------------------------------
  399. // templated overloads for selecting different inlines...
  400. typedef U32 CHOOSE_MAGNIFY;
  401. typedef S32 CHOOSE_SHRINK;
  402. typedef U32 CHOOSE_HCLIP;
  403. typedef S32 CHOOSE_NO_HCLIP;
  404. typedef U32 CHOOSE_OPAQUE;
  405. typedef S32 CHOOSE_TRANSPARENT;
  406. //-----------------------------------------------------------------------------------
  407. // at the internal level, assume all values have been verified..
  408. //
  409. inline short _rspBlit(UCHAR* pSrc,long lSrcP,short sSrcW,short sSrcH,
  410. UCHAR* pDst,long lDstP,short sDstW,short sDstH)
  411. {
  412. return 0;
  413. }
  414. // do the full transparent case with clipping:
  415. // (long version... overload shorter version...)
  416. // FOR THE DEMO, do ONLY shrinking, and do clipping AFTER shrinking.....
  417. //
  418. short rspBlitT(RImage* pimSrc,RImage* pimDst,RRect* prSrc,const RRect* prDst,
  419. const RRect* prDstClip,const RRect* prSrcClip)
  420. {
  421. #ifdef _DEBUG
  422. if (!pimSrc || !pimDst)
  423. {
  424. TRACE("rspBlitT: NULL images passed!\n");
  425. return -1;
  426. }
  427. // do type checking....
  428. //------------------------------------------------------------------------------
  429. if (!ImageIsUncompressed(pimSrc->m_type))
  430. {
  431. TRACE("rspBlitT: Only use this function with uncompressed Images.\n");
  432. return -1;
  433. }
  434. if (!ImageIsUncompressed(pimDst->m_type))
  435. {
  436. TRACE("rspBlitT: Only use this function with uncompressed Images.\n");
  437. return -1;
  438. }
  439. //------------------------------------------------------------------------------
  440. // do depth checking...
  441. //------------------------------------------------------------------------------
  442. if ((pimSrc->m_sDepth != 8) || (pimDst->m_sDepth != 8))
  443. {
  444. TRACE("rspBlitT: Currently, only 8-bit Images are fully supported.\n");
  445. return -1;
  446. }
  447. #endif
  448. //------------------------------------------------------------------------------
  449. // do optional source clipping
  450. //------------------------------------------------------------------------------
  451. // NOTE THAT THESE ARE THE WIDTH AND HEIGHT WHICH ARE ACTUALLY SCALED
  452. //
  453. short sSrcX = prSrc->sX, sSrcY = prSrc->sY, sSrcW = prSrc->sW, sSrcH = prSrc->sH;
  454. // TOO complex for now as it drastically alters the scaling...
  455. if (prSrcClip)
  456. {
  457. TRACE("rspBlitT: Source clipping not yet available...\n");
  458. return -1;
  459. }
  460. //------------------------------------------------------------------------------
  461. // do optional destination clipping
  462. //------------------------------------------------------------------------------
  463. // Destination clippiong rectangle:
  464. // NOTE: effective destination clipping done at a lower level.
  465. // Only source clipping would effect this...
  466. //
  467. short sDstClipX = 0, sDstClipY = 0;
  468. short sDstClipW = pimDst->m_sWidth, sDstClipH = pimDst->m_sHeight;
  469. // NOT FOR CLIPPING PURPOSES -> FIXED UINPUT VALUES!
  470. short sDstX = prDst->sX, sDstY = prDst->sY, sDstW = prDst->sW, sDstH = prDst->sH;
  471. if (prDstClip)
  472. {
  473. sDstClipX = prDstClip->sX;
  474. sDstClipY = prDstClip->sY;
  475. sDstClipW = prDstClip->sW;
  476. sDstClipH = prDstClip->sH;
  477. }
  478. //********************* MIRROR PART I => PRE CLIP:
  479. short sMirrorH = 1,sMirrorV = 1;
  480. if (sDstW < 0)
  481. {
  482. sMirrorH = -1; // flip the destination square's edges...
  483. sDstW = -sDstW;
  484. sDstX -= (sDstW - 1);
  485. }
  486. if (sDstH < 0)
  487. {
  488. sMirrorV = -1; // flip the destination square's edges...
  489. sDstH = -sDstH;
  490. sDstY -= (sDstH - 1);
  491. }
  492. //*********************
  493. //-------- Do the clipping:
  494. short sClipL,sClipR,sClipT,sClipB; // positive = clipped
  495. sClipL = sDstClipX - sDstX; if (sClipL < 0) sClipL = 0;
  496. sClipT = sDstClipY - sDstY; if (sClipT < 0) sClipT = 0;
  497. sClipR = (sDstX + sDstW - sDstClipX - sDstClipW); if (sClipR < 0) sClipR = 0;
  498. sClipB = (sDstY + sDstH - sDstClipY - sDstClipH); if (sClipB < 0) sClipB = 0;
  499. if ( ((sClipL + sClipR) >= sDstW) || ((sClipT + sClipB) >= sDstH) )
  500. {
  501. return 0; // fully clipped out
  502. }
  503. //********************* MIRROR PART II => POST CLIP, flip back...
  504. if (sMirrorH == -1)
  505. {
  506. sDstX += (sDstW - 1);
  507. SWAP(sClipL,sClipR); // the drawing order is reversed...
  508. }
  509. if (sMirrorV == -1)
  510. {
  511. sDstY += (sDstH - 1);
  512. SWAP(sClipT,sClipB); // the drawing order is reversed...
  513. }
  514. //*********************
  515. //------------------------------------------------------------------------------
  516. // set up IC
  517. //------------------------------------------------------------------------------
  518. UCHAR* pDst = pimDst->m_pData + pimDst->m_lPitch * sDstY + sDstX;
  519. UCHAR* pSrc = pimSrc->m_pData + pimSrc->m_lPitch * sSrcY + sSrcX;
  520. if ((sDstW <= sSrcW) && (sDstH <= sSrcH))
  521. _Blit_HS_VS_C(pSrc,pimSrc->m_lPitch,sSrcW,sSrcH,
  522. pDst,pimDst->m_lPitch,sDstW,sDstH,
  523. sClipL,sClipT,sClipR,sClipB,sMirrorH,sMirrorV);
  524. else if ((sDstW > sSrcW) && (sDstH > sSrcH))
  525. _Blit_HM_VM_C(pSrc,pimSrc->m_lPitch,sSrcW,sSrcH,
  526. pDst,pimDst->m_lPitch,sDstW,sDstH,
  527. sClipL,sClipT,sClipR,sClipB,sMirrorH,sMirrorV);
  528. else if ((sDstW <= sSrcW) && (sDstH > sSrcH))
  529. _Blit_HS_VM_C(pSrc,pimSrc->m_lPitch,sSrcW,sSrcH,
  530. pDst,pimDst->m_lPitch,sDstW,sDstH,
  531. sClipL,sClipT,sClipR,sClipB,sMirrorH,sMirrorV);
  532. else
  533. _Blit_HM_VS_C(pSrc,pimSrc->m_lPitch,sSrcW,sSrcH,
  534. pDst,pimDst->m_lPitch,sDstW,sDstH,
  535. sClipL,sClipT,sClipR,sClipB,sMirrorH,sMirrorV);
  536. return 0;
  537. }
  538. // easy call overloads:
  539. //
  540. #if WIN32
  541. inline
  542. #else
  543. extern
  544. #endif
  545. short rspBlitT(RImage* pimSrc,RImage* pimDst,short sDstX,short sDstY,
  546. short sDstW,short sDstH,const RRect* prDstClip)
  547. {
  548. RRect rSrc,rDst;
  549. #ifdef _DEBUG
  550. if (!pimSrc || !pimDst)
  551. {
  552. TRACE("rspBlitT: NULL images passed!\n");
  553. return -1;
  554. }
  555. #endif
  556. rSrc.sX = rSrc.sY = 0;
  557. rSrc.sW = pimSrc->m_sWidth;
  558. rSrc.sH = pimSrc->m_sHeight;
  559. rDst.sX = sDstX;
  560. rDst.sY = sDstY;
  561. rDst.sW = sDstW;
  562. rDst.sH = sDstH;
  563. return rspBlitT(pimSrc,pimDst,&rSrc,&rDst,prDstClip);
  564. }
  565. // easy call overloads:
  566. //
  567. #if WIN32
  568. inline
  569. #else
  570. extern
  571. #endif
  572. short rspBlitT(RImage* pimSrc,RImage* pimDst,short sDstX,short sDstY,
  573. double dRatW,double dRatH,const RRect* prDstClip)
  574. {
  575. #ifdef _DEBUG
  576. if (!pimSrc || !pimDst)
  577. {
  578. TRACE("rspBlitT: NULL images passed!\n");
  579. return -1;
  580. }
  581. #endif
  582. return rspBlitT(pimSrc,pimDst,sDstX,sDstY,(short)(dRatW * pimSrc->m_sWidth),
  583. (short)(dRatH * pimSrc->m_sHeight),prDstClip);
  584. }