40 #define DDPF_FOURCC (1 << 2)
41 #define DDPF_PALETTE (1 << 5)
42 #define DDPF_NORMALMAP (1U << 31)
123 int alpha_exponent, ycocg_classic, ycocg_scaled, normal_map,
array;
127 gimp_tag = bytestream2_get_le32(gbc);
128 alpha_exponent = gimp_tag ==
MKTAG(
'A',
'E',
'X',
'P');
129 ycocg_classic = gimp_tag ==
MKTAG(
'Y',
'C',
'G',
'1');
130 ycocg_scaled = gimp_tag ==
MKTAG(
'Y',
'C',
'G',
'2');
134 size = bytestream2_get_le32(gbc);
139 flags = bytestream2_get_le32(gbc);
143 fourcc = bytestream2_get_le32(gbc);
145 if (
ctx->compressed &&
ctx->paletted) {
147 "Disabling invalid palette flag for compressed dds.\n");
151 bpp =
ctx->bpp = bytestream2_get_le32(gbc);
152 r = bytestream2_get_le32(gbc);
153 g = bytestream2_get_le32(gbc);
154 b = bytestream2_get_le32(gbc);
155 a = bytestream2_get_le32(gbc);
171 if (
ctx->compressed) {
173 case MKTAG(
'D',
'X',
'T',
'1'):
175 ctx->tex_funct =
ctx->texdsp.dxt1a_block;
177 case MKTAG(
'D',
'X',
'T',
'2'):
179 ctx->tex_funct =
ctx->texdsp.dxt2_block;
181 case MKTAG(
'D',
'X',
'T',
'3'):
183 ctx->tex_funct =
ctx->texdsp.dxt3_block;
185 case MKTAG(
'D',
'X',
'T',
'4'):
187 ctx->tex_funct =
ctx->texdsp.dxt4_block;
189 case MKTAG(
'D',
'X',
'T',
'5'):
192 ctx->tex_funct =
ctx->texdsp.dxt5ys_block;
193 else if (ycocg_classic)
194 ctx->tex_funct =
ctx->texdsp.dxt5y_block;
196 ctx->tex_funct =
ctx->texdsp.dxt5_block;
198 case MKTAG(
'R',
'X',
'G',
'B'):
200 ctx->tex_funct =
ctx->texdsp.dxt5_block;
206 case MKTAG(
'A',
'T',
'I',
'1'):
207 case MKTAG(
'B',
'C',
'4',
'U'):
209 ctx->tex_funct =
ctx->texdsp.rgtc1u_block;
211 case MKTAG(
'B',
'C',
'4',
'S'):
213 ctx->tex_funct =
ctx->texdsp.rgtc1s_block;
215 case MKTAG(
'A',
'T',
'I',
'2'):
218 ctx->tex_funct =
ctx->texdsp.dxn3dc_block;
220 case MKTAG(
'B',
'C',
'5',
'U'):
222 ctx->tex_funct =
ctx->texdsp.rgtc2u_block;
224 case MKTAG(
'B',
'C',
'5',
'S'):
226 ctx->tex_funct =
ctx->texdsp.rgtc2s_block;
228 case MKTAG(
'U',
'Y',
'V',
'Y'):
232 case MKTAG(
'Y',
'U',
'Y',
'2'):
236 case MKTAG(
'P',
'8',
' ',
' '):
242 case MKTAG(
'G',
'1',
' ',
' '):
246 case MKTAG(
'D',
'X',
'1',
'0'):
248 dxgi = bytestream2_get_le32(gbc);
251 array = bytestream2_get_le32(gbc);
256 "Found array of size %d (ignored).\n",
array);
259 ctx->compressed = (dxgi >= 70) && (dxgi <= 84);
302 ctx->tex_funct =
ctx->texdsp.dxt1a_block;
309 ctx->tex_funct =
ctx->texdsp.dxt3_block;
316 ctx->tex_funct =
ctx->texdsp.dxt5_block;
321 ctx->tex_funct =
ctx->texdsp.rgtc1u_block;
325 ctx->tex_funct =
ctx->texdsp.rgtc1s_block;
330 ctx->tex_funct =
ctx->texdsp.rgtc2u_block;
334 ctx->tex_funct =
ctx->texdsp.rgtc2s_block;
338 "Unsupported DXGI format %d.\n", dxgi);
346 }
else if (
ctx->paletted) {
355 if (bpp == 4 &&
r == 0 &&
g == 0 &&
b == 0 &&
a == 0)
358 else if (bpp == 8 &&
r == 0xff &&
g == 0 &&
b == 0 &&
a == 0)
360 else if (bpp == 8 &&
r == 0 &&
g == 0 &&
b == 0 &&
a == 0xff)
363 else if (bpp == 16 &&
r == 0xff &&
g == 0 &&
b == 0 &&
a == 0xff00)
365 else if (bpp == 16 &&
r == 0xff00 &&
g == 0 &&
b == 0 &&
a == 0xff) {
369 else if (bpp == 16 &&
r == 0xffff &&
g == 0 &&
b == 0 &&
a == 0)
371 else if (bpp == 16 &&
r == 0x7c00 &&
g == 0x3e0 &&
b == 0x1f &&
a == 0)
373 else if (bpp == 16 &&
r == 0x7c00 &&
g == 0x3e0 &&
b == 0x1f &&
a == 0x8000)
375 else if (bpp == 16 &&
r == 0xf800 &&
g == 0x7e0 &&
b == 0x1f &&
a == 0)
378 else if (bpp == 24 &&
r == 0xff0000 &&
g == 0xff00 &&
b == 0xff &&
a == 0)
381 else if (bpp == 32 &&
r == 0xff0000 &&
g == 0xff00 &&
b == 0xff &&
a == 0)
383 else if (bpp == 32 &&
r == 0xff &&
g == 0xff00 &&
b == 0xff0000 &&
a == 0)
385 else if (bpp == 32 &&
r == 0xff0000 &&
g == 0xff00 &&
b == 0xff &&
a == 0xff000000)
387 else if (bpp == 32 &&
r == 0xff &&
g == 0xff00 &&
b == 0xff0000 &&
a == 0xff000000)
392 "[bpp %d r 0x%x g 0x%x b 0x%x a 0x%x].\n", bpp,
r,
g,
b,
a);
402 else if (ycocg_classic && !
ctx->compressed)
407 case MKTAG(
'A',
'2',
'X',
'Y'):
410 case MKTAG(
'x',
'G',
'B',
'R'):
413 case MKTAG(
'x',
'R',
'B',
'G'):
416 case MKTAG(
'R',
'B',
'x',
'G'):
419 case MKTAG(
'R',
'G',
'x',
'B'):
422 case MKTAG(
'R',
'x',
'B',
'G'):
425 case MKTAG(
'x',
'G',
'x',
'R'):
428 case MKTAG(
'A',
'2',
'D',
'5'):
437 int slice,
int thread_nb)
445 int start_slice, end_slice;
446 int base_blocks_per_slice = h_block /
ctx->slice_count;
447 int remainder_blocks = h_block %
ctx->slice_count;
452 start_slice = slice * base_blocks_per_slice;
454 start_slice +=
FFMIN(slice, remainder_blocks);
456 end_slice = start_slice + base_blocks_per_slice;
458 if (slice < remainder_blocks)
461 for (y = start_slice; y < end_slice; y++) {
463 int off = y * w_block;
464 for (x = 0; x < w_block; x++) {
466 d + (off + x) *
ctx->tex_ratio);
487 switch (
ctx->postproc) {
501 src[0] =
r *
a / 255;
502 src[1] =
g *
a / 255;
503 src[2] =
b *
a / 255;
515 x_off =
ctx->tex_ratio == 8 ? 0 : 3;
522 int d = (255 * 255 - x * x - y * y) / 2;
540 int cg =
src[1] - 128;
541 int co =
src[2] - 128;
627 if (bytestream2_get_le32(gbc) !=
MKTAG(
'D',
'D',
'S',
' ') ||
628 bytestream2_get_le32(gbc) != 124) {
635 height = bytestream2_get_le32(gbc);
636 width = bytestream2_get_le32(gbc);
650 mipmap = bytestream2_get_le32(gbc);
664 if (
ctx->compressed) {
672 "Compressed Buffer is too small (%d < %d).\n",
686 for (
i = 0;
i < 16;
i++) {
706 dst[x + 1] =
val >> 4;
717 for (
i = 0;
i < 256;
i++)
static double val(void *priv, double ch)
Libavcodec external API header.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define flags(name, subs,...)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
@ DXGI_FORMAT_B8G8R8A8_UNORM
@ DXGI_FORMAT_BC3_UNORM_SRGB
@ DXGI_FORMAT_BC3_TYPELESS
@ DXGI_FORMAT_R16G16B16A16_SNORM
@ DXGI_FORMAT_R16G16B16A16_UNORM
@ DXGI_FORMAT_BC1_UNORM_SRGB
@ DXGI_FORMAT_R8G8B8A8_TYPELESS
@ DXGI_FORMAT_BC2_TYPELESS
@ DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
@ DXGI_FORMAT_B8G8R8X8_TYPELESS
@ DXGI_FORMAT_B8G8R8A8_TYPELESS
@ DXGI_FORMAT_R16G16B16A16_UINT
@ DXGI_FORMAT_R8G8B8A8_SINT
@ DXGI_FORMAT_R8G8B8A8_SNORM
@ DXGI_FORMAT_R8G8B8A8_UINT
@ DXGI_FORMAT_R16G16B16A16_TYPELESS
@ DXGI_FORMAT_R16G16B16A16_FLOAT
@ DXGI_FORMAT_R8G8B8A8_UNORM
@ DXGI_FORMAT_BC5_TYPELESS
@ DXGI_FORMAT_BC2_UNORM_SRGB
@ DXGI_FORMAT_BC4_TYPELESS
@ DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
@ DXGI_FORMAT_R16G16B16A16_SINT
@ DXGI_FORMAT_BC1_TYPELESS
@ DXGI_FORMAT_B5G6R5_UNORM
@ DXGI_FORMAT_B8G8R8X8_UNORM_SRGB
@ DXGI_FORMAT_B8G8R8X8_UNORM
static int dds_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static void do_swizzle(AVFrame *frame, int x, int y)
static void run_postproc(AVCodecContext *avctx, AVFrame *frame)
static int decompress_texture_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
static int parse_pixel_format(AVCodecContext *avctx)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define av_fourcc2str(fourcc)
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
@ AV_PICTURE_TYPE_I
Intra.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Replacements for frequently missing libm functions.
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
#define AV_PIX_FMT_BGRA64
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorSpace colorspace
YUV colorspace type.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int coded_width
Bitstream width / height, may be different from width/height e.g.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
enum DDSPostProc postproc
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
static int array[MAX_W *MAX_W]
av_cold void ff_texturedsp_init(TextureDSPContext *c)
Texture block (4x4) module.