Image File Formats

Image File Formats — Loading and saving image data to standard formats (JPEG, PNG, PNM)

Functions

Types and Values

Includes

#include <grx-3.0.h>

Description

These functions are used to load data from disk and store data to disk using standard file formats.

Functions

grx_context_save_to_pbm ()

gboolean
grx_context_save_to_pbm (GrxContext *context,
                         const gchar *filename,
                         const gchar *comment,
                         GError **error);

Dump a context in a PBM file (black and white)

This routine works both in RGB and palette modes If the pixel color isn't Black it asumes White

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of pbm file.

[type filename]

comment

string saved like a comment in the pbm file.

[nullable]

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_save_to_pgm ()

gboolean
grx_context_save_to_pgm (GrxContext *context,
                         const gchar *filename,
                         const gchar *comment,
                         GError **error);

Dump a context in a PGM file (gray scale)

This routine works both in RGB and palette modes The colors are quantized to gray scale using .299r + .587g + .114b

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of pgm file.

[type filename]

comment

string saved like a comment in the pgm file.

[nullable]

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_save_to_ppm ()

gboolean
grx_context_save_to_ppm (GrxContext *context,
                         const gchar *filename,
                         const gchar *comment,
                         GError **error);

Dump a context in a PPM file (real color)

This routine works both in RGB and palette modes

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of ppm file.

[type filename]

comment

string saved like a comment in the ppm file.

[nullable]

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_load_from_pnm ()

gboolean
grx_context_load_from_pnm (GrxContext *context,
                           const gchar *filename,
                           GError **error);

Load a context from a PNM file.

Support only PBM, PGM and PPM binary files with maxval < 256

If context dimensions are less than pnm dimensions, the routine loads as much as it can

If color mode is not in RGB mode, the routine allocates as many colors as it can

Parameters

context

Context to be loaded or NULL to use the global context.

[nullable]

filename

Name of pnm file.

[type filename]

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_query_pnm_file ()

gboolean
grx_query_pnm_file (const gchar *filename,
                    GrxPnmFormat *format,
                    gint *width,
                    gint *height,
                    gint *maxval);

Query format, width and height data from a PNM file

Parameters

filename

Name of pnm file.

[type filename]

format

the GrxPnmFormat of the file.

[out]

width

return pnm width.

[out]

height

return pnm height.

[out]

maxval

max color component value.

[out]

Returns

TRUE on success, otherwise FALSE


grx_context_load_from_pnm_data ()

gboolean
grx_context_load_from_pnm_data (GrxContext *context,
                                const guint8 *buffer);

Load a context from a PNM buffer

Support only PBM, PGM and PPM binary buffers with maxval < 256

If context dimensions are lesser than pnm dimensions, the routine loads as much as it can

If color mode is not in RGB mode, the routine allocates as much colors as it can

Parameters

context

Context to be loaded or NULL to use the global context.

[nullable]

buffer

Buffer that holds data

 

Returns

TRUE on success, otherwise FALSE


grx_query_pnm_data ()

gboolean
grx_query_pnm_data (GByteArray *data,
                    GrxPnmFormat *format,
                    gint *width,
                    gint *height,
                    gint *maxval);

Query format, width and height data from a PNM buffer

Parameters

data

The image data

 

format

the GrxPnmFormat of the file.

[out]

width

return pnm width.

[out]

height

return pnm height.

[out]

maxval

max color component value.

[out]

Returns

TRUE on success, otherwise FALSE


grx_context_save_to_png ()

gboolean
grx_context_save_to_png (GrxContext *context,
                         const gchar *filename,
                         GError **error);

Dump a context in a PNG file

This routine works both in RGB and palette modes

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of png file.

[type filename]

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_load_from_png ()

gboolean
grx_context_load_from_png (GrxContext *context,
                           const gchar *filename,
                           gboolean use_alpha,
                           GError **error);

Load a context from a PNG file

If context dimensions are less than png dimensions, the routine loads as much as it can

If color mode is not in RGB mode, the routine allocates as many colors as it can

