A Survey of Gaussian Convolution Algorithms
|
Implements read_image and write_image functions. More...
Implements read_image and write_image functions.
Copyright (c) 2010-2013, Pascal Getreuer All rights reserved.
This program is free software: you can redistribute it and/or modify it under, at your option, the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version, or the terms of the simplified BSD license.
You should have received a copy of these licenses along this program. If not, see http://www.gnu.org/licenses/ and http://www.opensource.org/licenses/bsd-license.html.
Definition in file imageio.h.
Go to the source code of this file.
Macros | |
#define | MAX_IMAGE_SIZE 10000 |
Limit on the maximum allowed image width or height (security). | |
#define | READIMAGE_FORMATS_SUPPORTED "BMP" SUPPORTEDSTRING_JPEG SUPPORTEDSTRING_PNG SUPPORTEDSTRING_TIFF |
String macro listing supported formats for ReadImage . More... | |
#define | WRITEIMAGE_FORMATS_SUPPORTED "BMP" SUPPORTEDSTRING_JPEG SUPPORTEDSTRING_PNG SUPPORTEDSTRING_TIFF |
String macro listing supported formats for WriteImage . | |
#define | _CRT_SECURE_NO_WARNINGS |
Avoid MSVC warnings on using fopen. | |
Functions | |
int | identify_image_type (char *type, const char *filename) |
Identify the file type of an image file by its magic numbers. More... | |
void * | read_image (int *width, int *height, const char *filename, unsigned format) |
Read an image file as 32-bit RGBA data. More... | |
int | write_image (void *image, int width, int height, const char *filename, unsigned format, int quality) |
Write an image file from 8-bit RGBA image data. More... | |
#define READIMAGE_FORMATS_SUPPORTED "BMP" SUPPORTEDSTRING_JPEG SUPPORTEDSTRING_PNG SUPPORTEDSTRING_TIFF |
String macro listing supported formats for ReadImage
.
This macro can be used for example as
int identify_image_type | ( | char * | type, |
const char * | filename | ||
) |
Identify the file type of an image file by its magic numbers.
type | destination buffer with space for at least 5 chars |
filename | image file name |
The routine fills type with an identifying string. If there is an error or the file type is unknown, type is set to a null string.
void* read_image | ( | int * | width, |
int * | height, | ||
const char * | filename, | ||
unsigned | format | ||
) |
Read an image file as 32-bit RGBA data.
width,height | pointers to be filled with the image dimensions |
filename | image file name |
format | specifies the desired format for the image |
The calling syntax is that the filename is the input and width
, and height
and the returned pointer are outputs. read_image
allocates memory for the image as one contiguous block of memory and returns a pointer. It is the responsibility of the caller to call free
on this pointer when done to release this memory.
A non-null pointer indicates success. On failure, the returned pointer is null, and width
and height
are set to 0.
The format argument is used by specifying one of the data type options
and one of the channel options
and optionally either or both of the ordering options
With the default formatting IMAGEIO_U8 | IMAGEIO_RGBA, the image is organized in standard row major top-down 32-bit RGBA order. The image is organized as
(Top left) (Top right) image[0] image[1] ... image[width-1] image[width] image[width+1] ... image[2*width] ... ... ... ... image[width*(height-1)] ... ... image[width*height-1] (Bottom left) (Bottom right)
Each element image
[k] represents one RGBA pixel, which is a 32-bit bitfield. The components of pixel image
[k] can be unpacked as
Each component is an unsigned 8-bit integer value with range 0-255. Most images do not have alpha information, in which case the alpha component is set to value 255 (full opacity).
With IMAGEIO_SINGLE or IMAGEIO_DOUBLE, the components are values in the range 0 to 1.
int write_image | ( | void * | image, |
int | width, | ||
int | height, | ||
const char * | filename, | ||
unsigned | format, | ||
int | quality | ||
) |
Write an image file from 8-bit RGBA image data.
image | pointer to the image data |
width,height | image dimensions |
filename | image file name |
format | specifies how the data is formatted (see read_image) |
quality | the JPEG image quality (between 0 and 100) |
The input image
should be a 32-bit RGBA image stored as in the description of read_image
. write_image
writes to filename
in the file format specified by its extension. If saving a JPEG image, the quality
argument specifies the quality factor (between 0 and 100). quality
has no effect on other formats.
The return value indicates success with 1 or failure with 0.