Total Variation Inpainting using Split Bregman
|
Implements ReadImage and WriteImage functions. More...
Go to the source code of this file.
Macros | |
#define | FILE_BUFFER_CAPACITY (1024*4) |
Buffer size to use for BMP file I/O. | |
#define | ROUNDCLAMPF(x) |
#define | ROUNDCLAMP(x) |
Functions | |
static int | StringEndsWith (const char *String, const char *Suffix) |
Case-insensitive test to see if String ends with Suffix. | |
static void | FillImage (uint32_t *Image, int Width, int Height, uint32_t Color) |
Fill an image with a color. | |
static uint32_t * | GetImagePalette (int *NumColors, int *UseColor, int *UseAlpha, const uint32_t *Image, int Width, int Height) |
Check use of color and alpha, and count number of distinct colors. More... | |
static uint16_t | ReadWordLE (FILE *File) |
Read a 16-bit little Endian word from File. | |
static uint32_t | ReadDWordLE (FILE *File) |
Read a 32-bit little Endian double word from File. | |
static void | WriteWordLE (uint16_t w, FILE *File) |
Write a 16-bit word in little Endian format. | |
static void | WriteDWordLE (uint32_t dw, FILE *File) |
Write a 32-bit double word in little Endian format. | |
static int | ReadBmp1Bit (uint32_t *Image, int Width, int Height, FILE *File, const uint32_t *Palette) |
Internal function for reading 1-bit BMP. | |
static int | ReadBmp4Bit (uint32_t *Image, int Width, int Height, FILE *File, const uint32_t *Palette) |
Internal function for reading 4-bit BMP. | |
static int | ReadBmp4BitRle (uint32_t *Image, int Width, int Height, FILE *File, const uint32_t *Palette) |
Internal function for reading 4-bit RLE-compressed BMP. | |
static int | ReadBmp8Bit (uint32_t *Image, int Width, int Height, FILE *File, const uint32_t *Palette) |
Internal function for reading 8-bit BMP. | |
static int | ReadBmp8BitRle (uint32_t *Image, int Width, int Height, FILE *File, const uint32_t *Palette) |
Internal function for reading 8-bit RLE-compressed BMP. | |
static int | ReadBmp24Bit (uint32_t *Image, int Width, int Height, FILE *File) |
Internal function for reading 24-bit BMP. | |
static void | GetMaskShifts (uint32_t Mask, int *LeftShift, int *RightShift) |
Internal function for determining bit shifts in bitfield BMP. | |
static int | ReadBmp16Bit (uint32_t *Image, int Width, int Height, FILE *File, uint32_t RedMask, uint32_t GreenMask, uint32_t BlueMask, uint32_t AlphaMask) |
Internal function for reading 16-bit BMP. | |
static int | ReadBmp32Bit (uint32_t *Image, int Width, int Height, FILE *File, uint32_t RedMask, uint32_t GreenMask, uint32_t BlueMask, uint32_t AlphaMask) |
Internal function for reading 32-bit BMP. | |
static int | ReadBmp (uint32_t **Image, int *Width, int *Height, FILE *File) |
Read a BMP (Windows Bitmap) image file as RGBA data. More... | |
static int | WriteBmp (const uint32_t *Image, int Width, int Height, FILE *File) |
Write a BMP image. More... | |
static void * | ConvertToFormat (uint32_t *Src, int Width, int Height, unsigned Format) |
Convert from RGBA U8 to a specified format. | |
static uint32_t * | ConvertFromFormat (void *Src, int Width, int Height, unsigned Format) |
Convert from a specified format to RGBA U8. | |
int | IdentifyImageType (char *Type, const char *FileName) |
Identify the file type of an image file by its magic numbers. More... | |
void * | ReadImage (int *Width, int *Height, const char *FileName, unsigned Format) |
Read an image file as 32-bit RGBA data. More... | |
int | WriteImage (void *Image, int Width, int Height, const char *FileName, unsigned Format, int Quality) |
Write an image file from 8-bit RGBA image data. More... | |
Implements ReadImage and WriteImage functions.
Two high-level functions are provided, ReadImage
and WriteImage
, for reading and writing image BMP, JPEG, PNG, and TIFF files. The desired format of the image data can be specified to ReadImage
for how to return the data (and similarly to WriteImage
for how it should interpret the data). Formatting options allow specifying the datatype of the components, conversion to grayscale, channel ordering, interleaved vs. planar, and row-major vs. column-major.
ReadImage
automatically detects the format of the image being read so that the format does not need to be supplied explicitly. WriteImage
infers the file format from the file extension.
Also included is a function IdentifyImageType
to guess the file type (BMP, JPEG, PNG, TIFF, and a few other formats) from the file header's magic numbers without reading the image.
Support for BMP reading and writing is native: BMP reading supports 1-, 2-, 4-, 8-, 16-, 32-bit uncompressed, RLE, and bitfield images; BMP writing is limited to 24-bit uncompressed. The implementation calls libjpeg, libpng, and libtiff to handle JPEG, PNG, and TIFF images.
Copyright (c) 2010-2012, Pascal Getreuer All rights reserved.
This program is free software: you can use, modify and/or redistribute it under the terms of the simplified BSD License. You should have received a copy of this license along this program. If not, see http://www.opensource.org/licenses/bsd-license.html.
Definition in file imageio.c.
#define ROUNDCLAMP | ( | x | ) |
#define ROUNDCLAMPF | ( | x | ) |
|
static |
Check use of color and alpha, and count number of distinct colors.
NumColors | set by the routine to the number of unique colors |
UseColor | set to 1 if the image is not grayscale |
UseAlpha | set to 1 if the image alpha is not constant 255 |
Image | pointer to U8 RGBA interleaved image data |
Width,Height | dimensions of the image |
This routine checks whether an RGBA image makes use of color and alpha, and constructs a palette if the number of distinct colors is 256 or fewer. This information is useful for writing image files with smaller file size.
int IdentifyImageType | ( | 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.
|
static |
Read a BMP (Windows Bitmap) image file as RGBA data.
Image,Width,Height | pointers to be filled with the pointer to the image data and the image dimensions. |
File | stdio FILE pointer pointing to the beginning of the BMP file |
This function is called by ReadImage
to read BMP images. Before calling ReadBmp
, the caller should open File
as a FILE pointer in binary read mode. When ReadBmp
is complete, the caller should close File
.
void* ReadImage | ( | 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. ReadImage
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.
|
static |
Write a BMP image.
Image | pointer to RGBA image data |
Width,Height | the image dimensions |
File | stdio FILE pointer |
This function is called by WriteImage
to write BMP images. The caller should open File
in binary write mode. When WriteBmp
is complete, the caller should close File
.
The image is generally saved in uncompressed 24-bit RGB format. But where possible, the image is saved using an 8-bit palette for a substantial decrease in file size. The image data is always saved losslessly.
int WriteImage | ( | 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 ReadImage) |
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 ReadImage
. WriteImage
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.