Counter Strike : Global Offensive Source Code
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.

106 lines
5.5 KiB

  1. //========= Copyright (c) 1996-2009, 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. class CUtlBuffer;
  45. ConversionErrorType ImgUtl_ConvertJPEGToTGA( const char *jpgPath, const char *tgaPath, bool bRequirePowerOfTwoSize = true );
  46. ConversionErrorType ImgUtl_ConvertBMPToTGA( const char *bmpPath, const char *tgaPath );
  47. ConversionErrorType ImgUtl_ConvertTGA( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
  48. unsigned char *ImgUtl_ReadVTFAsRGBA( const char *vtfPath, int &width, int &height, ConversionErrorType &errcode );
  49. unsigned char *ImgUtl_ReadTGAAsRGBA( const char *tgaPath, int &width, int &height, ConversionErrorType &errcode, TGAHeader &tgaHeader );
  50. unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &height, ConversionErrorType &errcode );
  51. ConversionErrorType ImgUtl_ReadJPEGAsRGBA( CUtlBuffer &srcBuf, CUtlBuffer &dstBuf, int &width, int &height );
  52. unsigned char *ImgUtl_ReadBMPAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
  53. unsigned char *ImgUtl_ReadPNGAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
  54. unsigned char *ImgUtl_ReadPNGAsRGBAFromBuffer( CUtlBuffer &buffer, int &width, int &height, ConversionErrorType &errcode );
  55. unsigned char *ImgUtl_ReadImageAsRGBA( const char *path, int &width, int &height, ConversionErrorType &errcode );
  56. ConversionErrorType ImgUtl_StretchRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
  57. ConversionErrorType ImgUtl_PadRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
  58. ConversionErrorType ImgUtl_ConvertTGAToVTF( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
  59. ConversionErrorType ImgUtl_WriteGenericVMT( const char *vtfPath, const char *pMaterialsSubDir );
  60. ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
  61. ConversionErrorType ImgUtl_WriteRGBAAsJPEGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
  62. ConversionErrorType ImgUtl_ReadJPEGToRGB( CUtlBuffer &srcBuf,CUtlBuffer &dstBuf, int &width, int &height );
  63. bool ImgUtl_WriteRGBAToJPEG( unsigned char *pSrcBuf, unsigned int nSrcWidth, unsigned int nSrcHeight, const char *lpszFilename );
  64. //
  65. // Converts pInPath (which can be a TGA, BMP, or JPG file) to a VTF in pMaterialsSubDir, where
  66. // pMaterialsSubDir is a directory located relative to the game/materials directory. If the
  67. // output directory doesn't exist, it will be created. Dumps a generic VMT in pMaterialsSubDir
  68. // as well.
  69. //
  70. ConversionErrorType ImgUtl_ConvertToVTFAndDumpVMT( const char *pInPath, const char *pMaterialsSubDir,
  71. int nMaxWidth = -1, int nMaxHeight = -1 );
  72. /// Load from image file. We use the file extension to
  73. /// decide what file format to use
  74. ConversionErrorType ImgUtl_LoadBitmap( const char *pszFilename, Bitmap_t &bitmap );
  75. /// Load an image direct from memory buffer
  76. ConversionErrorType ImgUtl_LoadBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
  77. /// Save a bitmap to memory buffer
  78. ConversionErrorType ImgUtl_SaveBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
  79. /// Load a PNG direct from memory buffer
  80. ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap );
  81. /// Save a bitmap in PNG format to memory buffer
  82. ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap );
  83. /// Resize a bitmap. This currently only works for RGBA images!
  84. ConversionErrorType ImgUtl_ResizeBitmap( Bitmap_t &destBitmap, int nWidth, int nHeight, const Bitmap_t *pImgSource = NULL );
  85. ConversionErrorType ImgUtl_CropRGBA( int x0, int y0, int nSrcWidth, int nSrcHeight, int nDestWidth, int nDestHeight, const unsigned char *pIn, unsigned char *pOut );
  86. #endif // IMAGECONVERSION_H