Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 8 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | typedef struct WebPAuxStats WebPAuxStats; |
33 | typedef struct WebPAuxStats WebPAuxStats; |
34 | typedef struct WebPMemoryWriter WebPMemoryWriter; |
34 | typedef struct WebPMemoryWriter WebPMemoryWriter; |
35 | 35 | ||
36 | // Return the encoder's version number, packed in hexadecimal using 8bits for |
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. |
37 | // each of major/minor/revision. E.g: v2.5.7 is 0x020507. |
38 | WEBP_EXTERN |
38 | WEBP_EXTERN int WebPGetEncoderVersion(void); |
39 | 39 | ||
40 | //------------------------------------------------------------------------------ |
40 | //------------------------------------------------------------------------------ |
41 | // One-stop-shop call! No questions asked: |
41 | // One-stop-shop call! No questions asked: |
42 | 42 | ||
43 | // Returns the size of the compressed data (pointed to by *output), or 0 if |
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 |
44 | // an error occurred. The compressed data must be released by the caller |
45 | // using the call 'WebPFree(*output)'. |
45 | // using the call 'WebPFree(*output)'. |
46 | // These functions compress using the lossy format, and the quality_factor |
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, |
47 | // can go from 0 (smaller output, lower quality) to 100 (best quality, |
48 | // larger output). |
48 | // larger output). |
49 | WEBP_EXTERN |
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, |
|
50 | int width, int height, int stride, |
56 | int width, int height, int stride, |
51 | float quality_factor, uint8_t** output); |
57 | float quality_factor, uint8_t** output); |
52 | WEBP_EXTERN |
58 | WEBP_EXTERN size_t WebPEncodeBGRA(const uint8_t* bgra, |
53 | int width, int height, int stride, |
59 | int width, int height, int stride, |
54 | float quality_factor, uint8_t** output); |
60 | float quality_factor, uint8_t** output); |
55 | WEBP_EXTERN(size_t) WebPEncodeRGBA(const uint8_t* rgba, |
- | |
56 | int width, int height, int stride, |
- | |
57 | float quality_factor, uint8_t** output); |
- | |
58 | WEBP_EXTERN(size_t) WebPEncodeBGRA(const uint8_t* bgra, |
- | |
59 | int width, int height, int stride, |
- | |
60 | float quality_factor, uint8_t** output); |
- | |
61 | 61 | ||
62 | // These functions are the equivalent of the above, but compressing in a |
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 |
63 | // lossless manner. Files are usually larger than lossy format, but will |
64 | // not suffer any compression loss. |
64 | // not suffer any compression loss. |
65 | WEBP_EXTERN |
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, |
|
66 | int width, int height, int stride, |
72 | int width, int height, int stride, |
67 | uint8_t** output); |
73 | uint8_t** output); |
68 | WEBP_EXTERN |
74 | WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, |
69 | int width, int height, int stride, |
75 | int width, int height, int stride, |
70 | uint8_t** output); |
76 | uint8_t** output); |
71 | WEBP_EXTERN(size_t) WebPEncodeLosslessRGBA(const uint8_t* rgba, |
- | |
72 | int width, int height, int stride, |
- | |
73 | uint8_t** output); |
- | |
74 | WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra, |
- | |
75 | int width, int height, int stride, |
- | |
76 | uint8_t** output); |
- | |
77 | 77 | ||
78 | // Releases memory returned by the WebPEncode*() functions above. |
78 | // Releases memory returned by the WebPEncode*() functions above. |
79 | WEBP_EXTERN |
79 | WEBP_EXTERN void WebPFree(void* ptr); |
80 | 80 | ||
81 | //------------------------------------------------------------------------------ |
81 | //------------------------------------------------------------------------------ |
82 | // Coding parameters |
82 | // Coding parameters |
83 | 83 | ||
84 | // Image characteristics hint for the underlying encoder. |
84 | // Image characteristics hint for the underlying encoder. |
Line 91... | Line 91... | ||
91 | } WebPImageHint; |
91 | } WebPImageHint; |
92 | 92 | ||
93 | // Compression parameters. |
93 | // Compression parameters. |
94 | struct WebPConfig { |
94 | struct WebPConfig { |
95 | int lossless; // Lossless encoding (0=lossy(default), 1=lossless). |
95 | int lossless; // Lossless encoding (0=lossy(default), 1=lossless). |
96 | float quality; // between 0 |
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. |
|
97 | int method; // quality/speed trade-off (0=fast, 6=slower-better) |
101 | int method; // quality/speed trade-off (0=fast, 6=slower-better) |
98 | 102 | ||
99 | WebPImageHint image_hint; // Hint for image type (lossless only for now). |
103 | WebPImageHint image_hint; // Hint for image type (lossless only for now). |
100 | 104 | ||
101 | // Parameters related to lossy compression only: |
- | |
102 | int target_size; // if non-zero, set the desired target size in bytes. |
105 | int target_size; // if non-zero, set the desired target size in bytes. |
103 | // Takes precedence over the 'compression' parameter. |
106 | // Takes precedence over the 'compression' parameter. |
104 | float target_PSNR; // if non-zero, specifies the minimal distortion to |
107 | float target_PSNR; // if non-zero, specifies the minimal distortion to |
105 | // try to achieve. Takes precedence over target_size. |
108 | // try to achieve. Takes precedence over target_size. |
106 | int segments; // maximum number of segments to use, in [1..4] |
109 | int segments; // maximum number of segments to use, in [1..4] |
Line 157... | Line 160... | ||
157 | WEBP_PRESET_ICON, // small-sized colorful images |
160 | WEBP_PRESET_ICON, // small-sized colorful images |
158 | WEBP_PRESET_TEXT // text-like |
161 | WEBP_PRESET_TEXT // text-like |
159 | } WebPPreset; |
162 | } WebPPreset; |
160 | 163 | ||
161 | // Internal, version-checked, entry point |
164 | // Internal, version-checked, entry point |
162 | WEBP_EXTERN |
165 | WEBP_EXTERN int WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); |
163 | 166 | ||
164 | // Should always be called, to initialize a fresh WebPConfig structure before |
167 | // Should always be called, to initialize a fresh WebPConfig structure before |
165 | // modification. Returns false in case of version mismatch. WebPConfigInit() |
168 | // modification. Returns false in case of version mismatch. WebPConfigInit() |
166 | // must have succeeded before using the 'config' object. |
169 | // must have succeeded before using the 'config' object. |
167 | // Note that the default values are lossless=0 and quality=75. |
170 | // Note that the default values are lossless=0 and quality=75. |
Line 184... | Line 187... | ||
184 | // between 0 (fastest, lowest compression) and 9 (slower, best compression). |
187 | // between 0 (fastest, lowest compression) and 9 (slower, best compression). |
185 | // A good default level is '6', providing a fair tradeoff between compression |
188 | // A good default level is '6', providing a fair tradeoff between compression |
186 | // speed and final compressed size. |
189 | // speed and final compressed size. |
187 | // This function will overwrite several fields from config: 'method', 'quality' |
190 | // This function will overwrite several fields from config: 'method', 'quality' |
188 | // and 'lossless'. Returns false in case of parameter error. |
191 | // and 'lossless'. Returns false in case of parameter error. |
189 | WEBP_EXTERN |
192 | WEBP_EXTERN int WebPConfigLosslessPreset(WebPConfig* config, int level); |
190 | 193 | ||
191 | // Returns true if 'config' is non-NULL and all configuration parameters are |
194 | // Returns true if 'config' is non-NULL and all configuration parameters are |
192 | // within their valid ranges. |
195 | // within their valid ranges. |
193 | WEBP_EXTERN |
196 | WEBP_EXTERN int WebPValidateConfig(const WebPConfig* config); |
194 | 197 | ||
195 | //------------------------------------------------------------------------------ |
198 | //------------------------------------------------------------------------------ |
196 | // Input / Output |
199 | // Input / Output |
197 | // Structure for storing auxiliary statistics |
200 | // Structure for storing auxiliary statistics. |
198 | 201 | ||
199 | struct WebPAuxStats { |
202 | struct WebPAuxStats { |
200 | int coded_size; // final size |
203 | int coded_size; // final size |
201 | 204 | ||
202 | float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha |
205 | float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha |
Line 240... | Line 243... | ||
240 | size_t max_size; // total capacity |
243 | size_t max_size; // total capacity |
241 | uint32_t pad[1]; // padding for later use |
244 | uint32_t pad[1]; // padding for later use |
242 | }; |
245 | }; |
243 | 246 | ||
244 | // The following must be called first before any use. |
247 | // The following must be called first before any use. |
245 | WEBP_EXTERN |
248 | WEBP_EXTERN void WebPMemoryWriterInit(WebPMemoryWriter* writer); |
246 | 249 | ||
247 | // The following must be called to deallocate writer->mem memory. The 'writer' |
250 | // The following must be called to deallocate writer->mem memory. The 'writer' |
248 | // object itself is not deallocated. |
251 | // object itself is not deallocated. |
249 | WEBP_EXTERN |
252 | WEBP_EXTERN void WebPMemoryWriterClear(WebPMemoryWriter* writer); |
250 | // The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon |
253 | // The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon |
251 | // completion, writer.mem and writer.size will hold the coded data. |
254 | // completion, writer.mem and writer.size will hold the coded data. |
252 | // writer.mem must be freed by calling WebPMemoryWriterClear. |
255 | // writer.mem must be freed by calling WebPMemoryWriterClear. |
253 | WEBP_EXTERN |
256 | WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size, |
254 |
|
257 | const WebPPicture* picture); |
255 | 258 | ||
256 | // Progress hook, called from time to time to report progress. It can return |
259 | // Progress hook, called from time to time to report progress. It can return |
257 | // false to request an abort of the encoding process, or true otherwise if |
260 | // false to request an abort of the encoding process, or true otherwise if |
258 | // everything is OK. |
261 | // everything is OK. |
259 | typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); |
262 | typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); |
Line 352... | Line 355... | ||
352 | void* memory_argb_; // and for argb too. |
355 | void* memory_argb_; // and for argb too. |
353 | void* pad7[2]; // padding for later use |
356 | void* pad7[2]; // padding for later use |
354 | }; |
357 | }; |
355 | 358 | ||
356 | // Internal, version-checked, entry point |
359 | // Internal, version-checked, entry point |
357 | WEBP_EXTERN |
360 | WEBP_EXTERN int WebPPictureInitInternal(WebPPicture*, int); |
358 | 361 | ||
359 | // Should always be called, to initialize the structure. Returns false in case |
362 | // Should always be called, to initialize the structure. Returns false in case |
360 | // of version mismatch. WebPPictureInit() must have succeeded before using the |
363 | // of version mismatch. WebPPictureInit() must have succeeded before using the |
361 | // 'picture' object. |
364 | // 'picture' object. |
362 | // Note that, by default, use_argb is false and colorspace is WEBP_YUV420. |
365 | // Note that, by default, use_argb is false and colorspace is WEBP_YUV420. |
Line 369... | Line 372... | ||
369 | 372 | ||
370 | // Convenience allocation / deallocation based on picture->width/height: |
373 | // Convenience allocation / deallocation based on picture->width/height: |
371 | // Allocate y/u/v buffers as per colorspace/width/height specification. |
374 | // Allocate y/u/v buffers as per colorspace/width/height specification. |
372 | // Note! This function will free the previous buffer if needed. |
375 | // Note! This function will free the previous buffer if needed. |
373 | // Returns false in case of memory error. |
376 | // Returns false in case of memory error. |
374 | WEBP_EXTERN |
377 | WEBP_EXTERN int WebPPictureAlloc(WebPPicture* picture); |
375 | 378 | ||
376 | // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). |
379 | // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). |
377 | // Note that this function does _not_ free the memory used by the 'picture' |
380 | // Note that this function does _not_ free the memory used by the 'picture' |
378 | // object itself. |
381 | // object itself. |
379 | // Besides memory (which is reclaimed) all other fields of 'picture' are |
382 | // Besides memory (which is reclaimed) all other fields of 'picture' are |
380 | // preserved. |
383 | // preserved. |
381 | WEBP_EXTERN |
384 | WEBP_EXTERN void WebPPictureFree(WebPPicture* picture); |
382 | 385 | ||
383 | // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst |
386 | // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst |
384 | // will fully own the copied pixels (this is not a view). The 'dst' picture need |
387 | // will fully own the copied pixels (this is not a view). The 'dst' picture need |
385 | // not be initialized as its content is overwritten. |
388 | // not be initialized as its content is overwritten. |
386 | // Returns false in case of memory allocation error. |
389 | // Returns false in case of memory allocation error. |
387 | WEBP_EXTERN |
390 | WEBP_EXTERN int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); |
388 | 391 | ||
389 | // Compute the single distortion for packed planes of samples. |
392 | // Compute the single distortion for packed planes of samples. |
390 | // 'src' will be compared to 'ref', and the raw distortion stored into |
393 | // 'src' will be compared to 'ref', and the raw distortion stored into |
391 | // '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be |
394 | // '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be |
392 | // stored in '*result'. |
395 | // stored in '*result'. |
393 | // 'x_step' is the horizontal stride (in bytes) between samples. |
396 | // 'x_step' is the horizontal stride (in bytes) between samples. |
394 | // 'src/ref_stride' is the byte distance between rows. |
397 | // 'src/ref_stride' is the byte distance between rows. |
395 | // Returns false in case of error (bad parameter, memory allocation error, ...). |
398 | // Returns false in case of error (bad parameter, memory allocation error, ...). |
396 | WEBP_EXTERN |
399 | WEBP_EXTERN int WebPPlaneDistortion(const uint8_t* src, size_t src_stride, |
397 |
|
400 | const uint8_t* ref, size_t ref_stride, |
398 |
|
401 | int width, int height, |
399 |
|
402 | size_t x_step, |
400 |
|
403 | int type, // 0 = PSNR, 1 = SSIM, 2 = LSIM |
401 |
|
404 | float* distortion, float* result); |
402 | 405 | ||
403 | // Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results |
406 | // Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results |
404 | // are in dB, stored in result[] in the B/G/R/A/All order. The distortion is |
407 | // are in dB, stored in result[] in the B/G/R/A/All order. The distortion is |
405 | // always performed using ARGB samples. Hence if the input is YUV(A), the |
408 | // always performed using ARGB samples. Hence if the input is YUV(A), the |
406 | // picture will be internally converted to ARGB (just for the measurement). |
409 | // picture will be internally converted to ARGB (just for the measurement). |
407 | // Warning: this function is rather CPU-intensive. |
410 | // Warning: this function is rather CPU-intensive. |
408 | WEBP_EXTERN |
411 | WEBP_EXTERN int WebPPictureDistortion( |
409 | const WebPPicture* src, const WebPPicture* ref, |
412 | const WebPPicture* src, const WebPPicture* ref, |
410 | int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM |
413 | int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM |
411 | float result[5]); |
414 | float result[5]); |
412 | 415 | ||
413 | // self-crops a picture to the rectangle defined by top/left/width/height. |
416 | // self-crops a picture to the rectangle defined by top/left/width/height. |
Line 416... | Line 419... | ||
416 | // The rectangle for the view is defined by the top-left corner pixel |
419 | // The rectangle for the view is defined by the top-left corner pixel |
417 | // coordinates (left, top) as well as its width and height. This rectangle |
420 | // coordinates (left, top) as well as its width and height. This rectangle |
418 | // must be fully be comprised inside the 'src' source picture. If the source |
421 | // must be fully be comprised inside the 'src' source picture. If the source |
419 | // picture uses the YUV420 colorspace, the top and left coordinates will be |
422 | // picture uses the YUV420 colorspace, the top and left coordinates will be |
420 | // snapped to even values. |
423 | // snapped to even values. |
421 | WEBP_EXTERN |
424 | WEBP_EXTERN int WebPPictureCrop(WebPPicture* picture, |
422 |
|
425 | int left, int top, int width, int height); |
423 | 426 | ||
424 | // Extracts a view from 'src' picture into 'dst'. The rectangle for the view |
427 | // Extracts a view from 'src' picture into 'dst'. The rectangle for the view |
425 | // is defined by the top-left corner pixel coordinates (left, top) as well |
428 | // is defined by the top-left corner pixel coordinates (left, top) as well |
426 | // as its width and height. This rectangle must be fully be comprised inside |
429 | // as its width and height. This rectangle must be fully be comprised inside |
427 | // the 'src' source picture. If the source picture uses the YUV420 colorspace, |
430 | // the 'src' source picture. If the source picture uses the YUV420 colorspace, |
Line 430... | Line 433... | ||
430 | // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, |
433 | // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, |
431 | // the original dimension will be lost). Picture 'dst' need not be initialized |
434 | // the original dimension will be lost). Picture 'dst' need not be initialized |
432 | // with WebPPictureInit() if it is different from 'src', since its content will |
435 | // with WebPPictureInit() if it is different from 'src', since its content will |
433 | // be overwritten. |
436 | // be overwritten. |
434 | // Returns false in case of memory allocation error or invalid parameters. |
437 | // Returns false in case of memory allocation error or invalid parameters. |
435 | WEBP_EXTERN |
438 | WEBP_EXTERN int WebPPictureView(const WebPPicture* src, |
436 |
|
439 | int left, int top, int width, int height, |
437 |
|
440 | WebPPicture* dst); |
438 | 441 | ||
439 | // Returns true if the 'picture' is actually a view and therefore does |
442 | // Returns true if the 'picture' is actually a view and therefore does |
440 | // not own the memory for pixels. |
443 | // not own the memory for pixels. |
441 | WEBP_EXTERN |
444 | WEBP_EXTERN int WebPPictureIsView(const WebPPicture* picture); |
442 | 445 | ||
443 | // Rescale a picture to new dimension width x height. |
446 | // Rescale a picture to new dimension width x height. |
444 | // If either 'width' or 'height' (but not both) is 0 the corresponding |
447 | // If either 'width' or 'height' (but not both) is 0 the corresponding |
445 | // dimension will be calculated preserving the aspect ratio. |
448 | // dimension will be calculated preserving the aspect ratio. |
446 | // No gamma correction is applied. |
449 | // No gamma correction is applied. |
447 | // Returns false in case of error (invalid parameter or insufficient memory). |
450 | // Returns false in case of error (invalid parameter or insufficient memory). |
448 | WEBP_EXTERN |
451 | WEBP_EXTERN int WebPPictureRescale(WebPPicture* pic, int width, int height); |
449 | 452 | ||
450 | // Colorspace conversion function to import RGB samples. |
453 | // Colorspace conversion function to import RGB samples. |
451 | // Previous buffer will be free'd, if any. |
454 | // Previous buffer will be free'd, if any. |
452 | // *rgb buffer should have a size of at least height * rgb_stride. |
455 | // *rgb buffer should have a size of at least height * rgb_stride. |
453 | // Returns false in case of memory error. |
456 | // Returns false in case of memory error. |
454 | WEBP_EXTERN |
457 | WEBP_EXTERN int WebPPictureImportRGB( |
455 | WebPPicture* picture, const uint8_t* rgb, int rgb_stride); |
458 | WebPPicture* picture, const uint8_t* rgb, int rgb_stride); |
456 | // Same, but for RGBA buffer. |
459 | // Same, but for RGBA buffer. |
457 | WEBP_EXTERN |
460 | WEBP_EXTERN int WebPPictureImportRGBA( |
458 | WebPPicture* picture, const uint8_t* rgba, int rgba_stride); |
461 | WebPPicture* picture, const uint8_t* rgba, int rgba_stride); |
459 | // Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format |
462 | // Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format |
460 | // input buffer ignoring the alpha channel. Avoids needing to copy the data |
463 | // input buffer ignoring the alpha channel. Avoids needing to copy the data |
461 | // to a temporary 24-bit RGB buffer to import the RGB only. |
464 | // to a temporary 24-bit RGB buffer to import the RGB only. |
462 | WEBP_EXTERN |
465 | WEBP_EXTERN int WebPPictureImportRGBX( |
463 | WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); |
466 | WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); |
464 | 467 | ||
465 | // Variants of the above, but taking BGR(A|X) input. |
468 | // Variants of the above, but taking BGR(A|X) input. |
466 | WEBP_EXTERN |
469 | WEBP_EXTERN int WebPPictureImportBGR( |
467 | WebPPicture* picture, const uint8_t* bgr, int bgr_stride); |
470 | WebPPicture* picture, const uint8_t* bgr, int bgr_stride); |
468 | WEBP_EXTERN |
471 | WEBP_EXTERN int WebPPictureImportBGRA( |
469 | WebPPicture* picture, const uint8_t* bgra, int bgra_stride); |
472 | WebPPicture* picture, const uint8_t* bgra, int bgra_stride); |
470 | WEBP_EXTERN |
473 | WEBP_EXTERN int WebPPictureImportBGRX( |
471 | WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); |
474 | WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); |
472 | 475 | ||
473 | // Converts picture->argb data to the YUV420A format. The 'colorspace' |
476 | // Converts picture->argb data to the YUV420A format. The 'colorspace' |
474 | // parameter is deprecated and should be equal to WEBP_YUV420. |
477 | // parameter is deprecated and should be equal to WEBP_YUV420. |
475 | // Upon return, picture->use_argb is set to false. The presence of real |
478 | // Upon return, picture->use_argb is set to false. The presence of real |
476 | // non-opaque transparent values is detected, and 'colorspace' will be |
479 | // non-opaque transparent values is detected, and 'colorspace' will be |
477 | // adjusted accordingly. Note that this method is lossy. |
480 | // adjusted accordingly. Note that this method is lossy. |
478 | // Returns false in case of error. |
481 | // Returns false in case of error. |
479 | WEBP_EXTERN |
482 | WEBP_EXTERN int WebPPictureARGBToYUVA(WebPPicture* picture, |
480 |
|
483 | WebPEncCSP /*colorspace = WEBP_YUV420*/); |
481 | 484 | ||
482 | // Same as WebPPictureARGBToYUVA(), but the conversion is done using |
485 | // Same as WebPPictureARGBToYUVA(), but the conversion is done using |
483 | // pseudo-random dithering with a strength 'dithering' between |
486 | // pseudo-random dithering with a strength 'dithering' between |
484 | // 0.0 (no dithering) and 1.0 (maximum dithering). This is useful |
487 | // 0.0 (no dithering) and 1.0 (maximum dithering). This is useful |
485 | // for photographic picture. |
488 | // for photographic picture. |
486 | WEBP_EXTERN |
489 | WEBP_EXTERN int WebPPictureARGBToYUVADithered( |
487 | WebPPicture* picture, WebPEncCSP colorspace, float dithering); |
490 | WebPPicture* picture, WebPEncCSP colorspace, float dithering); |
488 | 491 | ||
489 | // Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion. |
492 | // Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion. |
490 | // Downsampling is handled with extra care in case of color clipping. This |
493 | // Downsampling is handled with extra care in case of color clipping. This |
491 | // method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better |
494 | // method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better |
492 | // and sharper YUV representation. |
495 | // and sharper YUV representation. |
493 | // Returns false in case of error. |
496 | // Returns false in case of error. |
494 | WEBP_EXTERN |
497 | WEBP_EXTERN int WebPPictureSharpARGBToYUVA(WebPPicture* picture); |
495 | // kept for backward compatibility: |
498 | // kept for backward compatibility: |
496 | WEBP_EXTERN |
499 | WEBP_EXTERN int WebPPictureSmartARGBToYUVA(WebPPicture* picture); |
497 | 500 | ||
498 | // Converts picture->yuv to picture->argb and sets picture->use_argb to true. |
501 | // Converts picture->yuv to picture->argb and sets picture->use_argb to true. |
499 | // The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to |
502 | // The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to |
500 | // ARGB incurs a small loss too. |
503 | // ARGB incurs a small loss too. |
501 | // Note that the use of this colorspace is discouraged if one has access to the |
504 | // Note that the use of this colorspace is discouraged if one has access to the |
502 | // raw ARGB samples, since using YUV420 is comparatively lossy. |
505 | // raw ARGB samples, since using YUV420 is comparatively lossy. |
503 | // Returns false in case of error. |
506 | // Returns false in case of error. |
504 | WEBP_EXTERN |
507 | WEBP_EXTERN int WebPPictureYUVAToARGB(WebPPicture* picture); |
505 | 508 | ||
506 | // Helper function: given a width x height plane of RGBA or YUV(A) samples |
509 | // Helper function: given a width x height plane of RGBA or YUV(A) samples |
507 | // clean-up the YUV or RGB |
510 | // clean-up or smoothen the YUV or RGB samples under fully transparent area, |
508 | // compressibility (no guarantee, though). |
511 | // to help compressibility (no guarantee, though). |
509 | WEBP_EXTERN |
512 | WEBP_EXTERN void WebPCleanupTransparentArea(WebPPicture* picture); |
510 | 513 | ||
511 | // Scan the picture 'picture' for the presence of non fully opaque alpha values. |
514 | // Scan the picture 'picture' for the presence of non fully opaque alpha values. |
512 | // Returns true in such case. Otherwise returns false (indicating that the |
515 | // Returns true in such case. Otherwise returns false (indicating that the |
513 | // alpha plane can be ignored altogether e.g.). |
516 | // alpha plane can be ignored altogether e.g.). |
514 | WEBP_EXTERN |
517 | WEBP_EXTERN int WebPPictureHasTransparency(const WebPPicture* picture); |
515 | 518 | ||
516 | // Remove the transparency information (if present) by blending the color with |
519 | // Remove the transparency information (if present) by blending the color with |
517 | // the background color 'background_rgb' (specified as 24bit RGB triplet). |
520 | // the background color 'background_rgb' (specified as 24bit RGB triplet). |
518 | // After this call, all alpha values are reset to 0xff. |
521 | // After this call, all alpha values are reset to 0xff. |
519 | WEBP_EXTERN |
522 | WEBP_EXTERN void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb); |
520 | 523 | ||
521 | //------------------------------------------------------------------------------ |
524 | //------------------------------------------------------------------------------ |
522 | // Main call |
525 | // Main call |
523 | 526 | ||
524 | // Main encoding call, after config and picture have been initialized. |
527 | // Main encoding call, after config and picture have been initialized. |
Line 529... | Line 532... | ||
529 | // 'picture' can hold the source samples in both YUV(A) or ARGB input, depending |
532 | // 'picture' can hold the source samples in both YUV(A) or ARGB input, depending |
530 | // on the value of 'picture->use_argb'. It is highly recommended to use |
533 | // on the value of 'picture->use_argb'. It is highly recommended to use |
531 | // the former for lossy encoding, and the latter for lossless encoding |
534 | // the former for lossy encoding, and the latter for lossless encoding |
532 | // (when config.lossless is true). Automatic conversion from one format to |
535 | // (when config.lossless is true). Automatic conversion from one format to |
533 | // another is provided but they both incur some loss. |
536 | // another is provided but they both incur some loss. |
534 | WEBP_EXTERN |
537 | WEBP_EXTERN int WebPEncode(const WebPConfig* config, WebPPicture* picture); |
535 | 538 | ||
536 | //------------------------------------------------------------------------------ |
539 | //------------------------------------------------------------------------------ |
537 | 540 | ||
538 | #ifdef __cplusplus |
541 | #ifdef __cplusplus |
539 | } // extern "C" |
542 | } // extern "C" |