home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / DC-PGS21.DMS / in.adf / Extras / DevDocs.LHA / DeveloperDocs / help / gio.txt < prev    next >
Encoding:
Text File  |  1996-06-03  |  17.9 KB  |  528 lines

  1. Programming information for .GIO files (updated 29/3/96 for Photogenics 2) 
  2. ==========================================================================
  3.  
  4. Copyright © Almathera Systems Ltd 1994-6. 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 on (UK) 0181 687 0040 during office hours, or email to:
  33.  
  34. jralph@cix.compulink.co.uk 
  35.  
  36. or Jolyon on IRC
  37.  
  38. We'll be happy to help out where we can.
  39.  
  40. If you've come up with an excellent idea for a loader but
  41. can't program it yourself, then let us know and we might
  42. have a go ourselves, or call our BBS, someone may
  43. have already written one!
  44.  
  45. -----------------------------------------------------
  46.  
  47. What is a .GIO file? - Jolyon Ralph (6/3/95)
  48. ============================================
  49.  
  50. GIO files are the 'loaders' and 'savers' that Photogenics
  51. uses to import and export files. Unlike other programs one file
  52. can support either loading, saving or both. Scanning, printing,
  53. digitizing, etc. can all be done within 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.). The examples provided
  58. were written using SAS V6.51 and Hisoft Devpac, but any C compiler
  59. and Assembler should be capable of compiling them with little
  60. or no alteration to the sourcecode.
  61.  
  62. Using libraries carries little overhead and has the major advantage
  63. that the Amiga operating system automatically handles ram cacheing
  64. of libraries and flushing libraries when ram is low without us having
  65. to worry about that.
  66.  
  67. Note. Several new functions have been added as of V1.2
  68.  
  69. Each library follows a standard function layout (as shown
  70. in the gio.fd file:)
  71.  
  72. ##base __GIOBase
  73. ##bias 30
  74. ##public
  75. GioInfo()()
  76. GioExamine(giodata)(a0)
  77. GioRead(giodata)(a0)
  78. GioWrite(giodata)(a0)
  79. GioSavePrefs(giodata)(a0)    [V1.2]
  80. GioCleanUp(giodata)(a0)        [V1.2]
  81. GioAbout(giodata)(a0)        [V1.2]
  82. GioStartup()()                   not implemented
  83. GioShutDown()()              not implemented
  84. GioLoadPrefs(giodata)(a0)    [V1.2]
  85. ##end
  86.  
  87. First a description of the functions:
  88.  
  89.  
  90. GioInfo
  91. =======
  92.  
  93. flags = GioInfo(void)
  94.  d0.L
  95.  
  96. This is required by all .gio files. It returns flags depending on
  97. the capabilities of the loader. The flags are (defined in gio.h)
  98.  
  99. GIOF_LOADER8 -
  100.  The .gio file can return 1 to 8-bit data with a palette.
  101.  (eg GIF.gio)
  102.  
  103. GIOF_LOADER24 -
  104.  The loader can return 24-bit data.
  105.  (eg JPEG.gio)
  106.  
  107. GIOF_SAVER8 -
  108.  The loader can save 1 to 8-bit data  // not currently implemented!
  109.  
  110. GIOF_SAVER24 -
  111.  The loader can save 24-bit data
  112.  
  113. GIOF_LOADFILE -
  114.  The loader expects a filename (eg any loader that loads from files)
  115.  Do NOT set for fractal creators, scanner drivers, etc.
  116.  
  117. GIOF_SAVEFILE -
  118.  The saver expects a filename (eg any loader that saves to files)
  119.  Do NOT set for printer drivers, 24-bit display devices, etc.
  120.  
  121. GIOF_PLANAR -
  122.  Load data is supplied in Planar format (ILBM.gio)
  123.  
  124. GIOF_NOID -
  125.  The loader is not capable of accurately identifying a file (eg
  126.  RAW.gio, SCULPT.gio, etc.). These loaders will NOT be attempted
  127.  for the UNIVERSAL loader. This does not have to be set if
  128.  GIOF_LOADFILE is not set.
  129.  
  130. GIOF_NOFILEOPEN -
  131.  By default Photogenics will open the file (using Open), read in
  132.  the first 64-bytes (for Universal loader detection) and pass
  133.  you the filehandle. It handles closing the file afterwards.
  134.  This flag tells Photogenics to not do any file open operations.
  135.  This flag requires the GIOF_LOADFILE to be set and may be ignored
  136.  if GIOF_NOID is not set and the loader is called via the UNIVERSAL
  137.  loader.
  138.  This should not be used unless vital!
  139.  
  140. GIOF_LOADNOPROGRESS -  [V1.2]
  141.  When this is selected no Progress requester is opened on calling
  142.  GioRead()
  143.  
  144. GIOF_SAVENOPROGRESS - [V1.2]
  145.  When this is selected no Progress requester is opened on calling
  146.  GioWrite()
  147.  
  148. GIOF_EXTENDED - [V1.2]
  149.  This flag must be used for all .GIO files that use any V1.2 features.
  150.  
  151. GIOF_SAVEPREFS - [V1.2]
  152.  A preferences page is available when calling GioSavePrefs()
  153.  
  154. GIOF_LOADPREFS - [V1.2]
  155.  A preferences page is available when calling GioLoadPrefs()
  156.  
  157. GioExamine
  158. ==========
  159.  
  160. error = GioExamine(struct GioData *giodata)
  161.  d0.L                               A0
  162.  
  163. GioExamine is expected to return enough information about the
  164. file to be loaded or created for memory to be allocated inside
  165. Photogenics. At the bare minimum, this means width (in pixels)
  166. and height (in pixels). With Photogenics V1 all buffers are
  167. 24-bit so depth is not important, although this should be set to
  168. the minimum depth you require for future compatibility.
  169.  
  170. If GIOF_LOADFILE is set, then giodata->Data will point to
  171. the first 64 bytes of the file, and giodata->FileHandle is
  172. a dos.library filehandle you can use to access the file
  173. (It is pointing at the 65th byte of the file as of
  174. calling GioExamine, you may need to Seek yourself).
  175.  
  176. NOTE!! When MacBinary header extraction is implemented it may
  177. not be safe to assume fixed positions in the file for seeks. We
  178. have added another value to the header (giodata->SkipBytes)
  179. which should be added to all Seek positions.  
  180.  
  181. If GIOF_NOID is not set, then GioExamine is also expected to
  182. determine whether the file is of the right type for the loader.
  183. This should be done by examining the first 64-bytes of the
  184. file (more if necessary) and not, unless absolutely unavoidable,
  185. by comparing patterns with the filename.
  186.  
  187. DO NOT TRASH ANY VALUES IN THE GIO IF YOU HAVE NOT POSITIVELY 
  188. IDENTIFIED THE FILE. SPECIFICALLY, DO NOT WRITE TO THE giodata->Data
  189. DATA. If you do this, and the file turns out NOT to be your
  190. type of file, the next .GIOs that try and examine the file
  191. will be given corrupt data. Similarly, do not mess with the filename.
  192.  
  193. If you cannot guarantee identification then set the GIOF_NOID flag
  194. in the GioInfo() structure...
  195.  
  196. The error returned indicates what kind of error.
  197.  
  198. Normally, GioExamine() should return one of three:
  199.  
  200. GIOF_OK        - No error
  201. GIOF_WRONGTYPE - Wrong type of file.
  202. GIOF_ABORTED   - User selected a Cancel button on a requester
  203.  
  204. although the other errors may also be needed in some cases (see
  205. gio.h)
  206.  
  207. If you come up with a specific error that is non-standard (for
  208. example, an unsupported compression system) you can
  209. bring up your own error with the following code:
  210.  
  211.     if(error_happened)
  212.     {
  213.         Error("Unable to load - Unsupported compression type!");
  214.         // this opens an error requester
  215.         giodata->Error = GIOF_ABORTED;
  216.         goto err;         // quit out of program
  217.     }
  218.  
  219. In this case GIOF_ABORTED is used, as this does NOT bring up
  220. another error requester when returning to the program.
  221.  
  222. Non-File loaders (eg scanner drivers)
  223. ======================================================
  224.  
  225. You must return the dimensions of your final image from here,
  226. so this function must contain either default fixed sizes or a call to 
  227. the pgs.library GetDimensions() call which opens a standard picture 
  228. size requester (see colournoise.c). 
  229. (There are various other functions in pgs.library that you might
  230. find useful for getting values from the user. See the
  231. pgs_protos.h file for prototypes to these functions.)
  232.  
  233. If writing a scanner driver or similar, the area to be scanned should
  234. be selected in this function. You will have to write your own user
  235. interface code to support this.
  236.  
  237.  
  238. GioRead
  239. =======
  240.  
  241. error = GioRead(struct GioData *giodata)
  242.  d0.L                             A0
  243.  
  244. Once GioExamine has returned, memory is allocated and a buffer
  245. set up. Photogenics 24-bit buffers are not allocated in one 
  246. contiguous lump (to make it easier to allocate memory on
  247. if ram is fragmented or if you have seperate RAM types (eg
  248. 24-bit and 32-bit) which are not merged.
  249.  
  250. Each line of 24-bit data is allocated seperately and a table
  251. of APTRs to each allocation is your only access method to
  252. the data. Each line is width*3 bytes long and the
  253. format is
  254.  
  255.    UBYTE R,G,B,R,G,B,R,G,B... and so on..
  256.  
  257. To write data to a bitmap you have to obtain a pointer to the
  258. line (you cannot access it directly from the gio!). Only then
  259. can you edit data in the line. Use the GetLine(giodata,linenumber)
  260. function to lock the line, and when you have finished with it you
  261. MUST use ReleaseLine(giodata,linenumber). You can have more
  262. than one line allocated at once, but it is *BAD* to allocate more
  263. lines than you really need. Never allocate all the lines for your
  264. picture at one go! Future versions of Photogenics will use the
  265. GetLine/ReleaseLine functions to arbitrate access to virtual memory,
  266. and this could prevent the loader using virtual memory correctly.
  267.  
  268. To set a pixel colour at position x,y;
  269.  
  270.     byteptr =GetLine(giodata,y);        // remember to check for errors!
  271.  
  272.     if(byteptr)
  273.     {
  274.         byteptr+=    3*x;
  275.         *byteptr++ = red;
  276.         *byteptr++ = green;
  277.         *byteptr   = blue;
  278.         ReleaseLine(giodata,y);
  279.     } else Error("Fatal error, couldn't get iimage data");
  280.  
  281.  
  282.  
  283. Obviously, if you are adding a whole row of pixels you only
  284. need to obtain the line and release it outside your horizontal
  285. loop and not every time you write a pixel.
  286.  
  287. GioRead() should decode data into this memory, but it does not need
  288. to decode the format to 24-bit. Simply read the data directly in
  289. (see how the BMP.c loader does this) and set the depth in giodata->Depth
  290. and Photogenics will convert it to 24-bit.
  291.  
  292. Similarly, Planar formats (eg ILBM) assume that each line contains a line
  293. of planar data (line 0 plane 0, line 0 plane 1... line 0 plane xx)
  294. and this will be converted to chunky internally.
  295.  
  296. Non-24 bit formats must have a palette associated. It must be written
  297. out here *NOT in GioExamine()* and giobase->Palette points to
  298. 768 bytes of memory already allocated to store up to 256 colour
  299. registers in RRGGBB format. (range 0 to 255 per component)
  300.  
  301. You can create a prefered palette for 24-bit pictures if
  302. you want. Palettes in IFF-24 pictures will be loaded.
  303.  
  304. Of course, you can convert to chunky/24-bit yourself if you
  305. prefer. Make sure the GIOF_PLANAR flag is not returned in GioInfo() and 
  306. that you always return giodata->Depth equal to 24.
  307.  
  308. DO NOT SET THE giodata->Depth in GioRead to a higher value than
  309. you set it in GioExamine!
  310.  
  311. If you want to do your own file handling (eg using fopen instead
  312. of Open) then it is perfectly safe to open the file pointed to
  313. in filename yourself. However you must first:
  314.     
  315.     Close(giodata->Filehandle);
  316.     giodata->Filehandle = 0;
  317.  
  318. This also allows you to do your own asynchronous file access.
  319. *THIS MUST ONLY BE DONE IN GIOREAD not GIOEXAMINE!!!*
  320.  
  321. GioWrite
  322. ========
  323. At the moment Photogenics only supports 24-bit data image buffers. Future
  324. versions will support saving 8-bit (or less) rendered data. To
  325. protect your code from future changes, make sure you check
  326. that you are being given 24-bit data (by checking that giodata->Depth
  327. == 24).
  328.  
  329. You can specify that you only want to save one type (8 or
  330. 24 bit) with the GIOF_ flags.
  331.  
  332. Example 24-bit saver code is included in the BMP.c code.
  333.  
  334. If you are writing a displayer (eg for graphics cards) you do not set the 
  335. GIOF_SAVEFILE bit and you do not receive a filehandle.
  336.  
  337. If you want to do your own file handling (eg using fopen instead
  338. of Open) then it is perfectly safe to open the file pointed to
  339. in filename yourself. However you must first:
  340.  
  341.     Close(giodata->Filehandle);
  342.     giodata->Filehandle = 0;
  343.  
  344. You could, of course, not set the GIOF_SAVEFILE bit, but then you'd
  345. have to ask the user for the filename yourself. Our ANIM saver has to do this.
  346.  
  347. GioSavePrefs [V1.2]
  348. ===================
  349. Rather than make the user select save options every time they try
  350. and save using your .GIO, you should try and put options that the
  351. user is unlikely to want to change every time into this function.
  352.  
  353. Make sure you add the GIOF_SAVEPREFS flag to the GioInfo() function
  354. return value, otherwise the user will not be able to select the
  355. "Prefs" button in the savers list.
  356.  
  357.  
  358. GioLoadPrefs [V1.2]
  359. ===================
  360. This works in the same way as GioSavePrefs(), but obviously for
  361. options for loading files.
  362.  
  363. Make sure you add the GIOF_LOADPREFS flag to the GioInfo() function
  364. return value, otherwise the user will not be able to select the
  365. "Prefs" button in the loaders list.
  366.  
  367. GioCleanUp [V1.2]
  368. =================
  369.  
  370. NOTE [1.2a] - In V1.2 this was documented but not actually
  371. implemented! It is now....
  372.  
  373. In previous versions, it was not safe to allocate memory or
  374. resources inside GioExamine() without closing them down again and, if 
  375. necessary, reallocating them inside GioRead(). This was because
  376. the memory allocation asked for by GioExamine() could fail and
  377. GioRead() would never be called.
  378.  
  379. Now, if the GIOF_EXTENDED flag is set, and for any reason
  380. GioExamine() is called but GioRead() is not called, GioCleanUp()
  381. will be called instead allowing you to deallocate resources.
  382.  
  383. A typical use, to avoid repeating code, would be (in pseudocode...)
  384.  
  385. GioExamine()
  386. {
  387.     if(file_is_right_type)
  388.     {
  389.         SetUpGioDataParameters();
  390.         AllocateMyResources();
  391.     }
  392.     else
  393.         return(GIO_WRONGTYPE);
  394. }
  395.  
  396. GioRead()
  397. {
  398.     ReadAndDecodeFile();
  399.     GioCleanUp(); // deallocate resources
  400. }
  401.  
  402. GioCleanUp()
  403. {
  404.     DeallocateMyResources();
  405. }
  406.  
  407. *** NOTE!!! Do not use this function if you can otherwise avoid it. ***
  408.  
  409. .GIO files written using GioCleanUp() will *NOT* work on old (V1.0/1.1/1.1a)
  410. versions of Photogenics, as they do not call GioCleanUp()
  411.  
  412. GioAbout() [V1.2]
  413. =================
  414. This routine (which is located in the assembler source module provided)
  415. is called if the GIOF_EXTENDED flag is set and the About button is
  416. clicked in either the loaders or savers lists in Photogenics.
  417. Normally, this would display a requester showing information
  418. on the .GIO file (version number, copyright text, author, etc.),
  419. however there is no reason why you could not use any custom code
  420. of your own for 'fancy' About requesters.
  421.  
  422. GioStartup() [NOT YET IMPLEMENTED]
  423. ==================================
  424. GioShutDown()
  425. ===================================
  426. These two functions are reserved for future versions and should
  427. be left void currently. They are primarily intended for Animation loaders.
  428.  
  429. (Actually, GioShutDown() is implemented, but it's use may change from the current implementation
  430. so we don't want to document it just yet...)
  431.  
  432.  
  433. How the system works:
  434. =====================
  435.  
  436. If you have either of the GIOF_LOADER flags set, then your
  437. loader will appear in the "Loaders" window. On selecting this
  438. loader it will open the GIO file and call GioExamine.
  439.  
  440. The full procedure inside Photogenics is:
  441.  
  442. flags = GioInfo();         // get flags
  443.  
  444. if(flags & GIOF_LOADFILE)  // if it needs a filename
  445. {
  446.    giodata->Filename = <call ASL requester to get filename>;
  447.  
  448.    if(!(flags & GIOF_NOFILEOPEN)) // by default open file..
  449.    {
  450.       giodata->Filehandle = Open(filename,MODE_READ);
  451.       Read(giodata->Filehandle,&giodata->Data,64);  // read first 64-bytes
  452.    }
  453. }
  454.  
  455.    if(GioExamine(giodata)) goto err;            // error exit
  456.  
  457.    buff = AllocateNew24BitBuffer(giodata->Width,giodata->Height)
  458.  
  459.    if(GioRead(giodata)) goto err;               // error exit
  460.  
  461.    // After this call giodata->Depth *must* be set. Most of
  462.    // the time it will be set in GioExamine()
  463.  
  464.    <now photogenics will covert the buffer from indexed and/or planar
  465.     to chunky 24-bit>
  466.  
  467. /*EXIT routine here..*/
  468.  
  469. Universal load
  470. ==============
  471. If the GioExamine() field returns WRONGTYPE it will choose the next
  472. type from the list that fits both _LOADFILE = TRUE and _NOID = FALSE
  473. and attempt the GioExamine() again. Note that the file is
  474. still only opened once and the 64-bytes of data are reused.
  475.  
  476. Because of this it is essential that giodata->Data and 
  477. giodata->Filehandle are *NEVER* written to or trashed by your loader
  478. (even if you have GIOF_NOFILEOPEN set and are not expecting them
  479. to be used)
  480.  
  481. And always try and test the 64-bytes of header first. If you can
  482. tell that the filetype is NOT the one you're after, quit out 
  483. as soon as you can from GioExamine() without reading any more data from the file.
  484.  
  485. The universal loader will be called automatically by "Open..." and
  486. could always work (if the loader you select fails it automatically
  487. tries to find a correct one).
  488.  
  489. Unlike some other image processing packages, 3rd party loaders can work 
  490. with the universal load system without alteration to our universal 
  491. loading code.
  492.  
  493. Don't build your own requesters unless you have to!
  494. ===================================================
  495. There are *many* pre-built requsters (for input of strings, values,
  496. new image dimensions, etc, etc, etc,) built into the photogenics
  497. pgs.library. These provide a simple and quick way to build up
  498. loaders.
  499.  
  500. All the reqesters are scalable and font sensitive. You do not
  501. have to worry about what configuration the user is running when using
  502. them.
  503.  
  504. Of course, you do not have to use these, you can use your own code or
  505. another library (GadTools, Triton, etc, etc,), but the
  506. main advantage of using our requesters is that if (when) in the
  507. future we update our user interface and make it look nicer (with
  508. better gadgets, etc.) your code will automatically take advantage
  509. of the new features. It also makes your code smaller and reduces the
  510. reliance on bulky and slow third party libraries.
  511.  
  512. These have been written for you to use - please use them! See pgs.doc
  513. for information on all the current requester types.
  514.  
  515. ARexx...
  516. --------
  517.  
  518. Since Photogenics 2 can pass you parameters from Arexx, it's probably a good idea for
  519. you to check for them and deal with them.
  520.  
  521. The bmp.gio example doesn't have any arexx parameters, but check the balance.efx code
  522. (in the effects drawer) for example of how to deal with arexx.
  523.  
  524. More information is provided in the efx.txt file. Using Arexx with gios is identical to using
  525. them with effects.
  526.  
  527.  
  528.