imageio_util.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2016 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. // Utility functions used by the image decoders.
  11. //
  12. #ifndef WEBP_IMAGEIO_IMAGEIO_UTIL_H_
  13. #define WEBP_IMAGEIO_IMAGEIO_UTIL_H_
  14. #include <stdio.h>
  15. #include "webp/types.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //------------------------------------------------------------------------------
  20. // File I/O
  21. // Reopen file in binary (O_BINARY) mode.
  22. // Returns 'file' on success, NULL otherwise.
  23. FILE* ImgIoUtilSetBinaryMode(FILE* file);
  24. // Allocates storage for entire file 'file_name' and returns contents and size
  25. // in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
  26. // be deleted using free().
  27. // Note: for convenience, the data will be null-terminated with an extra byte
  28. // (not accounted for in *data_size), in case the file is text and intended
  29. // to be used as a C-string.
  30. // If 'file_name' is NULL or equal to "-", input is read from stdin by calling
  31. // the function ImgIoUtilReadFromStdin().
  32. int ImgIoUtilReadFile(const char* const file_name,
  33. const uint8_t** data, size_t* data_size);
  34. // Same as ImgIoUtilReadFile(), but reads until EOF from stdin instead.
  35. int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size);
  36. // Write a data segment into a file named 'file_name'. Returns true if ok.
  37. // If 'file_name' is NULL or equal to "-", output is written to stdout.
  38. int ImgIoUtilWriteFile(const char* const file_name,
  39. const uint8_t* data, size_t data_size);
  40. //------------------------------------------------------------------------------
  41. // Copy width x height pixels from 'src' to 'dst' honoring the strides.
  42. void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
  43. uint8_t* dst, int dst_stride, int width, int height);
  44. //------------------------------------------------------------------------------
  45. // Returns 0 in case of overflow of nmemb * size.
  46. int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size);
  47. #ifdef __cplusplus
  48. } // extern "C"
  49. #endif
  50. #endif // WEBP_IMAGEIO_IMAGEIO_UTIL_H_