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 protected:
00045 GBmpMem *GetSurface(GSurface *pDC) { return pDC->pMem; }
00046 GRect *GetClip(GSurface *pDC) { return &pDC->Clip; }
00047 int GetLineLength(GSurface *pDC) { return (pDC->pMem) ? pDC->pMem->Line : 0; }
00048
00049 Progress *Meter;
00050
00051 inline void Swap(void *p, int len)
00052 {
00053 #ifdef __BIG_ENDIAN__
00054
00055 uint8 *a = (uint8*)p;
00056 uint8 *b = ((uint8*)p) + len - 1;
00057 while (a < b)
00058 {
00059 uint8 t = *a;
00060 *a = *b;
00061 *b = t;
00062 a++;
00063 b--;
00064 }
00065 #endif
00066 }
00067
00068 bool Read(GStream *s, void *p, int len)
00069 {
00070 int r = s->Read(p, len);
00071 if (r != len)
00072 return false;
00073
00074 Swap(p, len);
00075 return true;
00076 }
00077
00078 bool Write(GStream *s, void *p, int len)
00079 {
00080 Swap(p, len);
00081 int w = s->Write(p, len);
00082 Swap(p, len);
00083 return w == len;
00084 }
00085
00086 public:
00087 GDom *Props;
00088
00089 enum Format
00090 {
00091 FmtJpeg,
00092 FmtPng,
00093 FmtBmp,
00094 FmtIco,
00095 FmtTiff,
00096 FmtGif,
00097 FmtPcx,
00098 FmtSpi,
00099 FmtTga,
00100 };
00101
00102 GFilter()
00103 {
00104 Meter = 0;
00105 Props = 0;
00106 }
00107
00108 virtual ~GFilter() { }
00109 virtual Format GetFormat() = 0;
00110
00112 Progress *GetProgress() { return Meter; }
00114 void SetProgress(Progress *Prg) { Meter = Prg; }
00115
00118 virtual int GetCapabilites() { return 0; }
00120 virtual int GetImages() { return 1; }
00123 virtual bool ReadImage(GSurface *Out, GStream *In) = 0;
00126 virtual bool WriteImage(GStream *Out, GSurface *In) = 0;
00127 };
00128
00129 #define GDC_RLE_COLOUR 0x0001
00130 #define GDC_RLE_MONO 0x0002
00131 #define GDC_RLE_READONLY 0x0004
00132 #define GDC_RLE_KEY 0x0008 // set if valid
00133
00134 class LgiClass GdcRleDC : public GMemDC
00135 {
00136 protected:
00137 COLOUR Key;
00138
00139 int Flags;
00140 int Length;
00141 int Alloc;
00142 uchar *Data;
00143 uchar **ScanLine;
00144
00145 bool SetLength(int Len);
00146 bool FindScanLines();
00147 void Empty();
00148
00149 public:
00150 GdcRleDC();
00151 virtual ~GdcRleDC();
00152
00153 void Move(GdcRleDC *pDC);
00154
00155 bool Create(int x, int y, int Bits, int LineLen = 0);
00156 bool CreateInfo(int x, int y, int Bits);
00157 void ReadOnly(bool Read);
00158 bool ReadOnly();
00159 void Mono(bool Mono);
00160 bool Mono();
00161
00162 void Update(int Flags);
00163 void Draw(GSurface *Dest, int x, int y);
00164
00165 int SizeOf();
00166 bool Read(GFile &F);
00167 bool Write(GFile &F);
00168 };
00169
00170
00172
00176 class LgiClass GFilterFactory
00177 {
00178 static class GFilterFactory *First;
00179 class GFilterFactory *Next;
00180
00183 virtual bool CheckFile
00184 (
00187 char *File,
00189 int Access,
00192 uchar *Hint
00193 ) = 0;
00195 virtual GFilter *NewObject() = 0;
00196
00197 public:
00198 GFilterFactory();
00199 virtual ~GFilterFactory();
00200
00201 static GFilter *New(char *File, int Access, uchar *Hint);
00202 static GFilter *NewAt(int i);
00203 static int GetItems();
00204 };
00205
00206 #endif