ImagePacker.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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: ImagePacker.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: ImagePacker.h
  31. //
  32. // Created: Colin Day, August 2001
  33. //
  34. // Desc: Image packer tool
  35. //
  36. //-----------------------------------------------------------------------------
  37. ///////////////////////////////////////////////////////////////////////////////
  38. #pragma once
  39. #ifndef __IMAGEPACKER_H_
  40. #define __IMAGEPACKER_H_
  41. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  42. #include <windows.h>
  43. // USER INCLUDES //////////////////////////////////////////////////////////////
  44. #include "Lib/BaseType.h"
  45. #include "WWLib/Targa.h"
  46. #include "ImageDirectory.h"
  47. #include "ImageInfo.h"
  48. #include "TexturePage.h"
  49. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  52. ///////////////////////////////////////////////////////////////////////////////
  53. #define MAX_OUTPUT_FILE_LEN 128
  54. #define DEFAULT_TARGET_SIZE 512
  55. // ImagePacker ----------------------------------------------------------------
  56. // Class interface for running the image packer */
  57. //-----------------------------------------------------------------------------
  58. class ImagePacker
  59. {
  60. public:
  61. enum
  62. {
  63. GAP_METHOD_EXTEND_RGB = 0x00000001, ///< extend RGB (no alpha) of image on all sides
  64. GAP_METHOD_GUTTER = 0x00000002, ///< put transparent gutter on right and bottom side of image
  65. };
  66. public:
  67. ImagePacker( void );
  68. virtual ~ImagePacker( void );
  69. Bool init( void ); ///< initialize the system
  70. Bool process( void ); ///< run the process
  71. Bool getSettingsFromDialog( HWND dialog ); ///< get the options for exection
  72. void setWindowHandle( HWND hWnd ); ///< set window handle for 'dialog' app
  73. HWND getWindowHandle( void ); ///< get window handle for 'dialog' app
  74. ICoord2D *getTargetSize( void ); ///< get target size
  75. Int getTargetWidth( void ); ///< get target width
  76. Int getTargetHeight( void ); ///< bet target height
  77. void statusMessage( char *message ); ///< set a status message
  78. UnsignedInt getImageCount( void ); ///< get image count
  79. ImageInfo *getImage( Int index ); ///< get image
  80. TexturePage *getFirstTexturePage( void ); ///< get first texture page
  81. UnsignedInt getPageCount( void ); ///< get the count of texutre pages
  82. void setTargetPreviewPage( Int page ); ///< set the target preview page to view
  83. Int getTargetPreviewPage( void ); ///< get the target preview page to view
  84. void setGutter( UnsignedInt size ); ///< set gutter size in pixels
  85. UnsignedInt getGutter( void ); ///< get gutter size in pixels
  86. void setGapMethod( UnsignedInt methodBit ); ///< set gap method option
  87. void clearGapMethod( UnsignedInt methodBit ); ///< clear gap method option
  88. UnsignedInt getGapMethod( void ); ///< get gap method option
  89. void setOutputAlpha( Bool outputAlpha ); ///< set output alpha option
  90. Bool getOutputAlpha( void ); ///< get output alpha option
  91. void setPreviewWindow( HWND window ); ///< assign preview window handle
  92. HWND getPreviewWindow( void ); ///< get the preview window handle
  93. void setUseTexturePreview( Bool use ); ///< use the real image data in preview
  94. Bool getUseTexturePreview( void ); ///< get texture preview option
  95. void setINICreate( Bool create ); ///< set create INI file option
  96. Bool createINIFile( void ); ///< get create INI option
  97. char *getOutputFile( void ); ///< get output filename
  98. char *getOutputDirectory( void ); ///< get output directory
  99. void setCompressTextures( Bool compress ); ///< set compress textures option
  100. Bool getCompressTextures( void ); ///< get compress textures option
  101. protected:
  102. void setTargetSize( Int width, Int height ); ///< set the size of the output target image
  103. Bool checkOutputDirectory( void ); ///< verify output directory is OK
  104. void resetImageDirectoryList( void ); ///< clear the image directory list
  105. void resetImageList( void ); ///< clear the image list
  106. void resetPageList( void ); ///< clear the texture page list
  107. void addDirectory( char *path, Bool subDirs ); ///< add directory to directory list
  108. void addImagesInDirectory( char *dir ); ///< add all images from the specified directory
  109. void addImage( char *path ); ///< add image to image list
  110. Bool validateImages( void ); ///< validate that the loaded images can all be processed
  111. Bool packImages( void ); ///< do the packing
  112. void writeFinalTextures( void ); ///< write the packed textures
  113. Bool generateINIFile( void ); ///< generate the INI file for this image set
  114. TexturePage *createNewTexturePage( void ); ///< create a new texture page
  115. void sortImageList( void ); ///< sort the image list
  116. HWND m_hWnd; ///< window handle for app
  117. ICoord2D m_targetSize; ///< the target size
  118. Bool m_useSubFolders; ///< use subfolders option
  119. char m_outputFile[ MAX_OUTPUT_FILE_LEN ]; ///< output filename
  120. char m_outputDirectory[ _MAX_PATH ]; ///< destination for texture files
  121. ImageDirectory *m_dirList; ///< the directory list
  122. UnsignedInt m_dirCount; ///< length of dirList
  123. UnsignedInt m_imagesInDirs; ///< number of images in all directories
  124. ImageInfo **m_imageList; ///< the image list
  125. UnsignedInt m_imageCount; ///< length of imageList
  126. char m_statusBuffer[ 1024 ]; ///< for printing status messages
  127. TexturePage *m_pageTail; ///< end of the texture page list
  128. TexturePage *m_pageList; ///< the final images generated from the packer
  129. UnsignedInt m_pageCount; ///< length of page list
  130. UnsignedInt m_gapMethod; ///< gap method option bits
  131. UnsignedInt m_gutterSize; ///< gutter gaps between images in pixels
  132. Bool m_outputAlpha; ///< final image files will have an alpha channel
  133. Bool m_createINI; ///< create the INI file from compressed image data
  134. Int m_targetPreviewPage; ///< preview page we're looking at
  135. HWND m_hWndPreview; ///< the preview window
  136. Bool m_showTextureInPreview; ///< show actual texture in preview window
  137. Targa *m_targa; ///< targa for loading file headers
  138. Bool m_compressTextures; ///< compress the final textures
  139. };
  140. ///////////////////////////////////////////////////////////////////////////////
  141. // INLINING ///////////////////////////////////////////////////////////////////
  142. ///////////////////////////////////////////////////////////////////////////////
  143. inline void ImagePacker::setTargetSize( Int width, Int height ) { m_targetSize.x = width; m_targetSize.y = height; }
  144. inline ICoord2D *ImagePacker::getTargetSize( void ) { return &m_targetSize; }
  145. inline Int ImagePacker::getTargetWidth( void ) { return m_targetSize.x; }
  146. inline Int ImagePacker::getTargetHeight( void ) { return m_targetSize.y; }
  147. inline void ImagePacker::setWindowHandle( HWND hWnd ) { m_hWnd = hWnd; }
  148. inline HWND ImagePacker::getWindowHandle( void ) { return m_hWnd; }
  149. inline UnsignedInt ImagePacker::getImageCount( void ) { return m_imageCount; }
  150. inline ImageInfo *ImagePacker::getImage( Int index ) { return m_imageList[ index ]; }
  151. inline void ImagePacker::setTargetPreviewPage( Int page ) { m_targetPreviewPage = page; }
  152. inline Int ImagePacker::getTargetPreviewPage( void ) { return m_targetPreviewPage; }
  153. inline UnsignedInt ImagePacker::getPageCount( void ) { return m_pageCount; }
  154. inline void ImagePacker::setPreviewWindow( HWND window ) { m_hWndPreview = window; }
  155. inline HWND ImagePacker::getPreviewWindow( void ) { return m_hWndPreview; }
  156. inline void ImagePacker::setGutter( UnsignedInt size ) { m_gutterSize = size; }
  157. inline UnsignedInt ImagePacker::getGutter( void ) { return m_gutterSize; }
  158. inline void ImagePacker::setOutputAlpha( Bool outputAlpha ) { m_outputAlpha = outputAlpha; }
  159. inline Bool ImagePacker::getOutputAlpha( void ) { return m_outputAlpha; }
  160. inline TexturePage *ImagePacker::getFirstTexturePage( void ) { return m_pageList; }
  161. inline void ImagePacker::setUseTexturePreview( Bool use ) { m_showTextureInPreview = use; }
  162. inline Bool ImagePacker::getUseTexturePreview( void ) { return m_showTextureInPreview; }
  163. inline void ImagePacker::setINICreate( Bool create ) { m_createINI = create; };
  164. inline Bool ImagePacker::createINIFile( void ) { return m_createINI; }
  165. inline char *ImagePacker::getOutputFile( void ) { return m_outputFile; }
  166. inline char *ImagePacker::getOutputDirectory( void ) { return m_outputDirectory; }
  167. inline void ImagePacker::setCompressTextures( Bool compress ) { m_compressTextures = compress; }
  168. inline Bool ImagePacker::getCompressTextures( void ) { return m_compressTextures; }
  169. inline void ImagePacker::setGapMethod( UnsignedInt methodBit ) { BitSet( m_gapMethod, methodBit ); }
  170. inline void ImagePacker::clearGapMethod( UnsignedInt methodBit ) { BitClear( m_gapMethod, methodBit ); }
  171. inline UnsignedInt ImagePacker::getGapMethod( void ) { return m_gapMethod; }
  172. ///////////////////////////////////////////////////////////////////////////////
  173. // EXTERNALS //////////////////////////////////////////////////////////////////
  174. ///////////////////////////////////////////////////////////////////////////////
  175. extern ImagePacker *TheImagePacker;
  176. #endif // __IMAGEPACKER_H_