OTSMorphology.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. #include <stdafx.h>
  2. #include "OTSMorphology.h"
  3. // use verticl line of 3 pixel to erode a image
  4. void BErodeVertical3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  5. {
  6. WORD x, y, wcounts;
  7. if (rows <= 2 || columns <= 2)return;
  8. // top line
  9. for (x = 0; x < columns; x++)
  10. {
  11. *(target + x) = 0;
  12. }
  13. // bottom line
  14. for (x = 0; x < columns; x++)
  15. {
  16. *(target + (DWORD)(rows - 1) * columns + x) = 0;
  17. }
  18. for (y = 1; y < rows - 1; y++)
  19. {
  20. for (x = 0; x < columns; x++)
  21. {
  22. if (*(source + (DWORD)y * columns + x) == 0)
  23. {
  24. *(target + (DWORD)y * columns + x) = 0;
  25. continue;
  26. }
  27. wcounts = 0;
  28. if (*(source + (DWORD)(y - 1) * columns + x) == 255)
  29. {
  30. wcounts++;
  31. }
  32. if (*(source + (DWORD)(y + 1) * columns + x) == 255)
  33. {
  34. wcounts++;
  35. }
  36. if (wcounts == 2) *(target + (DWORD)y * columns + x) = 255;
  37. else *(target + (DWORD)y * columns + x) = 0;
  38. }
  39. }
  40. }
  41. // use left 45 degree line of 3 pixel to erode a image
  42. void BErodeLeft45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  43. {
  44. WORD x, y, wcounts;
  45. if (rows <= 2 || columns <= 2)return;
  46. // top line
  47. for (x = 0; x < columns; x++)
  48. {
  49. *(target + x) = 0;
  50. }
  51. // bottom line
  52. for (x = 0; x < columns; x++)
  53. {
  54. *(target + (DWORD)(rows - 1) * columns + x) = 0;
  55. }
  56. // left line
  57. for (y = 0; y < rows; y++)
  58. {
  59. *(target + (DWORD)y * columns) = 0;
  60. }
  61. // right line
  62. for (y = 0; y < rows; y++)
  63. {
  64. *(target + (DWORD)y * columns + columns - 1) = 0;
  65. }
  66. for (y = 1; y < rows - 1; y++)
  67. {
  68. for (x = 1; x < columns - 1; x++)
  69. {
  70. if (*(source + (DWORD)y * columns + x) == 0)
  71. {
  72. *(target + (DWORD)y * columns + x) = 0;
  73. continue;
  74. }
  75. wcounts = 0;
  76. if (*(source + (DWORD)(y - 1) * columns + x - 1) == 255)
  77. {
  78. wcounts++;
  79. }
  80. if (*(source + (DWORD)(y + 1) * columns + x + 1) == 255)
  81. {
  82. wcounts++;
  83. }
  84. if (wcounts == 2) *(target + (DWORD)y * columns + x) = 255;
  85. else *(target + (DWORD)y * columns + x) = 0;
  86. }
  87. }
  88. }
  89. // use horizoontal line of 3 pixel to erode a image
  90. void BErodeHorizontal3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  91. {
  92. WORD x, y, wcounts;
  93. if (rows <= 2 || columns <= 2)return;
  94. // left line
  95. for (y = 0; y < rows; y++)
  96. {
  97. *(target + (DWORD)y * columns) = 0;
  98. }
  99. // right line
  100. for (y = 0; y < rows; y++)
  101. {
  102. *(target + (DWORD)y * columns + columns - 1) = 0;
  103. }
  104. for (y = 0; y < rows; y++)
  105. {
  106. for (x = 1; x < columns - 1; x++)
  107. {
  108. if (*(source + (DWORD)y * columns + x) == 0)
  109. {
  110. *(target + (DWORD)y * columns + x) = 0;
  111. continue;
  112. }
  113. wcounts = 0;
  114. if (*(source + (DWORD)y * columns + x - 1) == 255)
  115. {
  116. wcounts++;
  117. }
  118. if (*(source + (DWORD)y * columns + x + 1) == 255)
  119. {
  120. wcounts++;
  121. }
  122. if (wcounts == 2) *(target + (DWORD)y * columns + x) = 255;
  123. else *(target + (DWORD)y * columns + x) = 0;
  124. }
  125. }
  126. }
  127. // use right 45 degree line of 3 pixel to erode a image
  128. void BErodeRight45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  129. {
  130. WORD x, y, wcounts;
  131. if (rows <= 2 || columns <= 2)return;
  132. // top line
  133. for (x = 0; x < columns; x++)
  134. {
  135. *(target + x) = 0;
  136. }
  137. // bottom line
  138. for (x = 0; x < columns; x++)
  139. {
  140. *(target + (DWORD)(rows - 1) * columns + x) = 0;
  141. }
  142. // left line
  143. for (y = 0; y < rows; y++)
  144. {
  145. *(target + (DWORD)y * columns) = 0;
  146. }
  147. // right line
  148. for (y = 0; y < rows; y++)
  149. {
  150. *(target + (DWORD)y * columns + columns - 1) = 0;
  151. }
  152. for (y = 1; y < rows - 1; y++)
  153. {
  154. for (x = 1; x < columns - 1; x++)
  155. {
  156. if (*(source + (DWORD)y * columns + x) == 0)
  157. {
  158. *(target + (DWORD)y * columns + x) = 0;
  159. continue;
  160. }
  161. wcounts = 0;
  162. if (*(source + (DWORD)(y - 1) * columns + x + 1) == 255)
  163. {
  164. wcounts++;
  165. }
  166. if (*(source + (DWORD)(y + 1) * columns + x - 1) == 255)
  167. {
  168. wcounts++;
  169. }
  170. if (wcounts == 2) *(target + (DWORD)y * columns + x) = 255;
  171. else *(target + (DWORD)y * columns + x) = 0;
  172. }
  173. }
  174. }
  175. void BDilateVertical3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  176. {
  177. WORD x, y;
  178. if (rows <= 2 || columns <= 2)return;
  179. // top line
  180. for (x = 0; x < columns; x++)
  181. {
  182. if (*(source + x) != 0)
  183. {
  184. *(target + x) = 0xff;
  185. }
  186. }
  187. // bottom line
  188. for (x = 0; x < columns; x++)
  189. {
  190. if (*(source + (DWORD)(rows - 1) * columns + x) != 0)
  191. {
  192. *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  193. }
  194. }
  195. for (y = 1; y < rows - 1; y++)
  196. {
  197. for (x = 1; x < columns - 1; x++)
  198. {
  199. if (*(source + (DWORD)y * columns + x) != 0)
  200. {
  201. *(target + (DWORD)y * columns + x) = 0xff;
  202. *(target + (DWORD)(y - 1) * columns + x) = 255;
  203. *(target + (DWORD)(y + 1) * columns + x) = 255;
  204. }
  205. else *(target + (DWORD)y * columns + x) = 0;
  206. }
  207. }
  208. }
  209. void BDilateLeft45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  210. {
  211. WORD x, y;
  212. if (rows <= 2 || columns <= 2)return;
  213. // top line
  214. for (x = 0; x < columns; x++)
  215. {
  216. if (*(source + x) != 0)
  217. {
  218. *(target + x) = 0xff;
  219. }
  220. }
  221. // bottom line
  222. for (x = 0; x < columns; x++)
  223. {
  224. if (*(source + (DWORD)(rows - 1) * columns + x) != 0)
  225. {
  226. *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  227. }
  228. }
  229. // left line
  230. for (y = 0; y < rows; y++)
  231. {
  232. if (*(source + (DWORD)y * columns) != 0)
  233. {
  234. *(target + (DWORD)y * columns) = 0xff;
  235. }
  236. }
  237. // right line
  238. for (y = 0; y < rows; y++)
  239. {
  240. if (*(source + (DWORD)y * columns + columns - 1) != 0)
  241. {
  242. *(target + (DWORD)y * columns + columns - 1) = 0xff;
  243. }
  244. }
  245. for (y = 1; y < rows - 1; y++)
  246. {
  247. for (x = 1; x < columns - 1; x++)
  248. {
  249. if (*(source + (DWORD)y * columns + x) != 0)
  250. {
  251. *(target + (DWORD)y * columns + x) = 0xff;
  252. *(target + (DWORD)(y - 1) * columns + x - 1) = 255;
  253. *(target + (DWORD)(y + 1) * columns + x + 1) = 255;
  254. }
  255. else *(target + (DWORD)y * columns + x) = 0;
  256. }
  257. }
  258. }
  259. void BDilateHorizontal3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  260. {
  261. WORD x, y;
  262. if (rows <= 2 || columns <= 2)return;
  263. // left line
  264. for (y = 0; y < rows; y++)
  265. {
  266. if (*(source + (DWORD)y * columns) != 0)
  267. {
  268. *(target + (DWORD)y * columns) = 0xff;
  269. }
  270. }
  271. // right line
  272. for (y = 0; y < rows; y++)
  273. {
  274. if (*(source + (DWORD)y * columns + columns - 1) != 0)
  275. {
  276. *(target + (DWORD)y * columns + columns - 1) = 0xff;
  277. }
  278. }
  279. for (y = 1; y < rows - 1; y++)
  280. {
  281. for (x = 1; x < columns - 1; x++)
  282. {
  283. if (*(source + (DWORD)y * columns + x) != 0)
  284. {
  285. *(target + (DWORD)y * columns + x) = 0xff;
  286. *(target + (DWORD)y * columns + x - 1) = 255;
  287. *(target + (DWORD)y * columns + x + 1) = 255;
  288. }
  289. else *(target + (DWORD)y * columns + x) = 0;
  290. }
  291. }
  292. }
  293. void BDilateRight45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
  294. {
  295. WORD x, y;
  296. if (rows <= 2 || columns <= 2)return;
  297. // top line
  298. for (x = 0; x < columns; x++)
  299. {
  300. if (*(source + x) != 0)
  301. {
  302. *(target + x) = 0xff;
  303. }
  304. }
  305. // bottom line
  306. for (x = 0; x < columns; x++)
  307. {
  308. if (*(source + (DWORD)(rows - 1) * columns + x) != 0)
  309. {
  310. *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  311. }
  312. }
  313. // left line
  314. for (y = 0; y < rows; y++)
  315. {
  316. if (*(source + (DWORD)y * columns) != 0)
  317. {
  318. *(target + (DWORD)y * columns) = 0xff;
  319. }
  320. }
  321. // right line
  322. for (y = 0; y < rows; y++)
  323. {
  324. if (*(source + (DWORD)y * columns + columns - 1) != 0)
  325. {
  326. *(target + (DWORD)y * columns + columns - 1) = 0xff;
  327. }
  328. }
  329. for (y = 1; y < rows - 1; y++)
  330. {
  331. for (x = 1; x < columns - 1; x++)
  332. {
  333. if (*(source + (DWORD)y * columns + x) != 0)
  334. {
  335. *(target + (DWORD)y * columns + x) = 0xff;
  336. *(target + (DWORD)(y - 1) * columns + x + 1) = 255;
  337. *(target + (DWORD)(y + 1) * columns + x - 1) = 255;
  338. }
  339. else *(target + (DWORD)y * columns + x) = 0;
  340. }
  341. }
  342. }
  343. void BErode3(LPBYTE source, LPBYTE target, WORD wDegree, WORD rows, WORD columns)
  344. {
  345. WORD x, y, i, j, wcounts;
  346. if (rows == 1 || columns == 1)return;
  347. for (y = 1; y < rows - 1; y++)
  348. {
  349. for (x = 1; x < columns - 1; x++)
  350. {
  351. if (*(source + (DWORD)y * columns + x) == 0)
  352. {
  353. *(target + (DWORD)y * columns + x) = 0;
  354. continue;
  355. }
  356. wcounts = 0;
  357. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  358. {
  359. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  360. {
  361. if (*(source + (DWORD)i * columns + j) == 0)
  362. {
  363. wcounts++;
  364. }
  365. }
  366. }
  367. if (wcounts >= wDegree) *(target + (DWORD)y * columns + x) = 0;
  368. else *(target + (DWORD)y * columns + x) = 0xff;
  369. }
  370. }
  371. // top line
  372. for (x = 1; x < columns - (WORD)1; x++)
  373. {
  374. if (*(source + x) == 0)
  375. {
  376. *(target + x) = 0;
  377. continue;
  378. }
  379. wcounts = 0;
  380. for (i = 0; i <= 1; i++)
  381. {
  382. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  383. {
  384. if (*(source + (DWORD)i * columns + j) == 0) wcounts++;
  385. }
  386. }
  387. if (wcounts >= wDegree * 5 / 8) *(target + x) = 0;
  388. else *(target + x) = 0xff;
  389. }
  390. // bottom line
  391. for (x = 1; x < columns - 1; x++)
  392. {
  393. if (*(source + (DWORD)(rows - 1) * columns + x) == 0)
  394. {
  395. *(target + (DWORD)(rows - 1) * columns + x) = 0;
  396. continue;
  397. }
  398. wcounts = 0;
  399. for (i = (WORD)(rows - 2); i <= (WORD)(rows - 1); i++)
  400. {
  401. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  402. {
  403. if (*(source + (DWORD)i * columns + j) == 0) wcounts++;
  404. }
  405. }
  406. if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)(rows - 1) * columns + x) = 0;
  407. else *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  408. }
  409. // left line
  410. for (y = 1; y < rows - 1; y++)
  411. {
  412. if (*(source + (DWORD)y * columns) == 0)
  413. {
  414. *(target + (DWORD)y * columns) = 0;
  415. continue;
  416. }
  417. wcounts = 0;
  418. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  419. {
  420. for (j = 0; j <= 1; j++)
  421. {
  422. if (*(source + (DWORD)i * columns + j) == 0) wcounts++;
  423. }
  424. }
  425. if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)y * columns) = 0;
  426. else *(target + (DWORD)y * columns) = 0xff;
  427. }
  428. // right line
  429. for (y = 1; y < rows - 1; y++)
  430. {
  431. if (*(source + (DWORD)y * columns + columns - 1) == 0)
  432. {
  433. *(target + (DWORD)y * columns + columns - 1) = 0;
  434. continue;
  435. }
  436. wcounts = 0;
  437. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  438. {
  439. for (j = (WORD)(columns - 2); j <= (WORD)(columns - 1); j++)
  440. {
  441. if (*(source + (DWORD)i * columns + j) == 0) wcounts++;
  442. }
  443. }
  444. if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)y * columns + columns - 1) = 0;
  445. else *(target + (DWORD)y * columns + columns - 1) = 0xff;
  446. }
  447. return;
  448. }
  449. void BDilate3(LPBYTE source, LPBYTE target, WORD wDegree, WORD rows, WORD columns)
  450. {
  451. WORD x, y, i, j, wcounts;
  452. for (y = 1; y < rows - 1; y++)
  453. {
  454. for (x = 1; x < columns - 1; x++)
  455. {
  456. if (*(source + (DWORD)y * columns + x) != 0)
  457. {
  458. *(target + (DWORD)y * columns + x) = 0xff;
  459. continue;
  460. }
  461. wcounts = 0;
  462. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  463. {
  464. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  465. {
  466. if (*(source + (DWORD)i * columns + j) != 0) wcounts++;
  467. }
  468. }
  469. if (wcounts >= wDegree) *(target + (DWORD)y * columns + x) = 0xff;
  470. else *(target + (DWORD)y * columns + x) = 0;
  471. }
  472. }
  473. // top line
  474. for (x = 1; x < columns - 1; x++)
  475. {
  476. if (*(source + x) != 0)
  477. {
  478. *(target + x) = 0xff;
  479. continue;
  480. }
  481. wcounts = 0;
  482. for (i = 0; i <= 1; i++)
  483. {
  484. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  485. {
  486. if (*(source + (DWORD)i * columns + j) != 0) wcounts++;
  487. }
  488. }
  489. if (wcounts >= wDegree * 5 / 8) // but does not mater, as we have border of 2 now
  490. {
  491. *(target + x) = 0xff;
  492. }
  493. else { *(target + x) = 0; }
  494. }
  495. // bottom line
  496. for (x = 1; x < columns - 1; x++)
  497. {
  498. if (*(source + (DWORD)(rows - 1) * columns + x) != 0)
  499. {
  500. *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  501. continue;
  502. }
  503. wcounts = 0;
  504. for (i = (WORD)(rows - 2); i <= (WORD)(rows - 1); i++)
  505. {
  506. for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
  507. {
  508. if (*(source + (DWORD)i * columns + j) != 0) wcounts++;
  509. }
  510. }
  511. if (wcounts > wDegree * 5 / 8)
  512. {
  513. *(target + (DWORD)(rows - 1) * columns + x) = 0xff;
  514. }
  515. else
  516. {
  517. *(target + (DWORD)(rows - 1) * columns + x) = 0;
  518. }
  519. }
  520. // left line
  521. for (y = 1; y < rows - 1; y++)
  522. {
  523. if (*(source + (DWORD)y * columns) != 0)
  524. {
  525. *(target + (DWORD)y * columns) = 0xff;
  526. continue;
  527. }
  528. wcounts = 0;
  529. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  530. {
  531. for (j = 0; j <= (WORD)1; j++)
  532. {
  533. if (*(source + (DWORD)i * columns + j) != 0) wcounts++;
  534. }
  535. }
  536. if (wcounts >= wDegree * 5 / 8)
  537. {
  538. *(target + (DWORD)y * columns) = 0xff;
  539. }
  540. else
  541. {
  542. *(target + (DWORD)y * columns) = 0;
  543. }
  544. }
  545. // right line
  546. for (y = 1; y < rows - 1; y++)
  547. {
  548. if (*(source + (DWORD)y * columns + columns - 1) != 0)
  549. {
  550. *(target + (DWORD)y * columns + columns - 1) = 0xff;
  551. continue;
  552. }
  553. wcounts = 0;
  554. for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
  555. {
  556. for (j = (WORD)(columns - 2); j <= (WORD)(columns - 1); j++)
  557. {
  558. if (*(source + (DWORD)i * columns + j) != 0) wcounts++;
  559. }
  560. }
  561. if (wcounts >= wDegree * 5 / 8)
  562. {
  563. *(target + (DWORD)y * columns + columns - 1) = 0xff;
  564. }
  565. else
  566. {
  567. *(target + (DWORD)y * columns + columns - 1) = 0;
  568. }
  569. }
  570. // four cornor points treated separately here
  571. // top-left
  572. if (*(source) != 0)
  573. {
  574. *target = 0xff;
  575. }
  576. else
  577. {
  578. wcounts = 0;
  579. if (*(source + 1) != 0) wcounts++;
  580. if (*(source + columns) != 0) wcounts++;
  581. if (*(source + columns + 1) != 0) wcounts++;
  582. // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
  583. if (wcounts * 8 >= wDegree * 3)
  584. {
  585. *target = 0xff;
  586. }
  587. else
  588. {
  589. *target = 0;
  590. }
  591. }
  592. //top-right
  593. if (*(source + columns - 1) != 0)
  594. {
  595. *(target + columns - 1) = 0xff;
  596. }
  597. else
  598. {
  599. wcounts = 0;
  600. if (*(source + columns - 2) != 0) wcounts++;
  601. if (*(source + columns * 2 - 1) != 0) wcounts++;
  602. if (*(source + columns * 2 - 2) != 0) wcounts++;
  603. // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
  604. if (wcounts * 8 >= wDegree * 3)
  605. {
  606. *(target + columns - 1) = 0xff;
  607. }
  608. else
  609. {
  610. *(target + columns - 1) = 0;
  611. }
  612. }
  613. //bottom-left
  614. if (*(source + (DWORD)columns * (rows - 1)) != 0)
  615. {
  616. *(target + (DWORD)columns * (rows - 1)) = 0xff;
  617. }
  618. else
  619. {
  620. wcounts = 0;
  621. if (*(source + (DWORD)columns * (rows - 1) + 1) != 0) wcounts++;
  622. if (*(source + (DWORD)columns * (rows - 2)) != 0) wcounts++;
  623. if (*(source + (DWORD)columns * (rows - 2) + 1) != 0) wcounts++;
  624. // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
  625. if (wcounts * 8 >= wDegree * 3)
  626. {
  627. *(target + (DWORD)columns * (rows - 1)) = 0xff;
  628. }
  629. else
  630. {
  631. *(target + (DWORD)columns * (rows - 1)) = 0;
  632. }
  633. }
  634. //bottom-right
  635. if (*(source + (DWORD)columns * rows - 1) != 0)
  636. {
  637. *(target + (DWORD)columns * rows - 1) = 0xff;
  638. }
  639. else
  640. {
  641. wcounts = 0;
  642. if (*(source + (DWORD)columns * rows - 2) != 0) wcounts++;
  643. if (*(source + (DWORD)columns * (rows - 1) - 2) != 0) wcounts++;
  644. if (*(source + (DWORD)columns * (rows - 1) - 1) != 0) wcounts++;
  645. // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
  646. if (wcounts * 8 >= wDegree * 3)
  647. {
  648. *(target + (DWORD)columns * rows - 1) = 0xff;
  649. }
  650. else
  651. {
  652. *(target + (DWORD)columns * rows - 1) = 0;
  653. }
  654. }
  655. return;
  656. }