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.

1543 lines
49 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. Palette.c
  5. Abstract:
  6. Implementation of the Palette Management.
  7. Environment:
  8. Windows NT Unidrv driver
  9. Revision History:
  10. 04/03/97 -ganeshp-
  11. Created
  12. --*/
  13. #include "unidrv.h"
  14. #pragma hdrstop("unidrv.h")
  15. //Comment out this line to disable FTRACE and FVALUE.
  16. //#define FILETRACE
  17. #include "unidebug.h"
  18. /* Local Function prototypes */
  19. LONG
  20. LSetupPalette (
  21. PDEV *pPDev,
  22. PAL_DATA *pPD,
  23. DEVINFO *pdevinfo,
  24. GDIINFO *pGDIInfo
  25. );
  26. BOOL
  27. BInitPalDevInfo(
  28. PDEV *pPDev,
  29. DEVINFO *pdevinfo,
  30. GDIINFO *pGDIInfo
  31. )
  32. /*++
  33. Routine Description:
  34. This function is called to setup the device caps, gdiinfo for
  35. the palette information for this printer.
  36. Arguments:
  37. pPDev Pointer to PDEV structure
  38. pDevInfo Pointer to DEVINFO structure
  39. pGDIInfo Pointer to GDIINFO structure
  40. Return Value:
  41. TRUE for success and FALSE for failure
  42. --*/
  43. {
  44. PAL_DATA *pPD;
  45. PCOLORMODEEX pColorModeEx = pPDev->pColorModeEx;
  46. LONG lRet = 0; //Default is failure.
  47. PCOMMAND pCmd;
  48. DWORD dwCommandIndex;
  49. //
  50. // allocate palette structure and zero initialized, so that all the palette entires
  51. // default to Black.
  52. //
  53. if( !(pPD = (PAL_DATA *)MemAllocZ( sizeof( PAL_DATA ) )) )
  54. {
  55. ERR(("Unidrv!BInitPalDevInfo: Memory allocation for PALDATA Failed.\n"));
  56. goto ErrorExit;
  57. }
  58. pPDev->pPalData = pPD;
  59. if ( !pColorModeEx ) //If no colormode, assume Monochrome.
  60. {
  61. //
  62. // Hardcode PCL-XL palette
  63. //
  64. // We need to disable Color Management tab in Printer Properties.
  65. // With out ColorMode in GPD, we need to set palette size here for XL.
  66. //
  67. if ( pPDev->ePersonality == kPCLXL )
  68. {
  69. pPD->fFlags |= PDF_PALETTE_FOR_24BPP | PDF_PALETTE_FOR_OEM_24BPP;
  70. pPD->wPalDev = 0;
  71. pdevinfo->cxDither = pdevinfo->cyDither = 0;
  72. pdevinfo->iDitherFormat = BMF_24BPP;
  73. }
  74. else
  75. {
  76. /*
  77. * Monochrome printer, so there are only 2 colours, black
  78. * and white. It would be nice if the bitmap was set with
  79. * black as 1 and white as 0. HOWEVER, there are presumptions
  80. * all over the place that 0 is black. SO, we set them to
  81. * the preferred way, then invert before rendering.
  82. */
  83. pPD->fFlags |= PDF_PALETTE_FOR_1BPP;
  84. lRet = LSetupPalette(pPDev, pPD, pdevinfo, pGDIInfo);
  85. if( lRet < 1 )
  86. {
  87. ERR(("Unidrv!BInitPalDevInfo:LSetupPalette for monochrome failed, returns %ld\n", lRet ));
  88. goto ErrorExit;
  89. }
  90. }
  91. }
  92. else //Explicit ColorMode structure
  93. {
  94. if ((pColorModeEx->dwDrvBPP != pColorModeEx->dwPrinterBPP) &&
  95. (pColorModeEx->dwDrvBPP != 4 || pColorModeEx->dwPrinterBPP != 1 ||
  96. (pColorModeEx->dwPrinterNumOfPlanes != 3 &&
  97. pColorModeEx->dwPrinterNumOfPlanes != 4)))
  98. {
  99. //
  100. // OEM wants to do the dump themselves so just create
  101. // a palette based on the DrvBPP
  102. //
  103. pPD->wPalDev = 1;
  104. switch(pColorModeEx->dwDrvBPP)
  105. {
  106. case 1:
  107. pPD->fFlags |= PDF_PALETTE_FOR_1BPP;
  108. break;
  109. case 4:
  110. pPD->fFlags |= PDF_PALETTE_FOR_4BPP;
  111. break;
  112. case 8:
  113. pPD->fFlags |= PDF_PALETTE_FOR_8BPP;
  114. break;
  115. case 24:
  116. if (pColorModeEx->bPaletteProgrammable)
  117. pPD->wPalDev = min((WORD)pColorModeEx->dwPaletteSize,PALETTE_MAX-PALETTE_SIZE_24BIT);
  118. pPD->fFlags |= PDF_PALETTE_FOR_24BPP | PDF_PALETTE_FOR_OEM_24BPP;
  119. break;
  120. default:
  121. //
  122. // BUG_BUG, do we need to handle the 16 and 32 bpp as well?
  123. // Alvin says no one has made such a request.
  124. //
  125. ERR(("Unidrv!BInitPalDevInfo:OEM dump, Format %d BPP not supporteds \n", pColorModeEx->dwDrvBPP));
  126. goto ErrorExit;
  127. }
  128. //
  129. // already opened and assigned to Ganeshp
  130. // BUG_BUG, Hack for Minidrivers with dump functionality.
  131. // This is a hack to fix the palette code for minidrivers, which
  132. // implement ImageProcessing. In this case we need a separate
  133. // Palette cache for device.In currunt implementation we have only
  134. // one palette cache which is also used for GDI palette. We need to
  135. // separate GDI palette and device palette. Because in case the
  136. // the OEM does the dump, we don't download the GDI palette to
  137. // the printer. But the cacheing code searches the common palette.
  138. // Because of this we don't select the colors correctly. For example
  139. // a input red color gets selects as index 1, even thoug index 1 is
  140. // not programmed to be read.
  141. // A complete solution at this point is risky, so we will use the
  142. // existing code for palettes smaller than GDI palette. For this we
  143. // create a device palette with just 1 entry, which will get
  144. // reprogrammed,if the input color is different. This is little
  145. // inefficeint but require much smaller change.
  146. //
  147. //
  148. }
  149. else
  150. {
  151. // Initialize to default palette size.
  152. if (pColorModeEx->bPaletteProgrammable)
  153. pPD->wPalDev = (WORD)pColorModeEx->dwPaletteSize;
  154. else
  155. pPD->wPalDev = PALETTE_SIZE_DEFAULT;
  156. // If rastermode is indexed we have to use GDI. Else a custom
  157. // (preferably VGA) palette will be downloaded. If the PaletteProgrammable
  158. // flag is set, the palette has to be downloaded. We already know which
  159. // palette has to be downloaded.
  160. if ( (pColorModeEx->dwRasterMode == RASTMODE_INDEXED) &&
  161. (pColorModeEx->bPaletteProgrammable) )
  162. {
  163. if (COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY) )
  164. {
  165. pPD->fFlags |= PDF_DOWNLOAD_GDI_PALETTE;
  166. }
  167. else
  168. {
  169. ERR(("Unidrv!BInitPalDevInfo:NO command to download Programmable Palette\n"));
  170. goto ErrorExit;
  171. }
  172. }
  173. if (pColorModeEx->dwPrinterNumOfPlanes == 1)
  174. {
  175. //
  176. // If the Source Bitmap format is also 8 Bit, Then we have
  177. // to download the palette.So the PaletteSize has to atleast
  178. // PALETTE_SIZE_8BIT.
  179. //
  180. if ( (pColorModeEx->dwPrinterBPP == 8) &&
  181. (pColorModeEx->dwDrvBPP == 8) )
  182. {
  183. if (pColorModeEx->dwPaletteSize < PALETTE_SIZE_8BIT)
  184. {
  185. ERR(("Unidrv!BInitPalDevInfo: Size of Palette should be atleast PALETTE_SIZE_8BIT\n"));
  186. goto ErrorExit;
  187. }
  188. else
  189. pPD->fFlags |= PDF_PALETTE_FOR_8BPP;
  190. }
  191. else if ((pColorModeEx->dwPrinterBPP == 24) &&
  192. (pColorModeEx->dwDrvBPP == 24))
  193. {
  194. if (pColorModeEx->dwPaletteSize < PALETTE_SIZE_24BIT &&
  195. pColorModeEx->dwPaletteSize != 1)
  196. {
  197. ERR(("Unidrv!BInitPalDevInfo: Size of Palette should be atleast PALETTE_SIZE_24BIT\n"));
  198. goto ErrorExit;
  199. }
  200. else
  201. {
  202. pPD->fFlags |= PDF_PALETTE_FOR_24BPP;
  203. }
  204. //
  205. // Special case. The vector pseudo-plugins (i.e. unidrv's HPGL2 and PCLXL)
  206. // want to get full color information
  207. // even though their colormode structure may specify a bpp less than 24.
  208. // For this special case, we set palette for 24bpp irrespective of what
  209. // the ColorModeEx says.
  210. //
  211. if ( pPDev->ePersonality == kPCLXL ||
  212. pPDev->ePersonality == kHPGL2 )
  213. {
  214. pPD->fFlags |= PDF_PALETTE_FOR_24BPP | PDF_PALETTE_FOR_OEM_24BPP;
  215. pdevinfo->cxDither = pdevinfo->cyDither = 0;
  216. pdevinfo->iDitherFormat = BMF_24BPP;
  217. }
  218. }
  219. else if ((pColorModeEx->dwPrinterBPP == 1) &&
  220. (pColorModeEx->dwDrvBPP == 1))
  221. {
  222. if (pColorModeEx->dwPaletteSize < PALETTE_SIZE_1BIT)
  223. {
  224. ERR(("Unidrv!BInitPalDevInfo: Size of Palette should be atleast PALETTE_SIZE_1BIT\n"));
  225. goto ErrorExit;
  226. }
  227. else
  228. pPD->fFlags |= PDF_PALETTE_FOR_1BPP;
  229. }
  230. }
  231. else
  232. {
  233. if ( ((pColorModeEx->dwPrinterNumOfPlanes == 3) ||
  234. (pColorModeEx->dwPrinterNumOfPlanes == 4)) &&
  235. (pColorModeEx->dwDrvBPP > 1) )
  236. pPD->fFlags |= PDF_PALETTE_FOR_4BPP;
  237. // Planer mode. Which may be indexed by Plane.In that case we need
  238. // to setup the Palette. So the PaletteSize must be atleast PALETTE_SIZE_4BIT.
  239. if (pPD->fFlags & PDF_DOWNLOAD_GDI_PALETTE)
  240. {
  241. if (pColorModeEx->dwPaletteSize < PALETTE_SIZE_3BIT)
  242. {
  243. ERR(("Unidrv!BInitPalDevInfo: Size of Palette should be atleast PALETTE_SIZE_4BIT\n"));
  244. goto ErrorExit;
  245. }
  246. else
  247. {
  248. // In planer mode we only provide programmable palette
  249. // support for 3planes.
  250. if (pColorModeEx->dwPrinterNumOfPlanes < 4 )
  251. {
  252. if( !(pPD->pulDevPalCol =
  253. (ULONG *)MemAllocZ( pPD->wPalDev * sizeof( ULONG ))) )
  254. {
  255. ERR(("Unidrv!BInitPalDevInfo: Memory allocation for Device Palette Failed.\n"));
  256. goto ErrorExit;
  257. }
  258. }
  259. else
  260. {
  261. ERR(("Unidrv!BInitPalDevInfo:Can't download Palette for more that 3 Planes.\n"));
  262. goto ErrorExit;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. lRet = LSetupPalette(pPDev, pPD, pdevinfo, pGDIInfo);
  269. if( lRet < 1 )
  270. {
  271. ERR(("Unidrv!BInitPalDevInfo:LSetupPalette failed, returns %ld\n", lRet ));
  272. goto ErrorExit;
  273. }
  274. // If Palette is not programmable set it to the same as wPalGdi.
  275. if (pColorModeEx->bPaletteProgrammable)
  276. {
  277. if ( COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY))
  278. pPDev->fMode |= PF_ANYCOLOR_BRUSH;
  279. //
  280. // The Palette is divided in to two parts. One non programmable and other
  281. // programmable. The wPalGdi part of the palette is non programmable. The
  282. // palette indexes between wPalGdi and wPalDev is programable. If both are
  283. // same then we have to use the WHITE entry of the palette to program the
  284. // color.
  285. //
  286. if (pPD->wPalDev <= pPD->wPalGdi && !(pPD->fFlags & PDF_PALETTE_FOR_OEM_24BPP))
  287. {
  288. //Use the WHITE One to programme a color.
  289. pPD->wIndexToUse = INVALID_INDEX;
  290. pPD->fFlags |= PDF_USE_WHITE_ENTRY;
  291. FTRACE(White palatte entry will be used for programming color);
  292. }
  293. else
  294. pPD->wIndexToUse = (WORD)pPD->wPalGdi;
  295. }
  296. else
  297. pPD->wPalDev = pPD->wPalGdi;
  298. //Find out when to download the Palette.dwCount for Invocation has Comand Index.
  299. pPD->fFlags |= PDF_DL_PAL_EACH_PAGE; //Default for palette Download is each Page.
  300. if (pCmd = COMMANDPTR(pPDev->pDriverInfo, CMD_BEGINPALETTEDEF)) //If the Command exist check the order dependency.
  301. {
  302. if (pCmd->ordOrder.eSection == SS_PAGESETUP)
  303. goto PALETTE_SEQUENCE_DETERMINED ; // default is ok.
  304. else if ((pCmd->ordOrder.eSection == SS_DOCSETUP) ||
  305. (pCmd->ordOrder.eSection == SS_JOBSETUP))
  306. {
  307. pPD->fFlags |= PDF_DL_PAL_EACH_DOC; //For SS_JOBSETUP or SS_DOCSETUP
  308. pPD->fFlags &= ~PDF_DL_PAL_EACH_PAGE;
  309. goto PALETTE_SEQUENCE_DETERMINED ;
  310. }
  311. // otherwise let ColorMode command determine when to init Palette.
  312. }
  313. // dwCount have index to the ColorMode Command. Get the command pointer.
  314. dwCommandIndex = pPDev->pColorMode->GenericOption.dwCmdIndex;
  315. pCmd = INDEXTOCOMMANDPTR(pPDev->pDriverInfo, dwCommandIndex) ;
  316. if (pCmd) //If the Command exist check the order dependency.
  317. {
  318. if ( (pCmd->ordOrder.eSection == SS_PAGEFINISH) ||
  319. (pCmd->ordOrder.eSection == SS_DOCFINISH) ||
  320. (pCmd->ordOrder.eSection == SS_JOBFINISH) )
  321. {
  322. ERR(("Unidrv!BInitPalDevInfo:Wrong Section for ColorMode Command, Verify GPD\n"));
  323. goto ErrorExit;
  324. }
  325. else if (pCmd->ordOrder.eSection != SS_PAGESETUP)
  326. {
  327. pPD->fFlags |= PDF_DL_PAL_EACH_DOC; //For SS_JOBSETUP or SS_DOCSETUP
  328. pPD->fFlags &= ~PDF_DL_PAL_EACH_PAGE;
  329. }
  330. }
  331. else
  332. {
  333. //
  334. // No Command for colormode so assume to download palette on each
  335. // page. The exception is monochrome 1 bit mode, as most printers
  336. // default to this mode, so no command is needed.
  337. //
  338. if ( pPDev->pColorModeEx->bColor || pColorModeEx->dwDrvBPP != 1)
  339. WARNING(("Unidrv!BInitPalDevInfo:No Command to select the ColorMode\n" ));
  340. }
  341. PALETTE_SEQUENCE_DETERMINED:
  342. // In Planer index mode, that device palette may not be same as GDI Palette.
  343. // So ask the raster module to fill the device paletter based upon the Plane
  344. // order.
  345. if (pPD->pulDevPalCol && !RMInitDevicePal(pPDev,pPD))
  346. {
  347. ERR(("Unidrv!BInitPalDevInfo:RMInitDevicePal Failed to init device palette\n"));
  348. goto ErrorExit;
  349. }
  350. }
  351. //Now Set various common fields in devinfo and gdiinfo.
  352. if (pPD->fFlags & PDF_PALETTE_FOR_24BPP)
  353. pdevinfo->hpalDefault = EngCreatePalette( PAL_RGB,
  354. 0, 0, 0, 0, 0 );
  355. else
  356. pdevinfo->hpalDefault = EngCreatePalette( PAL_INDEXED,
  357. pPD->wPalGdi, pPD->ulPalCol,
  358. 0, 0, 0 );
  359. //
  360. // Save the Palette Handle. We will need this to delete the palette.
  361. //
  362. pPD->hPalette = pdevinfo->hpalDefault;
  363. if (pdevinfo->hpalDefault == (HPALETTE) NULL)
  364. {
  365. ERR(("Unidrv!BInitPalDevInfo: NULL palette.\n"));
  366. goto ErrorExit;
  367. }
  368. pGDIInfo->ulNumPalReg = pPD->wPalGdi;
  369. //
  370. // For Monochrome mode, enable dither text only on 600 higher resolution
  371. // printer and in non N-UP mode.
  372. // For Color mode, enable dither text only on 300 higher resolution printer
  373. // and in non N-UP mode.
  374. // The threshold values, 600 dpi for mono and 300 dpi for color,
  375. // were determined not theoritically, but through try-and-erro procedure.
  376. // We don't know for sure that these values are perfectly value in all
  377. // situations.
  378. //
  379. // Now new GPD keyword "TextHalftoneThreshold is available.
  380. // If GPD file sets a value for the new keyword and the current resolution
  381. // is the same as dwTextHalftoneThreshold or greater, set GCAPS_ARBRUSHTEXT
  382. //
  383. if (pPDev->pGlobals->dwTextHalftoneThreshold)
  384. {
  385. if (pPDev->ptGrxRes.x >= (LONG)pPDev->pGlobals->dwTextHalftoneThreshold
  386. #ifndef WINNT_40
  387. && ( pPDev->pdmPrivate->iLayout == ONE_UP ))
  388. #endif
  389. {
  390. pdevinfo->flGraphicsCaps |= GCAPS_ARBRUSHTEXT ;
  391. }
  392. }
  393. else
  394. {
  395. if (pPD->fFlags & PDF_PALETTE_FOR_1BPP)
  396. {
  397. //
  398. // Monochrome
  399. //
  400. if (( pPDev->ptGrxRes.x >= 600 &&
  401. pPDev->ptGrxRes.y >= 600 )
  402. #ifndef WINNT_40
  403. && ( pPDev->pdmPrivate->iLayout == ONE_UP )
  404. #endif
  405. )
  406. pdevinfo->flGraphicsCaps |= GCAPS_ARBRUSHTEXT ;
  407. }
  408. else
  409. {
  410. //
  411. // Color
  412. //
  413. if (( pPDev->ptGrxRes.x >= 300 &&
  414. pPDev->ptGrxRes.y >= 300 )
  415. #ifndef WINNT_40
  416. && ( pPDev->pdmPrivate->iLayout == ONE_UP )
  417. #endif
  418. )
  419. pdevinfo->flGraphicsCaps |= GCAPS_ARBRUSHTEXT ;
  420. }
  421. }
  422. return TRUE;
  423. ErrorExit:
  424. if (pPD)
  425. {
  426. if (pPD->pulDevPalCol)
  427. MemFree(pPD->pulDevPalCol);
  428. MemFree(pPD);
  429. pPDev->pPalData = NULL;
  430. }
  431. return FALSE;
  432. }
  433. LONG
  434. LSetupPalette (
  435. PDEV *pPDev,
  436. PAL_DATA *pPD,
  437. DEVINFO *pdevinfo,
  438. GDIINFO *pGDIInfo
  439. )
  440. /*++
  441. Routine Description:
  442. LSetupPalette
  443. Function to read in the 256 color palette from GDI into the
  444. palette data structure in Dev Info.
  445. Arguments:
  446. pPD : Pointer to PALDATA.
  447. pdevinfo : DEVINFO pointer.
  448. pGDIInfo : GDIINFO Pointer.
  449. Return Value:
  450. The number of colors in the palette. Returns 0 if the call fails.
  451. Note:
  452. 4/7/1997 -ganeshp-
  453. Created it.
  454. --*/
  455. {
  456. long lRet = 0;
  457. int _iI;
  458. if (pPD->fFlags & PDF_PALETTE_FOR_1BPP)
  459. {
  460. /*
  461. * Monochrome printer, so there are only 2 colours, black
  462. * and white. It would be nice if the bitmap was set with
  463. * black as 1 and white as 0. HOWEVER, there are presumptions
  464. * all over the place that 0 is black. SO, we set them to
  465. * the preferred way, then invert before rendering.
  466. */
  467. lRet = pPD->wPalGdi = 2;
  468. pPD->ulPalCol[ 0 ] = RGB(0x00, 0x00, 0x00);
  469. pPD->ulPalCol[ 1 ] = RGB(0xff, 0xff, 0xff);
  470. pPD->iWhiteIndex = 1;
  471. pPD->iBlackIndex = 0;
  472. pdevinfo->iDitherFormat = BMF_1BPP; /* Monochrome format */
  473. pdevinfo->flGraphicsCaps |= GCAPS_FORCEDITHER;
  474. pGDIInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  475. pGDIInfo->ulHTOutputFormat = HT_FORMAT_1BPP;
  476. if ( COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY))
  477. {
  478. pPDev->fMode |= PF_ANYCOLOR_BRUSH;
  479. }
  480. //Set the monochrome brush attributes.
  481. //CODE_COMPLETE VSetMonochromeBrushAttributes(pPDev);
  482. }
  483. else if (pPD->fFlags & PDF_PALETTE_FOR_4BPP)
  484. {
  485. /*
  486. * We appear to GDI as an RGB surface, regardless of what
  487. * the printer is. CMY(K) printers have their pallete
  488. * reversed at rendering time. This is required for Win 3.1
  489. * compatability and many things assume an RGB palette, and
  490. * break if this is not the case.
  491. *
  492. * DC_PRIMARY_RGB
  493. * ------------------------------------------
  494. * Index 0 = Black
  495. * Index 1 = Red
  496. * Index 2 = Green
  497. * Index 3 = Yellow
  498. * Index 4 = Blue
  499. * Index 5 = Magenta
  500. * Index 6 = Cyan
  501. * Index 7 = White
  502. *--------------------------------------------
  503. * Bit 0 = Red
  504. * Bit 1 = Green
  505. * Bit 2 = Blue
  506. *
  507. * If a separate black dye is available, this can be arranged
  508. * to fall out at transpose time - we have a slightly different
  509. * transpose table to do the work.
  510. */
  511. /*
  512. * Many apps and the engine presume an RGB colour model, so
  513. * we pretend to be one! We invert the bits at render time.
  514. */
  515. pPD->iWhiteIndex = 7;
  516. pPD->iBlackIndex = 0;
  517. /*
  518. * Set the palette colours. Remember we are only RGB format.
  519. * NOTE that gdisrv requires us to fill in all 16 entries,
  520. * even though we have only 8. So the second 8 are a duplicate
  521. * of the first 8.
  522. */
  523. pPD->ulPalCol[ 0 ] = RGB( 0x00, 0x00, 0x00 );
  524. pPD->ulPalCol[ 1 ] = RGB( 0xff, 0x00, 0x00 );
  525. pPD->ulPalCol[ 2 ] = RGB( 0x00, 0xff, 0x00 );
  526. pPD->ulPalCol[ 3 ] = RGB( 0xff, 0xff, 0x00 );
  527. pPD->ulPalCol[ 4 ] = RGB( 0x00, 0x00, 0xff );
  528. pPD->ulPalCol[ 5 ] = RGB( 0xff, 0x00, 0xff );
  529. pPD->ulPalCol[ 6 ] = RGB( 0x00, 0xff, 0xff );
  530. pPD->ulPalCol[ 7 ] = RGB( 0xff, 0xff, 0xff );
  531. //
  532. // These palette entries will cause really light
  533. // colors to map to the correct color instead of white
  534. pPD->ulPalCol[ 8 ] = RGB( 0xef, 0xef, 0xef );
  535. pPD->ulPalCol[ 9 ] = RGB( 0xff, 0xe7, 0xe7 );
  536. pPD->ulPalCol[10 ] = RGB( 0xe7, 0xff, 0xe7 );
  537. pPD->ulPalCol[11 ] = RGB( 0xf7, 0xf7, 0xdf );
  538. pPD->ulPalCol[12 ] = RGB( 0xe7, 0xe7, 0xff );
  539. pPD->ulPalCol[13 ] = RGB( 0xf7, 0xdf, 0xf7 );
  540. pPD->ulPalCol[14 ] = RGB( 0xdf, 0xf7, 0xf7 );
  541. pPD->ulPalCol[15 ] = RGB( 0xff, 0xff, 0xff );
  542. lRet = pPD->wPalGdi = 16;
  543. pdevinfo->iDitherFormat = BMF_4BPP;
  544. pdevinfo->flGraphicsCaps |= GCAPS_FORCEDITHER;
  545. pGDIInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  546. pGDIInfo->ulHTOutputFormat = HT_FORMAT_4BPP;
  547. }
  548. else if (pPD->fFlags & PDF_PALETTE_FOR_8BPP)
  549. {
  550. // 8 Bit Mode.
  551. PALETTEENTRY pe[ 256 ]; /* 8 bits per pel - all the way */
  552. FillMemory (pe, sizeof (pe), 0xff);
  553. #ifndef WINNT_40
  554. if (pPDev->pColorModeEx->bColor == FALSE)
  555. {
  556. HT_SET_BITMASKPAL2RGB(pe);
  557. lRet = HT_Get8BPPMaskPalette(pe,TRUE,0x0,10000,10000,10000);
  558. }
  559. else
  560. #endif
  561. lRet = HT_Get8BPPFormatPalette(pe,
  562. (USHORT)pGDIInfo->ciDevice.RedGamma,
  563. (USHORT)pGDIInfo->ciDevice.GreenGamma,
  564. (USHORT)pGDIInfo->ciDevice.BlueGamma );
  565. #if PRINT_INFO
  566. DbgPrint("RedGamma = %d, GreenGamma = %d, BlueGamma = %d\n",(USHORT)pGDIInfo->ciDevice.RedGamma, (USHORT)pGDIInfo->ciDevice.GreenGamma, (USHORT)pGDIInfo->ciDevice.BlueGamma);
  567. #endif
  568. if( lRet < 1 )
  569. {
  570. ERR(( "Unidrv!LSetupPalette:HT_Get8BPPFormatPalette returns %ld\n", lRet ));
  571. return(0);
  572. }
  573. /*
  574. * Convert the HT derived palette to the engine's desired format.
  575. */
  576. for( _iI = 0; _iI < lRet; _iI++ )
  577. {
  578. pPD->ulPalCol[ _iI ] = RGB( pe[ _iI ].peRed,
  579. pe[ _iI ].peGreen,
  580. pe[ _iI ].peBlue );
  581. #if PRINT_INFO
  582. DbgPrint("Palette entry %d= (r = %d, g = %d, b = %d)\n",_iI,pe[ _iI ].peRed, pe[ _iI ].peGreen, pe[ _iI ].peBlue);
  583. #endif
  584. }
  585. pPD->wPalGdi = (WORD)lRet;
  586. pdevinfo->iDitherFormat = BMF_8BPP;
  587. pGDIInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  588. pGDIInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
  589. #ifndef WINNT_40
  590. if (pPDev->pColorModeEx->bColor == FALSE)
  591. {
  592. pGDIInfo->flHTFlags |= HT_FLAG_USE_8BPP_BITMASK;
  593. pPD->fFlags |= PDF_PALETTE_FOR_8BPP_MONO;
  594. if (HT_IS_BITMASKPALRGB(pe))
  595. {
  596. #if DBGROP
  597. DbgPrint ("New 8BPP GDI monochrome mode\n");
  598. #endif
  599. pGDIInfo->flHTFlags |= HT_FLAG_INVERT_8BPP_BITMASK_IDX;
  600. pPD->iBlackIndex = 0;
  601. pPD->iWhiteIndex = 255;
  602. }
  603. else
  604. {
  605. #if DBGROP
  606. DbgPrint ("Old 8BPP GDI monochrome mode\n");
  607. #endif
  608. pPDev->fMode2 |= PF2_INVERTED_ROP_MODE;
  609. pPD->ulPalCol[255] = RGB (0x00, 0x00, 0x00);
  610. pPD->iBlackIndex = 255;
  611. pPD->ulPalCol[ 0 ] = RGB (0xff, 0xff, 0xff);
  612. pPD->iWhiteIndex = 0;
  613. }
  614. }
  615. else
  616. #endif
  617. {
  618. // Make the 0 index white as most of the printers do ZERO_FILL.
  619. pPD->ulPalCol[ 7 ] = RGB (0x00, 0x00, 0x00);
  620. pPD->iBlackIndex = 7;
  621. pPD->ulPalCol[ 0 ] = RGB (0xff, 0xff, 0xff);
  622. pPD->iWhiteIndex = 0;
  623. }
  624. }
  625. else if (pPD->fFlags & PDF_PALETTE_FOR_24BPP)
  626. {
  627. // we fill the palette entries with -1, so that we know which
  628. // index is programmed.
  629. pPD->wPalGdi = PALETTE_SIZE_24BIT;
  630. pPD->iWhiteIndex = 0x00ffffff;
  631. pdevinfo->iDitherFormat = BMF_24BPP;
  632. pGDIInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  633. pGDIInfo->ulHTOutputFormat = HT_FORMAT_24BPP;
  634. FillMemory( pPD->ulPalCol, (PALETTE_MAX * sizeof(ULONG)), 0xff );
  635. //
  636. // Fix the first seven colors to primary colors. Render modules
  637. // assume that index 7 is black.
  638. //
  639. pPD->ulPalCol[ 0 ] = RGB (0xff, 0xff, 0xff);
  640. pPD->ulPalCol[ 1 ] = RGB( 0xff, 0x00, 0x00 );
  641. pPD->ulPalCol[ 2 ] = RGB( 0x00, 0xff, 0x00 );
  642. pPD->ulPalCol[ 3 ] = RGB( 0xff, 0xff, 0x00 );
  643. pPD->ulPalCol[ 4 ] = RGB( 0x00, 0x00, 0xff );
  644. pPD->ulPalCol[ 5 ] = RGB( 0xff, 0x00, 0xff );
  645. pPD->ulPalCol[ 6 ] = RGB( 0x00, 0xff, 0xff );
  646. pPD->ulPalCol[ 7 ] = RGB (0x00, 0x00, 0x00);
  647. lRet = 1;
  648. }
  649. else
  650. ERR(( "Unidrv!LSetupPalette:Unknown Palette Format\n"));
  651. return lRet;
  652. }
  653. VOID VInitPal8BPPMaskMode(
  654. PDEV *pPDev,
  655. GDIINFO *pGdiInfo
  656. )
  657. /*++
  658. Routine Description:
  659. Updates the driver palette if an OEM has requested 8bpp color mask mode.
  660. Arguments:
  661. pPDev Pointer to PDEV
  662. pGDIInfo Pointer to GDIINFO
  663. Return Value:
  664. Nothing
  665. Note:
  666. 10/23/2000 -alvins-
  667. Created it.
  668. --*/
  669. {
  670. ULONG i,lRet;
  671. PAL_DATA *pPD = (PAL_DATA *)pPDev->pPalData;
  672. PALETTEENTRY pe[256];
  673. FillMemory (pe, sizeof (pe), 0xff);
  674. //
  675. // only request inverted palette if requested by OEM
  676. //
  677. if (pGdiInfo->flHTFlags & HT_FLAG_INVERT_8BPP_BITMASK_IDX)
  678. {
  679. HT_SET_BITMASKPAL2RGB(pe);
  680. }
  681. //
  682. // Get color mask palette and map to internal format
  683. //
  684. lRet = HT_Get8BPPMaskPalette(pe,TRUE,(BYTE)(pGdiInfo->flHTFlags >> 24),10000,10000,10000);
  685. for( i = 0; i < lRet; i++ )
  686. {
  687. pPD->ulPalCol[i] = RGB( pe[i].peRed,pe[i].peGreen,pe[i].peBlue );
  688. }
  689. //
  690. // test whether inverted palette is active
  691. //
  692. if (HT_IS_BITMASKPALRGB(pe))
  693. {
  694. pPD->iBlackIndex = 0;
  695. pPD->iWhiteIndex = 255;
  696. }
  697. else
  698. {
  699. pPDev->fMode2 |= PF2_INVERTED_ROP_MODE;
  700. pPD->iBlackIndex = 255;
  701. pPD->iWhiteIndex = 0;
  702. }
  703. }
  704. VOID
  705. VLoadPal(
  706. PDEV *pPDev
  707. )
  708. /*++
  709. Routine Description:
  710. Download the palette to the printer if the colormode has programmable
  711. palette. Takes the colors from PALDATA which was setup during DrvEnablePDEV.
  712. Arguments:
  713. pPDev Pointer to PDEV
  714. Return Value:
  715. Nothing
  716. Note:
  717. 4/7/1997 -ganeshp-
  718. Created it.
  719. --*/
  720. {
  721. /*
  722. * Program the palette according to PCL5 spec.
  723. * The syntax is Esc*v#a#b#c#I
  724. * #a is the first color component
  725. * #b is the second color component
  726. * #c is the third color component
  727. * #I assigns the color to the specified palette index number
  728. * For example, Esc*v0a128b255c5I assigns the 5th index
  729. * of the palette to the color 0, 128, 255
  730. *
  731. */
  732. PAL_DATA *pPD;
  733. INT iEntriesToProgram, iI;
  734. ULONG *pPalette;
  735. pPD = pPDev->pPalData;
  736. if (pPD->fFlags & PDF_PALETTE_FOR_24BPP)
  737. {
  738. FillMemory( pPD->ulPalCol, (PALETTE_MAX * sizeof(ULONG)), 0xff );
  739. //
  740. // Fix the first seven colors to primary colors. Render modules
  741. // assume that index 7 is black.
  742. //
  743. pPD->ulPalCol[ 0 ] = RGB (0xff, 0xff, 0xff);
  744. pPD->ulPalCol[ 1 ] = RGB( 0xff, 0x00, 0x00 );
  745. pPD->ulPalCol[ 2 ] = RGB( 0x00, 0xff, 0x00 );
  746. pPD->ulPalCol[ 3 ] = RGB( 0xff, 0xff, 0x00 );
  747. pPD->ulPalCol[ 4 ] = RGB( 0x00, 0x00, 0xff );
  748. pPD->ulPalCol[ 5 ] = RGB( 0xff, 0x00, 0xff );
  749. pPD->ulPalCol[ 6 ] = RGB( 0x00, 0xff, 0xff );
  750. pPD->ulPalCol[ 7 ] = RGB (0x00, 0x00, 0x00);
  751. }
  752. if (pPD->fFlags & PDF_DOWNLOAD_GDI_PALETTE)
  753. {
  754. if (pPD->wPalDev > PALETTE_MAX)
  755. {
  756. WARNING(("Unidrv!vLoadPal: Invalid number of palette entries to program\n"));
  757. pPD->wPalDev = PALETTE_MAX;
  758. }
  759. if (pPD->pulDevPalCol)
  760. pPalette = pPD->pulDevPalCol;
  761. else if (pPD->fFlags & PDF_PALETTE_FOR_OEM_24BPP)
  762. pPalette = &pPD->ulPalCol[PALETTE_SIZE_24BIT];
  763. else
  764. pPalette = pPD->ulPalCol;
  765. if (pPD->fFlags & PDF_PALETTE_FOR_8BPP)
  766. iEntriesToProgram = min(256,pPD->wPalDev);
  767. else
  768. iEntriesToProgram = min(pPD->wPalDev,pPD->wPalGdi);
  769. // Start palette definition.
  770. WriteChannel( pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_BEGINPALETTEDEF));
  771. // if only one entry, program it to black
  772. //
  773. if (iEntriesToProgram == 1)
  774. {
  775. pPDev->dwRedValue = RED_VALUE(RGB_BLACK_COLOR);
  776. pPDev->dwGreenValue = GREEN_VALUE(RGB_BLACK_COLOR);
  777. pPDev->dwBlueValue = BLUE_VALUE(RGB_BLACK_COLOR);
  778. pPDev->dwPaletteIndexToProgram = 0;
  779. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY));
  780. }
  781. else
  782. {
  783. // Download each palette entry.
  784. for( iI = 0; iI < iEntriesToProgram; ++iI )
  785. {
  786. //pPDev->dwRedValue =RED_VALUE ((pPD->ulPalCol [iI] ^ 0x00FFFFFF));
  787. //pPDev->dwGreenValue = GREEN_VALUE ((pPD->ulPalCol [iI] ^ 0x00FFFFFF));
  788. //pPDev->dwBlueValue = BLUE_VALUE ((pPD->ulPalCol [iI] ^ 0x00FFFFFF));
  789. pPDev->dwRedValue =RED_VALUE((pPalette[iI]));
  790. pPDev->dwGreenValue = GREEN_VALUE((pPalette[iI]));
  791. pPDev->dwBlueValue = BLUE_VALUE((pPalette[iI]));
  792. pPDev->dwPaletteIndexToProgram = iI;
  793. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY));
  794. }
  795. }
  796. // Send End Palette definition command.
  797. WriteChannel( pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_ENDPALETTEDEF));
  798. }
  799. return;
  800. }
  801. BOOL
  802. BSelectProgrammableBrushColor(
  803. PDEV *pPDev,
  804. ULONG Color
  805. )
  806. /*++
  807. Routine Description:
  808. Sets the brush color to give color.
  809. Arguments:
  810. pPDev Pointer to PDEV
  811. Color Input Color to select. If it's -1 that means restore the palette
  812. to original state.
  813. Return Value:
  814. TRUE for success and FALSE for failure or if the palette can't be programmed.
  815. Note:
  816. 4/9/1997 -ganeshp-
  817. Created it.
  818. --*/
  819. {
  820. INT iIndex;
  821. INT iPaletteEntryToSelect;
  822. PAL_DATA *pPD;
  823. BOOL bProgramEntry = FALSE;
  824. BOOL bSelectEntry = TRUE;
  825. ULONG *pPalette;
  826. INT iWhiteIndex;
  827. FTRACE(TRACING BSelectProgrammableBrushColor);
  828. FVALUE(Color,0x%x);
  829. if (pPDev->fMode & PF_ANYCOLOR_BRUSH)
  830. {
  831. pPD = pPDev->pPalData;
  832. if (pPD->pulDevPalCol)
  833. pPalette = pPD->pulDevPalCol;
  834. else if (pPD->fFlags & PDF_PALETTE_FOR_OEM_24BPP)
  835. pPalette = &pPD->ulPalCol[PALETTE_SIZE_24BIT];
  836. else
  837. pPalette = pPD->ulPalCol;
  838. //
  839. // iWhiteIndex in 24 bit mode is set to the real color (0x00FFFFFF) and
  840. // not the index. We need to take care of this case. In this mode
  841. // white is programmed in 0 index, so we will use this number instead
  842. // of pPD->iWhiteIndex.
  843. //
  844. if (pPD->fFlags & PDF_PALETTE_FOR_24BPP)
  845. iWhiteIndex = 0;
  846. else
  847. iWhiteIndex = pPD->iWhiteIndex;
  848. FVALUE(iWhiteIndex,%d);
  849. // Check for Black or white color. As we can directly select the colors.
  850. // Also check if the White index has to be reprogrammed.
  851. // This should be done for non 24 bit mode.
  852. if (Color == INVALID_COLOR)
  853. {
  854. // Set the BrushColor to invalid,so that next time we always
  855. // program the input color.
  856. pPDev->ctl.ulBrushColor = Color;
  857. if ( pPDev->fMode & PF_RESTORE_WHITE_ENTRY ) //Special restore case.
  858. {
  859. iPaletteEntryToSelect = (pPD->pulDevPalCol) ?
  860. pPD->wIndexToUse : iWhiteIndex;
  861. bProgramEntry = TRUE;
  862. bSelectEntry = FALSE;
  863. pPDev->fMode &= ~PF_RESTORE_WHITE_ENTRY; //Clear the Flag.
  864. Color = RGB_WHITE_COLOR;
  865. FTRACE(Restoring White Entry);
  866. }
  867. else
  868. return TRUE; //Don't do any thing if color is -1 and flag is not set.
  869. }
  870. if( (Color != INVALID_COLOR) && (ULONG)Color != pPDev->ctl.ulBrushColor )
  871. {
  872. iPaletteEntryToSelect = pPD->wIndexToUse;
  873. // Search the Palette for the color unless palette size is 1
  874. if (pPD->wPalDev == 1)
  875. {
  876. bProgramEntry = TRUE;
  877. pPD->wIndexToUse = iIndex = 0;
  878. }
  879. else
  880. {
  881. for (iIndex = 0; iIndex < pPD->wPalDev; iIndex++ )
  882. {
  883. if (pPalette[iIndex] == Color) //Color is matched.
  884. {
  885. FTRACE(Color is found in palette.);
  886. FVALUE(iIndex,%d);
  887. break;
  888. }
  889. }
  890. }
  891. //Check if there was a match in the palette. If there is no match
  892. //then programme a entry else use the matched one.
  893. if (iIndex == pPD->wPalDev) //No Match
  894. {
  895. FTRACE(Color is not found in palette.Programme the Palette.);
  896. bProgramEntry = TRUE;
  897. if (!(pPD->fFlags & PDF_USE_WHITE_ENTRY))
  898. {
  899. FTRACE(Palette has spare entries to programme);
  900. iPaletteEntryToSelect = (pPD->wIndexToUse < pPD->wPalDev) ?
  901. pPD->wIndexToUse :
  902. (pPD->wIndexToUse = pPD->wPalGdi );
  903. pPD->wIndexToUse++;
  904. }
  905. else // Use White Entry to reprogramme the color
  906. {
  907. FTRACE(Palette does not have spare entries to program.);
  908. FTRACE(Using White entry to program.);
  909. pPDev->fMode |= PF_RESTORE_WHITE_ENTRY;
  910. //If initialized use it else find white.
  911. if (pPD->wIndexToUse != INVALID_INDEX)
  912. iPaletteEntryToSelect = pPD->wIndexToUse;
  913. else if (pPD->pulDevPalCol) //If there is a separate device pal use it.
  914. {
  915. //Remember the White Index.
  916. for (iIndex = 0; iIndex < pPD->wPalDev; iIndex++ )
  917. {
  918. if (pPalette[iIndex] == RGB_WHITE_COLOR)
  919. {
  920. pPD->wIndexToUse =
  921. iPaletteEntryToSelect = iIndex;
  922. break;
  923. }
  924. }
  925. if (iIndex == pPD->wPalDev) //No White Found,use the Last entry.
  926. {
  927. WARNING(("Unidrv!BSelectBrushColor: No White entry in device Palette.\n"));
  928. pPD->wIndexToUse =
  929. iPaletteEntryToSelect = iIndex -1;
  930. }
  931. }
  932. else
  933. pPD->wIndexToUse =
  934. iPaletteEntryToSelect = min((PALETTE_MAX-1),iWhiteIndex);
  935. }
  936. FVALUE(pPD->wIndexToUse,%d);
  937. }
  938. else //Color is Matched.
  939. iPaletteEntryToSelect = iIndex;
  940. FVALUE(iPaletteEntryToSelect,%d);
  941. ASSERTMSG((iPaletteEntryToSelect < PALETTE_MAX),("\n iPaletteEntryToSelect should always be less than PALETTE_MAX.\n"));
  942. }
  943. else
  944. bSelectEntry = FALSE; //The color is already selected.
  945. //If we have to program a palette entry, do it now.
  946. if (bProgramEntry)
  947. {
  948. //
  949. // Make sure that we don't overrun the palette.
  950. //
  951. if (iPaletteEntryToSelect >= PALETTE_MAX)
  952. iPaletteEntryToSelect = PALETTE_MAX-1;
  953. pPDev->dwRedValue = RED_VALUE (Color);
  954. pPDev->dwGreenValue = GREEN_VALUE (Color);
  955. pPDev->dwBlueValue = BLUE_VALUE (Color);
  956. pPDev->dwPaletteIndexToProgram = iPaletteEntryToSelect;
  957. pPalette[iPaletteEntryToSelect] = Color;
  958. if(COMMANDPTR(pPDev->pDriverInfo, CMD_BEGINPALETTEREDEF))
  959. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_BEGINPALETTEREDEF));
  960. if(COMMANDPTR(pPDev->pDriverInfo, CMD_REDEFINEPALETTEENTRY))
  961. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_REDEFINEPALETTEENTRY));
  962. else
  963. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_DEFINEPALETTEENTRY));
  964. if(COMMANDPTR(pPDev->pDriverInfo, CMD_ENDPALETTEREDEF))
  965. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_ENDPALETTEREDEF));
  966. }
  967. //Now Select the color.
  968. if (bSelectEntry)
  969. {
  970. pPDev->dwCurrentPaletteIndex = iPaletteEntryToSelect;
  971. WriteChannel (pPDev, COMMANDPTR(pPDev->pDriverInfo, CMD_SELECTPALETTEENTRY));
  972. //Set the BrushColor to new color.
  973. pPDev->ctl.ulBrushColor = Color;
  974. }
  975. FTRACE(End Tracing BSelectProgrammableBrushColor\n);
  976. return TRUE;
  977. }
  978. return FALSE;
  979. }
  980. VOID
  981. VResetProgrammableBrushColor(
  982. PDEV *pPDev
  983. )
  984. /*++
  985. Routine Description:
  986. Reset the programmable palette and select the default color.
  987. Arguments:
  988. pPDev Pointer to PDEV
  989. Return Value:
  990. None
  991. Note:
  992. 4/28/1997 -ganeshp-
  993. Created it.
  994. --*/
  995. {
  996. PAL_DATA *pPD;
  997. pPD = pPDev->pPalData;
  998. if (pPDev->fMode & PF_ANYCOLOR_BRUSH)
  999. {
  1000. // Special restore case.
  1001. if ( pPDev->fMode & PF_RESTORE_WHITE_ENTRY )
  1002. BSelectProgrammableBrushColor(pPDev, INVALID_COLOR);
  1003. // Select the black. We should actualy select the default palette color.
  1004. // But GPD doesn't have any entries for that.
  1005. if ((INT)pPDev->ctl.ulBrushColor != RGB_BLACK_COLOR)
  1006. BSelectProgrammableBrushColor(pPDev, RGB_BLACK_COLOR);
  1007. }
  1008. }
  1009. DWORD
  1010. ConvertRGBToGrey(
  1011. DWORD Color
  1012. )
  1013. /*++
  1014. Routine Description:
  1015. This function converts an RGB value to grey
  1016. Arguments:
  1017. Color - Color to be checked
  1018. Return Value:
  1019. DWORD - grey scale RGB color
  1020. Revision History:
  1021. --*/
  1022. {
  1023. //
  1024. // convert RGB value to grey scale intensity using sRGB or NTSC values
  1025. #ifndef SRGB
  1026. INT iIntensity = ((RED_VALUE(Color) * 54) +
  1027. (GREEN_VALUE(Color) * 183) +
  1028. (BLUE_VALUE(Color) * 19)) / 256;
  1029. #else
  1030. INT iIntensity = ((RED_VALUE(Color) * 77) +
  1031. (GREEN_VALUE(Color) * 151) +
  1032. (BLUE_VALUE(Color) * 28)) / 256;
  1033. #endif
  1034. return (RGB(iIntensity,iIntensity,iIntensity));
  1035. }
  1036. DWORD
  1037. BestMatchDeviceColor(
  1038. PDEV *pPDev,
  1039. DWORD Color
  1040. )
  1041. /*++
  1042. Routine Description:
  1043. This function find the best pen color index for the RGB color
  1044. Arguments:
  1045. pPDev - Pointer to our PDEV
  1046. Color - Color to be checked
  1047. Return Value:
  1048. LONG - Pen Index, this function assume 0 is always white and 1 up
  1049. to the max. pen is defined
  1050. Author:
  1051. 08-Feb-1994 Tue 00:23:36 created -by- Daniel Chou (danielc)
  1052. 23-Jun-1994 Thu 14:00:00 updated -by- Daniel Chou (danielc)
  1053. Updated for non-white pen match
  1054. Revision History:
  1055. --*/
  1056. {
  1057. UINT Count;
  1058. UINT RetIdx;
  1059. PAL_DATA *pPD;
  1060. pPD = pPDev->pPalData;
  1061. RetIdx = pPD->iBlackIndex; //Default to black.
  1062. if (Count = (UINT)(pPD->wPalGdi))
  1063. {
  1064. LONG LeastDiff;
  1065. LONG R;
  1066. LONG G;
  1067. LONG B;
  1068. UINT i;
  1069. LPDWORD pPal = (LPDWORD)pPD->ulPalCol;
  1070. //
  1071. // find closest intensity match since this is monochrome mapping
  1072. //
  1073. if (pPD->fFlags & PDF_PALETTE_FOR_8BPP_MONO)
  1074. Color = ConvertRGBToGrey(Color);
  1075. //
  1076. // find closest color using least square distance in RGB
  1077. //
  1078. LeastDiff = (3 * (256 * 256));
  1079. R = RED_VALUE(Color);
  1080. G = GREEN_VALUE(Color);
  1081. B = BLUE_VALUE(Color);
  1082. for (i = 0; i < Count; i++, pPal++) {
  1083. LONG Temp;
  1084. LONG Diff;
  1085. DWORD Pal;
  1086. Pal = *pPal;
  1087. if (Color == 0x00FFFFFF) {
  1088. //
  1089. // White Color we want to exact match
  1090. //
  1091. if (Color == Pal) {
  1092. RetIdx = i;
  1093. break;
  1094. }
  1095. }
  1096. else if (Pal != 0x00FFFFFF) {
  1097. //
  1098. // The Color is not white, so map to one of non-white color
  1099. //
  1100. Temp = R - (LONG)RED_VALUE(Pal);
  1101. Diff = Temp * Temp;
  1102. Temp = G - (LONG)GREEN_VALUE(Pal);
  1103. Diff += Temp * Temp;
  1104. Temp = B - (LONG)BLUE_VALUE(Pal);
  1105. Diff += Temp * Temp;
  1106. if (Diff < LeastDiff) {
  1107. RetIdx = i;
  1108. if (!(LeastDiff = Diff)) {
  1109. //
  1110. // We have exact match
  1111. //
  1112. break;
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. return((DWORD)RetIdx);
  1119. }
  1120. #if CODE_COMPLETE
  1121. VOID
  1122. VSetMonochromeBrushAttributes(
  1123. PDEV *pPDev
  1124. )
  1125. /*++
  1126. Routine Description:
  1127. This routine sets the monochrome brush attributes.
  1128. Arguments:
  1129. pPDev Pointer to PDEV
  1130. Note:
  1131. 4/21/1997 -ganeshp-
  1132. Created it.
  1133. --*/
  1134. {
  1135. PAL_DATA *pPD = pPDev->pPalData;
  1136. if (pPD)
  1137. {
  1138. // Check if the printer supports Fill rectangle command or not. We also
  1139. // check for min and max gray level. Min should be less than max.
  1140. if ( COMMANDPTR(pPDev->pDriverInfo,CMD_SELECTGRAYPATTERN) &&
  1141. (pPDev->pGlobals->dwMinPatternGrayLevel <
  1142. pPDev->pGlobals->dwMaxPatternGrayLevel) )
  1143. {
  1144. pPDev->fMode |= PF_GRAY_BRUSH;
  1145. // If White is not supported by gray level command, check if a
  1146. // separate command for white text simulation or not.
  1147. if ( (pPDev->pGlobals->dwMinPatternGrayLevel > 0)
  1148. {
  1149. //
  1150. // If the device doesn't support white as grey level
  1151. // then some other command has to be used for white.
  1152. // check if there is CMD_WHITEPATTERN command or not.
  1153. // If the device doesn't have this command, try for
  1154. // font simulation WHITE_TEXT_ON command.
  1155. //
  1156. if (COMMANDPTR(pPDev->pDriverInfo,CMD_SELECTWHITEPATTERN))
  1157. pPD->fFlags |= PDF_USE_WHITE_PATTERN;
  1158. /***TODEL****
  1159. else if (COMMANDPTR(pPDev->pDriverInfo,CMD_WHITETEXTON))
  1160. pPD->fFlags |= PDF_USE_WHITE_TEXT_ON_SIM;
  1161. ****TODEL****/
  1162. }
  1163. if ( (pPDev->pGlobals->dwMaxGrayFill < 100)
  1164. {
  1165. //
  1166. // If the device doesn't support black as grey level
  1167. // then some other command has to be used for black.
  1168. // check if there is CMD_BLACKPATTERN command or not.
  1169. // If the device doesn't have this command, try for
  1170. // font simulation WHITE_TEXT_OFF command.
  1171. //
  1172. if (COMMANDPTR(pPDev->pDriverInfo,CMD_WHITEPATTERN))
  1173. pPD->fFlags |= PDF_USE_BLACK_PATTERN;
  1174. /***TODEL****
  1175. else if (COMMANDPTR(pPDev->pDriverInfo,CMD_WHITETEXTON))
  1176. pPD->fFlags |= PDF_USE_WHITE_TEXT_OFF_SIM;
  1177. ****TODEL****/
  1178. }
  1179. }
  1180. }
  1181. else
  1182. {
  1183. ASSERTMSG(FALSE,("\n VSetMonochromeBrushAttributes pPDev->pPalData in NULL!!.\n"));
  1184. }
  1185. }
  1186. BOOL
  1187. BInitPatternScope(
  1188. PDEV *pPDev
  1189. )
  1190. /*++
  1191. Routine Description:
  1192. Initialize the scope of the pattern/brush. This is necessary
  1193. Arguments:
  1194. pPDev Pointer to PDEV
  1195. Return Value:
  1196. TRUE for success and FALSE for failure
  1197. Note:
  1198. 4/22/1997 -ganeshp-
  1199. Created it.
  1200. --*/
  1201. {
  1202. BOOL bRet = TRUE;
  1203. PLISTNODE pListNode;
  1204. PAL_DATA *pPD = pPDev->pPalData;
  1205. if (pListNode = LISTNODEPTR(pPDev->pDriverInfo ,
  1206. pPDev->pGlobals->liPatternScopeList ) )
  1207. {
  1208. while (pListNode)
  1209. {
  1210. // Check the pattern scope and set the corresponding bit in fScope.
  1211. switch (pListNode->dwData)
  1212. {
  1213. case PATTERN_SCOPE_TEXT:
  1214. pPD->fScope |= PDS_TEXT;
  1215. break;
  1216. case PATTERN_SCOPE_VECTOR:
  1217. pPD->fScope |= PDS_VECTOR;
  1218. break;
  1219. case PATTERN_SCOPE_RASTER:
  1220. pPD->fScope |= PDS_RASTER;
  1221. break;
  1222. case PATTERN_SCOPE_RECTFILL:
  1223. pPD->fScope |= PDS_RECTFILL;
  1224. break;
  1225. case PATTERN_SCOPE_LINE:
  1226. pPD->fScope |= PDS_LINE;
  1227. break;
  1228. default:
  1229. ERR(("Unidrv!BInitPatternScope: Wrong value in PatternScope List\n"));
  1230. bRet = FALSE;
  1231. break;
  1232. }
  1233. if (bRet)
  1234. pListNode = LISTNODEPTR(pPDev->pDriverInfo,pListNode->dwNextItem);
  1235. else
  1236. break; //Error
  1237. }
  1238. }
  1239. return bRet;
  1240. }
  1241. BOOL
  1242. BSelectMonochromeBrush(
  1243. PDEV *pPDev,
  1244. ULONG Color
  1245. )
  1246. /*++
  1247. Routine Description:
  1248. Sets the brush color to give color.
  1249. Arguments:
  1250. pPDev Pointer to PDEV
  1251. Color Input Color to select. If it's -1 that means restore the palette
  1252. to original state.
  1253. Return Value:
  1254. TRUE for success and FALSE for failure or if the palette can't be programmed.
  1255. Note:
  1256. 4/9/1997 -ganeshp-
  1257. Created it.
  1258. --*/
  1259. {
  1260. INT iIndex;
  1261. INT iPaletteEntryToSelect;
  1262. PAL_DATA *pPD;
  1263. BOOL bProgramEntry = FALSE;
  1264. BOOL bSelectEntry = TRUE;
  1265. ULONG *pPalette;
  1266. }
  1267. #endif //CODE_COMPLETE
  1268. #undef FILETRACE