Parameters

context

Context to be loaded or NULL to use the global context.

[nullable]

filename

Name of jpeg file.

[type filename]

use_alpha

if TRUE, use alpha channel if available

 

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_query_png_file ()

gboolean
grx_query_png_file (const gchar *filename,
                    gint *width,
                    gint *height);

Query width and height data from a PNG file

Parameters

filename

Name of jpeg file.

[type filename]

width

return pnm width.

[out]

height

return pnm height.

[out]

Returns

TRUE on success, otherwise FALSE


grx_context_load_from_jpeg ()

gboolean
grx_context_load_from_jpeg (GrxContext *context,
                            const gchar *filename,
                            gint scale,
                            GError **error);

Load a context from a JPEG file.

If context dimensions are less than jpeg dimensions, the function loads as much of the image as it can.

If color mode is not in RGB mode, the functions allocates as many colors as it can.

Parameters

context

Context to be loaded or NULL to use the global context.

[nullable]

filename

Name of jpeg file.

[type filename]

scale

scale the image to 1/scale, only 1, 2, 4 and 8 are supported

 

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_load_from_jpeg_data ()

gboolean
grx_context_load_from_jpeg_data (GrxContext *context,
                                 GByteArray *data,
                                 gint scale,
                                 GError **error);

Load a context from JPEG data.

If context dimensions are less than jpeg dimensions, the function loads as much of the image as it can.

If color mode is not in RGB mode, the functions allocates as many colors as it can.

Parameters

context

Context to be loaded or NULL to use the global context.

[nullable]

data

The jpeg data

 

scale

scale the image to 1/scale, only 1, 2, 4 and 8 are supported

 

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_query_jpeg_file ()

gboolean
grx_query_jpeg_file (const gchar *filename,
                     gint *width,
                     gint *height);

Query width and height data from a JPEG file

Parameters

filename

Name of jpeg file.

[type filename]

width

return image width.

[out]

height

return image height.

[out]

Returns

TRUE on success, otherwise FALSE


grx_query_jpeg_data ()

gboolean
grx_query_jpeg_data (GByteArray *data,
                     gint *width,
                     gint *height);

Query width and height data from a JPEG file

Parameters

data

The image data

 

width

return image width.

[out]

height

return image height.

[out]

Returns

TRUE on success, otherwise FALSE


grx_context_save_to_jpeg ()

gboolean
grx_context_save_to_jpeg (GrxContext *context,
                          const gchar *filename,
                          gint quality,
                          GError **error);

Dump a context in a JPEG file

This routine works both in RGB and palette modes

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of jpeg file.

[type filename]

quality

quality scaling (1 to 100) the normal value is 75

 

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE


grx_context_save_to_jpeg_grayscale ()

gboolean
grx_context_save_to_jpeg_grayscale (GrxContext *context,
                                    const gchar *filename,
                                    gint quality,
                                    GError **error);

Dump a context in a Gray JPEG file

This routine works both in RGB and palette modes

Parameters

context

Context to be saved or NULL to use the global context.

[nullable]

filename

Name of jpeg file.

[type filename]

quality

quality scaling (1 to 100) the normal value is 75

 

error

pointer to hold an error or NULL to ignore

 

Returns

TRUE on success, otherwise FALSE

Types and Values

enum GrxPnmFormat

PNM file formats.

Note: GRX supports load/save of binaries formats (4,5,6) only.

Members

GRX_PNM_FORMAT_ASCII_PBM

P1: black and white (1bpp) ascii file format

 

GRX_PNM_FORMAT_ASCII_PGM

P2: grayscale ascii file format

 

GRX_PNM_FORMAT_ASCII_PPM

P3: RGB ascii file format

 

GRX_PNM_FORMAT_BINARY_PBM

P4: black and white (1bpp) binary file format

 

GRX_PNM_FORMAT_BINARY_PGM

P5: grayscale binary file format

 

GRX_PNM_FORMAT_BINARY_PPM

P6: RGB binary file format