ispc_texcomp.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Copyright (c) 2013-2015, Intel Corporation
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Intel Corporation nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  17. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  18. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  19. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <stdint.h>
  28. struct rgba_surface
  29. {
  30. uint8_t* ptr;
  31. int32_t width;
  32. int32_t height;
  33. int32_t stride; // in bytes
  34. };
  35. struct bc7_enc_settings
  36. {
  37. bool mode_selection[4];
  38. int refineIterations[8];
  39. bool skip_mode2;
  40. int fastSkipTreshold_mode1;
  41. int fastSkipTreshold_mode3;
  42. int fastSkipTreshold_mode7;
  43. int mode45_channel0;
  44. int refineIterations_channel;
  45. int channels;
  46. };
  47. struct bc6h_enc_settings
  48. {
  49. bool slow_mode;
  50. bool fast_mode;
  51. int refineIterations_1p;
  52. int refineIterations_2p;
  53. int fastSkipTreshold;
  54. };
  55. struct etc_enc_settings
  56. {
  57. int fastSkipTreshold;
  58. };
  59. struct astc_enc_settings
  60. {
  61. int block_width;
  62. int block_height;
  63. int channels;
  64. int fastSkipTreshold;
  65. int refineIterations;
  66. };
  67. // profiles for RGB data (alpha channel will be ignored)
  68. extern "C" void GetProfile_ultrafast(bc7_enc_settings* settings);
  69. extern "C" void GetProfile_veryfast(bc7_enc_settings* settings);
  70. extern "C" void GetProfile_fast(bc7_enc_settings* settings);
  71. extern "C" void GetProfile_basic(bc7_enc_settings* settings);
  72. extern "C" void GetProfile_slow(bc7_enc_settings* settings);
  73. // profiles for RGBA inputs
  74. extern "C" void GetProfile_alpha_ultrafast(bc7_enc_settings* settings);
  75. extern "C" void GetProfile_alpha_veryfast(bc7_enc_settings* settings);
  76. extern "C" void GetProfile_alpha_fast(bc7_enc_settings* settings);
  77. extern "C" void GetProfile_alpha_basic(bc7_enc_settings* settings);
  78. extern "C" void GetProfile_alpha_slow(bc7_enc_settings* settings);
  79. // profiles for BC6H (RGB HDR)
  80. extern "C" void GetProfile_bc6h_veryfast(bc6h_enc_settings* settings);
  81. extern "C" void GetProfile_bc6h_fast(bc6h_enc_settings* settings);
  82. extern "C" void GetProfile_bc6h_basic(bc6h_enc_settings* settings);
  83. extern "C" void GetProfile_bc6h_slow(bc6h_enc_settings* settings);
  84. extern "C" void GetProfile_bc6h_veryslow(bc6h_enc_settings* settings);
  85. // profiles for ETC
  86. extern "C" void GetProfile_etc_slow(etc_enc_settings* settings);
  87. // profiles for ASTC
  88. extern "C" void GetProfile_astc_fast(astc_enc_settings* settings, int block_width, int block_height);
  89. extern "C" void GetProfile_astc_alpha_fast(astc_enc_settings* settings, int block_width, int block_height);
  90. extern "C" void GetProfile_astc_alpha_slow(astc_enc_settings* settings, int block_width, int block_height);
  91. // helper function to replicate border pixels for the desired block sizes (bpp = 32 or 64)
  92. extern "C" void ReplicateBorders(rgba_surface* dst_slice, const rgba_surface* src_tex, int x, int y, int bpp);
  93. /*
  94. Notes:
  95. - input width and height need to be a multiple of block size
  96. - LDR input is 32 bit/pixel (sRGB), HDR is 64 bit/pixel (half float)
  97. - dst buffer must be allocated with enough space for the compressed texture:
  98. 4 bytes/block for BC1/ETC1, 8 bytes/block for BC3/BC6H/BC7/ASTC
  99. the blocks are stored in raster scan order (natural CPU texture layout)
  100. - you can use GetProfile_* functions to select various speed/quality tradeoffs.
  101. - the RGB profiles are slightly faster as they ignore the alpha channel
  102. */
  103. extern "C" void CompressBlocksBC1(const rgba_surface* src, uint8_t* dst);
  104. extern "C" void CompressBlocksBC3(const rgba_surface* src, uint8_t* dst);
  105. extern "C" void CompressBlocksBC6H(const rgba_surface* src, uint8_t* dst, bc6h_enc_settings* settings);
  106. extern "C" void CompressBlocksBC7(const rgba_surface* src, uint8_t* dst, bc7_enc_settings* settings);
  107. extern "C" void CompressBlocksETC1(const rgba_surface* src, uint8_t* dst, etc_enc_settings* settings);
  108. extern "C" void CompressBlocksASTC(const rgba_surface* src, uint8_t* dst, astc_enc_settings* settings);