Blame imageio/imageio_util.h

Packit 9c6abc
// Copyright 2016 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
//  Utility functions used by the image decoders.
Packit 9c6abc
//
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_IMAGEIO_IMAGEIO_UTIL_H_
Packit 9c6abc
#define WEBP_IMAGEIO_IMAGEIO_UTIL_H_
Packit 9c6abc
Packit 9c6abc
#include <stdio.h>
Packit 9c6abc
#include "webp/types.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// File I/O
Packit 9c6abc
Packit 9c6abc
// Reopen file in binary (O_BINARY) mode.
Packit 9c6abc
// Returns 'file' on success, NULL otherwise.
Packit 9c6abc
FILE* ImgIoUtilSetBinaryMode(FILE* file);
Packit 9c6abc
Packit 9c6abc
// Allocates storage for entire file 'file_name' and returns contents and size
Packit 9c6abc
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
Packit 9c6abc
// be deleted using free().
Packit 9c6abc
// Note: for convenience, the data will be null-terminated with an extra byte
Packit 9c6abc
// (not accounted for in *data_size), in case the file is text and intended
Packit 9c6abc
// to be used as a C-string.
Packit 9c6abc
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
Packit 9c6abc
// the function ImgIoUtilReadFromStdin().
Packit 9c6abc
int ImgIoUtilReadFile(const char* const file_name,
Packit 9c6abc
                      const uint8_t** data, size_t* data_size);
Packit 9c6abc
Packit 9c6abc
// Same as ImgIoUtilReadFile(), but reads until EOF from stdin instead.
Packit 9c6abc
int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size);
Packit 9c6abc
Packit 9c6abc
// Write a data segment into a file named 'file_name'. Returns true if ok.
Packit 9c6abc
// If 'file_name' is NULL or equal to "-", output is written to stdout.
Packit 9c6abc
int ImgIoUtilWriteFile(const char* const file_name,
Packit 9c6abc
                       const uint8_t* data, size_t data_size);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
// Copy width x height pixels from 'src' to 'dst' honoring the strides.
Packit 9c6abc
void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
Packit 9c6abc
                        uint8_t* dst, int dst_stride, int width, int height);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
// Returns 0 in case of overflow of nmemb * size.
Packit 9c6abc
int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size);
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_IMAGEIO_IMAGEIO_UTIL_H_