home *** CD-ROM | disk | FTP | other *** search
- ; /*
-
- sc libcode parms=r streq constlib nostackcheck optimize opttime ignore=73 bitmap_library.c
- asm -m2 bitmap_chunky.s
- slink LIBFD bitmap.fd TO ///Libs/bitmap.library FROM LIB:libent.o LIB:libinit.o bitmap_library.o bitmap_chunky.o LIB lib:sc.lib libVersion 1 libRevision 4 libid "bitmap 1.4 (10.5.95) Copyright © 1994-1995 by Stefano Reksten" SC SD NOICONS STRIPDEBUG
- copy ///Libs/bitmap.library LIBS:
- delete bitmap_library.o
- delete bitmap_chunky.o
- quit
-
- bitmap.library 1.4
- Copyright © 1994-1995 Stefano Reksten of 3AM - The Three Amigos!!!
- All rights reserved.
-
- */
-
- #include <exec/memory.h>
- #include <exec/execbase.h>
- #include <intuition/intuition.h>
- #include <datatypes/pictureclass.h>
- #include <graphics/gfxbase.h>
-
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- /*#include <clib/graphics_protos.h>
- #include <pragma/graphics_pragmas.h>*/
- #include <proto/dos.h>
-
- #include "//include/bitmap/bitmap.h"
-
- struct GfxBase *GfxBase;
-
- int __saveds __asm __UserLibInit( register __a6 struct MyLibrary *libbase )
- {
- if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0L ) )
- return( 0 );
- else
- return( 1 );
- }
-
- void __saveds __asm __UserLibCleanup( register __a6 struct MyLibrary *libbase )
- {
- CloseLibrary( (struct Library *)GfxBase );
- }
-
-
- void __asm __saveds DisposeBitMap( register __a1 struct BitMap *bmap )
- {
- ULONG n;
- ULONG plane_size;
-
- if ( bmap )
- {
- if ( GfxBase->LibNode.lib_Version >= 39 )
- FreeBitMap( bmap );
- else
- {
- plane_size = bmap->BytesPerRow * bmap->Rows;
-
- for ( n = 0; n < bmap->Depth; n++ )
- {
- if ( bmap->Planes[n] )
- FreeMem( bmap->Planes[n], plane_size );
- }
- FreeMem( bmap, sizeof(struct BitMap) );
- }
- }
- }
-
-
- struct BitMap * __asm __saveds CreateBitMap( register __d0 UWORD width, register __d1 UWORD height, register __d2 UBYTE nPlanes )
- {
- register struct BitMap *bmap;
- ULONG plane_size = RASSIZE( width, height );
- PLANEPTR planeptr;
- ULONG n;
-
- if ( GfxBase->LibNode.lib_Version >= 39 )
- return AllocBitMap( width, height, nPlanes, BMF_CLEAR | BMF_STANDARD | BMF_DISPLAYABLE, NULL );
- else
- {
- if ( bmap = AllocMem( sizeof(struct BitMap), MEMF_CLEAR ) )
- {
- InitBitMap( bmap, nPlanes, width, height );
-
- for ( n = 0; n < nPlanes; n++ )
- {
- if ( !( planeptr = (PLANEPTR)AllocMem( plane_size, MEMF_CHIP|MEMF_CLEAR ) ) )
- goto warn;
- bmap->Planes[n] = planeptr;
- }
- return ( bmap );
- }
- warn:
- DisposeBitMap( bmap );
- return( 0L );
- }
- }
-
- /**************
- * *
- * ScaleBitMap *
- * *
- **************/
-
-
- BOOL __asm __saveds ScaleBitMap( register __a1 struct BitMapScaleInfo *scaleinfo )
- {
- register UWORD StillToGo, CurrentDest, DestXBytes, DestYBytes;
- register struct BitMap *TempBitMap;
-
- if ( !scaleinfo->bsi_HorDen || !scaleinfo->bsi_VertDen || !scaleinfo->bsi_HorNum || !scaleinfo->bsi_VertNum )
- return( FALSE );
-
- if ( !scaleinfo->bsi_TempBitMap )
- {
- if ( !( TempBitMap = CreateBitMap(
- (scaleinfo->bsi_Width + scaleinfo->bsi_HorDen - 1) * scaleinfo->bsi_HorNum / scaleinfo->bsi_HorDen,
- scaleinfo->bsi_Height,
- scaleinfo->bsi_SrcBitMap->Depth ) ) ) return( FALSE );
- }
- else
- TempBitMap = scaleinfo->bsi_TempBitMap;
-
- DestXBytes = scaleinfo->bsi_Width * scaleinfo->bsi_HorNum / scaleinfo->bsi_HorDen;
- DestYBytes = scaleinfo->bsi_Height * scaleinfo->bsi_VertNum / scaleinfo->bsi_VertDen;
-
- /* Let's start with columns. */
-
- CurrentDest = 0;
-
- if ( scaleinfo->bsi_Flags & BSIF_INVERTHOR )
- for ( StillToGo = 0; StillToGo < DestXBytes; StillToGo++ )
- BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge + ( ( DestXBytes - StillToGo - 1 ) * scaleinfo->bsi_HorDen / scaleinfo->bsi_HorNum ), scaleinfo->bsi_SrcTopEdge,
- TempBitMap, CurrentDest++, 0,
- 1, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
- else
- {
- if ( scaleinfo->bsi_HorNum == 1 && scaleinfo->bsi_HorDen == 1 )
- BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge, scaleinfo->bsi_SrcTopEdge,
- TempBitMap, 0, 0,
- scaleinfo->bsi_Width, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
- else
- {
- for ( StillToGo = 0; StillToGo < DestXBytes; StillToGo++ )
- BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge + ( StillToGo * scaleinfo->bsi_HorDen / scaleinfo->bsi_HorNum ), scaleinfo->bsi_SrcTopEdge,
- TempBitMap, CurrentDest++, 0,
- 1, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
- }
- }
-
- /* Now, go for the rows. */
-
- CurrentDest = scaleinfo->bsi_DestTopEdge;
-
- if ( scaleinfo->bsi_Flags & BSIF_INVERTVERT )
- for ( StillToGo = 0; StillToGo < DestYBytes; StillToGo++ )
- BltBitMap( TempBitMap, 0, scaleinfo->bsi_SrcTopEdge + ( ( DestYBytes - StillToGo - 1 ) * scaleinfo->bsi_VertDen / scaleinfo->bsi_VertNum ),
- scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, CurrentDest++,
- DestXBytes, 1, 0xC0, 0xFF, NULL );
- else
- {
- if ( scaleinfo->bsi_VertNum == 1 && scaleinfo->bsi_VertDen == 1 )
- BltBitMap( TempBitMap, 0, 0,
- scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, scaleinfo->bsi_DestTopEdge,
- DestXBytes, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
- else
- {
- for ( StillToGo = 0; StillToGo < DestYBytes; StillToGo++ )
- BltBitMap( TempBitMap, 0, StillToGo * scaleinfo->bsi_VertDen / scaleinfo->bsi_VertNum,
- scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, CurrentDest++,
- DestXBytes, 1, 0xC0, 0xFF, NULL );
- }
- }
-
- if ( scaleinfo->bsi_TempBitMap == 0 )
- DisposeBitMap( TempBitMap );
-
- return( TRUE );
- }
-