### FlashSV2 Compression Functions (Zlib) Source: https://ffmpeg.org/doxygen/8.0/flashsv2enc_8c Implements Zlib compression for blocks, with options for compressing the current block or both current and previous blocks (prime compression). These functions are essential for reducing the data size. ```c static int | encode_zlib (Block *b, uint8_t *buf, unsigned long *buf_size, z_stream *zstream) static int | encode_zlibprime (Block *b, Block *prime, uint8_t *buf, int *buf_size, z_stream *zstream) ``` -------------------------------- ### Compress DXT5 Texture Block (C) Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c_source Compresses one block of RGBA pixels into a DXT5 texture format, preserving alpha. This function first compresses the alpha channel, then the color, and returns the size of the compressed data (16 bytes). ```c static int dxt5_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block) { compress_alpha(dst, stride, block); compress_color(dst + 8, stride, block); return 16; } ``` -------------------------------- ### Function: dxt1_block - Compress RGBA to DXT1 Texture Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c Compresses a 4x4 block of RGBA pixels into the DXT1 texture format. The resulting compressed data is written to the 'dst' buffer. This function is essential for texture compression in graphics. ```c static int dxt1_block(uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_) ``` -------------------------------- ### Compress Hap Frame using Snappy Source: https://ffmpeg.org/doxygen/8.0/hapenc_8c_source This function compresses an entire Hap frame, chunk by chunk, using the Snappy algorithm. It calculates offsets and sizes for each chunk, compresses them, and writes the compressed data directly to the output packet buffer. If Snappy compression does not reduce the size, it falls back to copying the raw texture data. ```c #include #include "snappy-c.h" #include "libavutil/frame.h" #include "libavutil/imgutils.h" #include "libavutil/mem.h" #include "libavutil/opt.h" #include "avcodec.h" #include "bytestream.h" #include "codec_internal.h" #include "encode.h" #include "hap.h" #include "texturedsp.h" static int hap_compress_frame(AVCodecContext *avctx, uint8_t *dst) { HapContext *ctx = avctx->priv_data; int i, final_size = 0; for (i = 0; i < ctx->chunk_count; i++) { HapChunk *chunk = &ctx->chunks[i]; uint8_t *chunk_src, *chunk_dst; int ret; if (i == 0) { chunk->compressed_offset = 0; } else { chunk->compressed_offset = ctx->chunks[i-1].compressed_offset + ctx->chunks[i-1].compressed_size; } chunk->uncompressed_size = ctx->tex_size / ctx->chunk_count; chunk->uncompressed_offset = i * chunk->uncompressed_size; chunk->compressed_size = ctx->max_snappy; chunk_src = ctx->tex_buf + chunk->uncompressed_offset; chunk_dst = dst + chunk->compressed_offset; /* Compress with snappy too, write directly on packet buffer. */ ret = snappy_compress(chunk_src, chunk->uncompressed_size, chunk_dst, &chunk->compressed_size); if (ret != SNAPPY_OK) { av_log(avctx, AV_LOG_ERROR, "Snappy compress error.\n"); return AVERROR_BUG; } /* If there is no gain from snappy, just use the raw texture. */ if (chunk->compressed_size >= chunk->uncompressed_size) { av_log(avctx, AV_LOG_VERBOSE, "Snappy buffer bigger than uncompressed (%%"SIZE_SPECIFIER" >= %%"SIZE_SPECIFIER" bytes).\n", chunk->compressed_size, chunk->uncompressed_size); memcpy(chunk_dst, chunk_src, chunk->uncompressed_size); chunk->compressor = HAP_COMP_NONE; chunk->compressed_size = chunk->uncompressed_size; } else { chunk->compressor = HAP_COMP_SNAPPY; } final_size += chunk->compressed_size; } return final_size; } ``` -------------------------------- ### Compress DXT5-YCoCg Texture Block (C) Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c_source Compresses one block of RGBA pixels into a DXT5-YCoCg texture format, reordering components before compression. Alpha is not preserved. It calls `compress_alpha` and `compress_color` on reordered data and returns 16 bytes. ```c static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block) { int x, y; uint8_t reorder[64]; /* Reorder the components and then run a normal DXT5 compression. */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) rgba2ycocg(reorder + x * 4 + y * 16, block + x * 4 + y * stride); compress_alpha(dst + 0, 16, reorder); compress_color(dst + 8, 16, reorder); return 16; } ``` -------------------------------- ### EXR Context 'compression' Member Definition (C) Source: https://ffmpeg.org/doxygen/8.0/exr_8c_source Defines the 'compression' member within the EXRContext structure, which is an enum specifying the compression method used for the EXR image data. ```c enum ExrCompr compression; /* Compression method used for the EXR image */ ``` -------------------------------- ### ADPCM ARGO Compression Helper Functions Source: https://ffmpeg.org/doxygen/8.0/adpcmenc_8c_source Provides helper functions for the ADPCM ARGO compression algorithm. Includes a function to compress a single nibble and another to compress an entire block of samples, calculating the error introduced by compression. ```c static inline int adpcm_argo_compress_nibble(const ADPCMChannelStatus *cs, int16_t s, int shift, int flag) { int nibble; if (flag) nibble = 4 * s - 8 * cs->sample1 + 4 * cs->sample2; else nibble = 4 * s - 4 * cs->sample1; return (nibble >> shift) & 0x0F; } static int64_t adpcm_argo_compress_block(ADPCMChannelStatus *cs, PutBitContext *pb, const int16_t *samples, int nsamples, int shift, int flag) { int64_t error = 0; if (pb) { put_bits(pb, 4, shift - 2); put_bits(pb, 1, 0); put_bits(pb, 1, !!flag); put_bits(pb, 2, 0); } for (int n = 0; n < nsamples; n++) { /* Compress the nibble, then expand it to see how much precision we've lost. */ int nibble = adpcm_argo_compress_nibble(cs, samples[n], shift, flag); int16_t sample = ff_adpcm_argo_expand_nibble(cs, nibble, shift, flag); error += abs(samples[n] - sample); if (pb) put_bits(pb, 4, nibble); } return error; } ``` -------------------------------- ### FFmpeg lcldec.c LclDecContext compression Field Source: https://ffmpeg.org/doxygen/8.0/structLclDecContext Documentation for the 'compression' field within the LclDecContext structure, specifying the compression method. Defined in lcldec.c. ```c int LclDecContext::compression ``` -------------------------------- ### TargaCompr Enumeration Definition Source: https://ffmpeg.org/doxygen/8.0/targa_8h Defines compression methods for Targa files. Includes options for no compression, palette-based compression, RGB compression, black and white compression, and RLE compression. This enum is defined in the targa.h file. ```c enum TargaCompr { TGA_NODATA = 0, TGA_PAL = 1, TGA_RGB = 2, TGA_BW = 3, TGA_RLE = 8 } ``` -------------------------------- ### Compress and Write PNG Row (png_write_row) Source: https://ffmpeg.org/doxygen/8.0/pngenc_8c_source Compresses a single row of PNG image data using zlib's deflate function and writes it to the image data buffer. If the buffer is full, it calls png_write_image_data to flush the compressed data. Dependencies include zlib's deflate and PNG encoder context. ```c static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size) { PNGEncContext *s = avctx->priv_data; z_stream *const zstream = &s->zstream.zstream; int ret; zstream->avail_in = size; zstream->next_in = data; while (zstream->avail_in > 0) { ret = deflate(zstream, Z_NO_FLUSH); if (ret != Z_OK) return -1; if (zstream->avail_out == 0) { if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100) png_write_image_data(avctx, s->buf, IOBUF_SIZE); zstream->avail_out = IOBUF_SIZE; zstream->next_out = s->buf; } } return 0; } ``` -------------------------------- ### Compress DXT1 Texture Block (C) Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c_source Compresses one block of RGBA pixels into a DXT1 texture format. Alpha channel is not preserved. This function calls `compress_color` and returns the size of the compressed data (8 bytes). ```c static int dxt1_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block) { compress_color(dst, stride, block); return 8; } ``` -------------------------------- ### Compress ADPCM IMA Sample (C) Source: https://ffmpeg.org/doxygen/8.0/adpcmenc_8c Compresses a single audio sample using the ADPCM IMA algorithm. This inline static function takes a pointer to ADPCMChannelStatus and the sample to be compressed (int16_t), returning the compressed byte. ```c static uint8_t adpcm_ima_compress_sample(ADPCMChannelStatus *c, int16_t sample) ``` -------------------------------- ### LZO Compression and Decompression with FFmpeg Utilities (C) Source: https://ffmpeg.org/doxygen/8.0/tests_2lzo_8c_source This C code snippet demonstrates how to compress data using various LZO 1x compression levels provided by FFmpeg and subsequently decompress it. It reads input from a file specified by the first command-line argument and uses the second argument to select the compression level. The code includes checks to ensure the decompressed data matches the original. Dependencies include FFmpeg's LZO and logging utilities. ```c #include #include #include #include #include "libavutil/lzo.h" #include "libavutil/log.h" #define MAXSZ 1024*1024 // Example max size /* Define one of these to 1 if you wish to benchmark liblzo * instead of our native implementation. */ #define BENCHMARK_LIBLZO_SAFE 0 #define BENCHMARK_LIBLZO_UNSAFE 0 int main(int argc, char *argv[]) { FILE *in = fopen(argv[1], "rb"); int comp_level = argc > 2 ? atoi(argv[2]) : 0; uint8_t *orig = av_malloc(MAXSZ + 16); uint8_t *comp = av_malloc(2*MAXSZ + 16); uint8_t *decomp = av_malloc(MAXSZ + 16); size_t s = fread(orig, 1, MAXSZ, in); lzo_uint clen = 0; long tmp[LZO1X_MEM_COMPRESS]; int inlen, outlen; int i; av_log_set_level(AV_LOG_DEBUG); if (comp_level == 0) { lzo1x_1_compress(orig, s, comp, &clen, tmp); } else if (comp_level == 11) { lzo1x_1_11_compress(orig, s, comp, &clen, tmp); } else if (comp_level == 12) { lzo1x_1_12_compress(orig, s, comp, &clen, tmp); } else if (comp_level == 15) { lzo1x_1_15_compress(orig, s, comp, &clen, tmp); } else lzo1x_999_compress(orig, s, comp, &clen, tmp); for (i = 0; i < 300; i++) { inlen = clen; outlen = MAXSZ; #if BENCHMARK_LIBLZO_SAFE if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL)) #elif BENCHMARK_LIBLZO_UNSAFE if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL)) #else if (av_lzo1x_decode(decomp, &outlen, comp, &inlen)) #endif av_log(NULL, AV_LOG_ERROR, "decompression error\n"); } if (memcmp(orig, decomp, s)) av_log(NULL, AV_LOG_ERROR, "decompression incorrect\n"); else av_log(NULL, AV_LOG_ERROR, "decompression OK\n"); fclose(in); av_free(orig); av_free(comp); av_free(decomp); return 0; } ``` -------------------------------- ### VBN Compression and DXT Format Definitions (C) Source: https://ffmpeg.org/doxygen/8.0/vbn_8h_source Defines constants for VBN compression types and DXT (DirectX Texture Compression) formats. This includes no compression, LZW compression, and specific DXT formats like DXT1 and DXT5. ```c #define VBN_FORMAT_DXT1 2 #define VBN_FORMAT_DXT5 3 #define VBN_COMPRESSION_NONE 0 #define VBN_COMPRESSION_LZW 0x100 ``` -------------------------------- ### Function: compress_alpha - Compress Alpha Data Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c Compresses the alpha channel information from a block of pixels into a destination buffer 'dst'. Similar to compress_color, it uses the block stride for processing. ```c static void compress_alpha(uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_) ``` -------------------------------- ### LZSS Decompression (C) Source: https://ffmpeg.org/doxygen/8.0/aarch64_2h26x_2dsp_8h Implements the LZSS (Lempel–Ziv–Storer–Szymanski) compression algorithm for decompression. This is a dictionary-based compression method. ```c lzss_decompress(); lzss_uncompress(); ``` -------------------------------- ### Parse EXR Compression Type Source: https://ffmpeg.org/doxygen/8.0/exr_8c_source Reads the 'compression' attribute to identify the compression method used for the EXR image data. It expects a single byte value representing the compression type. If multiple compression attributes are found, a warning is logged, and only the first one is used. Unrecognized compression types are not explicitly handled beyond reading the value. ```c 201 } else if ((var_size = check_header_variable(s, "compression", 202 "compression", 29)) >= 0) { 203 if (!var_size) { 204 ret = AVERROR_INVALIDDATA; 205 goto fail; 206 } 207 208 if (s->compression == EXR_UNKN) 209 s->compression = bytestream2_get_byte(gb); 210 else { 211 bytestream2_skip(gb, 1); 212 av_log(s->avctx, AV_LOG_WARNING, 213 "Found more than one compression attribute.\n"); 214 } 215 216 continue; ``` -------------------------------- ### Encode Zlib: Zlib Compression Source: https://ffmpeg.org/doxygen/8.0/globals_func_e Applies Zlib compression to data. This is a general-purpose compression function used by various codecs that leverage Zlib. ```c // Placeholder for Zlib compression function // Actual implementation in flashsv2enc.c int encode_zlib(AVCodecContext *ctx, AVPacket *pkt) { return 0; } int encode_zlibprime(AVCodecContext *ctx, AVPacket *pkt) { return 0; } ``` -------------------------------- ### Run-Length Encoding Compression Source: https://ffmpeg.org/doxygen/8.0/exrenc_8c Performs Run-Length Encoding (RLE) compression on input data. It writes the compressed output to a specified buffer, ensuring not to exceed the provided output size. Returns the total size of the compressed data. ```c static int64_t rle_compress (uint8_t *out, int64_t out_size, const uint8_t *in, int64_t in_size) ``` -------------------------------- ### DXV Encoder Compression Function Source: https://ffmpeg.org/doxygen/8.0/dxvenc_8c_source Defines 'compress_tex', a function pointer within DXVEncContext, likely responsible for the texture compression process. ```c DXVEncContext::compress_tex int(* compress_tex)(AVCodecContext *avctx) **Definition:** dxvenc.c:64 ``` -------------------------------- ### C: Compress Color Blocks Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c_source This function compresses a color block, handling both constant and non-constant color cases. For constant colors, it uses lookup tables. For non-constant colors, it optimizes colors, determines solvability, and refines the color selection before writing the compressed data. ```c static void compress_color(uint8_t *dst, ptrdiff_t stride, const uint8_t *block) { uint32_t mask; uint16_t max16, min16; int constant = constant_color(block, stride); /* Constant color will load values from tables */ if (constant) { int r = block[0]; int g = block[1]; int b = block[2]; mask = 0xAAAAAAAA; max16 = (match5[r][0] << 11) | (match6[g][0] << 5) | match5[b][0]; min16 = (match5[r][1] << 11) | (match6[g][1] << 5) | match5[b][1]; } else { int refine; /* Otherwise find pca and map along principal axis */ optimize_colors(block, stride, &max16, &min16); if (max16 != min16) mask = match_colors(block, stride, max16, min16); else mask = 0; /* One pass refinement */ refine = refine_colors(block, stride, &max16, &min16, mask); if (refine) { if (max16 != min16) mask = match_colors(block, stride, max16, min16); else mask = 0; } } /* Finally write the color block */ if (max16 < min16) { FFSWAP(uint16_t, min16, max16); mask ^= 0x55555555; } AV_WL16(dst + 0, max16); AV_WL16(dst + 2, min16); AV_WL32(dst + 4, mask); } ``` -------------------------------- ### Compress Alpha Channel (C) Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c_source Compresses the alpha channel of a pixel block. It takes a destination buffer, stride, and the source pixel block as input. The function is defined in texturedspenc.c. ```c static void compress_alpha(uint8_t *dst, ptrdiff_t stride, const uint8_t *block) { // ... implementation details ... } ``` -------------------------------- ### Function zip_uncompress - C Source: https://ffmpeg.org/doxygen/8.0/exr_8c Decompresses data that was compressed using the ZIP (Deflate) algorithm within the EXR format. It takes compressed and uncompressed sizes as input and requires EXRThreadData for multi-threading. Defined in exr.c. ```c static int zip_uncompress(const EXRContext *_s_, const uint8_t *_src_, int _compressed_size_, int _uncompressed_size_, EXRThreadData *_td_) ``` -------------------------------- ### Compress Color RAM (C) Source: https://ffmpeg.org/doxygen/8.0/a64multienc_8c_source Compresses the color RAM data for the A64 codec. It takes a buffer, a charmap, and the colram as input. ```c static void a64_compress_colram(unsigned char *buf, int *charmap, uint8_t *colram) { // Implementation details... } ``` -------------------------------- ### FFmpeg Data Structures: Bitstream Size and Compression Source: https://ffmpeg.org/doxygen/8.0/structAGMContext This snippet shows the declaration of bitstream_size and compression within FFmpeg's data structures. bitstream_size represents the size of the compressed bitstream, and compression indicates the compression level or parameters. These fields are crucial for managing and analyzing compressed media data. ```cpp int | bitstream_size int | compression ``` -------------------------------- ### RLE Compress Row with FFmpeg Source: https://ffmpeg.org/doxygen/8.0/rle_8c_source The `ff_rle_encode` function compresses a row of pixels using Run-Length Encoding (RLE). It can handle both repeated pixel sequences (RLE) and uncompressed sequences (raw). The function returns the size of the compressed output or -1 if the output buffer is too small. ```c int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr, int bpp, int w, int add_rep, int xor_rep, int add_raw, int xor_raw) { int count, x; uint8_t *out = outbuf; for (x = 0; x < w; x += count) { /* see if we can encode the next set of pixels with RLE */ if ((count = ff_rle_count_pixels(ptr, w - x, bpp, 1)) > 1) { if (out + bpp + 1 > outbuf + out_size) return -1; *out++ = (count ^ xor_rep) + add_rep; memcpy(out, ptr, bpp); out += bpp; } else { /* fall back on uncompressed */ count = ff_rle_count_pixels(ptr, w - x, bpp, 0); if (out + bpp * count >= outbuf + out_size) return -1; *out++ = (count ^ xor_raw) + add_raw; memcpy(out, ptr, bpp * count); out += bpp * count; } ptr += count * bpp; } return out - outbuf; } ``` -------------------------------- ### Function huf_uncompress - C Source: https://ffmpeg.org/doxygen/8.0/exr_8c Decompresses data using Huffman coding. This function orchestrates the unpacking of the encoding table, building the decoding table, and then decoding the actual data. Defined in exr.c. ```c static int huf_uncompress(const EXRContext *_s_, EXRThreadData *_td_, GetByteContext *_gb_, uint16_t *_dst_, int _dst_size_) ``` -------------------------------- ### HAP Compressor Enumeration (C) Source: https://ffmpeg.org/doxygen/8.0/hap_8h_source Specifies the compression algorithms available for HAP streams. This includes options for no compression, Snappy compression, and a complex compression mode. ```c enum HapCompressor { HAP_COMP_NONE = 0xA0, HAP_COMP_SNAPPY = 0xB0, HAP_COMP_COMPLEX = 0xC0 }; ``` -------------------------------- ### Compress Coefficients for TNS (C) Source: https://ffmpeg.org/doxygen/8.0/aacenc__tns_8c_source Compresses coefficients used in Temporal Noise Shaping (TNS). This function attempts to reduce the number of bits required to represent coefficients. It is conditional on TNS_ENABLE_COEF_COMPRESSION being defined. If compression is not enabled or if coefficients do not meet certain criteria, it returns 0; otherwise, it modifies coefficients in-place and returns 1. ```c #include "lpc_functions.h" /* Could be set to 3 to save an additional bit at the cost of little quality */ #define TNS_Q_BITS 4 /* Coefficient resolution in short windows */ #define TNS_Q_BITS_IS8 4 /* We really need the bits we save here elsewhere */ #define TNS_ENABLE_COEF_COMPRESSION /* TNS will only be used if the LPC gain is within these margins */ #define TNS_GAIN_THRESHOLD_LOW 1.4f #define TNS_GAIN_THRESHOLD_HIGH 1.16f*TNS_GAIN_THRESHOLD_LOW static inline int compress_coeffs(int *coef, int order, int c_bits) { int i; const int low_idx = c_bits ? 4 : 2; const int shift_val = c_bits ? 8 : 4; const int high_idx = c_bits ? 11 : 5; #ifndef TNS_ENABLE_COEF_COMPRESSION return 0; #endif /* TNS_ENABLE_COEF_COMPRESSION */ for (i = 0; i < order; i++) if (coef[i] >= low_idx && coef[i] <= high_idx) return 0; for (i = 0; i < order; i++) coef[i] -= (coef[i] > high_idx) ? shift_val : 0; return 1; } ``` -------------------------------- ### DOVI Compression Enumeration Source: https://ffmpeg.org/doxygen/8.0/dovi__meta_8h Defines the possible compression methods for DOVI metadata. This enumeration specifies different levels of compression that can be applied. ```c enum AVDOVICompression { AV_DOVI_COMPRESSION_NONE = 0, AV_DOVI_COMPRESSION_LIMITED = 1, AV_DOVI_COMPRESSION_RESERVED = 2, AV_DOVI_COMPRESSION_EXTENDED = 3 } ``` -------------------------------- ### Hap Compressor Enumerations (C) Source: https://ffmpeg.org/doxygen/8.0/hap_8h Defines the available compression types for Hap video. Includes options for no compression, Snappy compression, and a more complex compression method. ```c enum HapCompressor { HAP_COMP_NONE, HAP_COMP_SNAPPY, HAP_COMP_COMPLEX }; // Definition at line 39 of file hap.h. ``` -------------------------------- ### Function: compress_color - Compress Color Data Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c Compresses the color information from a block of pixels into a destination buffer 'dst'. It utilizes helper functions like optimize_colors and refine_colors. The stride of the block is also provided. ```c static void compress_color(uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_) ``` -------------------------------- ### WebP Alpha Compression Enumeration Source: https://ffmpeg.org/doxygen/8.0/webp_8c Enumerates different methods for alpha channel compression in WebP images. It includes options for no compression and VP8L lossless compression. ```c enum AlphaCompression { ALPHA_COMPRESSION_NONE, ALPHA_COMPRESSION_VP8L }; ``` -------------------------------- ### Function rle_uncompress - C Source: https://ffmpeg.org/doxygen/8.0/exr_8c Decompresses data that was compressed using the Run-Length Encoding (RLE) method in EXR. It requires context, source data, sizes, and thread data. Defined in exr.c. ```c static int rle_uncompress(const EXRContext *_ctx_, const uint8_t *_src_, int _compressed_size_, int _uncompressed_size_, EXRThreadData *_td_) ``` -------------------------------- ### C Enum: Compression for compression algorithm types Source: https://ffmpeg.org/doxygen/8.0/g2meet_8c Enumerates different compression algorithms supported or used within the g2meet format. Currently lists two specific compression types: COMPR_EPIC_J_B and COMPR_KEMPF_J_B. Used to specify the decoding method for compressed data. ```c enum Compression --- Enumerator --- COMPR_EPIC_J_B | COMPR_KEMPF_J_B | ``` -------------------------------- ### FFmpeg compression Field Documentation Source: https://ffmpeg.org/doxygen/8.0/structLclEncContext Documentation for the 'compression' field within LclEncContext. This integer field is used to configure or represent the compression level or settings for FFmpeg's compression algorithms. Proper setting of this field can impact the trade-off between file size and compression/decompression speed. ```c int compression; ``` -------------------------------- ### Decompress DXT2 Texture Blocks (C) Source: https://ffmpeg.org/doxygen/8.0/texturedsp_8c Decompresses a single block of DXT2 texture data into RGBA pixels. This format includes premultiplied alpha. It takes the destination buffer, stride, and the compressed block as input. It returns the amount of texture data consumed. ```c static int dxt2_block( uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_ ) { // ... implementation details ... return consumed_data; } ``` -------------------------------- ### FFmpeg cpia Compression Status Macros Source: https://ffmpeg.org/doxygen/8.0/cpia_8c Defines constants for compression status in the cpia stream. NOT_COMPRESSED and COMPRESSED indicate whether data is uncompressed or compressed. ```c #define NOT_COMPRESSED 0 #define COMPRESSED 1 ``` -------------------------------- ### Initialize Deflate Compression - C Source: https://ffmpeg.org/doxygen/8.0/pngenc_8c_source Initializes the deflate compression stream. This is a wrapper around deflateInit() and is used for data compression, particularly in formats like PNG. ```c int ff_deflate_init(FFZStream *zstream, int level, void *logctx) { // ... implementation details ... } ``` -------------------------------- ### Compress ADPCM MS Sample (C) Source: https://ffmpeg.org/doxygen/8.0/adpcmenc_8c Compresses a single audio sample using the ADPCM MS (Microsoft) algorithm. It takes an ADPCMChannelStatus pointer and an int16_t sample, returning the resulting compressed byte. ```c static uint8_t adpcm_ms_compress_sample(ADPCMChannelStatus *c, int16_t sample) ``` -------------------------------- ### Decompress DXT4 Texture Blocks (C) Source: https://ffmpeg.org/doxygen/8.0/texturedsp_8c Decompresses a single block of DXT4 texture data into RGBA pixels. This format uses interpolated alpha. It takes the destination buffer, stride, and the compressed block as input. It returns the amount of texture data consumed. ```c static int dxt4_block( uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_ ) { // ... implementation details ... return consumed_data; } ``` -------------------------------- ### VP5 Compression Percentage Tables (C) Source: https://ffmpeg.org/doxygen/8.0/vp5data_8h_source These C arrays define percentage tables used in VP5 compression. They are organized by various compression modes and color components, influencing the compression ratios. ```c static const uint8_t vp5_vmc_pct[2][11] = { { 243, 220, 251, 253, 237, 232, 241, 245, 247, 251, 253 }, { 235, 211, 246, 249, 234, 231, 248, 249, 252, 252, 254 }, }; static const uint8_t vp5_dccv_pct[2][11] = { { 146, 197, 181, 207, 232, 243, 238, 251, 244, 250, 249 }, { 179, 219, 214, 240, 250, 254, 244, 254, 254, 254, 254 }, }; static const uint8_t vp5_ract_pct[3][2][6][11] = { { { { 227, 246, 230, 247, 244, 254, 254, 254, 254, 254, 254 }, { 202, 254, 209, 231, 231, 249, 249, 253, 254, 254, 254 }, { 206, 254, 225, 242, 241, 251, 253, 254, 254, 254, 254 }, { 235, 254, 241, 253, 252, 254, 254, 254, 254, 254, 254 }, { 234, 254, 248, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } }, { { 240, 254, 248, 254, 254, 254, 254, 254, 254, 254, 254 }, { 238, 254, 240, 253, 254, 254, 254, 254, 254, 254, 254 }, { 244, 254, 251, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } } }, { { { 206, 203, 227, 239, 247, 254, 253, 254, 254, 253, 254 }, { 207, 199, 220, 236, 243, 252, 252, 254, 254, 254, 254 }, { 212, 219, 230, 243, 244, 253, 252, 254, 254, 254, 254 }, { 236, 237, 247, 252, 253, 254, 254, 254, 254, 254, 254 }, { 240, 240, 248, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } }, { { 230, 233, 249, 254, 254, 254, 254, 254, 254, 254, 254 }, { 238, 238, 250, 254, 254, 254, 254, 254, 254, 254, 254 }, { 248, 251, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } } }, { { { 225, 239, 227, 231, 244, 253, 243, 254, 254, 253, 254 }, { 232, 234, 224, 228, 242, 249, 242, 252, 251, 251, 254 }, { 235, 249, 238, 240, 251, 254, 249, 254, 253, 253, 254 }, { 249, 253, 251, 250, 254, 254, 254, 254, 254, 254, 254 }, { 251, 250, 249, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } }, { { 243, 244, 250, 250, 254, 254, 254, 254, 254, 254, 254 }, { 249, 248, 250, 253, 254, 254, 254, 254, 254, 254, 254 }, { 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 }, { 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254 } } }}; ``` -------------------------------- ### LZW Main Compress Function Source: https://ffmpeg.org/doxygen/8.0/lzwenc_8c Performs the main LZW compression of the input data. ```APIDOC ## ff_lzw_encode() ### Description LZW main compress function. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **s** (LZWEncodeState *) - Pointer to the LZW encoder state structure. - **inbuf** (const uint8_t *) - Pointer to the input buffer containing data to be compressed. - **insize** (int) - The size of the input buffer. ### Request Example ```c LZWEncodeState state; uint8_t input_data[] = { ... }; int compressed_size = ff_lzw_encode(&state, input_data, sizeof(input_data)); ``` ### Response #### Success Response (int) - Number of bytes written to the output buffer. Returns the number of bytes written to the output buffer by the compression process. #### Response Example ``` 1024 ``` ``` -------------------------------- ### Handle EXR Compression Settings - C Source: https://ffmpeg.org/doxygen/8.0/exr_8c_source Configures the `scan_lines_per_block` based on the EXR compression type. It maps different compression schemes like EXR_RLE, EXR_ZIP16, EXR_PIZ, and EXR_DWAB to specific block sizes for efficient decoding. Includes error handling for unsupported compression types. ```c switch (s->compression) { case EXR_RAW: case EXR_RLE: case EXR_ZIP1: s->scan_lines_per_block = 1; break; case EXR_PXR24: case EXR_ZIP16: s->scan_lines_per_block = 16; break; case EXR_PIZ: case EXR_B44: case EXR_B44A: case EXR_DWAA: s->scan_lines_per_block = 32; break; case EXR_DWAB: s->scan_lines_per_block = 256; break; default: avpriv_report_missing_feature(avctx, "Compression %d", s->compression); return AVERROR_PATCHWELCOME; } ``` -------------------------------- ### Decompress DXT5 Texture Blocks (C) Source: https://ffmpeg.org/doxygen/8.0/texturedsp_8c Decompresses a single block of DXT5 texture data into RGBA pixels. This format uses interpolated alpha, similar to DXT4 but with a different encoding. It takes the destination buffer, stride, and the compressed block as input. It returns the amount of texture data consumed. ```c static int dxt5_block( uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_ ) { // ... implementation details ... return consumed_data; } ``` -------------------------------- ### FFmpeg TIFF Compression Handling Source: https://ffmpeg.org/doxygen/8.0/tiff_8c_source This C code snippet demonstrates how FFmpeg handles different TIFF compression types. It includes checks for enabled compression libraries like ZLib and LZMA, returning an error if they are not compiled in. It also identifies JPEG compression and logs unknown compression methods. ```c #if CONFIG_ZLIB break; #else av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n"); return AVERROR(ENOSYS); #endif case TIFF_JPEG: case TIFF_NEWJPEG: s->is_jpeg = 1; break; case TIFF_LZMA: #if CONFIG_LZMA break; #else av_log(s->avctx, AV_LOG_ERROR, "LZMA not compiled in\n"); return AVERROR(ENOSYS); #endif default: av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n", s->compr); return AVERROR_INVALIDDATA; } break; ``` -------------------------------- ### Texture Compression Function Source: https://ffmpeg.org/doxygen/8.0/hapenc_8c_source The `compress_texture` function is designed to compress texture data. It takes an AVCodecContext, output buffer, output length, and the input AVFrame. This function is likely used within the HAP encoding process for efficient texture data handling. ```c static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, const AVFrame *f) ``` -------------------------------- ### HAP Compression Type Definitions Source: https://ffmpeg.org/doxygen/8.0/hapenc_8c_source Definitions for HAP compression methods, including Snappy, None, and Complex. These are used to specify how image data is compressed within HAP chunks. ```c #define HAP_COMP_SNAPPY @ HAP_COMP_SNAPPY ``` ```c #define HAP_COMP_NONE @ HAP_COMP_NONE ``` ```c #define HAP_COMP_COMPLEX @ HAP_COMP_COMPLEX ``` -------------------------------- ### C Enum: ChunkType and Compression Source: https://ffmpeg.org/doxygen/8.0/g2meet_8c Defines enumerations for ChunkType and Compression used within the decoder. ChunkType specifies different data chunk identifiers, while Compression defines various compression methods. ```c enum | ChunkType { DISPLAY_INFO = 0xC8, TILE_DATA, CURSOR_POS, CURSOR_SHAPE, CHUNK_CC, CHUNK_CD, CHUNK_TYPE_DATA = 0x4424, CHUNK_TYPE_ASF_HEADER = 0x4824, CHUNK_TYPE_END = 0x4524, CHUNK_TYPE_STREAM_CHANGE = 0x4324 } enum | Compression { COMPR_EPIC_J_B = 2, COMPR_KEMPF_J_B } ``` -------------------------------- ### Function: dxt5_block - Compress RGBA to DXT5 Texture Source: https://ffmpeg.org/doxygen/8.0/texturedspenc_8c Compresses a 4x4 block of RGBA pixels into the DXT5 texture format. DXT5 supports alpha channels with interpolated or explicit alpha values. The compressed data is written to 'dst'. ```c static int dxt5_block(uint8_t *_dst_, ptrdiff_t _stride_, const uint8_t *_block_) ``` -------------------------------- ### BMP Compression Types Enum (C) Source: https://ffmpeg.org/doxygen/8.0/bmp_8h_source Defines an enumeration `BiCompression` for BMP image compression types. This enum is used internally by FFmpeg's BMP codecs to specify the compression method. It includes definitions for uncompressed RGB, RLE8, RLE4, and BITFIELDS compression. ```c #ifndef AVCODEC_BMP_H #define AVCODEC_BMP_H typedef enum { BMP_RGB =0, BMP_RLE8 =1, BMP_RLE4 =2, BMP_BITFIELDS =3, } BiCompression; #endif /* AVCODEC_BMP_H */ ``` -------------------------------- ### Compress ADPCM Yamaha Sample (C) Source: https://ffmpeg.org/doxygen/8.0/adpcmenc_8c Compresses a single audio sample using the ADPCM Yamaha algorithm. This inline static function takes an ADPCMChannelStatus pointer and an int16_t sample, returning the compressed byte. ```c static uint8_t adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, int16_t sample) ``` -------------------------------- ### DoviRpuContext::compression Field - C++ Source: https://ffmpeg.org/doxygen/8.0/structDoviRpuContext Detailed documentation for the 'compression' field within the DoviRpuContext structure. This field is an integer and is defined in libavcodec/bsf/dovi_rpu.c. ```cpp int DoviRpuContext::compression; ``` -------------------------------- ### AVPacket Structure for Compressed Data Source: https://ffmpeg.org/doxygen/8.0/bmvvideo_8c_source The AVPacket structure in FFmpeg is used to store compressed data. It contains information such as the size of the compressed data, presentation timestamps, and other metadata. This is fundamental for handling compressed streams. ```c typedef struct AVPacket { // ... other members ... int size; // size of the compressed data // ... other members ... } AVPacket; ``` -------------------------------- ### TIFF Strip Encoding with Compression (C) Source: https://ffmpeg.org/doxygen/8.0/tiffenc_8c_source Encodes a single image strip using various compression methods supported by FFmpeg's TIFF encoder. It supports raw data, RLE (PackBits), LZW, and Deflate (Zlib). Error handling is included for unsupported compression types and compression failures. ```c static int encode_strip(TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr) { switch (compr) { #if CONFIG_ZLIB case TIFF_DEFLATE: case TIFF_ADOBE_DEFLATE: { unsigned long zlen = s->buf_size - (*s->buf - s->buf_start); if (compress(dst, &zlen, src, n) != Z_OK) { av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n"); return AVERROR_EXTERNAL; } return zlen; } #endif case TIFF_RAW: if (check_size(s, n)) return AVERROR(EINVAL); memcpy(dst, src, n); return n; case TIFF_PACKBITS: return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), src, 1, n, 2, 0xff, -1, 0); case TIFF_LZW: return ff_lzw_encode(s->lzws, src, n); default: av_log(s->avctx, AV_LOG_ERROR, "Unsupported compression method: %d\n", compr); return AVERROR(EINVAL); } } ``` -------------------------------- ### AVPacket Structure for Compressed Data Source: https://ffmpeg.org/doxygen/8.0/pngenc_8c_source The AVPacket structure stores compressed data, representing a chunk of compressed media. It includes data pointers, size, and timestamp information. This is essential for handling compressed streams. ```c typedef struct AVPacket { ... } AVPacket; ```