// MPImage - Amiga Image Conversion
// Copyright (C) © 1996 Mark John Paddock
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

// mark@topic.demon.co.uk
// mpaddock@cix.compulink.co.uk
#include <proto/datatypes.h>
#include <proto/graphics.h>
#include <proto/utility.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <graphics/scale.h>
#include <datatypes/pictureclass.h>
#include <graphics/view.h>
#include <intuition/gadgetclass.h>
#include <dos/dostags.h>

#include <egs/egs.h>
#include <egs/pragmas/egs_pragmas.h>
#include <egs/clib/egs_protos.h>

extern struct Library *EGSBase;

#include <libraries/dctv.h>
#include <clib/dctv_protos.h>
#include <pragmas/dctv_pragmas.h>

// dctv includes do not have tagcalls
#pragma tagcall DCTVBase AllocDCTVCvtTags 42 9802

extern struct Library *DCTVBase;

#ifdef CYBER
#include <cybergraphics/cybergraphics.h>
#include <clib/cybergraphics_protos.h>
#include <pragmas/cybergraphics_pragmas.h>

extern struct Library *CyberGfxBase;
#endif

extern char ErrorMessage[];

#define USE_BUILTIN_MATH
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef _M68881
#include <mffp.h>
#else
#include <m68881.h>
#endif

#include <clib/alib_protos.h>

#include "libraries/MPImage.h"

#include "iffp/iff.h"
#include "iffp/ilbm.h"
#include "iffp/ILBMApp.h"

extern long __oslibversion;

struct p2cStruct {
  struct BitMap *bmap;
  UWORD startX, startY, width, height;
  UBYTE *chunkybuffer;
};

static struct c2pStruct {
  struct BitMap *bmap;
  UWORD startX, startY, width, height;
  UBYTE *chunkybuffer;
};

struct MyBitMap {
	struct BitMap BitMap;
	PLANEPTR xplanes[16];
};

extern void PlanarToChunky(struct p2cStruct *);
extern void ChunkyToPlanar(struct c2pStruct *);

extern void __asm PlanarToChunkyAsm(register __a0 struct p2cStruct *);

extern void __asm ChunkyToPlanarAsm(register __a0 struct c2pStruct *);

extern struct MyBitMap *MyAllocBitMap(UWORD wide,UWORD high, UWORD deep,UBYTE *filename);
extern void MyFreeBitMap(struct MyBitMap *bitmap,UBYTE *filename);

#include "progress.h"

extern void AddMessage(UBYTE *message);
extern void SetMax(int max);
extern void SetCur(int cur);

extern void LockSema(void);
extern void UnlockSema(void);

// initial value
#define DJPEG_INIT	0
// Waiting to read
#define DJPEG_WAIT	1
// Have read
#define DJPEG_HAVE	2
// Abort
#define DJPEG_ABORT	3

extern far ULONG djpegflag;
extern far char jpegpip[32];
extern void djpegWaitTask(void);
