Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

549 lines
20 KiB

  1. //
  2. // TOSHIBA CORPORATION PROPRIETARY INFORMATION
  3. // This software is supplied under the terms of a license agreement or
  4. // nondisclosure agreement with TOSHIBA Corporation and may not be copied
  5. // or disclosed except in accordance with the terms of that agreement.
  6. // Copyright (c) 1997 TOSHIBA Corporation. All Rights Reserved.
  7. //
  8. // Workfile: IMAGE.C
  9. //
  10. // Purpose:
  11. //
  12. // Contents:
  13. //
  14. #include "strmini.h"
  15. #include "ksmedia.h"
  16. #include "capmain.h"
  17. #include "capdebug.h"
  18. #include "bert.h"
  19. #include "Image.h"
  20. //
  21. // SetInputImageSize
  22. // Set Input Image Size
  23. // Set P_SKIP_REG, P_ISIZ_REG
  24. //
  25. BOOL SetInputImageSize(PHW_DEVICE_EXTENSION pHwDevExt, PRECT pRect)
  26. {
  27. ULONG ulSkipLine;
  28. ULONG ulSkipPix;
  29. ULONG ulSrcHeight;
  30. ULONG ulSrcWidth;
  31. if((pHwDevExt->MaxRect.bottom < pRect->bottom) || (pHwDevExt->MaxRect.right < pRect->right)) { // Mod 97-04-09(Wed)
  32. return FALSE;
  33. }
  34. ulSkipLine = pRect->left & 0x000003ff;
  35. ulSkipPix = pRect->top & 0x000003ff;
  36. ulSrcHeight = (pRect->bottom - pRect->top) & 0x000003ff;
  37. ulSrcWidth = (pRect->right - pRect->left) & 0x000003ff;
  38. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_SKIP_REG, 0xfc00ffff, ulSkipLine << 16);
  39. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_SKIP_REG, 0xfffffc00, ulSkipPix);
  40. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_ISIZ_REG, 0xfc00ffff, ulSrcHeight << 16);
  41. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_ISIZ_REG, 0xfffffc00, ulSrcWidth);
  42. return TRUE;
  43. }
  44. //
  45. // SetOutputImageSize
  46. // Set Output Image Size
  47. // Set P_OSIZ_REG
  48. //
  49. BOOL SetOutputImageSize(PHW_DEVICE_EXTENSION pHwDevExt,
  50. ULONG ulWidth,
  51. ULONG ulHeight
  52. )
  53. {
  54. ULONG ulMaxWidth = pHwDevExt->MaxRect.right - pHwDevExt->MaxRect.left;
  55. ULONG ulMaxHeight = pHwDevExt->MaxRect.bottom - pHwDevExt->MaxRect.top;
  56. if((ulWidth <= ulMaxWidth) && (ulHeight <= ulMaxHeight)){ // Mod 97-04-09(Wed)
  57. ulWidth &= 0x000003ff;
  58. ulHeight &= 0x000003ff;
  59. ulHeight <<= 16;
  60. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_OSIZ_REG, 0xfffffc00, ulWidth);
  61. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_OSIZ_REG, 0xfc00ffff, ulHeight);
  62. }
  63. else{
  64. return FALSE;
  65. }
  66. return TRUE;
  67. }
  68. //
  69. // SetLumiInfo
  70. // Set Luminance Info
  71. // Set P_LUMI_REG
  72. //
  73. BOOL SetLumiInfo(PHW_DEVICE_EXTENSION pHwDevExt,
  74. ULONG ulContrast,
  75. ULONG ulBrightness
  76. )
  77. {
  78. if(ulContrast > 0xff){
  79. return FALSE;
  80. }
  81. if(ulBrightness > 0xff){
  82. return FALSE;
  83. }
  84. ulContrast >>= 1; // 1/2
  85. ulContrast <<= 8;
  86. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_LUMI_REG, 0xffff80ff, ulContrast);
  87. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_LUMI_REG, 0xffffff00, ulBrightness);
  88. return TRUE;
  89. }
  90. //
  91. // SetColorInfo
  92. // Set Color Info
  93. // Set P_COL_REG
  94. //
  95. BOOL SetColorInfo(PHW_DEVICE_EXTENSION pHwDevExt, // Mod 97-04-12(Sat)
  96. ULONG ulHue,
  97. ULONG ulSaturation
  98. )
  99. {
  100. ULONG ulUFU, ulVFU, ulUFV, ulVFV;
  101. ULONG ulUFUVFU, ulUFVVFV;
  102. long lSatu;
  103. long sindata[256] = {
  104. -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-128~-120) 0~8
  105. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-119~-110) 9~18
  106. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-109~-100) 19~28
  107. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-99~-90) 29~38
  108. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-89~-80) 39~48
  109. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-79~-70) 49~58
  110. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-69~-60) 59~68
  111. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 1/sin(-59~-50) 69~78
  112. -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, // 1/sin(-49~-40) 79~88
  113. -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // 1/sin(-39~-30) 89~98
  114. -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, // 1/sin(-29~-20) 99~108
  115. -3, -3, -3, -4, -4, -4, -4, -5, -5, -6, // 1/sin(-19~-10) 109~118
  116. -6, -7, -8, -10, -11, -14, -19, -29, -57, // 1/sin(-9~-1) 119~127
  117. 0, // 1/sin(0) 128
  118. 57, 29, 19, 14, 11, 10, 8, 7, 6, 6, // 1/sin(1~10) 129~138
  119. 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, // 1/sin(11~20) 139~148
  120. 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, // 1/sin(21~30) 149~158
  121. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 1/sin(31~40) 159~168
  122. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(41~50) 169~178
  123. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(51~60) 179~188
  124. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(61~70) 189~198
  125. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(71~80) 199~208
  126. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(81~90) 209~218
  127. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(91~100) 219~228
  128. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(101~110) 229~238
  129. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/sin(111~120) 239~248
  130. 1, 1, 1, 1, 1, 1, 1 // 1/sin(121~127) 249~255
  131. };
  132. long cosdata[256] = {
  133. -2, -2, -2, -2, -2, -2, -2, -2, -2, // 1/cos(-128~-120) 0~8
  134. -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, // 1/cos(-119~-110) 9~18
  135. -3, -3, -3, -4, -4, -4, -4, -5, -5, -6, // 1/cos(-109~-100) 19~28
  136. -6, -7, -8, -10, -11, -14, -19, -29, -57, // 1/cos(-99~-91) 29~37
  137. 0, // 1/cos(-90) 38
  138. 57, 29, 19, 14, 11, 10, 8, 7, 6, 6, // 1/cos(-89~-80) 39~48
  139. 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, // 1/cos(-79~-70) 49~58
  140. 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, // 1/cos(-69~-60) 59~68
  141. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 1/cos(-59~-50) 69~78
  142. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(-49~-40) 79~88
  143. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(-39~-30) 89~98
  144. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(-29~-20) 99~108
  145. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(-19~-10) 109~118
  146. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(-9~0) 119~128
  147. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(1~10) 129~138
  148. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(11~20) 139~148
  149. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(21~30) 149~158
  150. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1/cos(31~40) 159~168
  151. 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, // 1/cos(41~50) 169~178
  152. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 1/cos(51~60) 179~188
  153. 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, // 1/cos(61~70) 189~198
  154. 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, // 1/cos(71~80) 199~208
  155. 6, 7, 8, 10, 11, 14, 19, 29, 57, // 1/cos(81~89) 209~217
  156. 0, // 1/cos(90) 218
  157. -57, -29, -19, -14, -11, -10, -8, -7, -6, -6, // 1/cos(91~100) 219~228
  158. -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, // 1/cos(101~110) 229~238
  159. -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, // 1/cos(111~120) 239~248
  160. -2, -2, -2, -2, -2, -2, -2 // 1/cos(121~127) 249~255
  161. };
  162. if(ulHue > 0xff){
  163. return FALSE;
  164. }
  165. if(ulSaturation > 0xff){
  166. return FALSE;
  167. }
  168. lSatu = ulSaturation / 2; // Mod 97-05-10(Sat)
  169. switch(ulHue){
  170. case 38: // -90
  171. ulUFU = 128;
  172. ulVFU = lSatu + 128;
  173. ulUFV = -lSatu + 127;
  174. ulVFV = 128;
  175. break;
  176. case 128: // 0
  177. ulUFU = lSatu + 128;
  178. ulVFU = 128;
  179. ulUFV = 128;
  180. ulVFV = lSatu + 128;
  181. break;
  182. case 218: // 90
  183. ulUFU = 128;
  184. ulVFU = -lSatu + 127;
  185. ulUFV = lSatu + 128;
  186. ulVFV = 128;
  187. break;
  188. default:
  189. ulUFU = lSatu / cosdata[ulHue] + 128;
  190. ulVFU = -lSatu / sindata[ulHue] + 128;
  191. ulUFV = lSatu / sindata[ulHue] + 128;
  192. ulVFV = lSatu / cosdata[ulHue] + 128;
  193. break;
  194. }
  195. ulUFU &= 0xff; // Add 97-04-19(Sat)
  196. ulVFU &= 0xff;
  197. ulUFV &= 0xff;
  198. ulVFV &= 0xff;
  199. ulUFUVFU = ulUFU << 24 | ulVFU << 16;
  200. ulUFVVFV = ulUFV << 8 | ulVFV;
  201. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_COL_REG, 0x0000ffff, ulUFUVFU);
  202. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_COL_REG, 0xffff0000, ulUFVVFV);
  203. return TRUE;
  204. }
  205. //
  206. // SetChgColInfo
  207. // Set ChangeColor Info
  208. // Set P_LUMI_REG
  209. //
  210. BOOL SetChgColInfo(PHW_DEVICE_EXTENSION pHwDevExt,
  211. ULONG ulChgCol
  212. )
  213. {
  214. switch(ulChgCol){
  215. case IMAGE_CHGCOL_AVAIL:
  216. case IMAGE_CHGCOL_NOTAVAIL:
  217. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_LUMI_REG, 0xfffeffff, ulChgCol);
  218. break;
  219. default:
  220. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_LUMI_REG, 0xfffeffff, 0UL);
  221. break;
  222. }
  223. return TRUE;
  224. }
  225. //
  226. // SetVerticalFilterInfo
  227. // Set Vertical Filter Info
  228. // Set P_FILT_REG
  229. //
  230. BOOL SetVerticalFilterInfo(PHW_DEVICE_EXTENSION pHwDevExt,
  231. ULONG ulVFL
  232. )
  233. {
  234. switch(ulVFL){
  235. case IMAGE_VFL:
  236. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffeffff, ulVFL); // Mod 97-04-14(Mon)
  237. break;
  238. default:
  239. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffeffff, 0UL);
  240. break;
  241. }
  242. return TRUE;
  243. }
  244. //
  245. // SetHorizontalFilterInfo
  246. // Set Horizontal Filter Info
  247. // Set P_FILT_REG
  248. //
  249. BOOL SetHorizontalFilterInfo(PHW_DEVICE_EXTENSION pHwDevExt,
  250. ULONG ulFL1,
  251. ULONG ulFL2,
  252. ULONG ulFL3,
  253. ULONG ulFL4
  254. )
  255. {
  256. switch(ulFL1){
  257. case IMAGE_FL_0:
  258. case IMAGE_FL_1:
  259. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffffff8, ulFL1);
  260. break;
  261. default:
  262. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffffff8, 0UL);
  263. break;
  264. }
  265. switch(ulFL2){
  266. case IMAGE_FL_0:
  267. case IMAGE_FL_1:
  268. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xffffff8f, ulFL2 << 4);
  269. break;
  270. case IMAGE_FL_2:
  271. case IMAGE_FL_3:
  272. case IMAGE_FL_4:
  273. default:
  274. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xffffff8f, 0UL);
  275. break;
  276. }
  277. switch(ulFL3){
  278. case IMAGE_FL_0:
  279. case IMAGE_FL_1:
  280. case IMAGE_FL_2:
  281. case IMAGE_FL_4:
  282. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffff8ff, ulFL3 << 8);
  283. break;
  284. case IMAGE_FL_3:
  285. default:
  286. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffff8ff, 0UL);
  287. break;
  288. }
  289. switch(ulFL4){
  290. case IMAGE_FL_0:
  291. case IMAGE_FL_2:
  292. case IMAGE_FL_4:
  293. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xffff8fff, ulFL4 << 12);
  294. break;
  295. case IMAGE_FL_1:
  296. case IMAGE_FL_3:
  297. default:
  298. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xffff8fff, 0UL);
  299. break;
  300. }
  301. return TRUE;
  302. }
  303. //
  304. // ImageSetInputImageSize
  305. // Set Input Image Size
  306. // Set P_SKIP_REG, P_ISIZ_REG
  307. //
  308. BOOL ImageSetInputImageSize(PHW_DEVICE_EXTENSION pHwDevExt,
  309. PRECT pRect
  310. )
  311. {
  312. if(!SetInputImageSize(pHwDevExt, pRect)){
  313. return FALSE;
  314. }
  315. return TRUE;
  316. }
  317. //
  318. // ImageSetOutputImageSize
  319. // Set Output Image Size
  320. // Set P_OSIZ_REG
  321. //
  322. BOOL ImageSetOutputImageSize(PHW_DEVICE_EXTENSION pHwDevExt,
  323. ULONG ulWidth,
  324. ULONG ulHeight
  325. )
  326. {
  327. if(!SetOutputImageSize(pHwDevExt, ulWidth, ulHeight)){
  328. return FALSE;
  329. }
  330. if(!ImageGetFilteringAvailable(pHwDevExt)){
  331. ImageFilterOFF(pHwDevExt);
  332. }
  333. else if(ImageGetFilterInfo(pHwDevExt)){ // Add 97-05-13(Tue)
  334. ImageFilterON(pHwDevExt);
  335. }
  336. return TRUE;
  337. }
  338. //
  339. // ImageSetChangeColorAvail
  340. // Set/Reset CHGCOL Bit
  341. // Set P_LUMI_REG
  342. //
  343. BOOL ImageSetChangeColorAvail(PHW_DEVICE_EXTENSION pHwDevExt,
  344. ULONG ulChgCol
  345. )
  346. {
  347. if(!SetChgColInfo(pHwDevExt, ulChgCol)){
  348. return FALSE;
  349. }
  350. return TRUE;
  351. }
  352. //
  353. // ImageSetHueBrightnessContrastSat
  354. // Set Color Info
  355. // Call SetLumiImfo, SetColorInfo
  356. //
  357. BOOL ImageSetHueBrightnessContrastSat(PHW_DEVICE_EXTENSION pHwDevExt) // Mod 97-04-08(Tue)
  358. {
  359. #ifdef TOSHIBA
  360. if(!SetLumiInfo(pHwDevExt, pHwDevExt->Contrast, pHwDevExt->Brightness)){
  361. return FALSE;
  362. }
  363. if(!SetColorInfo(pHwDevExt, pHwDevExt->Hue, pHwDevExt->Saturation)){
  364. return FALSE;
  365. }
  366. #else //TOSHIBA
  367. if(!SetLumiInfo(pHwDevExt, pHwDevExt->ulContrast, pHwDevExt->ulBrightness)){
  368. return FALSE;
  369. }
  370. if(!SetColorInfo(pHwDevExt, pHwDevExt->ulHue, pHwDevExt->ulSaturation)){
  371. return FALSE;
  372. }
  373. #endif//TOSHIBA
  374. return TRUE;
  375. }
  376. //
  377. // ImageSetFilterInfo
  378. // Set Filter Info
  379. // Set P_FILT_REG
  380. //
  381. BOOL ImageSetFilterInfo(PHW_DEVICE_EXTENSION pHwDevExt,
  382. ULONG ulVFL,
  383. ULONG ulFL1,
  384. ULONG ulFL2,
  385. ULONG ulFL3,
  386. ULONG ulFL4
  387. )
  388. {
  389. if(!SetHorizontalFilterInfo(pHwDevExt, ulFL1, ulFL2, ulFL3, ulFL4)){
  390. return FALSE;
  391. }
  392. if(!SetVerticalFilterInfo(pHwDevExt, ulVFL)){
  393. return FALSE;
  394. }
  395. return TRUE;
  396. }
  397. //
  398. // ImageFilterON
  399. //
  400. // Set P_FILT_REG
  401. //
  402. BOOL ImageFilterON(PHW_DEVICE_EXTENSION pHwDevExt)
  403. {
  404. ULONG ulFL1, ulFL2, ulFL3, ulFL4;
  405. if(pHwDevExt->ulWidth <= 80){ // 0 < Width <= 80
  406. ulFL1 = IMAGE_FL_1;
  407. ulFL2 = IMAGE_FL_1;
  408. ulFL3 = IMAGE_FL_2;
  409. ulFL4 = IMAGE_FL_4;
  410. }
  411. else if((pHwDevExt->ulWidth > 80) && (pHwDevExt->ulWidth <= 160)){ // 80 < Width <= 160
  412. ulFL1 = IMAGE_FL_1;
  413. ulFL2 = IMAGE_FL_1;
  414. ulFL3 = IMAGE_FL_2;
  415. ulFL4 = IMAGE_FL_0;
  416. }
  417. else{ // 160 < Width
  418. ulFL1 = IMAGE_FL_1;
  419. ulFL2 = IMAGE_FL_1;
  420. ulFL3 = IMAGE_FL_0;
  421. ulFL4 = IMAGE_FL_0;
  422. }
  423. if(!SetHorizontalFilterInfo(pHwDevExt, ulFL1, ulFL2, ulFL3, ulFL4)){
  424. return FALSE;
  425. }
  426. if(!SetVerticalFilterInfo(pHwDevExt, IMAGE_VFL)){
  427. return FALSE;
  428. }
  429. return TRUE;
  430. }
  431. //
  432. // ImageFilterOFF
  433. //
  434. // Set P_FILT_REG
  435. //
  436. BOOL ImageFilterOFF(PHW_DEVICE_EXTENSION pHwDevExt)
  437. {
  438. ReadModifyWriteRegUlong(pHwDevExt, BERT_P_FILT_REG, 0xfffe0000, 0UL);
  439. return TRUE;
  440. }
  441. //
  442. // ImageGetFilterInfo
  443. // Get Filter Info
  444. //
  445. BOOL ImageGetFilterInfo(PHW_DEVICE_EXTENSION pHwDevExt)
  446. {
  447. if(!ReadRegUlong(pHwDevExt, BERT_P_FILT_REG)){
  448. return FALSE;
  449. }
  450. return TRUE;
  451. }
  452. //
  453. // ImageGetFilteringAvailable
  454. //
  455. BOOL ImageGetFilteringAvailable(PHW_DEVICE_EXTENSION pHwDevExt)
  456. {
  457. ULONG ulISIZ, ulOSIZ;
  458. ULONG ulFL, ulFL1, ulFL2, ulFL3, ulFL4;
  459. ulISIZ = ReadRegUlong(pHwDevExt, BERT_P_ISIZ_REG);
  460. ulISIZ &= 0x3ff;
  461. ulOSIZ = ReadRegUlong(pHwDevExt, BERT_P_OSIZ_REG);
  462. ulOSIZ &= 0x3ff;
  463. ulFL = ReadRegUlong(pHwDevExt, BERT_P_FILT_REG);
  464. ulFL1 = ulFL & 0x7;
  465. ulFL2 = (ulFL >> 4) & 0x7;
  466. ulFL3 = (ulFL >> 8) & 0x7;
  467. ulFL4 = (ulFL >> 12) & 0x7;
  468. if((ulOSIZ > 400) || (ulOSIZ == 640)){
  469. return FALSE;
  470. }
  471. if((ulISIZ - ulOSIZ) < ((ulFL1 + ulFL2 + ulFL3 + ulFL4) * 2)){
  472. return FALSE;
  473. }
  474. return TRUE;
  475. }
  476.