home *** CD-ROM | disk | FTP | other *** search
-
- /*
- **
- ** $VER: classbase.c 1.3 (9.11.97)
- ** acbm.datatype 1.3
- **
- ** Library routines for a DataTypes class
- **
- ** Written 1996/97 by Roland 'Gizzy' Mainz
- ** Original example source from David N. Junod
- **
- */
-
-
- /* main includes */
- #include "classbase.h"
-
- /****** acbm.datatype/MAIN ***************************************************
- *
- * INTRODUCTION
- * Datatypes class for IFF ACBM pictures. Based on the CBM datatypes
- * example source/ documents written by David Junod and the AmigaBasic
- * ACBM tools
- *
- * REQUIREMENTS
- * - You need at least Kick/WB 3.0.
- *
- * - "datatypes/picture.datatype", >= V39.
- *
- * USAGE
- * If the datatypes descriptor file was activated, any attempt to load
- * an IFF ACBM picture using GMultiView, MultiView, AmigaGuide or
- * SwitchWindow will load and view the picture.
- *
- * acbm.datatype supports also the clipboard as input, e.g.
- * "MultiView CLIPBOARD", ClipView or SwitchWindow are able to show
- * IFF ACBMs from clipboard.
- *
- * If you want to save the current picture in acbm.datatype's local
- * format, use MultiView's "Project/Save As..." menu (or GMultiView's
- * "Project/Save As Raw...").
- * acbm.datatype saves then the current picture.
- *
- * INSTALLATION
- * After unpacking this archive:
- * Because this version does not include an Installer script, you have
- * to do the installation manually through the shell:
- *
- * - Unpack this archive and copy the "acbm.datatype" to
- * SYS:Classes/DataTypes:
- *
- * Copy CLONE FROM "acbm.datatype" TO "SYS:Classes/DataTypes/acbm.datatype"
- *
- * - Then copy the datatypes descriptor into the DEVS:DataTypes
- * directory.
- * If the descriptor already exists, you should not replace it,
- * otherwise you may loose "toolnodes" and other settings stored in
- * the existing descriptor.
- *
- * Copy CLONE FROM "ACBM(%|.info)" TO DEVS:Datatypes/
- *
- * SOURCE
- * This is the official datatypes.library V45 reference implementation
- * of a picture.datatype subclass which supports saving in it's local
- * format (such an encoder is used by "DTConvert" and other tools which
- * uses DataTypes for conversion, e.g. DataType -> DataType (e.g. GIF
- * -> IFF ACBM etc.)).
- *
- * Source is fully included here.
- *
- * AUTHOR
- * If you want to blame me, report any bugs, or wants a new version
- * send your letter to:
- * Roland Mainz
- * Hohenstaufenstraße 8
- * 52388 Nörvenich
- * GERMANY
- *
- * Phone: (+49)(0)2426/901568
- * Fax: (+49)(0)2426/901569
- *
- * EMAIL is also available (if you want to send me attachments
- * larger than 1MB (up to 5MB, more with my permission):
- *
- * GISBURN@w-specht.rhein-ruhr.de
- *
- * Up to December 1997 I'm reachable using this email address, too:
- * Reinhold.A.Mainz@KBV.DE
- *
- * | Please put your name and address in your mails !
- * | German mailers should add their phone numbers.
- * | See BUGS section above when submitting bug reports.
- *
- * Sorry, but I can only look once a week for mails.
- * If you don't hear something from me within three weeks, please
- * send your mail again (but watch about new releases) (problems with
- * this email port are caused by reconfigurations, hackers, network
- * problems etc.).
- *
- * The entire "acbm.datatype" package may be noncommercially
- * redistributed, provided that the package is always distributed
- * in it's complete form (including it's documentation). A small
- * copy fee for media costs is okay but any kind of commercial
- * distribution is strictly forbidden without my permission !
- * Comments and suggestions how to improve this program are
- * generally appreciated!
- *
- * Thanks to David Junod, who wrote the datatypes environment and lots
- * of the datatypes example code, Carolyn Scheppner and other people
- * for their file formats, Matt Dillon for his DICE, Olaf 'Olsen'
- * Barthel for his help, ideas and some text clips from his
- * documentations.
- *
- ******************************************************************************
- *
- */
-
-
- /****** acbm.datatype/--datasheed-- ******************************************
- *
- * NAME
- * acbm.datatype -- data type for IFF ACBM pictures
- *
- * SUPERCLASS
- * picture.datatype
- *
- * DESCRIPTION
- * The acbm datatype, a sub-class of the picture.datatype, is
- * used to load and save IFF ACBM pictures.
- *
- * This class is offloaded from the datatypes.library V45 example code
- * and is the reference implementation of a picture.datatype subclass
- * (using V42 API) which supports saving in it's local format (as used
- * by converters like "DTConvert").
- *
- * METHODS
- * OM_NEW -- Create a new picture object from a description file. The
- * source may be a file or a clipboard unit. An empty object
- * (using DTST_RAM) may also be created.
- *
- * OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
- * method will be executed like OM_SET downstairs.
- *
- * OM_SET -- Pass msg to superclass and call GM_RENDER if retval from
- * superclass was != 0UL.
- *
- * DTM_WRITE -- Save data in local (IFF ACBM) or superclass (IFF ILBM)
- * format.
- *
- * All other methods are passed unchanged to superclass.
- *
- * ATTRIBUTES
- * Following attributes are set by the object and are READ-ONLY for
- * applications (if the datatype is used for saving (e.g. the
- * application creates an empty acbm.datatype object and fills
- * in some required attributes as shown in the "DTConvert" example),
- * these attributes are used by the encoder to create an IFF ACBM
- * picture file):
- *
- * DTA_ObjName -- Set by an IFF NAME chunk. If missing,
- * DTA_ObjName will take DTA_Name's value.
- * DTA_ObjAuthor -- Set by an IFF AUTH chunk.
- * DTA_ObjAnnotation -- Set by an IFF ANNO chunk.
- * DTA_ObjCopyright -- Set by an IFF (C) chunk.
- * DTA_ObjVersion -- Set by an IFF FVER chunk.
- * DTA_NominalHoriz -- Same as PDTA_BitMapHeader -> bmh_Width
- * DTA_NominalVert -- Same as PDTA_BitMapHeader -> bmh_Height
- * PDTA_BitMapHeader -- Filled by the IFF ILBM BMHD chunk
- * PDTA_ModeID -- Set by an IFF ILBM/ACBM CAMG chunk. If missing
- * or the value here is 0, the datatype will
- * select a value based on BMHD information.
- * PDTA_NumColors -- Set by IFF ILBM/ACBM CMAP chunk
- * PDTA_ColorRegisters -- Set by IFF ILBM/ACBM CMAP chunk
- * PDTA_CRegs -- Set by IFF ILBM/ACBM CMAP chunk
- * PDTA_BitMap -- The image itself, created from IFF ACBM ABIT
- * chunk and some IFF ILBM/ACBM BMHD infos.
- *
- * BUGS
- * - ModeID selecttion does not support SUPERHIRES.
- *
- * - Images deeper than 8 planes are not fully supported yet; a colormap
- * is everytimes expected.
- *
- * TODO
- * - Fixing the bugs above.
- *
- * - Add GRAB support (e.g. IFF ILBM GRAB chunk and matching PDTA_Grab
- * chunk).
- *
- * - Add support for non-planar 8 bit deep bitmaps in the encoder.
- *
- * HISTORY
- * V1.1
- * First public release.
- *
- * V1.2
- * - Recompiled with SAS/C 6.58. Should fix some mc68060 related
- * problems.
- *
- * - Added 020, 040, 060 versions and the matching makefile to show
- * how to do this correctly (e.g. no mc68040 version attempts to run
- * on a plane mc68000, it rejects opening it silently instead of
- * crashing).
- *
- * - Moved BOOPSI class definitions to "classdata.h".
- *
- * - Added example "what to do" when no encoder is implemented
- * (e.g. returns result == 0 and result2 == ERROR_NOT_IMPLEMENTED)
- * if complied with the NO_ENCODER switch.
- *
- * - Moved "iffparse.library"'s OpenLibrary and CloseLibrary from
- * LibInit to LibOpen to handle it more dynamically...
- *
- * - Added missing ObtainSemaphoreShared/ReleaseSemaphore locking to
- * the encoder part.
- *
- * - Fixed the bug that on rare conditions (error after the bitmap has
- * been loaded) wasn't freed.
- * Fixed.
- *
- * - Improved iffparse.library handling; more speed and corrected
- * error handling.
- *
- * - Updates docs and source comments a little bit
- *
- * - Fixed the bug that some generic IFF chunks were not loaded
- * (like NAME, FVER, AUTH, (C) etc.).
- * Fixed.
- *
- * - The stack swapping code now allocates it's memory without the
- * MEMF_CLEAR bit which results in a small speedup.
- *
- * - Replaced BestModeIDA code by a simple flag setting code.
- * picture.datatype does BestModeIDA if the requested mode does
- * not exist.
- *
- * - Now allocates the bitmap with the BMF_MINPLANES flag set. Now
- * the datatype supports deeper images, but a colormap is still
- * expected.
- *
- * - Added missing MAIN section in the autodoc.
- *
- * V1.3
- * - Replaced stack swapping code by my "standard" module
- *
- * - Improved the "smakefile" a little bit
- *
- * - Minor code changes
- *
- * SEE ALSO
- * picture.datatype
- *
- *******************************************************************************
- *
- */
-
-
- /****** acbm.datatype/--input_format-- ****************************************
- *
- * NAME
- * IFF ACBM -- Amiga Contiguous BitMap
- *
- * DESCRIPTION
- * FORM ACBM has the same format as FORM ILBM except the normal BODY
- * chunk (Interleaved Bitmap) is replaced by an ABIT chunk (Amiga
- * BITplanes).
- *
- * The ABIT chunk contains continous bitplane data. The chunk contains
- * sequential data fro planes 0 through plane i.
- *
- * SEE ALSO
- * - ARKM Devices: IFF part
- *
- * - iffparse.library autodocs
- *
- * - AmigaBasic LoadACBM/SaveACBM
- *
- * THANKS TO
- * Carolyn Scheppner (CBM) for creating this format
- *
- *******************************************************************************
- *
- */
-
-
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- struct IClass *ObtainACBMEngine( REGA6 struct ClassBase *cb )
- {
- return( (cb -> cb_Lib . cl_Class) );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
- {
- cb -> cb_SegList = seglist;
- cb -> cb_SysBase = sysbase;
-
- InitSemaphore( (&(cb -> cb_Lock)) );
-
- #ifdef REQUIREDAFF
- /* Check if the requested cpu/fpu is available */
- if( ((sysbase -> AttnFlags) | REQUIREDAFF) != (sysbase -> AttnFlags) )
- {
- return( NULL );
- }
- #endif /* REQUIREDAFF */
-
- if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
- {
- /* Obtain ROM libs */
- if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
- {
- if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
- {
- if( cb -> cb_GfxBase = OpenLibrary( "graphics.library", 39UL ) )
- {
- if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
- {
- return( (&(cb -> cb_Lib . cl_Lib)) );
-
- #ifdef COMMENTED_OUT
- CloseLibrary( IntuitionBase );
- #endif /* COMMENTED_OUT */
- }
-
- CloseLibrary( (cb -> cb_GfxBase) );
- }
-
- CloseLibrary( (cb -> cb_DOSBase) );
- }
-
- CloseLibrary( (cb -> cb_UtilityBase) );
- }
- }
-
- return( NULL );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibOpen( REGA6 struct ClassBase *cb )
- {
- LONG retval = (LONG)cb;
- BOOL success = TRUE;
-
- ObtainSemaphore( (&(cb -> cb_Lock)) );
-
- /* Use an internal use counter */
- cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
- cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
-
- if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
- {
- if( (cb -> cb_Lib . cl_Class) == NULL )
- {
- success = FALSE;
-
- if( cb -> cb_IFFParseBase = OpenLibrary( "iffparse.library", 39UL ) )
- {
- if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
- {
- if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/picture.datatype", 39UL ) )
- {
- if( cb -> cb_Lib . cl_Class = initClass( cb ) )
- {
- success = TRUE;
- }
- }
- }
- }
- }
- }
-
- if( !success )
- {
- CloseLibrary( (cb -> cb_SuperClassBase) );
- CloseLibrary( (cb -> cb_DataTypesBase) );
- CloseLibrary( (cb -> cb_IFFParseBase) );
-
- cb -> cb_IFFParseBase = cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
-
- (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
-
- retval = 0L;
- }
-
- ReleaseSemaphore( (&(cb -> cb_Lock)) );
-
- return( retval );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibClose( REGA6 struct ClassBase *cb )
- {
- LONG retval = 0L;
-
- ObtainSemaphore( (&(cb -> cb_Lock)) );
-
- if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
- {
- (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
- }
-
- if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
- {
- if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
- {
- cb -> cb_Lib . cl_Class = NULL;
-
- CloseLibrary( (cb -> cb_SuperClassBase) );
- CloseLibrary( (cb -> cb_DataTypesBase) );
- CloseLibrary( (cb -> cb_IFFParseBase) );
- }
- else
- {
- cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
- }
- }
-
- ReleaseSemaphore( (&(cb -> cb_Lock)) );
-
- if( cb -> cb_Lib . cl_Lib . lib_Flags & LIBF_DELEXP )
- {
- retval = LibExpunge( cb );
- }
-
- return( retval );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibExpunge( REGA6 struct ClassBase *cb )
- {
- BPTR seg;
-
- if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
- {
- cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
-
- seg = NULL;
- }
- else
- {
- Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
-
- seg = cb -> cb_SegList;
-
- CloseLibrary( (cb -> cb_IntuitionBase) );
- CloseLibrary( (cb -> cb_GfxBase) );
- CloseLibrary( (cb -> cb_DOSBase) );
- CloseLibrary( (cb -> cb_UtilityBase) );
-
- 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)) );
- }
-
- return( (LONG)seg );
- }
-
-
-
-
-