Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

Gdc2.h

Go to the documentation of this file.
00001 
00008 #ifndef __GDC2_H_
00009 #define __GDC2_H_
00010 
00011 // sub-system headers
00012 #include "LgiDefs.h"                // Xp
00013 #include "LgiClass.h"
00014 #include "LgiOsDefs.h"              // Platform specific
00015 // #include "LgiOsClasses.h"            // Platform specific
00016 #include "Progress.h"               // Xp
00017 #include "GFile.h"                  // Platform specific
00018 #include "GMem.h"                   // Platform specific
00019 #include "Core.h"                   // Platform specific
00020 #include "GContainers.h"
00021 
00022 // Alpha Blting
00023 #ifdef WIN32
00024 #include "wingdi.h"
00025 #endif
00026 #ifndef AC_SRC_OVER
00027 #define AC_SRC_OVER                 0
00028 #endif
00029 #ifndef AC_SRC_ALPHA
00030 #define AC_SRC_ALPHA                1
00031 #endif
00032 #include "GLibrary.h"
00033 
00034 //              Defines
00035 
00037 #define LGI_DEFAULT_GAMMA               1.0
00038 
00039 #ifndef LGI_PI
00040 
00041 #define LGI_PI                      3.141592654
00042 #endif
00043 
00045 #define LGI_DegToRad(i)             ((i)*LGI_PI/180)
00046 
00048 #define LGI_RadToDeg(i)             ((i)*180/LGI_PI)
00049 
00050 #ifdef WIN32
00051 
00052 #define GDC_USE_ASM
00053 #endif
00054 
00056 #define GDC_SET                     0
00057 
00058 #define GDC_AND                     1
00059 
00060 #define GDC_OR                      2
00061 
00062 #define GDC_XOR                     3
00063 
00064 #define GDC_ALPHA                   4
00065 #define GDC_REMAP                   5
00066 #define GDC_MAXOP                   6
00067 #define GDC_CACHE_SIZE              4
00068 
00069 // Channel types
00070 #define GDCC_MONO                   0
00071 #define GDCC_GREY                   1
00072 #define GDCC_INDEX                  2
00073 #define GDCC_R                      3
00074 #define GDCC_G                      4
00075 #define GDCC_B                      5
00076 #define GDCC_ALPHA                  6
00077 
00078 // Native data formats
00079 #define GDC_8BIT                    0
00080 #define GDC_16BIT                   1
00081 #define GDC_24BIT                   2
00082 #define GDC_32BIT                   3
00083 #define GDC_MAXFMT                  4
00084 
00085 // Colour spaces
00086 #define GDC_8I                      0   // 8 bit paletted
00087 #define GDC_5R6G5B                  1   // 16 bit
00088 #define GDC_8B8G8B                  2   // 24 bit
00089 #define GDC_8A8R8G8B                3   // 32 bit
00090 #define GDC_MAXSPACE                4
00091 
00092 // Update types
00093 #define GDC_PAL_CHANGE              0x1
00094 #define GDC_BITS_CHANGE             0x2
00095 
00096 // Flood fill types
00097 
00099 #define GDC_FILL_TO_DIFFERENT       0
00100 
00101 #define GDC_FILL_TO_BORDER          1
00102 
00103 #define GDC_FILL_NEAR               2
00104 
00105 // Gdc options
00106 
00108 #define GDC_REDUCE_TYPE             0
00109 
00110     #define REDUCE_NONE                 0
00111 
00112     #define REDUCE_NEAREST              1
00113 
00114     #define REDUCE_HALFTONE             2
00115 
00116     #define REDUCE_ERROR_DIFFUSION      3
00117 
00118     #define REDUCE_DL1                  4
00119 
00120 #define GDC_HALFTONE_BASE_INDEX     1
00121 
00122 #define GDC_PALETTE_TYPE            2
00123 
00124     #define PALTYPE_ALLOC               0
00125 
00126     #define PALTYPE_RGB_CUBE            1
00127 
00128     #define PALTYPE_HSL                 2
00129 
00130 #define GDC_PROMOTE_ON_LOAD         3
00131 #define GDC_MAX_OPTION              4
00132 
00133 //  Flags
00134 // Surface
00135 #define GDC_OWN_MEMORY              0x0001
00136 #define GDC_ON_SCREEN               0x0002
00137 #define GDC_ALPHA_CHANNEL           0x0004
00138 #define GDC_UPDATED_PALETTE         0x0008
00139 
00140 // BaseDC
00141 #define GDC_OWN_APPLICATOR          0x0001
00142 #define GDC_CACHED_APPLICATOR       0x0002
00143 #define GDC_OWN_PALETTE             0x0004
00144 #define GDC_DRAW_ON_ALPHA           0x0008
00145 
00146 // Region types
00147 #define GDC_RGN_NONE                0   // No clipping
00148 #define GDC_RGN_SIMPLE              1   // Single rectangle
00149 #define GDC_RGN_COMPLEX             2   // Many rectangles
00150 
00151 // Error codes
00152 #define GDCERR_NONE                 0
00153 #define GDCERR_ERROR                1
00154 #define GDCERR_CANT_SET_SCAN_WIDTH  2
00155 #define GDC_INVALIDMODE             -1
00156 
00157 // Font display flags
00158 #define GDCFNT_TRANSPARENT          0x0001  // not set - SOLID
00159 #define GDCFNT_UNDERLINE            0x0002
00160 
00161 // Palette file types
00162 #define GDCPAL_JASC                 1
00163 #define GDCPAL_MICROSOFT            2
00164 
00165 // Misc
00166 #define BMPWIDTH(bits)              ((((bits)+31)/32)*4)
00167 
00168 
00169 //              Typedefs
00170 
00187 typedef uint32                      COLOUR;
00188 
00190 typedef uint8                       ALPHA;
00191 
00192 // colour conversion defines
00193 // RGB colour space
00194 #define BitWidth(bits, cropbits)    ( (((bits)+(cropbits)-1)/(cropbits)) * 4 )
00195 
00196 #ifdef WIN32
00197 #pragma pack(push, before_pack)
00198 #pragma pack(1)
00199 #endif
00200 
00201 #if defined WIN32
00202 
00203     #if LGI_LITTLE_ENDIAN
00204     #define C24R                    0
00205     #define C24G                    1
00206     #define C24B                    2
00207     #else
00208     #define C24R                    2
00209     #define C24G                    1
00210     #define C24B                    0
00211     #endif
00212 
00213     class LgiClass Pixel24
00214     {
00215     public:
00216         static int Size;
00217     
00218         uchar b, g, r;
00219         
00220         Pixel24 *Next() { return this + 1; }
00221     };
00222 
00223     #if LGI_LITTLE_ENDIAN
00224     #define C32B                    0
00225     #define C32G                    1
00226     #define C32R                    2
00227     #define C32A                    3
00228     #else
00229     #define C32B                    3
00230     #define C32G                    2
00231     #define C32R                    1
00232     #define C32A                    0
00233     #endif
00234 
00235     class LgiClass Pixel32
00236     {
00237     public:
00238         static int Size;
00239 
00240         uchar b, g, r, a;
00241         
00242         Pixel32 *Next() { return this + 1; }
00243     };
00244 
00245 #elif defined LINUX
00246 
00247     #if LGI_LITTLE_ENDIAN
00248     #define C24B                    0
00249     #define C24G                    1
00250     #define C24R                    2
00251     #else
00252     #define C24B                    2
00253     #define C24G                    1
00254     #define C24R                    0
00255     #endif
00256 
00257     class LgiClass Pixel24
00258     {
00259     public:
00260         static int Size;
00261 
00262         uchar b, g, r;
00263 
00264         Pixel24 *Next() { return (Pixel24*) ((char*)this + Size); }
00265     };
00266 
00267     #if LGI_LITTLE_ENDIAN
00268     #define C32B                    0
00269     #define C32G                    1
00270     #define C32R                    2
00271     #define C32A                    3
00272     #else
00273     #define C32B                    3
00274     #define C32G                    2
00275     #define C32R                    1
00276     #define C32A                    0
00277     #endif
00278 
00279     class LgiClass Pixel32
00280     {
00281     public:
00282         static int Size;
00283 
00284         uchar b, g, r, a;
00285 
00286         Pixel32 *Next() { return this + 1; }
00287     };
00288 
00289 #elif defined BEOS
00290 
00291     #if LGI_LITTLE_ENDIAN
00292     #define C24B                    0
00293     #define C24G                    1
00294     #define C24R                    2
00295     #else
00296     #define C24B                    2
00297     #define C24G                    1
00298     #define C24R                    0
00299     #endif
00300 
00301     class LgiClass Pixel24
00302     {
00303     public:
00304         static int Size;
00305 
00306         uchar b, g, r;
00307 
00308         Pixel24 *Next() { return this + 1; }
00309     };
00310 
00311     #if LGI_LITTLE_ENDIAN
00312     #define C32B                    0
00313     #define C32G                    1
00314     #define C32R                    2
00315     #define C32A                    3
00316     #else
00317     #define C32B                    3
00318     #define C32G                    2
00319     #define C32R                    1
00320     #define C32A                    0
00321     #endif
00322 
00323     class LgiClass Pixel32
00324     {
00325     public:
00326         static int Size;
00327 
00328         uchar b, g, r, a;
00329 
00330         Pixel32 *Next() { return this + 1; }
00331     };
00332 
00333 #elif defined MAC
00334 
00335     #if LGI_LITTLE_ENDIAN
00336     #define C24B                    0
00337     #define C24G                    1
00338     #define C24R                    2
00339     #else
00340     #define C24B                    2
00341     #define C24G                    1
00342     #define C24R                    0
00343     #endif
00344 
00345     class LgiClass Pixel24
00346     {
00347     public:
00348         static int Size;
00349 
00350         uchar r, g, b;
00351 
00352         Pixel24 *Next() { return this + 1; }
00353     };
00354 
00355     #if LGI_LITTLE_ENDIAN
00356     #define C32B                    0
00357     #define C32G                    1
00358     #define C32R                    2
00359     #define C32A                    3
00360     #else
00361     #define C32B                    3
00362     #define C32G                    2
00363     #define C32R                    1
00364     #define C32A                    0
00365     #endif
00366 
00367     class LgiClass Pixel32
00368     {
00369     public:
00370         static int Size;
00371 
00372         uchar r, g, b, a;
00373 
00374         Pixel32 *Next() { return this + 1; }
00375     };
00376 
00377 #endif
00378 
00380 #define Rgb15(r, g, b)              ( ((r&0xF8)<<7) | ((g&0xF8)<<2) | ((b&0xF8)>>3))
00381 #define Rgb32To15(c32)              ( ((c32&0xF8)>>3) | ((c32&0xF800)>>6) | ((c32&0xF80000)>>9) )
00382 #define Rgb24To15(c24)              ( (B24(c24)>>3) | ((G24(c24)<<2)&0x3E0) | ((R24(c24)<<7)&0x7C00) )
00383 #define Rgb16To15(c16)              ( ((c16&0xFFC0)>>1) | (c16&0x1F) )
00384 
00385 #define R15(c15)                    ( (uchar) ((c15>>10)&0x1F) )
00386 
00387 #define G15(c15)                    ( (uchar) ((c15>>5)&0x1F) )
00388 
00389 #define B15(c15)                    ( (uchar) ((c15)&0x1F) )
00390 
00391 #define Rc15(c)                     ( (((c) & 0x7C00) >> 7) | (((c) & 0x7C00) >> 12) )
00392 #define Gc15(c)                     ( (((c) & 0x03E0) >> 2) | (((c) & 0x03E0) >> 7) )
00393 #define Bc15(c)                     ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00394 
00396 #define Rgb16(r, g, b)              ( ((r&0xF8)<<8) | ((g&0xFC)<<3) | ((b&0xF8)>>3))
00397 #define Rgb32To16(c32)              ( ((c32&0xF8)>>3) | ((c32&0xFC00)>>5) | ((c32&0xF80000)>>8) )
00398 #define Rgb24To16(c24)              ( (B24(c24)>>3) | ((G24(c24)<<3)&0x7E0) | ((R24(c24)<<8)&0xF800) )
00399 #define Rgb15To16(c15)              ( ((c15&0x7FE0)<<1) | (c15&0x1F) )
00400 
00401 #define R16(c16)                    ( (uchar) ((c16>>11)&0x1F) )
00402 
00403 #define G16(c16)                    ( (uchar) ((c16>>5)&0x3F) )
00404 
00405 #define B16(c16)                    ( (uchar) ((c16)&0x1F) )
00406 
00407 #define Rc16(c)                     ( (((c) & 0xF800) >> 8) | (((c) & 0xF800) >> 13) )
00408 #define Gc16(c)                     ( (((c) & 0x07E0) >> 3) | (((c) & 0x07E0) >> 9) )
00409 #define Bc16(c)                     ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00410 
00412 #define R24(c24)                    ( ((c24)>>(C24R*8)) & 0xff )
00413 
00414 #define G24(c24)                    ( ((c24)>>(C24G*8)) & 0xff  )
00415 
00416 #define B24(c24)                    ( ((c24)>>(C24B*8)) & 0xff  )
00417 
00419 #define Rgb24(r, g, b)              ( (((r)&0xFF) << (C24R*8)) | (((g)&0xFF) << (C24G*8)) | (((b)&0xFF) << (C24B*8)) )
00420 #define Rgb32To24(c32)              Rgb24(R32(c32), G32(c32), B32(c32))
00421 #define Rgb15To24(c15)              ( ((c15&0x7C00)>>7) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<19) )
00422 #define Rgb16To24(c16)              ( ((c16&0xF800)>>8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<19) )
00423 
00424 // 32
00425 //              31              24 23              16 15              8  7               0
00426 //              |-|-|-|-|-|-|-|-|  |-|-|-|-|-|-|-|-|  |-|-|-|-|-|-|-|-|  |-|-|-|-|-|-|-|-|
00427 // Windows      |---- alpha ----|  |----- red -----|  |---- green ----|  |----- blue ----|
00428 // Linux        |----- blue ----|  |---- green ----|  |----- red -----|  |---- alpha ----|
00429 
00431 #define R32(c32)                    ( (uchar) (c32 >> (C32R*8)) )
00432 
00433 #define G32(c32)                    ( (uchar) (c32 >> (C32G*8)) )
00434 
00435 #define B32(c32)                    ( (uchar) (c32 >> (C32B*8)) )
00436 
00437 #define A32(c32)                    ( (uchar) (c32 >> (C32A*8)) )
00438 
00439 #define RgbPreMul(c, a)             ( Div255Lut[(c)*a] )
00440 #define Rgb32(r, g, b)              ( (((r)&0xFF)<<(C32R*8)) | (((g)&0xFF)<<(C32G*8)) | (((b)&0xFF)<<(C32B*8)) | (0xFF<<(C32A*8)) )
00441 #define Rgba32(r, g, b, a)          ( (((r)&0xFF)<<(C32R*8)) | (((g)&0xFF)<<(C32G*8)) | (((b)&0xFF)<<(C32B*8)) | (((a)&0xFF)<<(C32A*8)) )
00442 #define Rgbpa32(r, g, b, a)         ( (RgbPreMul(r, a)<<(C32R*8)) | (RgbPreMul(g, a)<<(C32G*8)) | (RgbPreMul(b, a)<<(C32B*8)) | ((a&0xFF)<<(C32A*8)) )
00443 #define Rgb24To32(c24)              Rgba32( R24(c24), G24(c24), B24(c24), 255 )
00444 #define Rgb15To32(c15)              ( ((c15&0x7C00)<<9) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<3) | (0xFF<<(C32A*8)) )
00445 #define Rgb16To32(c16)              ( ((c16&0xF800)<<8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<3) | (0xFF<<(C32A*8)) )
00446 
00447 // HLS colour Space
00448 #define Hls32(h, l, s)              ( ((h)<<16) | ((l)<<8) | (s) )
00449 #define H32(c)                      ( ((c)>>16)&0xFFFF )
00450 #define L32(c)                      ( ((c)>>8)&0xFF )
00451 #define S32(c)                      ( (c)&0xFF )
00452 #define HUE_UNDEFINED               1024
00453 #define HlsIsUndefined(Hls)         (H32(Hls) == HUE_UNDEFINED)
00454 
00455 // Look up tables
00456 #define Div255Lut                   (GdcDevice::GetInst()->GetDiv255())
00457 
00458 LgiFunc COLOUR RgbToHls(COLOUR Rgb24);
00459 LgiFunc COLOUR HlsToRgb(COLOUR Hsl32);
00460 
00461 #ifdef WIN32
00462 #pragma pack(pop, before_pack)
00463 #endif
00464 
00465 //              Classes
00466 class GFilter;
00467 class GSurface;
00468 
00469 #include "GRect.h"
00470 #include "GFont.h"
00471 
00473 class LgiClass GdcPt2
00474 {
00475 public:
00476     int x, y;
00477 
00478     GdcPt2(int Ix = 0, int Iy = 0)
00479     {
00480         x = Ix;
00481         y = Iy;
00482     }
00483 
00484     GdcPt2(const GdcPt2 &p)
00485     {
00486         x = p.x;
00487         y = p.y;
00488     }
00489 
00490     bool Inside(GRect &r)
00491     {
00492         return  (x >= r.x1) AND
00493                 (x <= r.x2) AND
00494                 (y >= r.y1) AND
00495                 (y <= r.y2);
00496     }
00497 };
00498 
00500 class LgiClass GdcPt3
00501 {
00502 public:
00503     int x, y, z;
00504 };
00505 
00506 #ifdef WIN32
00507 #pragma pack(push, before_pack)
00508 #pragma pack(1)
00509 #endif
00510 
00512 class LgiClass GdcRGB
00513 {
00514 public:
00515     uchar R, G, B;
00516     #ifndef MAC
00517     uchar Flags;
00518     #endif
00519 
00520     void Set(uchar r, uchar g, uchar b, uchar f = 0)
00521     {
00522         R = r;
00523         G = g;
00524         B = b;
00525         #ifndef MAC
00526         Flags = f;
00527         #endif
00528     }
00529 };
00530 
00531 #ifdef WIN32
00532 #pragma pack(pop, before_pack)
00533 #endif
00534 
00536 class LgiClass GPalette
00537 {
00538 protected:
00539     #ifdef WIN32
00540     HPALETTE    hPal;
00541     LOGPALETTE  *Data;
00542     #else
00543     int         Size;
00544     GdcRGB      *Data;
00545     #endif
00546     uchar *Lut;
00547 
00548 public:
00549     GPalette();
00550     virtual ~GPalette();
00551 
00552     #ifdef WIN32
00553     HPALETTE Handle() { return hPal; }
00554     #endif
00555 
00556     GPalette(GPalette *pPal);   
00557     GPalette(uchar *pPal, int s = 256);
00558     void Set(GPalette *pPal);
00559     void Set(uchar *pPal, int s = 256);
00560 
00561     int GetSize();
00562     GdcRGB *operator [](int i);
00563     bool Update();
00564     bool SetSize(int s = 256);
00565     void SwapRAndB();
00566     int MatchRgb(COLOUR Rgb);
00567     void CreateCube();
00568     void CreateGreyScale();
00569     bool Load(GFile &F);
00570     bool Save(GFile &F, int Format);
00571     uchar *MakeLut(int Bits = 16);
00572 
00573     bool operator ==(GPalette &p);
00574     bool operator !=(GPalette &p);
00575 };
00576 
00577 class LgiClass GBmpMem
00578 {
00579 public:
00580     uchar *Base;
00581     int x, y, Bits, Line;
00582     int Flags;
00583 
00584     GBmpMem();
00585     ~GBmpMem();
00586 };
00587 
00588 
00589 #define GAPP_ALPHA_A            1
00590 #define GAPP_ALPHA_PAL          2
00591 #define GAPP_BACKGROUND         3
00592 #define GAPP_ANGLE              4
00593 #define GAPP_BOUNDS             5
00594 
00600 class LgiClass GApplicator
00601 {
00602 protected:
00603     GBmpMem *Dest;
00604     GBmpMem *Alpha;
00605     GPalette *Pal;
00606     int Op;
00607 
00608 public:
00609     COLOUR c;               // main colour
00610 
00611     GApplicator() { c = 0; }
00612     GApplicator(COLOUR Colour) { c = Colour; }
00613     virtual ~GApplicator() { }
00614 
00616     virtual int GetVar(int Var) { return 0; }
00618     virtual int SetVar(int Var, int Value) { return 0; }
00619 
00621     void SetOp(int o) { Op = o; }
00623     int GetOp() { return Op; }
00625     int GetBits() { return (Dest) ? Dest->Bits : 0; }
00627     int GetFlags() { return (Dest) ? Dest->Flags : 0; }
00629     GPalette *GetPal() { return Pal; }
00630 
00632     virtual bool SetSurface(GBmpMem *d, GPalette *p = 0, GBmpMem *a = 0) = 0; // sets Dest, returns FALSE on error
00634     virtual void SetPtr(int x, int y) = 0;          // calculates Ptr from x, y
00636     virtual void IncX() = 0;
00638     virtual void IncY() = 0;
00640     virtual void IncPtr(int X, int Y) = 0;
00641 
00643     virtual void Set() = 0;
00645     virtual COLOUR Get() = 0;
00647     virtual void VLine(int height) = 0;
00649     virtual void Rectangle(int x, int y) = 0;
00651     virtual bool Blt(GBmpMem *Src, GPalette *SPal, GBmpMem *SrcAlpha = 0) = 0;
00652 };
00653 
00655 class LgiClass GApplicatorFactory
00656 {
00657 public:
00658     static List<GApplicatorFactory> Factories;
00659 
00660 public:
00661     GApplicatorFactory();
00662     virtual ~GApplicatorFactory();
00663 
00665     static GApplicator *NewApp(int Bits, int Op);
00666     virtual GApplicator *Create(int Bits, int Op) { return NULL; }
00667 };
00668 
00669 #define OrgX(x)         x -= OriginX
00670 #define OrgY(y)         y -= OriginY
00671 #define OrgXy(x, y)     x -= OriginX; y -= OriginY
00672 #define OrgPt(p)        p.x -= OriginX; p.y -= OriginY
00673 #define OrgRgn(r)       r.Offset(-OriginX, -OriginY)
00674 
00676 class LgiClass GDeviceContext
00677 {
00678     friend class GFilter;
00679     friend class GSurface;
00680 
00681 protected:
00682     int             Flags;
00683     int             PrevOp;
00684     GRect           Clip;
00685     GBmpMem         *pMem;
00686     GSurface        *pAlphaDC;
00687     GPalette        *pPalette;
00688     GApplicator     *pApp;
00689     GApplicator     *pAppCache[GDC_CACHE_SIZE];
00690     int             OriginX, OriginY;
00691 
00692     // Protected functions
00693     GApplicator     *CreateApplicator(int Op = GDC_SET, int Bits = 0);
00694 
00695 public:
00696     GDeviceContext();
00697     virtual ~GDeviceContext();
00698 
00699     virtual bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false) { return false; }
00700     virtual void Update(int Flags) {}
00701 
00702     // Alpha channel
00703     
00705     virtual bool IsAlpha() { return pAlphaDC != 0; }
00707     virtual bool IsAlpha(bool b);
00709     bool DrawOnAlpha() { return ((Flags & GDC_DRAW_ON_ALPHA) != 0); }
00711     bool DrawOnAlpha(bool Draw);
00713     GSurface *AlphaDC() { return pAlphaDC; }
00714 
00715     // Applicator
00716     virtual bool Applicator(GApplicator *pApp);
00717     virtual GApplicator *Applicator();
00718 
00719     // Palette
00720     virtual GPalette *Palette();
00721     virtual void Palette(GPalette *pPal, bool bOwnIt = true);
00722 
00723     // Clip region
00724     virtual GRect ClipRgn(GRect *Rgn);
00725     virtual GRect ClipRgn();
00726 
00728     virtual COLOUR Colour() { return pApp->c; }
00730     virtual COLOUR Colour
00731     (
00733         COLOUR c,
00735         int Bits = 0
00736     );
00738     virtual int Op() { return (pApp) ? pApp->GetOp() : 0; }
00741     virtual int Op(int Op);
00743     virtual int X() { return (pMem) ? pMem->x : 0; }
00745     virtual int Y() { return (pMem) ? pMem->y : 0; }
00747     virtual int DpiX() { return 100; }
00749     virtual int DpiY() { return 100; }
00751     virtual int GetBits() { return (pMem) ? pMem->Bits : 0; }
00753     virtual int PixelSize() { return GetBits() == 24 ? Pixel24::Size : GetBits() >> 3; }
00754     virtual int GetFlags() { return Flags; }
00756     virtual bool IsScreen() { return (pApp) ? (pApp->GetFlags() & GDC_ON_SCREEN) != 0 : 0; }
00758     virtual bool IsPrint() { return false; }
00760     virtual uchar *operator[](int y) { return (pMem AND y>=0 AND y<pMem->y) ? pMem->Base + (pMem->Line * y) : 0; }
00761 
00763     virtual void GetOrigin(int &x, int &y) { x = OriginX; y = OriginY; }
00765     virtual void SetOrigin(int x, int y) { OriginX = x; OriginY = y; }
00766 };
00767 
00769 class LgiClass GSurface : public GDeviceContext
00770 {
00771     #if defined BEOS || defined LINUX
00772     friend class GView;
00773     friend class GWindow;
00774     #endif
00775 
00776 protected:
00777     uint32      LineBits;
00778     uint32      LineMask;
00779     uint32      LineReset;
00780 
00781     #ifdef WIN32
00782     HDC         hDC;
00783     HBITMAP     hBmp;
00784     #endif
00785 
00786 public:
00787     GSurface();
00788     GSurface(GSurface *pDC);
00789 
00790     // Win32
00791     #if defined WIN32
00792 
00793     virtual HDC StartDC() { return hDC; }
00794     virtual void EndDC() {}
00795     HBITMAP GetBitmap() { return hBmp; }
00796     HDC Handle() { return hDC; }
00797     
00798     #else
00799     
00800     virtual OsPainter Handle() { return 0; }
00801     virtual OsBitmap GetBitmap() { return 0; }
00802     virtual void SetClient(GRect *c) { }
00803 
00804     #endif
00805     
00806     #ifdef MAC
00807     virtual CGColorSpaceRef GetColourSpace() { return 0; }
00808     #endif
00809 
00810     // Pixel
00811     
00813     virtual void Set(int x, int y);
00815     virtual COLOUR Get(int x, int y);
00816 
00817     // Line
00818 
00820     virtual void HLine(int x1, int x2, int y);
00822     virtual void VLine(int x, int y1, int y2);
00824     virtual void Line(int x1, int y1, int x2, int y2);
00825     
00826     virtual uint LineStyle(uint32 Bits, uint32 Reset = 0x80000000)
00827     {
00828         uint32 B = LineBits;
00829         LineBits = Bits;
00830         LineMask = LineReset = Reset;
00831         return B;
00832     }
00833     virtual uint LineStyle() { return LineBits; }
00834 
00835     // Curve
00836 
00838     virtual void Circle(double cx, double cy, double radius);
00840     virtual void FilledCircle(double cx, double cy, double radius);
00842     virtual void Arc(double cx, double cy, double radius, double start, double end);
00844     virtual void FilledArc(double cx, double cy, double radius, double start, double end);
00846     virtual void Ellipse(double cx, double cy, double x, double y);
00848     virtual void FilledEllipse(double cx, double cy, double x, double y);
00849 
00850     // Rectangular
00851 
00853     virtual void Box(int x1, int y1, int x2, int y2);
00855     virtual void Box
00856     (
00858         GRect *a = NULL
00859     );
00861     virtual void Rectangle(int x1, int y1, int x2, int y2);
00863     virtual void Rectangle
00864     (
00866         GRect *a = NULL
00867     );
00869     virtual void Blt
00870     (
00872         int x,
00874         int y,
00876         GSurface *Src,
00878         GRect *a = NULL
00879     );
00881     virtual void StretchBlt(GRect *d, GSurface *Src, GRect *s);
00882 
00883     // Other
00884 
00886     virtual void Polygon(int Points, GdcPt2 *Data);
00888     virtual void Bezier(int Threshold, GdcPt2 *Pt);
00890     virtual void FloodFill
00891     (
00893         int x,
00895         int y,
00897         int Mode,
00899         COLOUR Border = 0,
00901         GRect *Bounds = NULL
00902     );
00903 };
00904 
00909 class LgiClass GScreenDC : public GSurface
00910 {
00911     class GScreenPrivate *d;
00912 
00913 public:
00914     GScreenDC();
00915     virtual ~GScreenDC();
00916 
00917     // OS Sepcific
00918     #if defined WIN32
00919 
00920         GScreenDC(HWND hwnd);
00921         GScreenDC(HDC hdc, HWND hwnd, bool Release = false);
00922         GScreenDC(HBITMAP hBmp, int Sx, int Sy);
00923 
00924         bool Create(HDC hdc);
00925         void SetSize(int x, int y);
00926 
00927     #else
00928 
00929         GScreenDC(OsView view, void *Param = 0);
00930         #ifdef MAC
00931         GScreenDC(OsWindow view, void *Param = 0);
00932         #endif
00933 
00934         OsPainter Handle();
00935         int GetFlags();
00936         void SetClient(GRect *c);
00937 
00938     #endif
00939 
00940     // Properties
00941     void GetOrigin(int &x, int &y);
00942     void SetOrigin(int x, int y);
00943 
00944     GRect ClipRgn();
00945     GRect ClipRgn(GRect *Rgn);
00946 
00947     COLOUR Colour();
00948     COLOUR Colour(COLOUR c, int Bits = 0);
00949 
00950     int Op();
00951     int Op(int Op);
00952 
00953     int X();
00954     int Y();
00955 
00956     GPalette *Palette();
00957     void Palette(GPalette *pPal, bool bOwnIt = true);
00958 
00959     uint LineStyle();
00960     uint LineStyle(uint Bits, uint32 Reset = 0x80000000);
00961 
00962     int GetBits();
00963     bool IsScreen();
00964     uchar *operator[](int y) { return NULL; }
00965 
00966     // Primitives
00967     void Set(int x, int y);
00968     COLOUR Get(int x, int y);
00969     void HLine(int x1, int x2, int y);
00970     void VLine(int x, int y1, int y2);
00971     void Line(int x1, int y1, int x2, int y2);
00972     void Circle(double cx, double cy, double radius);
00973     void FilledCircle(double cx, double cy, double radius);
00974     void Arc(double cx, double cy, double radius, double start, double end);
00975     void FilledArc(double cx, double cy, double radius, double start, double end);
00976     void Ellipse(double cx, double cy, double x, double y);
00977     void FilledEllipse(double cx, double cy, double x, double y);
00978     void Box(int x1, int y1, int x2, int y2);
00979     void Box(GRect *a);
00980     void Rectangle(int x1, int y1, int x2, int y2);
00981     void Rectangle(GRect *a = NULL);
00982     void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
00983     void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
00984     void Polygon(int Points, GdcPt2 *Data);
00985     void Bezier(int Threshold, GdcPt2 *Pt);
00986     void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
00987 };
00988 
00989 #ifdef MAC
00990 class CGImg
00991 {
00992     class CGImgPriv *d;
00993 
00994 public:
00995     CGImg(int x, int y, int Bits, int Line, uchar *data, uchar *palette, GRect *r);
00996     ~CGImg();
00997     
00998     operator CGImageRef();
00999 };
01000 #endif
01001 
01006 class LgiClass GMemDC : public GSurface
01007 {
01008 protected:
01009     class GMemDCPrivate *d;
01010 
01011     #if defined WIN32
01012     PBITMAPINFO GetInfo();
01013     #endif
01014 
01015 public:
01017     GMemDC
01018     (
01020         int x = 0,
01022         int y = 0,
01024         int bits = 0
01025     );
01026     GMemDC(GSurface *pDC);
01027     virtual ~GMemDC();
01028 
01029     #if defined WIN32
01030     
01031         HDC StartDC();
01032         void EndDC();
01033         void Update(int Flags);
01034         void UpsideDown(bool upsidedown);
01035         
01036         // need this to tell the HDC about the
01037         // new clipping region
01038         GRect ClipRgn(GRect *Rgn);
01039 
01040     #else
01041 
01042         OsBitmap GetBitmap();
01043         bool IsScreen() { return false; }
01044         GRect ClipRgn() { return Clip; }
01045 
01046         OsPainter Handle();
01047 
01048         #if defined XWIN
01049 
01050         Pixmap GetPixmap();
01051         Pixmap GetPixmapMask();
01052 
01053         #elif defined MAC
01054         
01055         CGColorSpaceRef GetColourSpace();
01056         CGImg *GetImg(GRect *Sub = 0);
01057         
01058         #endif
01059         
01060     #endif
01061 
01063     bool Lock();
01068     bool Unlock();
01069 
01070     #ifdef XWIN
01071     // Returns the scanline when the bitmap is locked. Otherwise null.
01072     uchar *operator[](int y);
01073     #endif
01074     
01075     void SetOrigin(int x, int y);
01076 
01077     bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false);
01078     void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01079     void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01080 
01081     void HLine(int x1, int x2, int y, COLOUR a, COLOUR b);
01082     void VLine(int x, int y1, int y2, COLOUR a, COLOUR b);
01083 };
01084 
01090 class LgiClass GPrintDC
01091 #if defined WIN32
01092     : public GScreenDC
01093 #else
01094     : public GSurface
01095 #endif
01096 {
01097     #ifdef XWIN
01098     friend class PrintPainter;
01099     double Xc(int x);
01100     double Yc(int y);
01101     #endif
01102 
01103     class GPrintDCPrivate *d;
01104 
01105 public:
01106     GPrintDC(void *Handle, char *PrintJobName);
01107     ~GPrintDC();
01108 
01109     bool IsPrint() { return true; }
01110 
01111     int X();
01112     int Y();
01113     int GetBits();
01114 
01116     int DpiX();
01117 
01119     int DpiY();
01120 
01122     bool StartPage();
01124     void EndPage();
01125 
01126     #if defined XWIN
01127 
01128     OsPainter Handle();
01129     COLOUR Colour();
01130     COLOUR Colour(COLOUR c, int Bits = 0);
01131 
01132     void Set(int x, int y);
01133     COLOUR Get(int x, int y);
01134     void HLine(int x1, int x2, int y);
01135     void VLine(int x, int y1, int y2);
01136     void Line(int x1, int y1, int x2, int y2);
01137     void Circle(double cx, double cy, double radius);
01138     void FilledCircle(double cx, double cy, double radius);
01139     void Arc(double cx, double cy, double radius, double start, double end);
01140     void FilledArc(double cx, double cy, double radius, double start, double end);
01141     void Ellipse(double cx, double cy, double x, double y);
01142     void FilledEllipse(double cx, double cy, double x, double y);
01143     void Box(int x1, int y1, int x2, int y2);
01144     void Box(GRect *a = NULL);
01145     void Rectangle(int x1, int y1, int x2, int y2);
01146     void Rectangle(GRect *a = NULL);
01147     void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01148     void StretchBlt(GRect *d, GSurface *Src, GRect *s);
01149     void Polygon(int Points, GdcPt2 *Data);
01150     void Bezier(int Threshold, GdcPt2 *Pt);
01151     void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01152     
01153     #endif
01154 
01155 };
01156 
01158 class LgiClass GSprite
01159 {
01160 protected:
01161     // Dimensions
01162     int Sx, Sy, Bits;
01163     
01164     // Screen relation
01165     bool Visible;
01166     int PosX, PosY;
01167     int HotX, HotY;
01168 
01169     // Mode
01170     int DrawMode;           // See access functions for description
01171 
01172     // Destination DC, usually the screen
01173     // Don't own and must not be NULL
01174     GSurface *pScreen;
01175     
01176     // Internal sprite DC's
01177     // TODO: combine all these into one DC 3 times bigger
01178     GSurface *pBack;
01179     GSurface *pMask;
01180     GSurface *pColour;
01181     GSurface *pTemp;
01182 
01183     // This function gets called to update any sprite position dependent
01184     // graphics when the sprite moves.
01185     virtual void DrawOnMove(    GSurface *pDC,
01186                     int Nx, int Ny,
01187                     int Ox, int Oy) {}
01188 
01189 public:
01190     GSprite();
01191     virtual ~GSprite();
01192 
01193     int X() { return Sx; }
01194     int Y() { return Sy; }
01195     int GetPosX() { return PosX; }
01196     int GetPosY() { return PosY; }
01197     int GetHotX() { return HotX; }
01198     int GetHotY() { return HotY; }
01199     int GetBits() { return Bits; }
01200     bool IsVisible() { return Visible; }
01201 
01202     void SetXY(int x, int y);
01203 
01204     bool Create(GSurface *pScreen, int x, int y, int Bits, uchar *Colour, uchar *Mask);
01205     bool CreateKey(GSurface *pScreen, int x, int y, int Bits, uchar *Colour, int Key);
01206     bool Create(GSurface *pScreen, GSprite *pSpr);
01207     bool SetSize(int x, int y, int Bits, GSurface *pScr = NULL);
01208     void Delete();
01209 
01210     int Mode() { return DrawMode; }
01211     int Mode(int m) { int Old = DrawMode; DrawMode = m; return Old; }
01212     // Mode:
01213     //  0 - Transparent background, AND mask, XOR colour
01214     //  1 - Transparent background, AND mask, OR colour
01215     //  3 - COPY colour
01216 
01217     void SetHotPoint(int x, int y);
01218     void SetVisible(bool v);
01219     void Move(int x, int y, bool WaitRetrace);
01220 
01221     void Draw(int x, int y, COLOUR Back, int Mode = 0, GSurface *pDC = NULL);
01222     // Mode:
01223     //  0 - Solid background, AND colour, XOR mask
01224     //  1 - Solid background, AND mask, OR colour
01225     //  2 - Transparent background, AND mask, OR colour
01226     //  3 - COPY colour
01227 
01228     void MoveToScreen(GSurface *Scr)
01229     {
01230         bool v = Visible;
01231         SetVisible(false);
01232         pScreen = Scr;
01233         SetVisible(v);
01234     }
01235     GSurface *GetMask() { return pMask; }
01236     GSurface *GetColour() { return pColour; }
01237 };
01238 
01239 class LgiClass GGlobalColour
01240 {
01241     class GGlobalColourPrivate *d;
01242 
01243 public:
01244     GGlobalColour();
01245     ~GGlobalColour();
01246 
01247     // Add all the colours first
01248     COLOUR AddColour(COLOUR c24);
01249     bool AddBitmap(GSurface *pDC);
01250     bool AddBitmap(GImageList *il);
01251 
01252     // Then call this
01253     bool MakeGlobalPalette();
01254 
01255     // Which will give you a palette that
01256     // includes everything
01257     GPalette *GetPalette();
01258 
01259     // Convert a bitmap to the global palette
01260     COLOUR GetColour(COLOUR c24);
01261     bool RemapBitmap(GSurface *pDC);
01262 };
01263 
01264 #ifdef WIN32
01265 typedef int (__stdcall *MsImg32_AlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
01266 #endif
01267 
01269 class LgiClass GdcDevice
01270 {
01271     friend class GScreenDC;
01272     static GdcDevice *pInstance;
01273     class GdcDevicePrivate *d;
01274     #ifdef WIN32
01275     MsImg32_AlphaBlend AlphaBlend;
01276     #endif
01277 
01278 public:
01279     GdcDevice();
01280     ~GdcDevice();
01281     static GdcDevice *GetInst() { return pInstance; }
01282 
01284     int GetBits();
01286     int X();
01288     int Y();
01289 
01290     GGlobalColour *GetGlobalColour();
01291 
01293     int GetOption(int Opt);
01295     int SetOption(int Opt, int Value);
01296 
01298     ulong *GetCharSquares();
01300     uchar *GetDiv255();
01301 
01302     // Palette/Colour
01303     void SetGamma(double Gamma);
01304     double GetGamma();
01305 
01306     // Palette
01307     void SetSystemPalette(int Start, int Size, GPalette *Pal);
01308     GPalette *GetSystemPalette();
01309     void SetColourPaletteType(int Type);    // Type = PALTYPE_xxx define
01310     COLOUR GetColour(COLOUR Rgb24, GDeviceContext *pDC = NULL);
01311 
01312     // Lib
01313     GLibrary *GetIconv();
01314 };
01315 
01327 class GInlineBmp
01328 {
01329 public:
01331     int X;
01333     int Y;
01335     int Bits;
01337     uint32 *Data;
01338 
01340     GSurface *Create()
01341     {
01342         GSurface *pDC = NEW(GMemDC);
01343         if (pDC->Create(X, Y, Bits))
01344         {
01345             int Line = X * Bits / 8;
01346             for (int y=0; y<Y; y++)
01347             {
01348                 memcpy((*pDC)[y], ((uchar*)Data) + (y * Line), Line);
01349             }
01350         }
01351 
01352         return pDC;
01353     }
01354 };
01355 
01356 // file filter support
01357 #include "GFilter.h"
01358 
01359 // globals
01360 #define GdcD            GdcDevice::GetInst()
01361 
01363 LgiFunc GSurface *ConvertDC
01364 (
01366     GSurface *pDC,
01368     int Bits
01369 );
01370 
01386 LgiFunc GSurface *LoadDC
01387 (
01389     char *Name
01390 );
01391 
01393 LgiFunc bool WriteDC(char *Name, GSurface *pDC);
01394 
01396 LgiFunc COLOUR CBit(int DstBits, COLOUR c, int SrcBits = 24, GPalette *Pal = 0);
01397 
01399 LgiFunc COLOUR GdcMixColour(COLOUR a, COLOUR b, double HowMuchA = 0.5);
01400 
01402 LgiFunc COLOUR GdcGreyScale(COLOUR c, int Bits = 24);
01403 
01405 enum GColourReducePalette
01406 {
01407     CR_PAL_NONE = -1,
01408     CR_PAL_CUBE = 0,
01409     CR_PAL_OPT,
01410     CR_PAL_FILE
01411 };
01412 
01414 enum GColourReduceMatch
01415 {
01416     CR_MATCH_NONE = -1,
01417     CR_MATCH_NEAR = 0,
01418     CR_MATCH_HALFTONE,
01419     CR_MATCH_ERROR
01420 };
01421 
01423 class GReduceOptions
01424 {
01425 public:
01427     GColourReducePalette PalType;
01428     
01430     GColourReduceMatch MatchType;
01431     
01433     int Colours;
01434     
01436     GPalette *Palette;
01437 
01438     GReduceOptions()
01439     {
01440         Palette = 0;
01441         Colours = 256;
01442         PalType = CR_PAL_NONE;
01443         MatchType = CR_MATCH_NONE;
01444     }
01445 };
01446 
01448 LgiFunc bool GReduceBitDepth(GSurface *pDC, int Bits, GPalette *Pal = 0, GReduceOptions *Reduce = 0);
01449 
01450 #endif

Generated on Tue May 2 10:24:41 2006 for Lgi by  doxygen 1.4.1