Debian Codegraph @

thirdparty/libktx/include/ktx.h

raw symbols SCIP
1 /* -*- tab-width: 4; -*- */
2 /* vi: set sw=2 ts=4 expandtab: */
3
4 #ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1
5 #define KTX_H_A55A6F00956F42F3A137C11929827FE1
6
7 /*
8 * Copyright 2010-2018 The Khronos Group, Inc.
9 * SPDX-License-Identifier: Apache-2.0
10 *
11 * See the accompanying LICENSE.md for licensing details for all files in
12 * the KTX library and KTX loader tests.
13 */
14
15 /**
16 * @file
17 * @~English
18 *
19 * @brief Declares the public functions and structures of the
20 * KTX API.
21 *
22 * @author Mark Callow, Edgewise Consulting and while at HI Corporation
23 * @author Based on original work by Georg Kolling, Imagination Technology
24 *
25 * @snippet{doc} version.h API version
26 */
27
28 #include <limits.h>
29 #include <stdio.h>
30 #include <stdbool.h>
31 #include <sys/types.h>
32
33 #include <KHR/khr_df.h>
34
35 /*
36 * Don't use khrplatform.h in order not to break apps existing
37 * before these definitions were needed.
38 */
39 #if defined(KHRONOS_STATIC)
40 #define KTX_API
41 #elif defined(_WIN32) || defined(__CYGWIN__)
42 #if !defined(KTX_API)
43 #if __GNUC__
44 #define KTX_API __attribute__ ((dllimport))
45 #elif _MSC_VER
46 #define KTX_API __declspec(dllimport)
47 #else
48 #error "Your compiler's equivalent of dllimport is unknown"
49 #endif
50 #endif
51 #elif defined(__ANDROID__)
52 #define KTX_API __attribute__((visibility("default")))
53 #else
54 #define KTX_API
55 #endif
56
57 #if defined(_WIN32) && !defined(KHRONOS_STATIC)
58 #if !defined(KTX_APIENTRY)
59 #define KTX_APIENTRY __stdcall
60 #endif
61 #else
62 #define KTX_APIENTRY
63 #endif
64
65 /* To avoid including <KHR/khrplatform.h> define our own types. */
66 typedef unsigned char ktx_uint8_t;
67 typedef bool ktx_bool_t;
68 #ifdef _MSC_VER
69 typedef unsigned __int16 ktx_uint16_t;
70 typedef signed __int16 ktx_int16_t;
71 typedef unsigned __int32 ktx_uint32_t;
72 typedef signed __int32 ktx_int32_t;
73 typedef size_t ktx_size_t;
74 typedef unsigned __int64 ktx_uint64_t;
75 typedef signed __int64 ktx_int64_t;
76 #else
77 #include <stdint.h>
78 typedef uint16_t ktx_uint16_t;
79 typedef int16_t ktx_int16_t;
80 typedef uint32_t ktx_uint32_t;
81 typedef int32_t ktx_int32_t;
82 typedef size_t ktx_size_t;
83 typedef uint64_t ktx_uint64_t;
84 typedef int64_t ktx_int64_t;
85 #endif
86
87 /* This will cause compilation to fail if size of uint32 != 4. */
88 typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4];
89
90 /*
91 * This #if allows libktx to be compiled with strict c99. It avoids
92 * compiler warnings or even errors when a gl.h is already included.
93 * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if
94 * gl.h comes after. However nobody has complained about the unguarded typedefs
95 * since they were introduced so this is unlikely to be a problem in practice.
96 * Presumably everybody is using platform default compilers not c99 or else
97 * they are using C++.
98 */
99 #if !defined(GL_NO_ERROR)
100 /*
101 * To avoid having to including gl.h ...
102 */
103 typedef unsigned char GLboolean;
104 typedef unsigned int GLenum;
105 typedef int GLint;
106 typedef int GLsizei;
107 typedef unsigned int GLuint;
108 typedef unsigned char GLubyte;
109 #endif
110
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114
115 /**
116 * @~English
117 * @brief Key string for standard writer metadata.
118 */
119 #define KTX_ANIMDATA_KEY "KTXanimData"
120 /**
121 * @~English
122 * @brief Key string for standard orientation metadata.
123 */
124 #define KTX_ORIENTATION_KEY "KTXorientation"
125 /**
126 * @~English
127 * @brief Key string for standard swizzle metadata.
128 */
129 #define KTX_SWIZZLE_KEY "KTXswizzle"
130 /**
131 * @~English
132 * @brief Key string for standard writer metadata.
133 */
134 #define KTX_WRITER_KEY "KTXwriter"
135 /**
136 * @~English
137 * @brief Key string for standard writer supercompression parameter metadata.
138 */
139 #define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams"
140 /**
141 * @~English
142 * @brief Standard KTX 1 format for 1D orientation value.
143 */
144 #define KTX_ORIENTATION1_FMT "S=%c"
145 /**
146 * @~English
147 * @brief Standard KTX 1 format for 2D orientation value.
148 */
149 #define KTX_ORIENTATION2_FMT "S=%c,T=%c"
150 /**
151 * @~English
152 * @brief Standard KTX 1 format for 3D orientation value.
153 */
154 #define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c"
155 /**
156 * @~English
157 * @brief Required unpack alignment
158 */
159 #define KTX_GL_UNPACK_ALIGNMENT 4
160 #define KTX_FACESLICE_WHOLE_LEVEL UINT_MAX
161
162 #define KTX_TRUE true
163 #define KTX_FALSE false
164
165 /**
166 * @~English
167 * @brief Error codes returned by library functions.
168 */
169 typedef enum ktx_error_code_e {
170 KTX_SUCCESS = 0, /*!< Operation was successful. */
171 KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */
172 KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */
173 KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */
174 KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */
175 KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */
176 KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */
177 KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */
178 KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */
179 KTX_GL_ERROR, /*!< GL operations resulted in an error. */
180 KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */
181 KTX_INVALID_VALUE, /*!< A parameter value was not valid. */
182 KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */
183 KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */
184 KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */
185 KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */
186 KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */
187 KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */
188 KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */
189 KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */
190 KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */
191 KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */
192 } ktx_error_code_e;
193 /**
194 * @~English
195 * @deprecated Use #ktx_error_code_e.
196 * @brief For backward compatibility
197 */
198 #define KTX_error_code ktx_error_code_e
199
200 #define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }
201 #define KTX_ENDIAN_REF (0x04030201)
202 #define KTX_ENDIAN_REF_REV (0x01020304)
203 #define KTX_HEADER_SIZE (64)
204
205 /**
206 * @~English
207 * @brief Result codes returned by library functions.
208 */
209 typedef enum ktx_error_code_e ktxResult;
210
211 /**
212 * @class ktxHashList
213 * @~English
214 * @brief Opaque handle to a ktxHashList.
215 */
216 typedef struct ktxKVListEntry* ktxHashList;
217
218 typedef struct ktxStream ktxStream;
219
220 #define KTX_APIENTRYP KTX_APIENTRY *
221 /**
222 * @class ktxHashListEntry
223 * @~English
224 * @brief Opaque handle to an entry in a @ref ktxHashList.
225 */
226 typedef struct ktxKVListEntry ktxHashListEntry;
227
228 typedef enum ktxOrientationX {
229 KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r'
230 } ktxOrientationX;
231
232 typedef enum ktxOrientationY {
233 KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd'
234 } ktxOrientationY;
235
236 typedef enum ktxOrientationZ {
237 KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o'
238 } ktxOrientationZ;
239
240 typedef enum class_id {
241 ktxTexture1_c = 1,
242 ktxTexture2_c = 2
243 } class_id;
244
245 /**
246 * @~English
247 * @brief Struct describing the logical orientation of an image.
248 */
249 struct ktxOrientation {
250 ktxOrientationX x; /*!< Orientation in X */
251 ktxOrientationY y; /*!< Orientation in Y */
252 ktxOrientationZ z; /*!< Orientation in Z */
253 };
254
255 #define KTXTEXTURECLASSDEFN \
256 class_id classId; \
257 struct ktxTexture_vtbl* vtbl; \
258 struct ktxTexture_vvtbl* vvtbl; \
259 struct ktxTexture_protected* _protected; \
260 ktx_bool_t isArray; \
261 ktx_bool_t isCubemap; \
262 ktx_bool_t isCompressed; \
263 ktx_bool_t generateMipmaps; \
264 ktx_uint32_t baseWidth; \
265 ktx_uint32_t baseHeight; \
266 ktx_uint32_t baseDepth; \
267 ktx_uint32_t numDimensions; \
268 ktx_uint32_t numLevels; \
269 ktx_uint32_t numLayers; \
270 ktx_uint32_t numFaces; \
271 struct ktxOrientation orientation; \
272 ktxHashList kvDataHead; \
273 ktx_uint32_t kvDataLen; \
274 ktx_uint8_t* kvData; \
275 ktx_size_t dataSize; \
276 ktx_uint8_t* pData;
277
278
279 /**
280 * @class ktxTexture
281 * @~English
282 * @brief Base class representing a texture.
283 *
284 * ktxTextures should be created only by one of the provided
285 * functions and these fields should be considered read-only.
286 */
287 typedef struct ktxTexture {
288 KTXTEXTURECLASSDEFN
289 } ktxTexture;
290 /**
291 * @typedef ktxTexture::classId
292 * @~English
293 * @brief Identify the class type.
294 *
295 * Since there are no public ktxTexture constructors, this can only have
296 * values of ktxTexture1_c or ktxTexture2_c.
297 */
298 /**
299 * @typedef ktxTexture::vtbl
300 * @~English
301 * @brief Pointer to the class's vtble.
302 */
303 /**
304 * @typedef ktxTexture::vvtbl
305 * @~English
306 * @brief Pointer to the class's vtble for Vulkan functions.
307 *
308 * A separate vtble is used so this header does not need to include vulkan.h.
309 */
310 /**
311 * @typedef ktxTexture::_protected
312 * @~English
313 * @brief Opaque pointer to the class's protected variables.
314 */
315 /**
316 * @typedef ktxTexture::isArray
317 * @~English
318 *
319 * KTX_TRUE if the texture is an array texture, i.e,
320 * a GL_TEXTURE_*_ARRAY target is to be used.
321 */
322 /**
323 * @typedef ktxTexture::isCubemap
324 * @~English
325 *
326 * KTX_TRUE if the texture is a cubemap or cubemap array.
327 */
328 /**
329 * @typedef ktxTexture::isCompressed
330 * @~English
331 *
332 * KTX_TRUE if the texture's format is a block compressed format.
333 */
334 /**
335 * @typedef ktxTexture::generateMipmaps
336 * @~English
337 *
338 * KTX_TRUE if mipmaps should be generated for the texture by
339 * ktxTexture_GLUpload() or ktxTexture_VkUpload().
340 */
341 /**
342 * @typedef ktxTexture::baseWidth
343 * @~English
344 * @brief Width of the texture's base level.
345 */
346 /**
347 * @typedef ktxTexture::baseHeight
348 * @~English
349 * @brief Height of the texture's base level.
350 */
351 /**
352 * @typedef ktxTexture::baseDepth
353 * @~English
354 * @brief Depth of the texture's base level.
355 */
356 /**
357 * @typedef ktxTexture::numDimensions
358 * @~English
359 * @brief Number of dimensions in the texture: 1, 2 or 3.
360 */
361 /**
362 * @typedef ktxTexture::numLevels
363 * @~English
364 * @brief Number of mip levels in the texture.
365 *
366 * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a
367 * full pyramid but always starts at the base level.
368 */
369 /**
370 * @typedef ktxTexture::numLevels
371 * @~English
372 * @brief Number of array layers in the texture.
373 */
374 /**
375 * @typedef ktxTexture::numFaces
376 * @~English
377 * @brief Number of faces: 6 for cube maps, 1 otherwise.
378 */
379 /**
380 * @typedef ktxTexture::orientation
381 * @~English
382 * @brief Describes the logical orientation of the images in each dimension.
383 *
384 * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z.
385 */
386 /**
387 * @typedef ktxTexture::kvDataHead
388 * @~English
389 * @brief Head of the hash list of metadata.
390 */
391 /**
392 * @typedef ktxTexture::kvDataLen
393 * @~English
394 * @brief Length of the metadata, if it has been extracted in its raw form,
395 * otherwise 0.
396 */
397 /**
398 * @typedef ktxTexture::kvData
399 * @~English
400 * @brief Pointer to the metadata, if it has been extracted in its raw form,
401 * otherwise NULL.
402 */
403 /**
404 * @typedef ktxTexture::dataSize
405 * @~English
406 * @brief Byte length of the texture's uncompressed image data.
407 */
408 /**
409 * @typedef ktxTexture::pData
410 * @~English
411 * @brief Pointer to the start of the image data.
412 */
413
414 /**
415 * @memberof ktxTexture
416 * @~English
417 * @brief Signature of function called by the <tt>ktxTexture_Iterate*</tt>
418 * functions to receive image data.
419 *
420 * The function parameters are used to pass values which change for each image.
421 * Obtain values which are uniform across all images from the @c ktxTexture
422 * object.
423 *
424 * @param [in] miplevel MIP level from 0 to the max level which is
425 * dependent on the texture size.
426 * @param [in] face usually 0; for cube maps, one of the 6 cube
427 * faces in the order +X, -X, +Y, -Y, +Z, -Z,
428 * 0 to 5.
429 * @param [in] width width of the image.
430 * @param [in] height height of the image or, for 1D textures
431 * textures, 1.
432 * @param [in] depth depth of the image or, for 1D & 2D
433 * textures, 1.
434 * @param [in] faceLodSize number of bytes of data pointed at by
435 * @p pixels.
436 * @param [in] pixels pointer to the image data.
437 * @param [in,out] userdata pointer for the application to pass data to and
438 * from the callback function.
439 */
440
441 typedef KTX_error_code
442 (* PFNKTXITERCB)(int miplevel, int face,
443 int width, int height, int depth,
444 ktx_uint64_t faceLodSize,
445 void* pixels, void* userdata);
446
447 /* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */
448 typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This);
449 typedef KTX_error_code
450 (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level,
451 ktx_uint32_t layer,
452 ktx_uint32_t faceSlice,
453 ktx_size_t* pOffset);
454 typedef ktx_size_t
455 (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This);
456 typedef ktx_size_t
457 (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level);
458 typedef ktx_size_t
459 (KTX_APIENTRY* PFNKTEXGETLEVELSIZE)(ktxTexture* This, ktx_uint32_t level);
460 typedef KTX_error_code
461 (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb,
462 void* userdata);
463
464 typedef KTX_error_code
465 (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This,
466 PFNKTXITERCB iterCb,
467 void* userdata);
468 typedef KTX_error_code
469 (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This,
470 ktx_uint8_t* pBuffer,
471 ktx_size_t bufSize);
472 typedef ktx_bool_t
473 (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This);
474
475 typedef KTX_error_code
476 (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This,
477 ktx_uint32_t level,
478 ktx_uint32_t layer,
479 ktx_uint32_t faceSlice,
480 const ktx_uint8_t* src,
481 ktx_size_t srcSize);
482
483 typedef KTX_error_code
484 (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This,
485 ktx_uint32_t level,
486 ktx_uint32_t layer,
487 ktx_uint32_t faceSlice,
488 FILE* src, ktx_size_t srcSize);
489 typedef KTX_error_code
490 (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr);
491 typedef KTX_error_code
492 (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This,
493 const char* const dstname);
494 typedef KTX_error_code
495 (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This,
496 ktx_uint8_t** bytes, ktx_size_t* size);
497 typedef KTX_error_code
498 (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This,
499 ktxStream* dststr);
500
501 /**
502 * @memberof ktxTexture
503 * @~English
504 * @brief Table of virtual ktxTexture methods.
505 */
506 struct ktxTexture_vtbl {
507 PFNKTEXDESTROY Destroy;
508 PFNKTEXGETIMAGEOFFSET GetImageOffset;
509 PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed;
510 PFNKTEXGETIMAGESIZE GetImageSize;
511 PFNKTEXGETLEVELSIZE GetLevelSize;
512 PFNKTEXITERATELEVELS IterateLevels;
513 PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces;
514 PFNKTEXNEEDSTRANSCODING NeedsTranscoding;
515 PFNKTEXLOADIMAGEDATA LoadImageData;
516 PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory;
517 PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream;
518 PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream;
519 PFNKTEXWRITETONAMEDFILE WriteToNamedFile;
520 PFNKTEXWRITETOMEMORY WriteToMemory;
521 PFNKTEXWRITETOSTREAM WriteToStream;
522 };
523
524 /****************************************************************
525 * Macros to give some backward compatibility to the previous API
526 ****************************************************************/
527
528 /**
529 * @~English
530 * @brief Helper for calling the Destroy virtual method of a ktxTexture.
531 * @copydoc ktxTexture2.ktxTexture2_Destroy
532 */
533 #define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This)
534
535 /**
536 * @~English
537 * @brief Helper for calling the GetImageOffset virtual method of a
538 * ktxTexture.
539 * @copydoc ktxTexture2.ktxTexture2_GetImageOffset
540 */
541 #define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \
542 (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset)
543
544 /**
545 * @~English
546 * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture.
547 *
548 * For a ktxTexture1 this will always return the value of This->dataSize.
549 *
550 * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed
551 */
552 #define ktxTexture_GetDataSizeUncompressed(This) \
553 (This)->vtbl->GetDataSizeUncompressed(This)
554
555 /**
556 * @~English
557 * @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
558 * @copydoc ktxTexture2.ktxTexture2_GetImageSize
559 */
560 #define ktxTexture_GetImageSize(This, level) \
561 (This)->vtbl->GetImageSize(This, level)
562
563 /**
564 * @~English
565 * @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
566 * @copydoc ktxTexture2.ktxTexture2_GetImageSize
567 */
568 #define ktxTexture_GetLevelSize(This, level) \
569 (This)->vtbl->GetLevelSize(This, level)
570
571 /**
572 * @~English
573 * @brief Helper for calling the IterateLevels virtual method of a ktxTexture.
574 * @copydoc ktxTexture2.ktxTexture2_IterateLevels
575 */
576 #define ktxTexture_IterateLevels(This, iterCb, userdata) \
577 (This)->vtbl->IterateLevels(This, iterCb, userdata)
578
579 /**
580 * @~English
581 * @brief Helper for calling the IterateLoadLevelFaces virtual method of a
582 * ktxTexture.
583 * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces
584 */
585 #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \
586 (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata)
587
588 /**
589 * @~English
590 * @brief Helper for calling the LoadImageData virtual method of a ktxTexture.
591 * @copydoc ktxTexture2.ktxTexture2_LoadImageData
592 */
593 #define ktxTexture_LoadImageData(This, pBuffer, bufSize) \
594 (This)->vtbl->LoadImageData(This, pBuffer, bufSize)
595
596 /**
597 * @~English
598 * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture.
599 * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding
600 */
601 #define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This)
602
603 /**
604 * @~English
605 * @brief Helper for calling the SetImageFromMemory virtual method of a
606 * ktxTexture.
607 * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory
608 */
609 #define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \
610 src, srcSize) \
611 (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize)
612
613 /**
614 * @~English
615 * @brief Helper for calling the SetImageFromStdioStream virtual method of a
616 * ktxTexture.
617 * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream
618 */
619 #define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \
620 src, srcSize) \
621 (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \
622 src, srcSize)
623
624 /**
625 * @~English
626 * @brief Helper for calling the WriteToStdioStream virtual method of a
627 * ktxTexture.
628 * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream
629 */
630 #define ktxTexture_WriteToStdioStream(This, dstsstr) \
631 (This)->vtbl->WriteToStdioStream(This, dstsstr)
632
633 /**
634 * @~English
635 * @brief Helper for calling the WriteToNamedfile virtual method of a
636 * ktxTexture.
637 * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile
638 */
639 #define ktxTexture_WriteToNamedFile(This, dstname) \
640 (This)->vtbl->WriteToNamedFile(This, dstname)
641
642 /**
643 * @~English
644 * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture.
645 * @copydoc ktxTexture2.ktxTexture2_WriteToMemory
646 */
647 #define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \
648 (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize)
649
650 /**
651 * @~English
652 * @brief Helper for calling the WriteToStream virtual method of a ktxTexture.
653 * @copydoc ktxTexture2.ktxTexture2_WriteToStream
654 */
655 #define ktxTexture_WriteToStream(This, dststr) \
656 (This)->vtbl->WriteToStream(This, dststr)
657
658
659 /**
660 * @class ktxTexture1
661 * @~English
662 * @brief Class representing a KTX version 1 format texture.
663 *
664 * ktxTextures should be created only by one of the ktxTexture_Create*
665 * functions and these fields should be considered read-only.
666 */
667 typedef struct ktxTexture1 {
668 KTXTEXTURECLASSDEFN
669 ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */
670 ktx_uint32_t glInternalformat; /*!< Internal format of the texture data,
671 e.g., GL_RGB8. */
672 ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data,
673 e.g., GL_RGB. */
674 ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/
675 struct ktxTexture1_private* _private; /*!< Private data. */
676 } ktxTexture1;
677
678 /*===========================================================*
679 * KTX format version 2 *
680 *===========================================================*/
681
682 /**
683 * @~English
684 * @brief Enumerators identifying the supercompression scheme.
685 */
686 typedef enum ktxSupercmpScheme {
687 KTX_SS_NONE = 0, /*!< No supercompression. */
688 KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */
689 KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */
690 KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */
691 KTX_SS_BEGIN_RANGE = KTX_SS_NONE,
692 KTX_SS_END_RANGE = KTX_SS_ZLIB,
693 KTX_SS_BEGIN_VENDOR_RANGE = 0x10000,
694 KTX_SS_END_VENDOR_RANGE = 0x1ffff,
695 KTX_SS_BEGIN_RESERVED = 0x20000
696 } ktxSupercmpScheme;
697
698 /**
699 * @class ktxTexture2
700 * @~English
701 * @brief Class representing a KTX version 2 format texture.
702 *
703 * ktxTextures should be created only by one of the ktxTexture_Create*
704 * functions and these fields should be considered read-only.
705 */
706 typedef struct ktxTexture2 {
707 KTXTEXTURECLASSDEFN
708 ktx_uint32_t vkFormat;
709 ktx_uint32_t* pDfd;
710 ktxSupercmpScheme supercompressionScheme;
711 ktx_bool_t isVideo;
712 ktx_uint32_t duration;
713 ktx_uint32_t timescale;
714 ktx_uint32_t loopcount;
715 struct ktxTexture2_private* _private; /*!< Private data. */
716 } ktxTexture2;
717
718 /*
719 * If Doxygen sees this macro it gets confused and fails to spot
720 * references to ktxTexture_*() functions in the running text. It
721 * also complains it can't find the reference when @ref is used
722 * with a fully qualified method name to make an intra-class
723 * reference in the @c ktxTexture class.
724 * See https://github.com/doxygen/doxygen/issues/10311.
725 *
726 * Not documenting the macro is the lesser of two evils.
727 */
728 #if !defined(KTX_DOXYGEN_SKIP)
729 /**
730 * @brief Helper for casting ktxTexture1 and ktxTexture2 to ktxTexture.
731 *
732 * Use with caution.
733 */
734 #define ktxTexture(t) ((ktxTexture*)t)
735 #endif
736
737 /**
738 * @memberof ktxTexture
739 * @~English
740 * @brief Structure for passing texture information to ktxTexture1\_Create() and
741 * ktxTexture2\_Create().
742 *
743 * @sa @ref ktxTexture1::ktxTexture1\_Create() "ktxTexture1_Create()"
744 * @sa @ref ktxTexture2::ktxTexture2\_Create() "ktxTexture2_Create()"
745 */
746 typedef struct
747 {
748 ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g.,
749 GL_RGB8. Ignored when creating a
750 ktxTexture2. */
751 ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a
752 ktxTexture1. */
753 ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a
754 ktxTexture2 and only if vkFormat is
755 VK_FORMAT_UNDEFINED. */
756 ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */
757 ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */
758 ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */
759 ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2
760 or 3. */
761 ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be
762 1 if @c generateMipmaps is KTX_TRUE; */
763 ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */
764 ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */
765 ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an
766 array texture. Means OpenGL will use a
767 GL_TEXTURE_*_ARRAY target. */
768 ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be
769 generated for the texture when loading
770 into a 3D API. */
771 } ktxTextureCreateInfo;
772
773 /**
774 * @memberof ktxTexture
775 * @~English
776 * @brief Enum for requesting, or not, allocation of storage for images.
777 *
778 * @sa ktxTexture1_Create() and ktxTexture2_Create().
779 */
780 typedef enum {
781 KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */
782 KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */
783 } ktxTextureCreateStorageEnum;
784
785 /**
786 * @memberof ktxTexture
787 * @~English
788 * @brief Flags for requesting services during creation.
789 *
790 * @sa ktxTexture_CreateFrom*
791 */
792 enum ktxTextureCreateFlagBits {
793 KTX_TEXTURE_CREATE_NO_FLAGS = 0x00,
794 KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01,
795 /*!< Load the images from the KTX source. */
796 KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02,
797 /*!< Load the raw key-value data instead of
798 creating a @c ktxHashList from it. */
799 KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04,
800 /*!< Skip any key-value data. This overrides
801 the RAW_KVDATA_BIT. */
802 KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08
803 /*!< Load texture compatible with the rules
804 of KHR_texture_basisu glTF extension */
805 };
806 /**
807 * @memberof ktxTexture
808 * @~English
809 * @brief Type for TextureCreateFlags parameters.
810 *
811 * @sa ktxTexture_CreateFrom*()
812 */
813 typedef ktx_uint32_t ktxTextureCreateFlags;
814
815 /*===========================================================*
816 * ktxStream
817 *===========================================================*/
818
819 /*
820 * This is unsigned to allow ktxmemstreams to use the
821 * full amount of memory available. Platforms will
822 * limit the size of ktxfilestreams to, e.g, MAX_LONG
823 * on 32-bit and ktxfilestreams raises errors if
824 * offset values exceed the limits. This choice may
825 * need to be revisited if we ever start needing -ve
826 * offsets.
827 *
828 * Should the 2GB file size handling limit on 32-bit
829 * platforms become a problem, ktxfilestream will have
830 * to be changed to explicitly handle large files by
831 * using the 64-bit stream functions.
832 */
833 #if defined(_MSC_VER) && defined(_WIN64)
834 typedef unsigned __int64 ktx_off_t;
835 #else
836 typedef off_t ktx_off_t;
837 #endif
838 typedef struct ktxMem ktxMem;
839 typedef struct ktxStream ktxStream;
840
841 enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 };
842
843 /**
844 * @~English
845 * @brief type for a pointer to a stream reading function
846 */
847 typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst,
848 const ktx_size_t count);
849 /**
850 * @~English
851 * @brief type for a pointer to a stream skipping function
852 */
853 typedef KTX_error_code (*ktxStream_skip)(ktxStream* str,
854 const ktx_size_t count);
855
856 /**
857 * @~English
858 * @brief type for a pointer to a stream writing function
859 */
860 typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src,
861 const ktx_size_t size,
862 const ktx_size_t count);
863
864 /**
865 * @~English
866 * @brief type for a pointer to a stream position query function
867 */
868 typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset);
869
870 /**
871 * @~English
872 * @brief type for a pointer to a stream position query function
873 */
874 typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset);
875
876 /**
877 * @~English
878 * @brief type for a pointer to a stream size query function
879 */
880 typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size);
881
882 /**
883 * @~English
884 * @brief Destruct a stream
885 */
886 typedef void (*ktxStream_destruct)(ktxStream* str);
887
888 /**
889 * @~English
890 *
891 * @brief Interface of ktxStream.
892 *
893 * @author Maksim Kolesin
894 * @author Georg Kolling, Imagination Technology
895 * @author Mark Callow, HI Corporation
896 */
897 struct ktxStream
898 {
899 ktxStream_read read; /*!< pointer to function for reading bytes. */
900 ktxStream_skip skip; /*!< pointer to function for skipping bytes. */
901 ktxStream_write write; /*!< pointer to function for writing bytes. */
902 ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */
903 ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */
904 ktxStream_getsize getsize; /*!< pointer to function for querying size. */
905 ktxStream_destruct destruct; /*!< destruct the stream. */
906
907 enum streamType type;
908 union {
909 FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */
910 ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */
911 struct
912 {
913 void* address; /**< pointer to the data. */
914 void* allocatorAddress; /**< pointer to a memory allocator. */
915 ktx_size_t size; /**< size of the data. */
916 } custom_ptr; /**< pointer to a struct for custom streams. */
917 } data; /**< pointer to the stream data. */
918 ktx_off_t readpos; /**< used by FileStream for stdin. */
919 ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */
920 };
921
922 /*
923 * See the implementation files for the full documentation of the following
924 * functions.
925 */
926
927 /**
928 * @~English
929 * @brief typedef of function pointer returned by GLGetProcAddress functions.
930 */
931 typedef void (KTX_APIENTRY* PFNVOIDFUNCTION)(void);
932 /**
933 * @~English
934 * @brief typedef of pointer to function for retrieving OpenGL function pointers.
935 */
936 typedef PFNVOIDFUNCTION (KTX_APIENTRY* PFNGLGETPROCADDRESS) (const char *proc);
937 /*
938 * Load pointers for the OpenGL functions needed by ktxTexture_GLUpload.
939 */
940 KTX_API KTX_error_code KTX_APIENTRY
941 ktxLoadOpenGL(PFNGLGETPROCADDRESS pfnGLGetProcAddress);
942
943 /*
944 * These four create a ktxTexture1 or ktxTexture2 according to the data
945 * header, and return a pointer to the base ktxTexture class.
946 */
947 KTX_API KTX_error_code KTX_APIENTRY
948 ktxTexture_CreateFromStdioStream(FILE* stdioStream,
949 ktxTextureCreateFlags createFlags,
950 ktxTexture** newTex);
951
952 KTX_API KTX_error_code KTX_APIENTRY
953 ktxTexture_CreateFromNamedFile(const char* const filename,
954 ktxTextureCreateFlags createFlags,
955 ktxTexture** newTex);
956
957 KTX_API KTX_error_code KTX_APIENTRY
958 ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
959 ktxTextureCreateFlags createFlags,
960 ktxTexture** newTex);
961
962 KTX_API KTX_error_code KTX_APIENTRY
963 ktxTexture_CreateFromStream(ktxStream* stream,
964 ktxTextureCreateFlags createFlags,
965 ktxTexture** newTex);
966
967 /*
968 * Returns a pointer to the image data of a ktxTexture object.
969 */
970 KTX_API ktx_uint8_t* KTX_APIENTRY
971 ktxTexture_GetData(ktxTexture* This);
972
973 /*
974 * Returns the pitch of a row of an image at the specified level.
975 * Similar to the rowPitch in a VkSubResourceLayout.
976 */
977 KTX_API ktx_uint32_t KTX_APIENTRY
978 ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level);
979
980 /*
981 * Return the element size of the texture's images.
982 */
983 KTX_API ktx_uint32_t KTX_APIENTRY
984 ktxTexture_GetElementSize(ktxTexture* This);
985
986 /*
987 * Returns the size of all the image data of a ktxTexture object in bytes.
988 */
989 KTX_API ktx_size_t KTX_APIENTRY
990 ktxTexture_GetDataSize(ktxTexture* This);
991
992 /* Uploads a texture to OpenGL {,ES}. */
993 KTX_API KTX_error_code KTX_APIENTRY
994 ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget,
995 GLenum* pGlerror);
996
997 /*
998 * Iterate over the levels or faces in a ktxTexture object.
999 */
1000 KTX_API KTX_error_code KTX_APIENTRY
1001 ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb,
1002 void* userdata);
1003 /*
1004 * Create a new ktxTexture1.
1005 */
1006 KTX_API KTX_error_code KTX_APIENTRY
1007 ktxTexture1_Create(const ktxTextureCreateInfo* const createInfo,
1008 ktxTextureCreateStorageEnum storageAllocation,
1009 ktxTexture1** newTex);
1010
1011 /*
1012 * These four create a ktxTexture1 provided the data is in KTX format.
1013 */
1014 KTX_API KTX_error_code KTX_APIENTRY
1015 ktxTexture1_CreateFromStdioStream(FILE* stdioStream,
1016 ktxTextureCreateFlags createFlags,
1017 ktxTexture1** newTex);
1018
1019 KTX_API KTX_error_code KTX_APIENTRY
1020 ktxTexture1_CreateFromNamedFile(const char* const filename,
1021 ktxTextureCreateFlags createFlags,
1022 ktxTexture1** newTex);
1023
1024 KTX_API KTX_error_code KTX_APIENTRY
1025 ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
1026 ktxTextureCreateFlags createFlags,
1027 ktxTexture1** newTex);
1028
1029 KTX_API KTX_error_code KTX_APIENTRY
1030 ktxTexture1_CreateFromStream(ktxStream* stream,
1031 ktxTextureCreateFlags createFlags,
1032 ktxTexture1** newTex);
1033 KTX_API void KTX_APIENTRY
1034 ktxTexture1_Destroy(ktxTexture1* This);
1035
1036 KTX_API ktx_bool_t KTX_APIENTRY
1037 ktxTexture1_NeedsTranscoding(ktxTexture1* This);
1038
1039 KTX_API ktx_error_code_e KTX_APIENTRY
1040 ktxTexture1_LoadImageData(ktxTexture1* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1041
1042 /*
1043 * These four write a ktxTexture1 object to a KTX v1 file.
1044 */
1045 KTX_API KTX_error_code KTX_APIENTRY
1046 ktxTexture1_WriteToStdioStream(ktxTexture1* This, FILE* dstsstr);
1047
1048 KTX_API KTX_error_code KTX_APIENTRY
1049 ktxTexture1_WriteToNamedFile(ktxTexture1* This, const char* const dstname);
1050
1051 KTX_API KTX_error_code KTX_APIENTRY
1052 ktxTexture1_WriteToMemory(ktxTexture1* This,
1053 ktx_uint8_t** bytes, ktx_size_t* size);
1054
1055 KTX_API KTX_error_code KTX_APIENTRY
1056 ktxTexture1_WriteToStream(ktxTexture1* This, ktxStream *dststr);
1057
1058 /*
1059 * These four write a ktxTexture1 object to a KTX v2 file.
1060 */
1061 KTX_API KTX_error_code KTX_APIENTRY
1062 ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr);
1063
1064 KTX_API KTX_error_code KTX_APIENTRY
1065 ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname);
1066
1067 KTX_API KTX_error_code KTX_APIENTRY
1068 ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This,
1069 ktx_uint8_t** bytes, ktx_size_t* size);
1070
1071 KTX_API KTX_error_code KTX_APIENTRY
1072 ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr);
1073
1074 /*
1075 * Create a new ktxTexture2.
1076 */
1077 KTX_API KTX_error_code KTX_APIENTRY
1078 ktxTexture2_Create(const ktxTextureCreateInfo* const createInfo,
1079 ktxTextureCreateStorageEnum storageAllocation,
1080 ktxTexture2** newTex);
1081
1082 /*
1083 * Create a new ktxTexture2 as a copy of an existing texture.
1084 */
1085 KTX_API KTX_error_code KTX_APIENTRY
1086 ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex);
1087
1088 /*
1089 * These four create a ktxTexture2 provided the data is in KTX2 format.
1090 */
1091 KTX_API KTX_error_code KTX_APIENTRY
1092 ktxTexture2_CreateFromStdioStream(FILE* stdioStream,
1093 ktxTextureCreateFlags createFlags,
1094 ktxTexture2** newTex);
1095
1096 KTX_API KTX_error_code KTX_APIENTRY
1097 ktxTexture2_CreateFromNamedFile(const char* const filename,
1098 ktxTextureCreateFlags createFlags,
1099 ktxTexture2** newTex);
1100
1101 KTX_API KTX_error_code KTX_APIENTRY
1102 ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
1103 ktxTextureCreateFlags createFlags,
1104 ktxTexture2** newTex);
1105
1106 KTX_API KTX_error_code KTX_APIENTRY
1107 ktxTexture2_CreateFromStream(ktxStream* stream,
1108 ktxTextureCreateFlags createFlags,
1109 ktxTexture2** newTex);
1110
1111 KTX_API void KTX_APIENTRY
1112 ktxTexture2_Destroy(ktxTexture2* This);
1113
1114 KTX_API KTX_error_code KTX_APIENTRY
1115 ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality);
1116
1117 KTX_API KTX_error_code KTX_APIENTRY
1118 ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level);
1119
1120 KTX_API KTX_error_code KTX_APIENTRY
1121 ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level);
1122
1123 KTX_API void KTX_APIENTRY
1124 ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents,
1125 ktx_uint32_t* componentByteLength);
1126
1127 KTX_API KTX_error_code KTX_APIENTRY
1128 ktxTexture2_GetImageOffset(ktxTexture2* This, ktx_uint32_t level,
1129 ktx_uint32_t layer, ktx_uint32_t faceSlice,
1130 ktx_size_t* pOffset);
1131
1132 KTX_API ktx_uint32_t KTX_APIENTRY
1133 ktxTexture2_GetNumComponents(ktxTexture2* This);
1134
1135 KTX_API khr_df_transfer_e KTX_APIENTRY
1136 ktxTexture2_GetTransferFunction_e(ktxTexture2* This);
1137 /* For backward compatibility. */
1138 KTX_API khr_df_transfer_e KTX_APIENTRY
1139 ktxTexture2_GetOETF_e(ktxTexture2* This);
1140 KTX_API ktx_uint32_t KTX_APIENTRY
1141 ktxTexture2_GetOETF(ktxTexture2* This);
1142
1143 KTX_API khr_df_model_e KTX_APIENTRY
1144 ktxTexture2_GetColorModel_e(ktxTexture2* This);
1145
1146 KTX_API ktx_bool_t KTX_APIENTRY
1147 ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This);
1148
1149 KTX_API khr_df_primaries_e KTX_APIENTRY
1150 ktxTexture2_GetPrimaries_e(ktxTexture2* This);
1151
1152 KTX_API ktx_bool_t KTX_APIENTRY
1153 ktxTexture2_NeedsTranscoding(ktxTexture2* This);
1154
1155 KTX_API ktx_error_code_e KTX_APIENTRY
1156 ktxTexture2_SetTransferFunction(ktxTexture2* This, khr_df_transfer_e tf);
1157 /* For backward compatibility. */
1158 KTX_API ktx_error_code_e KTX_APIENTRY
1159 ktxTexture2_SetOETF(ktxTexture2* This, khr_df_transfer_e oetf);
1160
1161 KTX_API ktx_error_code_e KTX_APIENTRY
1162 ktxTexture2_SetPrimaries(ktxTexture2* This, khr_df_primaries_e primaries);
1163
1164 KTX_API ktx_error_code_e KTX_APIENTRY
1165 ktxTexture2_LoadImageData(ktxTexture2* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1166 /*
1167 * For rare testing scenarios. Use ktxTexture2_LoadImageData.
1168 */
1169 KTX_API ktx_error_code_e KTX_APIENTRY
1170 ktxTexture2_LoadDeflatedImageData(ktxTexture2* This,
1171 ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1172
1173 /*
1174 * These four write a ktxTexture2 object to a KTX v2 file.
1175 */
1176 KTX_API KTX_error_code KTX_APIENTRY
1177 ktxTexture2_WriteToStdioStream(ktxTexture2* This, FILE* dstsstr);
1178
1179 KTX_API KTX_error_code KTX_APIENTRY
1180 ktxTexture2_WriteToNamedFile(ktxTexture2* This, const char* const dstname);
1181
1182 KTX_API KTX_error_code KTX_APIENTRY
1183 ktxTexture2_WriteToMemory(ktxTexture2* This,
1184 ktx_uint8_t** bytes, ktx_size_t* size);
1185
1186 KTX_API KTX_error_code KTX_APIENTRY
1187 ktxTexture2_WriteToStream(ktxTexture2* This, ktxStream *dststr);
1188
1189 /**
1190 * @~English
1191 * @brief Flags specifiying UASTC encoding options.
1192 */
1193 typedef enum ktx_pack_uastc_flag_bits_e {
1194 KTX_PACK_UASTC_LEVEL_FASTEST = 0,
1195 /*!< Fastest compression. 43.45dB. */
1196 KTX_PACK_UASTC_LEVEL_FASTER = 1,
1197 /*!< Faster compression. 46.49dB. */
1198 KTX_PACK_UASTC_LEVEL_DEFAULT = 2,
1199 /*!< Default compression. 47.47dB. */
1200 KTX_PACK_UASTC_LEVEL_SLOWER = 3,
1201 /*!< Slower compression. 48.01dB. */
1202 KTX_PACK_UASTC_LEVEL_VERYSLOW = 4,
1203 /*!< Very slow compression. 48.24dB. */
1204 KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW,
1205 /*!< Maximum supported quality level. */
1206 KTX_PACK_UASTC_LEVEL_MASK = 0xF,
1207 /*!< Mask to extract the level from the other bits. */
1208 KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8,
1209 /*!< Optimize for lowest UASTC error. */
1210 KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16,
1211 /*!< Optimize for lowest BC7 error. */
1212 KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64,
1213 /*!< Optimize for faster transcoding to ETC1. */
1214 KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128,
1215 /*!< Optimize for fastest transcoding to ETC1. */
1216 KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256
1217 /*!< Not documented in BasisU code. */
1218 } ktx_pack_uastc_flag_bits_e;
1219 typedef ktx_uint32_t ktx_pack_uastc_flags;
1220
1221 /**
1222 * @~English
1223 * @brief Options specifiying ASTC encoding quality levels.
1224 */
1225 typedef enum ktx_pack_astc_quality_levels_e {
1226 KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0,
1227 /*!< Fastest compression. */
1228 KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10,
1229 /*!< Fast compression. */
1230 KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60,
1231 /*!< Medium compression. */
1232 KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98,
1233 /*!< Slower compression. */
1234 KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100,
1235 /*!< Very slow compression. */
1236 KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE,
1237 /*!< Maximum supported quality level. */
1238 } ktx_pack_astc_quality_levels_e;
1239
1240 /**
1241 * @~English
1242 * @brief Options specifiying ASTC encoding block dimensions
1243 */
1244 typedef enum ktx_pack_astc_block_dimension_e {
1245 // 2D formats
1246 KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp
1247 KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp
1248 KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp
1249 KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp
1250 KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp
1251 KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp
1252 KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp
1253 KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp
1254 KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp
1255 KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp
1256 KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp
1257 KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp
1258 KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp
1259 KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp
1260 // 3D formats
1261 KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp
1262 KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp
1263 KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp
1264 KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp
1265 KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp
1266 KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp
1267 KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp
1268 KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp
1269 KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp
1270 KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp
1271 KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6
1272 /*!< Maximum supported blocks. */
1273 } ktx_pack_astc_block_dimension_e;
1274
1275 /**
1276 * @~English
1277 * @brief Options specifying ASTC encoder mode.
1278 */
1279 typedef enum ktx_pack_astc_encoder_mode_e {
1280 KTX_PACK_ASTC_ENCODER_MODE_DEFAULT,
1281 /*!< Selects LDR mode if component size is <= 8-bit, HDR otherwise. */
1282 KTX_PACK_ASTC_ENCODER_MODE_LDR,
1283 /*!< Always encode in low dynamic range mode. */
1284 KTX_PACK_ASTC_ENCODER_MODE_HDR,
1285 /*!< Always encode in high dynamic range mode. */
1286 KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR
1287 /*!< Indicates the maximum permissible value. */
1288 } ktx_pack_astc_encoder_mode_e;
1289
1290 extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL;
1291
1292 /**
1293 * @memberof ktxTexture
1294 * @~English
1295 * @brief Structure for passing extended parameters to
1296 * ktxTexture_CompressAstc.
1297 *
1298 * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension
1299 * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to
1300 * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended.
1301 */
1302 typedef struct ktxAstcParams {
1303 ktx_uint32_t structSize;
1304 /*!< Size of this struct. Used so library can tell which version
1305 of struct is being passed.
1306 */
1307
1308 ktx_bool_t verbose;
1309 /*!< If true, prints Astc encoder operation details to
1310 @c stdout. Not recommended for GUI apps.
1311 */
1312
1313 ktx_uint32_t threadCount;
1314 /*!< Number of threads used for compression. Default is 1.
1315 */
1316
1317 /* astcenc params */
1318 ktx_uint32_t blockDimension;
1319 /*!< Combinations of block dimensions that astcenc supports
1320 i.e. 6x6, 8x8, 6x5 etc
1321 */
1322
1323 ktx_uint32_t mode;
1324 /*!< Can be {ldr/hdr} from astcenc
1325 */
1326
1327 ktx_uint32_t qualityLevel;
1328 /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive
1329 */
1330
1331 ktx_bool_t normalMap;
1332 /*!< Tunes codec parameters for better quality on normal maps
1333 In this mode normals are compressed to X,Y components
1334 Discarding Z component, reader will need to generate Z
1335 component in shaders.
1336 */
1337
1338 ktx_bool_t perceptual;
1339 /*!< The codec should optimize for perceptual error, instead of direct
1340 RMS error. This aims to improves perceived image quality, but
1341 typically lowers the measured PSNR score. Perceptual methods are
1342 currently only available for normal maps and RGB color data.
1343 */
1344
1345 char inputSwizzle[4];
1346 /*!< A swizzle to provide as input to astcenc. It must match the regular
1347 expression /^[rgba01]{4}$/.
1348 */
1349 } ktxAstcParams;
1350
1351 KTX_API KTX_error_code KTX_APIENTRY
1352 ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params);
1353
1354 KTX_API KTX_error_code KTX_APIENTRY
1355 ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality);
1356
1357 KTX_API KTX_error_code KTX_APIENTRY
1358 ktxTexture2_DecodeAstc(ktxTexture2* This);
1359
1360 /**
1361 * @memberof ktxTexture2
1362 * @~English
1363 * @brief Structure for passing extended parameters to
1364 * ktxTexture2_CompressBasisEx().
1365 *
1366 * If you only want default values, use ktxTexture2_CompressBasis(). Here, at
1367 * a minimum you must initialize the structure as follows:
1368 * @code
1369 * ktxBasisParams params = {0};
1370 * params.structSize = sizeof(params);
1371 * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL;
1372 * @endcode
1373 *
1374 * @e compressionLevel has to be explicitly set because 0 is a valid
1375 * @e compressionLevel but is not the default used by the BasisU encoder
1376 * when no value is set. Only the other settings that are to be non-default
1377 * must be non-zero.
1378 */
1379 typedef struct ktxBasisParams {
1380 ktx_uint32_t structSize;
1381 /*!< Size of this struct. Used so library can tell which version
1382 of struct is being passed.
1383 */
1384 ktx_bool_t uastc;
1385 /*!< True to use UASTC base, false to use ETC1S base. */
1386 ktx_bool_t verbose;
1387 /*!< If true, prints Basis Universal encoder operation details to
1388 @c stdout. Not recommended for GUI apps.
1389 */
1390 ktx_bool_t noSSE;
1391 /*!< True to forbid use of the SSE instruction set. Ignored if CPU
1392 does not support SSE. */
1393 ktx_uint32_t threadCount;
1394 /*!< Number of threads used for compression. Default is 1. */
1395
1396 /* ETC1S params */
1397
1398 ktx_uint32_t compressionLevel;
1399 /*!< Encoding speed vs. quality tradeoff. Range is [0,6]. Higher values
1400 are much slower, but give slightly higher quality. Higher levels
1401 are intended for video. There is no default. Callers must
1402 explicitly set this value. Callers can use
1403 KTX\_ETC1S\_DEFAULT\_COMPRESSION\_LEVEL as a default value.
1404 Currently this is 2.
1405 */
1406 ktx_uint32_t qualityLevel;
1407 /*!< Compression quality. Range is [1,255]. Lower gives better
1408 compression/lower quality/faster. Higher gives less compression
1409 /higher quality/slower. This automatically determines values for
1410 @c maxEndpoints, @c maxSelectors,
1411 @c endpointRDOThreshold and @c selectorRDOThreshold
1412 for the target quality level. Setting these parameters overrides
1413 the values determined by @c qualityLevel which defaults to
1414 128 if neither it nor both of @c maxEndpoints and
1415 @c maxSelectors have been set.
1416 @note @e Both of @c maxEndpoints and @c maxSelectors
1417 must be set for them to have any effect.
1418 @note qualityLevel will only determine values for
1419 @c endpointRDOThreshold and @c selectorRDOThreshold
1420 when its value exceeds 128, otherwise their defaults will be used.
1421 */
1422 ktx_uint32_t maxEndpoints;
1423 /*!< Manually set the max number of color endpoint clusters.
1424 Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors
1425 must also be set, otherwise the value will be ignored.
1426 */
1427 float endpointRDOThreshold;
1428 /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is
1429 higher quality but less quality per output bit (try [1.0,3.0].
1430 This will override the value chosen by @c qualityLevel.
1431 */
1432 ktx_uint32_t maxSelectors;
1433 /*!< Manually set the max number of color selector clusters. Range
1434 is [1,16128]. Default is 0, unset. If this is set, maxEndpoints
1435 must also be set, otherwise the value will be ignored.
1436 */
1437 float selectorRDOThreshold;
1438 /*!< Set selector RDO quality threshold. The default is 1.5. Lower is
1439 higher quality but less quality per output bit (try [1.0,3.0]).
1440 This will override the value chosen by @c qualityLevel.
1441 */
1442 char inputSwizzle[4];
1443 /*!< A swizzle to apply before encoding. It must match the regular
1444 expression /^[rgba01]{4}$/. If both this and preSwizzle
1445 are specified ktxTexture_CompressBasisEx will raise
1446 KTX_INVALID_OPERATION. Usable with both ETC1S and UASTC.
1447 */
1448 ktx_bool_t normalMap;
1449 /*!< Tunes codec parameters for better quality on normal maps (no
1450 selector RDO, no endpoint RDO) and sets the texture's DFD appropriately.
1451 Only valid for linear textures.
1452 */
1453 ktx_bool_t separateRGToRGB_A;
1454 /*!< @deprecated This was and is a no-op. 2-component inputs have
1455 always been automatically separated using an "rrrg" inputSwizzle.
1456 @sa inputSwizzle and normalMode.
1457 */
1458 ktx_bool_t preSwizzle;
1459 /*!< If the texture has @c KTXswizzle metadata, apply it before
1460 compressing. Swizzling, like @c rabb may yield drastically
1461 different error metrics if done after supercompression. Usable
1462 for both ETC1S and UASTC.
1463 */
1464 ktx_bool_t noEndpointRDO;
1465 /*!< Disable endpoint rate distortion optimizations. Slightly faster,
1466 less noisy output, but lower quality per output bit. Default is
1467 KTX_FALSE.
1468 */
1469 ktx_bool_t noSelectorRDO;
1470 /*!< Disable selector rate distortion optimizations. Slightly faster,
1471 less noisy output, but lower quality per output bit. Default is
1472 KTX_FALSE.
1473 */
1474
1475 /* UASTC params */
1476
1477 ktx_pack_uastc_flags uastcFlags;
1478 /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC
1479 encoding. The most important value is the level given in the
1480 least-significant 4 bits which selects a speed vs quality tradeoff
1481 as shown in the following table:
1482
1483 Level/Speed | Quality
1484 :-----: | :-------:
1485 KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB
1486 KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB
1487 KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB
1488 KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB
1489 KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB
1490 */
1491 ktx_bool_t uastcRDO;
1492 /*!< Enable Rate Distortion Optimization (RDO) post-processing.
1493 */
1494 float uastcRDOQualityScalar;
1495 /*!< UASTC RDO quality scalar (lambda). Lower values yield higher
1496 quality/larger LZ compressed files, higher values yield lower
1497 quality/smaller LZ compressed files. A good range to try is [.2,4].
1498 Full range is [.001,50.0]. Default is 1.0.
1499 */
1500 ktx_uint32_t uastcRDODictSize;
1501 /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower
1502 values=faster, but give less compression. Range is [64,65536].
1503 */
1504 float uastcRDOMaxSmoothBlockErrorScale;
1505 /*!< UASTC RDO max smooth block error scale. Range is [1,300].
1506 Default is 10.0, 1.0 is disabled. Larger values suppress more
1507 artifacts (and allocate more bits) on smooth blocks.
1508 */
1509 float uastcRDOMaxSmoothBlockStdDev;
1510 /*!< UASTC RDO max smooth block standard deviation. Range is
1511 [.01,65536.0]. Default is 18.0. Larger values expand the range of
1512 blocks considered smooth.
1513 */
1514 ktx_bool_t uastcRDODontFavorSimplerModes;
1515 /*!< Do not favor simpler UASTC modes in RDO mode.
1516 */
1517 ktx_bool_t uastcRDONoMultithreading;
1518 /*!< Disable RDO multithreading (slightly higher compression,
1519 deterministic).
1520 */
1521
1522 } ktxBasisParams;
1523
1524 KTX_API KTX_error_code KTX_APIENTRY
1525 ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params);
1526
1527 /**
1528 * @~English
1529 * @brief Enumerators for specifying the transcode target format.
1530 *
1531 * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate
1532 * RGB images, a.k.a slices within the BasisU compressed data. For UASTC
1533 * format they refer to the RGB and the alpha components of the UASTC data. If
1534 * the original image had only 2 components, R will be in the opaque portion
1535 * and G in the alpha portion. The R value will be replicated in the RGB
1536 * components. In the case of BasisU the G value will be replicated in all 3
1537 * components of the alpha slice. If the original image had only 1 component
1538 * it's value is replicated in all 3 components of the opaque portion and
1539 * there is no alpha.
1540 *
1541 * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R,
1542 * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565,
1543 * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor
1544 * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader
1545 * will not produce correct results if any texture filtering is being used.
1546 */
1547 typedef enum ktx_transcode_fmt_e {
1548 // Compressed formats
1549
1550 // ETC1-2
1551 KTX_TTF_ETC1_RGB = 0,
1552 /*!< Opaque only. Returns RGB or alpha data, if
1553 KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1554 specified. */
1555 KTX_TTF_ETC2_RGBA = 1,
1556 /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The
1557 alpha channel will be opaque for textures without an alpha
1558 channel. */
1559
1560 // BC1-5, BC7 (desktop, some mobile devices)
1561 KTX_TTF_BC1_RGB = 2,
1562 /*!< Opaque only, no punchthrough alpha support yet. Returns RGB
1563 or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS
1564 flag is specified. */
1565 KTX_TTF_BC3_RGBA = 3,
1566 /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The
1567 alpha channel will be opaque for textures without an alpha
1568 channel. */
1569 KTX_TTF_BC4_R = 4,
1570 /*!< One BC4 block. R = opaque.g or alpha.g, if
1571 KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1572 specified. */
1573 KTX_TTF_BC5_RG = 5,
1574 /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should
1575 have an alpha channel (if not G will be all 255's. For tangent
1576 space normal maps. */
1577 KTX_TTF_BC7_RGBA = 6,
1578 /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for
1579 UASTC. */
1580
1581 // PVRTC1 4bpp (mobile, PowerVR devices)
1582 KTX_TTF_PVRTC1_4_RGB = 8,
1583 /*!< Opaque only. Returns RGB or alpha data, if
1584 KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1585 specified. */
1586 KTX_TTF_PVRTC1_4_RGBA = 9,
1587 /*!< Opaque+alpha. Most useful for simple opacity maps. If the
1588 texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB
1589 will be used instead. Lowest quality of any supported
1590 texture format. */
1591
1592 // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day)
1593 KTX_TTF_ASTC_4x4_RGBA = 10,
1594 /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for
1595 textures without an alpha channel. The transcoder uses
1596 RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and
1597 [0,255]) endpoint precisions. */
1598
1599 // ATC and FXT1 formats are not supported by KTX2 as there
1600 // are no equivalent VkFormats.
1601
1602 KTX_TTF_PVRTC2_4_RGB = 18,
1603 /*!< Opaque-only. Almost BC1 quality, much faster to transcode
1604 and supports arbitrary texture dimensions (unlike
1605 PVRTC1 RGB). */
1606 KTX_TTF_PVRTC2_4_RGBA = 19,
1607 /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB.
1608 Premultiplied alpha is highly recommended, otherwise the
1609 color channel can leak into the alpha channel on transparent
1610 blocks. */
1611
1612 KTX_TTF_ETC2_EAC_R11 = 20,
1613 /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if
1614 KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1615 specified. */
1616 KTX_TTF_ETC2_EAC_RG11 = 21,
1617 /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The
1618 texture should have an alpha channel (if not G will be all
1619 255's. For tangent space normal maps. */
1620
1621 // Uncompressed (raw pixel) formats
1622 KTX_TTF_RGBA32 = 13,
1623 /*!< 32bpp RGBA image stored in raster (not block) order in
1624 memory, R is first byte, A is last byte. */
1625 KTX_TTF_RGB565 = 14,
1626 /*!< 16bpp RGB image stored in raster (not block) order in memory,
1627 R at bit position 11. */
1628 KTX_TTF_BGR565 = 15,
1629 /*!< 16bpp RGB image stored in raster (not block) order in memory,
1630 R at bit position 0. */
1631 KTX_TTF_RGBA4444 = 16,
1632 /*!< 16bpp RGBA image stored in raster (not block) order in memory,
1633 R at bit position 12, A at bit position 0. */
1634
1635 // Values for automatic selection of RGB or RGBA depending if alpha
1636 // present.
1637 KTX_TTF_ETC = 22,
1638 /*!< Automatically selects @c KTX_TTF_ETC1_RGB or
1639 @c KTX_TTF_ETC2_RGBA according to presence of alpha. */
1640 KTX_TTF_BC1_OR_3 = 23,
1641 /*!< Automatically selects @c KTX_TTF_BC1_RGB or
1642 @c KTX_TTF_BC3_RGBA according to presence of alpha. */
1643
1644 KTX_TTF_NOSELECTION = 0x7fffffff,
1645
1646 // Old enums for compatibility with code compiled against previous
1647 // versions of libktx.
1648 KTX_TF_ETC1 = KTX_TTF_ETC1_RGB,
1649 //!< @deprecated Use #KTX_TTF_ETC1_RGB.
1650 KTX_TF_ETC2 = KTX_TTF_ETC,
1651 //!< @deprecated Use #KTX_TTF_ETC.
1652 KTX_TF_BC1 = KTX_TTF_BC1_RGB,
1653 //!< @deprecated Use #KTX_TTF_BC1_RGB.
1654 KTX_TF_BC3 = KTX_TTF_BC3_RGBA,
1655 //!< @deprecated Use #KTX_TTF_BC3_RGBA.
1656 KTX_TF_BC4 = KTX_TTF_BC4_R,
1657 //!< @deprecated Use #KTX_TTF_BC4_R.
1658 KTX_TF_BC5 = KTX_TTF_BC5_RG,
1659 //!< @deprecated Use #KTX_TTF_BC5_RG.
1660 KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA,
1661 //!< @deprecated Use #KTX_TTF_BC7_RGBA.
1662 KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA,
1663 //!< @deprecated Use #KTX_TTF_BC7_RGBA.
1664 KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA,
1665 //!< @deprecated Use #KTX_TTF_BC7_RGBA
1666 KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB
1667 //!< @deprecated Use #KTX_TTF_PVRTC1_4_RGB.
1668 } ktx_transcode_fmt_e;
1669
1670 /**
1671 * @~English
1672 * @brief Flags guiding transcoding of Basis Universal compressed textures.
1673 */
1674 typedef enum ktx_transcode_flag_bits_e {
1675 KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2,
1676 /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger
1677 power of 2 (not implemented yet, but we're going to support it).
1678 Ignored if the slice's dimensions are already a power of 2.
1679 */
1680 KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4,
1681 /*!< When decoding to an opaque texture format, if the Basis data has
1682 alpha, decode the alpha slice instead of the color slice to the
1683 output texture format. Has no effect if there is no alpha data.
1684 */
1685 KTX_TF_HIGH_QUALITY = 32,
1686 /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and
1687 ETC2_EAC_RG11. The flag is unused by other UASTC transcoders.
1688 */
1689 } ktx_transcode_flag_bits_e;
1690 typedef ktx_uint32_t ktx_transcode_flags;
1691
1692 KTX_API KTX_error_code KTX_APIENTRY
1693 ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt,
1694 ktx_transcode_flags transcodeFlags);
1695
1696 /*
1697 * Returns a string corresponding to a KTX error code.
1698 */
1699 KTX_API const char* KTX_APIENTRY
1700 ktxErrorString(KTX_error_code error);
1701
1702 /*
1703 * Returns a string corresponding to a supercompression scheme.
1704 */
1705 KTX_API const char* KTX_APIENTRY
1706 ktxSupercompressionSchemeString(ktxSupercmpScheme scheme);
1707
1708 /*
1709 * Returns a string corresponding to a transcode target format.
1710 */
1711 KTX_API const char* KTX_APIENTRY
1712 ktxTranscodeFormatString(ktx_transcode_fmt_e format);
1713
1714 KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl);
1715 KTX_API KTX_error_code KTX_APIENTRY
1716 ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig);
1717 KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl);
1718 KTX_API void KTX_APIENTRY
1719 ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig);
1720 KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head);
1721 KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head);
1722
1723 /*
1724 * Adds a key-value pair to a hash list.
1725 */
1726 KTX_API KTX_error_code KTX_APIENTRY
1727 ktxHashList_AddKVPair(ktxHashList* pHead, const char* key,
1728 unsigned int valueLen, const void* value);
1729
1730 /*
1731 * Deletes a ktxHashListEntry from a ktxHashList.
1732 */
1733 KTX_API KTX_error_code KTX_APIENTRY
1734 ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry);
1735
1736 /*
1737 * Finds the entry for a key in a ktxHashList and deletes it.
1738 */
1739 KTX_API KTX_error_code KTX_APIENTRY
1740 ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key);
1741
1742 /*
1743 * Looks up a key and returns the ktxHashListEntry.
1744 */
1745 KTX_API KTX_error_code KTX_APIENTRY
1746 ktxHashList_FindEntry(ktxHashList* pHead, const char* key,
1747 ktxHashListEntry** ppEntry);
1748
1749 /*
1750 * Looks up a key and returns the value.
1751 */
1752 KTX_API KTX_error_code KTX_APIENTRY
1753 ktxHashList_FindValue(ktxHashList* pHead, const char* key,
1754 unsigned int* pValueLen, void** pValue);
1755
1756 /*
1757 * Return the next entry in a ktxHashList.
1758 */
1759 KTX_API ktxHashListEntry* KTX_APIENTRY
1760 ktxHashList_Next(ktxHashListEntry* entry);
1761
1762 /*
1763 * Sorts a ktxHashList into order of the key codepoints.
1764 */
1765 KTX_API KTX_error_code KTX_APIENTRY
1766 ktxHashList_Sort(ktxHashList* pHead);
1767
1768 /*
1769 * Serializes a ktxHashList to a block of memory suitable for
1770 * writing to a KTX file.
1771 */
1772 KTX_API KTX_error_code KTX_APIENTRY
1773 ktxHashList_Serialize(ktxHashList* pHead,
1774 unsigned int* kvdLen, unsigned char** kvd);
1775
1776 /*
1777 * Creates a hash table from the serialized data read from a
1778 * a KTX file.
1779 */
1780 KTX_API KTX_error_code KTX_APIENTRY
1781 ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd);
1782
1783 /*
1784 * Get the key from a ktxHashListEntry
1785 */
1786 KTX_API KTX_error_code KTX_APIENTRY
1787 ktxHashListEntry_GetKey(ktxHashListEntry* This,
1788 unsigned int* pKeyLen, char** ppKey);
1789
1790 /*
1791 * Get the value from a ktxHashListEntry
1792 */
1793 KTX_API KTX_error_code KTX_APIENTRY
1794 ktxHashListEntry_GetValue(ktxHashListEntry* This,
1795 unsigned int* pValueLen, void** ppValue);
1796
1797 /*===========================================================*
1798 * Utilities for printing info about a KTX file. *
1799 *===========================================================*/
1800
1801 KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream);
1802 KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename);
1803 KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size);
1804
1805 /*===========================================================*
1806 * Utilities for printing info about a KTX v1 file. *
1807 *===========================================================*/
1808
1809 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX1InfoTextForStream(ktxStream* stream);
1810
1811 /*===========================================================*
1812 * Utilities for printing info about a KTX v2 file. *
1813 *===========================================================*/
1814
1815 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size);
1816 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename);
1817 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream);
1818 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream);
1819 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1820 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1821 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1822 KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1823
1824 #ifdef __cplusplus
1825 }
1826 #endif
1827
1828 /**
1829 @~English
1830 @page libktx_history Revision History
1831
1832 No longer updated. Kept to preserve ancient history. For more recent history see the repo log at
1833 https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo.
1834
1835 @section v8 Version 4.0
1836 Added:
1837 @li Support for KTX Version 2.
1838 @li Support for encoding and transcoding Basis Universal images in KTX Version 2 files.
1839 @li Function to print info about a KTX file.
1840
1841 @section v7 Version 3.0.1
1842 Fixed:
1843 @li GitHub issue #159: compile failure with recent Vulkan SDKs.
1844 @li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents.
1845 @li Incorrect BC4 blocksize.
1846 @li Missing mapping of PVRTC formats from GL to Vulkan.
1847 @li Incorrect block width and height calculations for sizes that are not
1848 a multiple of the block size.
1849 @li Incorrect KTXorientation key in test images.
1850
1851 @section v6 Version 3.0
1852 Added:
1853 @li new ktxTexture object based API for reading KTX files without an OpenGL context.
1854 @li Vulkan loader. @#include <ktxvulkan.h> to use it.
1855
1856 Changed:
1857 @li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h.
1858 Applications using OpenGL must now include these files themselves.
1859 @li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures
1860 when the OpenGL context does not support 1D textures.
1861 KTX_UNSUPPORTED_TEXTURE_TYPE is now returned.
1862
1863 @section v5 Version 2.0.2
1864 Added:
1865 @li Support for cubemap arrays.
1866
1867 Changed:
1868 @li New build system
1869
1870 Fixed:
1871 @li GitHub issue #40: failure to byte-swap key-value lengths.
1872 @li GitHub issue #33: returning incorrect target when loading cubemaps.
1873 @li GitHub PR #42: loading of texture arrays.
1874 @li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined.
1875 @li GitHub issue #39: stack-buffer-overflow in toktx
1876 @li Don't use GL_EXTENSIONS on recent OpenGL versions.
1877
1878 @section v4 Version 2.0.1
1879 Added:
1880 @li CMake build files. Thanks to Pavel Rotjberg for the initial version.
1881
1882 Changed:
1883 @li ktxWriteKTXF to check the validity of the type & format combinations
1884 passed to it.
1885
1886 Fixed:
1887 @li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=999">999</a>: 16-bit luminance texture cannot be written.
1888 @li compile warnings from compilers stricter than MS Visual C++. Thanks to
1889 Pavel Rotjberg.
1890
1891 @section v3 Version 2.0
1892 Added:
1893 @li support for decoding ETC2 and EAC formats in the absence of a hardware
1894 decoder.
1895 @li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA,
1896 etc. formats to the equivalent R, RG, etc. format with an
1897 appropriate swizzle, when loading in OpenGL Core Profile contexts.
1898 @li ktxErrorString function to return a string corresponding to an error code.
1899 @li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3.
1900 The latter includes an EGL on WGL wrapper that makes porting apps between
1901 OpenGL ES and OpenGL easier on Windows.
1902 @li more texture formats to ktxLoadTexture[FN] and toktx tests.
1903
1904 Changed:
1905 @li ktxLoadTexture[FMN] to discover the capabilities of the GL context at
1906 run time and load textures, or not, according to those capabilities.
1907
1908 Fixed:
1909 @li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX
1910 format.
1911 @li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write
1912 more than 1 byte of face-LOD padding.
1913
1914 Although there is only a very minor API change, the addition of ktxErrorString,
1915 the functional changes are large enough to justify bumping the major revision
1916 number.
1917
1918 @section v2 Version 1.0.1
1919 Implemented ktxLoadTextureM.
1920 Fixed the following:
1921 @li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=571">571</a>: crash when null passed for pIsMipmapped.
1922 @li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=572">572</a>: memory leak when unpacking ETC textures.
1923 @li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=573">573</a>: potential crash when unpacking ETC textures with unused padding pixels.
1924 @li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=576">576</a>: various small fixes.
1925
1926 Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes.
1927
1928 @section v1 Version 1.0
1929 Initial release.
1930
1931 */
1932
1933 #endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */