00001
00008 #ifndef FILTER2_H
00009 #define FILTER2_H
00010
00011 #include <string.h>
00012 #include "GContainers.h"
00013
00014
00015
00016 #define LGI_FILTER_ERROR "ErrorMsg"
00017 #define LGI_FILTER_COLOUR_PROF "ColourProfile"
00018 #define LGI_FILTER_PARENT_WND "Parent"
00019 #define LGI_FILTER_FOREGROUND "Fore"
00020 #define LGI_FILTER_BACKGROUND "Back"
00021 #define LGI_FILTER_TRANSPARENT "Transparent"
00022 #define LGI_FILTER_QUALITY "Quality"
00023
00024
00026 #define LGI_FILTER_TYPE "Type"
00028 #define LGI_FILTER_EXTENSIONS "Extension"
00029
00030 LgiFunc int FindHeader(int Offset, char *Str, GStream *f);
00031
00033 #define FILTER_CAP_READ 0x0001
00035 #define FILTER_CAP_WRITE 0x0002
00037 #define FILTER_CAP_INFO 0x0004
00038
00042 class LgiClass GFilter : public GDom
00043 {
00044 GArray<uint8> Buf;
00045
00046 protected:
00047 GBmpMem *GetSurface(GSurface *pDC) { return pDC->pMem; }
00048 GRect *GetClip(GSurface *pDC) { return &pDC->Clip; }
00049 int GetLineLength(GSurface *pDC) { return (pDC->pMem) ? pDC->pMem->Line : 0; }
00050
00051 Progress *Meter;
00052
00053 inline void Swap(uint8 *out, const void *in, int len)
00054 {
00055 #ifdef __BIG_ENDIAN__
00056
00057 uint8 *o = out + len - 1;
00058 const uint8 *i = in;
00059 while (i < in + len)
00060 {
00061 *o++ = *i++;
00062 }
00063 #else
00064
00065 memcpy(out, in, len);
00066 #endif
00067 }
00068
00069 bool Read(GStream *s, void *p, int len)
00070 {
00071 if (Buf.Length() < len)
00072 Buf.Length(len);
00073
00074 int r = s->Read(&Buf[0], len);
00075 if (r != len)
00076 return false;
00077
00078 Swap((uint8*)p, &Buf[0], len);
00079 return true;
00080 }
00081
00082 bool Write(GStream *s, const void *p, int len)
00083 {
00084 if (Buf.Length() < len)
00085 Buf.Length(len);
00086 Swap(&Buf[0], p, len);
00087 int w = s->Write(&Buf[0], len);
00088 return w == len;
00089 }
00090
00091 public:
00092 GDom *Props;
00093
00094 enum Format
00095 {
00096 FmtJpeg,
00097 FmtPng,
00098 FmtBmp,
00099 FmtIco,
00100 FmtTiff,
00101 FmtGif,
00102 FmtPcx,
00103 FmtSpi,
00104 FmtTga,
00105 };
00106
00107 GFilter()
00108 {
00109 Meter = 0;
00110 Props = 0;
00111 }
00112
00113 virtual ~GFilter() { }
00114 virtual Format GetFormat() = 0;
00115
00117 Progress *GetProgress() { return Meter; }
00119 void SetProgress(Progress *Prg) { Meter = Prg; }
00120
00123 virtual int GetCapabilites() { return 0; }
00125 virtual int GetImages() { return 1; }
00128 virtual bool ReadImage(GSurface *Out, GStream *In) = 0;
00131 virtual bool WriteImage(GStream *Out, GSurface *In) = 0;
00132 };
00133
00134 #define GDC_RLE_COLOUR 0x0001
00135 #define GDC_RLE_MONO 0x0002
00136 #define GDC_RLE_READONLY 0x0004
00137 #define GDC_RLE_KEY 0x0008 // set if valid
00138
00139 class LgiClass GdcRleDC : public GMemDC
00140 {
00141 protected:
00142 COLOUR Key;
00143
00144 int Flags;
00145 int Length;
00146 int Alloc;
00147 uchar *Data;
00148 uchar **ScanLine;
00149
00150 bool SetLength(int Len);
00151 bool FindScanLines();
00152 void Empty();
00153
00154 public:
00155 GdcRleDC();
00156 virtual ~GdcRleDC();
00157
00158 void Move(GdcRleDC *pDC);
00159
00160 bool Create(int x, int y, int Bits, int LineLen = 0);
00161 bool CreateInfo(int x, int y, int Bits);
00162 void ReadOnly(bool Read);
00163 bool ReadOnly();
00164 void Mono(bool Mono);
00165 bool Mono();
00166
00167 void Update(int Flags);
00168 void Draw(GSurface *Dest, int x, int y);
00169
00170 int SizeOf();
00171 bool Read(GFile &F);
00172 bool Write(GFile &F);
00173 };
00174
00175
00177
00181 class LgiClass GFilterFactory
00182 {
00183 static class GFilterFactory *First;
00184 class GFilterFactory *Next;
00185
00188 virtual bool CheckFile
00189 (
00192 char *File,
00194 int Access,
00197 uchar *Hint
00198 ) = 0;
00200 virtual GFilter *NewObject() = 0;
00201
00202 public:
00203 GFilterFactory();
00204 virtual ~GFilterFactory();
00205
00206 static GFilter *New(char *File, int Access, uchar *Hint);
00207 static GFilter *NewAt(int i);
00208 static int GetItems();
00209 };
00210
00211 #endif