31#include "config_components.h"
45#define ASTC_HEADER_SIZE 16
46static const uint8_t
astc_magic[4] = { 0x13, 0xAB, 0xA1, 0x5C };
48 0xAB,
'K',
'T',
'X',
' ',
'1',
'1', 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
53 0x93B0, 0x93B1, 0x93B2, 0x93B3, 0x93B4, 0x93B5, 0x93B6, 0x93B7,
54 0x93B8, 0x93B9, 0x93BA, 0x93BB, 0x93BC, 0x93BD
56static const int astc_bx[14] = { 4, 5, 5, 6, 6, 8, 8, 8, 10, 10, 10, 10, 12, 12 };
57static const int astc_by[14] = { 4, 4, 5, 5, 6, 5, 6, 8, 5, 6, 8, 10, 10, 12 };
67 int base = (e >= 0x93D0 && e <= 0x93DD) ? (e - 0x20) : e;
68 for (
int i = 0;
i < 14;
i++) {
101 const char *p =
value;
104 if (p[0] ==
'S' && p[1] ==
'=' && p[2])
105 *hflip = p[2] ==
'l';
106 else if (p[0] ==
'T' && p[1] ==
'=' && p[2])
107 *vflip = p[2] ==
'u';
117 int *hflip,
int *vflip)
121 uint32_t
left = kvdata;
127 uint32_t padded = (
entry + 3) & ~3u;
135 if (
entry >=
sizeof(buf)) {
146 key = (
const char *)buf;
149 if (!strcmp(
key,
"KTXorientation"))
177 uint32_t endian, gl_type, gl_type_size, gl_format, gl_internal;
178 uint32_t gl_base_internal,
w,
h, depth,
array, faces, mips;
179 uint32_t kvdata, image_size;
180 uint8_t image_size_buf[4];
182 int hflip = 0, vflip = 0;
194 gl_type_size =
AV_RL32(hdr + 20);
196 gl_internal =
AV_RL32(hdr + 28);
197 gl_base_internal =
AV_RL32(hdr + 32);
206 if (endian != 0x04030201) {
210 if (gl_type || gl_type_size != 1 || gl_format || gl_base_internal != 0x1908 ||
211 !
w || !
h ||
w > 0xFFFFFF ||
h > 0xFFFFFF ||
212 depth ||
array || faces != 1 || mips != 1) {
224 if (
ffio_read_size(pb, image_size_buf,
sizeof(image_size_buf)) < 0)
226 image_size =
AV_RL32(image_size_buf);
227 if (!image_size || image_size > INT_MAX)
233 uint64_t expected = (((uint64_t)
w + bx - 1) / bx) *
234 (((uint64_t)
h + by - 1) / by) * 16;
235 if (image_size != expected) {
237 "KTX image size %u does not match the %"PRIu64
" bytes "
238 "required for a %ux%u texture with %dx%d blocks.\n",
239 image_size, expected,
w,
h, bx, by);
259 st->
codecpar->
profile = gl_internal >= 0x93D0 && gl_internal <= 0x93DD ?
266 memset(extra, 0,
sizeof(extra));
268 extra[4] = (uint8_t)bx;
269 extra[5] = (uint8_t)by;
280 if (hflip || vflip) {
294 "Applying KTXorientation (hflip %d, vflip %d).\n", hflip, vflip);
325 "Truncated KTX image: got %d of %u bytes.\n",
332 pkt->stream_index = 0;
341 .p.mime_type =
"image/ktx",
342 .p.extensions =
"ktx",
static const uint8_t astc_magic[4]
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
unsigned int avio_rl32(AVIOContext *s)
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
Misc types and constants that do not belong anywhere else.
#define AV_PROFILE_ASTC_LDR_SRGB
sRGB LDR.
#define AV_PROFILE_ASTC_LINEAR_ANY
static int read_header(FFV1Context *f, RangeCoder *c)
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
static int ktx_read_orientation(AVFormatContext *s, uint32_t kvdata, int *hflip, int *vflip)
static const uint8_t ktx_magic[12]
static int ktx_read_packet(AVFormatContext *s, AVPacket *pkt)
static const int astc_gl_linear[14]
static int gl_enum_to_block(uint32_t e, int *bx, int *by)
static int ktx_read_header(AVFormatContext *s)
static const int astc_by[14]
static void ktx_orientation_flips(const char *value, int *hflip, int *vflip)
static int ktx_probe(const AVProbeData *p)
static const int astc_bx[14]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_RGBAF16
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
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.
enum AVMediaType codec_type
General type of the encoded data.
int profile
Codec-specific bitstream restrictions that the stream conforms to.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
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.
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int array[MAX_W *MAX_W]