home *** CD-ROM | disk | FTP | other *** search
- #include "ImageBob.h"
- #include <intuition/intuition.h>
- #include <exec/memory.h>
- #include <stdlib.h>
- #include <string.h> /* added for memset() prototype -- EDB */
- #ifndef __GNUC__
- #include <clib/graphics_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/layers_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/layers.h>
- #endif
- #ifdef __SASC
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/layers.h>
- #endif
-
- #define ALLOCRASTER( w, h ) (WORD *)AllocRaster( w, h )
- #define WORDALIGN( n ) ( ( n + 15 ) & ~0x0F )
- /* rounds 'n' up to the nearest 16. */
-
-
- BOOL
- ImageBob_InitImage( struct Image *image,
- UWORD width,
- UWORD height,
- UWORD depth )
- {
- UWORD *image_mem;
- UWORD wa_width;
- UWORD i, planepick;
-
- /* Allocate memory for image. */
- wa_width = WORDALIGN( width );
-
- if( image_mem = (UWORD *)AllocRaster( width, height * depth ) )
- {
- /* clear the memory. */
- memset( image_mem, (char)0, ( wa_width/8 )* height * depth );
-
- /* initialize image. */
- image->LeftEdge = 0;
- image->TopEdge = 0;
- image->Width = width;
- image->Height = height;
- image->Depth = depth;
- image->ImageData = image_mem;
-
- for( i = 0, planepick = 0; i < depth; i++ )
- {
- planepick |= ( 1 << i );
- }
-
- image->PlanePick = planepick;
- image->PlaneOnOff = 0x00;
- image->NextImage = NULL;
-
- return TRUE;
- }
- return FALSE;
- }
-
-
- BOOL
- ImageBob_InitShadowMask( ImageBob *ibob )
- {
- struct Image image;
- UWORD wa_width;
-
- wa_width = WORDALIGN( ibob->Image.Width );
-
- /* Allocate memory for ShadowMask. */
- if( ibob->Bob.ImageShadow = ALLOCRASTER( wa_width,
- ibob->Image.Height ) )
- {
- /* printf( "Allocated Raster memory for ImageShadow.\n" ); */
-
- memset( ibob->Bob.ImageShadow, (char)0, ( wa_width/8 ) * ibob->Image.Height );
-
- /* cobble up a fake 'image' for the shadow port. */
-
- image = ibob->Image;
- image.Width = wa_width;
- image.Depth = 1;
- image.PlanePick = 1;
- image.ImageData = (UWORD *)ibob->Bob.ImageShadow;
-
- if( ClippedImageRastPort_Init( &ibob->ShadowPort, &image ) )
- {
- /* printf( "Initialized clipped shadowport.\n" ); */
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
-
-
- BOOL
- ImageBob_InitVSpriteBob( ImageBob *ibob )
- {
- UWORD wa_width;
-
- /* Initialize Sprite and Bob */
- wa_width = WORDALIGN( ibob->Image.Width );
-
- ibob->VSprite.Height = ibob->Image.Height;
- ibob->VSprite.Width = wa_width / 16;
- ibob->VSprite.Depth = ibob->Image.Depth;
- ibob->VSprite.ImageData = ibob->Image.ImageData;
- ibob->VSprite.VSBob = &ibob->Bob;
- ibob->VSprite.PlanePick = ibob->Image.PlanePick;
- ibob->VSprite.PlaneOnOff = ibob->Image.PlaneOnOff;
- ibob->VSprite.Flags = SAVEBACK | OVERLAY;
- ibob->Bob.BobVSprite = &ibob->VSprite;
- ibob->Bob.ImageShadow = NULL;
-
- /* Allocate Chip Memory for Save Buffer. */
- if( ibob->Bob.SaveBuffer = ALLOCRASTER( ibob->Image.Width,
- ibob->Image.Height * ibob->Image.Depth ) )
- {
- /* Create RastPorts for the Image and the Shadow. */
- if( ClippedImageRastPort_Init( &ibob->ImagePort, &ibob->Image ) )
- {
- if( ImageBob_InitShadowMask( ibob ) )
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
-
- BOOL
- ImageBob_Init( ImageBob *ibob,
- UWORD width,
- UWORD height,
- UWORD depth )
- {
- memset( ibob, 0, sizeof( ImageBob ) );
-
- if( ImageBob_InitImage( &ibob->Image, width, height, depth ) )
- {
- if( ImageBob_InitVSpriteBob( ibob ) )
- {
- return TRUE;
- }
- }
-
- ImageBob_CleanUp( ibob );
- return FALSE;
- }
-
- void
- ImageBob_CleanUpImage( struct Image *image )
- {
- if( image->ImageData )
- FreeRaster( (PLANEPTR) image->ImageData,
- image->Width, image->Height * image->Depth );
- image->ImageData = NULL;
- }
-
-
- void
- ImageBob_CleanUp( ImageBob *ibob )
- {
- USHORT width, height, depth;
-
- ClippedImageRastPort_CleanUp( &ibob->ImagePort );
- ClippedImageRastPort_CleanUp( &ibob->ShadowPort );
-
- ImageBob_CleanUpImage( &ibob->Image );
-
- width = ibob->Image.Width;
- height = ibob->Image.Height;
- depth = ibob->Image.Depth;
-
- if( ibob->Bob.SaveBuffer )
- FreeRaster( (PLANEPTR)ibob->Bob.SaveBuffer, width, height * depth );
-
- if( ibob->Bob.ImageShadow )
- FreeRaster( (PLANEPTR)ibob->Bob.ImageShadow, WORDALIGN( width ), height );
-
-
- memset( ibob, 0, sizeof( ImageBob ) );
-
- }
-
-