home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 106 / af106sub.adf / datatypes.LZX / anim_datatype / classbase.c < prev    next >
C/C++ Source or Header  |  2003-05-15  |  34KB  |  888 lines

  1.  
  2. /*
  3. **
  4. **  $VER: classbase.c 1.12 (12.11.97)
  5. **  anim.datatype 1.12
  6. **
  7. **  Library routines for a DataTypes class
  8. **
  9. **  Written 1996/1997 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14.  
  15. /* main includes */
  16. #include "classbase.h"
  17.  
  18.  
  19. /****** anim.datatype/MAIN ***************************************************
  20. *
  21. *    INTRODUCTION
  22. *        Datatypes class for IFF ANIM animations. Based on the CBM datatypes
  23. *        example source/ documents written by David Junod and the public
  24. *        domain Anim5 code by Jim Kent.
  25. *
  26. *    SHAREWARE
  27. *        Starting with V1.8, anim.datatype is Shareware.
  28. *
  29. *        "anim.datatype" is this version and it's contributed files
  30. *        are Copyright 1995/96/97 by Roland Mainz except otherwise noted.
  31. *        All rights reserved.
  32. *
  33. *        You are allowed to use anim.datatype for 30 days. If you
  34. *        want to use it after this time, please register.
  35. *        The registration fee is 15 DM, 10 US-$ or equivalent.
  36. *        There is no different registered version, this version of
  37. *        anim.datatype is fully functional.
  38. *
  39. *        Payment my be done using bank transfer (prefereed; see AUTHOR
  40. *        section below for my bank account), euro-scheques (on my name)
  41. *        or cash money in an envelope (ON YOUR OWN RISK !).
  42. *
  43. *        New versions are released through the Aminet.
  44. *
  45. *        As a service for registered users I will notify you about
  46. *        new versions if I get your email address.
  47. *        To be able to do this, you should fill in the following form
  48. *        and send this to my email/snail-mail address:
  49. *
  50. *        -- snip --
  51. *
  52. *        Product/Version: anim.datatype 1.10 (4.8.97)_______________________
  53. *
  54. *        Name:     _________________________________________________________
  55. *
  56. *        Street:   _________________________________________________________
  57. *
  58. *        City/ID:  _________________________________________________________
  59. *
  60. *        Country:  _________________________________________________________
  61. *
  62. *        Phone:    _________________________________________________________
  63. *
  64. *        EMail:    _________________________________________________________
  65. *
  66. *        Shareware fee: _ 10 US-$
  67. *                       _ 15 DM
  68. *                       _ other (in a amount which equals to the US-$ fee)
  69. *
  70. *        Payed by  _ cash money in envelope (on your own risk !)
  71. *                  _ euro-scheque (on my name)
  72. *                  _ bank transfer
  73. *
  74. *        Comments: _________________________________________________________
  75. *
  76. *                  _________________________________________________________
  77. *
  78. *                  _________________________________________________________
  79. *
  80. *        -- snip --
  81. *
  82. *    REQUIREMENTS
  83. *        - You need at least Kick/WB 3.0.
  84. *          | Many people wrote me that they cannot find an
  85. *          | "animation.datatype" class.
  86. *          | Only the 3.1 release contains it. (Subclasses of)
  87. *          | animation.datatype can run under 3.0.
  88. *
  89. *        - "datatypes/animation.datatype", >= V39.
  90. *          "animation.datatype 40.7 (28.09.93)" requires itself some
  91. *          libraries/boopsi classes:
  92. *        - "realtime.library", >= V39              - for timing
  93. *        - "gadgets/tapedeck.gadget" (any version) - for the controls
  94. *
  95. *           If you want to attach samples, you need "sound.datatype" >= V39
  96. *           and your prefereed subclass (8svx.datatype for IFF 8SVX samples
  97. *           etc.).
  98. *
  99. *    USAGE
  100. *        If the datatypes descriptor file was activated, any attempt to load
  101. *        an IFF anim stream using GMultiView, MultiView, AmigaGuide or
  102. *        SwitchWindow will load and play the animation. If the source was a
  103. *        file, anim.datatype loads frames dynamically from disk, if the
  104. *        source was the clipboard, anim.datatype caches the whole anim.
  105. *
  106. *        anim.datatype supports also the clipboard as input, e.g.
  107. *        "MultiView CLIPBOARD", ClipView or SwitchWindow are able to show
  108. *        IFF ANIMs from clipboard.
  109. *
  110. *        If you want to save the current animation in anim.datatype's local
  111. *        format, use MultiView's "Project/Save As..." menu (or GMultiView's
  112. *        "Project/Save As Raw...").
  113. *        anim.datatype saves the current animation, stating with the current
  114. *        frame as IFF ANIM-3.
  115. *        Other compression formats such as ANIM-0/1/2/4/5/7/8/J will
  116. *        be implemeted later.
  117. *
  118. *        If you want to attach samples to the animation, you must edit the
  119. *        prefs file (ENV:Classes/DataTypes/anim.prefs) and add the following
  120. *        line:
  121. *        VERBOSE SAMPLE="ram:have_a_nice_day.8svx"
  122. *        Which loads and attaches the sample "ram:have_a_nice_day.8svx" to the
  123. *        animation. See anim.datatype.doc/preferences for a complete
  124. *        description of the prefs file.
  125. *
  126. *    INSTALLATION
  127. *        After unpacking this archive:
  128. *        Because this version does not include an Installer script, you have
  129. *        to do the installation manually through the shell:
  130. *
  131. *          - Unpack this archive and copy the "anim.datatype" to
  132. *            SYS:Classes/DataTypes:
  133. *
  134. *     Copy CLONE FROM "anim.datatype" TO "SYS:Classes/DataTypes/anim.datatype"
  135. *
  136. *          - Then copy the datatypes descriptor into the DEVS:DataTypes
  137. *            directory.
  138. *            If the descriptor already exists, you should not replace it,
  139. *            otherwise you may loose "toolnodes" and other settings stored in
  140. *            the existing descriptor.
  141. *
  142. *     Copy CLONE FROM "ANIM(%|.info)" TO DEVS:Datatypes/
  143. *
  144. *    SOURCE
  145. *        Partial source is included as an example how to write an
  146. *        animation.datatype subclass which deals with things like
  147. *        "delta-compression" techniques.
  148. *
  149. *    AUTHOR
  150. *        If you want to blame me, report any bugs, or wants a new version
  151. *        send your letter to:
  152. *                        Roland Mainz
  153. *                        Hohenstaufenstraße 8
  154. *                        52388 Nörvenich
  155. *                        GERMANY
  156. *
  157. *        Phone: (+49)(0)2426/901568
  158. *        Fax:   (+49)(0)2426/901569
  159. *
  160. *        Bank account: Kto. 4866 02-508
  161. *        At:           Postbank Köln,
  162. *                      BLZ 37010050
  163. *
  164. *        EMAIL is also available (if you want to send me attachments
  165. *        larger than 1MB (up to 5MB, more with my permission):
  166. *
  167. *        GISBURN@w-specht.rhein-ruhr.de
  168. *
  169. *        Up to December 1997 I'm reachable using this email address, too:
  170. *        Reinhold.A.Mainz@KBV.DE
  171. *
  172. *        | Please put your name and address in your mails !
  173. *        | German mailers should add their phone numbers.
  174. *        | See BUGS section above when submitting bug reports.
  175. *
  176. *        Sorry, but I can only look once a week for mails.
  177. *        If you don't hear something from me within three weeks, please
  178. *        send your mail again (but watch about new releases) (problems with
  179. *        this email port are caused by reconfigurations, hackers, network
  180. *        problems etc.).
  181. *
  182. *        The  entire  "anim.datatype"  package  may  be  noncommercially
  183. *        redistributed, provided  that  the package  is always  distributed
  184. *        in it's complete  form (including it's documentation). A small
  185. *        copy fee  for media costs is okay but any kind of commercial
  186. *        distribution is strictly forbidden without my permission !
  187. *        Comments and suggestions how to improve this program are
  188. *        generally appreciated!
  189. *
  190. *        Thanks to David Junod, who wrote the animation.datatype and lots of
  191. *        the datatypes example code, Jim Kent, Eric Graham and other people
  192. *        for their compression formats, Matt Dillon for his DICE, Olaf
  193. *        'Olsen' Barthel for his help, ideas and some text clips from his
  194. *        documentations.
  195. *
  196. ******************************************************************************
  197. *
  198. */
  199.  
  200.  
  201.  
  202. /****** anim.datatype/--datasheed-- ******************************************
  203. *
  204. *   NAME
  205. *       anim.datatype -- data type for IFF ANIM animations
  206. *
  207. *   SUPERCLASS
  208. *       animation.datatype
  209. *
  210. *   DESCRIPTION
  211. *       The anim datatype, a sub-class of the animation.datatype, is used to
  212. *       load and play IFF anim animations.
  213. *       It supports all currently defined IFF anim compressions
  214. *       (0/1/2/3/4/5/6/7/8/J) and any "interleave count".
  215. *       ILBM BODY Interleaved bitmaps can be uncompressed or compressed using
  216. *       cmpByteRun1.
  217. *       Using the prefs-file, any sound can be attached to the animation.
  218. *
  219. *   METHODS
  220. *       OM_NEW -- Create a new animation object from a description file. The
  221. *           source may be a file or a clipboard unit, both given as an
  222. *           IFFHandle, or you may create an empty object (DTST_RAM).
  223. *
  224. *       OM_DISPOSE -- Dispose instance and contents (frames, colormaps, sounds
  225. *           etc.), then pass msg to superclass.
  226. *
  227. *       OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
  228. *           method will be executed like OM_SET downstairs.
  229. *
  230. *       OM_SET -- Pass msg to superclass and call GM_RENDER if retval from
  231. *           superclass was != 0UL.
  232. *
  233. *       DTM_WRITE -- Save object's contents in local (IFF ANIM-3) or
  234. *           superclass (IFF ILBM) format.
  235. *
  236. *       ADTM_START -- Start playback.
  237. *
  238. *       ADTM_PAUSE -- Pause playback.
  239. *
  240. *       ADTM_STOP -- Stop playback.
  241. *
  242. *       ADTM_LOADFRAME -- Fill in struct adtFrame with requested information
  243. *           from internal FrameNode list like bitmap, colormap and sample. If
  244. *           the bitmap information is not loaded yet, it will be loaded from
  245. *           disk.
  246. *
  247. *       ADTM_UNLOADFRAME -- Free resources obtained by ADTM_UNLOADFRAME.
  248. *
  249. *       All other methods are passed unchanged to superclass.
  250. *
  251. *   ATTRIBUTES
  252. *       Following attributes are set by the object and are READ-ONLY for
  253. *       applications:
  254. *       DTA_ObjName             -- set by anim file (IFF generic NAME chunk)
  255. *       DTA_ObjAuthor           -- set by anim file (IFF generic AUTH chunk)
  256. *       DTA_ObjAnnotation       -- set by anim file (IFF generic ANNO chunk)
  257. *       DTA_ObjCopyright        -- set by anim file (IFF generic (C)  chunk)
  258. *       DTA_ObjVersion          -- set by anim file (IFF generic FVER chunk)
  259. *       DTA_TotalVert           -- set by BitMapHeader (ILBM BMHD chunk)
  260. *       DTA_TotalHoriz          -- set by BitMapHeader (ILBM BMHD chunk)
  261. *       ADTA_Width              -- set by BitMapHeader (ILBM BMHD chunk)
  262. *       ADTA_Height             -- set by BitMapHeader (ILBM BMHD chunk)
  263. *       ADTA_Depth              -- set by BitMapHeader (ILBM BMHD chunk)
  264. *       ADTA_Frames             -- number of frames in animation
  265. *       ADTA_FramesPerSecond    -- FPS rate (possibly set by DPAN chunk)
  266. *       ADTA_KeyFrame           -- Key frame of animation
  267. *
  268. *   BUGS
  269. *       - In large videos, the frames at the end will be played slower than
  270. *         those at the beginning of the file. This is the result of the
  271. *         sequential search internally used (only serious with more than 25000
  272. *         frames (mc6030/50mhz)).
  273. *         May or may not be fixed.
  274. *
  275. *       - Animations with more than 8 planes will crash the system
  276. *         (anim.datatype handels 12 bit animations, but animation.datatype 
  277. *         V40 handles only anims with a depth of 8).
  278. *
  279. *       - ANIM-1-Code has been disabled because it draws the blocks to X and H
  280. *         dimensions which are divisible by 8 (can't be fixed: no test files).
  281. *
  282. *       - The ANHD (AnimHeader) ah_Mask-field will be ignored for ANIM-0,
  283. *         2,3,4,5,6,7,8,J. ANIM-1 (acmpXORILBM) respects this.
  284. *
  285. *       - The BMHD (BitMapHeader) bmh_Masking-field will be ignored.
  286. *
  287. *       - ANIM-4 isn' tested yet (no test files).
  288. *
  289. *       - ANIM-4 has been disabled for the reason above.
  290. *
  291. *       - ANIM-J is twice as slow as it should be because ANIM-J operates on
  292. *         interleaved bitmaps, but (currently) anim.datatype uses
  293. *         non-interleaved bitmaps internally. Therefore the current
  294. *         implementation interleaves the bitmap, then unpacks, then
  295. *         de-interleaves the bitmap. Not very efficient.
  296. *
  297. *       - Any flags in the ANHD (AnimHeader) ah_Flags field except ahfLongData
  298. *         (bit 0; used by Anim-7/8) and ahfXOR (bit 1; used for all
  299. *         compression types except ANIM-J (not required, ANIM-J has an
  300. *         internal XOR mode) and anim-0) are ignored. ANIM-4 suffers under
  301. *         these problems (cannot be fixed without example files).
  302. *
  303. *       - ANIM-6 left/right channels are viewed interleaved. Upon request,
  304. *         I can add options to view the left or right channel only.
  305. *
  306. *       - The internal "rollback" machanism used for creating full images from
  307. *         given DLTAs is slow. This is caused by implementation details,
  308. *         not the idea itself.
  309. *
  310. *       - If an animations contains colormaps-per-frame and the given CMAP
  311. *         contains less colors than (1UL << anim_depth), the remaining colors
  312. *         are filled with black. I don't know where to take the remaining
  313. *         colors (from last frame/previous (e.g. interleaved) frame)...
  314. *         Comments __VERY__ welcome.
  315. *
  316. *       - The ANIM-3 encoder has a slight problem in run-length compression;
  317. *         therefore this part has been disabled.
  318. *
  319. *       - The encoder does not support dynamic timing properly. Instead,
  320. *         all frames are saved.
  321. *
  322. *       - The encoded initial ANIM-3 IFF ILBM BODY is uncompressed.
  323. *
  324. *       - The encoder rejects any attempt to work with non-planar or
  325. *         interleaved planar bitmaps.
  326. *
  327. *   TODO
  328. *       - Fixing the bugs above.
  329. *
  330. *       - Internal cache for packed DLTA chunks. This may speed up the
  331. *         internal rollback mechanism used for random frame access.
  332. *
  333. *       - Other compression formats when saving, including the popular
  334. *         ANIM-5.
  335. *
  336. *       - PERIOD options to modify the given sound.
  337. *
  338. *       - Add support for animation.datatype V41 ADTA_TicksPerFrame timing.
  339. *
  340. *       - Write the "--input_format--"-Autodoc section.
  341. *
  342. *   HISTORY
  343. *       V1.1
  344. *         Released to the Waldspecht-BBS for testing.
  345. *
  346. *       V1.2
  347. *         Released to the Waldspecht-BBS for testing.
  348. *
  349. *       V1.3
  350. *         Released to the Waldspecht-BBS for testing.
  351. *
  352. *       V1.4
  353. *         First Aminet release.
  354. *
  355. *         - Partial code cleanup
  356. *
  357. *         - Recompiled with SAS/C 6.57.
  358. *
  359. *         - Redirected serial "verbose" output to a CON:-window, including
  360. *           the matching VERBOSE prefs option.
  361. *
  362. *         - Changed the VERBOSE output a little bit.
  363. *
  364. *       V1.5
  365. *         - Implemented palette per frame (ILBM CMAPs per frame).
  366. *           (animation.datatype 40.7 does not support these colormap changes
  367. *           per frame (it's output may look like a color trash). Custom
  368. *           animation players which uses animation.datatype subclasses for
  369. *           loading (like my DBufDTAnim) don't have this problem.
  370. *           animation.datatype will support these colormaps-per-frame in one
  371. *           of the next updates.)
  372. *
  373. *         - Internal changes to be able to support up to 12 planes in an anim.
  374. *           The animation.datatype 40.7 supports only anims up to 8 planes,
  375. *           otherwise the machine will crash. My animation.datatype V41 will
  376. *           support this.
  377. *
  378. *         - The generic IFF ANNO, AUTH, FVER, NAME and "(C) " chunks are now
  379. *           moved to the corresponsing DataTypes attributes if they appear in
  380. *           a FORM ILBM.
  381. *           The data will be moved like this:
  382. *           ANNO -> DTA_ObjAnnotation
  383. *           AUTH -> DTA_ObjAuthor
  384. *           FVER -> DTA_ObjVersion
  385. *           NAME -> DTA_ObjName
  386. *           (C)  -> DTA_ObjCopyright
  387. *
  388. *         - DTA_Title equals now to DTA_ObjName (e.g. a given NAME chunk). If
  389. *           this is NULL, DTA_Name is used instead.
  390. *
  391. *         - If a DPAN (DPaint Anim) chunk occurs, the FPS rate is taken from
  392. *           the "flags" field.
  393. *           Thanks to Brian Jones (bjones@cadvision.com) for reporting this.
  394. *           If the value taken is 0, the old, fixed rate (5 fps) is used
  395. *           again.
  396. *
  397. *         - Fixed a hole in the state machine which causes problems when an
  398. *           animation contains no frames. Should work now.
  399. *           Fixed.
  400. *
  401. *         - An error in the prefs-file will now force the VERBOSE option.
  402. *
  403. *         - Implemented sound. A sample can now be attached to the animation
  404. *           using the SAMPLE/VERBOSE options.
  405. *           Note that anim.datatype is still a GID_ANIMATION (anim WITHOUT
  406. *           sound) type datatype.
  407. *           The GID_#? idetifiers belongs to the source data, not the
  408. *           modifications done by a datatype code (a IFF ANIM does not contain
  409. *           any sound data, the sound is attached later).
  410. *
  411. *       V1.6
  412. *         - Disabled the optimizer. This fixes a mysterious System-Crash
  413. *           when resizing the parent application window. Don't know why this
  414. *           works now :-((
  415. *
  416. *       V1.7
  417. *         - Reorganisation of source (includes small cleanup).
  418. *
  419. *         - Fixed a silly hole in the state machine which causes the
  420. *           datatype to return errors on colormap changes (e.g. ILBM CMAPs).
  421. *           Error codes were returned like this:
  422. *           (Number_of_colors_in_CMAP * 3).
  423. *
  424. *         - Enabled the optimizer (see V1.6) again. Since reorganisation of
  425. *           the src, the problem never occured again. Any hint ?
  426. *
  427. *         - Fixed a bug in LibExpunge (didn't check lib_OpenCnt), which is
  428. *           also present in all my other external BOOSI classes (and
  429. *           datatypes).
  430. *           Thanks to Guenter Niki (gniki@informatik.uni-rostok.de) for
  431. *           reporting this bug.
  432. *
  433. *       V1.8
  434. *         * Shareware
  435. *           Starting with V1.8, anim.datatype is Shareware.
  436. *
  437. *         - Added experimental stack swapping code. The "Need more stack"-
  438. *           requester has been removed for this reason.
  439. *           This also fixes a possible deadlock of "input.device" because
  440. *           the GM_LAYOUT method was running with low stack.
  441. *
  442. *         - Uses OpenFromLock when obtaining a fh for random frame access.
  443. *           This allows the usage of "virtual filesystems" (datatypes.library
  444. *           V45 allows such things).
  445. *
  446. *         - Now supports saving in the local format (e.g. IFF ANIM,
  447. *           currently only ANIM-3).
  448. *           Note that saveing begins with the __current__ frame and can be
  449. *           controlled with the ADTA_Frame, ADTA_Frames and
  450. *           ADTA_FrameIncrement attributes.
  451. *
  452. *         - Now support DTST_RAM (creates an empty anim.datatype object).
  453. *
  454. *         - Now supports subclasses of anim.datatype, mainly to fill in
  455. *           the ADTM_LOADFRAME/ADTM_UNLOADFRAME methods when using an empty
  456. *           (e.g. created with DTST_RAM) anim.datatype object.
  457. *
  458. *         - Now the high order bits of each color gun are replicated through
  459. *           the whole INT32 in the colormap.
  460. *
  461. *       V1.9
  462. *         - Fixed a bug which prevents saving in local (IFF ANIM-3) format
  463. *           using an (created using DTST_RAM) empty object (like "DTConvert"
  464. *           does).
  465. *           Fixed.
  466. *
  467. *       V1.10
  468. *         - Moved IFF ANIM defines etc. to classdata.h include file.
  469. *
  470. *         - Reworked file scan. This fixes problems with many animations
  471. *           where the second frame was treated as an ILBM instead of an DLTA.
  472. *           Fixed.
  473. *
  474. *         - Implemented ADTM_START, ADTM_STOP and ADTM_PAUSE to get a more
  475. *           smoothly start and stop, see method autodocs for details.
  476. *
  477. *         - Implemented Martin Tailefer's AsyncIO code (currenty broken,
  478. *           has been disabled for now).
  479. *
  480. *         - Removed unnecessary GM_LAYOUT code; DTA_Total(Vert|Horiz) are now
  481. *           set in OM_NEW.
  482. *
  483. *         - Fixed ADTM_LOADFRAME that if a frame can't be loaded (seek error,
  484. *           or timestamp not found) now a matching error code will be
  485. *           returned in Result2.
  486. *
  487. *         - Removed NOREMAP feature and matching DTM_FRAMEBOX code because
  488. *           this was an ugly hack...
  489. *
  490. *         - XORBitMap has been rewritten, XOR mode for
  491. *           ANIM-2/-3/-4/-5/-6/-7-/8 should now be a little bit faster;
  492. *           this also fixes two bugs:
  493. *           - The bitmaps were incorrectly merged together when the bitmap
  494. *             size grows over 64k per plane (for example 1280 * 512)
  495. *             Fixed.
  496. *           - Due rounding errors the last 8 pixels were not processed
  497. *             Fixed.
  498. *
  499. *         - Plane pointers are now on a quad-long boundary to get more speed
  500. *           on a mc68040.
  501. *
  502. *         - Internal CopyBitMap has been optimized to use CopyMemQuick if
  503. *           possible.
  504. *
  505. *         - Added compatibility code for DPaint ANIM Brushes, compressed with
  506. *           ANIM-5 and XOR mode, but which don't have the XOR bit set.
  507. *           Added NODPAINTBRUSHPATCH to disable this function.
  508. *           This fixes the problems with the animations I found in the CanDo
  509. *           distribution.
  510. *
  511. *         - Added support for GRAB chunk (grabbing point of animation).
  512. *           Does only work with animation.datatype V41 (which implements
  513. *           PDTA_Grab attribute).
  514. *
  515. *         - Stack swapping code has been improved; the stack is now only
  516. *           swapped if stacksize falls below 16384 / 2 bytes; this saves
  517. *           the stack allocation for ADTM_LOADFRAME / ADTM_UNLOADFRAME
  518. *           in animation.datatype V41.
  519. *
  520. *         - Added WaitBlit in OM_DISPOSE to wait for blitter which may
  521. *           use our bitmaps.
  522. *
  523. *         - Added seperate memory pool for frame bitmaps, which is
  524. *           set up to have the correct size for this job.
  525. *           This should speed up bitmap memory allocations.
  526. *           The pool's size is reduced if there is not enougth memory.
  527. *           The other "misc usage" pool is increased to 32k get the
  528. *           correct size for DLTA temp mem usage.
  529. *           The datatype now uses AllocVecPooled instead of AllocVec
  530. *           for delta buffers.
  531. *
  532. *         - Cut some chars from the AnimHeader dump output. Now it fits
  533. *           on a single-line in a 640 pixel CON: window (topaz 8 font).
  534. *
  535. *         - Added NOLOADALL and CMAPS switch for multi-line prefs using
  536. *           the MATCHPROJECT option.
  537. *
  538. *         - Added additional checking code for CAMG chunk data. Invalid
  539. *           flags are now removed.
  540. *
  541. *         - Added support for dynamic timing, e.g. anim.datatype now uses
  542. *           AnimHeader's ah_AbsTime and ah_RelTime fields. Does only work
  543. *           properly with animation.datatype V41 (for animation.datatype
  544. *           V40 this option is turned off per default and turned on if
  545. *           superclass is animation.datatype V41); matching NODYNAMICTIMING
  546. *           and DYNAMICTIMING options have been added; modifications
  547. *           have been made in AttachSamples and ADTM_LOADFRAME, too.
  548. *
  549. *         - Fixed the bug that the last sample's length wasn't calculated
  550. *           correctly, which may have caused Enforcer read-hits (never
  551. *           seen, but...).
  552. *
  553. *         - Added SAMPLESPERFRAME option to override own calculations.
  554. *           This allows to get rid of rounding errors in such cases.
  555. *
  556. *         - Added "wanted" message for IFF ANIM-4 animations. If you have
  557. *           such an animation, and if you are the FIRST who send's me a VALID
  558. *           IFF ANIM-4 compressed animation, you'll get $10. No joke.
  559. *
  560. *         - ANIM-3 encoder has been cut down in functionality to get
  561. *           (temporary) rid of a bug in run-length encoding (DPaint IV AGA
  562. *           does not like this !?).
  563. *
  564. *         - The encoder does not not fail if a subclass returns
  565. *           ERROR_OBJECT_NOT_FOUND for ADTM_LOADFRAME. It simply tries
  566. *           to load the next frame. This fixes some problems with dynamic
  567. *           timing.
  568. *
  569. *         - The encoder now checks explicitly for non-planar or interleaved
  570. *           planar input bitmaps, which are NOT supported yet (e.g.
  571. *           such an attempt results in ERROR_NOT_IMPLEMENTED).
  572. *
  573. *         - A fps value greater than 60 fps found in a DPAN chunk is now
  574. *           treated as invalid.
  575. *
  576. *       V1.11
  577. *         - Recompiled with SAS/C 6.58. May fix some mc68060 related
  578. *           problems.
  579. *
  580. *         - Found the longstanding bug that animation.datatype V40.7
  581. *           didn't free some frames. Reason is that ADTM_LOADFRAME
  582. *           may be used like "realloc". Now alf_UserData is checked;
  583. *           any given frame will be freed (ADTM_UNLOADFRAME).
  584. *           Fixed.
  585. *
  586. *         - ADTM_UNLOADFRAME now clears alf_UserData to indicate that the
  587. *           frame has been freed.
  588. *
  589. *         - Now supports anims deeper than 8 planes, but a colormap
  590. *           (e.g. a CMAP chunk) is still expected.
  591. *
  592. *         - Fixed the bug that a free of the current frame caused an frame
  593. *           to be not freed. (The idea was to hold the current frame for
  594. *           following delta accesses; this has been replaced by the idea
  595. *           of the "posted free").
  596. *
  597. *         - Implemented the idea of a "posted free". For delta accesses,
  598. *           it's not very usefull to free the frame when the next frame
  599. *           needs it for it's delta access. Therefore, the anim.datatype
  600. *           now manages a "free list", where the free of the previous
  601. *           and the previous-previous frame will be posted until
  602. *           it is really not longer in use.
  603. *
  604. *         - Fixed a bug in the LOADALL mode that the wrong previous
  605. *           frame was used (due a change in V1.10).
  606. *
  607. *         - The single framenodes now caches a pointer to their previous
  608. *           frame. This should speed up loading a little bit.
  609. *
  610. *         - If an animation has dynamic timing and the superclass
  611. *           (animation.datatype) has the ADTA_AdaptiveFPS flag set,
  612. *           the playback speed now defaults to 60 fps.
  613. *
  614. *         - Saved an AllocVecPooled in ADTM_LOADFRAME by merging multiple
  615. *           delta buffer allocations to one allocation (which can hold the
  616. *           largest delta).
  617. *
  618. *         - The stack swapping code now allocates it's memory without
  619. *           the MEMF_CLEAR flags, which should speed up things.
  620. *
  621. *         - Removed BestModeIDA code, because animation.datatype does
  622. *           the same.
  623. *
  624. *         - The options setting for DPaint brush compatibility patch
  625. *           worked wrong (the order was wrong). Now the options
  626. *           work as described.
  627. *           Fixed.
  628. *
  629. *         - Fixed a bug in the encoder that the last color of a dynamic
  630. *           pallete as not copied (GetRGB32 got numcolors - 1 instead
  631. *           of numcolors).
  632. *           Fixed.
  633. *
  634. *       V1.12
  635. *         - Replaced the custom stack swapping code by my "standard" module.
  636. *
  637. *         - Now the default FPS rate is 10 if animation.datatype is
  638. *           < V41. If V41 is running with ADTA_AdaptiveFPS, the
  639. *           fps is set to 60.
  640. *
  641. *         - Fixed ModeID handling. The previous behaviour was that
  642. *           a 0 mode id causes the datatype to select it's own mode id.
  643. *           But 0 means LORES. Now the default is -1 (which means
  644. +           INVALID_ID), which causes the datatype to do it's own
  645. *           calculations.
  646. *           Fixed.
  647. *
  648. *         - OM_DISPOSE now preserves Result2 (IoErr()) to avoid that an 
  649. *           error code may get lost.
  650. *
  651. *   NOTES
  652. *       This datatype first scans the whole animation to get index
  653. *       information (if the LOADALL switch was set in the prefs-file,
  654. *       the entire animation will be loaded), colormaps will be loaded
  655. *       immediately.
  656. *
  657. *   SEE ALSO
  658. *       animation.datatype,
  659. *       mpegsystem.datatype, mpegvideo.datatype,
  660. *       picmovie.datatype,
  661. *       cdxl.datatype. avi.datatype, quicktime.datatype,
  662. *       moviesetter.datatype,
  663. *       film.datatype,
  664. *       directory.datatype,
  665. *       markabletextdtclass
  666. *
  667. *******************************************************************************
  668. *
  669. */
  670.  
  671.  
  672. /****** anim.datatype/--input_format-- ****************************************
  673. *
  674. *    NAME
  675. *        IFF ANIM -- IFF animation format
  676. *
  677. *    DESCRIPTION
  678. *        <Not written yet, sorry>
  679. *
  680. *        acmpILBM             -- ILBM BODY
  681. *        acmpXORILBM          -- XOR
  682. *        acmpLongDelta        -- Long Delta
  683. *        acmpShortDelta       -- Short Delta
  684. *        acmpDelta            -- General Delta
  685. *        acmpByteDelta        -- Byte Vertical
  686. *        acmpStereoByteDelta  -- Stereo Byte Vertical (left/right channel)
  687. *        acmpAnim7            -- Anim7 (nonstandard format)
  688. *        acmpAnim8            -- Anim5 compression using LONG/WORD data
  689. *        acmpAnimJ            -- Eric Grahams compression format
  690. *
  691. *
  692. *    SEE ALSO
  693. *        - "ANIM.DOC" IFF Animspecs,
  694. *          "ANIM.BRUSH.DOC" Anim specs,
  695. *          "ANIM.OP6" Anim specs,
  696. *          "ANIM7.DOC" Anim specs
  697. *          "ANIM.OP8" Anim specs
  698. *
  699. *        - ARKM Devices (Addison Wesley): IFF part
  700. *
  701. *        - iffparse.library autodocs
  702. *
  703. *        - AAP/AAC docs (for a complete description of the Anim7 format)
  704. *
  705. *        - Viewtek (VT) distribution for Anim 7 info
  706. *
  707. *******************************************************************************
  708. *
  709. */
  710.  
  711.  
  712.  
  713. /*****************************************************************************/
  714.  
  715. DISPATCHERFLAGS
  716. struct IClass *ObtainAnimEngine( REGA6 struct ClassBase *cb )
  717. {
  718.     return( (cb -> cb_Lib . cl_Class) );
  719. }
  720.  
  721. /*****************************************************************************/
  722.  
  723. DISPATCHERFLAGS
  724. struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
  725. {
  726.     cb -> cb_SegList = seglist;
  727.     cb -> cb_SysBase = sysbase;
  728.  
  729.     InitSemaphore( (&(cb -> cb_Lock)) );
  730.  
  731.     if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
  732.     {
  733.       /* Obtain ROM libs */
  734.       if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
  735.       {
  736.         if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
  737.         {
  738.           if( cb -> cb_IFFParseBase = OpenLibrary( "iffparse.library", 39UL ) )
  739.           {
  740.             if( cb -> cb_GfxBase = OpenLibrary( "graphics.library",  39UL ) )
  741.             {
  742.               if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
  743.               {
  744.                 return( (&(cb -> cb_Lib . cl_Lib)) );
  745.  
  746. #ifdef COMMENTED_OUT
  747.                 CloseLibrary( (cb -> cb_IntuitionBase) );
  748. #endif /* COMMENTED_OUT */
  749.               }
  750.  
  751.               CloseLibrary( (cb -> cb_GfxBase) );
  752.             }
  753.  
  754.             CloseLibrary( (cb -> cb_IFFParseBase) );
  755.           }
  756.  
  757.           CloseLibrary( (cb -> cb_DOSBase) );
  758.         }
  759.  
  760.         CloseLibrary( (cb -> cb_UtilityBase) );
  761.       }
  762.     }
  763.  
  764.     return( NULL );
  765. }
  766.  
  767. /*****************************************************************************/
  768.  
  769. DISPATCHERFLAGS
  770. LONG LibOpen( REGA6 struct ClassBase *cb )
  771. {
  772.     LONG retval = (LONG)cb;
  773.     BOOL success = TRUE;
  774.  
  775.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  776.  
  777.     /* Use an internal use counter */
  778.     cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
  779.     cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
  780.  
  781.     if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
  782.     {
  783.       if( (cb -> cb_Lib . cl_Class) == NULL )
  784.       {
  785.         success = FALSE;
  786.  
  787.         if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
  788.         {
  789.           if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/animation.datatype", 39UL ) )
  790.           {
  791.             if( cb -> cb_Lib . cl_Class = initClass( cb ) )
  792.             {
  793.               success = TRUE;
  794.             }
  795.           }
  796.         }
  797.       }
  798.     }
  799.  
  800.     if( !success )
  801.     {
  802.       CloseLibrary( (cb -> cb_SuperClassBase) );
  803.       CloseLibrary( (cb -> cb_DataTypesBase) );
  804.  
  805.       cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
  806.  
  807.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  808.  
  809.       retval = 0L;
  810.     }
  811.  
  812.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  813.  
  814.     return( retval );
  815. }
  816.  
  817. /*****************************************************************************/
  818.  
  819. DISPATCHERFLAGS
  820. LONG LibClose( REGA6 struct ClassBase *cb )
  821. {
  822.     LONG retval = 0L;
  823.  
  824.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  825.  
  826.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  827.     {
  828.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  829.     }
  830.  
  831.     if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
  832.     {
  833.       if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
  834.       {
  835.         cb -> cb_Lib . cl_Class = NULL;
  836.  
  837.         CloseLibrary( (cb -> cb_SuperClassBase) );
  838.         CloseLibrary( (cb -> cb_DataTypesBase) );
  839.       }
  840.       else
  841.       {
  842.         cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  843.       }
  844.     }
  845.  
  846.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  847.  
  848.     if( (cb -> cb_Lib . cl_Lib . lib_Flags) & LIBF_DELEXP )
  849.     {
  850.       retval = LibExpunge( cb );
  851.     }
  852.  
  853.     return( retval );
  854. }
  855.  
  856. /*****************************************************************************/
  857.  
  858. DISPATCHERFLAGS
  859. LONG LibExpunge( REGA6 struct ClassBase *cb )
  860. {
  861.     BPTR seg;
  862.  
  863.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  864.     {
  865.       cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  866.  
  867.       seg = NULL;
  868.     }
  869.     else
  870.     {
  871.       Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
  872.  
  873.       seg = cb -> cb_SegList;
  874.  
  875.       CloseLibrary( (cb -> cb_IntuitionBase) );
  876.       CloseLibrary( (cb -> cb_GfxBase) );
  877.       CloseLibrary( (cb -> cb_IFFParseBase) );
  878.       CloseLibrary( (cb -> cb_DOSBase) );
  879.       CloseLibrary( (cb -> cb_UtilityBase) );
  880.  
  881.       FreeMem( (APTR)((ULONG)(cb) - (ULONG)(cb -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((cb -> cb_Lib . cl_Lib . lib_NegSize) + (cb -> cb_Lib . cl_Lib . lib_PosSize)) );
  882.     }
  883.  
  884.     return( (LONG)seg );
  885. }
  886.  
  887.  
  888.