⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmng.txt

📁 Linux下的基于X11的图形开发环境。
💻 TXT
📖 第 1 页 / 共 3 页
字号:
The fourth and last field may be used to supply the library with theentry-point of a trace callback function. For regular use you will notneed this!The function returns a handle which will be your ticket to MNG-heaven.All other functions rely on this handle. It is the single fixed uniquereference-point between your application and the library.You should call the initialization function for each image you wish toprocess simultaneously. If you are processing images consecutively, you canreset the internal status of the library with the mng_reset() function.This function will clear all internal state variables, free any storedchunks and/or objects, etc, etc. Your callbacks and other external parameterswill be retained.After you successfully received the handle it is time to set the requiredcallbacks. The sections on reading, displaying & writing indicate whichcallbacks are required and which are optional.To set the callbacks simply do:    myretcode = mng_setcb_xxxxxx (myhandle, my_xxxxxx);    if (myretcode != MNG_NOERROR)      /* process error */;Naturally you'd replace the x's with the name of the callback.> CleanupOnce you've gotten hold of that precious mng_handle, you should always,and I mean always, call the cleanup function when you're done.Just do:    mng_cleanup (myhandle);And you're done. There shouldn't be an ounce of memory spilled afterthat call.Note that if you would like to process multiple files consecutivelyyou do not need to do mng_cleanup() / mng_initialize() between each filebut simply    myretcode = mng_reset (myhandle);    if (myretcode != MNG_NOERROR)      /* process error */;will suffice. Saves some time and effort, that.> Error handlingFrom the examples in the previous paragraphs you may have noticed ameticulous scheme for error handling. And yes, that's exactly what it is.Practically each call simply returns an errorcode, indicating success,eg. MNG_NOERROR or failure, anything else but MNG_NEEDMOREDATA andMNG_NEEDTIMERWAIT. These latter two will be discussed in more detail intheir respective fields of interest: the reading section and displayingsection respectively.It is the application's responsibility to check the returncode aftereach call. You can call mng_getlasterror() to receive the details ofthe last detected error. This even includes a discriptive error-messageif you enabled that option during compilation of the library.Note that after receiving an error it is still possible to call thelibrary, but it's also very likely that any following call will fail.The only functions deemed to work will be mng_reset() and mng_cleanup().Yes, if you abort your program after an error, you should still callmng_cleanup().IV. ReadingReading a MNG, JNG or PNG is fairly easy. It depends slightly on yourultimate goal how certain specifics are to be handled, but the basicsare similar in all cases.For the read functioins to work you must have compiled the library withthe MNG_READ_SUPPRT directive. The standard DLL and Shared Libraryhave this on by default!> SetupNaturally you must have initialized the library and be the owner ofa mng_handle. The following callbacks are essential:    mng_openstream, mng_readdata, mng_closestreamYou may optionally define:    mng_errorproc, mng_traceproc    mng_processheader, mng_processtext    mng_processsave, mng_processseekThe reading bit will also fail if you are already creating ordisplaying a file. Seems a bit obvious, but I thought I'd mention it,just in case.> To suspend or not to suspendThere is one choice you need to make before calling the read function.Are you in need of suspension-mode or not?If you're reading from a disk you most certainly do not needsuspension-mode. Even the oldest and slowest of disks will be fastenough for straight reading.However, if your input comes from a really slow device, such as adialup-line or the likes, you may opt for suspension-mode. This is doneby calling    myretcode = mng_set_suspensionmode (myhandle,                                        MNG_TRUE);    if (myretcode != MNG_NOERROR)      /* process error */;Suspension-mode will force the library to use special buffering on theinput. This allows your application to receive data of arbitrarily lengthand return this in the mng_readdata() callback, without disturbing thechunk processing routines of the library.Suspension-mode does require a little extra care in the main logic of the1application. The read function may return with MNG_NEEDMOREDATA when themng_readdata() callback returns less data then it needs to process thenext chunk. This indicates the application to wait for more data to arriveand then resume processing by calling mng_read_resume().> The read HLAPIThe actual reading is just plain simple. Since all I/O is done1outside the library through the callbacks, the library can focus onits real task. Understanding, checking and labelling the input data!All you really need to do is this:    myretcode = mng_read (myhandle);    if (myretcode != MNG_NOERROR)      /* process error */;Of course, if you're on suspension-mode the code is a little morecomplicated:    myretcode = mng_read (myhandle);    while (myretcode == MNG_NEEDMOREDATA) {      /* wait for input-data to arrive */      myretcode = mng_read_resume (myhandle);    }        if (myretcode != MNG_NOERROR)      /* process error */;This is rather crude and more sophisticated programming methods maydictate another approach. Whatever method you decide on, it shouldact as if the above code was in its place.There is also the mng_readdisplay() function, but this is discussedin the displaying section. It functions pretty much as the mng_read()function, but also immediately starts displaying the image.mng_read_resume() should be replaced by mng_display_resume() in thatcase!> What happens insideWhat actually happens inside the library depends on the configurationoptions set during the compilation of the library.Basically the library will first read the 8-byte file header, to determineits validity and the type of image it is about to process. Then it willrepeatedly read a 4-byte chunk-length and then the remainder of the chunkuntil it either reaches EOF (indicated by the mng_readdata() callback) orimplicitly decides EOF as it processed the logically last chunk of theimage.Applications that require strict conformity and do not allow superfluousdata after the ending chunk, will need to perform this check in theirmng_closestream() callback.Each chunk is then checked on CRC, after which it is handed over to theappropriate chunk processing routine. These routines will disect thechunk, check the validity of its contents, check its position with respectto other chunks, etc, etc.If everything checks out, the chunk is further processed as follows:If display support has been selected during compilation, certain pre-displayinitialization will take place.If chunk-storage support has been selected during compilation, the chunksdata may be stored in a special internal structure and held for futurereference.> Storing and accessing chunksOne of the compilation options activates support for chunk storage.This option may be useful if you want to examine an image. The directiveis MNG_STORE_CHUNKS. You must also turn on the MNG_ACCESS_CHUNKSdirective.The actual storage facility can be turned on or off with themng_set_storechunks() function. If set to MNG_TRUE, chunks will bestored as they are read.At any point you can then call the mng_iterate_chunks() functionto iterate through the current list of chunks. This function requiresa callback which is called for each chunk and receives a specificchunk-handle. This chunk-handle can be used to call the appropriatemng_getchunk_xxxx() function, to access the chunks properties.A typical implementation may look like this:    mng_bool my_iteratechunk (mng_handle  hHandle,                              mng_handle  hChunk,                              mng_chunkid iChunkid,                              mng_uint32  iChunkseq) {      switch (iChunkid) {        case MNG_UINT_MHDR : { /* process MHDR */;                               break; }        case MNG_UINT_FRAM : { /* process FRAM */;                               break; }            ...etc...        case MNG_UINT_HUH  : { /* unknown chunk */;                                break; }        default : { /* duh; forgot one */; }      }      return MNG_TRUE; /* keep'm coming */    }To get to the actual chunk fields of lets say a SHOW chunk you would do:    mng_bool isempty;    mng_uint16 firstid, lastid;    mng_uint8 showmode;    myretcode mng_getchunk_show (hHandle, hChunk,                                  isempty, firstid,                                 lastid, showmode);    if (myretcode != MNG_NOERROR)      /* process error */;V. Displaying> SetupAssuming you have initialized the library and are the owner ofa mng_handle. The following callbacks are essential:    mng_getcanvasline, mng_refresh    mng_gettickcount, mng_settimerIf you wish to use an application supplied background you must supply:    mng_getbkgdlineIf you wish to use the MNG_CANVAS_RGB8_A8 canvas style you must supply:    mng_getalphalineYou may optionally define:    mng_errorproc, mng_traceproc    mng_processheader, mng_processtext    mng_processsave, mng_processseekNote that the mng_processheader() callback is optional but willbe quite significant for proper operation!Displaying an image will fail if you are creating a file or alreadydisplaying one. Yes, you can't display it twice!> A word on canvas stylesThe canvas style describes how your drawing canvas is made up.You must set this before the library actually starts drawing, sothe mng_processheader() callback is a pretty good place for it.Currently only 8-bit RGB canvas styles are supported, either withor without an alpha channel.If you like to do alpha composition yourself you can select one ofthe canvas styles that include an alpha channel. You can even havea separate alpha canvas by selecting the MNG_CANVAS_RGB8_A8 style.All styles require a compact model. Eg. MNG_CANVAS_BGR8 requiresyour canvas lines in bgrbgrbgr... storage, where each letterrepresents an 8-bit value of the corresponding color, and eachthreesome makes up the values of one(1) pixel.The library processes a line at a time, so the canvas lines do notactually need to be consecutive in memory.> Alpha composition and application backgroundsAll Network Graphics can be partially transparent. This requiresspecial processing if you need to display an image against somebackground. Note that the MNG header (MHDR chunk) contains asimplicity field indicating whether transparency information inthe file is critical or not. This only applies to embedded images,which means the full image-frame of the MNG may still contain fullytransparent pixels!Depending on your needs you can supply a single background color,a background canvas or tell the library to return the alpha-channeland do alpha composition yourself.This is different from the BACK chunk in a MNG, or the bKGD chunkin an (embedded) PNG or JNG. The BACK chunk indicates an optional ormandatory background color and/or image. The bKGD chunk only indicatesan optional background color. These chunks indicate the Authorspreferences. They may be absent in which case you need to supplysome sort of background yourself.> Composing against a background colorThis is the easiest method. Call the mng_set_bgcolor() function toset the values of the red, green and blue component of your preferredbackground color.Use one of the canvas styles that do not have an alpha-channel, andwhich matches your output requirements.> Composing against a background canvasThis is somewhat more complicated. You will need to set themng_getbkgdline() callback. This will be called whenever the libraryneeds to compose a partially transparent line.This canvas must hold the background against which the image shouldbe composed. Its size must match exactly with the image dimensionsand thus the drawing canvas!Use one of the canvas styles that do not have an alpha-channel, andwhich matches your output requirements. The canvas style of thebackground canvas may even differ from the drawing canvas. The library'scomposing will still function properly.> Composing within the applicationIf you have the option in your application to draw a (partially)transparent canvas to the output device, this option is preferred.Select one of the canvas styles that do have an alpha-channel.The library will now supply the appropriate alpha information,allowing the application to compose the image as it sees fit.> Color information and CMSNetwork Graphics may, and usually will, contain color-correctioninformation. This information is intended to compensate for thedifference in recording and display devices used.This document does not address the specifics of color-management.See the PNG specification for a more detailed description.> Using little cms by Marti Maria Saguer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -