Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / mpegvideo / classbase.c
blob5c8bddd71bac4251435f02cab79eb633b395d6f2
2 /*
3 **
4 ** $VER: classbase.c 1.11 (7.11.97)
5 ** mpegvideo.datatype 1.11
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
14 #ifndef DEBUG
15 # define DEBUG 0
16 #endif
17 #include <aros/debug.h>
19 /* main includes */
20 #include "classbase.h"
22 #ifdef __SASC
23 /* SAS/C compatibly hack. This may be caused by a math library */
24 __stdargs
25 void _XCEXIT( long dummy )
28 #endif /* __SASC */
31 /****** mpegvideo.datatype/--datasheed-- *************************************
33 * NAME
34 * mpegvideo.datatype -- data type for mpeg video streams
36 * SUPERCLASS
37 * animation.datatype
39 * DESCRIPTION
40 * The mpegvideo data type, a sub-class of the animation.datatype, is
41 * used to load and play mpeg 1 video streams (Layer I).
43 * METHODS
44 * OM_NEW -- Create a new animation object from a description file. The
45 * source may only be a file.
47 * OM_DISPOSE -- Dispose instance and contents (frames, colormaps etc.),
48 * then pass msg to superclass
50 * OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
51 * method will be executed like OM_SET downstairs.
53 * OM_SET -- Pass msg to superclass, and if the mpegvideo.datatype
54 * instance is the "top instance", call GM_RENDER if retval from
55 * superclass was != 0UL.
57 * ADTM_LOADFRAME -- Fill in struct adtFrame with requested information
58 * from internal FrameNode list like bitmap, colormap, samples, etc..
60 * All other methods are passed unchanged to superclass.
62 * ATTRIBUTES
63 * Following attributes are set by the object and are READ-ONLY for
64 * applications:
65 * DTA_NominalHoriz -- same as ADTA_Width
66 * DTA_NominalVert -- same as ADTA_Height
67 * DTA_ObjName -- same as DTA_Name
68 * ADTA_Width -- set by video stream
69 * ADTA_Height -- set by video stream
70 * ADTA_Depth -- set by video stream (or by prefs)
71 * ADTA_NumColors -- set by ADTA_Depth or to the num. of
72 * palette entries
73 * ADTA_ColorRegisters -- obj's palette with ADTA_NumColors entries
74 * ADTA_CRegs -- obj's palette with ADTA_NumColors entries
75 * ADTA_Frames -- total number of frames
76 * ADTA_FramesPerSecond -- set by video stream
77 * ADTA_ModeID -- calculated internally or set by prefs
78 * ADTA_KeyFrame -- key frame
79 * ADTA_Sample -- sample (optional, if a sample is attached)
80 * ADTA_SampleLength -- sample length (optional, see ADTA_Sample)
81 * ADTA_Period -- sample period (optional, see ADTA_Sample)
82 * ADTA_Volume -- sample volume (optional, see ADTA_Sample)
83 * ADTA_Cycles -- sample cycle (optional, see ADTA_Sample)
85 * BUGS
86 * - If the mpeg video stream is not 100% standart conform,
87 * the decoder part of this datatype will CRASH your machine.
88 * Innocent memory will be overwritten !!
90 * - If you don't have my "paranimdtcpatch" patch running,
91 * animation.datatype (animation.datatype 40.7 (28.09.93)) subclasses
92 * will suffer under timing problems when two or more
93 * animation.datatype objetcs are playing. I've released a matching
94 * patch, DON'T blame me for this bug. Any comments for this problem
95 * should be related to the "paranimdtcpatch" project.
96 * "paranimdtcpatch" is available in the aminet
97 * ("util/dtype/panimdtcptch012.LhA").
98 * NOTE that animation.datatype V41 does NOT require the patch
99 * anymore.
101 * - In large videos, the frames at the end will be played slower than
102 * those at the beginning of the file. This is the result of the
103 * sequential search internally used (only serious with more than 25000
104 * frames (mc68030/50mhz)).
105 * Will be fixed.
107 * - The LOADALL mode does not work perfectly. It sometimes "forgets" to
108 * fill some frames during loading.
110 * - The time code in the NOLODALL mode is slightly wrong (I assume up
111 * to +/- 6 frames).
113 * - The NOPFRAMES and NOBFRAMES options are incompatible with the
114 * NOLOADALL mode.
116 * - CyberGFX 24 bit output mode uses 32 bit ARGB bitmaps, but the A
117 * (alpha) byte is not set to 0xFF (visible), instead it is set to 0.
118 * The same for 15 bit output mode, where the MSB is a alpha mask bit.
120 * TODO
121 * - better error handling (and error messages)
123 * - code cleanup
125 * - bug fixing
127 * - Writing an amigaguide document
129 * - EHB
131 * HISTORY
132 * V1.1
133 * First (official) public release.
135 * V1.2
136 * Major code cleanup. I decided to rebuild the whole project from
137 * scratch instead of releasing my internal V1.8. The reason is that
138 * many things coded in it wasn't done with the required care. Now
139 * I try to fix this.
141 * - Sorry, but in the V1.1 release, I've forgotten the COPYRIGHT
142 * notice. Because I don't have the original ones (my code was a
143 * mergin of mpeg_play 1.X, 2.0, I've taken them from the
144 * mpeg_play 2.0 distribution).
146 * - Implemented the NOPFRAMES and NOBFRAMES switch (for those people
147 * who like it).
149 * - The loader now returns usefull return codes instead of failing
150 * silently.
152 * - Decrased the default depth from 7 to 5 planes. This is a more
153 * reliable default value for grayscale mpeg videos (screen or
154 * window).
156 * - Implemented "DICECOLOR" and "ORDERED" dithering.
157 * The options COLORERROR and DICESKIP are for fine-tuning
158 * speed <--> color output.
160 * - Introduced MAXFRAME (maximum number of frame to load) and
161 * SKIPFRAMES to allow loading of large videos.
163 * - MODEID option added (for those which don't like the default
164 * settings).
166 * - The datatypes descriptor file was WRONG. Now it should be correct.
167 * If not, send me a mail (and if possible, the sample file which
168 * won't work (packed with LhA for compression and CHECKSUMMING).
169 * (Later versions of the descriptor should use additional code
170 * to check the data).
172 * V1.3
173 * - COLOR output implemented.
175 * - DICECOLOR: Found a bug (?? very strange one ??) in my code which
176 * avoids the usage of a frame palette. DICECOLOR was intended
177 * to produce high-quality per frame color remapping instead using
178 * a global anim palette. Broken (e.g. working, but after a frame is
179 * finished, the color table isn't cleared for now...).
181 * - I found out that the most time is consumed by the WritePixelArray
182 * and copy functions. Later versions should contain a custom
183 * WritePixelArray replacement which should be able to write directly
184 * into FAST-RAM instead of writing into CHIP-RAM and them do a copy
185 * into FAST-RAM. This would save __MUCH__ time.
187 * - Silly mistake: A
188 * SetIoErr( 0L ); len = FRead( ..., requested ); sequence returns
189 * under various fs IoErr() == (-1L) or something else. The loader
190 * then aborts with this error code. (The code worked with RAM: disk,
191 * my VideoCD-fs ("white book" mode)) and AMICDROM, but wasn't tested
192 * with FFS or something else).
193 * The code now uses Read instead of FRead, checks for
194 * (len != requested), and only if TRUE IoErr() will be checked for
195 * any error.
197 * - Introduced BUFFER preferences option.
199 * - A CTRL-D signal send to the loading process now stops the load.
200 * This feature was implemented in V1.2, but I forgot to write it
201 * down here.
203 * - The autodoc now has a TOC (table of contents).
205 * - Support for Martin Apel's VMM (Virtual Memory Manager).
206 * (USEVMM switch in prefs file). The bitmaps can now be in virtual
207 * memory (the colormaps are traditional allocated by GetColorMap
208 * and cannot be in virtual memory (not yet nor in the future !)).
209 * The mpegvideo.datatype uses the vmm.library, this allows
210 * virtual memory usage even if the vmm.prefs disables virtual memory
211 * for all other tasks.
212 * NOTE: VMM is Shareware !!
214 * V1.4
215 * - vmm.library is now opened on demand (e.g. the USEVMM switch was
216 * set in the prefs file) inside the OM_NEW method.
217 * This fixes two problems:
218 * First: vmm.library was opened even it wasn't used.
219 * Second: OpenLibrary( "vmm.library", ... ) inside the LibInit
220 * function caused various problems.
221 * vmm.library will be closed by LibExpuge function.
223 * - Removed serial verbose output. Now, if the VERBOSE switch was set
224 * in the prefs file, all verbose output will be printed to
225 * "CON://///auto/wait/close/inactive".
227 * - Set the SC NOOPTIMIZERPEEPHOLE switch for mc68060 support:
228 * phase5 said that SAS/C 6.56 has a small bug in the peephole
229 * optimizer which may cause trouble with mc68060. The peephole
230 * optimizer will be turned on again if I know more details (and
231 * a workaround).
233 * - The product of LUM_RANGE * CR_RANGE * CB_RANGE was limited to
234 * a maximum of 512. LUM_RANGE, CR_RANGE, CB_RANGE can now have
235 * any positive value up to 255. A value of 0 is treated as 1,
236 * fixing the problem of a possible division by zero.
238 * - Found a bug in COLOR dithering, which causes quality loss and
239 * color disorientation. Fixing this bug will take MUCH time.
240 * Not fixed yet.
242 * - To match the "DataTypes proposal", changes have been made:
243 * 1. The location of the prefs file is now ENV:Classes/DataTypes/
244 * mpegvideo.prefs instead of ENV:DataTypes/mpegvideo.prefs
245 * 2. Subclasses of mpegvideo.datatype are not supported. Any
246 * attempt to create a subclass object of mpegvideo.datatype
247 * will be rejected by mpegvideo.datatype.
249 * - Partial code cleanup. I've implemented partial support for
250 * output depths up to 16 bits. Currently, I'm limited to a maximum
251 * depth of 8 bitplanes (e.g. 256 colors) for two reasons:
252 * First, the system WritePixelArray8 function handles only byte
253 * width pen indexes, second, animation.datatype handles only a
254 * bitmaps up to 8 planes. Future releases of animation.datatype may
255 * handle deeper bitplanes. (Custom players like my DBufDTAnim which
256 * are using their own display code are able to display deeper
257 * bitmaps yet.)
259 * - Found out a little problem: When using VMM (swap file) with
260 * Enforcer, enforcer hits may block your system (occured on a
261 * A2000 Apollo 2030 mc68030 board).
262 * Who knows an answer for this problem ?
264 * V1.5
265 * Minor changes to support special compiled versions for 68020+,
266 * fpu etc.
268 * - Implemented the IGNOREERRORS switch, which attempts to ignore any
269 * error during loading.
271 * - Removed some dead code.
273 * V1.6
274 * The datatypes supports now scaling and sound. Sound was implemented
275 * for two reasons:
276 * 1. For those streams which are distributed with a matching sound
277 * file.
278 * 2. I'm reworking mpegsystem.datatype (which can play system streams,
279 * e.g. video with interleaved audio). The goal is to implement
280 * mpegsystem.datatype as a subclass of mpegvideo.datatype. The
281 * audio stream will be parsed using mpegaudio.datatype.
282 * Note that mpegvideo.datatype is still a GID_ANIMATION type datatype.
283 * The GID_#? idetifiers belongs to the source data, not the
284 * modifications done by a datatype code (a mpeg 1 video stream does
285 * not contain any audio information, the sound is attached later).
287 * - Implemented the WIDTH and HEIGHT options in the prefs file to
288 * support scaling.
290 * - Implemented SAMPLE and VOLUME options to support sound.
292 * - Now uses BestModeID for selecting the screen mode of the
293 * animation. The MODEID preference option overides this.
294 * The old behavior was to set the ADTA_ModeID attribute only if the
295 * MODEID prefs option was set, otherwise the default from
296 * animation.datatype was taken (which was everytimes 0).
298 * - Fixed the FPS preference option. If it was set, the value was got
299 * from the depth option instead using the given value.
301 * - Implemented a processing gauge as requested by Allan Odgaard
302 * (Duff@DK-Online.DK) and many other people. The matching
303 * NOPROGRESSGAUGE switch disables it. If the input filehandle is a
304 * pipe, the gauge may not work properly.
306 * - Implemented a lowermem limit (MINTOTALMEM option) for those
307 * people who wants to see at least the beginning of a big anim
308 * (idea by Allan Odgaard (Duff@DK-Online.DK)).
310 * - Implemented multi-line preferences, supports comments and
311 * per-project settings (MATCHPROJECT option). The old preference
312 * files/vars are compatible.
314 * - The stack size for the OM_NEW method is now checked. If the
315 * required size (curretly 12kb) isn't available, a requester will
316 * notify the user and the method returns an error.
318 * V1.7
319 * - Recompiled with SAS/C 6.57. Switched the peephole optimizer on
320 * (see V1.4 bugs).
322 * - Rewrote the DICECOLOR dithering/remapping code. The DICECOLOR
323 * color mode now creates a colormap per frame (animation.datatype
324 * 40.7 does not support these colormap changes per frame (it's
325 * output looks like a color trash). Custom animation players which
326 * uses animation.datatype subclasses for loading (like my
327 * DBufDTAnim) don't have this problem. animation.datatype V41 will
328 * support these colormaps-per-frame.
330 * I changed the algorithm from a single-pass into a multi-pass
331 * operation, which allows the code to run on other output modes
332 * like ORDERED or FS (Floyd-Steinberg). A side-effect of this
333 * change is that options like COLORERROR and DICESKIP are selected
334 * automatically, which is more user-friendly.
336 * If you want to get the old DICECOLOR output, use
337 * DITHER=COLOR PALETTEPERFRAME options.
339 * - The mpegvideo.datatype uses 24 bit-colors internally and
340 * writes 32 bits per (r,b,g) gun. Now the high order bits of each
341 * color gun are replicated through the whole INT32.
343 * - Fixed a bug in the SAMPLE option, which caused possible crashes.
345 * - Fixed a bug in LibExpunge (didn't check lib_OpenCnt), which is
346 * also present in all my other external BOOSI classes (and
347 * datatypes).
348 * Thanks to Guenter Niki (gniki@informatik.uni-rostok.de) for
349 * reporting this bug.
351 * - Implemented the mpeg saving code (mpeg encoder). Currently,
352 * only mpeg-1 streams are written out.
353 * (Will be enabled in the public versions ONLY upon request;
354 * code is currently under construction).
356 * - Increased the stack requirements from 12kb up to 16kb, mainly
357 * to allow more recursive operations.
359 * - Implemented random access to frames (e.g you need not to load
360 * the whole animation, decoding is done on the fly).
361 * (Will be enabled in the public versions ONLY upon request;
362 * code is currently under construction,
363 * the matching LOADALL switch it set everytimes).
365 * V1.8
366 * - Added partial support for mpeg-2 (MPEG-2 does NOT work yet !),
367 * both encoder+decoder.
369 * - Added my own WritePixelArray8 replacement, which operates
370 * directly on the fast-mem bitmaps. This saves some internal
371 * copies, chipmem buffer for WPA8 etc.
373 * - Added my own scaling routine, replacing
374 * graphics.library/BitMapScale (which needs chipmem as temp.
375 * buffer).
376 * Does not work properly yet.
378 * - Fixed the gauge, which didn't work correctly with large streams
379 * (>= 8MB).
380 * Fixed.
382 * - The gauge ha now a text info, which shows the remaining time
383 * to decode.
385 * - Added experimental stack swapping code. The "Need more stack"-
386 * requester has been removed for this reason.
388 * This also fixes a possible deadlock of "input.device" because
389 * the GM_LAYOUT method was running with low stack.
390 * Fixed.
392 * - Color table setup now retries color table build with an increased
393 * COLORERROR if table (set by LUM_RANGE * CR_RANGE * CB_RANGE) does
394 * not fit. This allows any #?_RANGE value.
396 * - Fixed different problems within color setup. Now this should
397 * work with a higher quality, and a little bit faster.
399 * - Fixed the descriptor, which din't match all mpeg video streams.
400 * Fixed.
402 * - DTM_WRITE should return ERROR_NOT_IMPLEMENTED if DTWM_RAW mode is
403 * requested (becuase the encoder has been disabled, e.g. commented
404 * out). Now this is correctly done.
405 * Fixed.
407 * - The mc68060-Version now checks for the AFF_68060 (1L<<7) execbase
408 * flag instead using the AFF_68040.
409 * Fixed.
411 * - Added QUALITY prefs option and matching float-dct code.
413 * V1.9
414 * - Recompiled with SAS/C 6.58. Should fix some mc68060 related
415 * problems.
417 * - Minor and major housekeeping changes.
419 * - Added HAM code and HAM dither option as requested by many people.
420 * Thanks to Olaf Barthel for his fast HAM conversion code.
422 * - DTA_ObjName is now set (and equals to DTA_Name).
424 * - GM_LAYOUT/DTM_PROCLAYOUT code has been removed because
425 * animation.datatype class does the same.
427 * - Removed NOREMAP switch (and matching DTM_FRAMEBOX code) because
428 * this was an ugly hack. After all, it seems that MuliView
429 * sets ADTA_Remap to FALSE on it's custom screens, and that
430 * using ADTA_Remap == FALSE on a screen which does not have the
431 * matching size may cause trouble.
433 * - ADTA_NumColors is now set to the number of used colors instead
434 * of 1UL << anim_depth. This saves some pens when allocating
435 * shared pens on shared screens.
436 * When palette-per-frames are used, the number of colors equals to
437 * 1UL << anim_depth again.
439 * - Moved scaling code before dithering code. It now scales the lum,
440 * cr, cb data, which is more usefull when doing ordered or HAM
441 * dithering.
443 * - VMM support seems to be safe...
445 * - Changed the whole prefs-system. Now the defaults options are more
446 * usefull and are adapted correctly to some settings.
448 * - DITHER option now defaults to HAM, for those people who don't
449 * like to edit the prefs-file.
451 * - Added NOPALETTEPERFRAME/S, PFRAMES/S, BFRAMES/S, NOLOADALL/S,
452 * PROGRESSGAUGE/S, NOQUALITY/S switches to support multi-line
453 * prefs-files which uses the MATCHPROJECT feature.
455 * - Internal timing now uses animation.datatype V41
456 * ADTA_TicksPerFrame instead of ADTA_FramesPerSecond. This
457 * makes timing more precise.
458 * (ADTA_TicksPerFrame means 1200 / fps, based on realtime.library's
459 * timing model).
461 * - Increased the decoding the speed a little bit. But this may affect
462 * stability if someone feeds a corrupt mpeg file in the datatype.
463 * I try to fix the problem...
465 * - Now uses Peter McGavin's (p.mcgavin@irl.cri.nz) WritePixelArray8
466 * code (the C version).
468 * - Fixed the encoder stack problem.
470 * - The encoder now has no problems with dynamic frame delays (e.g.
471 * alf_Duration field in adtFrame).
473 * - The SKIP option now uses struct adtFrame -> alf_Duration instead
474 * of creating empty frames. This causes that the SKIPFRAMES option
475 * works only with animation.datatype V41.
477 * - Fixed the bug that the last sample might be too long, which
478 * caused unallocated memory reads (but only a few bytes) and small
479 * clicks at the end of the animation.
481 * - The startup-code has been rewritten, the code now gurantees that
482 * the order of OpenLibrary and CloseLibrary are correct and in a
483 * more usefull order.
485 * - Updated the autodoc a little bit.
487 * V1.10
488 * INTERNAL RELEASE
490 * - Large code cleanup.
492 * - If we reach the file end, we now add a end of sequence code
493 * manually to avoid any problems if we does not see the end code
494 * (this occurs in the NOLOADALL mode in the past...).
496 * - Removed all remaining parts of "recmpeg". Now I'm allowed to
497 * release the source :-)
499 * - Moved the encoder to the mpegvideo.datatype V2.
501 * - Moved the YUV -> 24-bit interleaved-planar to
502 * mpegvideo.datatype V2.
504 * - Removed the whole MPEG-2 support. mpegvideo.datatype V2 does this
505 * better.
507 * - Wrote a replacement for the 24 bit planar code (currently
508 * non-interleaved).
510 * - Rewrote the 24/15/16 bit dither code.
511 * Should fix some visual problems.
513 * - Fixed the bug that animation.datatype V41 wasn't detected
514 * correctly (the version check didn't match, therefore
515 * any V41 related features were not used).
516 * Fixed.
518 * - Added GAMMACORRECT and CHROMACORRECT options.
520 * - Removed BestModeIDA code because animation.datatype does the
521 * same job (better).
523 * - Fixed the bug that MODEID=0 turns the internal mode selection
524 * on instead of using LORES.
525 * This also requires a change in the prefs behaviour, the
526 * default value for the MODEID option is now "-1".
527 * Fixed.
529 * - Removed all internal accesses to ADTA_BitMapHeader because they
530 * are unneccesary (dead code).
532 * - The VERBOSE output is now turned on if a serious error occurs.
534 * - If frames are skipped (using the NOPFRAMES or NOBFRAMES option)
535 * now the duration of the last frame is increased to get sync
536 * with the stream time.
538 * - Fixed the bug that the total number of frames might be incorrect
539 * in rare cases.
540 * Fixed.
542 * - Fixed a bug in the color setup of ORDERED dithering which
543 * caused that the values runned from 0 upto 256 (256 == 0 in an
544 * UBYTE). Now the color values are correctly running from 0-255.
545 * Fixed.
547 * Fixed the same bug in GRAY dither setup.
548 * Fixed.
550 * V1.11
551 * - Enabled the NOLOADALL mode for the public.
553 * - Small code cleanup to remove some unneccesary parts of code
554 * (mainly the obsolete encoder support).
556 * - Fixed the bug that the depth of a CyberGFX ARGB bitmap must be 32
557 * instead of 24.
558 * Fixed.
560 * - Added some safety in CyerGFX LockBitMap handling (which has a bug
561 * in tag parsing).
563 * - Added workaround for NOLOADALL mode that ADTM_LOADFRAME returns
564 * 1UL instead of NULL if it forgets a frame (to avoid that the
565 * playback stops...).
566 * Not nice...
568 * - Fixed a bug in 24bit -> HAM dithering introduced in V1.10.
569 * Fixed.
571 * - Replaced stack swapping code by a "standard module".
573 * - Increased the "default" buffer size from 4096 up to 16384.
574 * This makes the gauge less accurate for small streams, but
575 * gives a small speedup when parsing large streams.
577 * SEE ALSO
578 * animation.datatype,
579 * mpegsystem.datatype, mpegvideo.datatype
580 * picmovie.datatype,
581 * paranimdtcpatch
583 *******************************************************************************
589 /*****************************************************************************/
591 DISPATCHERFLAGS
592 struct IClass *ObtainMPEGVideoEngine( REGA6 struct ClassBase *classbase )
594 return( (classbase -> cb_Lib . cl_Class) );
597 /*****************************************************************************/
599 #if !defined(__AROS__)
600 DISPATCHERFLAGS
601 struct Library *LibInit( REGD0 struct ClassBase *classbase, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
603 #ifdef USEIEEELIB
604 extern struct Library *MathIeeeDoubBasBase;
605 #endif /* USEIEEELIB */
607 classbase -> cb_SegList = seglist;
608 classbase -> cb_SysBase = sysbase;
609 #else
610 /* Open superclass */
611 ADD2LIBS("datatypes/animation.datatype", 0, struct Library *, AnimationBase);
613 static int LibInit(struct ClassBase *classbase)
615 bug("[mpegvideo.datatype] %s()\n", __PRETTY_FUNCTION__);
616 #endif
618 InitSemaphore( (&(classbase -> cb_Lock)) );
620 #if !defined(__AROS__)
621 #ifdef REQUIREDAFF
622 /* Check if the requested cpu/fpu is available*/
623 if( ((classbase -> cb_SysBase -> AttnFlags) | REQUIREDAFF) != (classbase -> cb_SysBase -> AttnFlags) )
625 return( NULL );
627 #endif /* REQUIREDAFF */
629 /* Requires at least Kick 3.0 */
630 if( (classbase -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
632 /* Obtain ROM libs */
633 if( classbase -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
635 #undef GfxBase
636 if( classbase -> cb_GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 39UL ) )
638 classbase -> cb_CyberGfxBase = OpenLibrary( CYBERGFXNAME, CYBERGFXVERSION );
640 if( classbase -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
642 if( classbase -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
644 #ifdef USEIEEELIB
645 if( MathIeeeDoubBasBase = OpenLibrary( "mathieeedoubbas.library", 38UL ) )
647 #endif /* USEIEEELIB */
648 /* vmm.library will be opened on demand (see dispatch.c) */
649 classbase -> cb_VMMBase = NULL;
651 return( (&(classbase -> cb_Lib . cl_Lib)) );
653 #ifdef COMMENTED_OUT
654 CloseLibrary( MathIeeeDoubBasBase );
655 #endif /* COMMENTED_OUT */
657 #ifdef USEIEEELIB
660 CloseLibrary( (classbase -> cb_DOSBase) );
661 #endif /* USEIEEELIB */
664 CloseLibrary( (classbase -> cb_IntuitionBase) );
667 CloseLibrary( (classbase -> cb_CyberGfxBase) );
668 CloseLibrary( (&(classbase -> cb_GfxBase -> LibNode)) );
671 CloseLibrary( (classbase -> cb_UtilityBase) );
675 return( NULL );
676 #else
677 return TRUE;
678 #endif
681 /*****************************************************************************/
683 #if !defined(__AROS__)
684 DISPATCHERFLAGS
685 LONG LibOpen( REGA6 struct ClassBase *classbase )
687 LONG retval = (LONG)classbase;
688 BOOL success = TRUE;
690 ObtainSemaphore( (&(classbase -> cb_Lock)) );
692 /* Use an internal use counter */
693 classbase -> cb_Lib . cl_Lib . lib_OpenCnt++;
694 classbase -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
696 if( (classbase -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
698 if( (classbase -> cb_Lib . cl_Class) == NULL )
700 success = FALSE;
702 if( classbase -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
704 if( classbase -> cb_SuperClassBase = OpenLibrary( "datatypes/animation.datatype", 39UL ) )
706 if( classbase -> cb_Lib . cl_Class = initClass( classbase ) )
708 success = TRUE;
715 if( !success )
717 CloseLibrary( (classbase -> cb_SuperClassBase) );
718 CloseLibrary( (classbase -> cb_DataTypesBase) );
720 classbase -> cb_DataTypesBase = classbase -> cb_SuperClassBase = NULL;
722 (classbase -> cb_Lib . cl_Lib . lib_OpenCnt)--;
724 retval = 0L;
727 ReleaseSemaphore( (&(classbase -> cb_Lock)) );
729 return( retval );
732 /*****************************************************************************/
734 DISPATCHERFLAGS
735 LONG LibClose( REGA6 struct ClassBase *classbase )
737 LONG retval = 0L;
739 ObtainSemaphore( (&(classbase -> cb_Lock)) );
741 if( classbase -> cb_Lib . cl_Lib . lib_OpenCnt )
743 (classbase -> cb_Lib . cl_Lib . lib_OpenCnt)--;
746 if( ((classbase -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (classbase -> cb_Lib . cl_Class) )
748 if( FreeClass( (classbase -> cb_Lib . cl_Class) ) )
750 classbase -> cb_Lib . cl_Class = NULL;
752 CloseLibrary( (classbase -> cb_SuperClassBase) );
753 CloseLibrary( (classbase -> cb_DataTypesBase) );
755 else
757 classbase -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
761 ReleaseSemaphore( (&(classbase -> cb_Lock)) );
763 if( (classbase -> cb_Lib . cl_Lib . lib_Flags) & LIBF_DELEXP )
765 retval = LibExpunge( classbase );
768 return( retval );
771 /*****************************************************************************/
773 DISPATCHERFLAGS
774 LONG LibExpunge( REGA6 struct ClassBase *classbase )
776 BPTR seg;
777 #ifdef USEIEEELIB
778 extern struct Library *MathIeeeDoubBasBase;
779 #endif /* USEIEEELIB */
781 if( classbase -> cb_Lib . cl_Lib . lib_OpenCnt )
783 classbase -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
785 seg = NULL;
787 else
789 Remove( (&(classbase -> cb_Lib . cl_Lib . lib_Node)) );
791 seg = classbase -> cb_SegList;
793 CloseLibrary( (classbase -> cb_VMMBase) );
794 #ifdef USEIEEELIB
795 CloseLibrary( MathIeeeDoubBasBase );
796 #endif /* USEIEEELIB */
797 CloseLibrary( (classbase -> cb_DOSBase) );
798 CloseLibrary( (classbase -> cb_IntuitionBase) );
799 CloseLibrary( (classbase -> cb_CyberGfxBase) );
800 CloseLibrary( (&(classbase -> cb_GfxBase -> LibNode)) );
801 CloseLibrary( (classbase -> cb_UtilityBase) );
803 FreeMem( (APTR)((ULONG)(classbase) - (ULONG)(classbase -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((classbase -> cb_Lib . cl_Lib . lib_NegSize) + (classbase -> cb_Lib . cl_Lib . lib_PosSize)) );
806 return( (LONG)seg );
808 #else
809 ADD2INITLIB(LibInit, 0);
810 #endif