@cpp.js/package-webp 1.0.0-beta.23 → 1.0.0-beta.24

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