TexturePage.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. ** Command & Conquer Generals(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. // FILE: TexturePage.h ////////////////////////////////////////////////////////
  19. //-----------------------------------------------------------------------------
  20. //
  21. // Westwood Studios Pacific.
  22. //
  23. // Confidential Information
  24. // Copyright (C) 2001 - All Rights Reserved
  25. //
  26. //-----------------------------------------------------------------------------
  27. //
  28. // Project: ImagePacker
  29. //
  30. // File name: TexturePage.h
  31. //
  32. // Created: Colin Day, August 2001
  33. //
  34. // Desc: This class represents a texture that contains packed
  35. // images.
  36. //
  37. //-----------------------------------------------------------------------------
  38. ///////////////////////////////////////////////////////////////////////////////
  39. #pragma once
  40. #ifndef __TEXTUREPAGE_H_
  41. #define __TEXTUREPAGE_H_
  42. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  43. #include <stdlib.h>
  44. ///////////////////////////////////////////////////////////////////////////////
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. ///////////////////////////////////////////////////////////////////////////////
  47. #include "WWLib/Targa.h"
  48. #include "Lib/BaseType.h"
  49. #include "ImageInfo.h"
  50. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  51. ///////////////////////////////////////////////////////////////////////////////
  52. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // TexturePage ----------------------------------------------------------------
  55. /** A texture page continaing multiple source images */
  56. //-----------------------------------------------------------------------------
  57. class TexturePage
  58. {
  59. public:
  60. enum
  61. {
  62. FREE = 0, ///< open pixel in the cavas
  63. USED = 1, ///< used pixel in the canvas
  64. };
  65. enum
  66. {
  67. READY = 0x00000001, ///< texture page here and OK
  68. PAGE_ERROR = 0x00000002, ///< error on page somewhere
  69. CANT_ALLOCATE_PACKED_IMAGE = 0x00000004, ///< couldn't generate final image
  70. CANT_ADD_IMAGE_DATA = 0x00000008, ///< couldn't add image data to page
  71. NO_TEXTURE_DATA = 0x00000010, ///< there was no image data to write
  72. ERROR_DURING_SAVE = 0x00000020, ///< couldn't save final file
  73. };
  74. TexturePage( Int width, Int height );
  75. ~TexturePage( void );
  76. Bool addImage( ImageInfo *image ); ///< try to add image to this page
  77. void setID( Int id ); ///< set page id
  78. Int getID( void ); ///< get page id
  79. Bool generateTexture( void ); ///< generate the final packed texture
  80. Bool writeFile( char *baseFilename ); ///< write generated texture to file
  81. ImageInfo *getFirstImage( void ); ///< get the first image in the list
  82. Int getWidth( void ); ///< get width of texture page
  83. Int getHeight( void ); ///< get height of texture page
  84. // get rgb from final generated texture (putting this in for quick preview)
  85. void getPixel( Int x, Int y, Byte *r, Byte *g, Byte *b, Byte *a = NULL );
  86. TexturePage *m_next;
  87. TexturePage *m_prev;
  88. UnsignedInt m_status; ///< status bits
  89. protected:
  90. Bool spotUsed( Int x, Int y ); ///< is this spot used
  91. Bool lineUsed( Int sx, Int sy, Int ex, Int ey ); ///< is any spot on the line used
  92. /// build a region to try to fit given the position, size, and border options
  93. UnsignedInt buildFitRegion( IRegion2D *region,
  94. Int startX, Int startY,
  95. Int imageWidth, Int imageHeight,
  96. Int *xGutter, Int *yGutter,
  97. Bool allSidesBorder );
  98. void markRegionUsed( IRegion2D *region ); ///< mark this region as used
  99. /// add the actual image data of 'image' to the destination buffer
  100. Bool addImageData( Byte *destBuffer,
  101. Int destWidth,
  102. Int destHeight,
  103. Int destBPP,
  104. ImageInfo *image );
  105. /// extend edges of image outward into border if present
  106. void extendImageEdges( Byte *destBuffer,
  107. Int destWidth,
  108. Int destHeight,
  109. Int destBPP,
  110. ImageInfo *image,
  111. Bool extendAlpha );
  112. /// if the pixel at abolve/below row is open, extend pixel at src to its location
  113. void extendToRowIfOpen( char *src,
  114. Int buffWidth,
  115. Int buffBPP,
  116. Bool extendAlpha,
  117. Int imageHeight,
  118. UnsignedInt fitBits,
  119. Int srcX, Int srcY );
  120. Int m_id; ///< texture page ID
  121. ICoord2D m_size; ///< dimensions of texture page
  122. UnsignedByte *m_canvas; ///< as big as the texture page, a used spot is non zero
  123. ImageInfo *m_imageList; ///< list of images packed on this page
  124. Byte *m_packedImage; ///< final generated image data
  125. Targa *m_targa; ///< final packed image all in a nice little targa file
  126. };
  127. ///////////////////////////////////////////////////////////////////////////////
  128. // INLINING ///////////////////////////////////////////////////////////////////
  129. ///////////////////////////////////////////////////////////////////////////////
  130. inline void TexturePage::setID( Int id ) { m_id = id; }
  131. inline Int TexturePage::getID( void ) { return m_id; }
  132. inline ImageInfo *TexturePage::getFirstImage( void ) { return m_imageList; }
  133. inline Int TexturePage::getWidth( void ) { return m_size.x; }
  134. inline Int TexturePage::getHeight( void ) { return m_size.y; }
  135. // EXTERNALS //////////////////////////////////////////////////////////////////
  136. #endif // __TEXTUREPAGE_H_