| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 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 | 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 | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Misc. common utility functions | 10 // Misc. common utility functions |
| 11 // | 11 // |
| 12 // Authors: Skal (pascal.massimino@gmail.com) | 12 // Authors: Skal (pascal.massimino@gmail.com) |
| 13 // Urvang (urvang@google.com) | 13 // Urvang (urvang@google.com) |
| 14 | 14 |
| 15 #ifndef WEBP_UTILS_UTILS_H_ | 15 #ifndef WEBP_UTILS_UTILS_H_ |
| 16 #define WEBP_UTILS_UTILS_H_ | 16 #define WEBP_UTILS_UTILS_H_ |
| 17 | 17 |
| 18 #ifdef HAVE_CONFIG_H | 18 #ifdef HAVE_CONFIG_H |
| 19 #include "../webp/config.h" | 19 #include "../webp/config.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #include <assert.h> | 22 #include <assert.h> |
| 23 #include <limits.h> |
| 23 | 24 |
| 24 #include "../dsp/dsp.h" | 25 #include "../dsp/dsp.h" |
| 25 #include "../webp/types.h" | 26 #include "../webp/types.h" |
| 26 | 27 |
| 27 #ifdef __cplusplus | 28 #ifdef __cplusplus |
| 28 extern "C" { | 29 extern "C" { |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 //------------------------------------------------------------------------------ | 32 //------------------------------------------------------------------------------ |
| 32 // Memory allocation | 33 // Memory allocation |
| 33 | 34 |
| 34 // This is the maximum memory amount that libwebp will ever try to allocate. | 35 // This is the maximum memory amount that libwebp will ever try to allocate. |
| 35 #define WEBP_MAX_ALLOCABLE_MEMORY (1ULL << 40) | 36 #ifndef WEBP_MAX_ALLOCABLE_MEMORY |
| 37 #if SIZE_MAX > (1ULL << 34) |
| 38 #define WEBP_MAX_ALLOCABLE_MEMORY (1ULL << 34) |
| 39 #else |
| 40 // For 32-bit targets keep this below INT_MAX to avoid valgrind warnings. |
| 41 #define WEBP_MAX_ALLOCABLE_MEMORY ((1ULL << 31) - (1 << 16)) |
| 42 #endif |
| 43 #endif // WEBP_MAX_ALLOCABLE_MEMORY |
| 36 | 44 |
| 37 // size-checking safe malloc/calloc: verify that the requested size is not too | 45 // size-checking safe malloc/calloc: verify that the requested size is not too |
| 38 // large, or return NULL. You don't need to call these for constructs like | 46 // large, or return NULL. You don't need to call these for constructs like |
| 39 // malloc(sizeof(foo)), but only if there's picture-dependent size involved | 47 // malloc(sizeof(foo)), but only if there's picture-dependent size involved |
| 40 // somewhere (like: malloc(num_pixels * sizeof(*something))). That's why this | 48 // somewhere (like: malloc(num_pixels * sizeof(*something))). That's why this |
| 41 // safe malloc() borrows the signature from calloc(), pointing at the dangerous | 49 // safe malloc() borrows the signature from calloc(), pointing at the dangerous |
| 42 // underlying multiply involved. | 50 // underlying multiply involved. |
| 43 WEBP_EXTERN(void*) WebPSafeMalloc(uint64_t nmemb, size_t size); | 51 WEBP_EXTERN(void*) WebPSafeMalloc(uint64_t nmemb, size_t size); |
| 44 // Note that WebPSafeCalloc() expects the second argument type to be 'size_t' | 52 // Note that WebPSafeCalloc() expects the second argument type to be 'size_t' |
| 45 // in order to favor the "calloc(num_foo, sizeof(foo))" pattern. | 53 // in order to favor the "calloc(num_foo, sizeof(foo))" pattern. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 WEBP_EXTERN(int) WebPGetColorPalette(const struct WebPPicture* const pic, | 181 WEBP_EXTERN(int) WebPGetColorPalette(const struct WebPPicture* const pic, |
| 174 uint32_t* const palette); | 182 uint32_t* const palette); |
| 175 | 183 |
| 176 //------------------------------------------------------------------------------ | 184 //------------------------------------------------------------------------------ |
| 177 | 185 |
| 178 #ifdef __cplusplus | 186 #ifdef __cplusplus |
| 179 } // extern "C" | 187 } // extern "C" |
| 180 #endif | 188 #endif |
| 181 | 189 |
| 182 #endif /* WEBP_UTILS_UTILS_H_ */ | 190 #endif /* WEBP_UTILS_UTILS_H_ */ |
| OLD | NEW |