Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/include/webp
File: encode.h
// Copyright 2011 Google Inc. All Rights Reserved.
[0] Fix | Delete
//
[1] Fix | Delete
// Use of this source code is governed by a BSD-style license
[2] Fix | Delete
// that can be found in the COPYING file in the root of the source
[3] Fix | Delete
// tree. An additional intellectual property rights grant can be found
[4] Fix | Delete
// in the file PATENTS. All contributing project authors may
[5] Fix | Delete
// be found in the AUTHORS file in the root of the source tree.
[6] Fix | Delete
// -----------------------------------------------------------------------------
[7] Fix | Delete
//
[8] Fix | Delete
// WebP encoder: main interface
[9] Fix | Delete
//
[10] Fix | Delete
// Author: Skal (pascal.massimino@gmail.com)
[11] Fix | Delete
[12] Fix | Delete
#ifndef WEBP_WEBP_ENCODE_H_
[13] Fix | Delete
#define WEBP_WEBP_ENCODE_H_
[14] Fix | Delete
[15] Fix | Delete
#include "./types.h"
[16] Fix | Delete
[17] Fix | Delete
#ifdef __cplusplus
[18] Fix | Delete
extern "C" {
[19] Fix | Delete
#endif
[20] Fix | Delete
[21] Fix | Delete
#define WEBP_ENCODER_ABI_VERSION 0x020e // MAJOR(8b) + MINOR(8b)
[22] Fix | Delete
[23] Fix | Delete
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
[24] Fix | Delete
// the types are left here for reference.
[25] Fix | Delete
// typedef enum WebPImageHint WebPImageHint;
[26] Fix | Delete
// typedef enum WebPEncCSP WebPEncCSP;
[27] Fix | Delete
// typedef enum WebPPreset WebPPreset;
[28] Fix | Delete
// typedef enum WebPEncodingError WebPEncodingError;
[29] Fix | Delete
typedef struct WebPConfig WebPConfig;
[30] Fix | Delete
typedef struct WebPPicture WebPPicture; // main structure for I/O
[31] Fix | Delete
typedef struct WebPAuxStats WebPAuxStats;
[32] Fix | Delete
typedef struct WebPMemoryWriter WebPMemoryWriter;
[33] Fix | Delete
[34] Fix | Delete
// Return the encoder's version number, packed in hexadecimal using 8bits for
[35] Fix | Delete
// each of major/minor/revision. E.g: v2.5.7 is 0x020507.
[36] Fix | Delete
WEBP_EXTERN int WebPGetEncoderVersion(void);
[37] Fix | Delete
[38] Fix | Delete
//------------------------------------------------------------------------------
[39] Fix | Delete
// One-stop-shop call! No questions asked:
[40] Fix | Delete
[41] Fix | Delete
// Returns the size of the compressed data (pointed to by *output), or 0 if
[42] Fix | Delete
// an error occurred. The compressed data must be released by the caller
[43] Fix | Delete
// using the call 'WebPFree(*output)'.
[44] Fix | Delete
// These functions compress using the lossy format, and the quality_factor
[45] Fix | Delete
// can go from 0 (smaller output, lower quality) to 100 (best quality,
[46] Fix | Delete
// larger output).
[47] Fix | Delete
WEBP_EXTERN size_t WebPEncodeRGB(const uint8_t* rgb,
[48] Fix | Delete
int width, int height, int stride,
[49] Fix | Delete
float quality_factor, uint8_t** output);
[50] Fix | Delete
WEBP_EXTERN size_t WebPEncodeBGR(const uint8_t* bgr,
[51] Fix | Delete
int width, int height, int stride,
[52] Fix | Delete
float quality_factor, uint8_t** output);
[53] Fix | Delete
WEBP_EXTERN size_t WebPEncodeRGBA(const uint8_t* rgba,
[54] Fix | Delete
int width, int height, int stride,
[55] Fix | Delete
float quality_factor, uint8_t** output);
[56] Fix | Delete
WEBP_EXTERN size_t WebPEncodeBGRA(const uint8_t* bgra,
[57] Fix | Delete
int width, int height, int stride,
[58] Fix | Delete
float quality_factor, uint8_t** output);
[59] Fix | Delete
[60] Fix | Delete
// These functions are the equivalent of the above, but compressing in a
[61] Fix | Delete
// lossless manner. Files are usually larger than lossy format, but will
[62] Fix | Delete
// not suffer any compression loss.
[63] Fix | Delete
WEBP_EXTERN size_t WebPEncodeLosslessRGB(const uint8_t* rgb,
[64] Fix | Delete
int width, int height, int stride,
[65] Fix | Delete
uint8_t** output);
[66] Fix | Delete
WEBP_EXTERN size_t WebPEncodeLosslessBGR(const uint8_t* bgr,
[67] Fix | Delete
int width, int height, int stride,
[68] Fix | Delete
uint8_t** output);
[69] Fix | Delete
WEBP_EXTERN size_t WebPEncodeLosslessRGBA(const uint8_t* rgba,
[70] Fix | Delete
int width, int height, int stride,
[71] Fix | Delete
uint8_t** output);
[72] Fix | Delete
WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra,
[73] Fix | Delete
int width, int height, int stride,
[74] Fix | Delete
uint8_t** output);
[75] Fix | Delete
[76] Fix | Delete
// Releases memory returned by the WebPEncode*() functions above.
[77] Fix | Delete
WEBP_EXTERN void WebPFree(void* ptr);
[78] Fix | Delete
[79] Fix | Delete
//------------------------------------------------------------------------------
[80] Fix | Delete
// Coding parameters
[81] Fix | Delete
[82] Fix | Delete
// Image characteristics hint for the underlying encoder.
[83] Fix | Delete
typedef enum WebPImageHint {
[84] Fix | Delete
WEBP_HINT_DEFAULT = 0, // default preset.
[85] Fix | Delete
WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot
[86] Fix | Delete
WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting
[87] Fix | Delete
WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc).
[88] Fix | Delete
WEBP_HINT_LAST
[89] Fix | Delete
} WebPImageHint;
[90] Fix | Delete
[91] Fix | Delete
// Compression parameters.
[92] Fix | Delete
struct WebPConfig {
[93] Fix | Delete
int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
[94] Fix | Delete
float quality; // between 0 and 100. For lossy, 0 gives the smallest
[95] Fix | Delete
// size and 100 the largest. For lossless, this
[96] Fix | Delete
// parameter is the amount of effort put into the
[97] Fix | Delete
// compression: 0 is the fastest but gives larger
[98] Fix | Delete
// files compared to the slowest, but best, 100.
[99] Fix | Delete
int method; // quality/speed trade-off (0=fast, 6=slower-better)
[100] Fix | Delete
[101] Fix | Delete
WebPImageHint image_hint; // Hint for image type (lossless only for now).
[102] Fix | Delete
[103] Fix | Delete
int target_size; // if non-zero, set the desired target size in bytes.
[104] Fix | Delete
// Takes precedence over the 'compression' parameter.
[105] Fix | Delete
float target_PSNR; // if non-zero, specifies the minimal distortion to
[106] Fix | Delete
// try to achieve. Takes precedence over target_size.
[107] Fix | Delete
int segments; // maximum number of segments to use, in [1..4]
[108] Fix | Delete
int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum.
[109] Fix | Delete
int filter_strength; // range: [0 = off .. 100 = strongest]
[110] Fix | Delete
int filter_sharpness; // range: [0 = off .. 7 = least sharp]
[111] Fix | Delete
int filter_type; // filtering type: 0 = simple, 1 = strong (only used
[112] Fix | Delete
// if filter_strength > 0 or autofilter > 0)
[113] Fix | Delete
int autofilter; // Auto adjust filter's strength [0 = off, 1 = on]
[114] Fix | Delete
int alpha_compression; // Algorithm for encoding the alpha plane (0 = none,
[115] Fix | Delete
// 1 = compressed with WebP lossless). Default is 1.
[116] Fix | Delete
int alpha_filtering; // Predictive filtering method for alpha plane.
[117] Fix | Delete
// 0: none, 1: fast, 2: best. Default if 1.
[118] Fix | Delete
int alpha_quality; // Between 0 (smallest size) and 100 (lossless).
[119] Fix | Delete
// Default is 100.
[120] Fix | Delete
int pass; // number of entropy-analysis passes (in [1..10]).
[121] Fix | Delete
[122] Fix | Delete
int show_compressed; // if true, export the compressed picture back.
[123] Fix | Delete
// In-loop filtering is not applied.
[124] Fix | Delete
int preprocessing; // preprocessing filter:
[125] Fix | Delete
// 0=none, 1=segment-smooth, 2=pseudo-random dithering
[126] Fix | Delete
int partitions; // log2(number of token partitions) in [0..3]. Default
[127] Fix | Delete
// is set to 0 for easier progressive decoding.
[128] Fix | Delete
int partition_limit; // quality degradation allowed to fit the 512k limit
[129] Fix | Delete
// on prediction modes coding (0: no degradation,
[130] Fix | Delete
// 100: maximum possible degradation).
[131] Fix | Delete
int emulate_jpeg_size; // If true, compression parameters will be remapped
[132] Fix | Delete
// to better match the expected output size from
[133] Fix | Delete
// JPEG compression. Generally, the output size will
[134] Fix | Delete
// be similar but the degradation will be lower.
[135] Fix | Delete
int thread_level; // If non-zero, try and use multi-threaded encoding.
[136] Fix | Delete
int low_memory; // If set, reduce memory usage (but increase CPU use).
[137] Fix | Delete
[138] Fix | Delete
int near_lossless; // Near lossless encoding [0 = max loss .. 100 = off
[139] Fix | Delete
// (default)].
[140] Fix | Delete
int exact; // if non-zero, preserve the exact RGB values under
[141] Fix | Delete
// transparent area. Otherwise, discard this invisible
[142] Fix | Delete
// RGB information for better compression. The default
[143] Fix | Delete
// value is 0.
[144] Fix | Delete
[145] Fix | Delete
int use_delta_palette; // reserved for future lossless feature
[146] Fix | Delete
int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion
[147] Fix | Delete
[148] Fix | Delete
uint32_t pad[2]; // padding for later use
[149] Fix | Delete
};
[150] Fix | Delete
[151] Fix | Delete
// Enumerate some predefined settings for WebPConfig, depending on the type
[152] Fix | Delete
// of source picture. These presets are used when calling WebPConfigPreset().
[153] Fix | Delete
typedef enum WebPPreset {
[154] Fix | Delete
WEBP_PRESET_DEFAULT = 0, // default preset.
[155] Fix | Delete
WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot
[156] Fix | Delete
WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting
[157] Fix | Delete
WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details
[158] Fix | Delete
WEBP_PRESET_ICON, // small-sized colorful images
[159] Fix | Delete
WEBP_PRESET_TEXT // text-like
[160] Fix | Delete
} WebPPreset;
[161] Fix | Delete
[162] Fix | Delete
// Internal, version-checked, entry point
[163] Fix | Delete
WEBP_EXTERN int WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int);
[164] Fix | Delete
[165] Fix | Delete
// Should always be called, to initialize a fresh WebPConfig structure before
[166] Fix | Delete
// modification. Returns false in case of version mismatch. WebPConfigInit()
[167] Fix | Delete
// must have succeeded before using the 'config' object.
[168] Fix | Delete
// Note that the default values are lossless=0 and quality=75.
[169] Fix | Delete
static WEBP_INLINE int WebPConfigInit(WebPConfig* config) {
[170] Fix | Delete
return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f,
[171] Fix | Delete
WEBP_ENCODER_ABI_VERSION);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
// This function will initialize the configuration according to a predefined
[175] Fix | Delete
// set of parameters (referred to by 'preset') and a given quality factor.
[176] Fix | Delete
// This function can be called as a replacement to WebPConfigInit(). Will
[177] Fix | Delete
// return false in case of error.
[178] Fix | Delete
static WEBP_INLINE int WebPConfigPreset(WebPConfig* config,
[179] Fix | Delete
WebPPreset preset, float quality) {
[180] Fix | Delete
return WebPConfigInitInternal(config, preset, quality,
[181] Fix | Delete
WEBP_ENCODER_ABI_VERSION);
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
// Activate the lossless compression mode with the desired efficiency level
[185] Fix | Delete
// between 0 (fastest, lowest compression) and 9 (slower, best compression).
[186] Fix | Delete
// A good default level is '6', providing a fair tradeoff between compression
[187] Fix | Delete
// speed and final compressed size.
[188] Fix | Delete
// This function will overwrite several fields from config: 'method', 'quality'
[189] Fix | Delete
// and 'lossless'. Returns false in case of parameter error.
[190] Fix | Delete
WEBP_EXTERN int WebPConfigLosslessPreset(WebPConfig* config, int level);
[191] Fix | Delete
[192] Fix | Delete
// Returns true if 'config' is non-NULL and all configuration parameters are
[193] Fix | Delete
// within their valid ranges.
[194] Fix | Delete
WEBP_EXTERN int WebPValidateConfig(const WebPConfig* config);
[195] Fix | Delete
[196] Fix | Delete
//------------------------------------------------------------------------------
[197] Fix | Delete
// Input / Output
[198] Fix | Delete
// Structure for storing auxiliary statistics.
[199] Fix | Delete
[200] Fix | Delete
struct WebPAuxStats {
[201] Fix | Delete
int coded_size; // final size
[202] Fix | Delete
[203] Fix | Delete
float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha
[204] Fix | Delete
int block_count[3]; // number of intra4/intra16/skipped macroblocks
[205] Fix | Delete
int header_bytes[2]; // approximate number of bytes spent for header
[206] Fix | Delete
// and mode-partition #0
[207] Fix | Delete
int residual_bytes[3][4]; // approximate number of bytes spent for
[208] Fix | Delete
// DC/AC/uv coefficients for each (0..3) segments.
[209] Fix | Delete
int segment_size[4]; // number of macroblocks in each segments
[210] Fix | Delete
int segment_quant[4]; // quantizer values for each segments
[211] Fix | Delete
int segment_level[4]; // filtering strength for each segments [0..63]
[212] Fix | Delete
[213] Fix | Delete
int alpha_data_size; // size of the transparency data
[214] Fix | Delete
int layer_data_size; // size of the enhancement layer data
[215] Fix | Delete
[216] Fix | Delete
// lossless encoder statistics
[217] Fix | Delete
uint32_t lossless_features; // bit0:predictor bit1:cross-color transform
[218] Fix | Delete
// bit2:subtract-green bit3:color indexing
[219] Fix | Delete
int histogram_bits; // number of precision bits of histogram
[220] Fix | Delete
int transform_bits; // precision bits for transform
[221] Fix | Delete
int cache_bits; // number of bits for color cache lookup
[222] Fix | Delete
int palette_size; // number of color in palette, if used
[223] Fix | Delete
int lossless_size; // final lossless size
[224] Fix | Delete
int lossless_hdr_size; // lossless header (transform, huffman etc) size
[225] Fix | Delete
int lossless_data_size; // lossless image data size
[226] Fix | Delete
[227] Fix | Delete
uint32_t pad[2]; // padding for later use
[228] Fix | Delete
};
[229] Fix | Delete
[230] Fix | Delete
// Signature for output function. Should return true if writing was successful.
[231] Fix | Delete
// data/data_size is the segment of data to write, and 'picture' is for
[232] Fix | Delete
// reference (and so one can make use of picture->custom_ptr).
[233] Fix | Delete
typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size,
[234] Fix | Delete
const WebPPicture* picture);
[235] Fix | Delete
[236] Fix | Delete
// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using
[237] Fix | Delete
// the following WebPMemoryWriter object (to be set as a custom_ptr).
[238] Fix | Delete
struct WebPMemoryWriter {
[239] Fix | Delete
uint8_t* mem; // final buffer (of size 'max_size', larger than 'size').
[240] Fix | Delete
size_t size; // final size
[241] Fix | Delete
size_t max_size; // total capacity
[242] Fix | Delete
uint32_t pad[1]; // padding for later use
[243] Fix | Delete
};
[244] Fix | Delete
[245] Fix | Delete
// The following must be called first before any use.
[246] Fix | Delete
WEBP_EXTERN void WebPMemoryWriterInit(WebPMemoryWriter* writer);
[247] Fix | Delete
[248] Fix | Delete
// The following must be called to deallocate writer->mem memory. The 'writer'
[249] Fix | Delete
// object itself is not deallocated.
[250] Fix | Delete
WEBP_EXTERN void WebPMemoryWriterClear(WebPMemoryWriter* writer);
[251] Fix | Delete
// The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon
[252] Fix | Delete
// completion, writer.mem and writer.size will hold the coded data.
[253] Fix | Delete
// writer.mem must be freed by calling WebPMemoryWriterClear.
[254] Fix | Delete
WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size,
[255] Fix | Delete
const WebPPicture* picture);
[256] Fix | Delete
[257] Fix | Delete
// Progress hook, called from time to time to report progress. It can return
[258] Fix | Delete
// false to request an abort of the encoding process, or true otherwise if
[259] Fix | Delete
// everything is OK.
[260] Fix | Delete
typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture);
[261] Fix | Delete
[262] Fix | Delete
// Color spaces.
[263] Fix | Delete
typedef enum WebPEncCSP {
[264] Fix | Delete
// chroma sampling
[265] Fix | Delete
WEBP_YUV420 = 0, // 4:2:0
[266] Fix | Delete
WEBP_YUV420A = 4, // alpha channel variant
[267] Fix | Delete
WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors
[268] Fix | Delete
WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present
[269] Fix | Delete
} WebPEncCSP;
[270] Fix | Delete
[271] Fix | Delete
// Encoding error conditions.
[272] Fix | Delete
typedef enum WebPEncodingError {
[273] Fix | Delete
VP8_ENC_OK = 0,
[274] Fix | Delete
VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects
[275] Fix | Delete
VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits
[276] Fix | Delete
VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL
[277] Fix | Delete
VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid
[278] Fix | Delete
VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height
[279] Fix | Delete
VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k
[280] Fix | Delete
VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M
[281] Fix | Delete
VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes
[282] Fix | Delete
VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G
[283] Fix | Delete
VP8_ENC_ERROR_USER_ABORT, // abort request by user
[284] Fix | Delete
VP8_ENC_ERROR_LAST // list terminator. always last.
[285] Fix | Delete
} WebPEncodingError;
[286] Fix | Delete
[287] Fix | Delete
// maximum width/height allowed (inclusive), in pixels
[288] Fix | Delete
#define WEBP_MAX_DIMENSION 16383
[289] Fix | Delete
[290] Fix | Delete
// Main exchange structure (input samples, output bytes, statistics)
[291] Fix | Delete
struct WebPPicture {
[292] Fix | Delete
// INPUT
[293] Fix | Delete
//////////////
[294] Fix | Delete
// Main flag for encoder selecting between ARGB or YUV input.
[295] Fix | Delete
// It is recommended to use ARGB input (*argb, argb_stride) for lossless
[296] Fix | Delete
// compression, and YUV input (*y, *u, *v, etc.) for lossy compression
[297] Fix | Delete
// since these are the respective native colorspace for these formats.
[298] Fix | Delete
int use_argb;
[299] Fix | Delete
[300] Fix | Delete
// YUV input (mostly used for input to lossy compression)
[301] Fix | Delete
WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr).
[302] Fix | Delete
int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION)
[303] Fix | Delete
uint8_t *y, *u, *v; // pointers to luma/chroma planes.
[304] Fix | Delete
int y_stride, uv_stride; // luma/chroma strides.
[305] Fix | Delete
uint8_t* a; // pointer to the alpha plane
[306] Fix | Delete
int a_stride; // stride of the alpha plane
[307] Fix | Delete
uint32_t pad1[2]; // padding for later use
[308] Fix | Delete
[309] Fix | Delete
// ARGB input (mostly used for input to lossless compression)
[310] Fix | Delete
uint32_t* argb; // Pointer to argb (32 bit) plane.
[311] Fix | Delete
int argb_stride; // This is stride in pixels units, not bytes.
[312] Fix | Delete
uint32_t pad2[3]; // padding for later use
[313] Fix | Delete
[314] Fix | Delete
// OUTPUT
[315] Fix | Delete
///////////////
[316] Fix | Delete
// Byte-emission hook, to store compressed bytes as they are ready.
[317] Fix | Delete
WebPWriterFunction writer; // can be NULL
[318] Fix | Delete
void* custom_ptr; // can be used by the writer.
[319] Fix | Delete
[320] Fix | Delete
// map for extra information (only for lossy compression mode)
[321] Fix | Delete
int extra_info_type; // 1: intra type, 2: segment, 3: quant
[322] Fix | Delete
// 4: intra-16 prediction mode,
[323] Fix | Delete
// 5: chroma prediction mode,
[324] Fix | Delete
// 6: bit cost, 7: distortion
[325] Fix | Delete
uint8_t* extra_info; // if not NULL, points to an array of size
[326] Fix | Delete
// ((width + 15) / 16) * ((height + 15) / 16) that
[327] Fix | Delete
// will be filled with a macroblock map, depending
[328] Fix | Delete
// on extra_info_type.
[329] Fix | Delete
[330] Fix | Delete
// STATS AND REPORTS
[331] Fix | Delete
///////////////////////////
[332] Fix | Delete
// Pointer to side statistics (updated only if not NULL)
[333] Fix | Delete
WebPAuxStats* stats;
[334] Fix | Delete
[335] Fix | Delete
// Error code for the latest error encountered during encoding
[336] Fix | Delete
WebPEncodingError error_code;
[337] Fix | Delete
[338] Fix | Delete
// If not NULL, report progress during encoding.
[339] Fix | Delete
WebPProgressHook progress_hook;
[340] Fix | Delete
[341] Fix | Delete
void* user_data; // this field is free to be set to any value and
[342] Fix | Delete
// used during callbacks (like progress-report e.g.).
[343] Fix | Delete
[344] Fix | Delete
uint32_t pad3[3]; // padding for later use
[345] Fix | Delete
[346] Fix | Delete
// Unused for now
[347] Fix | Delete
uint8_t *pad4, *pad5;
[348] Fix | Delete
uint32_t pad6[8]; // padding for later use
[349] Fix | Delete
[350] Fix | Delete
// PRIVATE FIELDS
[351] Fix | Delete
////////////////////
[352] Fix | Delete
void* memory_; // row chunk of memory for yuva planes
[353] Fix | Delete
void* memory_argb_; // and for argb too.
[354] Fix | Delete
void* pad7[2]; // padding for later use
[355] Fix | Delete
};
[356] Fix | Delete
[357] Fix | Delete
// Internal, version-checked, entry point
[358] Fix | Delete
WEBP_EXTERN int WebPPictureInitInternal(WebPPicture*, int);
[359] Fix | Delete
[360] Fix | Delete
// Should always be called, to initialize the structure. Returns false in case
[361] Fix | Delete
// of version mismatch. WebPPictureInit() must have succeeded before using the
[362] Fix | Delete
// 'picture' object.
[363] Fix | Delete
// Note that, by default, use_argb is false and colorspace is WEBP_YUV420.
[364] Fix | Delete
static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) {
[365] Fix | Delete
return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION);
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
//------------------------------------------------------------------------------
[369] Fix | Delete
// WebPPicture utils
[370] Fix | Delete
[371] Fix | Delete
// Convenience allocation / deallocation based on picture->width/height:
[372] Fix | Delete
// Allocate y/u/v buffers as per colorspace/width/height specification.
[373] Fix | Delete
// Note! This function will free the previous buffer if needed.
[374] Fix | Delete
// Returns false in case of memory error.
[375] Fix | Delete
WEBP_EXTERN int WebPPictureAlloc(WebPPicture* picture);
[376] Fix | Delete
[377] Fix | Delete
// Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*().
[378] Fix | Delete
// Note that this function does _not_ free the memory used by the 'picture'
[379] Fix | Delete
// object itself.
[380] Fix | Delete
// Besides memory (which is reclaimed) all other fields of 'picture' are
[381] Fix | Delete
// preserved.
[382] Fix | Delete
WEBP_EXTERN void WebPPictureFree(WebPPicture* picture);
[383] Fix | Delete
[384] Fix | Delete
// Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst
[385] Fix | Delete
// will fully own the copied pixels (this is not a view). The 'dst' picture need
[386] Fix | Delete
// not be initialized as its content is overwritten.
[387] Fix | Delete
// Returns false in case of memory allocation error.
[388] Fix | Delete
WEBP_EXTERN int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst);
[389] Fix | Delete
[390] Fix | Delete
// Compute the single distortion for packed planes of samples.
[391] Fix | Delete
// 'src' will be compared to 'ref', and the raw distortion stored into
[392] Fix | Delete
// '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be
[393] Fix | Delete
// stored in '*result'.
[394] Fix | Delete
// 'x_step' is the horizontal stride (in bytes) between samples.
[395] Fix | Delete
// 'src/ref_stride' is the byte distance between rows.
[396] Fix | Delete
// Returns false in case of error (bad parameter, memory allocation error, ...).
[397] Fix | Delete
WEBP_EXTERN int WebPPlaneDistortion(const uint8_t* src, size_t src_stride,
[398] Fix | Delete
const uint8_t* ref, size_t ref_stride,
[399] Fix | Delete
int width, int height,
[400] Fix | Delete
size_t x_step,
[401] Fix | Delete
int type, // 0 = PSNR, 1 = SSIM, 2 = LSIM
[402] Fix | Delete
float* distortion, float* result);
[403] Fix | Delete
[404] Fix | Delete
// Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results
[405] Fix | Delete
// are in dB, stored in result[] in the B/G/R/A/All order. The distortion is
[406] Fix | Delete
// always performed using ARGB samples. Hence if the input is YUV(A), the
[407] Fix | Delete
// picture will be internally converted to ARGB (just for the measurement).
[408] Fix | Delete
// Warning: this function is rather CPU-intensive.
[409] Fix | Delete
WEBP_EXTERN int WebPPictureDistortion(
[410] Fix | Delete
const WebPPicture* src, const WebPPicture* ref,
[411] Fix | Delete
int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM
[412] Fix | Delete
float result[5]);
[413] Fix | Delete
[414] Fix | Delete
// self-crops a picture to the rectangle defined by top/left/width/height.
[415] Fix | Delete
// Returns false in case of memory allocation error, or if the rectangle is
[416] Fix | Delete
// outside of the source picture.
[417] Fix | Delete
// The rectangle for the view is defined by the top-left corner pixel
[418] Fix | Delete
// coordinates (left, top) as well as its width and height. This rectangle
[419] Fix | Delete
// must be fully be comprised inside the 'src' source picture. If the source
[420] Fix | Delete
// picture uses the YUV420 colorspace, the top and left coordinates will be
[421] Fix | Delete
// snapped to even values.
[422] Fix | Delete
WEBP_EXTERN int WebPPictureCrop(WebPPicture* picture,
[423] Fix | Delete
int left, int top, int width, int height);
[424] Fix | Delete
[425] Fix | Delete
// Extracts a view from 'src' picture into 'dst'. The rectangle for the view
[426] Fix | Delete
// is defined by the top-left corner pixel coordinates (left, top) as well
[427] Fix | Delete
// as its width and height. This rectangle must be fully be comprised inside
[428] Fix | Delete
// the 'src' source picture. If the source picture uses the YUV420 colorspace,
[429] Fix | Delete
// the top and left coordinates will be snapped to even values.
[430] Fix | Delete
// Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed
[431] Fix | Delete
// ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so,
[432] Fix | Delete
// the original dimension will be lost). Picture 'dst' need not be initialized
[433] Fix | Delete
// with WebPPictureInit() if it is different from 'src', since its content will
[434] Fix | Delete
// be overwritten.
[435] Fix | Delete
// Returns false in case of memory allocation error or invalid parameters.
[436] Fix | Delete
WEBP_EXTERN int WebPPictureView(const WebPPicture* src,
[437] Fix | Delete
int left, int top, int width, int height,
[438] Fix | Delete
WebPPicture* dst);
[439] Fix | Delete
[440] Fix | Delete
// Returns true if the 'picture' is actually a view and therefore does
[441] Fix | Delete
// not own the memory for pixels.
[442] Fix | Delete
WEBP_EXTERN int WebPPictureIsView(const WebPPicture* picture);
[443] Fix | Delete
[444] Fix | Delete
// Rescale a picture to new dimension width x height.
[445] Fix | Delete
// If either 'width' or 'height' (but not both) is 0 the corresponding
[446] Fix | Delete
// dimension will be calculated preserving the aspect ratio.
[447] Fix | Delete
// No gamma correction is applied.
[448] Fix | Delete
// Returns false in case of error (invalid parameter or insufficient memory).
[449] Fix | Delete
WEBP_EXTERN int WebPPictureRescale(WebPPicture* pic, int width, int height);
[450] Fix | Delete
[451] Fix | Delete
// Colorspace conversion function to import RGB samples.
[452] Fix | Delete
// Previous buffer will be free'd, if any.
[453] Fix | Delete
// *rgb buffer should have a size of at least height * rgb_stride.
[454] Fix | Delete
// Returns false in case of memory error.
[455] Fix | Delete
WEBP_EXTERN int WebPPictureImportRGB(
[456] Fix | Delete
WebPPicture* picture, const uint8_t* rgb, int rgb_stride);
[457] Fix | Delete
// Same, but for RGBA buffer.
[458] Fix | Delete
WEBP_EXTERN int WebPPictureImportRGBA(
[459] Fix | Delete
WebPPicture* picture, const uint8_t* rgba, int rgba_stride);
[460] Fix | Delete
// Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format
[461] Fix | Delete
// input buffer ignoring the alpha channel. Avoids needing to copy the data
[462] Fix | Delete
// to a temporary 24-bit RGB buffer to import the RGB only.
[463] Fix | Delete
WEBP_EXTERN int WebPPictureImportRGBX(
[464] Fix | Delete
WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride);
[465] Fix | Delete
[466] Fix | Delete
// Variants of the above, but taking BGR(A|X) input.
[467] Fix | Delete
WEBP_EXTERN int WebPPictureImportBGR(
[468] Fix | Delete
WebPPicture* picture, const uint8_t* bgr, int bgr_stride);
[469] Fix | Delete
WEBP_EXTERN int WebPPictureImportBGRA(
[470] Fix | Delete
WebPPicture* picture, const uint8_t* bgra, int bgra_stride);
[471] Fix | Delete
WEBP_EXTERN int WebPPictureImportBGRX(
[472] Fix | Delete
WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride);
[473] Fix | Delete
[474] Fix | Delete
// Converts picture->argb data to the YUV420A format. The 'colorspace'
[475] Fix | Delete
// parameter is deprecated and should be equal to WEBP_YUV420.
[476] Fix | Delete
// Upon return, picture->use_argb is set to false. The presence of real
[477] Fix | Delete
// non-opaque transparent values is detected, and 'colorspace' will be
[478] Fix | Delete
// adjusted accordingly. Note that this method is lossy.
[479] Fix | Delete
// Returns false in case of error.
[480] Fix | Delete
WEBP_EXTERN int WebPPictureARGBToYUVA(WebPPicture* picture,
[481] Fix | Delete
WebPEncCSP /*colorspace = WEBP_YUV420*/);
[482] Fix | Delete
[483] Fix | Delete
// Same as WebPPictureARGBToYUVA(), but the conversion is done using
[484] Fix | Delete
// pseudo-random dithering with a strength 'dithering' between
[485] Fix | Delete
// 0.0 (no dithering) and 1.0 (maximum dithering). This is useful
[486] Fix | Delete
// for photographic picture.
[487] Fix | Delete
WEBP_EXTERN int WebPPictureARGBToYUVADithered(
[488] Fix | Delete
WebPPicture* picture, WebPEncCSP colorspace, float dithering);
[489] Fix | Delete
[490] Fix | Delete
// Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion.
[491] Fix | Delete
// Downsampling is handled with extra care in case of color clipping. This
[492] Fix | Delete
// method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better
[493] Fix | Delete
// and sharper YUV representation.
[494] Fix | Delete
// Returns false in case of error.
[495] Fix | Delete
WEBP_EXTERN int WebPPictureSharpARGBToYUVA(WebPPicture* picture);
[496] Fix | Delete
// kept for backward compatibility:
[497] Fix | Delete
WEBP_EXTERN int WebPPictureSmartARGBToYUVA(WebPPicture* picture);
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function