/* $Id$
*/
#include <intuition/IntuitionBase.h>
#include <graphics/GfxBase.h>
#include <exec/memory.h>
#include <dos/dos.h>

#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/macros.h>

#include <stdlib.h>

#include <libraries/iff.h>

char *MYLIBNAME="iff.library";

extern struct IntuitionBase *IntuitionBase;
extern struct Library *IFFBase;

struct picdata {
    struct BitMap *bitmap;
    ULONG *colortable;
    };

void
SavePicture(Object *Picture,const STRPTR FileName)
{
   struct picdata *data=(struct picdata *)Picture;

   if (!IFFL_SaveBitMap(FileName,data->bitmap,(WORD *)data->colortable,1)) {
       printf("Error On Saving");
       }
   }

Object *
GetPicture(BOOL scr)
{
    struct picdata *data=(struct picdata *)malloc(sizeof(struct picdata));
    ULONG IntuiLock;
    struct Window *Window;
    BOOL Locked=TRUE;
    struct Screen *Screen;
    LONG NumColours;

    IntuiLock=LockIBase(NULL);

    if(!scr) {
        Window = IntuitionBase -> ActiveWindow;

        data->bitmap=Window->RPort->BitMap;
        }
    else {
        Screen = IntuitionBase -> ActiveScreen;

        data->bitmap=Screen->RastPort.BitMap;
        }

    NumColours = ((scr)?(Screen -> ViewPort . ColorMap -> Count):(Window -> WScreen -> ViewPort . ColorMap -> Count));

    if(data->colortable=(ULONG *)malloc(sizeof(ULONG)*3*NumColours)) {

         GetRGB32(((scr)?(Screen -> ViewPort . ColorMap):(Window -> WScreen -> ViewPort . ColorMap)),0,NumColours,
         data->colortable);

         UnlockIBase(IntuiLock);

         Locked=FALSE;

         return((Object *)data);
         }
    }






