libmng (3) - Linux Manuals
libmng: Multiple-image Network Graphics (MNG) Reference Library 1.0.9
NAME
libmng - Multiple-image Network Graphics (MNG) Reference Library 1.0.9SYNOPSIS
#include <libmng.h>
DESCRIPTION
The libmng library supports decoding, displaying, encoding, and various other manipulations of the Multiple-image Network Graphics (MNG) format image files. It uses the zlib(3) compression library, and optionally the JPEG library by the Independant JPEG Group (IJG) and/or lcms (little cms), a color-management library by Marti Maria Saguer.
I. Introduction
This file describes how to use and modify the MNG reference library (known as libmng) for your own use. There are seven sections to this file: introduction, callbacks, housekeeping, reading, displaying, writing, and modification and configuration notes for various special platforms. We assume that libmng is already installed; see the INSTALL.README file for instructions on how to install libmng.
Libmng was written to support and promote the MNG specification.
The MNG-1.0 specification is available at <http://www.libpng.org/pub/mng/spec/>.
Other information about MNG can be found at the MNG home page, <http://www.libpng.org/pub/mng/>. The latest version of libmng can be found at its own homepage at <http://www.libmng.com/>.
In most cases the library will not need to be changed. For standardization purposes the library contains both a Windows DLL and a makefile for building a shared library (SO). The library is written in C, but an interface for Borland Delphi is also available.
Libmng has been designed to handle multiple sessions at one time, to be easily modifiable, to be portable to the vast majority of machines (ANSI, K&R, 32-, and 64-bit) available, and to be easy to use.
Libmng uses zlib for its compression and decompression of MNG files. Further information about zlib, and the latest version of zlib, can be found at the zlib home page, <http://www.zlib.org/>. The zlib compression utility is a general purpose utility that is useful for more than MNG/PNG files, and can be used without libmng. See the documentation delivered with zlib for more details.
Libmng optionally uses the JPEG library by the Independant JPEG Group (IJG). This library is used for the JNG sub-format, which is part of the MNG specification, and allows for inclusion of JPEG decoded and thus highly compressed (photographic) images. Further information about the IJG JPEG library and the latest sources can be found at <http://www.ijg.org/>.
Libmng can also optionally use the lcms (little CMS) library by Marti Maria Saguer. This library provides an excellent color-management system (CMS), which gives libmng the ability to provide full color-correction for images with the proper color-information encoded. Further information and the latest sources can be found at <http://www.littlecms.com/>.
Libmng is thread safe, provided the threads are using different handles as returned by the initialization call. Each thread should have its own handle and thus its own image. Libmng does not protect itself against two threads using the same instance of a handle.
The libmng.h header file is the single reference needed for programming with libmng:
#include <libmng.h>
II. Callbacks
Libmng makes extensive use of callback functions. This is meant to keep the library as platform-independant and flexible as possible. Actually, the first call you will make to the library, already contains three parameters you can use to provide callback entry-points.
Most functions must return a mng_bool (boolean). Returning MNG_FALSE indicates the library the callback failed in some way and the library will immediately return from whatever it was doing back to the application. Returning MNG_TRUE indicates there were no problems and processing can continue.
Let's step through each of the possible callbacks. The sections on reading, displaying and writing will also explain which callbacks are needed when and where.
- mng_ptr mng_memalloc (mng_size_t iLen)
A very basic function which the library uses to allocate a memory-block with the given size. A typical implementation would be:
Note that the library requires you to zero-out the memory-block!!!
- void mng_memfree (mng_ptr pPtr,
Counterpart of the previous function. Typically:
- mng_bool mng_openstream (mng_handle hHandle)
- mng_bool mng_closestream (mng_handle hHandle)
These are called by the library just before it starts to process
(either read or write) a file and just after the processing stops.
This is the recommended place to do I/O initialization & finalization.
Whether you do or not, is up to you. The library does not put any
meaning into the calls. They are simply provided for your convenience.
- mng_bool mng_readdata (mng_handle hHandle,
In NSMOD, the library requires you to return exactly the amount of bytes
requested (= iBuflen). Any lesser amount indicates the input file
is exhausted and the library will return a MNG_UNEXPECTEDEOF errorcode.
In SMOD, you may return a smaller amount of bytes than requested.
This tells the library it should temporarily wait for more input to
arrive. The lib will return with MNG_NEEDMOREDATA, and will expect a
call to mng_read_resume() or mng_display_resume() next, as soon as
more input-data has arrived.
For NSMOD this function could be as simple as:
- mng_bool mng_writedata (mng_handle hHandle,
This function is called during the mng_write() function to actually
output data to the file. There is no suspension-mode during write,
so the application must return the exact number of bytes the library
requests to be written.
A typical implementation could be:
return calloc
free
*pRead
return MNG_TRUE;