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