35#define DXV_HEADER_LENGTH 12
40#define DXV_ALIGN(x) FFALIGN(x, 16)
47#define LOOKBACK_HT_ELEMS 0x20202
48#define LOOKBACK_WORDS 0x20202
76 if (bytestream2_get_bytes_left_p(pbc) < 4) { \
77 return AVERROR_INVALIDDATA; \
79 value = pbc->buffer; \
80 bytestream2_put_le32(pbc, 0); \
83 if (idx >= 0x102 * x) { \
85 bytestream2_put_le16(pbc, (idx / x) - 0x102); \
86 } else if (idx >= 2 * x) { \
88 bytestream2_put_byte(pbc, (idx / x) - 2); \
89 } else if (idx == x) { \
94 AV_WL32(value, AV_RL32(value) | (op << (state * 2))); \
103 uint32_t idx, combo_idx, prev_pos, old_pos,
state = 16,
pos = 0,
op = 0;
111 bytestream2_put_le32(pbc,
AV_RL32(
ctx->tex_data));
114 bytestream2_put_le32(pbc,
AV_RL32(
ctx->tex_data + 4));
118 while (
pos + 2 <=
ctx->tex_size / 4) {
175 if (
ctx->enc.tex_funct) {
176 uint8_t *safe_data[4] = {
frame->data[0], 0, 0, 0};
177 int safe_linesize[4] = {
frame->linesize[0], 0, 0, 0};
201 for (
int y = 0; y < avctx->
height; y++) {
202 memset(safe_data[0] + y * safe_linesize[0] + 4*avctx->
width, 0, safe_linesize[0] - 4*avctx->
width);
207 memset(safe_data[0] + y * safe_linesize[0], 0, safe_linesize[0]);
212 ctx->enc.tex_data.out =
ctx->tex_data;
213 ctx->enc.frame_data.in = safe_data[0];
214 ctx->enc.stride = safe_linesize[0];
219 if (safe_data[0] !=
frame->data[0])
228 bytestream2_put_le32(pbc,
ctx->tex_fmt);
229 bytestream2_put_byte(pbc, 4);
230 bytestream2_put_byte(pbc, 0);
231 bytestream2_put_byte(pbc, 0);
232 bytestream2_put_byte(pbc, 0);
236 ret =
ctx->compress_tex(avctx);
261 switch (
ctx->tex_fmt) {
265 ctx->enc.tex_ratio = 8;
271 ctx->enc.raw_ratio = 16;
278 if (!
ctx->tex_data) {
308#define OFFSET(x) offsetof(DXVEncContext, x)
309#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
312 {
"dxt1",
"DXT1 (Normal Quality, No Alpha)", 0,
AV_OPT_TYPE_CONST, { .i64 =
DXV_FMT_DXT1 }, 0, 0,
FLAGS, .unit =
"format" },
317 .class_name =
"DXV encoder",
const FFCodec ff_dxv_encoder
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CEIL_RSHIFT(a, b)
static av_cold int dxv_init(AVCodecContext *avctx)
static av_cold int dxv_close(AVCodecContext *avctx)
static av_cold int dxv_init(AVCodecContext *avctx)
static const AVClass dxvenc_class
static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static av_cold int dxv_close(AVCodecContext *avctx)
static int dxv_compress_dxt1(AVCodecContext *avctx)
#define DXV_HEADER_LENGTH
#define LOOKBACK_HT_ELEMS
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
static struct @346255127015250356166251341105367306144006377143 state
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#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 AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
#define LIBAVUTIL_VERSION_INT
av_cold int ff_hashtable_alloc(FFHashtableContext **ctx, size_t key_size, size_t val_size, size_t max_entries)
Create a fixed-sized Robin Hood hash table.
int ff_hashtable_set(struct FFHashtableContext *ctx, const void *key, const void *val)
Store a value in a hash table given a key.
int ff_hashtable_delete(struct FFHashtableContext *ctx, const void *key)
Delete a value from a hash table given a key.
void ff_hashtable_clear(struct FFHashtableContext *ctx)
Delete all values from a hash table.
int ff_hashtable_get(const struct FFHashtableContext *ctx, const void *key, void *val)
Look up a value from a hash table given a key.
av_cold void ff_hashtable_freep(FFHashtableContext **ctx)
Free a hash table.
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Memory handling functions.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
FFHashtableContext * lut_ht
FFHashtableContext * combo_ht
TextureDSPThreadContext enc
FFHashtableContext * color_ht
int(* compress_tex)(AVCodecContext *avctx)
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
static AVFormatContext * ctx
Texture block (4x4) module.
void ff_texturedspenc_init(TextureDSPEncContext *c)
int ff_texturedsp_exec_compress_threads(struct AVCodecContext *avctx, TextureDSPThreadContext *ctx)