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.

1236 lines
34 KiB

  1. /**************************************************************************
  2. *
  3. * SETDI.C - contains routines for doing a SetDIBits() into a bitmap.
  4. *
  5. **************************************************************************/
  6. #include <windows.h>
  7. #include <windowsx.h>
  8. #include <win32.h>
  9. #include "lockbm.h"
  10. #include "setdi.h"
  11. /**************************************************************************
  12. *
  13. * format conversion functions.
  14. *
  15. * special functions....
  16. * copy_8_8 (no translate)
  17. * dither_8_8 (dither from 8bpp to fixed color device (like VGA, SVGA...)
  18. *
  19. **************************************************************************/
  20. extern CONVERTPROC copy_8_8, dither_8_8;
  21. extern CONVERTPROC convert_8_8, convert_8_16, convert_8_24, convert_8_32, convert_8_VGA, convert_8_565, convert_8_RGB, convert_8_RGBX;
  22. extern CONVERTPROC convert_16_8, convert_16_16, convert_16_24, convert_16_32, convert_16_VGA, convert_16_565, convert_16_RGB, convert_16_RGBX;
  23. extern CONVERTPROC convert_24_8, convert_24_16, convert_24_24, convert_24_32, convert_24_VGA, convert_24_565, convert_24_RGB, convert_24_RGBX;
  24. extern CONVERTPROC convert_32_8, convert_32_16, convert_32_24, convert_32_32, convert_32_VGA, convert_32_565, convert_32_RGB, convert_32_RGBX;
  25. static INITPROC init_8_8, init_8_16, init_8_24, init_8_32, init_8_VGA, init_8_565, init_8_RGB, init_8_RGBX;
  26. static INITPROC init_16_8, init_16_16, init_16_24, init_16_32, init_16_VGA, init_16_565, init_16_RGB, init_16_RGBX;
  27. static INITPROC init_24_8, init_24_16, init_24_24, init_24_32, init_24_VGA, init_24_565, init_24_RGB, init_24_RGBX;
  28. static INITPROC init_32_8, init_32_16, init_32_24, init_32_32, init_32_VGA, init_32_565, init_32_RGB, init_32_RGBX;
  29. static INITPROC init_setdi;
  30. static CONVERTPROC convert_setdi;
  31. static FREEPROC free_common;
  32. static LPVOID init_dither_8_8(HDC hdc, LPBITMAPINFOHEADER lpbi);
  33. /**************************************************************************
  34. *
  35. * some conversions we dont do
  36. *
  37. **************************************************************************/
  38. #define convert_8_VGA NULL
  39. #define convert_16_VGA NULL
  40. #define convert_24_VGA NULL
  41. #define convert_32_VGA NULL
  42. #define convert_8_32 NULL
  43. #define convert_16_32 NULL
  44. #define convert_24_32 NULL
  45. #define convert_32_32 NULL
  46. #define convert_8_RGBX NULL
  47. #define convert_16_RGBX NULL
  48. #define convert_24_RGBX NULL
  49. #define convert_32_RGBX NULL
  50. #define convert_8_RGB NULL
  51. #define convert_16_RGB NULL
  52. #define convert_24_RGB NULL
  53. #define convert_32_RGB NULL
  54. #define convert_16_8 NULL // not now later!
  55. #define convert_24_8 NULL
  56. #define convert_32_8 NULL
  57. /**************************************************************************
  58. *
  59. * format conversion tables...
  60. *
  61. * BITMAP types
  62. *
  63. * 8 0
  64. * 16 1
  65. * 24 2
  66. * 32 3
  67. * VGA 4
  68. * 16 565 5
  69. * 24 RGB 6
  70. * 32 RGB 7
  71. *
  72. **************************************************************************/
  73. static PCONVERTPROC ConvertProcTable[4][8] = {
  74. {convert_8_8, convert_8_16, convert_8_24, convert_8_32, convert_8_VGA, convert_8_565, convert_8_RGB, convert_8_RGBX},
  75. {convert_16_8, convert_16_16, convert_16_24, convert_16_32, convert_16_VGA, convert_16_565, convert_16_RGB, convert_16_RGBX},
  76. {convert_24_8, convert_24_16, convert_24_24, convert_24_32, convert_24_VGA, convert_24_565, convert_24_RGB, convert_24_RGBX},
  77. {convert_32_8, convert_32_16, convert_32_24, convert_32_32, convert_32_VGA, convert_32_565, convert_32_RGB, convert_32_RGBX},
  78. };
  79. static PINITPROC InitProcTable[4][8] = {
  80. {init_8_8, init_8_16, init_8_24, init_8_32, init_8_VGA, init_8_565, init_8_RGB, init_8_RGBX},
  81. {init_16_8, init_16_16, init_16_24, init_16_32, init_16_VGA, init_16_565, init_16_RGB, init_16_RGBX},
  82. {init_24_8, init_24_16, init_24_24, init_24_32, init_24_VGA, init_24_565, init_24_RGB, init_24_RGBX},
  83. {init_32_8, init_32_16, init_32_24, init_32_32, init_32_VGA, init_32_565, init_32_RGB, init_32_RGBX},
  84. };
  85. /**************************************************************************
  86. **************************************************************************/
  87. #define RGB555(r,g,b) (\
  88. (((WORD)(r) >> 3) << 10) | \
  89. (((WORD)(g) >> 3) << 5) | \
  90. (((WORD)(b) >> 3) << 0) )
  91. #define RGB565(r,g,b) (\
  92. (((WORD)(r) >> 3) << 11) | \
  93. (((WORD)(g) >> 2) << 5) | \
  94. (((WORD)(b) >> 3) << 0) )
  95. /**************************************************************************
  96. **************************************************************************/
  97. #ifdef DEBUG
  98. static
  99. #else
  100. __inline
  101. #endif
  102. LONG BitmapXY(IBITMAP *pbm, int x, int y)
  103. {
  104. LONG offset = pbm->bmOffset;
  105. //!!! wrong!!! but y for bitmaps is always zero....
  106. // if (pbm->bmFillBytes)
  107. // offset += (y / pbm->bmScanSegment) * pbm->bmFillBytes;
  108. offset += y * (long)pbm->bmNextScan;
  109. offset += x * pbm->bmBitsPixel / 8;
  110. return offset;
  111. }
  112. /**************************************************************************
  113. * @doc INTERNAL SetBitmapBegin
  114. *
  115. * @api BOOL | SetBitmapBegin | prepare to do a SetDIBits() into a bitmap
  116. *
  117. * @rdesc Returns TRUE if success.
  118. *
  119. **************************************************************************/
  120. BOOL FAR SetBitmapBegin(
  121. PSETDI psd,
  122. HDC hdc, //
  123. HBITMAP hbm, // bitmap to set into
  124. LPBITMAPINFOHEADER lpbi, // --> BITMAPINFO of source
  125. UINT DibUsage)
  126. {
  127. BITMAP bm;
  128. SetBitmapEnd(psd); // free and old stuff
  129. GetObject(hbm, sizeof(bm), &bm);
  130. psd->hbm = hbm;
  131. // psd->hdc = hdc;
  132. // psd->hpal = hpal;
  133. psd->DibUsage= DibUsage;
  134. psd->color_convert = NULL;
  135. psd->convert = NULL;
  136. psd->size = sizeof(SETDI);
  137. if (!GetBitmapDIB(lpbi, NULL, &psd->bmSrc, sizeof(psd->bmSrc)))
  138. return FALSE;
  139. //
  140. // make sure we can lock the bitmap
  141. //
  142. if (GetBitmap(hbm, &psd->bmDst, sizeof(psd->bmDst)) &&
  143. psd->bmDst.bmFillBytes <= 0 &&
  144. psd->bmSrc.bmType > 0 && psd->bmSrc.bmType <= 4 &&
  145. psd->bmDst.bmType > 0 && psd->bmDst.bmType <= 8)
  146. {
  147. psd->init = InitProcTable[psd->bmSrc.bmType-1][psd->bmDst.bmType-1];
  148. psd->convert = ConvertProcTable[psd->bmSrc.bmType-1][psd->bmDst.bmType-1];
  149. psd->free = free_common;
  150. }
  151. //
  152. // if we cant convert ourself try SetDIBits()
  153. //
  154. if (psd->convert == NULL)
  155. {
  156. psd->convert = convert_setdi;
  157. psd->init = init_setdi;
  158. psd->free = NULL;
  159. }
  160. if (psd->init)
  161. {
  162. psd->hdc = hdc;
  163. if (!psd->init(psd))
  164. {
  165. psd->hdc = 0;
  166. psd->size = 0;
  167. psd->convert = NULL;
  168. return FALSE;
  169. }
  170. psd->hdc = NULL;
  171. psd->hpal = NULL;
  172. }
  173. return TRUE;
  174. }
  175. /**************************************************************************
  176. * @doc INTERNAL SetBitmapColorChange
  177. *
  178. * @api BOOL | SetBitmapColorChange | re-init the color conversion
  179. *
  180. * @rdesc Returns TRUE if success.
  181. *
  182. **************************************************************************/
  183. void FAR SetBitmapColorChange(PSETDI psd, HDC hdc, HPALETTE hpal)
  184. {
  185. if (psd->size != sizeof(SETDI))
  186. return;
  187. if (hdc == NULL)
  188. return;
  189. if (psd->free) //!!! ack?
  190. psd->free(psd);
  191. psd->hdc = hdc;
  192. psd->hpal = hpal;
  193. if (psd->init)
  194. psd->init(psd);
  195. psd->hdc = NULL;
  196. psd->hpal = NULL;
  197. }
  198. /**************************************************************************
  199. * @doc INTERNAL SetBitmapEnd
  200. *
  201. * @api void | SetBitmapEnd | clean out a SETDI structure
  202. *
  203. **************************************************************************/
  204. void FAR SetBitmapEnd(PSETDI psd)
  205. {
  206. if (psd->size != sizeof(SETDI))
  207. return;
  208. if (psd->free)
  209. psd->free(psd);
  210. psd->size = 0;
  211. psd->convert = NULL;
  212. psd->init = NULL;
  213. psd->free = NULL;
  214. }
  215. /**************************************************************************
  216. * @doc INTERNAL SetBitmap
  217. *
  218. * @api BOOL | SetBitmap | convert DIB bits to bitmaps bits.
  219. *
  220. **************************************************************************/
  221. BOOL FAR SetBitmap(PSETDI psd, int DstX, int DstY, int DstDX, int DstDY, LPVOID lpBits, int SrcX, int SrcY, int SrcDX, int SrcDY)
  222. {
  223. if (psd->size != sizeof(SETDI))
  224. return FALSE;
  225. psd->convert(
  226. psd->bmDst.bmBits, // --> dst.
  227. BitmapXY(&psd->bmDst, DstX, DstY), // offset to start at
  228. psd->bmDst.bmNextScan, // dst_next_scan.
  229. psd->bmDst.bmFillBytes, // fill bytes
  230. lpBits, // --> Src.
  231. BitmapXY(&psd->bmSrc, SrcX, SrcY), // offset to start at
  232. psd->bmSrc.bmNextScan, // Src_next_scan.
  233. DstDX,
  234. DstDY,
  235. psd->color_convert);
  236. return TRUE;
  237. }
  238. /**************************************************************************
  239. *
  240. * cleanup stuff
  241. *
  242. **************************************************************************/
  243. static BOOL free_common(PSETDI psd)
  244. {
  245. //
  246. // clean up what we did
  247. //
  248. if (psd->color_convert != NULL)
  249. GlobalFreePtr(psd->color_convert);
  250. psd->color_convert = NULL;
  251. return TRUE;
  252. }
  253. /**************************************************************************
  254. *
  255. * GetBackgroundTranslate
  256. *
  257. * get the foreground to background translate table.
  258. *
  259. * does this by calling GDI, this should always work.
  260. * this only works on a palette device.
  261. *
  262. **************************************************************************/
  263. BOOL GetBackgroundTranslate(HDC hdc, LPBYTE pb)
  264. {
  265. int i;
  266. int n;
  267. DWORD rgb;
  268. DWORD *prgb;
  269. #ifndef _WIN32 // until we can find this on NT... make it 16bit only
  270. extern BOOL FAR PASCAL IsDCCurrentPalette(HDC hdc);
  271. if (IsDCCurrentPalette(hdc))
  272. {
  273. for (i=0; i<256; i++)
  274. pb[i] = i;
  275. return TRUE;
  276. }
  277. #endif
  278. prgb = (DWORD *)LocalAlloc(LPTR, 256 * sizeof(DWORD));
  279. if (prgb == NULL)
  280. return TRUE;
  281. GetSystemPaletteEntries(hdc, 0, 256,(PALETTEENTRY FAR *)prgb);
  282. for (n=0; n<256; n++) //!!! is this needed.
  283. prgb[n] &= 0x00FFFFFF;
  284. for (i=0; i<256; i++)
  285. {
  286. //
  287. // GDI will figure out what physical color this palette
  288. // index is mapped to.
  289. //
  290. rgb = GetNearestColor(hdc, PALETTEINDEX(i)) & 0x00FFFFFF;
  291. //
  292. // quick check for identity map.
  293. //
  294. if (prgb[i] == rgb)
  295. {
  296. pb[i] = (BYTE)i;
  297. continue;
  298. }
  299. //
  300. // now we have to find the rgb in the physical palette
  301. //
  302. for (n=0; n<256; n++)
  303. if (prgb[n] == rgb)
  304. break;
  305. //
  306. // our search should never fail, because GDI gave us a RGB
  307. // in the palette.
  308. //
  309. if (n == 256) //!!! should never happen
  310. n = 0;
  311. pb[i] = (BYTE)n;
  312. }
  313. LocalFree((HLOCAL)prgb);
  314. return TRUE;
  315. }
  316. /**************************************************************************
  317. *
  318. * @doc INTERNAL GetPaletteMap
  319. *
  320. * @api BOOL | GetPhysPaletteMap | gets the physical mapping for a DIB
  321. *
  322. * returns TRUE if the mapping is a 1:1 mapping, FALSE otherwise
  323. *
  324. **************************************************************************/
  325. BOOL GetPhysDibPaletteMap(HDC hdc, LPBITMAPINFOHEADER lpbi, UINT Usage, LPBYTE pb)
  326. {
  327. int i;
  328. int n;
  329. BYTE ab[256];
  330. GetDibPaletteMap(hdc, lpbi, Usage, pb);
  331. GetBackgroundTranslate(hdc, ab);
  332. //
  333. // translate forground palette to physical
  334. //
  335. for (i=0; i<256; i++)
  336. pb[i] = ab[pb[i]];
  337. //
  338. // test for 1:1
  339. //
  340. n = (int)lpbi->biClrUsed ? (int)lpbi->biClrUsed : 256;
  341. for (i=0; i<n; i++)
  342. if (pb[i] != i)
  343. break;
  344. return i == n;
  345. }
  346. /**************************************************************************
  347. *
  348. * @doc INTERNAL
  349. *
  350. * @api void | GetDibPaletteMap | gets the mapping of a DIB color table
  351. * in foreground palette index's
  352. *
  353. **************************************************************************/
  354. BOOL GetDibPaletteMap(HDC hdc, LPBITMAPINFOHEADER lpbi, UINT Usage, LPBYTE pb)
  355. {
  356. HBITMAP hbm;
  357. int i;
  358. int n;
  359. LONG biWidth = lpbi->biWidth;
  360. LONG biHeight = lpbi->biHeight;
  361. LONG biSizeImage = lpbi->biSizeImage;
  362. n = (int)lpbi->biClrUsed ? (int)lpbi->biClrUsed : 256;
  363. for (i=0; i<n; i++)
  364. pb[i] = (BYTE) i;
  365. for (; i<256; i++)
  366. pb[i] = 0;
  367. if (lpbi->biBitCount != 8)
  368. return FALSE;
  369. hbm = CreateCompatibleBitmap(hdc,256,1);
  370. lpbi->biSizeImage = 256;
  371. lpbi->biWidth = 256;
  372. lpbi->biHeight = 1;
  373. SetDIBits(hdc, hbm, 0, 1, pb, (LPBITMAPINFO)lpbi, Usage);
  374. GetBitmapBits(hbm, 256, pb);
  375. DeleteObject(hbm);
  376. lpbi->biWidth = biWidth;
  377. lpbi->biHeight = biHeight;
  378. lpbi->biSizeImage = biSizeImage;
  379. //
  380. // test for 1:1 translate
  381. //
  382. for (i=0; i<n; i++)
  383. {
  384. if (pb[i] != i)
  385. {
  386. //
  387. // some ET4000 drivers have the same color (128,128,128)
  388. // at index 7 and at index 248.
  389. //
  390. // we should detect a identity palette in this case.
  391. //
  392. if (i == 248 && pb[i] == 7)
  393. {
  394. pb[i] = 248;
  395. continue;
  396. }
  397. break;
  398. }
  399. }
  400. return i == n;
  401. }
  402. /**************************************************************************
  403. *
  404. * convert for SetDIBits
  405. *
  406. **************************************************************************/
  407. void FAR PASCAL convert_setdi(
  408. LPVOID pd, // --> dst.
  409. LONG dd, // offset to start at
  410. LONG nd, // dst_next_scan.
  411. LONG fd, // dst fill bytes
  412. LPVOID ps, // --> source.
  413. LONG ds, // offset to start at
  414. LONG ns, // src_next_scan.
  415. LONG dx, // pixel count.
  416. LONG dy, // scan count.
  417. LPVOID pc) // pixel convert table.
  418. {
  419. PSETDI psd = (PSETDI)(LONG_PTR)pd;
  420. LPBITMAPINFOHEADER lpbi;
  421. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  422. lpbi->biHeight = dy;
  423. SetDIBits(
  424. psd->hdc,
  425. psd->hbm,
  426. 0,(int)dy,
  427. ((BYTE _huge *)ps) + ds - dd,
  428. (LPBITMAPINFO)lpbi,
  429. psd->DibUsage);
  430. lpbi->biHeight = psd->bmSrc.bmHeight;
  431. }
  432. /**************************************************************************
  433. *
  434. * init stuff for SetDIBits
  435. *
  436. **************************************************************************/
  437. static BOOL init_setdi(PSETDI psd)
  438. {
  439. UINT u;
  440. HDC hdc;
  441. LPBYTE p;
  442. LPBITMAPINFOHEADER lpbi;
  443. // test to see if SetDIBits() works.
  444. // !!! we should check for 16 or a 32bit DIB and do the escape.
  445. // !!! on a palette device we need to build a palette map!!!
  446. if (psd->bmSrc.bmBitsPixel == 16 ||
  447. psd->bmSrc.bmBitsPixel == 32)
  448. return FALSE;
  449. // convert_setdi will need this.
  450. psd->bmDst.bmBits = (LPVOID)(UINT_PTR)psd;
  451. psd->bmDst.bmOffset = 0;
  452. psd->bmDst.bmBitsPixel = psd->bmSrc.bmBitsPixel;
  453. if (psd->hdc && psd->hpal)
  454. {
  455. // map colors to current palette!!!!!!!!!!!!!!!!!!!!!!!!!!
  456. //set this to be the BITMAPINFO + color map.
  457. psd->color_convert = 0;
  458. }
  459. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  460. lpbi->biHeight = 1;
  461. p = (LPBYTE)GlobalAllocPtr(GHND,psd->bmSrc.bmWidthBytes);
  462. hdc = GetDC(NULL);
  463. u = SetDIBits(
  464. hdc,
  465. psd->hbm,0,1,p,
  466. (LPBITMAPINFO)psd->bmSrc.bmBitmapInfo,
  467. psd->DibUsage);
  468. ReleaseDC(NULL, hdc);
  469. lpbi->biHeight = psd->bmSrc.bmHeight;
  470. GlobalFreePtr(p);
  471. return u == 1;
  472. }
  473. /**************************************************************************
  474. *
  475. * init stuff for 8bpp bitmaps
  476. *
  477. **************************************************************************/
  478. static BOOL init_8_8(PSETDI psd)
  479. {
  480. LPBITMAPINFOHEADER lpbi;
  481. //
  482. // if we are mapping from one DIB to another figure this out
  483. //
  484. if (psd->hdc == NULL || psd->bmDst.bmBitmapInfo != 0)
  485. {
  486. // we assume this routine will not be used for color matching
  487. // from DIB to DIB, so give up.
  488. psd->convert = copy_8_8;
  489. return TRUE;
  490. }
  491. //
  492. // we are mapping to a device (HDC)
  493. //
  494. // we need to compute a 8-->8 conversion table, from the source colors
  495. // (in psd->lpbiSrc) to the colors on the device.
  496. //
  497. // how we do this depends on weather the device is a palette device or not.
  498. //
  499. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  500. if (GetDeviceCaps(psd->hdc, RASTERCAPS) & RC_PALETTE)
  501. {
  502. if (psd->hpal == NULL)
  503. {
  504. // no palette to match to yet
  505. psd->convert = copy_8_8;
  506. return TRUE;
  507. }
  508. if (psd->color_convert == NULL)
  509. psd->color_convert = GlobalAllocPtr(GHND, 256);
  510. //
  511. // we can do this one of two ways,
  512. //
  513. // we can always convert to the palette foreground mapping, or
  514. //
  515. // we can convert to the current colors always (using this method
  516. // we will need to recompute the xlat table on every palette
  517. // change)
  518. //
  519. // lets convert to the current device colors. (this may cause
  520. // problems we will check on later...)
  521. //
  522. // if (GetPhysDibPaletteMap(psd->hdc, lpbi, psd->DibUsage, psd->color_convert))
  523. if (GetDibPaletteMap(psd->hdc, lpbi, psd->DibUsage, psd->color_convert))
  524. psd->convert = copy_8_8;
  525. else
  526. psd->convert = convert_8_8;
  527. }
  528. else
  529. {
  530. // !!!we should check for solid colors (ie no dither needed) and also
  531. // check for 1:1 (no translate)
  532. if (psd->color_convert == NULL) //!!!
  533. psd->color_convert = init_dither_8_8(psd->hdc, lpbi);
  534. psd->convert = dither_8_8;
  535. //!!! we need to give the device colors to the caller
  536. }
  537. return TRUE;
  538. }
  539. static BOOL init_16_8(PSETDI psd)
  540. {
  541. return FALSE; // we dont handle dither yet!
  542. }
  543. static BOOL init_24_8(PSETDI psd)
  544. {
  545. return FALSE; // we dont handle dither yet!
  546. }
  547. static BOOL init_32_8(PSETDI psd)
  548. {
  549. return FALSE; // we dont handle dither yet!
  550. }
  551. /**************************************************************************
  552. *
  553. * init stuff for 16bpp bitmaps
  554. *
  555. **************************************************************************/
  556. static BOOL init_8_16(PSETDI psd)
  557. {
  558. WORD FAR*pw;
  559. int i;
  560. int n;
  561. LPRGBQUAD prgb;
  562. LPBITMAPINFOHEADER lpbi;
  563. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  564. if (psd->color_convert == NULL) //!!!
  565. psd->color_convert = GlobalAllocPtr(GHND, 256*2);
  566. n = (lpbi->biClrUsed == 0) ? 256 : (int)lpbi->biClrUsed;
  567. prgb = (LPRGBQUAD)((LPBYTE)lpbi + (int)lpbi->biSize);
  568. pw = psd->color_convert;
  569. for (i=0; i<n; i++)
  570. pw[i] = RGB555(prgb[i].rgbRed, prgb[i].rgbGreen, prgb[i].rgbBlue);
  571. for (; i<256; i++)
  572. pw[i] = 0;
  573. return TRUE;
  574. }
  575. static BOOL init_16_16(PSETDI psd)
  576. {
  577. return TRUE;
  578. }
  579. static BOOL init_24_16(PSETDI psd)
  580. {
  581. return TRUE;
  582. }
  583. static BOOL init_32_16(PSETDI psd)
  584. {
  585. return TRUE;
  586. }
  587. /**************************************************************************
  588. *
  589. * init stuff for 24bpp bitmaps
  590. *
  591. **************************************************************************/
  592. static BOOL init_8_24(PSETDI psd)
  593. {
  594. DWORD FAR*pd;
  595. int i;
  596. int n;
  597. LPRGBQUAD prgb;
  598. LPBITMAPINFOHEADER lpbi;
  599. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  600. if (psd->color_convert == NULL) //!!!
  601. psd->color_convert = GlobalAllocPtr(GHND, 256*4);
  602. n = (lpbi->biClrUsed == 0) ? 256 : (int)lpbi->biClrUsed;
  603. prgb = (LPRGBQUAD)((LPBYTE)lpbi + (int)lpbi->biSize);
  604. pd = psd->color_convert;
  605. for (i=0; i<n; i++)
  606. pd[i] = RGB(prgb[i].rgbBlue, prgb[i].rgbGreen, prgb[i].rgbRed);
  607. for (; i<256; i++)
  608. pd[i] = 0;
  609. return TRUE;
  610. }
  611. static BOOL init_16_24(PSETDI psd)
  612. {
  613. return TRUE;
  614. }
  615. static BOOL init_24_24(PSETDI psd)
  616. {
  617. return TRUE;
  618. }
  619. static BOOL init_32_24(PSETDI psd)
  620. {
  621. return TRUE;
  622. }
  623. /**************************************************************************
  624. *
  625. * init stuff for 32bpp bitmaps
  626. *
  627. **************************************************************************/
  628. static BOOL init_8_32(PSETDI psd)
  629. {
  630. return FALSE;
  631. ////return init_8_24(psd);
  632. }
  633. static BOOL init_16_32(PSETDI psd)
  634. {
  635. return FALSE;
  636. }
  637. static BOOL init_24_32(PSETDI psd)
  638. {
  639. return FALSE;
  640. }
  641. static BOOL init_32_32(PSETDI psd)
  642. {
  643. return FALSE;
  644. }
  645. /**************************************************************************
  646. *
  647. * init stuff for VGA bitmaps
  648. *
  649. **************************************************************************/
  650. static BOOL init_8_VGA(PSETDI psd)
  651. {
  652. return FALSE;
  653. }
  654. static BOOL init_16_VGA(PSETDI psd)
  655. {
  656. return FALSE;
  657. }
  658. static BOOL init_24_VGA(PSETDI psd)
  659. {
  660. return FALSE;
  661. }
  662. static BOOL init_32_VGA(PSETDI psd)
  663. {
  664. return FALSE;
  665. }
  666. /**************************************************************************
  667. *
  668. * init stuff for RGB 565 bitmaps
  669. *
  670. **************************************************************************/
  671. static BOOL init_8_565(PSETDI psd)
  672. {
  673. WORD FAR*pw;
  674. int i;
  675. int n;
  676. LPRGBQUAD prgb;
  677. LPBITMAPINFOHEADER lpbi;
  678. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  679. if (psd->color_convert == NULL) //!!!
  680. psd->color_convert = GlobalAllocPtr(GHND, 256*2);
  681. n = (lpbi->biClrUsed == 0) ? 256 : (int)lpbi->biClrUsed;
  682. prgb = (LPRGBQUAD)((LPBYTE)lpbi + (int)lpbi->biSize);
  683. pw = psd->color_convert;
  684. for (i=0; i<n; i++)
  685. pw[i] = RGB565(prgb[i].rgbRed, prgb[i].rgbGreen, prgb[i].rgbBlue);
  686. for (; i<256; i++)
  687. pw[i] = 0;
  688. return TRUE;
  689. }
  690. static BOOL init_16_565(PSETDI psd)
  691. {
  692. return TRUE;
  693. }
  694. static BOOL init_24_565(PSETDI psd)
  695. {
  696. return TRUE;
  697. }
  698. static BOOL init_32_565(PSETDI psd)
  699. {
  700. return TRUE;
  701. }
  702. /**************************************************************************
  703. *
  704. * init stuff for RGB 24bpp bitmaps
  705. *
  706. **************************************************************************/
  707. static BOOL init_8_RGB(PSETDI psd)
  708. {
  709. DWORD FAR *pd;
  710. int i;
  711. int n;
  712. LPRGBQUAD prgb;
  713. LPBITMAPINFOHEADER lpbi;
  714. lpbi = (LPBITMAPINFOHEADER)psd->bmSrc.bmBitmapInfo;
  715. if (psd->color_convert == NULL) //!!!
  716. psd->color_convert = GlobalAllocPtr(GHND, 256*4);
  717. n = (lpbi->biClrUsed == 0) ? 256 : (int)lpbi->biClrUsed;
  718. prgb = (LPRGBQUAD)((LPBYTE)lpbi + (int)lpbi->biSize);
  719. pd = psd->color_convert;
  720. for (i=0; i<n; i++)
  721. pd[i] = RGB(prgb[i].rgbRed, prgb[i].rgbGreen, prgb[i].rgbBlue);
  722. for (; i<256; i++)
  723. pd[i] = 0;
  724. return TRUE;
  725. }
  726. static BOOL init_16_RGB(PSETDI psd)
  727. {
  728. return FALSE;
  729. }
  730. static BOOL init_24_RGB(PSETDI psd)
  731. {
  732. return FALSE;
  733. }
  734. static BOOL init_32_RGB(PSETDI psd)
  735. {
  736. return FALSE;
  737. }
  738. /**************************************************************************
  739. *
  740. * init stuff for RGB 32bpp bitmaps
  741. *
  742. **************************************************************************/
  743. static BOOL init_8_RGBX(PSETDI psd)
  744. {
  745. return init_8_RGB(psd);
  746. }
  747. static BOOL init_16_RGBX(PSETDI psd)
  748. {
  749. return FALSE;
  750. }
  751. static BOOL init_24_RGBX(PSETDI psd)
  752. {
  753. return FALSE;
  754. }
  755. static BOOL init_32_RGBX(PSETDI psd)
  756. {
  757. return FALSE;
  758. }
  759. /**************************************************************************
  760. *
  761. * init_dither_8_8
  762. *
  763. * initialize a dither table that maps a 8 bit color to the device's dither
  764. *
  765. * pel = dither_table[y&7][pel][x&7]
  766. *
  767. **************************************************************************/
  768. static LPVOID init_dither_8_8(HDC hdc, LPBITMAPINFOHEADER lpbi)
  769. {
  770. HBRUSH hbr;
  771. HDC hdcMem;
  772. // HDC hdc;
  773. HBITMAP hbm;
  774. HBITMAP hbmT;
  775. int i;
  776. int nColors;
  777. LPRGBQUAD prgb;
  778. LPVOID lpDitherTable;
  779. struct {
  780. BITMAPINFOHEADER bi;
  781. RGBQUAD rgb[256];
  782. } dib;
  783. lpDitherTable = GlobalAllocPtr(GHND, 256*8*8);
  784. if (lpDitherTable == NULL)
  785. return (LPVOID)-1;
  786. hdc = GetDC(NULL);
  787. hdcMem = CreateCompatibleDC(hdc);
  788. hbm = CreateCompatibleBitmap(hdc, 256*8, 8);
  789. hbmT = SelectObject(hdcMem, hbm);
  790. if ((nColors = (int)lpbi->biClrUsed) == 0)
  791. nColors = 1 << (int)lpbi->biBitCount;
  792. prgb = (LPRGBQUAD)(lpbi+1);
  793. for (i=0; i<nColors; i++)
  794. {
  795. hbr = CreateSolidBrush(RGB(prgb[i].rgbRed,prgb[i].rgbGreen,prgb[i].rgbBlue));
  796. hbr = SelectObject(hdcMem, hbr);
  797. PatBlt(hdcMem, i*8, 0, 8, 8, PATCOPY);
  798. hbr = SelectObject(hdcMem, hbr);
  799. DeleteObject(hbr);
  800. }
  801. #ifdef XDEBUG
  802. for (i=0; i<16; i++)
  803. BitBlt(hdc,0,i*8,16*8,8,hdcMem,i*(16*8),0,SRCCOPY);
  804. #endif
  805. dib.bi.biSize = sizeof(BITMAPINFOHEADER);
  806. dib.bi.biPlanes = 1;
  807. dib.bi.biBitCount = 8;
  808. dib.bi.biWidth = 256*8;
  809. dib.bi.biHeight = 8;
  810. dib.bi.biCompression = BI_RGB;
  811. dib.bi.biSizeImage = 256*8*8;
  812. dib.bi.biXPelsPerMeter = 0;
  813. dib.bi.biYPelsPerMeter = 0;
  814. dib.bi.biClrUsed = 0;
  815. dib.bi.biClrImportant = 0;
  816. GetDIBits(hdc, hbm, 0, 8, lpDitherTable, (LPBITMAPINFO)&dib, DIB_RGB_COLORS);
  817. SelectObject(hdcMem, hbmT);
  818. DeleteDC(hdcMem);
  819. DeleteObject(hbm);
  820. ReleaseDC(NULL, hdc);
  821. return (LPVOID)lpDitherTable;
  822. }
  823. #ifdef _WIN32 // Provide some dummy entry points as a temporary measure for NT
  824. void FAR PASCAL convert_16_16
  825. (LPVOID pd, // --> dst.
  826. LONG dd, // offset to start at
  827. LONG nd, // dst_next_scan.
  828. LONG fd, // dst fill bytes
  829. LPVOID ps, // --> source.
  830. LONG ds, // offset to start at
  831. LONG ns, // src_next_scan.
  832. LONG dx, // pixel count.
  833. LONG dy, // scan count.
  834. LPVOID pc) // pixel convert table.
  835. {
  836. return;
  837. }
  838. void FAR PASCAL convert_16_24
  839. (LPVOID pd, // --> dst.
  840. LONG dd, // offset to start at
  841. LONG nd, // dst_next_scan.
  842. LONG fd, // dst fill bytes
  843. LPVOID ps, // --> source.
  844. LONG ds, // offset to start at
  845. LONG ns, // src_next_scan.
  846. LONG dx, // pixel count.
  847. LONG dy, // scan count.
  848. LPVOID pc) // pixel convert table.
  849. {
  850. return;
  851. }
  852. void FAR PASCAL convert_16_565
  853. (LPVOID pd, // --> dst.
  854. LONG dd, // offset to start at
  855. LONG nd, // dst_next_scan.
  856. LONG fd, // dst fill bytes
  857. LPVOID ps, // --> source.
  858. LONG ds, // offset to start at
  859. LONG ns, // src_next_scan.
  860. LONG dx, // pixel count.
  861. LONG dy, // scan count.
  862. LPVOID pc) // pixel convert table.
  863. {
  864. return;
  865. }
  866. void FAR PASCAL convert_24_16
  867. (LPVOID pd, // --> dst.
  868. LONG dd, // offset to start at
  869. LONG nd, // dst_next_scan.
  870. LONG fd, // dst fill bytes
  871. LPVOID ps, // --> source.
  872. LONG ds, // offset to start at
  873. LONG ns, // src_next_scan.
  874. LONG dx, // pixel count.
  875. LONG dy, // scan count.
  876. LPVOID pc) // pixel convert table.
  877. {
  878. return;
  879. }
  880. void FAR PASCAL convert_24_24
  881. (LPVOID pd, // --> dst.
  882. LONG dd, // offset to start at
  883. LONG nd, // dst_next_scan.
  884. LONG fd, // dst fill bytes
  885. LPVOID ps, // --> source.
  886. LONG ds, // offset to start at
  887. LONG ns, // src_next_scan.
  888. LONG dx, // pixel count.
  889. LONG dy, // scan count.
  890. LPVOID pc) // pixel convert table.
  891. {
  892. return;
  893. }
  894. void FAR PASCAL convert_24_565
  895. (LPVOID pd, // --> dst.
  896. LONG dd, // offset to start at
  897. LONG nd, // dst_next_scan.
  898. LONG fd, // dst fill bytes
  899. LPVOID ps, // --> source.
  900. LONG ds, // offset to start at
  901. LONG ns, // src_next_scan.
  902. LONG dx, // pixel count.
  903. LONG dy, // scan count.
  904. LPVOID pc) // pixel convert table.
  905. {
  906. return;
  907. }
  908. void FAR PASCAL convert_32_16
  909. (LPVOID pd, // --> dst.
  910. LONG dd, // offset to start at
  911. LONG nd, // dst_next_scan.
  912. LONG fd, // dst fill bytes
  913. LPVOID ps, // --> source.
  914. LONG ds, // offset to start at
  915. LONG ns, // src_next_scan.
  916. LONG dx, // pixel count.
  917. LONG dy, // scan count.
  918. LPVOID pc) // pixel convert table.
  919. {
  920. return;
  921. }
  922. void FAR PASCAL convert_32_24
  923. (LPVOID pd, // --> dst.
  924. LONG dd, // offset to start at
  925. LONG nd, // dst_next_scan.
  926. LONG fd, // dst fill bytes
  927. LPVOID ps, // --> source.
  928. LONG ds, // offset to start at
  929. LONG ns, // src_next_scan.
  930. LONG dx, // pixel count.
  931. LONG dy, // scan count.
  932. LPVOID pc) // pixel convert table.
  933. {
  934. return;
  935. }
  936. void FAR PASCAL convert_32_565
  937. (LPVOID pd, // --> dst.
  938. LONG dd, // offset to start at
  939. LONG nd, // dst_next_scan.
  940. LONG fd, // dst fill bytes
  941. LPVOID ps, // --> source.
  942. LONG ds, // offset to start at
  943. LONG ns, // src_next_scan.
  944. LONG dx, // pixel count.
  945. LONG dy, // scan count.
  946. LPVOID pc) // pixel convert table.
  947. {
  948. return;
  949. }
  950. void FAR PASCAL convert_8_16
  951. (LPVOID pd, // --> dst.
  952. LONG dd, // offset to start at
  953. LONG nd, // dst_next_scan.
  954. LONG fd, // dst fill bytes
  955. LPVOID ps, // --> source.
  956. LONG ds, // offset to start at
  957. LONG ns, // src_next_scan.
  958. LONG dx, // pixel count.
  959. LONG dy, // scan count.
  960. LPVOID pc) // pixel convert table.
  961. {
  962. return;
  963. }
  964. void FAR PASCAL convert_8_24
  965. (LPVOID pd, // --> dst.
  966. LONG dd, // offset to start at
  967. LONG nd, // dst_next_scan.
  968. LONG fd, // dst fill bytes
  969. LPVOID ps, // --> source.
  970. LONG ds, // offset to start at
  971. LONG ns, // src_next_scan.
  972. LONG dx, // pixel count.
  973. LONG dy, // scan count.
  974. LPVOID pc) // pixel convert table.
  975. {
  976. return;
  977. }
  978. void FAR PASCAL convert_8_565
  979. (LPVOID pd, // --> dst.
  980. LONG dd, // offset to start at
  981. LONG nd, // dst_next_scan.
  982. LONG fd, // dst fill bytes
  983. LPVOID ps, // --> source.
  984. LONG ds, // offset to start at
  985. LONG ns, // src_next_scan.
  986. LONG dx, // pixel count.
  987. LONG dy, // scan count.
  988. LPVOID pc) // pixel convert table.
  989. {
  990. return;
  991. }
  992. void FAR PASCAL convert_8_8
  993. (LPVOID pd, // --> dst.
  994. LONG dd, // offset to start at
  995. LONG nd, // dst_next_scan.
  996. LONG fd, // dst fill bytes
  997. LPVOID ps, // --> source.
  998. LONG ds, // offset to start at
  999. LONG ns, // src_next_scan.
  1000. LONG dx, // pixel count.
  1001. LONG dy, // scan count.
  1002. LPVOID pc) // pixel convert table.
  1003. {
  1004. return;
  1005. }
  1006. void FAR PASCAL copy_8_8
  1007. (LPVOID pd, // --> dst.
  1008. LONG dd, // offset to start at
  1009. LONG nd, // dst_next_scan.
  1010. LONG fd, // dst fill bytes
  1011. LPVOID ps, // --> source.
  1012. LONG ds, // offset to start at
  1013. LONG ns, // src_next_scan.
  1014. LONG dx, // pixel count.
  1015. LONG dy, // scan count.
  1016. LPVOID pc) // pixel convert table.
  1017. {
  1018. return;
  1019. }
  1020. void FAR PASCAL dither_8_8
  1021. (LPVOID pd, // --> dst.
  1022. LONG dd, // offset to start at
  1023. LONG nd, // dst_next_scan.
  1024. LONG fd, // dst fill bytes
  1025. LPVOID ps, // --> source.
  1026. LONG ds, // offset to start at
  1027. LONG ns, // src_next_scan.
  1028. LONG dx, // pixel count.
  1029. LONG dy, // scan count.
  1030. LPVOID pc) // pixel convert table.
  1031. {
  1032. return;
  1033. }
  1034. #endif