BinaryImage.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __BINARYIMAGE_H__
  21. #define __BINARYIMAGE_H__
  22. #include "BinaryImageData.h"
  23. /*
  24. ================================================
  25. idBinaryImage is used by the idImage class for constructing mipmapped
  26. textures and for loading and saving generated files by idImage.
  27. Also used in a memory-mapped form for imageCPU for offline megatexture
  28. generation.
  29. ================================================
  30. */
  31. class idBinaryImage {
  32. public:
  33. idBinaryImage( const char * name ) : imgName( name ) { }
  34. const char * GetName() const { return imgName.c_str(); }
  35. void SetName( const char *_name ) { imgName = _name; }
  36. void Load2DFromMemory( int width, int height, const byte * pic_const, int numLevels, textureFormat_t & textureFormat, textureColor_t & colorFormat, bool gammaMips );
  37. void LoadCubeFromMemory( int width, const byte * pics[6], int numLevels, textureFormat_t & textureFormat, bool gammaMips );
  38. ID_TIME_T LoadFromGeneratedFile( ID_TIME_T sourceFileTime );
  39. ID_TIME_T WriteGeneratedFile( ID_TIME_T sourceFileTime );
  40. const bimageFile_t & GetFileHeader() { return fileData; }
  41. int NumImages() { return images.Num(); }
  42. const bimageImage_t & GetImageHeader( int i ) const { return images[i]; }
  43. const byte * GetImageData( int i ) const { return images[i].data; }
  44. static void GetGeneratedFileName( idStr & gfn, const char *imageName );
  45. private:
  46. idStr imgName; // game path, including extension (except for cube maps), may be an image program
  47. bimageFile_t fileData;
  48. class idBinaryImageData : public bimageImage_t {
  49. public:
  50. byte * data;
  51. idBinaryImageData() : data( NULL ) { }
  52. ~idBinaryImageData() { Free(); }
  53. idBinaryImageData & operator=( idBinaryImageData & other ) {
  54. if ( this == &other ) {
  55. return *this;
  56. }
  57. Alloc( other.dataSize );
  58. memcpy( data, other.data, other.dataSize );
  59. return *this;
  60. }
  61. void Free() {
  62. if ( data != NULL ) {
  63. Mem_Free( data );
  64. data = NULL;
  65. dataSize = 0;
  66. }
  67. }
  68. void Alloc( int size ) {
  69. Free();
  70. dataSize = size;
  71. data = (byte *)Mem_Alloc( size, TAG_CRAP );
  72. }
  73. };
  74. idList< idBinaryImageData, TAG_IDLIB_LIST_IMAGE > images;
  75. private:
  76. void MakeGeneratedFileName( idStr & gfn );
  77. bool LoadFromGeneratedFile( idFile * f, ID_TIME_T sourceFileTime );
  78. };
  79. #endif // __BINARYIMAGE_H__