{"id":4379,"date":"2022-12-20T17:49:07","date_gmt":"2022-12-20T20:49:07","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/xli-loader-guide-man5\/"},"modified":"2022-12-20T17:49:07","modified_gmt":"2022-12-20T20:49:07","slug":"xli-loader-guide-man5","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/xli-loader-guide-man5\/","title":{"rendered":"XLI LOADER GUIDE (man5)"},"content":{"rendered":"<h1 align=\"center\">XLI LOADER GUIDE<\/h1>\n<p> <a href=\"#Guide to writing image loaders for xli\">Guide to writing image loaders for xli<\/a><br \/> <a href=\"#Include files\">Include files<\/a><br \/> <a href=\"#Identify function\">Identify function<\/a><br \/> <a href=\"#Loading the image\">Loading the image<\/a><br \/> <a href=\"#Useful info in image_ops:\">Useful info in image_ops:<\/a><br \/> <a href=\"#Useful things to set in the image structure:\">Useful things to set in the image structure:<\/a><br \/> <a href=\"#Creating and destroying Image structures:\">Creating and destroying Image structures:<\/a><br \/> <a href=\"#File input resources:\">File input resources:<\/a><br \/> <a href=\"#Memory allocation:\">Memory allocation:<\/a><br \/> <a href=\"#Other facilities:\">Other facilities:<\/a><br \/> <a href=\"#If all else fails:\">If all else fails:<\/a> <\/p>\n<hr>\n<h2>Guide to writing image loaders for xli <a name=\"Guide to writing image loaders for xli\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This is a introduction on how an image load routine should be written, and what resources are available for use by the writer.<\/p>\n<h2>Include files <a name=\"Include files\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The include file xli.h is generally sufficient to make all the xli resources available: ie:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#include &#8220;xli.h&#8221;<\/p>\n<h2>Identify function <a name=\"Identify function\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The identification function is used to implement the <i>-identify<\/i> option of xli. It is generally of the form : <br \/> int xyyzIdent(fullname, name) <br \/> char \u2217fullname, \u2217name; <br \/> { <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">where this is an xyyz type image loader file.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">fullname is the name including path, while name is the short name of the file that is used as a title, or to refer to the file in messages.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Return 0 if the image is NOT identified.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Return 1 if the image IS identified.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the file is identified, use a message something like: <br \/> printf(&#8220;%s is a %dx%d xyyz image with %d colorsn&#8221;,<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>name, width, height, ncolors);<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Try and be quick about identifying the image &#8211; don\u2019t read the whole image just to identify it !<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Use printf even if something is wrong with the file. Use perror for a system error &#8211; ie. unable to open file.<\/p>\n<h2>Loading the image <a name=\"Loading the image\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The load function is used to identify and load the file if it is recognized. It is of the form: <br \/> Image xyyzLoad(fullname, image_ops, verbose) <br \/> ImageOptions \u2217image_ops; <br \/> char \u2217fullname; <br \/> boolean verbose; <br \/> { <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Identify the image as quickly as possible.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Return NULL if the image is not identified.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Otherwise Return a pointer to an image structure with the image in it.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the image is properly identified, but there is something wrong with it before anything useful is read in, report the error &#8211; ie. <br \/> fprintf(stderr,&#8221;xyyzLoad: %s &#8211; corrupted color mapn&#8221;,name);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">clean up (ie. release the image structure and any allocated memory) and return NULL.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the image is properly identified, and there is something wrong with it, but something useful has been read in (ie. color maps etc. have been loaded, and part of the image is loaded), report the error using fprintf (as above) and return what there is of the image.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Remember to release and temporary memory allocated on returning, whether the image is loaded ok, or if something goes wrong.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Remember to read any trailing options before returning a successfully loaded image, and before closing the file. Trailing options are read by calling the function: <br \/> read_trail_opt(image_ops, zf, image, verbose) <br \/> ImageOptions \u2217image_ops; <br \/> ZFILE \u2217zf; <br \/> Image \u2217image; <br \/> boolean verbose;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Remember to close the file before returning.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Remember to add any additional info to the image structure &#8211; ie. name, gamma if known etc.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">NEVER EVER exit(). There may be other image loaders and other images to load.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Use printf to give verbose output on image details.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Use fprintf(stderr,&#8221; &#8230; &#8220;); to give error warning if the file is corrupted.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use perror for a system error &#8211; ie. unable to open file.<\/p>\n<h2>Useful info in image_ops: <a name=\"Useful info in image_ops:\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>char \u2217name; \/\u2217 Short name of image \u2217\/<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>Useful things to set in the image structure: <a name=\"Useful things to set in the image structure:\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\">\n<p>char \u2217title; \/\u2217 name of image \u2217\/<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\">\n<p>RGBMap rgb; \/ RGB map of image if IRGB type \u2217\/<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\">\n<p>byte \u2217data; \/\u2217 data, rounded to full byte for each row \u2217\/<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\">\n<p>float<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\">\n<p>gamma;<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\">\n<p>\/\u2217 gamma of display the image is adjusted \u2217\/<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"8%\"><\/td>\n<td width=\"46%\">\n<p>\/\u2217 for, if know. \u2217\/<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>Creating and destroying Image structures: <a name=\"Creating and destroying Image structures:\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The image structure is created by a call to one of three routines: <br \/> \/\u2217 For a monochrome bitmap \u2217\/ <br \/> Image \u2217newBitImage(width, height) <br \/> unsigned int width, height;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 For a color image with a color map \u2217\/ <br \/> Image \u2217newRGBImage(width, height, depth) <br \/> unsigned int width, height, depth;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 For a true color image \u2217\/ <br \/> Image \u2217newTrueImage(width, height) <br \/> unsigned int width, height;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">And the image can be freed with: <br \/> void freeImageData(image) <br \/> Image \u2217image;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Examine another image loader (ie. gif.c) to see how to set up a color map.<\/p>\n<h2>File input resources: <a name=\"File input resources:\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">A set of file input functions are available that automatically handle compressed files, and also by default buffer the file in memory to speed up the detection of the image type. The following functions are available: <br \/> \/\u2217 <br \/> Open a file by name and return a pointer to <br \/> a file descriptor. <br \/> \u2217\/ <br \/> ZFILE \u2217zopen(name) <br \/> char \u2217name;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Read some data into a buffer <br \/> \u2217\/ <br \/> int zread(zf, buf, len) <br \/> ZFILE \u2217zf; <br \/> byte \u2217buf; <br \/> int len;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Macro that returns a character from the file. <br \/> \u2217\/ <br \/> zgetc(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Function that reads a string into a buffer <br \/> \u2217\/ <br \/> char \u2217zgets(buf, size, zf) <br \/> char \u2217buf; <br \/> unsigned int size; <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 Return the files EOF status \u2217\/ <br \/> int zeof(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Clear any errors (ie. EOF) <br \/> \u2217\/ <br \/> void zclearerr(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Turn off caching when an image has been identified <br \/> and there is no need to re-open it. The cached part <br \/> of the file is still kept, but any reads past this <br \/> point are not cached. <br \/> \u2217\/ <br \/> void znocache(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Rewind the cached file. This won\u2019t work if the file <br \/> is stdin and we have read past the cached part of <br \/> the file. Return TRUE on success. <br \/> \u2217\/ <br \/> boolean zrewind(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Return a block of data back to the input stream. <br \/> Useful for a load routine that does its own buffering <br \/> and wants to return what is left after it has read <br \/> an image. (This is needed to allow trailing options <br \/> to be recognized.) Can also be used instead of ungetc(). <br \/> \u2217\/ <br \/> void zunread(zf, buf, len) <br \/> ZFILE \u2217zf; <br \/> byte \u2217buf; <br \/> int len;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Close a file. <br \/> The file is not actually closed until zreset is called, <br \/> in case another loader wants to re-open it. <br \/> \u2217\/ <br \/> void zclose(zf) <br \/> ZFILE \u2217zf;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 <br \/> Really close a file. Not used by imageLoad functions. <br \/> \u2217\/ <br \/> void zreset(filename) <br \/> char \u2217filename;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Some macros are provided to facilitate reading and writing elements larger than a character from\/to a data buffer according to the desired endianness:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Big endian: <br \/> #define memToVal(PTR,LEN)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#define valToMem(VAL,PTR,LEN)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Little Endian <br \/> #define memToValLSB(PTR,LEN)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#define valToMemLSB(VAL,PTR,LEN)<\/p>\n<h2>Memory allocation: <a name=\"Memory allocation:\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The built in memory allocation routines are guaranteed not to fail. <br \/> \/\u2217 Duplicate a string. Good for making up the image title etc. \u2217\/ <br \/> char \u2217dupString(s) <br \/> char \u2217s;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">byte \u2217lmalloc(size) <br \/> unsigned int size;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">byte \u2217lcalloc(size) <br \/> unsigned int size;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">void lfree(area) <br \/> byte \u2217area;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Be careful not to call lfree with NULL. It may cause a fault.<\/p>\n<h2>Other facilities: <a name=\"Other facilities:\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Memory manipulation <br \/> \/\u2217 Copy a block of memory \u2217\/ <br \/> bcopy(S,D,N)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 Zero a block of memory \u2217\/ <br \/> bzero(P,N)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/\u2217 Fill a block of memory with a value \u2217\/ <br \/> bfill(P,N,C)<\/p>\n<h2>If all else fails: <a name=\"If all else fails:\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Read the source. xli.h and image.h are a good place to start. Look at one of the existing loaders ie. pcx.c Grep for anything else!<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>XLI LOADER GUIDE Guide to writing image loaders for xli Include files Identify function Loading the image Useful info in image_ops: Useful things to set in the image structure: Creating and destroying Image structures: File input resources: Memory allocation: Other facilities: If all else fails: Guide to writing image loaders for xli This is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[959],"tags":[961,1291,1387],"class_list":["post-4379","post","type-post","status-publish","format-standard","hentry","category-5-formatos-de-ficheros","tag-961","tag-man5","tag-xliguide"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4379"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4379\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}