OPNGLIB
PNG optimization library
 All Data Structures Files Functions Typedefs Pages
Data Structures | Typedefs | Enumerations | Functions
opngcore.h File Reference

OPNGCORE is a PNG Compression Optimization and Recovery Engine. More...

#include <limits.h>
#include <stddef.h>
#include "optk/bits.h"

Go to the source code of this file.

Data Structures

struct  opng_options
 The user options structure. More...
 
struct  opng_version_info
 The version info structure. More...
 

Typedefs

typedef struct opng_optimizer opng_optimizer_t
 The optimizer type.
 
typedef struct opng_image opng_image_t
 The image type.
 

Enumerations

enum  {
  OPNG_MSG_ALL = 0, OPNG_MSG_DEBUG = 10, OPNG_MSG_INFO = 20, OPNG_MSG_WARNING = 30,
  OPNG_MSG_ERROR = 40, OPNG_MSG_CRITICAL = 50, OPNG_MSG_OFF = (unsigned int)(-1), OPNG_MSG_DEFAULT = OPNG_MSG_OFF
}
 Message severity levels. More...
 
enum  { OPNG_MSGFMT_RAW = 0, OPNG_MSGFMT_UNIX = 1, OPNG_MSGFMT_FANCY = 2, OPNG_MSGFMT_DEFAULT = OPNG_MSGFMT_UNIX }
 Message formats.
 
enum  {
  OPNG_OPTIM_LEVEL_MIN = -2, OPNG_OPTIM_LEVEL_MAX = 6, OPNG_OPTIM_LEVEL_FASTEST = -2, OPNG_OPTIM_LEVEL_FAST = -1,
  OPNG_OPTIM_LEVEL_DEFAULT = 2, OPNG_FILTER_MIN = 0, OPNG_FILTER_MAX = 5, OPNG_FILTER_SET_MASK = (1 << (5+1)) - (1 << 0),
  OPNG_ZCOMPR_LEVEL_MIN = 1, OPNG_ZCOMPR_LEVEL_MAX = 9, OPNG_ZCOMPR_LEVEL_SET_MASK = (1 << (9+1)) - (1 << 1), OPNG_ZMEM_LEVEL_MIN = 1,
  OPNG_ZMEM_LEVEL_MAX = 9, OPNG_ZMEM_LEVEL_SET_MASK = (1 << (9+1)) - (1 << 1), OPNG_ZSTRATEGY_MIN = 0, OPNG_ZSTRATEGY_MAX = 3,
  OPNG_ZSTRATEGY_SET_MASK = (1 << (3+1)) - (1 << 0), OPNG_ZWINDOW_BITS_MIN = 8, OPNG_ZWINDOW_BITS_MAX = 15, OPNG_ZWINDOW_BITS_SET_MASK = (1 << (15+1)) - (1 << 8)
}
 Encoder constants and limits.
 

Functions

opng_optimizer_topng_create_optimizer (void)
 Creates an optimizer object.
 
int opng_set_options (opng_optimizer_t *optimizer, const struct opng_options *user_options)
 Sets the user options in an optimizer object.
 
int opng_optimize_file (opng_optimizer_t *optimizer, const char *in_fname, const char *out_fname, const char *out_dirname)
 Optimizes an image file.
 
void opng_destroy_optimizer (opng_optimizer_t *optimizer)
 Destroys an optimizer object.
 
void opng_set_logging_name (const char *program_name)
 Sets the program name associated with the logger.
 
void opng_set_logging_level (unsigned int level)
 Sets the logging severity level.
 
void opng_set_logging_format (int format)
 Sets the logging format.
 
int opng_flush_logging (unsigned int level)
 Flushes the logger at the given severity level.
 
int opng_print_message (unsigned int level, const char *fname, const char *message)
 Prints a message of a given severity level, concerning a given file name, using the current logging message format, to the logger.
 
int opng_debugf (const char *format,...)
 Prints a printf-formatted debug message (level = OPNG_MSG_DEBUG) to the logger.
 
