diff --git a/src/lib/objgfx40/Makefile b/src/lib/objgfx40/Makefile index dc4c1d2..8653ed7 100644 --- a/src/lib/objgfx40/Makefile +++ b/src/lib/objgfx40/Makefile @@ -8,7 +8,7 @@ REMOVE = rm -f #Objects -OBJS = vWidget.o vWindow.o objgfx40.o ogFont.o ogSprite.o ogBlit.o ogPixCon.o +OBJS = objgfx40.o ogFont.o ogSprite.o ogBlit.o ogPixCon.o ogPixelFmt.o #Include INCLUDE = -I./ -I../../lib/libc/include -I../../lib/libcpp/include diff --git a/src/lib/objgfx40/main.cpp b/src/lib/objgfx40/main.cpp index f0b450d..d9cab6c 100644 --- a/src/lib/objgfx40/main.cpp +++ b/src/lib/objgfx40/main.cpp @@ -1,610 +1,610 @@ -/********************************************************************** -will add copyright bs later - -$Id$ -**********************************************************************/ - -#include "ogPixCon.h" -#include "objgfx40.h" -#include "ogFont.h" -#include "ogSprite.h" -#include "ogBlit.h" -#ifdef __DJGPP__ -#include "ogDisplay_VESA.h" -#endif -#include -#include -#include -#include - -using namespace std; - -void -testPixCon(void) { - ogSurface * buf1 = new ogSurface(); - ogSurface * buf2 = new ogSurface(); - ogPixCon * pixCon = new ogPixCon(OG_PIXFMT_32BPP, OG_PIXFMT_16BPP); - uInt8 r, g, b; - - buf1->Create(100, 100, OG_PIXFMT_32BPP); - buf2->Create(100, 200, OG_PIXFMT_16BPP); - - buf1->SetPixel(0, 0, buf1->Pack(128, 42, 69)); - buf2->SetPixel(0, 0, pixCon->ConvPix(buf1->GetPixel(0, 0))); - - buf2->Unpack(buf2->GetPixel(0, 0), r, g, b); -// cout << "r: " << (uInt32)r << endl; -// cout << "g: " << (uInt32)g << endl; -// cout << "b: " << (uInt32)b << endl; - return; -}; // textPixCon - -void testSetPixel(ogSurface& buf) { - uInt32 xx,yy; - buf.Clear(buf.Pack(0,255,0)); - for (yy = 0; yy<=buf.GetMaxY(); yy++) - for (xx = 0; xx<=buf.GetMaxX(); xx++) - buf.SetPixel(xx,yy,xx*yy); - getc(stdin); - return; -} // testSetPixel - -void testRect(ogSurface& buf) { - uInt32 count; - if (buf.GetBPP()==8) - for (count=0; count<1000; count++) - buf.Rect(buf.GetMaxX() / 2 - count, buf.GetMaxY() / 2 - count, - buf.GetMaxX() / 2 + count, buf.GetMaxY() / 2 + count, - count); - else - for (count=0; count<1000; count++) - buf.Rect(buf.GetMaxX() / 2 - count, buf.GetMaxY() / 2 - count, - buf.GetMaxX() / 2 + count, buf.GetMaxY() / 2 + count, - buf.Pack(count,count,count)); - getc(stdin); - return; -} // testRect - -void testLine(ogSurface & buf) { - uInt32 count; - uInt32 colour; - buf.Clear(buf.Pack(0, 0, 0)); - for (count = 150; count > 0; count--) { - buf.Line(buf.GetMaxX() / 2, buf.GetMaxY() / 2, - buf.GetMaxX(), count*4, buf.Pack(192, 192, 192)); - } // for count - getc(stdin); - if (buf.GetBPP()==8) - for (count=0; count<(buf.GetMaxX()+1); count+=2) { - buf.Line(count-10,-10,buf.GetMaxX()-count+10,buf.GetMaxY()+10,count); - } // for - else { - colour = 255; - for (count = 0; count < (buf.GetMaxX()+1)/2; count+=4) { - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX()/2-count,buf.GetMaxY(), - buf.Pack(colour,colour,colour)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX()/2+count,buf.GetMaxY(), - buf.Pack(colour,colour,colour)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX()/2-count,0, - buf.Pack(0,colour,0)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX()/2+count,0, - buf.Pack(0,colour,0)); - - --colour; - } // for - - colour = 255; - for (count = 0; count < (buf.GetMaxY()+1)/2; count+=4) { - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - 0, buf.GetMaxY()/2-count, - buf.Pack(colour,0,0)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - 0, buf.GetMaxY()/2+count, - buf.Pack(colour,0,0)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX(), buf.GetMaxY()/2-count, - buf.Pack(0,0,colour)); - buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, - buf.GetMaxX(), buf.GetMaxY()/2+count, - buf.Pack(0,0,colour)); - --colour; - } // for - } // else - getc(stdin); - return; -} // testLine - -void testClear(ogSurface & buf) { - uInt32 count; - if (buf.GetBPP()==8) - for (count=0; count<256; count++) - buf.Clear(count); - else { - for (count=0; count<256; count+=8) - buf.Clear(buf.Pack(count,0,0)); - for (count=0; count<256; count+=8) - buf.Clear(buf.Pack(0,count,0)); - for (count=0; count<256; count+=8) - buf.Clear(buf.Pack(0,0,count)); - for (count=0; count<256; count+=8) - buf.Clear(buf.Pack(count,count,count)); - } // else - getc(stdin); - return; -} // testClear - -void testCircle(ogSurface & buf) { - uInt32 count; - if (buf.GetBPP()==8) - for (count=0; count<1000; count++) - buf.Circle(buf.GetMaxX()/2,buf.GetMaxY()/2, count, count); - else - for (count=0; count<1000; count++) - buf.Circle(buf.GetMaxX()/2,buf.GetMaxY()/2,count,buf.Pack(count,0,count)); - getc(stdin); -} // testCircle - -void testVFlip(ogSurface & buf) { - buf.VFlip(); - getc(stdin); - return; -} // testVFlip - -void testHFlip(ogSurface & buf) { - buf.HFlip(); - getc(stdin); - return; -} // testHFlip - -void testArc(ogSurface & buf) { - uInt32 radius; - uInt32 mid_x, mid_y; - mid_x = buf.GetMaxX()/2; - mid_y = buf.GetMaxY()/2; - if (buf.GetBPP()==8) { - for (radius = 1; radius <9; radius++) { - buf.Arc(mid_x, mid_y, radius*10, 0, 90, radius*15); - buf.Arc(mid_x, mid_y, radius*10, 180,270, 249-(radius-1)*16); - } // for - } else { - for (radius = 1; radius <255; radius++) { - buf.Arc(mid_x, mid_y, radius, 0, 90, buf.Pack(radius,radius,0)); - buf.Arc(mid_x, mid_y, radius, 180,270,buf.Pack(0,255-radius,255-radius)); - } // for - } // else - getchar(); - return; -} // testArc - -void testCubicBezierCurve(ogSurface & buf) { - buf.CubicBezierCurve(100, 100, - 300,50, - 400,120, - 350,300, - 25, buf.Pack(255,255,255)); - getchar(); - return; -} // testCubicBezierCurve - -void testCurve(ogSurface & buf) { - buf.Curve(10,10,100,30,35,160,20,buf.Pack(255,255,255)); - getchar(); - return; -} // testCurve -void testSprite(ogSurface & buf) { - uInt32 count; - uInt32 w,h; - ogSprite * sprite = NULL; - sprite = new ogSprite(); - - buf.Clear(buf.Pack(0, 0, 0)); - testLine(buf); - if (buf.GetBPP()==8) - sprite->Get(buf, - buf.GetMaxX()/2-80,buf.GetMaxY()/2-80, - buf.GetMaxX()/2+80,buf.GetMaxY()/2+80); - else - sprite->Get(buf, - buf.GetMaxX()/2-150,buf.GetMaxY()/2-150, - buf.GetMaxX()/2+150,buf.GetMaxY()/2+150); - - sprite->Save("test.spr"); - delete sprite; - sprite = new ogSprite(); - sprite->Load("test.spr"); - w = sprite->GetWidth()/2; - h = sprite->GetHeight()/2; - buf.Clear(buf.Pack(0, 0, 0)); - sprite->Put(buf,-10000,-10000); // test *really* off the screen - sprite->Put(buf,10000,10000); // test *really* off the screen - - sprite->Put(buf,buf.GetMaxX()/2-w,buf.GetMaxY()/2-h); - sprite->Put(buf,-w,-h); - sprite->Put(buf,buf.GetMaxX()/2-w,-h); - sprite->Put(buf,buf.GetMaxX()-w,-h); - sprite->Put(buf,-w,buf.GetMaxY()/2-h); - sprite->Put(buf,buf.GetMaxX()-w,buf.GetMaxY()/2-h); - sprite->Put(buf,-w,buf.GetMaxY()-h); - sprite->Put(buf,buf.GetMaxX()/2-w,buf.GetMaxY()-h); - sprite->Put(buf,buf.GetMaxX()-w,buf.GetMaxY()-h); - getc(stdin); - for (count = 0; count < 256; count++) { - sprite->Put(buf,random() % (buf.GetMaxX()+sprite->GetWidth()) - sprite->GetWidth(), - random() % (buf.GetMaxY()+sprite->GetHeight()) - sprite->GetHeight()); - } // for - delete sprite; - getc(stdin); - return; -} // testSprite - -void testBlit(ogSurface & buf) { - int32 xx, yy, count; - ogBlit * blit = NULL; - ogBlit * blit2 = NULL; - - blit = new ogBlit(); - - buf.Clear(buf.Pack(0, 0, 0)); - for (xx= 0; xx<= 20; xx++) { - buf.Line(128,0,128-xx*6,255,buf.Pack(255,255,255)); - buf.Line(128,0,128+xx*6,255,buf.Pack(255,255,255)); - buf.Line(128,255,128-xx*6,0,buf.Pack(255,255,255)); - buf.Line(128,255,128+xx*6,0,buf.Pack(255,255,255)); - } // for - - buf.FillCircle(128,128,60,buf.Pack(255,255,255)); - blit->Get(buf,0,0,255,255); - for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) - for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) - buf.SetPixel(xx,yy,xx*yy); - blit->Save("test.blt"); - blit2 = new ogBlit(*blit, true); - - delete blit; - blit2->Save("test2.blt"); - blit = new ogBlit(); - blit->Load("test.blt"); - - blit->Put(buf,-10000,-10000); // test *really* off the screen - blit->Put(buf,10000,10000); // test *really* off the screen - - blit->Put(buf,-128,-128); - blit->Put(buf,buf.GetMaxX()/2-128,-128); - blit->Put(buf,buf.GetMaxX()-128,-128); - blit->Put(buf,-128,buf.GetMaxY()/2-128); - blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); - blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()/2-128); - blit->Put(buf,-128,buf.GetMaxY()-128); - blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()-128); - blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()-128); - - getc(stdin); - buf.Clear(buf.Pack(0, 0, 0)); - for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) - for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) - buf.SetPixel(xx,yy,xx*yy); - blit->GetBlitWithMask(buf, - buf.GetMaxX()/2-blit->GetWidth(), - buf.GetMaxY()/2-blit->GetHeight()); - buf.Clear(buf.Pack(0, 0, 0)); - blit->Put(buf,-10000,-10000); // test *really* off the screen - blit->Put(buf,10000,10000); // test *really* off the screen - - blit->Put(buf,-128,-128); - blit->Put(buf,buf.GetMaxX()/2-128,-128); - blit->Put(buf,buf.GetMaxX()-128,-128); - blit->Put(buf,-128,buf.GetMaxY()/2-128); - blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); - blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()/2-128); - blit->Put(buf,-128,buf.GetMaxY()-128); - blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()-128); - blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()-128); - - getc(stdin); - for (count = 0; count < 1000; count++) { - blit->Put(buf,random() % (buf.GetMaxX()+blit->GetWidth()) - blit->GetWidth(), - random() % (buf.GetMaxY()+blit->GetHeight()) - blit->GetHeight()); - } // for - getc(stdin); - for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) - for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) - buf.SetPixel(xx,yy,xx*yy); - - blit->GetBlitWithMask(buf,buf.GetMaxX()/2,buf.GetMaxY()-128); - buf.Clear(buf.Pack(128,128,128)); - blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); - getc(stdin); - delete blit; - delete blit2; - - return; -} // testBlit - -void -testBlit2(ogSurface & buf) { - ogBlit * blit = new ogBlit(); - ogSurface * buf2 = new ogSurface(); - ogSurface * blitsource = new ogSurface(); - uInt32 xx,yy,count,colour; - buf.Clear(buf.Pack(0, 0, 0)); - if (!buf2->Clone(buf)) cout << "Clone failed!!!" << endl; - if (!blitsource->Clone(buf)) cout << "Clone failed!!" << endl; - - colour = 255; - for (count = 0; count < (buf2->GetMaxX()+1)/2; count+=4) { - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX()/2-count,buf2->GetMaxY(), - buf2->Pack(colour,colour,colour)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX()/2+count,buf2->GetMaxY(), - buf2->Pack(colour,colour,colour)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX()/2-count,0, - buf2->Pack(0,colour,0)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX()/2+count,0, - buf2->Pack(0,colour,0)); - --colour; - } // for - - colour = 255; - for (count = 0; count < (buf.GetMaxY()+1)/2; count+=4) { - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - 0, buf2->GetMaxY()/2-count, - buf2->Pack(colour,0,0)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - 0, buf2->GetMaxY()/2+count, - buf2->Pack(colour,0,0)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX(), buf2->GetMaxY()/2-count, - buf2->Pack(0,0,colour)); - buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, - buf2->GetMaxX(), buf2->GetMaxY()/2+count, - buf2->Pack(0,0,colour)); - --colour; - } // for - for (yy = 0; yy<=buf2->GetMaxY(); yy++) - for (xx = 0; xx<=buf2->GetMaxX(); xx++) - buf2->SetPixel(xx,yy, xx*yy); - for (count = 0; count<200; count++) - blitsource->FillCircle(random() % blitsource->GetMaxX(), random() % blitsource->GetMaxY(), - random() % 35+1,blitsource->Pack(255,255,255)); - - blit->Get(*blitsource,0,0,blitsource->GetMaxX(),blitsource->GetMaxY()); - blit->Save("bigblit.blt"); - delete blit; - blit = new ogBlit; - blit->Load("bigblit.blt"); - for (count = 0; count<=256; count+=4) { - for (yy = 0; yy<=buf2->GetMaxY(); yy++) - for (xx = 0; xx<=buf2->GetMaxX(); xx++) - buf2->SetPixel(xx,yy,xx*yy*count); - - blit->GetBlitWithMask(*buf2,0,0); - blit->Put(buf,0,0); - } // for - - getc(stdin); - delete blitsource; - delete buf2; - delete blit; - return; -} // testBlit2 - -void -testBlit3(ogSurface & buf) { - int32 count; - ogBlit * blit = NULL; - ogSurface * buf2 = NULL; - buf2 = new ogSurface(); - blit = new ogBlit(); - buf.Clear(buf.Pack(0, 0, 0)); - buf.FillCircle(buf.GetMaxX()/2,buf.GetMaxY()/2,14,buf.Pack(255,255,255)); - blit->Get(buf,buf.GetMaxX()/2-20,buf.GetMaxY()/2-20, - buf.GetMaxX()/2+20,buf.GetMaxY()/2+20); - blit->Put(buf,0,0); - for (count=0; count<(int32)buf.GetMaxX(); count++) - buf.Line(count,0,count,buf.GetMaxY(),count); - buf2->Clone(buf); - blit->GetBlitWithMask(*buf2,10,10); - buf.Clear(buf.Pack(63,63,63)); - for (count=-40; count<(int32)buf.GetMaxX()+10; count++) { - blit->GetBlitWithMask(*buf2,count,buf2->GetMaxY()/2-20); - blit->Put(buf,count,buf.GetMaxY()/2-20); - blit->GetBlitWithMask(*buf2,buf2->GetMaxX()/2-20,count); - blit->Put(buf,buf.GetMaxX()/2-20,count); - } - getc(stdin); - delete blit; - return; -} // testBlit3 - -void -testSaveLoadPal(ogSurface & buf) { - uInt32 count; - testRect(buf); - for (count=0; count<256; count++) - buf.SetPalette(count,count,count,count); - if (buf.SavePalette("test.pal")==false) cout << "SavePal() failed" << endl; - for (count=0; count<256; count++) - buf.SetPalette(count,0,0,0); - if (buf.LoadPalette("test.pal")==false) cout << "LoadPal() failed" << endl; - testRect(buf); -} // testSaveLoadPal - -void -testPolygon(ogSurface & buf) { - ogPoint2d points[16]; - uInt32 count; - buf.Clear(buf.Pack(0, 0, 0)); - for (count=0; count<16; count++) { - points[count].x = random() % buf.GetMaxX(); - points[count].y = random() % buf.GetMaxY(); - } // for - buf.FillPolygon(16, points, buf.Pack(random() & 255,random() & 255,random() & 255)); - getc(stdin); - return; -} // testPolygon - -void -testSpline(ogSurface & buf) { - ogPoint2d points[8]; - uInt32 i; - for (i=0; i<8; i++) { - points[i].x = random() % buf.GetMaxX(); - points[i].y = random() % buf.GetMaxY(); - } // for - buf.Clear(buf.Pack(0, 0, 0)); - buf.Polygon(8, points, buf.Pack(22,229,52)); - buf.Spline(8, points, 24, buf.Pack(64,64,255)); - buf.BSpline(8, points, 24, buf.Pack(255,128,128)); - getchar(); - return; -} // testSpline - -void -testFont(ogSurface & buf) { - uInt32 xx, yy; - ogBitFont * font = new ogBitFont(); - font->Load("SCRIPT.DPF", 0); - font->SetFGColor(255, 255, 255, 255); - font->SetBGColor(0, 0, 0, 255); - - font->PutString(buf, 0, 0, "abAByzYZ"); - - for (yy = 0; yyGetHeight(); yy++) { - for (xx = 0; xx<79; xx++) - if ((buf.GetPixel(xx, yy) & buf.GetAlphaMasker()) == 0) - cout << " "; - else - cout << "*"; - cout << endl; - } - - delete font; - return; -} // testFont - -void -testGouraud(ogSurface & buf) { - uInt8 r, g, b; - ogPoint2d points[4]; - ogRGBA8 colours[4]; - r = g = b = 0; - - points[0].x = buf.GetMaxX() - 150; - points[0].y = 0; - points[1].x = buf.GetMaxX(); - points[1].y = 0; - points[2].x = buf.GetMaxX(); - points[2].y = 150; - points[3].x = buf.GetMaxX() - 250; - points[3].y = 250; - colours[0].red = 255; - colours[0].green = 0; - colours[0].blue = 0; - colours[0].alpha = 255; - colours[1].red = 0; - colours[1].green = 255; - colours[1].blue = 128; - colours[1].alpha = 255; - colours[2].red = 128; - colours[2].green = 255; - colours[2].blue = 128; - colours[2].alpha = 255; - colours[3].red = 63; - colours[3].green = 63; - colours[3].blue = 63; - colours[3].alpha = 255; - buf.FillGouraudPolygon(4, points, colours); - getc(stdin); - return; -} // testGouraud - -void -testCopyBuf(ogSurface & buf) { - ogSurface * buf2 = new ogSurface(); - ogPixelFmt pixFmt; - buf.GetPixFmt(pixFmt); - buf2->Create(400, 400, OG_PIXFMT_32BPP); - buf2->Clear(buf2->Pack(255, 128, 255)); - buf.CopyBuf(0, 0, *buf2, 0, 0, buf2->GetMaxX(), buf2->GetMaxY()); - delete buf2; - getc(stdin); - return; -} - -void -testFillRect(ogSurface & buf) { - uInt32 count; - for (count = 100; count > 0; count--) { - buf.FillRect(count, count, 0, 0, buf.Pack(count*2, count*2, count*2)); - } - getc(stdin); - - return; -} // testFillRect() -int main() { - ogSurface* buf = NULL; - -#ifdef __DJGPP__ - buf = new ogDisplay_VESA(); - buf->Create(800, 600, OG_PIXFMT_16BPP); -#else - buf = new ogSurface(); - if (buf->Create(1024, 768, OG_PIXFMT_16BPP)==false) exit(1); -#endif - srandom(time(NULL)); - -// buf->SetBlending(true); -// buf->SetAlpha(127); - buf->SetAntiAliasing(true); - -//cout << "testPixCon()" << endl; -// testPixCon(); - cout << "testFillRect()" << endl; - testFillRect(*buf); - cout << "testCopyBuf()" << endl; - testCopyBuf(*buf); - cout << "testGouraud()" << endl; - testGouraud(*buf); - cout << "testFont()" << endl; - testFont(*buf); - cout << "TestRect()" << endl; - testRect(*buf); - cout << "testCircle()" << endl; - testCircle(*buf); - cout << "TestLine()" << endl; - testLine(*buf); -cout << "TestVFlip()" << endl; - testVFlip(*buf); -cout << "TestHFlip()" << endl; - testHFlip(*buf); -cout << "TestArc()" << endl; - testArc(*buf); -cout << "TestSetPixel()" << endl; - testSetPixel(*buf); -cout << "TestClear()" << endl; - testClear(*buf); -cout << "TestSprite()" << endl; - testSprite(*buf); -cout << "TestBlit()" << endl; - testBlit(*buf); -cout << "TestBlit2()" << endl; - testBlit2(*buf); -// testBlit3(*buf); // special test for 320x200x8bpp -// testSaveLoadPal(*buf); // use an 8bpp mode -cout << "TestPolygon()" << endl; - testPolygon(*buf); -cout << "TestCurve()" << endl; - testCurve(*buf); -cout << "TestSpline()" << endl; - testSpline(*buf); - delete buf; -// buf->SetPixel(0, 0, buf->Pack(0, 0, 0)); - return(0); -} +/********************************************************************** +will add copyright bs later + +$Id$ +**********************************************************************/ + +#include "ogPixCon.h" +#include "objgfx40.h" +#include "ogFont.h" +#include "ogSprite.h" +#include "ogBlit.h" +#ifdef __DJGPP__ +#include "ogDisplay_VESA.h" +#endif +#include +#include +#include +#include + +using namespace std; + +void +testPixCon(void) { + ogSurface * buf1 = new ogSurface(); + ogSurface * buf2 = new ogSurface(); + ogPixCon * pixCon = new ogPixCon(OG_PIXFMT_32BPP, OG_PIXFMT_16BPP); + uInt8 r, g, b; + + buf1->Create(100, 100, OG_PIXFMT_32BPP); + buf2->Create(100, 200, OG_PIXFMT_16BPP); + + buf1->SetPixel(0, 0, buf1->Pack(128, 42, 69)); + buf2->SetPixel(0, 0, pixCon->ConvPix(buf1->GetPixel(0, 0))); + + buf2->Unpack(buf2->GetPixel(0, 0), r, g, b); +// cout << "r: " << (uInt32)r << endl; +// cout << "g: " << (uInt32)g << endl; +// cout << "b: " << (uInt32)b << endl; + return; +}; // textPixCon + +void testSetPixel(ogSurface& buf) { + uInt32 xx,yy; + buf.Clear(buf.Pack(0,255,0)); + for (yy = 0; yy<=buf.GetMaxY(); yy++) + for (xx = 0; xx<=buf.GetMaxX(); xx++) + buf.SetPixel(xx,yy,xx*yy); + getc(stdin); + return; +} // testSetPixel + +void testRect(ogSurface& buf) { + uInt32 count; + if (buf.GetBPP()==8) + for (count=0; count<1000; count++) + buf.Rect(buf.GetMaxX() / 2 - count, buf.GetMaxY() / 2 - count, + buf.GetMaxX() / 2 + count, buf.GetMaxY() / 2 + count, + count); + else + for (count=0; count<1000; count++) + buf.Rect(buf.GetMaxX() / 2 - count, buf.GetMaxY() / 2 - count, + buf.GetMaxX() / 2 + count, buf.GetMaxY() / 2 + count, + buf.Pack(count,count,count)); + getc(stdin); + return; +} // testRect + +void testLine(ogSurface & buf) { + uInt32 count; + uInt32 colour; + buf.Clear(buf.Pack(0, 0, 0)); + for (count = 150; count > 0; count--) { + buf.Line(buf.GetMaxX() / 2, buf.GetMaxY() / 2, + buf.GetMaxX(), count*4, buf.Pack(192, 192, 192)); + } // for count + getc(stdin); + if (buf.GetBPP()==8) + for (count=0; count<(buf.GetMaxX()+1); count+=2) { + buf.Line(count-10,-10,buf.GetMaxX()-count+10,buf.GetMaxY()+10,count); + } // for + else { + colour = 255; + for (count = 0; count < (buf.GetMaxX()+1)/2; count+=4) { + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX()/2-count,buf.GetMaxY(), + buf.Pack(colour,colour,colour)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX()/2+count,buf.GetMaxY(), + buf.Pack(colour,colour,colour)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX()/2-count,0, + buf.Pack(0,colour,0)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX()/2+count,0, + buf.Pack(0,colour,0)); + + --colour; + } // for + + colour = 255; + for (count = 0; count < (buf.GetMaxY()+1)/2; count+=4) { + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + 0, buf.GetMaxY()/2-count, + buf.Pack(colour,0,0)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + 0, buf.GetMaxY()/2+count, + buf.Pack(colour,0,0)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX(), buf.GetMaxY()/2-count, + buf.Pack(0,0,colour)); + buf.Line(buf.GetMaxX()/2, buf.GetMaxY()/2, + buf.GetMaxX(), buf.GetMaxY()/2+count, + buf.Pack(0,0,colour)); + --colour; + } // for + } // else + getc(stdin); + return; +} // testLine + +void testClear(ogSurface & buf) { + uInt32 count; + if (buf.GetBPP()==8) + for (count=0; count<256; count++) + buf.Clear(count); + else { + for (count=0; count<256; count+=8) + buf.Clear(buf.Pack(count,0,0)); + for (count=0; count<256; count+=8) + buf.Clear(buf.Pack(0,count,0)); + for (count=0; count<256; count+=8) + buf.Clear(buf.Pack(0,0,count)); + for (count=0; count<256; count+=8) + buf.Clear(buf.Pack(count,count,count)); + } // else + getc(stdin); + return; +} // testClear + +void testCircle(ogSurface & buf) { + uInt32 count; + if (buf.GetBPP()==8) + for (count=0; count<1000; count++) + buf.Circle(buf.GetMaxX()/2,buf.GetMaxY()/2, count, count); + else + for (count=0; count<1000; count++) + buf.Circle(buf.GetMaxX()/2,buf.GetMaxY()/2,count,buf.Pack(count,0,count)); + getc(stdin); +} // testCircle + +void testVFlip(ogSurface & buf) { + buf.VFlip(); + getc(stdin); + return; +} // testVFlip + +void testHFlip(ogSurface & buf) { + buf.HFlip(); + getc(stdin); + return; +} // testHFlip + +void testArc(ogSurface & buf) { + uInt32 radius; + uInt32 mid_x, mid_y; + mid_x = buf.GetMaxX()/2; + mid_y = buf.GetMaxY()/2; + if (buf.GetBPP()==8) { + for (radius = 1; radius <9; radius++) { + buf.Arc(mid_x, mid_y, radius*10, 0, 90, radius*15); + buf.Arc(mid_x, mid_y, radius*10, 180,270, 249-(radius-1)*16); + } // for + } else { + for (radius = 1; radius <255; radius++) { + buf.Arc(mid_x, mid_y, radius, 0, 90, buf.Pack(radius,radius,0)); + buf.Arc(mid_x, mid_y, radius, 180,270,buf.Pack(0,255-radius,255-radius)); + } // for + } // else + getchar(); + return; +} // testArc + +void testCubicBezierCurve(ogSurface & buf) { + buf.CubicBezierCurve(100, 100, + 300,50, + 400,120, + 350,300, + 25, buf.Pack(255,255,255)); + getchar(); + return; +} // testCubicBezierCurve + +void testCurve(ogSurface & buf) { + buf.Curve(10,10,100,30,35,160,20,buf.Pack(255,255,255)); + getchar(); + return; +} // testCurve +void testSprite(ogSurface & buf) { + uInt32 count; + uInt32 w,h; + ogSprite * sprite = NULL; + sprite = new ogSprite(); + + buf.Clear(buf.Pack(0, 0, 0)); + testLine(buf); + if (buf.GetBPP()==8) + sprite->Get(buf, + buf.GetMaxX()/2-80,buf.GetMaxY()/2-80, + buf.GetMaxX()/2+80,buf.GetMaxY()/2+80); + else + sprite->Get(buf, + buf.GetMaxX()/2-150,buf.GetMaxY()/2-150, + buf.GetMaxX()/2+150,buf.GetMaxY()/2+150); + + sprite->Save("test.spr"); + delete sprite; + sprite = new ogSprite(); + sprite->Load("test.spr"); + w = sprite->GetWidth()/2; + h = sprite->GetHeight()/2; + buf.Clear(buf.Pack(0, 0, 0)); + sprite->Put(buf,-10000,-10000); // test *really* off the screen + sprite->Put(buf,10000,10000); // test *really* off the screen + + sprite->Put(buf,buf.GetMaxX()/2-w,buf.GetMaxY()/2-h); + sprite->Put(buf,-w,-h); + sprite->Put(buf,buf.GetMaxX()/2-w,-h); + sprite->Put(buf,buf.GetMaxX()-w,-h); + sprite->Put(buf,-w,buf.GetMaxY()/2-h); + sprite->Put(buf,buf.GetMaxX()-w,buf.GetMaxY()/2-h); + sprite->Put(buf,-w,buf.GetMaxY()-h); + sprite->Put(buf,buf.GetMaxX()/2-w,buf.GetMaxY()-h); + sprite->Put(buf,buf.GetMaxX()-w,buf.GetMaxY()-h); + getc(stdin); + for (count = 0; count < 256; count++) { + sprite->Put(buf,random() % (buf.GetMaxX()+sprite->GetWidth()) - sprite->GetWidth(), + random() % (buf.GetMaxY()+sprite->GetHeight()) - sprite->GetHeight()); + } // for + delete sprite; + getc(stdin); + return; +} // testSprite + +void testBlit(ogSurface & buf) { + int32 xx, yy, count; + ogBlit * blit = NULL; + ogBlit * blit2 = NULL; + + blit = new ogBlit(); + + buf.Clear(buf.Pack(0, 0, 0)); + for (xx= 0; xx<= 20; xx++) { + buf.Line(128,0,128-xx*6,255,buf.Pack(255,255,255)); + buf.Line(128,0,128+xx*6,255,buf.Pack(255,255,255)); + buf.Line(128,255,128-xx*6,0,buf.Pack(255,255,255)); + buf.Line(128,255,128+xx*6,0,buf.Pack(255,255,255)); + } // for + + buf.FillCircle(128,128,60,buf.Pack(255,255,255)); + blit->Get(buf,0,0,255,255); + for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) + buf.SetPixel(xx,yy,xx*yy); + blit->Save("test.blt"); + blit2 = new ogBlit(*blit, true); + + delete blit; + blit2->Save("test2.blt"); + blit = new ogBlit(); + blit->Load("test.blt"); + + blit->Put(buf,-10000,-10000); // test *really* off the screen + blit->Put(buf,10000,10000); // test *really* off the screen + + blit->Put(buf,-128,-128); + blit->Put(buf,buf.GetMaxX()/2-128,-128); + blit->Put(buf,buf.GetMaxX()-128,-128); + blit->Put(buf,-128,buf.GetMaxY()/2-128); + blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); + blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()/2-128); + blit->Put(buf,-128,buf.GetMaxY()-128); + blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()-128); + blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()-128); + + getc(stdin); + buf.Clear(buf.Pack(0, 0, 0)); + for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) + buf.SetPixel(xx,yy,xx*yy); + blit->GetBlitWithMask(buf, + buf.GetMaxX()/2-blit->GetWidth(), + buf.GetMaxY()/2-blit->GetHeight()); + buf.Clear(buf.Pack(0, 0, 0)); + blit->Put(buf,-10000,-10000); // test *really* off the screen + blit->Put(buf,10000,10000); // test *really* off the screen + + blit->Put(buf,-128,-128); + blit->Put(buf,buf.GetMaxX()/2-128,-128); + blit->Put(buf,buf.GetMaxX()-128,-128); + blit->Put(buf,-128,buf.GetMaxY()/2-128); + blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); + blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()/2-128); + blit->Put(buf,-128,buf.GetMaxY()-128); + blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()-128); + blit->Put(buf,buf.GetMaxX()-128,buf.GetMaxY()-128); + + getc(stdin); + for (count = 0; count < 1000; count++) { + blit->Put(buf,random() % (buf.GetMaxX()+blit->GetWidth()) - blit->GetWidth(), + random() % (buf.GetMaxY()+blit->GetHeight()) - blit->GetHeight()); + } // for + getc(stdin); + for (yy = 0; yy<=(int32)buf.GetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.GetMaxX(); xx++) + buf.SetPixel(xx,yy,xx*yy); + + blit->GetBlitWithMask(buf,buf.GetMaxX()/2,buf.GetMaxY()-128); + buf.Clear(buf.Pack(128,128,128)); + blit->Put(buf,buf.GetMaxX()/2-128,buf.GetMaxY()/2-128); + getc(stdin); + delete blit; + delete blit2; + + return; +} // testBlit + +void +testBlit2(ogSurface & buf) { + ogBlit * blit = new ogBlit(); + ogSurface * buf2 = new ogSurface(); + ogSurface * blitsource = new ogSurface(); + uInt32 xx,yy,count,colour; + buf.Clear(buf.Pack(0, 0, 0)); + if (!buf2->Clone(buf)) cout << "Clone failed!!!" << endl; + if (!blitsource->Clone(buf)) cout << "Clone failed!!" << endl; + + colour = 255; + for (count = 0; count < (buf2->GetMaxX()+1)/2; count+=4) { + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX()/2-count,buf2->GetMaxY(), + buf2->Pack(colour,colour,colour)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX()/2+count,buf2->GetMaxY(), + buf2->Pack(colour,colour,colour)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX()/2-count,0, + buf2->Pack(0,colour,0)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX()/2+count,0, + buf2->Pack(0,colour,0)); + --colour; + } // for + + colour = 255; + for (count = 0; count < (buf.GetMaxY()+1)/2; count+=4) { + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + 0, buf2->GetMaxY()/2-count, + buf2->Pack(colour,0,0)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + 0, buf2->GetMaxY()/2+count, + buf2->Pack(colour,0,0)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX(), buf2->GetMaxY()/2-count, + buf2->Pack(0,0,colour)); + buf2->Line(buf2->GetMaxX()/2, buf2->GetMaxY()/2, + buf2->GetMaxX(), buf2->GetMaxY()/2+count, + buf2->Pack(0,0,colour)); + --colour; + } // for + for (yy = 0; yy<=buf2->GetMaxY(); yy++) + for (xx = 0; xx<=buf2->GetMaxX(); xx++) + buf2->SetPixel(xx,yy, xx*yy); + for (count = 0; count<200; count++) + blitsource->FillCircle(random() % blitsource->GetMaxX(), random() % blitsource->GetMaxY(), + random() % 35+1,blitsource->Pack(255,255,255)); + + blit->Get(*blitsource,0,0,blitsource->GetMaxX(),blitsource->GetMaxY()); + blit->Save("bigblit.blt"); + delete blit; + blit = new ogBlit; + blit->Load("bigblit.blt"); + for (count = 0; count<=256; count+=4) { + for (yy = 0; yy<=buf2->GetMaxY(); yy++) + for (xx = 0; xx<=buf2->GetMaxX(); xx++) + buf2->SetPixel(xx,yy,xx*yy*count); + + blit->GetBlitWithMask(*buf2,0,0); + blit->Put(buf,0,0); + } // for + + getc(stdin); + delete blitsource; + delete buf2; + delete blit; + return; +} // testBlit2 + +void +testBlit3(ogSurface & buf) { + int32 count; + ogBlit * blit = NULL; + ogSurface * buf2 = NULL; + buf2 = new ogSurface(); + blit = new ogBlit(); + buf.Clear(buf.Pack(0, 0, 0)); + buf.FillCircle(buf.GetMaxX()/2,buf.GetMaxY()/2,14,buf.Pack(255,255,255)); + blit->Get(buf,buf.GetMaxX()/2-20,buf.GetMaxY()/2-20, + buf.GetMaxX()/2+20,buf.GetMaxY()/2+20); + blit->Put(buf,0,0); + for (count=0; count<(int32)buf.GetMaxX(); count++) + buf.Line(count,0,count,buf.GetMaxY(),count); + buf2->Clone(buf); + blit->GetBlitWithMask(*buf2,10,10); + buf.Clear(buf.Pack(63,63,63)); + for (count=-40; count<(int32)buf.GetMaxX()+10; count++) { + blit->GetBlitWithMask(*buf2,count,buf2->GetMaxY()/2-20); + blit->Put(buf,count,buf.GetMaxY()/2-20); + blit->GetBlitWithMask(*buf2,buf2->GetMaxX()/2-20,count); + blit->Put(buf,buf.GetMaxX()/2-20,count); + } + getc(stdin); + delete blit; + return; +} // testBlit3 + +void +testSaveLoadPal(ogSurface & buf) { + uInt32 count; + testRect(buf); + for (count=0; count<256; count++) + buf.SetPalette(count,count,count,count); + if (buf.SavePalette("test.pal")==false) cout << "SavePal() failed" << endl; + for (count=0; count<256; count++) + buf.SetPalette(count,0,0,0); + if (buf.LoadPalette("test.pal")==false) cout << "LoadPal() failed" << endl; + testRect(buf); +} // testSaveLoadPal + +void +testPolygon(ogSurface & buf) { + ogPoint2d points[16]; + uInt32 count; + buf.Clear(buf.Pack(0, 0, 0)); + for (count=0; count<16; count++) { + points[count].x = random() % buf.GetMaxX(); + points[count].y = random() % buf.GetMaxY(); + } // for + buf.FillPolygon(16, points, buf.Pack(random() & 255,random() & 255,random() & 255)); + getc(stdin); + return; +} // testPolygon + +void +testSpline(ogSurface & buf) { + ogPoint2d points[8]; + uInt32 i; + for (i=0; i<8; i++) { + points[i].x = random() % buf.GetMaxX(); + points[i].y = random() % buf.GetMaxY(); + } // for + buf.Clear(buf.Pack(0, 0, 0)); + buf.Polygon(8, points, buf.Pack(22,229,52)); + buf.Spline(8, points, 24, buf.Pack(64,64,255)); + buf.BSpline(8, points, 24, buf.Pack(255,128,128)); + getchar(); + return; +} // testSpline + +void +testFont(ogSurface & buf) { + uInt32 xx, yy; + ogBitFont * font = new ogBitFont(); + font->Load("SCRIPT.DPF", 0); + font->SetFGColor(255, 255, 255, 255); + font->SetBGColor(0, 0, 0, 255); + + font->PutString(buf, 0, 0, "abAByzYZ"); + + for (yy = 0; yyGetHeight(); yy++) { + for (xx = 0; xx<79; xx++) + if ((buf.GetPixel(xx, yy) & buf.GetAlphaMasker()) == 0) + cout << " "; + else + cout << "*"; + cout << endl; + } + + delete font; + return; +} // testFont + +void +testGouraud(ogSurface & buf) { + uInt8 r, g, b; + ogPoint2d points[4]; + ogRGBA8 colours[4]; + r = g = b = 0; + + points[0].x = buf.GetMaxX() - 150; + points[0].y = 0; + points[1].x = buf.GetMaxX(); + points[1].y = 0; + points[2].x = buf.GetMaxX(); + points[2].y = 150; + points[3].x = buf.GetMaxX() - 250; + points[3].y = 250; + colours[0].red = 255; + colours[0].green = 0; + colours[0].blue = 0; + colours[0].alpha = 255; + colours[1].red = 0; + colours[1].green = 255; + colours[1].blue = 128; + colours[1].alpha = 255; + colours[2].red = 128; + colours[2].green = 255; + colours[2].blue = 128; + colours[2].alpha = 255; + colours[3].red = 63; + colours[3].green = 63; + colours[3].blue = 63; + colours[3].alpha = 255; + buf.FillGouraudPolygon(4, points, colours); + getc(stdin); + return; +} // testGouraud + +void +testCopyBuf(ogSurface & buf) { + ogSurface * buf2 = new ogSurface(); + ogPixelFmt pixFmt; + buf.GetPixFmt(pixFmt); + buf2->Create(400, 400, OG_PIXFMT_32BPP); + buf2->Clear(buf2->Pack(255, 128, 255)); + buf.CopyBuf(0, 0, *buf2, 0, 0, buf2->GetMaxX(), buf2->GetMaxY()); + delete buf2; + getc(stdin); + return; +} + +void +testFillRect(ogSurface & buf) { + uInt32 count; + for (count = 100; count > 0; count--) { + buf.FillRect(count, count, 0, 0, buf.Pack(count*2, count*2, count*2)); + } + getc(stdin); + + return; +} // testFillRect() +int main() { + ogSurface* buf = NULL; + cout << "Starting program" << endl; +#ifdef __DJGPP__ + buf = new ogDisplay_VESA(); + buf->Create(800, 600, OG_PIXFMT_16BPP); +#else + buf = new ogSurface(); + if (buf->Create(1024, 768, OG_PIXFMT_16BPP)==false) exit(1); +#endif + srandom(time(NULL)); + +// buf->SetBlending(true); +// buf->SetAlpha(127); + buf->SetAntiAliasing(true); + +//cout << "testPixCon()" << endl; +// testPixCon(); + cout << "testFillRect()" << endl; + testFillRect(*buf); + cout << "testCopyBuf()" << endl; + testCopyBuf(*buf); + cout << "testGouraud()" << endl; + testGouraud(*buf); + cout << "testFont()" << endl; + testFont(*buf); + cout << "TestRect()" << endl; + testRect(*buf); + cout << "testCircle()" << endl; + testCircle(*buf); + cout << "TestLine()" << endl; + testLine(*buf); +cout << "TestVFlip()" << endl; + testVFlip(*buf); +cout << "TestHFlip()" << endl; + testHFlip(*buf); +cout << "TestArc()" << endl; + testArc(*buf); +cout << "TestSetPixel()" << endl; + testSetPixel(*buf); +cout << "TestClear()" << endl; + testClear(*buf); +cout << "TestSprite()" << endl; + testSprite(*buf); +cout << "TestBlit()" << endl; + testBlit(*buf); +cout << "TestBlit2()" << endl; + testBlit2(*buf); +// testBlit3(*buf); // special test for 320x200x8bpp +// testSaveLoadPal(*buf); // use an 8bpp mode +cout << "TestPolygon()" << endl; + testPolygon(*buf); +cout << "TestCurve()" << endl; + testCurve(*buf); +cout << "TestSpline()" << endl; + testSpline(*buf); + delete buf; +// buf->SetPixel(0, 0, buf->Pack(0, 0, 0)); + return(0); +} diff --git a/src/lib/objgfx40/objgfx40.cpp b/src/lib/objgfx40/objgfx40.cpp index 53e87e5..e6ce3ce 100644 --- a/src/lib/objgfx40/objgfx40.cpp +++ b/src/lib/objgfx40/objgfx40.cpp @@ -25,7 +25,9 @@ #include #include +#include #include + #ifdef __UBIXOS__ #include #endif diff --git a/src/lib/objgfx40/objgfx40/objgfx40.h b/src/lib/objgfx40/objgfx40/objgfx40.h index 34d7b5c..72a0e3c 100644 --- a/src/lib/objgfx40/objgfx40/objgfx40.h +++ b/src/lib/objgfx40/objgfx40/objgfx40.h @@ -5,79 +5,20 @@ #ifndef OBJGFX40_H #define OBJGFX40_H +#include "ogTypes.h" +#include "ogPixelFmt.h" + #ifndef __UBIXOS_KERNEL__ #include // for NULL, true, false #endif #define ogVERSION 4.0; -typedef signed char int8; -typedef signed short int int16; -typedef signed long int int32; -typedef signed long long int int64; -typedef unsigned char uInt8; -typedef unsigned short int uInt16; -typedef unsigned long int uInt32; -typedef unsigned long long int uInt64; +class ogPixelFmt; extern const uInt32 OG_MASKS[32]; -enum ogDataState { ogNone, ogOwner, ogAliasing }; - -enum ogErrorCode { - ogOK, - ogMemAllocFail, - ogAlreadyOwner, - ogNoSurface, - ogNoPalette, - ogBadBPP, - ogSourceOutOfBounds, - ogDestOutOfBounds, - ogFileNotFound, - ogFileReadError, - ogFileWriteError, - ogNoCloning, - ogNoAliasing, - ogNoModeSupport -}; // ogErrorCode - -struct ogRGB8 { - uInt8 red; - uInt8 green; - uInt8 blue; -}; - -struct ogRGBA8 { - uInt8 red; - uInt8 green; - uInt8 blue; - uInt8 alpha; -}; - -struct ogRGB32 { - uInt32 red; - uInt32 green; - uInt32 blue; -}; - -struct ogRGBA32 { - uInt32 red; - uInt32 green; - uInt32 blue; - uInt32 alpha; -}; - -struct ogPoint2d { - int32 x; - int32 y; -}; - -struct ogPoint3d { - int32 x; - int32 y; - int32 z; -}; - +#if 0 typedef class ogPixelFmt { public: @@ -91,10 +32,11 @@ uInt8 blueMaskSize; uInt8 alphaMaskSize; uInt8 reserved[7]; + ogPixelFmt(uInt8, uInt8, uInt8, uInt8, uInt8, + uInt8, uInt8, uInt8, uInt8); + virtual ~ogPixelFmt(void) {}; }; - // Default pixel formats - const ogPixelFmt OG_NULL_PIXFMT = { 0, 0,0,0,0,0,0,0,0, {0,0,0,0,0,0}}; const ogPixelFmt OG_PIXFMT_8BPP = { 8, 0,0,0,0,0,0,0,0, {0,0,0,0,0,0}}; const ogPixelFmt OG_PIXFMT_15BPP = {15, 10,5,0,15,5,5,5,1, {0,0,0,0,0,0}}; @@ -102,6 +44,8 @@ const ogPixelFmt OG_PIXFMT_24BPP = {24, 16,8,0,0,8,8,8,0, {0,0,0,0,0,0}}; const ogPixelFmt OG_PIXFMT_32BPP = {32, 16,8,0,24,8,8,8,8, {0,0,0,0,0,0}}; const ogPixelFmt OG_MAC_PIXFMT_16BPP = {16, 8,4,0,12,4,4,4,4, {0,0,0,0,0,0}}; +#endif + #if 0 class ogAttributes(uInt32 transparentColour = 0, diff --git a/src/lib/objgfx40/objgfx40/ogPixelFmt.h b/src/lib/objgfx40/objgfx40/ogPixelFmt.h new file mode 100644 index 0000000..3ed655a --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogPixelFmt.h @@ -0,0 +1,33 @@ +#ifndef OGPIXELFMT_H +#define OGPIXELFMT_H + +#include "ogTypes.h" +#include "objgfx40.h" + +class ogPixelFmt { + public: + uInt8 BPP; + uInt8 redFieldPosition; + uInt8 greenFieldPosition; + uInt8 blueFieldPosition; + uInt8 alphaFieldPosition; + uInt8 redMaskSize; + uInt8 greenMaskSize; + uInt8 blueMaskSize; + uInt8 alphaMaskSize; + uInt8 reserved[7]; + ogPixelFmt(void); + ogPixelFmt(uInt8, uInt8, uInt8, uInt8, uInt8, + uInt8, uInt8, uInt8, uInt8); + virtual ~ogPixelFmt(void) {} +}; // ogPixelFmt + +static ogPixelFmt OG_NULL_PIXFMT = ogPixelFmt(0, 0,0,0,0, 0,0,0,0); +static ogPixelFmt OG_PIXFMT_8BPP = ogPixelFmt(8, 0,0,0,0, 0,0,0,0); +static ogPixelFmt OG_PIXFMT_15BPP = ogPixelFmt(15, 10,5,0,15, 5,5,5,1); +static ogPixelFmt OG_PIXFMT_16BPP = ogPixelFmt(16, 11,5,0,0, 5,6,5,0); +static ogPixelFmt OG_PIXFMT_24BPP = ogPixelFmt(24, 16,8,0,0, 8,8,8,0); +static ogPixelFmt OG_PIXFMT_32BPP = ogPixelFmt(32, 16,8,0,24, 8,8,8,8); +static ogPixelFmt OG_MAC_PIXFMT_16BPP = ogPixelFmt(16, 8,4,0,12, 4,4,4,4); + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogTypes.h b/src/lib/objgfx40/objgfx40/ogTypes.h new file mode 100644 index 0000000..0bc42d8 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogTypes.h @@ -0,0 +1,69 @@ +#ifndef OGTYPES_H +#define OGTYPES_H + +typedef signed char int8; +typedef signed short int int16; +typedef signed long int int32; +typedef signed long long int int64; +typedef unsigned char uInt8; +typedef unsigned short int uInt16; +typedef unsigned long int uInt32; +typedef unsigned long long int uInt64; + +enum ogDataState { ogNone, ogOwner, ogAliasing }; + +enum ogErrorCode { + ogOK, + ogMemAllocFail, + ogAlreadyOwner, + ogNoSurface, + ogNoPalette, + ogBadBPP, + ogSourceOutOfBounds, + ogDestOutOfBounds, + ogFileNotFound, + ogFileReadError, + ogFileWriteError, + ogNoCloning, + ogNoAliasing, + ogNoModeSupport +}; // ogErrorCode + +struct ogRGB8 { + uInt8 red; + uInt8 green; + uInt8 blue; +}; + +struct ogRGBA8 { + uInt8 red; + uInt8 green; + uInt8 blue; + uInt8 alpha; +}; + +struct ogRGB32 { + uInt32 red; + uInt32 green; + uInt32 blue; +}; + +struct ogRGBA32 { + uInt32 red; + uInt32 green; + uInt32 blue; + uInt32 alpha; +}; + +struct ogPoint2d { + int32 x; + int32 y; +}; + +struct ogPoint3d { + int32 x; + int32 y; + int32 z; +}; + +#endif diff --git a/src/lib/objgfx40/ogPixelFmt.cpp b/src/lib/objgfx40/ogPixelFmt.cpp new file mode 100644 index 0000000..8af881c --- /dev/null +++ b/src/lib/objgfx40/ogPixelFmt.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +ogPixelFmt::ogPixelFmt(void) : BPP(0), + redFieldPosition(0), greenFieldPosition(0), + blueFieldPosition(0), alphaFieldPosition(0), + redMaskSize(0), greenMaskSize(0), + blueMaskSize(0), alphaMaskSize(0) { + for (int i = 0; i < 7; i++) reserved[i] = 0; + return; +} + +ogPixelFmt::ogPixelFmt(uInt8 bitsPerPix, + uInt8 RFP, uInt8 GFP, uInt8 BFP, uInt8 AFP, + uInt8 RMS, uInt8 GMS, uInt8 BMS, uInt8 AMS) { + + BPP = bitsPerPix; + redFieldPosition = RFP; + greenFieldPosition = GFP; + blueFieldPosition = BFP; + alphaFieldPosition = AFP; + redMaskSize = RMS; + greenMaskSize = GMS; + blueMaskSize = BMS; + alphaMaskSize = AMS; + + for (int i = 0; i < 7; i++) reserved[i] = 0; + + return; +} // ogPixelFmt::ogPixelFmt() diff --git a/src/lib/objgfx40/rh_opt.gdt b/src/lib/objgfx40/rh_opt.gdt index 325a7f1..26ed536 100644 --- a/src/lib/objgfx40/rh_opt.gdt +++ b/src/lib/objgfx40/rh_opt.gdt Binary files differ diff --git a/src/lib/objgfx40/rh_opt.gpr b/src/lib/objgfx40/rh_opt.gpr index f3883ae..a438c71 100644 --- a/src/lib/objgfx40/rh_opt.gpr +++ b/src/lib/objgfx40/rh_opt.gpr Binary files differ