Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: third_party/libwebp/webp/encode.h

Issue 16871017: libwebp-0.3.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 0.3.1 final -> no changes since rc2 Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libwebp/webp/demux.h ('k') | third_party/libwebp/webp/format_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // This code is licensed under the same terms as WebM: 3 // Use of this source code is governed by a BSD-style license
4 // Software License Agreement: http://www.webmproject.org/license/software/ 4 // that can be found in the COPYING file in the root of the source
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 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.
6 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
7 // 9 //
8 // WebP encoder: main interface 10 // WebP encoder: main interface
9 // 11 //
10 // Author: Skal (pascal.massimino@gmail.com) 12 // Author: Skal (pascal.massimino@gmail.com)
11 13
12 #ifndef WEBP_WEBP_ENCODE_H_ 14 #ifndef WEBP_WEBP_ENCODE_H_
13 #define WEBP_WEBP_ENCODE_H_ 15 #define WEBP_WEBP_ENCODE_H_
14 16
15 #include "./types.h" 17 #include "./types.h"
16 18
17 #if defined(__cplusplus) || defined(c_plusplus) 19 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" { 20 extern "C" {
19 #endif 21 #endif
20 22
21 #define WEBP_ENCODER_ABI_VERSION 0x0201 // MAJOR(8b) + MINOR(8b) 23 #define WEBP_ENCODER_ABI_VERSION 0x0201 // MAJOR(8b) + MINOR(8b)
22 24
23 #if !(defined(__cplusplus) || defined(c_plusplus)) 25 // Note: forward declaring enumerations is not allowed in (strict) C and C++,
24 typedef enum WebPImageHint WebPImageHint; 26 // the types are left here for reference.
25 typedef enum WebPEncCSP WebPEncCSP; 27 // typedef enum WebPImageHint WebPImageHint;
26 typedef enum WebPPreset WebPPreset; 28 // typedef enum WebPEncCSP WebPEncCSP;
27 typedef enum WebPEncodingError WebPEncodingError; 29 // typedef enum WebPPreset WebPPreset;
28 #endif 30 // typedef enum WebPEncodingError WebPEncodingError;
29 typedef struct WebPConfig WebPConfig; 31 typedef struct WebPConfig WebPConfig;
30 typedef struct WebPPicture WebPPicture; // main structure for I/O 32 typedef struct WebPPicture WebPPicture; // main structure for I/O
31 typedef struct WebPAuxStats WebPAuxStats; 33 typedef struct WebPAuxStats WebPAuxStats;
32 typedef struct WebPMemoryWriter WebPMemoryWriter; 34 typedef struct WebPMemoryWriter WebPMemoryWriter;
33 35
34 // 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
35 // 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.
36 WEBP_EXTERN(int) WebPGetEncoderVersion(void); 38 WEBP_EXTERN(int) WebPGetEncoderVersion(void);
37 39
38 //------------------------------------------------------------------------------ 40 //------------------------------------------------------------------------------
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 int width, int height, int stride, 72 int width, int height, int stride,
71 uint8_t** output); 73 uint8_t** output);
72 WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra, 74 WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra,
73 int width, int height, int stride, 75 int width, int height, int stride,
74 uint8_t** output); 76 uint8_t** output);
75 77
76 //------------------------------------------------------------------------------ 78 //------------------------------------------------------------------------------
77 // Coding parameters 79 // Coding parameters
78 80
79 // Image characteristics hint for the underlying encoder. 81 // Image characteristics hint for the underlying encoder.
80 enum WebPImageHint { 82 typedef enum WebPImageHint {
81 WEBP_HINT_DEFAULT = 0, // default preset. 83 WEBP_HINT_DEFAULT = 0, // default preset.
82 WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot 84 WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot
83 WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting 85 WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting
84 WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc). 86 WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc).
85 WEBP_HINT_LAST 87 WEBP_HINT_LAST
86 }; 88 } WebPImageHint;
87 89
88 // Compression parameters. 90 // Compression parameters.
89 struct WebPConfig { 91 struct WebPConfig {
90 int lossless; // Lossless encoding (0=lossy(default), 1=lossless). 92 int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
91 float quality; // between 0 (smallest file) and 100 (biggest) 93 float quality; // between 0 (smallest file) and 100 (biggest)
92 int method; // quality/speed trade-off (0=fast, 6=slower-better) 94 int method; // quality/speed trade-off (0=fast, 6=slower-better)
93 95
94 WebPImageHint image_hint; // Hint for image type (lossless only for now). 96 WebPImageHint image_hint; // Hint for image type (lossless only for now).
95 97
96 // Parameters related to lossy compression only: 98 // Parameters related to lossy compression only:
(...skipping 29 matching lines...) Expand all
126 // JPEG compression. Generally, the output size will 128 // JPEG compression. Generally, the output size will
127 // be similar but the degradation will be lower. 129 // be similar but the degradation will be lower.
128 int thread_level; // If non-zero, try and use multi-threaded encoding. 130 int thread_level; // If non-zero, try and use multi-threaded encoding.
129 int low_memory; // If set, reduce memory usage (but increase CPU use). 131 int low_memory; // If set, reduce memory usage (but increase CPU use).
130 132
131 uint32_t pad[5]; // padding for later use 133 uint32_t pad[5]; // padding for later use
132 }; 134 };
133 135
134 // Enumerate some predefined settings for WebPConfig, depending on the type 136 // Enumerate some predefined settings for WebPConfig, depending on the type
135 // of source picture. These presets are used when calling WebPConfigPreset(). 137 // of source picture. These presets are used when calling WebPConfigPreset().
136 enum WebPPreset { 138 typedef enum WebPPreset {
137 WEBP_PRESET_DEFAULT = 0, // default preset. 139 WEBP_PRESET_DEFAULT = 0, // default preset.
138 WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot 140 WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot
139 WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting 141 WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting
140 WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details 142 WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details
141 WEBP_PRESET_ICON, // small-sized colorful images 143 WEBP_PRESET_ICON, // small-sized colorful images
142 WEBP_PRESET_TEXT // text-like 144 WEBP_PRESET_TEXT // text-like
143 }; 145 } WebPPreset;
144 146
145 // Internal, version-checked, entry point 147 // Internal, version-checked, entry point
146 WEBP_EXTERN(int) WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); 148 WEBP_EXTERN(int) WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int);
147 149
148 // Should always be called, to initialize a fresh WebPConfig structure before 150 // Should always be called, to initialize a fresh WebPConfig structure before
149 // modification. Returns false in case of version mismatch. WebPConfigInit() 151 // modification. Returns false in case of version mismatch. WebPConfigInit()
150 // must have succeeded before using the 'config' object. 152 // must have succeeded before using the 'config' object.
151 // Note that the default values are lossless=0 and quality=75. 153 // Note that the default values are lossless=0 and quality=75.
152 static WEBP_INLINE int WebPConfigInit(WebPConfig* config) { 154 static WEBP_INLINE int WebPConfigInit(WebPConfig* config) {
153 return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f, 155 return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // writer.mem must be freed using the call 'free(writer.mem)'. 225 // writer.mem must be freed using the call 'free(writer.mem)'.
224 WEBP_EXTERN(int) WebPMemoryWrite(const uint8_t* data, size_t data_size, 226 WEBP_EXTERN(int) WebPMemoryWrite(const uint8_t* data, size_t data_size,
225 const WebPPicture* picture); 227 const WebPPicture* picture);
226 228
227 // Progress hook, called from time to time to report progress. It can return 229 // Progress hook, called from time to time to report progress. It can return
228 // false to request an abort of the encoding process, or true otherwise if 230 // false to request an abort of the encoding process, or true otherwise if
229 // everything is OK. 231 // everything is OK.
230 typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); 232 typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture);
231 233
232 // Color spaces. 234 // Color spaces.
233 enum WebPEncCSP { 235 typedef enum WebPEncCSP {
234 // chroma sampling 236 // chroma sampling
235 WEBP_YUV420 = 0, // 4:2:0 237 WEBP_YUV420 = 0, // 4:2:0
236 WEBP_YUV422 = 1, // 4:2:2 238 WEBP_YUV422 = 1, // 4:2:2
237 WEBP_YUV444 = 2, // 4:4:4 239 WEBP_YUV444 = 2, // 4:4:4
238 WEBP_YUV400 = 3, // grayscale 240 WEBP_YUV400 = 3, // grayscale
239 WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors 241 WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors
240 // alpha channel variants 242 // alpha channel variants
241 WEBP_YUV420A = 4, 243 WEBP_YUV420A = 4,
242 WEBP_YUV422A = 5, 244 WEBP_YUV422A = 5,
243 WEBP_YUV444A = 6, 245 WEBP_YUV444A = 6,
244 WEBP_YUV400A = 7, // grayscale + alpha 246 WEBP_YUV400A = 7, // grayscale + alpha
245 WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present 247 WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present
246 }; 248 } WebPEncCSP;
247 249
248 // Encoding error conditions. 250 // Encoding error conditions.
249 enum WebPEncodingError { 251 typedef enum WebPEncodingError {
250 VP8_ENC_OK = 0, 252 VP8_ENC_OK = 0,
251 VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects 253 VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects
252 VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits 254 VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits
253 VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL 255 VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL
254 VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid 256 VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid
255 VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height 257 VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height
256 VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k 258 VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k
257 VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M 259 VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M
258 VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes 260 VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes
259 VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G 261 VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G
260 VP8_ENC_ERROR_USER_ABORT, // abort request by user 262 VP8_ENC_ERROR_USER_ABORT, // abort request by user
261 VP8_ENC_ERROR_LAST // list terminator. always last. 263 VP8_ENC_ERROR_LAST // list terminator. always last.
262 }; 264 } WebPEncodingError;
263 265
264 // maximum width/height allowed (inclusive), in pixels 266 // maximum width/height allowed (inclusive), in pixels
265 #define WEBP_MAX_DIMENSION 16383 267 #define WEBP_MAX_DIMENSION 16383
266 268
267 // Main exchange structure (input samples, output bytes, statistics) 269 // Main exchange structure (input samples, output bytes, statistics)
268 struct WebPPicture { 270 struct WebPPicture {
269 // INPUT 271 // INPUT
270 ////////////// 272 //////////////
271 // Main flag for encoder selecting between ARGB or YUV input. 273 // Main flag for encoder selecting between ARGB or YUV input.
272 // It is recommended to use ARGB input (*argb, argb_stride) for lossless 274 // It is recommended to use ARGB input (*argb, argb_stride) for lossless
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Returns false in case of memory error. 355 // Returns false in case of memory error.
354 WEBP_EXTERN(int) WebPPictureAlloc(WebPPicture* picture); 356 WEBP_EXTERN(int) WebPPictureAlloc(WebPPicture* picture);
355 357
356 // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). 358 // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*().
357 // Note that this function does _not_ free the memory used by the 'picture' 359 // Note that this function does _not_ free the memory used by the 'picture'
358 // object itself. 360 // object itself.
359 // Besides memory (which is reclaimed) all other fields of 'picture' are 361 // Besides memory (which is reclaimed) all other fields of 'picture' are
360 // preserved. 362 // preserved.
361 WEBP_EXTERN(void) WebPPictureFree(WebPPicture* picture); 363 WEBP_EXTERN(void) WebPPictureFree(WebPPicture* picture);
362 364
363 // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, 365 // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst
364 // *dst will fully own the copied pixels (this is not a view). 366 // will fully own the copied pixels (this is not a view). The 'dst' picture need
367 // not be initialized as its content is overwritten.
365 // Returns false in case of memory allocation error. 368 // Returns false in case of memory allocation error.
366 WEBP_EXTERN(int) WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); 369 WEBP_EXTERN(int) WebPPictureCopy(const WebPPicture* src, WebPPicture* dst);
367 370
368 // Compute PSNR, SSIM or LSIM distortion metric between two pictures. 371 // Compute PSNR, SSIM or LSIM distortion metric between two pictures.
369 // Result is in dB, stores in result[] in the Y/U/V/Alpha/All order. 372 // Result is in dB, stores in result[] in the Y/U/V/Alpha/All order.
370 // Returns false in case of error (src and ref don't have same dimension, ...) 373 // Returns false in case of error (src and ref don't have same dimension, ...)
371 // Warning: this function is rather CPU-intensive. 374 // Warning: this function is rather CPU-intensive.
372 WEBP_EXTERN(int) WebPPictureDistortion( 375 WEBP_EXTERN(int) WebPPictureDistortion(
373 const WebPPicture* src, const WebPPicture* ref, 376 const WebPPicture* src, const WebPPicture* ref,
374 int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM 377 int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM
(...skipping 10 matching lines...) Expand all
385 WEBP_EXTERN(int) WebPPictureCrop(WebPPicture* picture, 388 WEBP_EXTERN(int) WebPPictureCrop(WebPPicture* picture,
386 int left, int top, int width, int height); 389 int left, int top, int width, int height);
387 390
388 // Extracts a view from 'src' picture into 'dst'. The rectangle for the view 391 // Extracts a view from 'src' picture into 'dst'. The rectangle for the view
389 // is defined by the top-left corner pixel coordinates (left, top) as well 392 // is defined by the top-left corner pixel coordinates (left, top) as well
390 // as its width and height. This rectangle must be fully be comprised inside 393 // as its width and height. This rectangle must be fully be comprised inside
391 // the 'src' source picture. If the source picture uses the YUV420 colorspace, 394 // the 'src' source picture. If the source picture uses the YUV420 colorspace,
392 // the top and left coordinates will be snapped to even values. 395 // the top and left coordinates will be snapped to even values.
393 // Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed 396 // Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed
394 // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, 397 // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so,
395 // the original dimension will be lost). 398 // the original dimension will be lost). Picture 'dst' need not be initialized
399 // with WebPPictureInit() if it is different from 'src', since its content will
400 // be overwritten.
396 // Returns false in case of memory allocation error or invalid parameters. 401 // Returns false in case of memory allocation error or invalid parameters.
397 WEBP_EXTERN(int) WebPPictureView(const WebPPicture* src, 402 WEBP_EXTERN(int) WebPPictureView(const WebPPicture* src,
398 int left, int top, int width, int height, 403 int left, int top, int width, int height,
399 WebPPicture* dst); 404 WebPPicture* dst);
400 405
401 // Returns true if the 'picture' is actually a view and therefore does 406 // Returns true if the 'picture' is actually a view and therefore does
402 // not own the memory for pixels. 407 // not own the memory for pixels.
403 WEBP_EXTERN(int) WebPPictureIsView(const WebPPicture* picture); 408 WEBP_EXTERN(int) WebPPictureIsView(const WebPPicture* picture);
404 409
405 // Rescale a picture to new dimension width x height. 410 // Rescale a picture to new dimension width x height.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // another is provided but they both incur some loss. 476 // another is provided but they both incur some loss.
472 WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture); 477 WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture);
473 478
474 //------------------------------------------------------------------------------ 479 //------------------------------------------------------------------------------
475 480
476 #if defined(__cplusplus) || defined(c_plusplus) 481 #if defined(__cplusplus) || defined(c_plusplus)
477 } // extern "C" 482 } // extern "C"
478 #endif 483 #endif
479 484
480 #endif /* WEBP_WEBP_ENCODE_H_ */ 485 #endif /* WEBP_WEBP_ENCODE_H_ */
OLDNEW
« no previous file with comments | « third_party/libwebp/webp/demux.h ('k') | third_party/libwebp/webp/format_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698