• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // This code is licensed under the same terms as WebM:
4 //  Software License Agreement:  http://www.webmproject.org/license/software/
5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 // Misc. common utility functions
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11 
12 #ifndef WEBP_UTILS_UTILS_H_
13 #define WEBP_UTILS_UTILS_H_
14 
15 #include "webp/types.h"
16 
17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" {
19 #endif
20 
21 //------------------------------------------------------------------------------
22 // Memory allocation
23 
24 // This is the maximum memory amount that libwebp will ever try to allocate.
25 #define WEBP_MAX_ALLOCABLE_MEMORY (1ULL << 40)
26 
27 // size-checking safe malloc/calloc: verify that the requested size is not too
28 // large, or return NULL. You don't need to call these for constructs like
29 // malloc(sizeof(foo)), but only if there's picture-dependent size involved
30 // somewhere (like: malloc(num_pixels * sizeof(*something))). That's why this
31 // safe malloc() borrows the signature from calloc(), pointing at the dangerous
32 // underlying multiply involved.
33 void* WebPSafeMalloc(uint64_t nmemb, size_t size);
34 // Note that WebPSafeCalloc() expects the second argument type to be 'size_t'
35 // in order to favor the "calloc(num_foo, sizeof(foo))" pattern.
36 void* WebPSafeCalloc(uint64_t nmemb, size_t size);
37 
38 //------------------------------------------------------------------------------
39 
40 #if defined(__cplusplus) || defined(c_plusplus)
41 }    // extern "C"
42 #endif
43 
44 #endif  /* WEBP_UTILS_UTILS_H_ */
45