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.

60 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "imageloadwrapper.h"
  7. bool ConvertImageToRGB( const byte *pubImageData, int cubImageData, CUtlBuffer &bufOutput, int &width, int &height )
  8. {
  9. bool bSuccess = false;
  10. if ( GetJpegDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) )
  11. {
  12. bSuccess = ConvertJpegToRGB( pubImageData, cubImageData, bufOutput, width, height );
  13. }
  14. else if ( GetPNGDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) )
  15. {
  16. if ( ConvertPNGToRGBA( pubImageData, cubImageData, bufOutput, width, height ) )
  17. bSuccess = BConvertRGBAToRGB( bufOutput, width, height );
  18. }
  19. else if ( GetTGADimensions( cubImageData, (char*)pubImageData, &width, &height ) )
  20. {
  21. byte *pubRGB = NULL;
  22. int cubRGB = 0;
  23. bSuccess = LoadTGA( cubImageData, (char*)pubImageData, &pubRGB, &cubRGB, &width, &height );
  24. if ( bSuccess )
  25. {
  26. bufOutput.CopyBuffer( pubRGB, cubRGB );
  27. delete [] pubRGB;
  28. bSuccess = BConvertRGBAToRGB( bufOutput, width, height );
  29. }
  30. }
  31. return bSuccess;
  32. }
  33. bool ConvertImageToRGBA( const byte *pubImageData, int cubImageData, CUtlBuffer &bufOutput, int &width, int &height )
  34. {
  35. bool bSuccess = false;
  36. if ( GetJpegDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) )
  37. {
  38. bSuccess = ConvertJpegToRGBA( pubImageData, cubImageData, bufOutput, width, height );
  39. }
  40. else if ( GetPNGDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) )
  41. {
  42. bSuccess = ConvertPNGToRGBA( pubImageData, cubImageData, bufOutput, width, height );
  43. }
  44. else if ( GetTGADimensions( cubImageData, (char*)pubImageData, &width, &height ) )
  45. {
  46. byte *pubRGB = NULL;
  47. int cubRGB = 0;
  48. bSuccess = LoadTGA( cubImageData, (char*)pubImageData, &pubRGB, &cubRGB, &width, &height );
  49. if ( bSuccess )
  50. {
  51. bufOutput.CopyBuffer( pubRGB, cubRGB );
  52. delete [] pubRGB;
  53. }
  54. }
  55. return bSuccess;
  56. }