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.

109 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef S3TC_DECODE_H
  7. #define S3TC_DECODE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "bitmap/imageformat.h"
  12. enum ImageFormat;
  13. class S3RGBA
  14. {
  15. public:
  16. unsigned char b, g, r, a;
  17. };
  18. class S3PaletteIndex
  19. {
  20. public:
  21. unsigned char m_AlphaIndex;
  22. unsigned char m_ColorIndex;
  23. };
  24. #define MAX_S3TC_BLOCK_BYTES 16
  25. S3PaletteIndex S3TC_GetPixelPaletteIndex( ImageFormat format, const char *pS3Block, int x, int y );
  26. void S3TC_SetPixelPaletteIndex( ImageFormat format, char *pS3Block, int x, int y, S3PaletteIndex iPaletteIndex );
  27. // Note: width, x, and y are in texels, not S3 blocks.
  28. S3PaletteIndex S3TC_GetPaletteIndex(
  29. unsigned char *pFaceData,
  30. ImageFormat format,
  31. int imageWidth,
  32. int x,
  33. int y );
  34. // Note: width, x, and y are in texels, not S3 blocks.
  35. void S3TC_SetPaletteIndex(
  36. unsigned char *pFaceData,
  37. ImageFormat format,
  38. int imageWidth,
  39. int x,
  40. int y,
  41. S3PaletteIndex paletteIndex );
  42. const char* S3TC_GetBlock(
  43. const void *pCompressed,
  44. ImageFormat format,
  45. int nBlocksWide, // How many blocks wide is the image (pixels wide / 4).
  46. int xBlock,
  47. int yBlock );
  48. char* S3TC_GetBlock(
  49. void *pCompressed,
  50. ImageFormat format,
  51. int nBlocksWide, // How many blocks wide is the image (pixels wide / 4).
  52. int xBlock,
  53. int yBlock );
  54. // Merge the two palettes and copy the colors
  55. void S3TC_MergeBlocks(
  56. char **blocks,
  57. S3RGBA **pOriginals, // Original RGBA colors in the texture. This allows it to avoid doubly compressing.
  58. int nBlocks,
  59. int lPitch, // (in BYTES)
  60. ImageFormat format
  61. );
  62. // Convert an RGB565 color to RGBA8888.
  63. inline S3RGBA S3TC_RGBAFrom565( unsigned short color, unsigned char alphaValue=255 )
  64. {
  65. S3RGBA ret;
  66. ret.a = alphaValue;
  67. ret.r = (unsigned char)( (color >> 11) << 3 );
  68. ret.g = (unsigned char)( ((color >> 5) & 0x3F) << 2 );
  69. ret.b = (unsigned char)( (color & 0x1F) << 3 );
  70. return ret;
  71. }
  72. // Blend from one color to another..
  73. inline S3RGBA S3TC_RGBABlend( const S3RGBA &a, const S3RGBA &b, int aMul, int bMul, int div )
  74. {
  75. S3RGBA ret;
  76. ret.r = (unsigned char)(( (int)a.r * aMul + (int)b.r * bMul ) / div );
  77. ret.g = (unsigned char)(( (int)a.g * aMul + (int)b.g * bMul ) / div );
  78. ret.b = (unsigned char)(( (int)a.b * aMul + (int)b.b * bMul ) / div );
  79. ret.a = (unsigned char)(( (int)a.a * aMul + (int)b.a * bMul ) / div );
  80. return ret;
  81. }
  82. #endif // S3TC_DECODE_H