1 // File: crnlib.h - Advanced DXTn texture compression library.
2 // Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
3 // See copyright notice and license at the end of this file.
5 // This header file contains the public crnlib declarations for DXTn,
6 // clustered DXTn, and CRN compression/decompression.
8 // Note: This library does NOT need to be linked into your game executable if
9 // all you want to do is transcode .CRN files to raw DXTn bits at run-time.
10 // The crn_decomp.h header file library contains all the code necessary for
13 // Important: If compiling with gcc, be sure strict aliasing is disabled: -fno-strict-aliasing
18 #pragma warning(disable : 4127) // conditional expression is constant
21 #define CRNLIB_VERSION 104
23 #define CRNLIB_SUPPORT_ATI_COMPRESS 0
24 #define CRNLIB_SUPPORT_SQUISH 0
26 typedef unsigned char crn_uint8;
27 typedef unsigned short crn_uint16;
28 typedef unsigned int crn_uint32;
29 typedef signed char crn_int8;
30 typedef signed short crn_int16;
31 typedef signed int crn_int32;
32 typedef unsigned int crn_bool;
34 // crnlib can compress to these file types.
39 // .DDS using regular DXT or clustered DXT
42 cCRNFileTypeForceDWORD = 0xFFFFFFFF
45 // Supported compressed pixel formats.
46 // Basically all the standard DX9 formats, with some swizzled DXT5 formats
47 // (most of them supported by ATI's Compressonator), along with some ATI/X360 GPU specific formats.
53 cCRNFmtFirstValid = cCRNFmtDXT1,
55 // cCRNFmtDXT3 is not currently supported when writing to CRN - only DDS.
60 // Various DXT5 derivatives
61 cCRNFmtDXT5_CCxY, // Luma-chroma
62 cCRNFmtDXT5_xGxR, // Swizzled 2-component
63 cCRNFmtDXT5_xGBR, // Swizzled 3-component
64 cCRNFmtDXT5_AGBR, // Swizzled 4-component
66 // ATI 3DC and X360 DXN
70 // DXT5 alpha blocks only
79 cCRNFmtForceDWORD = 0xFFFFFFFF
82 // Various library/file format limits.
84 // Max. mipmap level resolution on any axis.
85 cCRNMaxLevelResolution = 4096,
87 cCRNMinPaletteSize = 8,
88 cCRNMaxPaletteSize = 8192,
93 cCRNMaxHelperThreads = 16,
95 cCRNMinQualityLevel = 0,
96 cCRNMaxQualityLevel = 255
99 // CRN/DDS compression flags.
100 // See the m_flags member in the crn_comp_params struct, below.
101 enum crn_comp_flags {
102 // Enables perceptual colorspace distance metrics if set.
103 // Important: Be sure to disable this when compressing non-sRGB colorspace images, like normal maps!
105 cCRNCompFlagPerceptual = 1,
107 // Enables (up to) 8x8 macroblock usage if set. If disabled, only 4x4 blocks are allowed.
108 // Compression ratio will be lower when disabled, but may cut down on blocky artifacts because the process used to determine
109 // where large macroblocks can be used without artifacts isn't perfect.
111 cCRNCompFlagHierarchical = 2,
113 // cCRNCompFlagQuick disables several output file optimizations - intended for things like quicker previews.
115 cCRNCompFlagQuick = 4,
117 // DXT1: OK to use DXT1 alpha blocks for better quality or DXT1A transparency.
118 // DXT5: OK to use both DXT5 block types.
119 // Currently only used when writing to .DDS files, as .CRN uses only a subset of the possible DXTn block types.
121 cCRNCompFlagUseBothBlockTypes = 8,
123 // OK to use DXT1A transparent indices to encode black (assumes pixel shader ignores fetched alpha).
124 // Currently only used when writing to .DDS files, .CRN never uses alpha blocks.
126 cCRNCompFlagUseTransparentIndicesForBlack = 16,
128 // Disables endpoint caching, for more deterministic output.
129 // Currently only used when writing to .DDS files.
131 cCRNCompFlagDisableEndpointCaching = 32,
133 // If enabled, use the cCRNColorEndpointPaletteSize, etc. params to control the CRN palette sizes. Only useful when writing to .CRN files.
135 cCRNCompFlagManualPaletteSizes = 64,
137 // If enabled, DXT1A alpha blocks are used to encode single bit transparency.
139 cCRNCompFlagDXT1AForTransparency = 128,
141 // If enabled, the DXT1 compressor's color distance metric assumes the pixel shader will be converting the fetched RGB results to luma (Y part of YCbCr).
142 // This increases quality when compressing grayscale images, because the compressor can spread the luma error amoung all three channels (i.e. it can generate blocks
143 // with some chroma present if doing so will ultimately lead to lower luma error).
144 // Only enable on grayscale source images.
146 cCRNCompFlagGrayscaleSampling = 256,
148 // If enabled, debug information will be output during compression.
150 cCRNCompFlagDebugging = 0x80000000,
152 cCRNCompFlagForceDWORD = 0xFFFFFFFF
155 // Controls DXTn quality vs. speed control - only used when compressing to .DDS.
156 enum crn_dxt_quality {
157 cCRNDXTQualitySuperFast,
159 cCRNDXTQualityNormal,
160 cCRNDXTQualityBetter,
165 cCRNDXTQualityForceDWORD = 0xFFFFFFFF
168 // Which DXTn compressor to use when compressing to plain (non-clustered) .DDS.
169 enum crn_dxt_compressor_type {
170 cCRNDXTCompressorCRN, // Use crnlib's ETC1 or DXTc block compressor (default, highest quality, comparable or better than ati_compress or squish, and crnlib's ETC1 is a lot fasterw with similiar quality to Erricson's)
171 cCRNDXTCompressorCRNF, // Use crnlib's "fast" DXTc block compressor
172 cCRNDXTCompressorRYG, // Use RYG's DXTc block compressor (low quality, but very fast)
174 #if CRNLIB_SUPPORT_ATI_COMPRESS
175 cCRNDXTCompressorATI,
178 #if CRNLIB_SUPPORT_SQUISH
179 cCRNDXTCompressorSquish,
182 cCRNTotalDXTCompressors,
184 cCRNDXTCompressorForceDWORD = 0xFFFFFFFF
187 // Progress callback function.
188 // Processing will stop prematurely (and fail) if the callback returns false.
189 // phase_index, total_phases - high level progress
190 // subphase_index, total_subphases - progress within current phase
191 typedef crn_bool (*crn_progress_callback_func)(crn_uint32 phase_index, crn_uint32 total_phases, crn_uint32 subphase_index, crn_uint32 total_subphases, void* pUser_data_ptr);
193 // CRN/DDS compression parameters struct.
194 struct crn_comp_params {
195 inline crn_comp_params() { clear(); }
197 // Clear struct to default parameters.
198 inline void clear() {
199 m_size_of_obj = sizeof(*this);
200 m_file_type = cCRNFileTypeCRN;
205 m_format = cCRNFmtDXT1;
206 m_flags = cCRNCompFlagPerceptual | cCRNCompFlagHierarchical | cCRNCompFlagUseBothBlockTypes;
208 for (crn_uint32 f = 0; f < cCRNMaxFaces; f++)
209 for (crn_uint32 l = 0; l < cCRNMaxLevels; l++)
210 m_pImages[f][l] = NULL;
212 m_target_bitrate = 0.0f;
213 m_quality_level = cCRNMaxQualityLevel;
214 m_dxt1a_alpha_threshold = 128;
215 m_dxt_quality = cCRNDXTQualityUber;
216 m_dxt_compressor_type = cCRNDXTCompressorCRN;
217 m_alpha_component = 3;
219 m_crn_adaptive_tile_color_psnr_derating = 2.0f;
220 m_crn_adaptive_tile_alpha_psnr_derating = 2.0f;
221 m_crn_color_endpoint_palette_size = 0;
222 m_crn_color_selector_palette_size = 0;
223 m_crn_alpha_endpoint_palette_size = 0;
224 m_crn_alpha_selector_palette_size = 0;
226 m_num_helper_threads = 0;
229 m_pProgress_func = NULL;
230 m_pProgress_func_data = NULL;
233 inline bool operator==(const crn_comp_params& rhs) const {
234 #define CRNLIB_COMP(x) \
236 if ((x) != (rhs.x)) \
239 CRNLIB_COMP(m_size_of_obj);
240 CRNLIB_COMP(m_file_type);
241 CRNLIB_COMP(m_faces);
242 CRNLIB_COMP(m_width);
243 CRNLIB_COMP(m_height);
244 CRNLIB_COMP(m_levels);
245 CRNLIB_COMP(m_format);
246 CRNLIB_COMP(m_flags);
247 CRNLIB_COMP(m_target_bitrate);
248 CRNLIB_COMP(m_quality_level);
249 CRNLIB_COMP(m_dxt1a_alpha_threshold);
250 CRNLIB_COMP(m_dxt_quality);
251 CRNLIB_COMP(m_dxt_compressor_type);
252 CRNLIB_COMP(m_alpha_component);
253 CRNLIB_COMP(m_crn_adaptive_tile_color_psnr_derating);
254 CRNLIB_COMP(m_crn_adaptive_tile_alpha_psnr_derating);
255 CRNLIB_COMP(m_crn_color_endpoint_palette_size);
256 CRNLIB_COMP(m_crn_color_selector_palette_size);
257 CRNLIB_COMP(m_crn_alpha_endpoint_palette_size);
258 CRNLIB_COMP(m_crn_alpha_selector_palette_size);
259 CRNLIB_COMP(m_num_helper_threads);
260 CRNLIB_COMP(m_userdata0);
261 CRNLIB_COMP(m_userdata1);
262 CRNLIB_COMP(m_pProgress_func);
263 CRNLIB_COMP(m_pProgress_func_data);
265 for (crn_uint32 f = 0; f < cCRNMaxFaces; f++)
266 for (crn_uint32 l = 0; l < cCRNMaxLevels; l++)
267 CRNLIB_COMP(m_pImages[f][l]);
273 // Returns true if the input parameters are reasonable.
274 inline bool check() const {
275 if ((m_file_type > cCRNFileTypeDDS) ||
276 (((int)m_quality_level < (int)cCRNMinQualityLevel) || ((int)m_quality_level > (int)cCRNMaxQualityLevel)) ||
277 (m_dxt1a_alpha_threshold > 255) ||
278 ((m_faces != 1) && (m_faces != 6)) ||
279 ((m_width < 1) || (m_width > cCRNMaxLevelResolution)) ||
280 ((m_height < 1) || (m_height > cCRNMaxLevelResolution)) ||
281 ((m_levels < 1) || (m_levels > cCRNMaxLevels)) ||
282 ((m_format < cCRNFmtDXT1) || (m_format >= cCRNFmtTotal)) ||
283 ((m_crn_color_endpoint_palette_size) && ((m_crn_color_endpoint_palette_size < cCRNMinPaletteSize) || (m_crn_color_endpoint_palette_size > cCRNMaxPaletteSize))) ||
284 ((m_crn_color_selector_palette_size) && ((m_crn_color_selector_palette_size < cCRNMinPaletteSize) || (m_crn_color_selector_palette_size > cCRNMaxPaletteSize))) ||
285 ((m_crn_alpha_endpoint_palette_size) && ((m_crn_alpha_endpoint_palette_size < cCRNMinPaletteSize) || (m_crn_alpha_endpoint_palette_size > cCRNMaxPaletteSize))) ||
286 ((m_crn_alpha_selector_palette_size) && ((m_crn_alpha_selector_palette_size < cCRNMinPaletteSize) || (m_crn_alpha_selector_palette_size > cCRNMaxPaletteSize))) ||
287 (m_alpha_component > 3) ||
288 (m_num_helper_threads > cCRNMaxHelperThreads) ||
289 (m_dxt_quality > cCRNDXTQualityUber) ||
290 (m_dxt_compressor_type >= cCRNTotalDXTCompressors)) {
296 // Helper to set/get flags from m_flags member.
297 inline bool get_flag(crn_comp_flags flag) const { return (m_flags & flag) != 0; }
298 inline void set_flag(crn_comp_flags flag, bool val) {
304 crn_uint32 m_size_of_obj;
306 crn_file_type m_file_type; // Output file type: cCRNFileTypeCRN or cCRNFileTypeDDS.
308 crn_uint32 m_faces; // 1 (2D map) or 6 (cubemap)
309 crn_uint32 m_width; // [1,cCRNMaxLevelResolution], non-power of 2 OK, non-square OK
310 crn_uint32 m_height; // [1,cCRNMaxLevelResolution], non-power of 2 OK, non-square OK
311 crn_uint32 m_levels; // [1,cCRNMaxLevelResolution], non-power of 2 OK, non-square OK
313 crn_format m_format; // Output pixel format.
315 crn_uint32 m_flags; // see crn_comp_flags enum
317 // Array of pointers to 32bpp input images.
318 const crn_uint32* m_pImages[cCRNMaxFaces][cCRNMaxLevels];
320 // Target bitrate - if non-zero, the compressor will use an interpolative search to find the
321 // highest quality level that is <= the target bitrate. If it fails to find a bitrate high enough, it'll
322 // try disabling adaptive block sizes (cCRNCompFlagHierarchical flag) and redo the search. This process can be pretty slow.
323 float m_target_bitrate;
325 // Desired quality level.
326 // Currently, CRN and DDS quality levels are not compatible with eachother from an image quality standpoint.
327 crn_uint32 m_quality_level; // [cCRNMinQualityLevel, cCRNMaxQualityLevel]
329 // DXTn compression parameters.
330 crn_uint32 m_dxt1a_alpha_threshold;
331 crn_dxt_quality m_dxt_quality;
332 crn_dxt_compressor_type m_dxt_compressor_type;
334 // Alpha channel's component. Defaults to 3.
335 crn_uint32 m_alpha_component;
337 // Various low-level CRN specific parameters.
338 float m_crn_adaptive_tile_color_psnr_derating;
339 float m_crn_adaptive_tile_alpha_psnr_derating;
341 crn_uint32 m_crn_color_endpoint_palette_size; // [cCRNMinPaletteSize,cCRNMaxPaletteSize]
342 crn_uint32 m_crn_color_selector_palette_size; // [cCRNMinPaletteSize,cCRNMaxPaletteSize]
344 crn_uint32 m_crn_alpha_endpoint_palette_size; // [cCRNMinPaletteSize,cCRNMaxPaletteSize]
345 crn_uint32 m_crn_alpha_selector_palette_size; // [cCRNMinPaletteSize,cCRNMaxPaletteSize]
347 // Number of helper threads to create during compression. 0=no threading.
348 crn_uint32 m_num_helper_threads;
350 // CRN userdata0 and userdata1 members, which are written directly to the header of the output file.
351 crn_uint32 m_userdata0;
352 crn_uint32 m_userdata1;
354 // User provided progress callback.
355 crn_progress_callback_func m_pProgress_func;
356 void* m_pProgress_func_data;
359 // Mipmap generator's mode.
361 cCRNMipModeUseSourceOrGenerateMips, // Use source texture's mipmaps if it has any, otherwise generate new mipmaps
362 cCRNMipModeUseSourceMips, // Use source texture's mipmaps if it has any, otherwise the output has no mipmaps
363 cCRNMipModeGenerateMips, // Always generate new mipmaps
364 cCRNMipModeNoMips, // Output texture has no mipmaps
368 cCRNModeForceDWORD = 0xFFFFFFFF
371 const char* crn_get_mip_mode_desc(crn_mip_mode m);
372 const char* crn_get_mip_mode_name(crn_mip_mode m);
374 // Mipmap generator's filter kernel.
375 enum crn_mip_filter {
378 cCRNMipFilterLanczos4,
379 cCRNMipFilterMitchell,
380 cCRNMipFilterKaiser, // Kaiser=default mipmap filter
384 cCRNMipFilterForceDWORD = 0xFFFFFFFF
387 const char* crn_get_mip_filter_name(crn_mip_filter f);
389 // Mipmap generator's scale mode.
390 enum crn_scale_mode {
400 cCRNSMForceDWORD = 0xFFFFFFFF
403 const char* crn_get_scale_mode_desc(crn_scale_mode sm);
405 // Mipmap generator parameters.
406 struct crn_mipmap_params {
407 inline crn_mipmap_params() { clear(); }
409 inline void clear() {
410 m_size_of_obj = sizeof(*this);
411 m_mode = cCRNMipModeUseSourceOrGenerateMips;
412 m_filter = cCRNMipFilterKaiser;
413 m_gamma_filtering = true;
415 // Default "blurriness" factor of .9 actually sharpens the output a little.
417 m_renormalize = false;
420 m_max_levels = cCRNMaxLevels;
423 m_scale_mode = cCRNSMDisabled;
432 m_clamp_scale = false;
437 inline bool check() const { return true; }
439 inline bool operator==(const crn_mipmap_params& rhs) const {
440 #define CRNLIB_COMP(x) \
442 if ((x) != (rhs.x)) \
445 CRNLIB_COMP(m_size_of_obj);
447 CRNLIB_COMP(m_filter);
448 CRNLIB_COMP(m_gamma_filtering);
449 CRNLIB_COMP(m_gamma);
450 CRNLIB_COMP(m_blurriness);
451 CRNLIB_COMP(m_renormalize);
452 CRNLIB_COMP(m_rtopmip);
453 CRNLIB_COMP(m_tiled);
454 CRNLIB_COMP(m_max_levels);
455 CRNLIB_COMP(m_min_mip_size);
456 CRNLIB_COMP(m_scale_mode);
457 CRNLIB_COMP(m_scale_x);
458 CRNLIB_COMP(m_scale_y);
459 CRNLIB_COMP(m_window_left);
460 CRNLIB_COMP(m_window_top);
461 CRNLIB_COMP(m_window_right);
462 CRNLIB_COMP(m_window_bottom);
463 CRNLIB_COMP(m_clamp_scale);
464 CRNLIB_COMP(m_clamp_width);
465 CRNLIB_COMP(m_clamp_height);
469 crn_uint32 m_size_of_obj;
472 crn_mip_filter m_filter;
474 crn_bool m_gamma_filtering;
479 crn_uint32 m_max_levels;
480 crn_uint32 m_min_mip_size;
482 crn_bool m_renormalize;
486 crn_scale_mode m_scale_mode;
490 crn_uint32 m_window_left;
491 crn_uint32 m_window_top;
492 crn_uint32 m_window_right;
493 crn_uint32 m_window_bottom;
495 crn_bool m_clamp_scale;
496 crn_uint32 m_clamp_width;
497 crn_uint32 m_clamp_height;
500 // -------- High-level helper function definitions for CDN/DDS compression.
502 #ifndef CRNLIB_MIN_ALLOC_ALIGNMENT
503 #define CRNLIB_MIN_ALLOC_ALIGNMENT sizeof(size_t) * 2
506 // Function to set an optional user provided memory allocation/reallocation/msize routines.
507 // By default, crnlib just uses malloc(), free(), etc. for all allocations.
508 typedef void* (*crn_realloc_func)(void* p, size_t size, size_t* pActual_size, bool movable, void* pUser_data);
509 typedef size_t (*crn_msize_func)(void* p, void* pUser_data);
510 void crn_set_memory_callbacks(crn_realloc_func pRealloc, crn_msize_func pMSize, void* pUser_data);
512 // Frees memory blocks allocated by crn_compress(), crn_decompress_crn_to_dds(), or crn_decompress_dds_to_images().
513 void crn_free_block(void* pBlock);
515 // Compresses a 32-bit/pixel texture to either: a regular DX9 DDS file, a "clustered" (or reduced entropy) DX9 DDS file, or a CRN file in memory.
517 // comp_params is the compression parameters struct, defined above.
518 // compressed_size will be set to the size of the returned memory block containing the output file.
519 // The returned block must be freed by calling crn_free_block().
520 // *pActual_quality_level will be set to the actual quality level used to compress the image. May be NULL.
521 // *pActual_bitrate will be set to the output file's effective bitrate, possibly taking into account LZMA compression. May be NULL.
523 // The compressed file data, or NULL on failure.
524 // compressed_size will be set to the size of the returned memory buffer.
526 // A "regular" DDS file is compressed using normal DXTn compression at the specified DXT quality level.
527 // A "clustered" DDS file is compressed using clustered DXTn compression to either the target bitrate or the specified integer quality factor.
528 // The output file is a standard DX9 format DDS file, except the compressor assumes you will be later losslessly compressing the DDS output file using the LZMA algorithm.
529 // A texture is defined as an array of 1 or 6 "faces" (6 faces=cubemap), where each "face" consists of between [1,cCRNMaxLevels] mipmap levels.
530 // Mipmap levels are simple 32-bit 2D images with a pitch of width*sizeof(uint32), arranged in the usual raster order (top scanline first).
531 // The image pixels may be grayscale (YYYX bytes in memory), grayscale/alpha (YYYA in memory), 24-bit (RGBX in memory), or 32-bit (RGBA) colors (where "X"=don't care).
532 // RGB color data is generally assumed to be in the sRGB colorspace. If not, be sure to clear the "cCRNCompFlagPerceptual" in the crn_comp_params struct!
533 void* crn_compress(const crn_comp_params& comp_params, crn_uint32& compressed_size, crn_uint32* pActual_quality_level = NULL, float* pActual_bitrate = NULL);
535 // Like the above function, except this function can also do things like generate mipmaps, and resize or crop the input texture before compression.
536 // The actual operations performed are controlled by the crn_mipmap_params struct members.
537 // Be sure to set the "m_gamma_filtering" member of crn_mipmap_params to false if the input texture is not sRGB.
538 void* crn_compress(const crn_comp_params& comp_params, const crn_mipmap_params& mip_params, crn_uint32& compressed_size, crn_uint32* pActual_quality_level = NULL, float* pActual_bitrate = NULL);
540 // Transcodes an entire CRN file to DDS using the crn_decomp.h header file library to do most of the heavy lifting.
541 // The output DDS file's format is guaranteed to be one of the DXTn formats in the crn_format enum.
542 // This is a fast operation, because the CRN format is explicitly designed to be efficiently transcodable to DXTn.
543 // For more control over decompression, see the lower-level helper functions in crn_decomp.h, which do not depend at all on crnlib.
544 void* crn_decompress_crn_to_dds(const void* pCRN_file_data, crn_uint32& file_size);
546 // Decompresses an entire DDS file in any supported format to uncompressed 32-bit/pixel image(s).
547 // See the crnlib::pixel_format enum in inc/dds_defs.h for a list of the supported DDS formats.
548 // You are responsible for freeing each image block, either by calling crn_free_all_images() or manually calling crn_free_block() on each image pointer.
549 struct crn_texture_desc {
554 crn_uint32 m_fmt_fourcc; // Same as crnlib::pixel_format
556 bool crn_decompress_dds_to_images(const void* pDDS_file_data, crn_uint32 dds_file_size, crn_uint32** ppImages, crn_texture_desc& tex_desc);
558 // Frees all images allocated by crn_decompress_dds_to_images().
559 void crn_free_all_images(crn_uint32** ppImages, const crn_texture_desc& desc);
561 // -------- crn_format related helpers functions.
563 // Returns the FOURCC format equivalent to the specified crn_format.
564 crn_uint32 crn_get_format_fourcc(crn_format fmt);
566 // Returns the crn_format's bits per texel.
567 crn_uint32 crn_get_format_bits_per_texel(crn_format fmt);
569 // Returns the crn_format's number of bytes per block.
570 crn_uint32 crn_get_bytes_per_dxt_block(crn_format fmt);
572 // Returns the non-swizzled, basic DXTn version of the specified crn_format.
573 // This is the format you would supply D3D or OpenGL.
574 crn_format crn_get_fundamental_dxt_format(crn_format fmt);
576 // -------- String helpers.
578 // Converts a crn_file_type to a string.
579 const char* crn_get_file_type_ext(crn_file_type file_type);
581 // Converts a crn_format to a string.
582 const char* crn_get_format_string(crn_format fmt);
584 // Converts a crn_dxt_quality to a string.
585 const char* crn_get_dxt_quality_string(crn_dxt_quality q);
587 // -------- Low-level DXTn 4x4 block compressor API
589 // crnlib's DXTn endpoint optimizer actually supports any number of source pixels (i.e. from 1 to thousands, not just 16),
590 // but for simplicity this API only supports 4x4 texel blocks.
591 typedef void* crn_block_compressor_context_t;
593 // Create a DXTn block compressor.
594 // This function only supports the basic/nonswizzled "fundamental" formats: DXT1, DXT3, DXT5, DXT5A, DXN_XY and DXN_YX.
595 // Avoid calling this multiple times if you intend on compressing many blocks, because it allocates some memory.
596 crn_block_compressor_context_t crn_create_block_compressor(const crn_comp_params& params);
598 // Compresses a block of 16 pixels to the destination DXTn block.
599 // pDst_block should be 8 (for DXT1/DXT5A) or 16 bytes (all the others).
600 // pPixels should be an array of 16 crn_uint32's. Each crn_uint32 must be r,g,b,a (r is always first) in memory.
601 void crn_compress_block(crn_block_compressor_context_t pContext, const crn_uint32* pPixels, void* pDst_block);
603 // Frees a DXTn block compressor.
604 void crn_free_block_compressor(crn_block_compressor_context_t pContext);
606 // Unpacks a compressed block to pDst_pixels.
607 // pSrc_block should be 8 (for DXT1/DXT5A) or 16 bytes (all the others).
608 // pDst_pixel should be an array of 16 crn_uint32's. Each uint32 will be r,g,b,a (r is always first) in memory.
609 // crn_fmt should be one of the "fundamental" formats: DXT1, DXT3, DXT5, DXT5A, DXN_XY and DXN_YX.
610 // The various swizzled DXT5 formats (such as cCRNFmtDXT5_xGBR, etc.) will be unpacked as if they where plain DXT5.
611 // Returns false if the crn_fmt is invalid.
612 bool crn_decompress_block(const void* pSrc_block, crn_uint32* pDst_pixels, crn_format crn_fmt);
616 //------------------------------------------------------------------------------
618 // crnlib uses the ZLIB license:
619 // http://opensource.org/licenses/Zlib
621 // Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
623 // This software is provided 'as-is', without any express or implied
624 // warranty. In no event will the authors be held liable for any damages
625 // arising from the use of this software.
627 // Permission is granted to anyone to use this software for any purpose,
628 // including commercial applications, and to alter it and redistribute it
629 // freely, subject to the following restrictions:
631 // 1. The origin of this software must not be misrepresented; you must not
632 // claim that you wrote the original software. If you use this software
633 // in a product, an acknowledgment in the product documentation would be
634 // appreciated but is not required.
636 // 2. Altered source versions must be plainly marked as such, and must not be
637 // misrepresented as being the original software.
639 // 3. This notice may not be removed or altered from any source distribution.
641 //------------------------------------------------------------------------------