home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Misc / OTT-PHT3.DMS / in.adf / devdocs / gio / gio.doc < prev    next >
Encoding:
Text File  |  1994-11-21  |  12.7 KB  |  371 lines

  1. Programming information for .GIO files 
  2. ======================================
  3.  
  4. Copyright © Almathera Systems Ltd 1994. All Rights Reserved.
  5.  
  6. All programming examples and documentation is proprietary
  7. and may only be used to create .GIO files for use
  8. with the Photogenics program.
  9.  
  10. Any other use of this documentation and source is strictly
  11. prohibited. It may not be reproduced or copied without
  12. written authorisation from Almathera.
  13.  
  14. Permission is hereby given to allow free or commercial
  15. distribution of .GIO files for Photogenics written using
  16. this code. Almathera encourages the free distribution
  17. of .GIO files for use with Photogenics.
  18.  
  19. (ie. If you write a GIO, you can do whatever you want with
  20. it!)
  21.  
  22. .GIO files may not be distributed for use with any other
  23. Amiga software.
  24.  
  25. (ie. You can't reverse engineer our system and build your
  26. own image-processor around our files)
  27.  
  28. ---------------------------------------------------
  29. If you have any problems developing add-on files for
  30. Photogenics, then please contact:
  31.  
  32. Jolyon Ralph or Keith Smith on (UK) 0181 687 0040
  33. during office hours, or email to:
  34.  
  35. jralph@cix.compulink.co.uk
  36.  
  37. We'll be happy to help out where we can.
  38.  
  39. If you've come up with an excellent idea for a loader but
  40. can't program it yourself, then let us know and we might
  41. have a go ourselves, or call our BBS, someone may
  42. have already written one!
  43.  
  44. -----------------------------------------------------
  45.  
  46. What is a .GIO file? - Jolyon Ralph (21/11/94)
  47. ==============================================
  48.  
  49. GIO files are the 'loaders' and 'savers' that Photogenics
  50. uses to import and export files. Unlike other programs one file
  51. can support either loading, saving or both. Scanning, printing,
  52. digitizing, fractal creation, etc. can all be done within
  53. a .GIO file.
  54.  
  55. A .GIO file is a standard system disk-based library file. You can
  56. create .GIO files with any programming language that can create
  57. a library (assembler, C, C++, Modula II, etc.) although all
  58. the examples provided use SAS V6.50 or higher as library
  59. creation with this is simple using the libinitr link code.
  60.  
  61. Using libraries carries little overhead and has the major advantage
  62. that the Amiga operating system automatically handles ram cacheing
  63. of libraries and flushing libraries when ram is low without us having
  64. to worry about that.
  65.  
  66. Each library follows a standard function layout (as shown
  67. in the gio.fd file:)
  68.  
  69. ##base __GIOBase
  70. ##bias 30
  71. ##public
  72. GioInfo()()
  73. GioExamine(giodata)(a0)
  74. GioRead(giodata)(a0)
  75. GioWrite(giodata)(a0)
  76. ##end
  77.  
  78. First a description of the functions:
  79.  
  80.  
  81. GioInfo
  82. =======
  83.  
  84. flags = GioInfo(void)
  85.  d0.L
  86.  
  87. This is required by all .gio files. It returns flags depending on
  88. the capabilities of the loader. The flags are (defined in gio.h)
  89.  
  90. GIOF_LOADER8 -
  91.  The .gio file can return 1 to 8-bit data with a palette.
  92.  (eg GIF.gio)
  93.  
  94. GIOF_LOADER24 -
  95.  The loader can return 24-bit data.
  96.  (eg JPEG.gio)
  97.  
  98. GIOF_SAVER8 -
  99.  The loader can save 1 to 8-bit data  // not currently implemented!
  100.  
  101. GIOF_SAVER24 -
  102.  The loader can save 24-bit data
  103.  
  104. GIOF_LOADFILE -
  105.  The loader expects a filename (eg any loader that loads from files)
  106.  Do NOT set for fractal creators, scanner drivers, etc.
  107.  
  108. GIOF_SAVEFILE -
  109.  The saver expects a filename (eg any loader that saves to files)
  110.  Do NOT set for printer drivers, 24-bit display devices, etc.
  111.  
  112. GIOF_PLANAR -
  113.  Load data is supplied in Planar format (ILBM.gio)
  114.  
  115. GIOF_NOID -
  116.  The loader is not capable of accurately identifying a file (eg
  117.  RAW.gio, SCULPT.gio, etc.). These loaders will NOT be attempted
  118.  for the UNIVERSAL loader. This does not have to be set if
  119.  GIOF_LOADFILE is not set.
  120.  
  121. GIOF_NOFILEOPEN -
  122.  By default Photogenics will open the file (using Open), read in
  123.  the first 64-bytes (for Universal loader detection) and pass
  124.  you the filehandle. It handles closing the file afterwards.
  125.  This flag tells Photogenics to not do any file open operations.
  126.  This flag requires the GIOF_LOADFILE to be set and may be ignored
  127.  if GIOF_NOID is not set and the loader is called via the UNIVERSAL
  128.  loader.
  129.  
  130.  This should not be used unless vital!
  131.  
  132. GioExamine
  133. ==========
  134.  
  135. error = GioExamine(struct GioData *giodata)
  136.  d0.L                               A0
  137.  
  138. GioExamine is expected to return enough information about the
  139. file to be loaded or created for memory to be allocated inside
  140. Photogenics. At the bare minimum, this means width (in pixels)
  141. and height (in pixels). With Photogenics V1 all buffers are
  142. 24-bit so depth is not important, although this should be set to
  143. the minimum depth you require for future compatibility.
  144.  
  145. If GIOF_LOADFILE is set, then giodata->Data will point to
  146. the first 64 bytes of the file, and giodata->FileHandle is
  147. a dos.library filehandle you can use to access the file
  148. (It is pointing at the 65th byte of the file as of
  149. calling GioExamine, you may need to Seek yourself).
  150.  
  151. NOTE!! When MacBinary header extraction is implemented it may
  152. not be safe to assume fixed positions in the file for seeks. We
  153. have added another value to the header (giodata->SkipBytes)
  154. which should be added to all Seek positions.  
  155.  
  156. If GIOF_NOID is not set, then GioExamine is also expected to
  157. determine whether the file is of the right type for the loader.
  158. This should be done by examining the first 64-bytes of the
  159. file (more if necessary) and not, unless absolutely unavoidable,
  160. by comparing patterns with the filename.
  161.  
  162. DO NOT TRASH ANY VALUES IN THE GIO IF YOU HAVE NOT POSITIVELY 
  163. IDENTIFIED THE FILE. SPECIFICALLY, DO NOT WRITE TO THE giodata->Data
  164. DATA. If you do this, and the file turns out NOT to be your
  165. type of file, the next .GIOs that try and examine the file
  166. will be given corrupt data. Similarly, do not mess with the filename.
  167.  
  168. If you cannot guarantee identification then set the GIOF_NOID flag
  169. in the GioInfo() structure...
  170.  
  171. The error returned indicates what kind of error.
  172.  
  173. Normally, GioExamine() should return one of three:
  174.  
  175. GIOF_OK        - No error
  176. GIOF_WRONGTYPE - Wrong type of file.
  177. GIOF_ABORTED   - User selected a Cancel button on a requester
  178.  
  179. although the other errors may also be needed in some cases (see
  180. gio.h)
  181.  
  182. If you come up with a specific error that is non-standard (for
  183. example, an unsupported compression system) you can
  184. bring up your own error with the following code:
  185.  
  186.     if(error_happened)
  187.     {
  188.         Error("Unable to load - Unsupported compression type!");
  189.         // this opens an error requester
  190.         giodata->Error = GIOF_ABORTED;
  191.         goto err;         // quit out of program
  192.     }
  193.  
  194. In this case GIOF_ABORTED is used, as this does NOT bring up
  195. another error requester when returning to the program.
  196.  
  197. Non-File loaders (eg fractal creators/scanner drivers)
  198. ======================================================
  199.  
  200. You must return the dimensions of your final image from here,
  201. so this function must contain either default fixed sizes or a call to 
  202. the pgs.library GetDimensions() call which opens a standard picture 
  203. size requester (see colournoise.c). 
  204. (There are various other functions in pgs.library that you might
  205. find useful for getting values from the user. See the
  206. pgs_protos.h file for prototypes to these functions.)
  207.  
  208. If writing a scanner driver or similar, the area to be scanned should
  209. be selected in this function. You will have to write your own user
  210. interface code to support this.
  211.  
  212.  
  213. GioRead
  214. =======
  215.  
  216. error = GioRead(struct GioData *giodata)
  217.  d0.L                             A0
  218.  
  219. Once GioExamine has returned, memory is allocated and a buffer
  220. set up. Photogenics 24-bit buffers are not allocated in one 
  221. contiguous lump (to make it easier to allocate memory on
  222. if ram is fragmented or if you have seperate RAM types (eg
  223. 24-bit and 32-bit) which are not merged.
  224.  
  225. Each line of 24-bit data is allocated seperately and a table
  226. of APTRs to each allocation is your only access method to
  227. the data. Each line is width*3 bytes long and the
  228. format is
  229.  
  230.    UBYTE R,G,B,R,G,B,R,G,B... and so on..
  231.  
  232. To write data to a bitmap you have to obtain a pointer to the
  233. line (you cannot access it directly from the gio!). Only then
  234. can you edit data in the line. Use the GetLine(giodata,linenumber)
  235. function to lock the line, and when you have finished with it you
  236. MUST use ReleaseLine(giodata,linenumber). You can have more
  237. than one line allocated at once, but it is *BAD* to allocate more
  238. lines than you really need. Never allocate all the lines for your
  239. picture at one go! Future versions of Photogenics will use the
  240. GetLine/ReleaseLine functions to arbitrate access to virtual memory,
  241. and this could prevent the loader using virtual memory correctly.
  242.  
  243. To set a pixel colour at position x,y:
  244.  
  245.     byteptr =GetLine(giodata,y)+3*x;
  246.     *byteptr++ = red;
  247.     *byteptr++ = green;
  248.     *byteptr   = blue;
  249.     ReleaseLine(giodata,y);
  250.  
  251. Obviously, if you are adding a whole row of pixels you only
  252. need to obtain the line and release it outside your horizontal
  253. loop and not every time you write a pixel.
  254.  
  255. GioRead() should decode data into this memory, but it does not need
  256. to decode the format to 24-bit. Simply read the data directly in
  257. (see how the BMP.c loader does this) and set the depth in giodata->Depth
  258. and Photogenics will convert it to 24-bit.
  259.  
  260. Similarly, Planar formats (eg ILBM) assume that each line contains a line
  261. of planar data (line 0 plane 0, line 0 plane 1... line 0 plane xx)
  262. and this will be converted to chunky internally.
  263.  
  264. Non-24 bit formats must have a palette associated. It must be written
  265. out here *NOT in GioExamine()* and giobase->Palette points to
  266. 768 bytes of memory already allocated to store up to 256 colour
  267. registers in RRGGBB format. (range 0 to 255 per component)
  268.  
  269. You can create a prefered palette for 24-bit pictures if
  270. you want. Palettes in IFF-24 pictures will be loaded.
  271.  
  272. Of course, you can convert to chunky/24-bit yourself if you
  273. prefer. Make sure the GIOF_PLANAR flag is not returned in GioInfo() and 
  274. that you always return giodata->Depth equal to 24.
  275.  
  276. DO NOT SET THE giodata->Depth in GioRead to a higher value than
  277. you set it in GioExamine!
  278.  
  279. If you want to do your own file handling (eg using fopen instead
  280. of Open) then it is perfectly safe to open the file pointed to
  281. in filename yourself. However you must first:
  282.     
  283.     Close(giodata->Filehandle);
  284.     giodata->Filehandle = 0;
  285.  
  286. This also allows you to do your own asynchronous file access.
  287. *THIS MUST ONLY BE DONE IN GIOREAD not GIOEXAMINE!!!*
  288.  
  289.  
  290. GioWrite
  291. ========
  292. At the moment Photogenics only supports saving 24-bit data. Future
  293. versions will support saving 8-bit (or less) rendered data. To
  294. protect your code from future changes, make sure you check
  295. that you are being given 24-bit data (by checking that giodata->Depth
  296. == 24).
  297.  
  298. You can specify that you only want to save one type (8 or
  299. 24 bit) with the GIOF_ flags.
  300.  
  301. Example 24-bit saver code is included in the BMP.c code.
  302.  
  303. If you are writing a displayer (eg for graphics cards) you do not set the 
  304. GIOF_SAVEFILE bit and you do not receive a filehandle.
  305.  
  306. If you want to do your own file handling (eg using fopen instead
  307. of Open) then it is perfectly safe to open the file pointed to
  308. in filename yourself. However you must first:
  309.  
  310.     Close(giodata->Filehandle);
  311.     giodata->Filehandle = 0;
  312.  
  313. You could, of course, not set the GIOF_SAVEFILE bit, but then you'd
  314. have to ask the user for the filename yourself.
  315.  
  316. How the system works:
  317. =====================
  318.  
  319. If you have either of the GIOF_LOADER flags set, then your
  320. loader will appear in the "Loaders" window. On selecting this
  321. loader it will open the GIO file and call GioExamine.
  322.  
  323. The full procedure inside Photogenics is:
  324.  
  325. flags = GioInfo();         // get flags
  326.  
  327. if(flags & GIOF_LOADFILE)  // if it needs a filename
  328. {
  329.    giodata->Filename = <call ASL requester to get filename>;
  330.  
  331.    if(!(flags & GIOF_NOFILEOPEN)) // by default open file..
  332.    {
  333.       giodata->Filehandle = Open(filename,MODE_READ);
  334.       Read(giodata->Filehandle,&giodata->Data,64);  // read first 64-bytes
  335.    }
  336. }
  337.  
  338.    if(GioExamine(giodata)) goto err;            // error exit
  339.  
  340.    buff = AllocateNew24BitBuffer(giodata->Width,giodata->Height)
  341.  
  342.    if(GioRead(giodata)) goto err;               // error exit
  343.  
  344.    // After this call giodata->Depth *must* be set. Most of
  345.    // the time it will be set in GioExamine()
  346.  
  347.    <now photogenics will covert the buffer from indexed and/or planar
  348.     to chunky 24-bit>
  349.  
  350. /*EXIT routine here..*/
  351.  
  352. Universal load
  353. ==============
  354. If the GioExamine() field returns WRONGTYPE it will choose the next
  355. type from the list that fits both _LOADFILE = TRUE and _NOID = FALSE
  356. and attempt the GioExamine() again. Note that the file is
  357. still only opened once and the 64-bytes of data are reused.
  358.  
  359. Because of this it is essential that giodata->Data and 
  360. giodata->Filehandle are *NEVER* written to or trashed by your loader
  361. (even if you have GIOF_NOFILEOPEN set and are not expecting them
  362. to be used)
  363.  
  364. The universal loader will be called automatically by "Open..." and
  365. could always work (if the loader you select fails it automatically
  366. tries to find a correct one).
  367.  
  368. Unlike other image processing packages, 3rd party loaders work
  369. can work with the universal load system without alteration to our
  370. universal loading code.
  371.