62 lines
2.1 KiB
C
62 lines
2.1 KiB
C
/*
|
|
*
|
|
* Singe 3
|
|
* Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 3
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
// Singe - KTX2 textures: Basis Universal (ETC1S or UASTC) images transcoded at load to the block
|
|
// format the GPU has, so one shipped file works everywhere.
|
|
|
|
#ifndef KTX2_H
|
|
#define KTX2_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// What a KTX2 image may be transcoded to, best first.
|
|
typedef enum Ktx2FormatE {
|
|
KTX2_RGBA = 0, // Uncompressed, the fallback
|
|
KTX2_BC7 = 1, // Desktop GPUs
|
|
KTX2_ASTC = 2, // ASTC 4x4: Apple GPUs, the Raspberry Pi 4 and phones
|
|
KTX2_BC3 = 3, // Older desktop GPUs
|
|
KTX2_ETC2 = 4 // ETC2 with EAC alpha: the one block format OpenGL ES 3 guarantees (handhelds, the Pi under GLES)
|
|
} Ktx2FormatE;
|
|
|
|
typedef struct Ktx2LevelS {
|
|
uint8_t *data;
|
|
size_t size;
|
|
int32_t width; // Pixels
|
|
int32_t height;
|
|
} Ktx2LevelT;
|
|
|
|
typedef struct Ktx2ImageS {
|
|
Ktx2FormatE format;
|
|
int32_t width;
|
|
int32_t height;
|
|
int32_t levelCount;
|
|
Ktx2LevelT *levels; // Largest first
|
|
bool srgb; // The file says its colours are sRGB
|
|
} Ktx2ImageT;
|
|
|
|
void ktx2Free(Ktx2ImageT *image);
|
|
bool ktx2Is(const void *bytes, size_t size); // Starts with the KTX2 identifier
|
|
bool ktx2Transcode(const void *bytes, size_t size, Ktx2FormatE wanted, Ktx2ImageT *out); // Every level; free with ktx2Free
|
|
|
|
#endif
|