xref: /aosp_15_r20/external/webp/imageio/imageio_util.h (revision b2055c353e87c8814eb2b6b1b11112a1562253bd)
1*b2055c35SXin Li // Copyright 2016 Google Inc. All Rights Reserved.
2*b2055c35SXin Li //
3*b2055c35SXin Li // Use of this source code is governed by a BSD-style license
4*b2055c35SXin Li // that can be found in the COPYING file in the root of the source
5*b2055c35SXin Li // tree. An additional intellectual property rights grant can be found
6*b2055c35SXin Li // in the file PATENTS. All contributing project authors may
7*b2055c35SXin Li // be found in the AUTHORS file in the root of the source tree.
8*b2055c35SXin Li // -----------------------------------------------------------------------------
9*b2055c35SXin Li //
10*b2055c35SXin Li //  Utility functions used by the image decoders.
11*b2055c35SXin Li //
12*b2055c35SXin Li 
13*b2055c35SXin Li #ifndef WEBP_IMAGEIO_IMAGEIO_UTIL_H_
14*b2055c35SXin Li #define WEBP_IMAGEIO_IMAGEIO_UTIL_H_
15*b2055c35SXin Li 
16*b2055c35SXin Li #include <stdio.h>
17*b2055c35SXin Li #include "webp/types.h"
18*b2055c35SXin Li 
19*b2055c35SXin Li #ifdef __cplusplus
20*b2055c35SXin Li extern "C" {
21*b2055c35SXin Li #endif
22*b2055c35SXin Li 
23*b2055c35SXin Li //------------------------------------------------------------------------------
24*b2055c35SXin Li // File I/O
25*b2055c35SXin Li 
26*b2055c35SXin Li // Reopen file in binary (O_BINARY) mode.
27*b2055c35SXin Li // Returns 'file' on success, NULL otherwise.
28*b2055c35SXin Li FILE* ImgIoUtilSetBinaryMode(FILE* file);
29*b2055c35SXin Li 
30*b2055c35SXin Li // Allocates storage for entire file 'file_name' and returns contents and size
31*b2055c35SXin Li // in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
32*b2055c35SXin Li // be deleted using WebPFree().
33*b2055c35SXin Li // Note: for convenience, the data will be null-terminated with an extra byte
34*b2055c35SXin Li // (not accounted for in *data_size), in case the file is text and intended
35*b2055c35SXin Li // to be used as a C-string.
36*b2055c35SXin Li // If 'file_name' is NULL or equal to "-", input is read from stdin by calling
37*b2055c35SXin Li // the function ImgIoUtilReadFromStdin().
38*b2055c35SXin Li int ImgIoUtilReadFile(const char* const file_name,
39*b2055c35SXin Li                       const uint8_t** data, size_t* data_size);
40*b2055c35SXin Li 
41*b2055c35SXin Li // Same as ImgIoUtilReadFile(), but reads until EOF from stdin instead.
42*b2055c35SXin Li int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size);
43*b2055c35SXin Li 
44*b2055c35SXin Li // Write a data segment into a file named 'file_name'. Returns true if ok.
45*b2055c35SXin Li // If 'file_name' is NULL or equal to "-", output is written to stdout.
46*b2055c35SXin Li int ImgIoUtilWriteFile(const char* const file_name,
47*b2055c35SXin Li                        const uint8_t* data, size_t data_size);
48*b2055c35SXin Li 
49*b2055c35SXin Li //------------------------------------------------------------------------------
50*b2055c35SXin Li 
51*b2055c35SXin Li // Copy width x height pixels from 'src' to 'dst' honoring the strides.
52*b2055c35SXin Li void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
53*b2055c35SXin Li                         uint8_t* dst, int dst_stride, int width, int height);
54*b2055c35SXin Li 
55*b2055c35SXin Li //------------------------------------------------------------------------------
56*b2055c35SXin Li 
57*b2055c35SXin Li // Returns 0 in case of overflow, memory over-allocation or excessive dimension.
58*b2055c35SXin Li int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t stride, size_t height);
59*b2055c35SXin Li 
60*b2055c35SXin Li #ifdef __cplusplus
61*b2055c35SXin Li }    // extern "C"
62*b2055c35SXin Li #endif
63*b2055c35SXin Li 
64*b2055c35SXin Li #endif  // WEBP_IMAGEIO_IMAGEIO_UTIL_H_
65