int opng_printf (const char *format,...)
 Prints a printf-formatted informational message (level = OPNG_MSG_INFO) to the logger.
 
int opng_warning (const char *fname, const char *message)
 Prints a warning message (level = OPNG_MSG_WARNING) to the logger.
 
int opng_error (const char *fname, const char *message, const char *submessage)
 Prints an error message (level = OPNG_MSG_ERROR), optionally accompanied by a submessage, to the logger.
 
struct opng_version_infoopng_get_version_info (void)
 Returns an array of version info objects, terminated by NULLs.
 

Detailed Description

OPNGCORE is a PNG Compression Optimization and Recovery Engine.

Copyright (C) 2001-2012 Cosmin Truta.

This software is distributed under the zlib license. Please see the accompanying LICENSE file, or visit http://www.opensource.org/licenses/zlib-license.php

Typedef Documentation

typedef struct opng_image opng_image_t

The image type.

Image objects are currently used internally only. There is no public API to access them yet.

Todo:
3rd-party applications may wish to use this type in order to create optimized PNG files from in-memory images (e.g. in-memory compressed files, raw pixel data, BMP handles, etc.). Your contribution will be appreciated ;-)
typedef struct opng_optimizer opng_optimizer_t

The optimizer type.

An optimizer object can optimize one or more images, sequentially.

Bug:
Multiple optimizer objects are designed to run in parallel (but they don't, yet).

Enumeration Type Documentation

anonymous enum

Message severity levels.

Each level allows up to 10 custom sub-levels. The level numbers are loosely based on the Python logging module.

Function Documentation

opng_optimizer_t* opng_create_optimizer ( void  )

Creates an optimizer object.

Returns
the optimizer created, or NULL on failure.
void opng_destroy_optimizer ( opng_optimizer_t optimizer)

Destroys an optimizer object.

Parameters
optimizerthe optimizer object to be destroyed.
int opng_flush_logging ( unsigned int  level)

Flushes the logger at the given severity level.

To avoid useless fflush operations, it is recommended to set the severity level to the level of the messages that have been displayed and need to be flushed.

Parameters
levelthe minimum severity level at which flushing is triggered.
int opng_optimize_file ( opng_optimizer_t optimizer,
const char *  in_fname,
const char *  out_fname,
const char *  out_dirname 
)

Optimizes an image file.

Parameters
optimizerthe optimizer object.
in_fnamethe input file name.
out_fnamethe output file name. It can be NULL, in which case the output has the same name as the input.
out_dirnamethe output directory name. It can be NULL.
Returns
0 on success, or a non-zero exit code on failure.
int opng_print_message ( unsigned int  level,
const char *  fname,
const char *  message 
)

Prints a message of a given severity level, concerning a given file name, using the current logging message format, to the logger.

Parameters
fnamethe file name associated with the message; can be NULL.
levelthe severity level OPNG_MSG_...
messagethe message to be displayed.
Returns
1 if a message was displayed, 0 if nothing was displayed, or -1 if an error occurred.
void opng_set_logging_format ( int  format)

Sets the logging format.

Parameters
formatthe format OPNG_MSGFMT_...
See Also
opng_print_message.
void opng_set_logging_level ( unsigned int  level)

Sets the logging severity level.

Parameters
levelthe severity level OPNG_MSG_...
See Also
opng_print_message.
void opng_set_logging_name ( const char *  program_name)

Sets the program name associated with the logger.

Parameters
program_namethe program name displayed on warnings or errors. It can be NULL.
int opng_set_options ( opng_optimizer_t optimizer,
const struct opng_options user_options 
)

Sets the user options in an optimizer object.

An optimizer can run only if it has been given a set of options; there are no defaults. Options can be changed repeatedly between optimization sessions (for the benefit of interactive applications), but they shall not be changed during these sessions.

Parameters
optimizerthe optimizer object whose user options are changed.
user_optionsthe user options.
Returns
0 if the options are valid, or -1 otherwise.