Meanshift  1.0
Macros | Functions
io_png.c File Reference

PNG read/write simplified interface. More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <png.h>
#include "io_png.h"
Include dependency graph for io_png.c:

Macros

#define PNG_SIG_LEN   4
 
#define IO_PNG_U8   0x0001 /* 8bit unsigned integer */
 
#define IO_PNG_F32   0x0002 /* 32bit float */
 

Functions

char * io_png_info (void)
 helps tracking versions, via the string tag inserted into the library More...
 
unsigned char * io_png_read_u8 (const char *fname, size_t *nxp, size_t *nyp, size_t *ncp)
 read a PNG file into a 8bit integer array More...
 
unsigned char * io_png_read_u8_rgb (const char *fname, size_t *nxp, size_t *nyp)
 read a PNG file into a 8bit integer array, converted to RGB More...
 
unsigned char * io_png_read_u8_gray (const char *fname, size_t *nxp, size_t *nyp)
 read a PNG file into a 8bit integer array, converted to gray More...
 
float * io_png_read_f32 (const char *fname, size_t *nxp, size_t *nyp, size_t *ncp)
 read a PNG file into a 32bit float array More...
 
float * io_png_read_f32_rgb (const char *fname, size_t *nxp, size_t *nyp)
 read a PNG file into a 32bit float array, converted to RGB More...
 
float * io_png_read_f32_gray (const char *fname, size_t *nxp, size_t *nyp)
 read a PNG file into a 32bit float array, converted to gray More...
 
int io_png_write_u8 (const char *fname, const unsigned char *data, size_t nx, size_t ny, size_t nc)
 write a 8bit unsigned integer array into a PNG file More...
 
int io_png_write_f32 (const char *fname, const float *data, size_t nx, size_t ny, size_t nc)
 write a float array into a PNG file More...
 

Detailed Description

PNG read/write simplified interface.

This is a front-end to libpng, with routines to:

Multi-channel images are handled: grey, grey+alpha, rgb and rgb+alpha, as well as on-the-fly color model conversion.

Todo:

handle lossless 16bit data

add a test suite

internally handle RGB/gray conversion in io_png_read_raw()

handle deinterlacing as a libpng transform function

Author
Nicolas Limare nicol.nosp@m.as.l.nosp@m.imare.nosp@m.@cml.nosp@m.a.ens.nosp@m.-cac.nosp@m.han.f.nosp@m.r

Function Documentation

◆ io_png_info()

char* io_png_info ( void  )

helps tracking versions, via the string tag inserted into the library

This function is not expected to be used in real-world programs.

Returns
a pointer to a version info string

◆ io_png_read_f32()

float* io_png_read_f32 ( const char *  fname,
size_t *  nxp,
size_t *  nyp,
size_t *  ncp 
)

read a PNG file into a 32bit float array

The array contains the deinterlaced channels. 1, 2, 4 and 8bit images are converted to float values between 0. and 1., 3., 15. or 255. 16bit images are also downscaled to 8bit before conversion.

Parameters
fnamePNG file name
nxp,nyp,ncppointers to variables to be filled with the number of columns, lines and channels of the image
Returns
pointer to an allocated unsigned char array of pixels, or NULL if an error happens

◆ io_png_read_f32_gray()

float* io_png_read_f32_gray ( const char *  fname,
size_t *  nxp,
size_t *  nyp 
)

read a PNG file into a 32bit float array, converted to gray

See io_png_read_f32() for details.

◆ io_png_read_f32_rgb()

float* io_png_read_f32_rgb ( const char *  fname,
size_t *  nxp,
size_t *  nyp 
)

read a PNG file into a 32bit float array, converted to RGB

See io_png_read_f32() for details.

◆ io_png_read_u8()

unsigned char* io_png_read_u8 ( const char *  fname,
size_t *  nxp,
size_t *  nyp,
size_t *  ncp 
)

read a PNG file into a 8bit integer array

The array contains the deinterlaced channels. 1, 2 and 4bit images are converted to 8bit. 16bit images are previously downscaled to 8bit.

Todo:
don't downscale 16bit images.
Parameters
fnamePNG file name
nxp,nyp,ncppointers to variables to be filled with the number of columns, lines and channels of the image
Returns
pointer to an allocated unsigned char array of pixels, or NULL if an error happens

◆ io_png_read_u8_gray()

unsigned char* io_png_read_u8_gray ( const char *  fname,
size_t *  nxp,
size_t *  nyp 
)

read a PNG file into a 8bit integer array, converted to gray

See io_png_read_u8() for details.

◆ io_png_read_u8_rgb()

unsigned char* io_png_read_u8_rgb ( const char *  fname,
size_t *  nxp,
size_t *  nyp 
)

read a PNG file into a 8bit integer array, converted to RGB

See io_png_read_u8() for details.

◆ io_png_write_f32()

int io_png_write_f32 ( const char *  fname,
const float *  data,
size_t  nx,
size_t  ny,
size_t  nc 
)

write a float array into a PNG file

The float values are rounded to 8bit integers, and bounded to [0, 255].

Todo:
handle 16bit images and flexible min/max
Parameters
fnamePNG file name
dataarray to write
nx,ny,ncnumber of columns, lines and channels of the image
Returns
0 if everything OK, -1 if an error occured

◆ io_png_write_u8()

int io_png_write_u8 ( const char *  fname,
const unsigned char *  data,
size_t  nx,
size_t  ny,
size_t  nc 
)

write a 8bit unsigned integer array into a PNG file

Parameters
fnamePNG file name
dataarray to write
nx,ny,ncnumber of columns, lines and channels of the image
Returns
0 if everything OK, -1 if an error occured