00001
00008 #ifndef __GDC2_H_
00009 #define __GDC2_H_
00010
00011
00012 #include "LgiDefs.h"
00013 #include "LgiClass.h"
00014 #include "LgiOsDefs.h"
00015
00016 #include "Progress.h"
00017 #include "GFile.h"
00018 #include "GMem.h"
00019 #include "Core.h"
00020 #include "GContainers.h"
00021
00022
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
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
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
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
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
00093 #define GDC_PAL_CHANGE 0x1
00094 #define GDC_BITS_CHANGE 0x2
00095
00096
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
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
00134
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
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
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
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
00158 #define GDCFNT_TRANSPARENT 0x0001 // not set - SOLID
00159 #define GDCFNT_UNDERLINE 0x0002
00160
00161
00162 #define GDCPAL_JASC 1
00163 #define GDCPAL_MICROSOFT 2
00164
00165
00166 #define BMPWIDTH(bits) ((((bits)+31)/32)*4)
00167
00168
00169
00170
00187 typedef uint32 COLOUR;
00188
00190 typedef uint8 ALPHA;
00191
00192
00193
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 #if LGI_LITTLE_ENDIAN
00219 uchar b, g, r;
00220 #else
00221 uchar r, g, b;
00222 #endif
00223
00224 Pixel24 *Next() { return this + 1; }
00225 };
00226
00227 #if LGI_LITTLE_ENDIAN
00228 #define C32B 0
00229 #define C32G 1
00230 #define C32R 2
00231 #define C32A 3
00232 #else
00233 #define C32B 3
00234 #define C32G 2
00235 #define C32R 1
00236 #define C32A 0
00237 #endif
00238
00239 class LgiClass Pixel32
00240 {
00241 public:
00242 static int Size;
00243
00244 #if LGI_LITTLE_ENDIAN
00245 uchar b, g, r, a;
00246 #else
00247 uchar a, r, g, b;
00248 #endif
00249
00250 Pixel32 *Next() { return this + 1; }
00251 };
00252
00253 #elif defined LINUX
00254
00255 #if LGI_LITTLE_ENDIAN
00256 #define C24B 0
00257 #define C24G 1
00258 #define C24R 2
00259 #else
00260 #define C24B 2
00261 #define C24G 1
00262 #define C24R 0
00263 #endif
00264
00265 class LgiClass Pixel24
00266 {
00267 public:
00268 static int Size;
00269
00270 #if LGI_LITTLE_ENDIAN
00271 uchar b, g, r;
00272 #else
00273 uchar r, g, b;
00274 #endif
00275
00276 Pixel24 *Next() { return (Pixel24*) ((char*)this + Size); }
00277 };
00278
00279 #if LGI_LITTLE_ENDIAN
00280 #define C32B 0
00281 #define C32G 1
00282 #define C32R 2
00283 #define C32A 3
00284 #else
00285 #define C32B 3
00286 #define C32G 2
00287 #define C32R 1
00288 #define C32A 0
00289 #endif
00290
00291 class LgiClass Pixel32
00292 {
00293 public:
00294 static int Size;
00295
00296 #if LGI_LITTLE_ENDIAN
00297 uchar b, g, r, a;
00298 #else
00299 uchar a, r, g, b;
00300 #endif
00301
00302 Pixel32 *Next() { return this + 1; }
00303 };
00304
00305 #elif defined BEOS
00306
00307 #if LGI_LITTLE_ENDIAN
00308 #define C24B 0
00309 #define C24G 1
00310 #define C24R 2
00311 #else
00312 #define C24B 2
00313 #define C24G 1
00314 #define C24R 0
00315 #endif
00316
00317 class LgiClass Pixel24
00318 {
00319 public:
00320 static int Size;
00321
00322 #if LGI_LITTLE_ENDIAN
00323 uchar b, g, r;
00324 #else
00325 uchar r, g, b;
00326 #endif
00327
00328 Pixel24 *Next() { return this + 1; }
00329 };
00330
00331 #if LGI_LITTLE_ENDIAN
00332 #define C32B 0
00333 #define C32G 1
00334 #define C32R 2
00335 #define C32A 3
00336 #else
00337 #define C32B 3
00338 #define C32G 2
00339 #define C32R 1
00340 #define C32A 0
00341 #endif
00342
00343 class LgiClass Pixel32
00344 {
00345 public:
00346 static int Size;
00347
00348 #if LGI_LITTLE_ENDIAN
00349 uchar b, g, r, a;
00350 #else
00351 uchar a, r, g, b;
00352 #endif
00353
00354 Pixel32 *Next() { return this + 1; }
00355 };
00356
00357 #endif
00358
00360 #define Rgb15(r, g, b) ( ((r&0xF8)<<7) | ((g&0xF8)<<2) | ((b&0xF8)>>3))
00361 #define Rgb32To15(c32) ( ((c32&0xF8)>>3) | ((c32&0xF800)>>6) | ((c32&0xF80000)>>9) )
00362 #define Rgb24To15(c24) ( (B24(c24)>>3) | ((G24(c24)<<2)&0x3E0) | ((R24(c24)<<7)&0x7C00) )
00363 #define Rgb16To15(c16) ( ((c16&0xFFC0)>>1) | (c16&0x1F) )
00364
00365 #define R15(c15) ( (uchar) ((c15>>10)&0x1F) )
00366
00367 #define G15(c15) ( (uchar) ((c15>>5)&0x1F) )
00368
00369 #define B15(c15) ( (uchar) ((c15)&0x1F) )
00370
00371 #define Rc15(c) ( (((c) & 0x7C00) >> 7) | (((c) & 0x7C00) >> 12) )
00372 #define Gc15(c) ( (((c) & 0x03E0) >> 2) | (((c) & 0x03E0) >> 7) )
00373 #define Bc15(c) ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00374
00376 #define Rgb16(r, g, b) ( ((r&0xF8)<<8) | ((g&0xFC)<<3) | ((b&0xF8)>>3))
00377 #define Rgb32To16(c32) ( ((c32&0xF8)>>3) | ((c32&0xFC00)>>5) | ((c32&0xF80000)>>8) )
00378 #define Rgb24To16(c24) ( (B24(c24)>>3) | ((G24(c24)<<3)&0x7E0) | ((R24(c24)<<8)&0xF800) )
00379 #define Rgb15To16(c15) ( ((c15&0x7FE0)<<1) | (c15&0x1F) )
00380
00381 #define R16(c16) ( (uchar) ((c16>>11)&0x1F) )
00382
00383 #define G16(c16) ( (uchar) ((c16>>5)&0x3F) )
00384
00385 #define B16(c16) ( (uchar) ((c16)&0x1F) )
00386
00387 #define Rc16(c) ( (((c) & 0xF800) >> 8) | (((c) & 0xF800) >> 13) )
00388 #define Gc16(c) ( (((c) & 0x07E0) >> 3) | (((c) & 0x07E0) >> 9) )
00389 #define Bc16(c) ( (((c) & 0x001F) << 3) | (((c) & 0x001F) >> 2) )
00390
00392 #define R24(c24) ( ((c24)>>(C24R*8)) & 0xff )
00393
00394 #define G24(c24) ( ((c24)>>(C24G*8)) & 0xff )
00395
00396 #define B24(c24) ( ((c24)>>(C24B*8)) & 0xff )
00397
00399 #define Rgb24(r, g, b) ( (((r)&0xFF) << (C24R*8)) | (((g)&0xFF) << (C24G*8)) | (((b)&0xFF) << (C24B*8)) )
00400 #define Rgb32To24(c32) Rgb24(R32(c32), G32(c32), B32(c32))
00401 #define Rgb15To24(c15) ( ((c15&0x7C00)>>7) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<19) )
00402 #define Rgb16To24(c16) ( ((c16&0xF800)>>8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<19) )
00403
00404
00405
00406
00407
00408
00409
00411 #define R32(c32) ( (uchar) (c32 >> (C32R*8)) )
00412
00413 #define G32(c32) ( (uchar) (c32 >> (C32G*8)) )
00414
00415 #define B32(c32) ( (uchar) (c32 >> (C32B*8)) )
00416
00417 #define A32(c32) ( (uchar) (c32 >> (C32A*8)) )
00418
00419 #define RgbPreMul(c, a) ( Div255Lut[(c)*a] )
00420 #define Rgb32(r, g, b) ( (((r)&0xFF)<<(C32R*8)) | (((g)&0xFF)<<(C32G*8)) | (((b)&0xFF)<<(C32B*8)) | (0xFF<<(C32A*8)) )
00421 #define Rgba32(r, g, b, a) ( (((r)&0xFF)<<(C32R*8)) | (((g)&0xFF)<<(C32G*8)) | (((b)&0xFF)<<(C32B*8)) | (((a)&0xFF)<<(C32A*8)) )
00422 #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)) )
00423 #define Rgb24To32(c24) Rgba32( R24(c24), G24(c24), B24(c24), 255 )
00424 #define Rgb15To32(c15) ( ((c15&0x7C00)<<9) | ((c15&0x3E0)<<6) | ((c15&0x1F)<<3) | (0xFF<<(C32A*8)) )
00425 #define Rgb16To32(c16) ( ((c16&0xF800)<<8) | ((c16&0x7E0)<<5) | ((c16&0x1F)<<3) | (0xFF<<(C32A*8)) )
00426
00427
00428 #define Hls32(h, l, s) ( ((h)<<16) | ((l)<<8) | (s) )
00429 #define H32(c) ( ((c)>>16)&0xFFFF )
00430 #define L32(c) ( ((c)>>8)&0xFF )
00431 #define S32(c) ( (c)&0xFF )
00432 #define HUE_UNDEFINED 1024
00433 #define HlsIsUndefined(Hls) (H32(Hls) == HUE_UNDEFINED)
00434
00435
00436 #define Div255Lut (GdcDevice::GetInst()->GetDiv255())
00437
00438 LgiFunc COLOUR RgbToHls(COLOUR Rgb24);
00439 LgiFunc COLOUR HlsToRgb(COLOUR Hsl32);
00440
00441 #ifdef WIN32
00442 #pragma pack(pop, before_pack)
00443 #endif
00444
00445
00446 class GFilter;
00447 class GSurface;
00448
00449 #include "GRect.h"
00450 #include "GFont.h"
00451
00453 class LgiClass GdcPt2
00454 {
00455 public:
00456 int x, y;
00457
00458 GdcPt2(int Ix = 0, int Iy = 0)
00459 {
00460 x = Ix;
00461 y = Iy;
00462 }
00463
00464 GdcPt2(const GdcPt2 &p)
00465 {
00466 x = p.x;
00467 y = p.y;
00468 }
00469
00470 bool Inside(GRect &r)
00471 {
00472 return (x >= r.x1) AND
00473 (x <= r.x2) AND
00474 (y >= r.y1) AND
00475 (y <= r.y2);
00476 }
00477 };
00478
00480 class LgiClass GdcPt3
00481 {
00482 public:
00483 int x, y, z;
00484 };
00485
00486 #ifdef WIN32
00487 #pragma pack(push, before_pack)
00488 #pragma pack(1)
00489 #endif
00490
00492 class LgiClass GdcRGB
00493 {
00494 public:
00495 uchar R, G, B, Flags;
00496
00497 void Set(uchar r, uchar g, uchar b, uchar f = 0)
00498 {
00499 R = r;
00500 G = g;
00501 B = b;
00502 Flags = f;
00503 }
00504 };
00505
00506 #ifdef WIN32
00507 #pragma pack(pop, before_pack)
00508 #endif
00509
00511 class LgiClass GPalette
00512 {
00513 protected:
00514 #ifdef WIN32
00515 HPALETTE hPal;
00516 LOGPALETTE *Data;
00517 #else
00518 int Size;
00519 GdcRGB *Data;
00520 #endif
00521 uchar *Lut;
00522
00523 public:
00524 GPalette();
00525 virtual ~GPalette();
00526
00527 #ifdef WIN32
00528 HPALETTE Handle() { return hPal; }
00529 #endif
00530
00531 GPalette(GPalette *pPal);
00532 GPalette(uchar *pPal, int s = 256);
00533 void Set(GPalette *pPal);
00534 void Set(uchar *pPal, int s = 256);
00535
00536 int GetSize();
00537 GdcRGB *operator [](int i);
00538 bool Update();
00539 bool SetSize(int s = 256);
00540 void SwapRAndB();
00541 int MatchRgb(COLOUR Rgb);
00542 void CreateCube();
00543 void CreateGreyScale();
00544 bool Load(GFile &F);
00545 bool Save(GFile &F, int Format);
00546 uchar *MakeLut(int Bits = 16);
00547
00548 bool operator ==(GPalette &p);
00549 bool operator !=(GPalette &p);
00550 };
00551
00552 class LgiClass GBmpMem
00553 {
00554 public:
00555 uchar *Base;
00556 int x, y, Bits, Line;
00557 int Flags;
00558
00559 GBmpMem();
00560 ~GBmpMem();
00561 };
00562
00563
00564 #define GAPP_ALPHA_A 1
00565 #define GAPP_ALPHA_PAL 2
00566 #define GAPP_BACKGROUND 3
00567 #define GAPP_ANGLE 4
00568 #define GAPP_BOUNDS 5
00569
00575 class LgiClass GApplicator
00576 {
00577 protected:
00578 GBmpMem *Dest;
00579 GBmpMem *Alpha;
00580 GPalette *Pal;
00581 int Op;
00582
00583 public:
00584 COLOUR c;
00585
00586 GApplicator() { c = 0; }
00587 GApplicator(COLOUR Colour) { c = Colour; }
00588 virtual ~GApplicator() { }
00589
00591 virtual int GetVar(int Var) { return 0; }
00593 virtual int SetVar(int Var, int Value) { return 0; }
00594
00596 void SetOp(int o) { Op = o; }
00598 int GetOp() { return Op; }
00600 int GetBits() { return (Dest) ? Dest->Bits : 0; }
00602 int GetFlags() { return (Dest) ? Dest->Flags : 0; }
00604 GPalette *GetPal() { return Pal; }
00605
00607 virtual bool SetSurface(GBmpMem *d, GPalette *p = 0, GBmpMem *a = 0) = 0;
00609 virtual void SetPtr(int x, int y) = 0;
00611 virtual void IncX() = 0;
00613 virtual void IncY() = 0;
00615 virtual void IncPtr(int X, int Y) = 0;
00616
00618 virtual void Set() = 0;
00620 virtual COLOUR Get() = 0;
00622 virtual void VLine(int height) = 0;
00624 virtual void Rectangle(int x, int y) = 0;
00626 virtual bool Blt(GBmpMem *Src, GPalette *SPal, GBmpMem *SrcAlpha = 0) = 0;
00627 };
00628
00630 class LgiClass GApplicatorFactory
00631 {
00632 public:
00633 static List<GApplicatorFactory> Factories;
00634
00635 public:
00636 GApplicatorFactory();
00637 virtual ~GApplicatorFactory();
00638
00640 static GApplicator *NewApp(int Bits, int Op);
00641 virtual GApplicator *Create(int Bits, int Op) { return NULL; }
00642 };
00643
00644 #define OrgX(x) x -= OriginX
00645 #define OrgY(y) y -= OriginY
00646 #define OrgXy(x, y) x -= OriginX; y -= OriginY
00647 #define OrgPt(p) p.x -= OriginX; p.y -= OriginY
00648 #define OrgRgn(r) r.Offset(-OriginX, -OriginY)
00649
00651 class LgiClass GDeviceContext
00652 {
00653 friend class GFilter;
00654 friend class GSurface;
00655
00656 protected:
00657 int Flags;
00658 int PrevOp;
00659 GRect Clip;
00660 GBmpMem *pMem;
00661 GSurface *pAlphaDC;
00662 GPalette *pPalette;
00663 GApplicator *pApp;
00664 GApplicator *pAppCache[GDC_CACHE_SIZE];
00665 int OriginX, OriginY;
00666
00667
00668 GApplicator *CreateApplicator(int Op = GDC_SET, int Bits = 0);
00669
00670 public:
00671 GDeviceContext();
00672 virtual ~GDeviceContext();
00673
00674 virtual bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false) { return false; }
00675 virtual void Update(int Flags) {}
00676
00677
00678
00680 virtual bool IsAlpha() { return pAlphaDC != 0; }
00682 virtual bool IsAlpha(bool b);
00684 bool DrawOnAlpha() { return ((Flags & GDC_DRAW_ON_ALPHA) != 0); }
00686 bool DrawOnAlpha(bool Draw);
00688 GSurface *AlphaDC() { return pAlphaDC; }
00689
00690
00691 virtual bool Applicator(GApplicator *pApp);
00692 virtual GApplicator *Applicator();
00693
00694
00695 virtual GPalette *Palette();
00696 virtual void Palette(GPalette *pPal, bool bOwnIt = true);
00697
00698
00699 virtual GRect ClipRgn(GRect *Rgn);
00700 virtual GRect ClipRgn();
00701
00703 virtual COLOUR Colour() { return pApp->c; }
00705 virtual COLOUR Colour
00706 (
00708 COLOUR c,
00710 int Bits = 0
00711 );
00713 virtual int Op() { return (pApp) ? pApp->GetOp() : 0; }
00716 virtual int Op(int Op);
00718 virtual int X() { return (pMem) ? pMem->x : 0; }
00720 virtual int Y() { return (pMem) ? pMem->y : 0; }
00722 virtual int GetBits() { return (pMem) ? pMem->Bits : 0; }
00724 virtual int PixelSize() { return GetBits() == 24 ? Pixel24::Size : GetBits() >> 3; }
00725 virtual int GetFlags() { return Flags; }
00727 virtual bool IsScreen() { return (pApp) ? (pApp->GetFlags() & GDC_ON_SCREEN) != 0 : 0; }
00729 virtual uchar *operator[](int y) { return (pMem AND y>=0 AND y<pMem->y) ? pMem->Base + (pMem->Line * y) : 0; }
00730
00732 virtual void GetOrigin(int &x, int &y) { x = OriginX; y = OriginY; }
00734 virtual void SetOrigin(int x, int y) { OriginX = x; OriginY = y; }
00735 };
00736
00738 class LgiClass GSurface : public GDeviceContext
00739 {
00740 #if defined BEOS || defined LINUX
00741 friend class GView;
00742 friend class GWindow;
00743 #endif
00744
00745 protected:
00746 uint32 LineBits;
00747 uint32 LineMask;
00748 uint32 LineReset;
00749
00750 #ifdef WIN32
00751 HDC hDC;
00752 HBITMAP hBmp;
00753 #endif
00754
00755 public:
00756 GSurface();
00757 GSurface(GSurface *pDC);
00758
00759
00760 #if defined WIN32
00761
00762 virtual HDC StartDC() { return hDC; }
00763 virtual void EndDC() {}
00764 HBITMAP GetBitmap() { return hBmp; }
00765 HDC Handle() { return hDC; }
00766
00767 #else
00768
00769 virtual OsPainter Handle() { return 0; }
00770 virtual OsBitmap GetBitmap() { return 0; }
00771
00772 #endif
00773
00774
00775
00777 virtual void Set(int x, int y);
00779 virtual COLOUR Get(int x, int y);
00780
00781
00782
00784 virtual void HLine(int x1, int x2, int y);
00786 virtual void VLine(int x, int y1, int y2);
00788 virtual void Line(int x1, int y1, int x2, int y2);
00789
00790 virtual uint LineStyle(uint32 Bits, uint32 Reset = 0x80000000)
00791 {
00792 uint32 B = LineBits;
00793 LineBits = Bits;
00794 LineMask = LineReset = Reset;
00795 return B;
00796 }
00797 virtual uint LineStyle() { return LineBits; }
00798
00799
00800
00802 virtual void Circle(double cx, double cy, double radius);
00804 virtual void FilledCircle(double cx, double cy, double radius);
00806 virtual void Arc(double cx, double cy, double radius, double start, double end);
00808 virtual void FilledArc(double cx, double cy, double radius, double start, double end);
00810 virtual void Ellipse(double cx, double cy, double x, double y);
00812 virtual void FilledEllipse(double cx, double cy, double x, double y);
00813
00814
00815
00817 virtual void Box(int x1, int y1, int x2, int y2);
00819 virtual void Box
00820 (
00822 GRect *a = NULL
00823 );
00825 virtual void Rectangle(int x1, int y1, int x2, int y2);
00827 virtual void Rectangle
00828 (
00830 GRect *a = NULL
00831 );
00833 virtual void Blt
00834 (
00836 int x,
00838 int y,
00840 GSurface *Src,
00842 GRect *a = NULL
00843 );
00845 virtual void StretchBlt(GRect *d, GSurface *Src, GRect *s);
00846
00847
00848
00850 virtual void Polygon(int Points, GdcPt2 *Data);
00852 virtual void Bezier(int Threshold, GdcPt2 *Pt);
00854 virtual void FloodFill
00855 (
00857 int x,
00859 int y,
00861 int Mode,
00863 COLOUR Border = 0,
00865 GRect *Bounds = NULL
00866 );
00867 };
00868
00873 class LgiClass GScreenDC : public GSurface
00874 {
00875 class GScreenPrivate *d;
00876
00877 public:
00878 GScreenDC();
00879 virtual ~GScreenDC();
00880
00881
00882 #if defined WIN32
00883
00884 GScreenDC(HWND hwnd);
00885 GScreenDC(HDC hdc, HWND hwnd, bool Release = false);
00886 GScreenDC(HBITMAP hBmp, int Sx, int Sy);
00887
00888 bool Create(HDC hdc);
00889 void SetSize(int x, int y);
00890
00891 #else
00892
00893 GScreenDC(OsView view, void *Param = 0);
00894
00895 OsPainter Handle();
00896 int GetFlags();
00897
00898 #endif
00899
00900
00901 void GetOrigin(int &x, int &y);
00902 void SetOrigin(int x, int y);
00903
00904 GRect ClipRgn();
00905 GRect ClipRgn(GRect *Rgn);
00906
00907 COLOUR Colour();
00908 COLOUR Colour(COLOUR c, int Bits = 0);
00909
00910 int Op();
00911 int Op(int Op);
00912
00913 int X();
00914 int Y();
00915
00916 GPalette *Palette();
00917 void Palette(GPalette *pPal, bool bOwnIt = true);
00918
00919 uint LineStyle();
00920 uint LineStyle(uint Bits, uint32 Reset = 0x80000000);
00921
00922 int GetBits();
00923 bool IsScreen();
00924 uchar *operator[](int y) { return NULL; }
00925
00926
00927 void Set(int x, int y);
00928 COLOUR Get(int x, int y);
00929 void HLine(int x1, int x2, int y);
00930 void VLine(int x, int y1, int y2);
00931 void Line(int x1, int y1, int x2, int y2);
00932 void Circle(double cx, double cy, double radius);
00933 void FilledCircle(double cx, double cy, double radius);
00934 void Arc(double cx, double cy, double radius, double start, double end);
00935 void FilledArc(double cx, double cy, double radius, double start, double end);
00936 void Ellipse(double cx, double cy, double x, double y);
00937 void FilledEllipse(double cx, double cy, double x, double y);
00938 void Box(int x1, int y1, int x2, int y2);
00939 void Box(GRect *a);
00940 void Rectangle(int x1, int y1, int x2, int y2);
00941 void Rectangle(GRect *a = NULL);
00942 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
00943 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
00944 void Polygon(int Points, GdcPt2 *Data);
00945 void Bezier(int Threshold, GdcPt2 *Pt);
00946 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
00947 };
00948
00953 class LgiClass GMemDC : public GSurface
00954 {
00955 protected:
00956 class GMemDCPrivate *d;
00957
00958 #if defined WIN32
00959 PBITMAPINFO GetInfo();
00960 #endif
00961
00962 public:
00964 GMemDC
00965 (
00967 int x = 0,
00969 int y = 0,
00971 int bits = 0
00972 );
00973 GMemDC(GSurface *pDC);
00974 virtual ~GMemDC();
00975
00976 #if defined WIN32
00977
00978 HDC StartDC();
00979 void EndDC();
00980 void Update(int Flags);
00981
00982
00983
00984 GRect ClipRgn(GRect *Rgn);
00985
00986 #else
00987
00988 OsBitmap GetBitmap();
00989 bool IsScreen() { return false; }
00990 GRect ClipRgn() { return Clip; }
00991
00992 OsPainter Handle();
00993 #ifdef XWIN
00994 Pixmap GetPixmap();
00995 Pixmap GetPixmapMask();
00996 #endif
00997
00998 #endif
00999
01001 bool Lock();
01006 bool Unlock();
01007
01008 #ifdef LINUX
01009
01010 uchar *operator[](int y);
01011 #endif
01012
01013 void SetOrigin(int x, int y);
01014
01015 bool Create(int x, int y, int Bits, int LineLen = 0, bool KeepData = false);
01016 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01017 void StretchBlt(GRect *d, GSurface *Src, GRect *s = NULL);
01018
01019 void HLine(int x1, int x2, int y, COLOUR a, COLOUR b);
01020 void VLine(int x, int y1, int y2, COLOUR a, COLOUR b);
01021 };
01022
01028 class LgiClass GPrintDC
01029 #if defined WIN32
01030 : public GScreenDC
01031 #else
01032 : public GSurface
01033 #endif
01034 {
01035 #ifdef LINUX
01036 friend class PrintPainter;
01037 double Xc(int x);
01038 double Yc(int y);
01039 #endif
01040
01041 class GPrintDCPrivate *d;
01042
01043 public:
01044 GPrintDC(void *Handle, char *PrintJobName);
01045 ~GPrintDC();
01046
01047 int X();
01048 int Y();
01049 int GetBits();
01050
01052 int DpiX();
01053
01055 int DpiY();
01056
01058 bool StartPage();
01060 void EndPage();
01061
01062 #if defined LINUX
01063
01064 OsPainter Handle();
01065 COLOUR Colour();
01066 COLOUR Colour(COLOUR c, int Bits = 0);
01067
01068 void Set(int x, int y);
01069 COLOUR Get(int x, int y);
01070 void HLine(int x1, int x2, int y);
01071 void VLine(int x, int y1, int y2);
01072 void Line(int x1, int y1, int x2, int y2);
01073 void Circle(double cx, double cy, double radius);
01074 void FilledCircle(double cx, double cy, double radius);
01075 void Arc(double cx, double cy, double radius, double start, double end);
01076 void FilledArc(double cx, double cy, double radius, double start, double end);
01077 void Ellipse(double cx, double cy, double x, double y);
01078 void FilledEllipse(double cx, double cy, double x, double y);
01079 void Box(int x1, int y1, int x2, int y2);
01080 void Box(GRect *a = NULL);
01081 void Rectangle(int x1, int y1, int x2, int y2);
01082 void Rectangle(GRect *a = NULL);
01083 void Blt(int x, int y, GSurface *Src, GRect *a = NULL);
01084 void StretchBlt(GRect *d, GSurface *Src, GRect *s);
01085 void Polygon(int Points, GdcPt2 *Data);
01086 void Bezier(int Threshold, GdcPt2 *Pt);
01087 void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GRect *Bounds = NULL);
01088
01089 #endif
01090
01091 };
01092
01094 class LgiClass GSprite
01095 {
01096 protected:
01097
01098 int Sx, Sy, Bits;
01099
01100
01101 bool Visible;
01102 int PosX, PosY;
01103 int HotX, HotY;
01104
01105
01106 int DrawMode;
01107
01108
01109
01110 GSurface *pScreen;
01111
01112
01113
01114 GSurface *pBack;
01115 GSurface *pMask;
01116 GSurface *pColour;
01117 GSurface *pTemp;
01118
01119
01120
01121 virtual void DrawOnMove( GSurface *pDC,
01122 int Nx, int Ny,
01123 int Ox, int Oy) {}
01124
01125 public:
01126 GSprite();
01127 virtual ~GSprite();
01128
01129 int X() { return Sx; }
01130 int Y() { return Sy; }
01131 int GetPosX() { return PosX; }
01132 int GetPosY() { return PosY; }
01133 int GetHotX() { return HotX; }
01134 int GetHotY() { return HotY; }
01135 int GetBits() { return Bits; }
01136 bool IsVisible() { return Visible; }
01137
01138 void SetXY(int x, int y);
01139
01140 bool Create(GSurface *pScreen, int x, int y, int Bits, uchar *Colour, uchar *Mask);
01141 bool CreateKey(GSurface *pScreen, int x, int y, int Bits, uchar *Colour, int Key);
01142 bool Create(GSurface *pScreen, GSprite *pSpr);
01143 bool SetSize(int x, int y, int Bits, GSurface *pScr = NULL);
01144 void Delete();
01145
01146 int Mode() { return DrawMode; }
01147 int Mode(int m) { int Old = DrawMode; DrawMode = m; return Old; }
01148
01149
01150
01151
01152
01153 void SetHotPoint(int x, int y);
01154 void SetVisible(bool v);
01155 void Move(int x, int y, bool WaitRetrace);
01156
01157 void Draw(int x, int y, COLOUR Back, int Mode = 0, GSurface *pDC = NULL);
01158
01159
01160
01161
01162
01163
01164 void MoveToScreen(GSurface *Scr)
01165 {
01166 bool v = Visible;
01167 SetVisible(false);
01168 pScreen = Scr;
01169 SetVisible(v);
01170 }
01171 GSurface *GetMask() { return pMask; }
01172 GSurface *GetColour() { return pColour; }
01173 };
01174
01175 class LgiClass GGlobalColour
01176 {
01177 class GGlobalColourPrivate *d;
01178
01179 public:
01180 GGlobalColour();
01181 ~GGlobalColour();
01182
01183
01184 COLOUR AddColour(COLOUR c24);
01185 bool AddBitmap(GSurface *pDC);
01186 bool AddBitmap(GImageList *il);
01187
01188
01189 bool MakeGlobalPalette();
01190
01191
01192
01193 GPalette *GetPalette();
01194
01195
01196 COLOUR GetColour(COLOUR c24);
01197 bool RemapBitmap(GSurface *pDC);
01198 };
01199
01200 #ifdef WIN32
01201 typedef int (__stdcall *MsImg32_AlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
01202 #endif
01203
01205 class LgiClass GdcDevice
01206 {
01207 friend class GScreenDC;
01208 static GdcDevice *pInstance;
01209 class GdcDevicePrivate *d;
01210 #ifdef WIN32
01211 MsImg32_AlphaBlend AlphaBlend;
01212 #endif
01213
01214 public:
01215 GdcDevice();
01216 ~GdcDevice();
01217 static GdcDevice *GetInst() { return pInstance; }
01218
01220 int GetBits();
01222 int X();
01224 int Y();
01225
01226 GGlobalColour *GetGlobalColour();
01227
01229 int GetOption(int Opt);
01231 int SetOption(int Opt, int Value);
01232
01234 ulong *GetCharSquares();
01236 uchar *GetDiv255();
01237
01238
01239 void SetGamma(double Gamma);
01240 double GetGamma();
01241
01242
01243 void SetSystemPalette(int Start, int Size, GPalette *Pal);
01244 GPalette *GetSystemPalette();
01245 void SetColourPaletteType(int Type);
01246 COLOUR GetColour(COLOUR Rgb24, GDeviceContext *pDC = NULL);
01247
01248
01249 GLibrary *GetIconv();
01250 };
01251
01263 class GInlineBmp
01264 {
01265 public:
01267 int X;
01269 int Y;
01271 int Bits;
01273 uint32 *Data;
01274
01276 GSurface *Create()
01277 {
01278 GSurface *pDC = NEW(GMemDC);
01279 if (pDC->Create(X, Y, Bits))
01280 {
01281 int Line = X * Bits / 8;
01282 for (int y=0; y<Y; y++)
01283 {
01284 memcpy((*pDC)[y], ((uchar*)Data) + (y * Line), Line);
01285 }
01286 }
01287
01288 return pDC;
01289 }
01290 };
01291
01292
01293 #include "GFilter.h"
01294
01295
01296 #define GdcD GdcDevice::GetInst()
01297
01299 LgiFunc GSurface *ConvertDC
01300 (
01302 GSurface *pDC,
01304 int Bits
01305 );
01306
01322 LgiFunc GSurface *LoadDC
01323 (
01325 char *Name
01326 );
01327
01329 LgiFunc bool WriteDC(char *Name, GSurface *pDC);
01330
01332 LgiFunc COLOUR CBit(int DstBits, COLOUR c, int SrcBits = 24, GPalette *Pal = 0);
01333
01335 LgiFunc COLOUR GdcMixColour(COLOUR a, COLOUR b, double HowMuchA = 0.5);
01336
01338 LgiFunc COLOUR GdcGreyScale(COLOUR c, int Bits = 24);
01339
01341 enum GColourReducePalette
01342 {
01343 CR_PAL_NONE = -1,
01344 CR_PAL_CUBE = 0,
01345 CR_PAL_OPT,
01346 CR_PAL_FILE
01347 };
01348
01350 enum GColourReduceMatch
01351 {
01352 CR_MATCH_NONE = -1,
01353 CR_MATCH_NEAR = 0,
01354 CR_MATCH_HALFTONE,
01355 CR_MATCH_ERROR
01356 };
01357
01359 class GReduceOptions
01360 {
01361 public:
01363 GColourReducePalette PalType;
01364
01366 GColourReduceMatch MatchType;
01367
01369 int Colours;
01370
01372 GPalette *Palette;
01373
01374 GReduceOptions()
01375 {
01376 Palette = 0;
01377 Colours = 256;
01378 PalType = CR_PAL_NONE;
01379 MatchType = CR_MATCH_NONE;
01380 }
01381 };
01382
01384 LgiFunc bool GReduceBitDepth(GSurface *pDC, int Bits, GPalette *Pal = 0, GReduceOptions *Reduce = 0);
01385
01386 #endif