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.

106 lines
2.9 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // indcmap.cpp
  4. //
  5. // Implements indirect colormap code.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. typedef struct _RLDDIIndirectPrivate
  13. {
  14. RLDDIColorAllocator* alloc;
  15. size_t size;
  16. unsigned long* map;
  17. } RLDDIIndirectPrivate;
  18. static void Destroy(RLDDIColormap* cmap);
  19. static void SetColor(RLDDIColormap* cmap,
  20. int index, int red, int green, int blue);
  21. RLDDIColormap* RLDDICreateIndirectColormap(RLDDIColorAllocator* alloc,
  22. size_t size)
  23. {
  24. RLDDIColormap* cmap;
  25. RLDDIIndirectPrivate* priv;
  26. size_t i;
  27. if (D3DMalloc((void**) &cmap, sizeof(RLDDIColormap)))
  28. return NULL;
  29. if (D3DMalloc((void**) &priv, sizeof(RLDDIIndirectPrivate)))
  30. {
  31. D3DFree(cmap);
  32. return NULL;
  33. }
  34. cmap->size = size;
  35. cmap->destroy = Destroy;
  36. cmap->set_color = SetColor;
  37. cmap->priv = priv;
  38. priv->alloc = alloc;
  39. priv->size = size;
  40. if (D3DMalloc((void**) &priv->map, size * sizeof(unsigned long)))
  41. {
  42. D3DFree(priv);
  43. D3DFree(cmap);
  44. return NULL;
  45. }
  46. for (i = 0; i < size; i++)
  47. priv->map[i] = alloc->allocate_color(alloc->priv, 0, 0, 0);
  48. return cmap;
  49. }
  50. unsigned long* RLDDIIndirectColormapGetMap(RLDDIColormap* cmap)
  51. {
  52. RLDDIIndirectPrivate* priv;
  53. if (cmap == NULL)
  54. return NULL;
  55. priv = (RLDDIIndirectPrivate*) cmap->priv;
  56. if ( priv == NULL)
  57. return NULL;
  58. else
  59. return priv->map;
  60. }
  61. static void Destroy(RLDDIColormap* cmap)
  62. {
  63. if (cmap && cmap->priv && ((RLDDIIndirectPrivate*)cmap->priv)->alloc)
  64. {
  65. RLDDIIndirectPrivate* priv = (RLDDIIndirectPrivate*) cmap->priv;
  66. RLDDIColorAllocator* alloc = priv->alloc;
  67. size_t i;
  68. for (i = 0; i < priv->size; i++)
  69. alloc->free_color(alloc->priv, priv->map[i]);
  70. D3DFree(priv->map);
  71. D3DFree(priv);
  72. D3DFree(cmap);
  73. }
  74. }
  75. static void SetColor(RLDDIColormap* cmap,
  76. int index, int red, int green, int blue)
  77. {
  78. red = min(max(red, 0x0), 0xff);
  79. green = min(max(green, 0x0), 0xff);
  80. blue = min(max(blue, 0x0), 0xff);
  81. if (cmap && cmap->priv && ((RLDDIIndirectPrivate*)cmap->priv)->alloc)
  82. {
  83. RLDDIIndirectPrivate* priv = (RLDDIIndirectPrivate*) cmap->priv;
  84. RLDDIColorAllocator* alloc = priv->alloc;
  85. if (index >= 0 && ((size_t)index) < priv->size)
  86. {
  87. alloc->free_color(alloc->priv, priv->map[index]);
  88. priv->map[index] = alloc->allocate_color(alloc->priv, red, green, blue);
  89. }
  90. }
  91. }