39#define ASTC_HEADER_SIZE 16
40static const uint8_t
astc_magic[4] = { 0x13, 0xAB, 0xA1, 0x5C };
45 0x93B0, 0x93B1, 0x93B2, 0x93B3, 0x93B4, 0x93B5, 0x93B6, 0x93B7,
46 0x93B8, 0x93B9, 0x93BA, 0x93BB, 0x93BC, 0x93BD
49 0x93D0, 0x93D1, 0x93D2, 0x93D3, 0x93D4, 0x93D5, 0x93D6, 0x93D7,
50 0x93D8, 0x93D9, 0x93DA, 0x93DB, 0x93DC, 0x93DD
53static const int astc_bx[14] = { 4, 5, 5, 6, 6, 8, 8, 8, 10, 10, 10, 10, 12, 12 };
54static const int astc_by[14] = { 4, 4, 5, 5, 6, 5, 6, 8, 5, 6, 8, 10, 10, 12 };
71 int *hflip,
int *vflip)
93 "only records axis flips, not rotations, scales, translations "
108 uint8_t bx = 0, by = 0;
109 int glfmt = 0,
i, srgb, profile_srgb, ret;
110 int hflip, vflip, kv_size, kv_padded;
117 "(block size) from the encoder.\n");
146 "Writing HDR ASTC to KTX 1.0 is not supported; use the .astc "
147 "container for HDR output.\n");
170 srgb =
ctx->srgb >= 0 ?
ctx->srgb :
171 profile_srgb >= 0 ? profile_srgb : 1;
174 if (
ctx->srgb >= 0 && profile_srgb >= 0 && profile_srgb !=
ctx->srgb) {
176 "KTX srgb option does not match the encoder profile.\n");
184 "Writing 3D ASTC blocks to KTX is not supported; use the .astc "
185 "container for 3D block output.\n");
189 for (
i = 0;
i < 14;
i++) {
206 memcpy(orientation,
"S=r,T=d",
sizeof(orientation));
207 orientation[2] = hflip ?
'l' :
'r';
208 orientation[6] = vflip ?
'u' :
'd';
213 kv_padded = (kv_size + 3) & ~3;
215 memset(hdr, 0,
sizeof(hdr));
217 hdr[0] = 0xAB; hdr[1] =
'K'; hdr[2] =
'T'; hdr[3] =
'X';
218 hdr[4] =
' '; hdr[5] =
'1'; hdr[6] =
'1'; hdr[7] = 0xBB;
219 hdr[8] = 0x0D; hdr[9] = 0x0A; hdr[10] = 0x1A; hdr[11] = 0x0A;
230 AV_WL32(hdr + 60, 4 + kv_padded);
238 for (
i = kv_size;
i % 4;
i++)
250 if (
ctx->wrote_image) {
252 ".ktx muxer supports a single image per file.\n");
255 ctx->wrote_image = 1;
262#define OFFSET(x) offsetof(KTXMuxerContext, x)
263#define VE AV_OPT_FLAG_ENCODING_PARAM
265 {
"srgb",
"GL internal format color space",
OFFSET(srgb),
267 {
"auto",
"Follow the encoder profile", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
VE, .unit =
"srgb" },
268 {
"linear",
"Write the linear ASTC format", 0,
AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0,
VE, .unit =
"srgb" },
269 {
"srgb",
"Write the sRGB ASTC format", 0,
AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0,
VE, .unit =
"srgb" },
274 .class_name =
"ktx_muxer",
283 .p.mime_type =
"image/ktx",
284 .p.extensions =
"ktx",
static AVFormatContext * ctx
static const uint8_t astc_magic[4]
void avio_wl32(AVIOContext *s, unsigned int val)
void avio_w8(AVIOContext *s, int b)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define i(width, name, range_min, range_max)
#define FFABSU(a)
Unsigned Absolute value.
Misc types and constants that do not belong anywhere else.
#define AV_PROFILE_ASTC_LDR
Linear LDR.
#define AV_PROFILE_ASTC_HDR
HDR RGB and alpha.
#define AV_PROFILE_ASTC_HDR_RGB_LDR_A
HDR RGB with LDR alpha.
#define AV_PROFILE_ASTC_LDR_SRGB
sRGB LDR.
#define AV_PROFILE_ASTC_LINEAR_ANY
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
static const int astc_gl_linear[14]
static const int astc_by[14]
static const int astc_bx[14]
static int ktx_orientation_from_side_data(AVFormatContext *s, AVStream *st, int *hflip, int *vflip)
static const AVClass ktx_muxer_class
static const AVOption ktx_options[]
static const char ktx_orientation_key[]
static const int astc_gl_srgb[14]
static int ktx_write_header(AVFormatContext *s)
static int ktx_write_packet(AVFormatContext *s, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
Describe the class of an AVClass context structure.
int extradata_size
Size of the extradata content in bytes.
int height
The height of the video frame in pixels.
int nb_coded_side_data
Amount of entries in coded_side_data.
int width
The width of the video frame in pixels.
int profile
Codec-specific bitstream restrictions that the stream conforms to.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
This structure stores compressed data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.