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.

772 lines
27 KiB

  1. #include "precomp.h"
  2. //
  3. // values that the WIA/TWAIN data source provides for capability negotation
  4. //
  5. TW_UINT16 g_CameraUnits[] = {TWUN_PIXELS};
  6. TW_UINT16 g_CameraBitOrder[] = {TWBO_MSBFIRST};
  7. TW_UINT16 g_CameraXferMech[] = {TWSX_NATIVE, TWSX_FILE, TWSX_MEMORY};
  8. TW_UINT16 g_CameraPixelFlavor[] = {TWPF_CHOCOLATE};
  9. TW_UINT16 g_CameraPlanarChunky[] = {TWPC_CHUNKY};
  10. const TW_UINT32 NUM_CAMERACAPDATA = 23;
  11. CAPDATA CAMERA_CAPDATA[NUM_CAMERACAPDATA] =
  12. {
  13. //
  14. // Every source must support all five DG_CONTROL / DAT_CAPABILITY operations on:
  15. //
  16. {CAP_XFERCOUNT, TWTY_INT16, TWON_ONEVALUE,
  17. sizeof(TW_INT16), 0, 0, 0, 32767, 1, NULL, NULL
  18. },
  19. //
  20. // Every source must support DG_CONTROL / DAT_CAPABILITY, MSG_GET on:
  21. //
  22. {CAP_SUPPORTEDCAPS, TWTY_UINT16, TWON_ARRAY,
  23. sizeof(TW_UINT16), 0, 0, 0, 0, 0, NULL, NULL
  24. },
  25. {CAP_UICONTROLLABLE, TWTY_BOOL, TWON_ONEVALUE,
  26. sizeof(TW_BOOL), TRUE, TRUE, TRUE, TRUE, 0, NULL, NULL
  27. },
  28. //
  29. // Sources that supply image information must support DG_CONTROL / DAT_CAPABILITY /
  30. // MSG_GET, MSG_GETCURRENT, and MSG_GETDEFAULT on:
  31. //
  32. {ICAP_COMPRESSION, TWTY_UINT16, TWON_ENUMERATION,
  33. sizeof(TW_UINT16), 0, 0, 0, 0, 0, NULL, NULL
  34. },
  35. {ICAP_PLANARCHUNKY, TWTY_UINT16, TWON_ENUMERATION,
  36. sizeof(TW_UINT16), 0, 0, 0, 0, 0, g_CameraPlanarChunky, NULL
  37. },
  38. {ICAP_PHYSICALHEIGHT, TWTY_UINT32, TWON_ONEVALUE,
  39. sizeof(TW_UINT32), 1024, 1024, 1024, 1024, 0, NULL, NULL
  40. },
  41. {ICAP_PHYSICALWIDTH, TWTY_UINT32, TWON_ONEVALUE,
  42. sizeof(TW_UINT32), 1536, 1536, 1536, 1536, 0, NULL, NULL
  43. },
  44. {ICAP_PIXELFLAVOR, TWTY_UINT16, TWON_ENUMERATION,
  45. sizeof(TW_UINT16), 0, 0, 0, 0, 0, g_CameraPixelFlavor, NULL
  46. },
  47. //
  48. // Sources that supply image information must support DG_CONTROL / DAT_CAPABILITY /
  49. // MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_RESET, and MSG_SET on:
  50. //
  51. {ICAP_BITDEPTH, TWTY_UINT16, TWON_ENUMERATION,
  52. sizeof(TW_UINT16), 0, 0, 0, 0, 0, NULL, NULL
  53. },
  54. {ICAP_BITORDER, TWTY_UINT16, TWON_ENUMERATION,
  55. sizeof(TW_UINT16), 0, 0, 0, 0, 0, g_CameraBitOrder, NULL
  56. },
  57. {ICAP_PIXELTYPE, TWTY_UINT16, TWON_ENUMERATION,
  58. sizeof(TW_UINT16), 0, 0, 0, 0, 0, NULL, NULL
  59. },
  60. {ICAP_UNITS, TWTY_UINT16, TWON_ENUMERATION,
  61. sizeof(TW_UINT16), 0, 0, 0, 0, 0, g_CameraUnits, NULL
  62. },
  63. {ICAP_XFERMECH, TWTY_UINT16, TWON_ENUMERATION,
  64. sizeof(TW_UINT16), 0, 0, 0, 2, 0, g_CameraXferMech, NULL
  65. },
  66. {ICAP_XRESOLUTION, TWTY_FIX32, TWON_ONEVALUE,
  67. sizeof(TW_FIX32), 75, 75, 75, 75, 0, NULL, NULL
  68. },
  69. {ICAP_YRESOLUTION, TWTY_FIX32, TWON_ONEVALUE,
  70. sizeof(TW_FIX32), 75, 75, 75, 75, 0, NULL, NULL
  71. },
  72. //
  73. // The following capabilities are camera specific capabilities
  74. //
  75. {CAP_THUMBNAILSENABLED, TWTY_BOOL, TWON_ONEVALUE,
  76. sizeof(TW_BOOL), FALSE, FALSE, TRUE, TRUE, 0, NULL, NULL
  77. },
  78. {CAP_CAMERAPREVIEWUI, TWTY_BOOL, TWON_ONEVALUE,
  79. sizeof(TW_BOOL), TRUE, TRUE, TRUE, TRUE, 0, NULL, NULL
  80. },
  81. {ICAP_IMAGEDATASET, TWTY_UINT32, TWON_RANGE,
  82. sizeof(TW_UINT32), 1, 1, 1, 50, 1, NULL, NULL
  83. },
  84. //
  85. // The following capabilities are provided for application compatiblity only.
  86. //
  87. {ICAP_IMAGEFILEFORMAT, TWTY_UINT16, TWON_ENUMERATION,
  88. sizeof(TW_UINT16), 0, 0, 0, 0, 0, NULL, NULL
  89. },
  90. {CAP_INDICATORS, TWTY_BOOL, TWON_ONEVALUE,
  91. sizeof(TW_BOOL), TRUE, TRUE, TRUE, TRUE, 0, NULL, NULL
  92. },
  93. {CAP_ENABLEDSUIONLY, TWTY_BOOL, TWON_ONEVALUE,
  94. sizeof(TW_BOOL), FALSE, FALSE, FALSE, FALSE, 0, NULL, NULL
  95. },
  96. {CAP_DEVICEONLINE, TWTY_BOOL, TWON_ONEVALUE,
  97. sizeof(TW_BOOL), TRUE, TRUE, TRUE, TRUE, 0, NULL, NULL
  98. },
  99. {CAP_SUPPORTEDCAPSEXT, TWTY_BOOL, TWON_ONEVALUE,
  100. sizeof(TW_BOOL), FALSE, FALSE, FALSE, FALSE, 0, NULL, NULL
  101. },
  102. };
  103. TW_UINT16 CWiaCameraDS::OpenDS(PTWAIN_MSG ptwMsg)
  104. {
  105. TW_UINT16 twRc = TWRC_SUCCESS;
  106. TW_UINT16 twCc = TWCC_SUCCESS;
  107. m_bArrayModeAcquisition = FALSE;
  108. m_pulImageIndexes = NULL;
  109. m_lNumValidIndexes = 0;
  110. m_lCurrentArrayIndex = 0;
  111. m_bRangeModeAcquisition = FALSE;
  112. memset(&m_twImageRange,0,sizeof(TW_RANGE));
  113. //
  114. // create capability list
  115. //
  116. twCc = CreateCapList(NUM_CAMERACAPDATA, CAMERA_CAPDATA);
  117. if (TWCC_SUCCESS != twCc) {
  118. m_twStatus.ConditionCode = twCc;
  119. return TWRC_FAILURE;
  120. }
  121. twRc = CWiaDataSrc::OpenDS(ptwMsg);
  122. if (TWRC_SUCCESS == twRc) {
  123. HRESULT hr = m_pDevice->AcquireImages(NULL, FALSE);
  124. if (SUCCEEDED(hr)) {
  125. //
  126. // get number of pictures taken, for IMAGEDATASET query
  127. //
  128. LONG lNumImages = 0;
  129. m_pDevice->GetNumAcquiredImages(&lNumImages);
  130. CCap *pCap = NULL;
  131. pCap = FindCap(ICAP_IMAGEDATASET);
  132. if (pCap) {
  133. pCap->Set((TW_UINT32)lNumImages,(TW_UINT32)lNumImages,(TW_UINT32)lNumImages,(TW_UINT32)lNumImages,1);
  134. }
  135. hr = m_pDevice->EnumAcquiredImage(0, &m_pCurrentIWiaItem);
  136. if (SUCCEEDED(hr)) {
  137. //
  138. // attempt to get common settings from the camera device
  139. // if at any point a "bad" WIA item is encountered, fall
  140. // through and get common default settings. This will
  141. // allow the camera to be used in a TWAIN session even if
  142. // the WIA item tree appears to be corrupted.
  143. //
  144. twRc = GetCommonSettings();
  145. if(twRc != TWRC_SUCCESS) {
  146. twRc = GetCommonDefaultSettings();
  147. }
  148. } else {
  149. //
  150. // camera devices, can be in a state that there are no still images
  151. // to transfer
  152. //
  153. twRc = GetCommonDefaultSettings();
  154. }
  155. }
  156. }
  157. return twRc;
  158. }
  159. TW_UINT16 CWiaCameraDS::CloseDS(PTWAIN_MSG ptwMsg)
  160. {
  161. DestroyCapList();
  162. return CWiaDataSrc::CloseDS(ptwMsg);
  163. }
  164. TW_UINT16 CWiaCameraDS::SetCapability(CCap *pCap,TW_CAPABILITY *ptwCap)
  165. {
  166. TW_UINT16 twRc = TWRC_SUCCESS;
  167. if (ptwCap->Cap == ICAP_IMAGEDATASET) {
  168. switch(ptwCap->ConType){
  169. case TWON_ONEVALUE:
  170. DBG_TRC(("CWiaCameraDS::SetCapability(), setting ICAP_IMAGEDATASET to a TWON_ONEVALUE"));
  171. //
  172. // implied contiguous image transfer, from 1 to the specified TW_ONEVALUE
  173. //
  174. twRc = CWiaDataSrc::SetCapability(pCap, ptwCap);
  175. break;
  176. case TWON_RANGE:
  177. DBG_TRC(("CWiaCameraDS::SetCapability(), setting ICAP_IMAGEDATASET to a TW_RANGE"));
  178. //
  179. // contiguous image transfer, from MinValue to MaxValue TW_RANGE (using StepSize? or increment by 1?)
  180. //
  181. twRc = SetRangeOfImageIndexes(ptwCap);
  182. break;
  183. case TWON_ARRAY:
  184. DBG_TRC(("CWiaCameraDS::SetCapability(), setting ICAP_IMAGEDATASET to a TW_ARRAY"));
  185. //
  186. // image transfer with specified indexes supplied by the TWAIN application (user)
  187. //
  188. twRc = SetArrayOfImageIndexes(ptwCap);
  189. break;
  190. default:
  191. DBG_WRN(("CWiaCameraDS::SetCapability(), setting ICAP_IMAGEDATASET unknown container type (%d)",ptwCap->ConType));
  192. break;
  193. }
  194. } else {
  195. twRc = CWiaDataSrc::SetCapability(pCap, ptwCap);
  196. if(TWRC_SUCCESS == twRc){
  197. if(m_pCurrentIWiaItem){
  198. twRc = CWiaDataSrc::SetCommonSettings(pCap);
  199. }
  200. }
  201. }
  202. return twRc;
  203. }
  204. TW_UINT16 CWiaCameraDS::SetArrayOfImageIndexes(TW_CAPABILITY *ptwCap)
  205. {
  206. TW_UINT16 twRc = TWRC_FAILURE;
  207. switch (ptwCap->ConType) {
  208. case TWON_ARRAY:
  209. twRc = TWRC_SUCCESS;
  210. break;
  211. default:
  212. DBG_ERR(("CWiaCameraDS::SetArrayOfImageIndexes(), invalid image index container was sent to data source."));
  213. break;
  214. }
  215. if (TWRC_SUCCESS == twRc) {
  216. TW_ARRAY *pArray = (TW_ARRAY*)GlobalLock(ptwCap->hContainer);
  217. if (pArray) {
  218. TW_UINT32 *pUINT32Array = NULL;
  219. pUINT32Array = (TW_UINT32*)pArray->ItemList;
  220. if(pUINT32Array){
  221. if (m_pulImageIndexes) {
  222. delete [] m_pulImageIndexes;
  223. m_pulImageIndexes = NULL;
  224. }
  225. m_lNumValidIndexes = pArray->NumItems;
  226. m_pulImageIndexes = new LONG[m_lNumValidIndexes];
  227. if (m_pulImageIndexes) {
  228. DBG_TRC(("CWiaCameraDS::SetArrayOfImageIndexes(), number of selected images to transfer = %d",m_lNumValidIndexes));
  229. for (int i = 0; i < m_lNumValidIndexes; i++) {
  230. //
  231. // subtract 1 from the supplied index in the application index array, because TWAIN's image index
  232. // array starts at 1 and goes to n. WIA (image) item array is zero-based. This will sync
  233. // up the indexes here, to avoid any strange calculations later on.
  234. //
  235. m_pulImageIndexes[i] = (pUINT32Array[i] - 1);
  236. DBG_TRC(("CWiaCameraDS::SetArrayOfImageIndexes(), image index copied into index array = %d",m_pulImageIndexes[i]));
  237. }
  238. } else {
  239. DBG_ERR(("CWiaCameraDS::SetArrayOfImageIndexes(), could not allocate image index array"));
  240. twRc = TWRC_FAILURE;
  241. }
  242. } else {
  243. DBG_ERR(("CWiaCameraDS::SetArrayOfImageIndexes(), could not assign TW_ARRAY pointer to TW_UINT32 pointer"));
  244. twRc = TWRC_FAILURE;
  245. }
  246. GlobalUnlock(ptwCap->hContainer);
  247. } else {
  248. DBG_ERR(("CWiaCameraDS::SetArrayOfImageIndexes(), could not LOCK the array container for write access"));
  249. twRc = TWRC_FAILURE;
  250. }
  251. }
  252. if(TWRC_SUCCESS == twRc){
  253. m_bArrayModeAcquisition = TRUE;
  254. m_bRangeModeAcquisition = FALSE;
  255. }
  256. return twRc;
  257. }
  258. TW_UINT16 CWiaCameraDS::SetRangeOfImageIndexes(TW_CAPABILITY *ptwCap)
  259. {
  260. TW_UINT16 twRc = TWRC_FAILURE;
  261. switch (ptwCap->ConType) {
  262. case TWON_RANGE:
  263. twRc = TWRC_SUCCESS;
  264. break;
  265. default:
  266. DBG_ERR(("CWiaCameraDS::SetRangeOfImageIndexes(), invalid image index container was sent to data source."));
  267. break;
  268. }
  269. if (TWRC_SUCCESS == twRc) {
  270. TW_RANGE *pRange = (TW_RANGE*)GlobalLock(ptwCap->hContainer);
  271. if (pRange) {
  272. m_bRangeModeAcquisition = TRUE;
  273. memcpy(&m_twImageRange,pRange,sizeof(TW_RANGE));
  274. //
  275. // adjust values to be zero-based to match our stored item list
  276. //
  277. m_twImageRange.CurrentValue -=1;
  278. m_twImageRange.DefaultValue -=1;
  279. m_twImageRange.MaxValue-=1;
  280. m_twImageRange.MinValue-=1;
  281. DBG_TRC(("CWiaCameraDS::SetRangeOfImageIndexes(), Set to the following Range Values"));
  282. DBG_TRC(("m_twImageRange.ItemType = %d",m_twImageRange.ItemType));
  283. DBG_TRC(("m_twImageRange.CurrentValue = %d",m_twImageRange.CurrentValue));
  284. DBG_TRC(("m_twImageRange.DefaultValue = %d",m_twImageRange.DefaultValue));
  285. DBG_TRC(("m_twImageRange.MaxValue = %d",m_twImageRange.MaxValue));
  286. DBG_TRC(("m_twImageRange.MinValue = %d",m_twImageRange.MinValue));
  287. DBG_TRC(("m_twImageRange.StepSize = %d",m_twImageRange.StepSize));
  288. } else {
  289. DBG_ERR(("CWiaCameraDS::SetRangeOfImageIndexes(), could not assign TW_RANGE pointer to TW_RANGE pointer"));
  290. twRc = TWRC_FAILURE;
  291. }
  292. GlobalUnlock(ptwCap->hContainer);
  293. } else {
  294. DBG_ERR(("CWiaCameraDS::SetRangeOfImageIndexes(), could not LOCK the range container for read access"));
  295. twRc = TWRC_FAILURE;
  296. }
  297. if(TWRC_SUCCESS == twRc){
  298. m_bRangeModeAcquisition = TRUE;
  299. m_bArrayModeAcquisition = FALSE;
  300. }
  301. return twRc;
  302. }
  303. TW_UINT16 CWiaCameraDS::EnableDS(TW_USERINTERFACE *pUI)
  304. {
  305. TW_UINT16 twRc = TWRC_FAILURE;
  306. if (DS_STATE_4 == GetTWAINState()) {
  307. HRESULT hr = S_OK;
  308. if (pUI->ShowUI) {
  309. //
  310. // since we were told to show UI, ignore the UI-LESS settings, and
  311. // get a new image item list from the WIA UI.
  312. //
  313. DBG_TRC(("CWiaCameraDS::EnableDS(), TWAIN UI MODE"));
  314. m_pDevice->FreeAcquiredImages();
  315. } else {
  316. DBG_TRC(("CWiaCameraDS::EnableDS(), TWAIN UI-LESS MODE"));
  317. }
  318. hr = m_pDevice->AcquireImages(HWND (pUI->ShowUI ? pUI->hParent : NULL),
  319. pUI->ShowUI);
  320. LONG lNumImages = 0;
  321. if (S_OK == hr) {
  322. twRc = TWRC_SUCCESS;
  323. m_pDevice->GetNumAcquiredImages(&lNumImages);
  324. if (lNumImages) {
  325. m_NumIWiaItems = (TW_UINT32)lNumImages;
  326. m_pIWiaItems = new (IWiaItem *[m_NumIWiaItems]);
  327. if (m_pIWiaItems) {
  328. hr = m_pDevice->GetAcquiredImageList(lNumImages, m_pIWiaItems, NULL);
  329. if (FAILED(hr)) {
  330. delete [] m_pIWiaItems;
  331. m_pIWiaItems = NULL;
  332. m_NumIWiaItems = 0;
  333. m_NextIWiaItemIndex = 0;
  334. m_twStatus.ConditionCode = TWCC_BUMMER;
  335. twRc = TWRC_FAILURE;
  336. }
  337. } else {
  338. m_NumIWiaItems = 0;
  339. m_twStatus.ConditionCode = TWCC_LOWMEMORY;
  340. twRc = TWRC_FAILURE;
  341. }
  342. }
  343. } else if(S_FALSE == hr) {
  344. return TWRC_CANCEL;
  345. } else {
  346. m_twStatus.ConditionCode = TWCC_OPERATIONERROR;
  347. twRc = TWRC_FAILURE;
  348. }
  349. //
  350. // check for number of image items returned
  351. //
  352. if(lNumImages <= 0) {
  353. m_twStatus.ConditionCode = TWCC_BUMMER;
  354. twRc = TWRC_CANCEL;
  355. }
  356. if (TWRC_SUCCESS == twRc) {
  357. //
  358. // set current item pointer
  359. //
  360. if(m_bRangeModeAcquisition){
  361. DBG_TRC(("CWiaCameraDS::EnableDS(), RANGE MODE"));
  362. m_pCurrentIWiaItem = m_pIWiaItems[m_twImageRange.MinValue];
  363. m_NextIWiaItemIndex = m_twImageRange.MinValue + 1; // use Step value???
  364. } else if(m_bArrayModeAcquisition){
  365. DBG_TRC(("CWiaCameraDS::EnableDS(), ARRAY MODE"));
  366. m_lCurrentArrayIndex = 0;
  367. m_pCurrentIWiaItem = m_pIWiaItems[m_pulImageIndexes[m_lCurrentArrayIndex]];
  368. if(m_lNumValidIndexes > 1){
  369. m_NextIWiaItemIndex = m_pulImageIndexes[m_lCurrentArrayIndex + 1]; // the next index value
  370. } else {
  371. m_NextIWiaItemIndex = m_lCurrentArrayIndex;
  372. }
  373. } else {
  374. m_pCurrentIWiaItem = m_pIWiaItems[0];
  375. m_NextIWiaItemIndex = 1;
  376. }
  377. //
  378. // set total image count
  379. //
  380. CCap *pcapXferCount = NULL;
  381. TW_UINT32 NumImages = 0;
  382. pcapXferCount = FindCap(CAP_XFERCOUNT);
  383. if (pcapXferCount) {
  384. if(m_bRangeModeAcquisition){
  385. // only images in the specified range (zero-based)
  386. twRc = pcapXferCount->SetCurrent((m_twImageRange.MaxValue - m_twImageRange.MinValue) + 1);
  387. } else if(m_bArrayModeAcquisition){
  388. // only selected images (zero-based)
  389. twRc = pcapXferCount->SetCurrent(m_lNumValidIndexes);
  390. } else {
  391. // all images (zero-based)
  392. twRc = pcapXferCount->SetCurrent(m_NumIWiaItems);
  393. }
  394. NumImages = pcapXferCount->GetCurrent();
  395. } else {
  396. DBG_ERR(("CWiaCameraDS::EnableDS(), could not find CAP_XFERCOUNT in supported CAP list"));
  397. twRc = TWRC_FAILURE;
  398. }
  399. if (TWRC_SUCCESS == twRc) {
  400. //
  401. // set thumbnail count
  402. //
  403. CCap *pDataSet = NULL;
  404. pDataSet = FindCap(ICAP_IMAGEDATASET);
  405. if(pDataSet){
  406. pDataSet->Set((TW_UINT32)NumImages,(TW_UINT32)NumImages,(TW_UINT32)NumImages,(TW_UINT32)NumImages,1);
  407. }
  408. if (m_NumIWiaItems) {
  409. //
  410. // transition to STATE_5, XferReady will transition to STATE_6
  411. //
  412. SetTWAINState(DS_STATE_5);
  413. NotifyXferReady();
  414. } else {
  415. NotifyCloseReq();
  416. //
  417. // transition to STATE_5
  418. //
  419. SetTWAINState(DS_STATE_5);
  420. }
  421. }
  422. }
  423. }
  424. return twRc;
  425. }
  426. TW_UINT16 CWiaCameraDS::OnPendingXfersMsg(PTWAIN_MSG ptwMsg)
  427. {
  428. TW_UINT16 twRc = TWRC_SUCCESS;
  429. CCap *pXferCount;
  430. pXferCount = FindCap(CAP_XFERCOUNT);
  431. if (!pXferCount) {
  432. m_twStatus.ConditionCode = TWCC_BUMMER;
  433. return TWRC_FAILURE;
  434. }
  435. twRc = TWRC_SUCCESS;
  436. switch (ptwMsg->MSG) {
  437. case MSG_GET:
  438. switch (GetTWAINState()) {
  439. case DS_STATE_4:
  440. case DS_STATE_5:
  441. case DS_STATE_6:
  442. case DS_STATE_7:
  443. ((TW_PENDINGXFERS *)ptwMsg->pData)->Count = (TW_INT16)pXferCount->GetCurrent();
  444. DBG_TRC(("CWiaCameraDS::OnPendingXfersMsg(), MSG_GET returning %d",((TW_PENDINGXFERS *)ptwMsg->pData)->Count));
  445. break;
  446. default:
  447. twRc = TWRC_FAILURE;
  448. m_twStatus.ConditionCode = TWCC_SEQERROR;
  449. DSError();
  450. break;
  451. }
  452. break;
  453. case MSG_ENDXFER:
  454. if (DS_STATE_6 == GetTWAINState() || DS_STATE_7 == GetTWAINState()) {
  455. ResetMemXfer();
  456. TW_INT32 Count = 0;
  457. Count = pXferCount->GetCurrent();
  458. Count--;
  459. if (Count <= 0) {
  460. Count = 0;
  461. DBG_TRC(("CWiaCameraDS::OnPendingXfersMsg(), MSG_ENDXFER, 0 (no more images left to transfer)"));
  462. ((TW_PENDINGXFERS *)ptwMsg->pData)->Count = (TW_UINT16)0;
  463. //
  464. // update count now, so NotifyCoseReq can be prepared for reentry by a TWAIN application
  465. //
  466. pXferCount->SetCurrent((TW_UINT32)0);
  467. //
  468. // Transition to STATE_5
  469. //
  470. SetTWAINState(DS_STATE_5);
  471. NotifyCloseReq();
  472. } else {
  473. DBG_TRC(("CWiaCameraDS::OnPendingXfersMsg(), MSG_ENDXFER, %d (more images may be ready to transfer)",Count));
  474. //
  475. // Advance to next image
  476. //
  477. if (m_bRangeModeAcquisition) {
  478. m_NextIWiaItemIndex+=1; // use Step value???
  479. if(m_NextIWiaItemIndex <= (LONG)m_twImageRange.MaxValue){
  480. m_pCurrentIWiaItem = m_pIWiaItems[m_NextIWiaItemIndex];
  481. } else {
  482. DBG_ERR(("CWiaCameraDS::OnPendingXfersMsg(), MSG_ENDXFER, we are over our allowed RANGE index"));
  483. }
  484. } else if (m_bArrayModeAcquisition) {
  485. m_lCurrentArrayIndex++; // advance to next image index
  486. DBG_TRC(("CWiaCameraDS::OnPendingXfersMsg(), MSG_ENDXFER, next image index to acquire = %d",m_pulImageIndexes[m_lCurrentArrayIndex]));
  487. m_NextIWiaItemIndex = m_pulImageIndexes[m_lCurrentArrayIndex];
  488. if(m_NextIWiaItemIndex <= m_lNumValidIndexes){
  489. m_pCurrentIWiaItem = m_pIWiaItems[m_NextIWiaItemIndex];
  490. } else {
  491. DBG_ERR(("CWiaCameraDS::OnPendingXfersMsg(), MSG_ENDXFER, we are over our allowed ARRAY index"));
  492. }
  493. } else {
  494. m_pCurrentIWiaItem = m_pIWiaItems[m_NextIWiaItemIndex++];
  495. }
  496. //
  497. // Transition to STATE_6
  498. //
  499. SetTWAINState(DS_STATE_6);
  500. ((TW_PENDINGXFERS *)ptwMsg->pData)->Count = (TW_UINT16)Count;
  501. }
  502. //
  503. // update count
  504. //
  505. pXferCount->SetCurrent((TW_UINT32)Count);
  506. } else {
  507. twRc = TWRC_FAILURE;
  508. m_twStatus.ConditionCode = TWCC_SEQERROR;
  509. DSError();
  510. }
  511. break;
  512. case MSG_RESET:
  513. if (DS_STATE_6 == GetTWAINState()) {
  514. ((TW_PENDINGXFERS*)ptwMsg->pData)->Count = 0;
  515. pXferCount->SetCurrent((TW_UINT32)0);
  516. ResetMemXfer();
  517. //
  518. // Transition to STATE_5
  519. //
  520. SetTWAINState(DS_STATE_5);
  521. } else {
  522. twRc = TWRC_FAILURE;
  523. m_twStatus.ConditionCode = TWCC_SEQERROR;
  524. DSError();
  525. }
  526. break;
  527. default:
  528. twRc = TWRC_FAILURE;
  529. m_twStatus.ConditionCode = TWCC_BADPROTOCOL;
  530. DSError();
  531. break;
  532. }
  533. return twRc;
  534. }
  535. TW_UINT16 CWiaCameraDS::OnImageInfoMsg(PTWAIN_MSG ptwMsg)
  536. {
  537. TW_UINT16 twRc = TWRC_FAILURE;
  538. BOOL bThumbailMode = FALSE;
  539. CCap *pCap = NULL;
  540. pCap = FindCap(CAP_THUMBNAILSENABLED);
  541. if (pCap) {
  542. if (pCap->GetCurrent()) {
  543. bThumbailMode = TRUE;
  544. }
  545. } else {
  546. DBG_ERR(("CWiaCameraDS::OnImageInfoMsg(), could not get CAP_THUMBNAILSENABLED capabilty settings"));
  547. }
  548. if (bThumbailMode) {
  549. DBG_TRC(("CWiaCameraDS::OnImageInfoMsg(), Reporting Thumbnail image information"));
  550. TW_IMAGEINFO *ptwImageInfo = NULL;
  551. if (DS_STATE_6 == GetTWAINState()) {
  552. if (MSG_GET == ptwMsg->MSG) {
  553. ptwImageInfo = (TW_IMAGEINFO *)ptwMsg->pData;
  554. HRESULT hr = S_OK;
  555. hr = m_pDevice->GetThumbnailImageInfo(m_pCurrentIWiaItem, &m_MemoryTransferInfo);
  556. if (SUCCEEDED(hr)) {
  557. ptwImageInfo->ImageWidth = (TW_INT32)m_MemoryTransferInfo.mtiWidthPixels;
  558. ptwImageInfo->ImageLength = (TW_INT32)m_MemoryTransferInfo.mtiHeightPixels;
  559. ptwImageInfo->BitsPerPixel = (TW_INT16)m_MemoryTransferInfo.mtiBitsPerPixel;
  560. ptwImageInfo->SamplesPerPixel = (TW_INT16)m_MemoryTransferInfo.mtiNumChannels;
  561. ptwImageInfo->Planar = (TW_BOOL)m_MemoryTransferInfo.mtiPlanar;
  562. //
  563. // set PixelType to corresponding TWAIN pixel type
  564. //
  565. switch (m_MemoryTransferInfo.mtiDataType) {
  566. case WIA_DATA_THRESHOLD:
  567. ptwImageInfo->PixelType = TWPT_BW;
  568. break;
  569. case WIA_DATA_GRAYSCALE:
  570. ptwImageInfo->PixelType = TWPT_GRAY;
  571. break;
  572. case WIA_DATA_COLOR:
  573. default:
  574. ptwImageInfo->PixelType = TWPT_RGB;
  575. break;
  576. }
  577. //
  578. // set compression to NONE
  579. //
  580. ptwImageInfo->Compression = TWCP_NONE;
  581. //
  582. // Unit conversion.......
  583. //
  584. ptwImageInfo->XResolution = FloatToFix32((float)m_MemoryTransferInfo.mtiXResolution);
  585. ptwImageInfo->YResolution = FloatToFix32((float)m_MemoryTransferInfo.mtiYResolution);
  586. twRc = TWRC_SUCCESS;
  587. } else {
  588. m_twStatus.ConditionCode = TWCC_OPERATIONERROR;
  589. twRc = TWRC_FAILURE;
  590. }
  591. if (TWRC_SUCCESS == twRc) {
  592. DBG_TRC(("CWiaCameraDS::OnImageInfoMsg(), Reported Image Information from data source"));
  593. DBG_TRC(("XResolution = %d.%d",ptwImageInfo->XResolution.Whole,ptwImageInfo->XResolution.Frac));
  594. DBG_TRC(("YResolution = %d.%d",ptwImageInfo->YResolution.Whole,ptwImageInfo->YResolution.Frac));
  595. DBG_TRC(("ImageWidth = %d",ptwImageInfo->ImageWidth));
  596. DBG_TRC(("ImageLength = %d",ptwImageInfo->ImageLength));
  597. DBG_TRC(("SamplesPerPixel = %d",ptwImageInfo->SamplesPerPixel));
  598. memset(ptwImageInfo->BitsPerSample,0,sizeof(ptwImageInfo->BitsPerSample));
  599. if (ptwImageInfo->BitsPerPixel < 24) {
  600. ptwImageInfo->BitsPerSample[0] = ptwImageInfo->BitsPerPixel;
  601. } else {
  602. for (int i = 0; i < ptwImageInfo->SamplesPerPixel; i++) {
  603. ptwImageInfo->BitsPerSample[i] = (ptwImageInfo->BitsPerPixel/ptwImageInfo->SamplesPerPixel);
  604. }
  605. }
  606. // (bpp / spp) = bps
  607. DBG_TRC(("BitsPerSample = [%d],[%d],[%d],[%d],[%d],[%d],[%d],[%d]",ptwImageInfo->BitsPerSample[0],
  608. ptwImageInfo->BitsPerSample[1],
  609. ptwImageInfo->BitsPerSample[2],
  610. ptwImageInfo->BitsPerSample[3],
  611. ptwImageInfo->BitsPerSample[4],
  612. ptwImageInfo->BitsPerSample[5],
  613. ptwImageInfo->BitsPerSample[6],
  614. ptwImageInfo->BitsPerSample[7]));
  615. DBG_TRC(("BitsPerPixel = %d",ptwImageInfo->BitsPerPixel));
  616. DBG_TRC(("Planar = %d",ptwImageInfo->Planar));
  617. DBG_TRC(("PixelType = %d",ptwImageInfo->PixelType));
  618. DBG_TRC(("Compression = %d",ptwImageInfo->Compression));
  619. }
  620. } else {
  621. m_twStatus.ConditionCode = TWCC_BADPROTOCOL;
  622. twRc = TWRC_FAILURE;
  623. }
  624. } else {
  625. m_twStatus.ConditionCode = TWCC_SEQERROR;
  626. twRc = TWRC_FAILURE;
  627. }
  628. if (TWRC_SUCCESS != twRc) {
  629. DSError();
  630. }
  631. } else {
  632. twRc = CWiaDataSrc::OnImageInfoMsg(ptwMsg);
  633. }
  634. return twRc;
  635. }
  636. TW_UINT16 CWiaCameraDS::TransferToDIB(HGLOBAL *phDIB)
  637. {
  638. TW_UINT16 twRc = TWRC_FAILURE;
  639. BOOL bThumbailMode = FALSE;
  640. CCap *pCap = NULL;
  641. pCap = FindCap(CAP_THUMBNAILSENABLED);
  642. if (pCap) {
  643. bThumbailMode = pCap->GetCurrent();
  644. }
  645. if(bThumbailMode){
  646. twRc = CWiaDataSrc::TransferToThumbnail(phDIB);
  647. } else {
  648. twRc = CWiaDataSrc::TransferToDIB(phDIB);
  649. }
  650. return twRc;
  651. }