source: trunk/src/3rdparty/libmng/doc/man/libmng.3

Last change on this file was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 40.5 KB
Line 
1.TH LIBMNG 3 "January 30th, 2005"
2.SH NAME
3libmng \- Multiple-image Network Graphics (MNG) Reference Library 1.0.9
4.SH SYNOPSIS
5\fI\fB
6
7\fB#include <libmng.h>\fP
8
9
10.SH DESCRIPTION
11The
12.I libmng
13library supports decoding, displaying, encoding, and various other
14manipulations of the Multiple-image Network Graphics (MNG) format
15image files. It uses the
16.IR zlib(3)
17compression library, and optionally the JPEG library by the Independant
18JPEG Group (IJG) and/or lcms (little cms), a color-management library
19by Marti Maria Saguer.
20
21
22.SH I. Introduction
23
24This file describes how to use and modify the MNG reference library
25(known as libmng) for your own use. There are seven sections to this
26file: introduction, callbacks, housekeeping, reading, displaying,
27writing, and modification and configuration notes for various special
28platforms. We assume that libmng is already installed; see the
29INSTALL.README file for instructions on how to install libmng.
30
31Libmng was written to support and promote the MNG specification.
32
33The MNG-1.0 specification is available at
34<http://www.libpng.org/pub/mng/spec/>.
35
36Other information about MNG can be found at the MNG home page,
37<http://www.libpng.org/pub/mng/>.
38The latest version of libmng can be found at its own homepage at
39<http://www.libmng.com/>.
40
41In most cases the library will not need to be changed.
42For standardization purposes the library contains both a Windows DLL
43and a makefile for building a shared library (SO). The library is
44written in C, but an interface for Borland Delphi is also available.
45
46Libmng has been designed to handle multiple sessions at one time,
47to be easily modifiable, to be portable to the vast majority of
48machines (ANSI, K&R, 32-, and 64-bit) available, and to be easy
49to use.
50
51Libmng uses zlib for its compression and decompression of MNG files.
52Further information about zlib, and the latest version of zlib, can be
53found at the zlib home page, <http://www.zlib.org/>.
54The zlib compression utility is a general purpose utility that is
55useful for more than MNG/PNG files, and can be used without libmng.
56See the documentation delivered with zlib for more details.
57
58Libmng optionally uses the JPEG library by the Independant JPEG Group
59(IJG). This library is used for the JNG sub-format, which is part of
60the MNG specification, and allows for inclusion of JPEG decoded and
61thus highly compressed (photographic) images.
62Further information about the IJG JPEG library and the latest sources
63can be found at <http://www.ijg.org/>.
64
65Libmng can also optionally use the lcms (little CMS) library by
66Marti Maria Saguer. This library provides an excellent color-management
67system (CMS), which gives libmng the ability to provide full
68color-correction for images with the proper color-information encoded.
69Further information and the latest sources can be found at
70<http://www.littlecms.com/>.
71
72Libmng is thread safe, provided the threads are using different
73handles as returned by the initialization call.
74Each thread should have its own handle and thus its own image.
75Libmng does not protect itself against two threads using the
76same instance of a handle.
77
78The libmng.h header file is the single reference needed for programming
79with libmng:
80
81#include <libmng.h>
82
83
84.SH II. Callbacks
85
86Libmng makes extensive use of callback functions. This is meant to
87keep the library as platform-independant and flexible as possible.
88Actually, the first call you will make to the library, already contains
89three parameters you can use to provide callback entry-points.
90
91Most functions must return a mng_bool (boolean). Returning MNG_FALSE
92indicates the library the callback failed in some way and the library
93will immediately return from whatever it was doing back to the
94application. Returning MNG_TRUE indicates there were no problems and
95processing can continue.
96
97Let's step through each of the possible callbacks. The sections on
98reading, displaying and writing will also explain which callbacks are
99needed when and where.
100
101\- mng_ptr mng_memalloc (mng_size_t iLen)
102
103A very basic function which the library uses to allocate a memory-block
104with the given size. A typical implementation would be:
105
106 mng_ptr my_alloc (mng_size_t iLen) {
107 return calloc (1, iLen);
108 }
109
110Note that the library requires you to zero-out the memory-block!!!
111
112\- void mng_memfree (mng_ptr pPtr,
113 mng_size_t iLen)
114
115Counterpart of the previous function. Typically:
116
117 void my_free (mng_ptr pPtr, mng_size_t iLen) {
118 free (pPtr);
119 }
120
121\- mng_bool mng_openstream (mng_handle hHandle)
122
123\- mng_bool mng_closestream (mng_handle hHandle)
124
125These are called by the library just before it starts to process
126(either read or write) a file and just after the processing stops.
127This is the recommended place to do I/O initialization & finalization.
128Whether you do or not, is up to you. The library does not put any
129meaning into the calls. They are simply provided for your convenience.
130
131\- mng_bool mng_readdata (mng_handle hHandle,
132 mng_ptr pBuf,
133 mng_uint32 iBuflen,
134 mng_uint32p pRead)
135
136This function is called when the library needs some more input while
137reading an image. The reading process supports two modes:
138Suspension-mode (SMOD) and non-suspension-mode (NSMOD).
139See mng_set_suspensionmode() for a more detailed description.
140
141In NSMOD, the library requires you to return exactly the amount of bytes
142requested (= iBuflen). Any lesser amount indicates the input file
143is exhausted and the library will return a MNG_UNEXPECTEDEOF errorcode.
144
145In SMOD, you may return a smaller amount of bytes than requested.
146This tells the library it should temporarily wait for more input to
147arrive. The lib will return with MNG_NEEDMOREDATA, and will expect a
148call to mng_read_resume() or mng_display_resume() next, as soon as
149more input-data has arrived.
150
151For NSMOD this function could be as simple as:
152
153 mng_bool my_read (mng_handle hHandle,
154 mng_ptr pBuf,
155 mng_uint32 iBuflen,
156 mng_uint32p pRead) {
157 *pRead = fread (pBuf, 1, iBuflen, myfile);
158 return MNG_TRUE;
159 }
160
161\- mng_bool mng_writedata (mng_handle hHandle,
162 mng_ptr pBuf,
163 mng_uint32 iBuflen,
164 mng_uint32p pWritten)
165
166This function is called during the mng_write() function to actually
167output data to the file. There is no suspension-mode during write,
168so the application must return the exact number of bytes the library
169requests to be written.
170
171A typical implementation could be:
172
173 mng_bool my_write (mng_handle hHandle,
174 mng_ptr pBuf,
175 mng_uint32 iBuflen,
176 mng_uint32p pWritten) {
177 *pWritten = fwrite (pBuf, 1, iBuflen, myfile);
178 return MNG_TRUE;
179 }
180
181\- mng_bool mng_errorproc (mng_handle hHandle,
182 mng_int32 iErrorcode,
183 mng_int8 iSeverity,
184 mng_chunkid iChunkname,
185 mng_uint32 iChunkseq,
186 mng_int32 iExtra1,
187 mng_int32 iExtra2,
188 mng_pchar zErrortext)
189
190This function is called whenever an error is detected inside the
191library. This may be caused by invalid input, callbacks indicating
192failure, or wrongfully calling functions out of place.
193
194If you do not provide this callback the library will still return
195an errorcode from the called function, and the mng_getlasterror()
196function can be used to retrieve the other parameters.
197
198This function is currently only provided for convenience, but may
199at some point be used to indicate certain errors may be acceptable,
200and processing should continue.
201
202\- mng_bool mng_traceproc (mng_handle hHandle,
203 mng_int32 iFuncnr,
204 mng_int32 iFuncseq,
205 mng_pchar zFuncname)
206
207This function is provided to allow a functional analysis of the
208library. This may be useful if you encounter certain errors and
209cannot determine what the problem is.
210
211Almost all functions inside the library will activate this
212callback with an appropriate function-name at the start and end
213of the function. Please note that large images may generate an
214enormous amount of calls.
215
216\- mng_bool mng_processheader (mng_handle hHandle,
217 mng_uint32 iWidth,
218 mng_uint32 iHeight)
219
220This function is called once the header information of an input-
221image has been processed. At this point the image dimensions are
222available and also some other properties depending on the type
223of the image. Eg. for a MNG the frame-/layercount, playtime &
224simplicity fields are known.
225
226The primary purpose of this callback is to inform the application
227of the size of the image, and for the application to initialize
228the drawing canvas to be used by the library. This is also a good
229point to set the canvas-style. Eg. mng_set_canvasstyle().
230
231\- mng_bool mng_processtext (mng_handle hHandle,
232 mng_uint8 iType,
233 mng_pchar zKeyword,
234 mng_pchar zText,
235 mng_pchar zLanguage,
236 mng_pchar zTranslation)
237
238This callback is activated for each textual chunk in the input-
239image. These are tEXt, zTXt & iTXt. It may be used to retain
240specific comments for presentation to the user.
241
242\- mng_bool mng_processsave (mng_handle hHandle)
243
244\- mng_bool mng_processseek (mng_handle hHandle,
245 mng_pchar zName)
246
247The purpose of these callbacks is to signal the processing of the
248SAVE & SEEK chunks in a MNG input-file. This may be used in the
249future to specify some special processing. At the moment these
250functions are only provided as a signal.
251
252\- mng_ptr mng_getcanvasline (mng_handle hHandle,
253 mng_uint32 iLinenr)
254
255\- mng_ptr mng_getbkgdline (mng_handle hHandle,
256 mng_uint32 iLinenr)
257
258\- mng_ptr mng_getalphaline (mng_handle hHandle,
259 mng_uint32 iLinenr)
260
261These callbacks are used to access the drawing canvas, background
262canvas and an optional separate alpha-channel canvas. The latter is
263used only with the MNG_CANVAS_RGB8_A8 canvas-style.
264
265If the getbkgdline() callback is not supplied the library will
266composite fully or partially transparent pixels in the image against
267a specified background color. See mng_set_bgcolor() for more details.
268If a chosen canvas-style includes an alpha-channel, this callback
269is very likely not needed.
270
271The application is responsible for returning a pointer to a line of
272pixels, which should be in the exact format as defined by the call
273to mng_set_canvasstyle() and mng_set_bkgdstyle(), without gaps between
274the representation of each pixel, unless specified by the canvas-style.
275
276\- mng_bool mng_refresh (mng_handle hHandle,
277 mng_uint32 iX,
278 mng_uint32 iY,
279 mng_uint32 iWidth,
280 mng_uint32 iHeight)
281
282This callback is called when the library has drawn a complete frame
283onto the drawing canvas, and it is ready to be displayed.
284The application is responsible for transferring the drawing canvas
285from memory onto the actual output device.
286
287\- mng_uint32 mng_gettickcount (mng_handle hHandle)
288
289This function should return the number of milliseconds on some internal
290clock. The entire animation timing depends heavily on this function,
291and the number returned should be as accurate as possible.
292
293\- mng_bool mng_settimer (mng_handle hHandle,
294 mng_uint32 iMsecs)
295
296This callback is activated every time the library requires a "pause".
297Note that the function itself should NOT execute the wait. It should
298simply store the time-field and allow the library to return. Libmng
299will return with the MNG_NEEDTIMERWAIT code, indicating the callback
300was called and it is now time to execute the pause.
301
302After the indicated number of milliseconds have elapsed, the application
303should call mng_display_resume(), to resume the animation as planned.
304
305This method allows for both a real timer or a simple wait command in the
306application. Whichever method you select, both the gettickcount() and
307settimer() callbacks are crucial for proper animation timing.
308
309\- mng_bool mng_processgamma (mng_handle hHandle,
310 mng_uint32 iGamma)
311
312\- mng_bool mng_processchroma (mng_handle hHandle,
313 mng_uint32 iWhitepointx,
314 mng_uint32 iWhitepointy,
315 mng_uint32 iRedx,
316 mng_uint32 iRedy,
317 mng_uint32 iGreenx,
318 mng_uint32 iGreeny,
319 mng_uint32 iBluex,
320 mng_uint32 iBluey)
321
322\- mng_bool mng_processsrgb (mng_handle hHandle,
323 mng_uint8 iRenderingintent)
324
325\- mng_bool mng_processiccp (mng_handle hHandle,
326 mng_uint32 iProfilesize,
327 mng_ptr pProfile)
328
329\- mng_bool mng_processarow (mng_handle hHandle,
330 mng_uint32 iRowsamples,
331 mng_bool bIsRGBA16,
332 mng_ptr pRow)
333
334These callbacks are only required when you selected the MNG_APP_CMS
335directive during compilation of the library. See the configuration
336section for more details.
337
338\- mng_bool mng_iteratechunk (mng_handle hHandle,
339 mng_handle hChunk,
340 mng_chunkid iChunkid,
341 mng_uint32 iChunkseq)
342
343This callback is only used for the mng_iterate_chunks() function.
344It is called exactly once for each chunk stored.
345
346
347.SH III. Housekeeping
348
349
350.SS Memory management
351
352The library can use internal memory allocation/deallocation or use
353provided callbacks for its memory management. The choice is made at
354compilation time. See the section on customization for details.
355
356If internal management has been selected, the memory callback functions
357need not be supplied. Even if you do supply them they will not be used.
358The actual code used is similar to the code discussed in the callback
359section:
360
361 pPtr = calloc (1, iLen);
362
363 free (pPtr);
364
365If your compiler does not support these functions, or you wish to monitor
366the library's use of memory for certain reasons, you can choose to
367compile the library with external memory management. In this case the
368memory callback functions MUST be supplied, and should function as if the
369above code was used.
370
371
372.SS Initialization
373
374The basic initialization of the library is short and swift:
375
376 myhandle = mng_initialize (myuserdata, my_alloc,
377 my_free, MNG_NULL);
378 if (myhandle == MNG_NULL)
379 /* process error */;
380
381The first field is an application-only parameter. It is saved in
382libmng's internal structures and available at all times through the
383mng_get_userdata() function. This is especially handy in callback functions
384if your program may be handling multiple files at the same time.
385
386The second and third field supply the library with the memory callback
387function entry-points. These are described in more detail in the callback
388section and the previous paragraph.
389
390The fourth and last field may be used to supply the library with the
391entry-point of a trace callback function. For regular use you will not
392need this!
393
394The function returns a handle which will be your ticket to MNG-heaven.
395All other functions rely on this handle. It is the single fixed unique
396reference-point between your application and the library.
397
398You should call the initialization function for each image you wish to
399process simultaneously. If you are processing images consecutively, you can
400reset the internal status of the library with the mng_reset() function.
401This function will clear all internal state variables, free any stored
402chunks and/or objects, etc, etc. Your callbacks and other external parameters
403will be retained.
404
405After you successfully received the handle it is time to set the required
406callbacks. The sections on reading, displaying & writing indicate which
407callbacks are required and which are optional.
408To set the callbacks simply do:
409
410 myretcode = mng_setcb_xxxxxx (myhandle, my_xxxxxx);
411 if (myretcode != MNG_NOERROR)
412 /* process error */;
413
414Naturally you'd replace the x's with the name of the callback.
415
416
417.SS Cleanup
418
419Once you've gotten hold of that precious mng_handle, you should always,
420and I mean always, call the cleanup function when you're done.
421Just do:
422
423 mng_cleanup (myhandle);
424
425And you're done. There shouldn't be an ounce of memory spilled after
426that call.
427
428Note that if you would like to process multiple files consecutively
429you do not need to do mng_cleanup() / mng_initialize() between each file
430but simply
431
432 myretcode = mng_reset (myhandle);
433 if (myretcode != MNG_NOERROR)
434 /* process error */;
435
436will suffice. Saves some time and effort, that.
437
438
439.SS Error handling
440
441From the examples in the previous paragraphs you may have noticed a
442meticulous scheme for error handling. And yes, that's exactly what it is.
443Practically each call simply returns an errorcode, indicating success,
444eg. MNG_NOERROR or failure, anything else but MNG_NEEDMOREDATA and
445MNG_NEEDTIMERWAIT. These latter two will be discussed in more detail in
446their respective fields of interest: the reading section and displaying
447section respectively.
448
449It is the application's responsibility to check the returncode after
450each call. You can call mng_getlasterror() to receive the details of
451the last detected error. This even includes a discriptive error-message
452if you enabled that option during compilation of the library.
453
454Note that after receiving an error it is still possible to call the
455library, but it's also very likely that any following call will fail.
456The only functions deemed to work will be mng_reset() and mng_cleanup().
457Yes, if you abort your program after an error, you should still call
458mng_cleanup().
459
460
461.SH IV. Reading
462
463Reading a MNG, JNG or PNG is fairly easy. It depends slightly on your
464ultimate goal how certain specifics are to be handled, but the basics
465are similar in all cases.
466
467For the read functioins to work you must have compiled the library with
468the MNG_READ_SUPPRT directive. The standard DLL and Shared Library
469have this on by default!
470
471
472.SS Setup
473
474Naturally you must have initialized the library and be the owner of
475a mng_handle. The following callbacks are essential:
476
477 mng_openstream, mng_readdata, mng_closestream
478
479You may optionally define:
480
481 mng_errorproc, mng_traceproc
482 mng_processheader, mng_processtext
483 mng_processsave, mng_processseek
484
485The reading bit will also fail if you are already creating or
486displaying a file. Seems a bit obvious, but I thought I'd mention it,
487just in case.
488
489
490.SS To suspend or not to suspend
491
492There is one choice you need to make before calling the read function.
493Are you in need of suspension-mode or not?
494
495If you're reading from a disk you most certainly do not need
496suspension-mode. Even the oldest and slowest of disks will be fast
497enough for straight reading.
498
499However, if your input comes from a really slow device, such as a
500dialup-line or the likes, you may opt for suspension-mode. This is done
501by calling
502
503 myretcode = mng_set_suspensionmode (myhandle,
504 MNG_TRUE);
505 if (myretcode != MNG_NOERROR)
506 /* process error */;
507
508Suspension-mode will force the library to use special buffering on the
509input. This allows your application to receive data of arbitrarily length
510and return this in the mng_readdata() callback, without disturbing the
511chunk processing routines of the library.
512
513Suspension-mode does require a little extra care in the main logic of the
514application. The read function may return with MNG_NEEDMOREDATA when the
515mng_readdata() callback returns less data then it needs to process the
516next chunk. This indicates the application to wait for more data to arrive
517and then resume processing by calling mng_read_resume().
518
519
520.SS The read HLAPI
521
522The actual reading is just plain simple. Since all I/O is done
523outside the library through the callbacks, the library can focus on
524its real task. Understanding, checking and labelling the input data!
525
526All you really need to do is this:
527
528 myretcode = mng_read (myhandle);
529 if (myretcode != MNG_NOERROR)
530 /* process error */;
531
532Of course, if you're on suspension-mode the code is a little more
533complicated:
534
535 myretcode = mng_read (myhandle);
536
537 while (myretcode == MNG_NEEDMOREDATA) {
538 /* wait for input-data to arrive */
539 myretcode = mng_read_resume (myhandle);
540 }
541
542 if (myretcode != MNG_NOERROR)
543 /* process error */;
544
545This is rather crude and more sophisticated programming methods may
546dictate another approach. Whatever method you decide on, it should
547act as if the above code was in its place.
548
549There is also the mng_readdisplay() function, but this is discussed
550in the displaying section. It functions pretty much as the mng_read()
551function, but also immediately starts displaying the image.
552mng_read_resume() should be replaced by mng_display_resume() in that
553case!
554
555
556.SS What happens inside
557
558What actually happens inside the library depends on the configuration
559options set during the compilation of the library.
560
561Basically the library will first read the 8-byte file header, to determine
562its validity and the type of image it is about to process. Then it will
563repeatedly read a 4-byte chunk-length and then the remainder of the chunk
564until it either reaches EOF (indicated by the mng_readdata() callback) or
565implicitly decides EOF as it processed the logically last chunk of the
566image.
567
568Applications that require strict conformity and do not allow superfluous
569data after the ending chunk, will need to perform this check in their
570mng_closestream() callback.
571
572Each chunk is then checked on CRC, after which it is handed over to the
573appropriate chunk processing routine. These routines will disect the
574chunk, check the validity of its contents, check its position with respect
575to other chunks, etc, etc.
576
577If everything checks out, the chunk is further processed as follows:
578
579If display support has been selected during compilation, certain pre-display
580initialization will take place.
581
582If chunk-storage support has been selected during compilation, the chunks
583data may be stored in a special internal structure and held for future
584reference.
585
586
587.SS Storing and accessing chunks
588
589One of the compilation options activates support for chunk storage.
590This option may be useful if you want to examine an image. The directive
591is MNG_STORE_CHUNKS. You must also turn on the MNG_ACCESS_CHUNKS
592directive.
593
594The actual storage facility can be turned on or off with the
595mng_set_storechunks() function. If set to MNG_TRUE, chunks will be
596stored as they are read.
597
598At any point you can then call the mng_iterate_chunks() function
599to iterate through the current list of chunks. This function requires
600a callback which is called for each chunk and receives a specific
601chunk-handle. This chunk-handle can be used to call the appropriate
602mng_getchunk_xxxx() function, to access the chunks properties.
603
604A typical implementation may look like this:
605
606 mng_bool my_iteratechunk (mng_handle hHandle,
607 mng_handle hChunk,
608 mng_chunkid iChunkid,
609 mng_uint32 iChunkseq) {
610 switch (iChunkid) {
611 case MNG_UINT_MHDR : { /* process MHDR */;
612 break; }
613 case MNG_UINT_FRAM : { /* process FRAM */;
614 break; }
615
616 ...etc...
617
618 case MNG_UINT_HUH : { /* unknown chunk */;
619 break; }
620 default : { /* duh; forgot one */; }
621 }
622
623 return MNG_TRUE; /* keep'm coming */
624 }
625
626To get to the actual chunk fields of lets say a SHOW chunk you would do:
627
628 mng_bool isempty;
629 mng_uint16 firstid, lastid;
630 mng_uint8 showmode;
631
632 myretcode mng_getchunk_show (hHandle, hChunk,
633 isempty, firstid,
634 lastid, showmode);
635 if (myretcode != MNG_NOERROR)
636 /* process error */;
637
638
639.SH V. Displaying
640
641
642.SS Setup
643
644Assuming you have initialized the library and are the owner of
645a mng_handle. The following callbacks are essential:
646
647 mng_getcanvasline, mng_refresh
648 mng_gettickcount, mng_settimer
649
650If you wish to use an application supplied background you must supply:
651
652 mng_getbkgdline
653
654If you wish to use the MNG_CANVAS_RGB8_A8 canvas style you must supply:
655
656 mng_getalphaline
657
658You may optionally define:
659
660 mng_errorproc, mng_traceproc
661 mng_processheader, mng_processtext
662 mng_processsave, mng_processseek
663
664Note that the mng_processheader() callback is optional but will
665be quite significant for proper operation!
666
667Displaying an image will fail if you are creating a file or already
668displaying one. Yes, you can't display it twice!
669
670
671.SS A word on canvas styles
672
673The canvas style describes how your drawing canvas is made up.
674You must set this before the library actually starts drawing, so
675the mng_processheader() callback is a pretty good place for it.
676
677Currently only 8-bit RGB canvas styles are supported, either with
678or without an alpha channel.
679
680If you like to do alpha composition yourself you can select one of
681the canvas styles that include an alpha channel. You can even have
682a separate alpha canvas by selecting the MNG_CANVAS_RGB8_A8 style.
683
684All styles require a compact model. Eg. MNG_CANVAS_BGR8 requires
685your canvas lines in bgrbgrbgr... storage, where each letter
686represents an 8-bit value of the corresponding color, and each
687threesome makes up the values of one(1) pixel.
688
689The library processes a line at a time, so the canvas lines do not
690actually need to be consecutive in memory.
691
692
693.SS Alpha composition and application backgrounds
694
695All Network Graphics can be partially transparent. This requires
696special processing if you need to display an image against some
697background. Note that the MNG header (MHDR chunk) contains a
698simplicity field indicating whether transparency information in
699the file is critical or not. This only applies to embedded images,
700which means the full image-frame of the MNG may still contain fully
701transparent pixels!
702
703Depending on your needs you can supply a single background color,
704a background canvas or tell the library to return the alpha-channel
705and do alpha composition yourself.
706
707This is different from the BACK chunk in a MNG, or the bKGD chunk
708in an (embedded) PNG or JNG. The BACK chunk indicates an optional or
709mandatory background color and/or image. The bKGD chunk only indicates
710an optional background color. These chunks indicate the Authors
711preferences. They may be absent in which case you need to supply
712some sort of background yourself.
713
714.SS Composing against a background color
715
716This is the easiest method. Call the mng_set_bgcolor() function to
717set the values of the red, green and blue component of your preferred
718background color.
719
720Use one of the canvas styles that do not have an alpha-channel, and
721which matches your output requirements.
722
723.SS Composing against a background canvas
724
725This is somewhat more complicated. You will need to set the
726mng_getbkgdline() callback. This will be called whenever the library
727needs to compose a partially transparent line.
728
729This canvas must hold the background against which the image should
730be composed. Its size must match exactly with the image dimensions
731and thus the drawing canvas!
732
733Use one of the canvas styles that do not have an alpha-channel, and
734which matches your output requirements. The canvas style of the
735background canvas may even differ from the drawing canvas. The library's
736composing will still function properly.
737
738.SS Composing within the application
739
740If you have the option in your application to draw a (partially)
741transparent canvas to the output device, this option is preferred.
742
743Select one of the canvas styles that do have an alpha-channel.
744The library will now supply the appropriate alpha information,
745allowing the application to compose the image as it sees fit.
746
747
748.SS Color information and CMS
749
750Network Graphics may, and usually will, contain color-correction
751information. This information is intended to compensate for the
752difference in recording and display devices used.
753
754This document does not address the specifics of color-management.
755See the PNG specification for a more detailed description.
756
757.SS Using little cms by Marti Maria Saguer
758
759This is the easiest method, providing you can compile the lcms package.
760Select the MNG_FULL_CMS directive during compilation, and sit back and
761relax. The library will take care of all color-correction for you.
762
763.SS Using an OS- or application-supplied CMS
764
765If you are so lucky to have access to CMS functionality from within
766your application, you may instruct the library to leave color-correction
767to you.
768
769Select the MNG_APP_CMS directive during compilation of the library.
770You MUST also set the following callbacks:
771
772 mng_processgamma, mng_processchroma,
773 mng_processsrgb, mng_processiccp and
774 mng_processarow
775
776The last callback is called when the library needs you to correct
777an arbitrary line of pixels. The other callbacks are called when
778the corresponding color-information is encountered in the file.
779You must store this information somewhere for use in the
780mng_processarow() callback.
781
782.SS Using gamma-only correction
783
784This isn't a preferred method, but it's better than no correction
785at all. Gamma-only correction will at least compensate for
786gamma-differences between the original recorder and your output device.
787
788Select the MNG_GAMMA_ONLY directive during compilation
789of the library. Your compiler MUST support fp operations.
790
791.SS No color correction
792
793Ouch. This is really bad. This is the least preferred method,
794but may be necessary if your system cannot use lcms, doesn't
795have its own CMS, and does not allow fp operations, ruling out
796the gamma-only option.
797
798Select the MNG_NO_CMS directive during compilation.
799Images will definitely not be displayed as seen by the Author!!!
800
801
802.SS Animations and timing
803
804Animations require some form of timing support. The library relies
805on two callbacks for this purpose. The mng_gettickcount() and
806mng_settimer() callbacks. mng_gettickcount() is used to determine
807the passing of time in milliseconds since the beginning of the
808animation. This is also used to compensate during suspension-mode
809if you are using the mng_readdisplay() function to read & display
810the file simultaneously.
811
812The callback may return an arbitrary number of milliseconds, but
813this number must increase proportionaly between calls. Most modern
814systems will have some tickcount() function which derives its
815input from an internal clock. The value returned from this function
816is more than adequate for libmng.
817
818The mng_settimer() callback is called when the library determines
819a little "pause" is required before rendering another frame of the
820animation. The pause interval is also expressed in milliseconds.
821Your application should store this value and return immediately.
822The library will then make appropriate arrangements to store its
823internal state and returns to your application with the
824MNG_NEEDTIMERWAIT code.
825
826At that point you should suspend processing and wait the given
827interval. Please use your OS features for this. Do not engage some
828sort of loop. That is real bad programming practice. Most modern
829systems will have some timing functions. A simple wait() function
830may suffice, but this may prevent your applications main-task from
831running, and possibly prevent the actual update of your output device.
832
833
834.SS The mng_refresh() callback
835
836The mng_refresh() callback is called whenever the library has
837"finished" drawing a new frame onto your canvas, and just before it
838will call the mng_settimer() callback.
839
840This allows you to perform some actions necessary to "refresh" the
841canvas onto your output device. Please do NOT suspend processing
842inside this callback. This must be handled after the mng_settimer()
843callback!
844
845
846.SS Displaying while reading
847
848This method is preferred if you are reading from a slow input device
849(such as a dialup-line) and you wish to start displaying something
850as quickly as possible. This functionality is provided mainly for
851browser-type applications but may be appropriate for other
852applications as well.
853
854The method is usually used in unison with the suspension-mode of
855the read module. A typical implementation would look like this:
856
857 /* initiale library and set required callbacks */
858
859 /* activate suspension-mode */
860 myretcode = mng_set_suspensionmode (myhandle,
861 MNG_TRUE);
862 if (myretcode != MNG_NOERROR)
863 /* process error */;
864
865 myretcode = mng_readdisplay (myhandle);
866
867 while ((myretcode == MNG_NEEDMOREDATA) ||
868 (myretcode == MNG_NEEDTIMERWAIT)) {
869 if (myretcode == MNG_NEEDMOREDATA)
870 /* wait for more input-data */;
871 else
872 /* wait for timer interval */;
873
874 myretcode = mng_display_resume (myhandle);
875 }
876
877 if (myretcode != MNG_NOERROR)
878 /* process error */;
879
880More advanced programming methods may require a different approach,
881but the final result should function as in the code above.
882
883
884.SS Displaying after reading
885
886This method is used to display a file that was previously read.
887It is primarily meant for viewers with direct file access, such as
8881a local harddisk.
889
890Once you have successfully read the file, all you need to do is:
891
892 myretcode = mng_display (myhandle);
893
894 while (myretcode == MNG_NEEDTIMERWAIT) {
895 /* wait for timer interval */;
896 myretcode = mng_display_resume (myhandle);
897 }
898
899 if (myretcode != MNG_NOERROR)
900 /* process error */;
901
902Again, more advanced programming methods may require a different
903approach, but the final result should function as in the code above.
904
905
906.SS Display manipulation
907
908Several HLAPI functions are provided to allow a user to manipulate
909the normal flow of an animation.
910
911\- mng_display_freeze (mng_handle hHandle)
912
913This will "freeze" the animation in place.
914
915\- mng_display_resume (mng_handle hHandle)
916
917This function can be used to resume a frozen animation, or to force
918the library to advance the animation to the next frame.
919
920\- mng_display_reset (mng_handle hHandle)
921
922This function will "reset" the animation into its pristine state.
923Calling mng_display() afterwards will re-display the animation
924from the first frame.
925
926\- mng_display_golayer (mng_handle hHandle,
927 mng_uint32 iLayer)
928
929\- mng_display_goframe (mng_handle hHandle,
930 mng_uint32 iFrame)
931
932\- mng_display_gotime (mng_handle hHandle,
933 mng_uint32 iPlaytime)
934
935These three functions can be used to "jump" to a specific layer, frame
936or timeslot in the animation. You must "freeze" the animation before
937using any of these functions.
938
939All above functions may only be called during a timer interval!
940It is the applications responsibility to cleanup any resources with
941respect to the timer wait.
942
943
944.SH VI. Writing
945
946The main focus of the library lies in its displaying capabilites.
947But it does offer writing support as well.
948You can create and write a file, or you can write a file you
949have previously read, providing the storage of chunks was enabled
950and active.
951
952For this to work you must have compiled the library with the
953MNG_WRITE_SUPPO1RT and MNG_ACCESS_CHUNKS directives. The standard DLL and
954Shared Library have this on by default!
955
956
957.SS Setup
958
959As always you must have initialized the library and be the owner of
960a mng_handle. The following callbacks are essential:
961
962 mng_openstream, mng_writedata, mng_closestream
963
964You can optionally define:
965
966 mng_errorproc, mng_traceproc
967
968The creation and writing functions will fail if you are in the middle
969of reading, creating or writing a file.
970
971
972.SS Creating a new file
973
974To start a new file the library must be in its initial state.
975First you need to tell the library your intentions:
976
977 myretcode = mng_create (myhandle);
978 if (myretcode != MNG_NOERROR)
979 /* process error */;
980
981After that you start adding the appropriate chunks:
982
983 myretcode = mng_put1chunk_mhdr (myhandle, ...);
984 if (myretcode != MNG_NOERROR)
985 /* process error */;
986
987And so on, and so forth. Note that the library will automatically signal
988the logical end of the file by the ending chunk. Also the first chunk
989will indicate the library the filetype (eg. PNG, JNG or MNG) and force
990the proper signature when writing the file.
991
992The code above can be simplified, as you can always get the last errorcode
993by using the mng_getlasterror() function:
994
995 if ( (mng_putchunk_xxxx (myhandle, ...)) or
996 (mng_putchunk_xxxx (myhandle, ...)) or
997 ...etc... )
998 /* process error */;
999
1000Please note that you must have a pretty good understanding of the chunk
1001specification. Unlike the read functions, there are virtually no checks,
1002so it is quite possible to write completely wrong files.
1003It is a good practice to read back your file into the library to verify
1004its integrity.
1005
1006Once you've got all the chunks added, all you do is:
1007
1008 myretcode mng_write (myhandle);
1009 if (myretcode != MNG_NOERROR)
1010 /* process error */;
1011
1012And presto. You're done. The real work is of course carried out in
1013your callbacks. Note that this is a single operation as opposed to
1014the read & display functions that may return with MNG_NEEDMOREDATA
1015and/or MNG_NEEDTIMERWAIT. The write function just does the job, and
1016only returns after it's finished or if it encounters some
1017unrecoverable error.
1018
1019
1020.SS Writing a previously read file
1021
1022If you have already successfully read a file, you can use the library to
1023write it out as a copy or something. You MUST have compiled the library
1024with the MNG_STORE_CHUNKS directive, and you must have done
1025mng_set_storechunks (myhandle, MNG_TRUE).
1026
1027This doesn't require the MNG_ACCESS_CHUNKS directive, unless you want
1028to fiddle with the chunks as well.
1029
1030Again all you need to do is:
1031
1032 myretcode mng_write (myhandle);
1033 if (myretcode != MNG_NOERROR)
1034 /* process error */;
1035
1036
1037.SH VII. Modifying/Customizing libmng:
1038
1039not finished yet
1040
1041.SS Compilation directives
1042
1043not finished yet
1044
1045.SS Platform dependant modification
1046
1047not finished yet
1048
1049.SH "SEE ALSO"
1050.IR mng(5), jng(5), png(5), libpng(3)
1051
1052.LP
1053libmng :
1054.IP
1055.br
1056http://www.libmng.com
1057
1058.LP
1059zlib :
1060.IP
1061.br
1062http://www.info-zip.org/pub/infozip/zlib/
1063
1064.LP
1065IJG JPEG library :
1066.IP
1067.br
1068http://www.ijg.org
1069
1070.LP
1071lcms (little CMS) by Marti Maria Saguer :
1072.IP
1073.br
1074http://www.littlecms.com/
1075
1076.LP
1077MNG specification:
1078.IP
1079.br
1080http://www.libpng.org/pub/mng
1081
1082.LP
1083In the case of any inconsistency between the MNG specification
1084and this library, the specification takes precedence.
1085
1086
1087.SH AUTHORS
1088This man page: Gerard Juyn
1089<gerard at libmng.com>
1090
1091The contributing authors would like to thank all those who helped
1092with testing, bug fixes, and patience. This wouldn't have been
1093possible without all of you!!!
1094
1095
1096.SH COPYRIGHT NOTICE:
1097
1098Copyright (c) 2000-2002 Gerard Juyn
1099
1100For the purposes of this copyright and license, "Contributing Authors"
1101is defined as the following set of individuals:
1102
1103 Gerard Juyn
1104
1105The MNG Library is supplied "AS IS". The Contributing Authors
1106disclaim all warranties, expressed or implied, including, without
1107limitation, the warranties of merchantability and of fitness for any
1108purpose. The Contributing Authors assume no liability for direct,
1109indirect, incidental, special, exemplary, or consequential damages,
1110which may result from the use of the MNG Library, even if advised of
1111the possibility of such damage.
1112
1113Permission is hereby granted to use, copy, modify, and distribute this
1114source code, or portions hereof, for any purpose, without fee, subject
1115to the following restrictions:
1116
11171. The origin of this source code must not be misrepresented;
1118you must not claim that you wrote the original software.
1119
11202. Altered versions must be plainly marked as such and must not be
1121misrepresented as being the original source.
1122
11233. This Copyright notice may not be removed or altered from any source
1124or altered source distribution.
1125
1126The Contributing Authors specifically permit, without fee, and
1127encourage the use of this source code as a component to supporting
1128the MNG and JNG file format in commercial products. If you use this
1129source code in a product, acknowledgment would be highly appreciated.
1130
1131.SH Remarks
1132
1133Parts of this software have been adapted from the libpng library.
1134Although this library supports all features from the PNG specification
1135(as MNG descends from it) it does not require the libpng library.
1136It does require the zlib library and optionally the IJG JPEG library,
1137and/or the "little-cms" library by Marti Maria Saguer (depending on the
1138inclusion of support for JNG and Full-Color-Management respectively.
1139
1140This library's function is primarily to read and display MNG
1141animations. It is not meant as a full-featured image-editing
1142component! It does however offer creation and editing functionality
1143at the chunk level. (future modifications may include some more
1144support for creation and or editing)
1145
1146.\" end of man page
Note: See TracBrowser for help on using the repository browser.