convert.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /G/wwlib/Convert.h $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 4/02/99 11:59a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef CONVERT_H
  39. #define CONVERT_H
  40. #include "blitter.h"
  41. #include "palette.h"
  42. #include "surface.h"
  43. /*
  44. ** Flags used to fetch the appropriate blitter object.
  45. */
  46. typedef enum {
  47. SHAPE_NORMAL = 0x0000, // Standard shape (which is transparent)
  48. SHAPE_WIN_REL = 0x0400,
  49. SHAPE_CENTER = 0x0200, // Coords are based on shape's center pt
  50. SHAPE_DARKEN = 0x0001, // Force all pixels to darken the destination.
  51. SHAPE_TRANSLUCENT25 = 0x0002, // Translucent to destination (25%).
  52. SHAPE_TRANSLUCENT50 = 0x0004, // Translucent to destination (50%).
  53. SHAPE_TRANSLUCENT75 = 0x0006, // Translucent to destination (75%).
  54. SHAPE_PREDATOR = 0x0008, // Predator effect
  55. SHAPE_REMAP = 0x0010, // Simple remap
  56. SHAPE_NOTRANS = 0x0020 // A non transparent but otherwise standard shape
  57. } ShapeFlags_Type;
  58. /*
  59. ** This class is the data that represents the marriage between a source art
  60. ** palette and a destination palette/pixel-format. Facilities provied by this
  61. ** class allow conversion from the source 8 bit pixel format to the correct
  62. ** screen pixel format.
  63. **
  64. ** Although this class can convert one pixel at a time through the conversion
  65. ** function, the preferred way to convert pixels is through the translation
  66. ** table provided. This table consists of 256 entries. Each entry is either
  67. ** an 8 bit or 16 bit pixel in the correct screen-space format. Use the
  68. ** Bytes_Per_Pixel() function to determine how to index into this translation
  69. ** table.
  70. **
  71. ** Expected use of this class would be to create separate objects of this class for
  72. ** every source art palette. For an 8 bit display, an additional object will be
  73. ** required for every additional palette set to the video DAC registers. It is
  74. ** presumed that one general best-case palette will be used.
  75. */
  76. class ConvertClass
  77. {
  78. public:
  79. ConvertClass(PaletteClass const & artpalette, PaletteClass const & screenpalette, Surface const & typicalsurface);
  80. ~ConvertClass(void);
  81. /*
  82. ** Convert from source pixel to dest screen pixel.
  83. */
  84. int Convert_Pixel(int pixel) const {
  85. if (BBP == 1) return(((unsigned char const *)Translator)[pixel]);
  86. return(((unsigned short const *)Translator)[pixel]);
  87. }
  88. /*
  89. ** Fetch a blitter object to use according to the draw flags
  90. ** specified.
  91. */
  92. Blitter const * Blitter_From_Flags(ShapeFlags_Type flags) const;
  93. RLEBlitter const * RLEBlitter_From_Flags(ShapeFlags_Type flags) const;
  94. /*
  95. ** This returns the bytes per pixel. Use this to determine how to index
  96. ** through the translation table.
  97. */
  98. int Bytes_Per_Pixel(void) const {return(BBP);}
  99. /*
  100. ** Fetches the translation table. Sometimes the provided blitter objects
  101. ** won't suffice and manual access to the translation process is necessary.
  102. */
  103. void const * Get_Translate_Table(void) const {return(Translator);}
  104. /*
  105. ** Sets the dynamic remap table so that the remapping blitters will use
  106. ** it without having to recreate the blitter objects.
  107. */
  108. void Set_Remap(unsigned char const * remap) {RemapTable = remap;}
  109. protected:
  110. /*
  111. ** Bytes per pixel in screen format.
  112. */
  113. int BBP;
  114. /*
  115. ** These are the blitter objects used to handle all the draw styles that this
  116. ** drawing dispatcher implements.
  117. */
  118. Blitter * PlainBlitter; // No transparency (rarely used).
  119. Blitter * TransBlitter; // Skips transparent pixels.
  120. Blitter * ShadowBlitter; // Shadowizes the destination pixels.
  121. Blitter * RemapBlitter; // Remaps source pixels then draws with transparency.
  122. Blitter * Translucent1Blitter; // 25% translucent.
  123. Blitter * Translucent2Blitter; // 50% translucent.
  124. Blitter * Translucent3Blitter; // 75% translucent.
  125. /*
  126. ** These are the RLE aware blitters to handle all drawing styles that may
  127. ** be used by RLE compressed images.
  128. */
  129. RLEBlitter * RLETransBlitter; // Skips transparent pixels.
  130. RLEBlitter * RLEShadowBlitter; // Shadowizes the destination pixels.
  131. RLEBlitter * RLERemapBlitter; // Remaps source pixels then draws with transparency.
  132. RLEBlitter * RLETranslucent1Blitter; // 25% translucent.
  133. RLEBlitter * RLETranslucent2Blitter; // 50% translucent.
  134. RLEBlitter * RLETranslucent3Blitter; // 75% translucent.
  135. /*
  136. ** This is a translation table pointer. All source artwork is in 8 bit format.
  137. ** This table will translate this source pixel into a screen dependant pixel
  138. ** format datum.
  139. */
  140. void * Translator;
  141. /*
  142. ** This will shade an 8 bit pixel to about 1/2 intensity.
  143. */
  144. unsigned char * ShadowTable;
  145. /*
  146. ** Remap table pointer used for blits that require remapping. This value
  147. ** will change according to the draw parameter. The blitting routines keep track
  148. ** of this member object and use it to determine the remap table to use.
  149. */
  150. mutable unsigned char const * RemapTable;
  151. };
  152. #endif