Team Fortress 2 Source Code as on 22/4/2020
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.

99 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef IMAGECONVERSION_H
  5. #define IMAGECONVERSION_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. #include "tier0/basetypes.h"
  10. class CUtlBuffer;
  11. struct Bitmap_t;
  12. enum ConversionErrorType
  13. {
  14. CE_SUCCESS,
  15. CE_MEMORY_ERROR,
  16. CE_CANT_OPEN_SOURCE_FILE,
  17. CE_ERROR_PARSING_SOURCE,
  18. CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED,
  19. CE_SOURCE_FILE_TGA_FORMAT_NOT_SUPPORTED,
  20. CE_SOURCE_FILE_BMP_FORMAT_NOT_SUPPORTED,
  21. CE_SOURCE_FILE_SIZE_NOT_SUPPORTED,
  22. CE_ERROR_WRITING_OUTPUT_FILE,
  23. CE_ERROR_LOADING_DLL
  24. };
  25. enum ImageFileFormat
  26. {
  27. kImageFileFormat_PNG,
  28. kImageFileFormat_JPG,
  29. };
  30. struct TGAHeader {
  31. byte identsize; // size of ID field that follows 18 byte header (0 usually)
  32. byte colourmaptype; // type of colour map 0=none, 1=has palette
  33. byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
  34. short colourmapstart; // first colour map entry in palette
  35. short colourmaplength; // number of colours in palette
  36. byte colourmapbits; // number of bits per palette entry 15,16,24,32
  37. short xstart; // image x origin
  38. short ystart; // image y origin
  39. short width; // image width in pixels
  40. short height; // image height in pixels
  41. byte bits; // image bits per pixel 8,16,24,32
  42. byte descriptor; // image descriptor bits (vh flip bits)
  43. };
  44. ConversionErrorType ImgUtl_ConvertJPEGToTGA( const char *jpgPath, const char *tgaPath, bool bRequirePowerOfTwoSize = true );
  45. ConversionErrorType ImgUtl_ConvertBMPToTGA( const char *bmpPath, const char *tgaPath );
  46. ConversionErrorType ImgUtl_ConvertTGA( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
  47. unsigned char *ImgUtl_ReadVTFAsRGBA( const char *vtfPath, int &width, int &height, ConversionErrorType &errcode );
  48. unsigned char *ImgUtl_ReadTGAAsRGBA( const char *tgaPath, int &width, int &height, ConversionErrorType &errcode, TGAHeader &tgaHeader );
  49. unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &height, ConversionErrorType &errcode );
  50. unsigned char *ImgUtl_ReadBMPAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
  51. unsigned char *ImgUtl_ReadPNGAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
  52. unsigned char *ImgUtl_ReadPNGAsRGBAFromBuffer( CUtlBuffer &buffer, int &width, int &height, ConversionErrorType &errcode );
  53. unsigned char *ImgUtl_ReadImageAsRGBA( const char *path, int &width, int &height, ConversionErrorType &errcode );
  54. ConversionErrorType ImgUtl_StretchRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
  55. ConversionErrorType ImgUtl_PadRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
  56. ConversionErrorType ImgUtl_ConvertTGAToVTF( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
  57. ConversionErrorType ImgUtl_WriteGenericVMT( const char *vtfPath, const char *pMaterialsSubDir );
  58. ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
  59. ConversionErrorType ImgUtl_WriteRGBAAsJPEGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
  60. //
  61. // Converts pInPath (which can be a TGA, BMP, or JPG file) to a VTF in pMaterialsSubDir, where
  62. // pMaterialsSubDir is a directory located relative to the game/materials directory. If the
  63. // output directory doesn't exist, it will be created. Dumps a generic VMT in pMaterialsSubDir
  64. // as well.
  65. //
  66. ConversionErrorType ImgUtl_ConvertToVTFAndDumpVMT( const char *pInPath, const char *pMaterialsSubDir,
  67. int nMaxWidth = -1, int nMaxHeight = -1 );
  68. /// Load from image file. We use the file extension to
  69. /// decide what file format to use
  70. ConversionErrorType ImgUtl_LoadBitmap( const char *pszFilename, Bitmap_t &bitmap );
  71. /// Load an image direct from memory buffer
  72. ConversionErrorType ImgUtl_LoadBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
  73. /// Save a bitmap to memory buffer
  74. ConversionErrorType ImgUtl_SaveBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
  75. /// Load a PNG direct from memory buffer
  76. ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap );
  77. /// Save a bitmap in PNG format to memory buffer
  78. ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap );
  79. /// Resize a bitmap. This currently only works for RGBA images!
  80. ConversionErrorType ImgUtl_ResizeBitmap( Bitmap_t &destBitmap, int nWidth, int nHeight, const Bitmap_t *pImgSource = NULL );
  81. #endif // IMAGECONVERSION_H