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.

111 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include <stdlib.h>
  9. #include <stdlib.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include "vtf/vtf.h"
  13. #include "UtlBuffer.h"
  14. int main( int argc, char **argv )
  15. {
  16. if( argc != 5 )
  17. {
  18. fprintf( stderr, "Usage: vtfscreen blah.vtf 0 1 2\n" );
  19. exit( -1 );
  20. }
  21. const char *pSrcFilename = argv[1];
  22. int rOffset = atoi( argv[2] );
  23. int gOffset = atoi( argv[3] );
  24. int bOffset = atoi( argv[4] );
  25. CUtlBuffer srcData;
  26. struct _stat buf;
  27. if( _stat( pSrcFilename, &buf ) == -1 )
  28. {
  29. fprintf( stderr, "Couldn't stat %s\n", pSrcFilename );
  30. exit( -1 );
  31. }
  32. int srcFileSize = buf.st_size;
  33. srcData.EnsureCapacity( srcFileSize );
  34. FILE *fp = fopen( pSrcFilename, "rb" );
  35. if( !fp )
  36. {
  37. fprintf( stderr, "Couldn't open %s\n", pSrcFilename );
  38. exit( -1 );
  39. }
  40. int nBytesRead = fread( srcData.Base(), 1, srcFileSize, fp );
  41. fclose( fp );
  42. srcData.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead );
  43. IVTFTexture *pSrcTexture = CreateVTFTexture();
  44. pSrcTexture->Unserialize( srcData );
  45. ImageFormat srcFormat = pSrcTexture->Format();
  46. pSrcTexture->ConvertImageFormat( IMAGE_FORMAT_DEFAULT, false );
  47. int totalSize = pSrcTexture->ComputeTotalSize();
  48. unsigned char *pImageData = pSrcTexture->ImageData();
  49. int i;
  50. for( i = 0; i < totalSize; i += 4 )
  51. {
  52. #if 0
  53. // ATI BEFORE E32003
  54. int r, g, b;
  55. r = ( int )pImageData[i+0];
  56. g = ( int )pImageData[i+1];
  57. b = ( int )pImageData[i+2];
  58. int grey = r + g + b;
  59. grey = grey / 3;
  60. pImageData[i+0] = 0;
  61. pImageData[i+1] = grey;
  62. pImageData[i+2] = 0;
  63. #endif
  64. #if 0
  65. // NVIDIA - first e3 build
  66. pImageData[i+1] = 0;
  67. pImageData[i+2] = 0;
  68. #endif
  69. #if 0
  70. // ATI e3 build on . .get the green component and stomp all channels with it.
  71. pImageData[i+0] = pImageData[i+1];
  72. pImageData[i+2] = pImageData[i+1];
  73. #endif
  74. #if 0
  75. // Intel . .get the blue component and stomp all channels with it.
  76. pImageData[i+0] = pImageData[i+2];
  77. pImageData[i+1] = pImageData[i+2];
  78. #endif
  79. // leave alpha alone
  80. int tmpR, tmpG, tmpB;
  81. tmpR = pImageData[i+rOffset];
  82. tmpG = pImageData[i+gOffset];
  83. tmpB = pImageData[i+bOffset];
  84. pImageData[i+0] = tmpR;
  85. pImageData[i+1] = tmpG;
  86. pImageData[i+2] = tmpB;
  87. }
  88. pSrcTexture->ConvertImageFormat( srcFormat, false );
  89. CUtlBuffer dstData;
  90. pSrcTexture->Serialize( dstData );
  91. fp = fopen( pSrcFilename, "wb" );
  92. fwrite( dstData.Base(), 1, dstData.TellPut(), fp );
  93. fclose( fp );
  94. return 0;
  95. }