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