diff options
author | eddie-0815 <eddie-0815@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2007-10-29 21:40:14 +0000 |
---|---|---|
committer | eddie-0815 <eddie-0815@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2007-10-29 21:40:14 +0000 |
commit | 52eeec05d021df5334934f50dfafff981cbca33b (patch) | |
tree | a5f459e4b3065312820250e6c4ecbc1c7fcc6e0d /Game/Code/MacOSX/Wrapper/Graphics.pas | |
parent | e779d4f8a8ca13215895338f71e6929dc795cf60 (diff) | |
download | usdx-52eeec05d021df5334934f50dfafff981cbca33b.tar.gz usdx-52eeec05d021df5334934f50dfafff981cbca33b.tar.xz usdx-52eeec05d021df5334934f50dfafff981cbca33b.zip |
Just adding first MacOSX version. This does not compile yet.
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@540 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/MacOSX/Wrapper/Graphics.pas')
-rwxr-xr-x | Game/Code/MacOSX/Wrapper/Graphics.pas | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/Game/Code/MacOSX/Wrapper/Graphics.pas b/Game/Code/MacOSX/Wrapper/Graphics.pas new file mode 100755 index 00000000..5982bb77 --- /dev/null +++ b/Game/Code/MacOSX/Wrapper/Graphics.pas @@ -0,0 +1,190 @@ +unit Graphics;
+
+{$INCLUDE ../Platform.inc}
+
+interface
+
+uses
+ Classes, SysUtils, Windows, FreeBitmap, FreeImage;
+
+type
+ TPixelFormat = (pfDevice, pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit, pfCustom);
+ TColor = -$7FFFFFFF-1..$7FFFFFFF;
+
+ TCanvas = class
+ private
+ FImage : TFreeBitmap;
+ function GetPixel(x, y: Integer): TColor;
+ procedure SetPixel(x, y: Integer; const Value: TColor);
+ public
+ Constructor Create(const bmp : TFreeBitmap);
+ property Pixels[x,y : Integer] : TColor read GetPixel write SetPixel;
+ end;
+
+ TBitmap = class
+ private
+ FCanvas : TCanvas;
+ function GetHeight: Integer;
+ function GetWidth: Integer;
+ procedure SetHeight(const Value: Integer);
+ procedure SetWidth(const Value: Integer);
+ function GetPixelFormat: TPixelFormat;
+ procedure SetPixelFormat(const Value: TPixelFormat);
+ function GetScanLine(Line: Integer): Pointer;
+ protected
+ FImage : TFreeBitmap;
+ public
+ Constructor Create;
+ Destructor Destroy; override;
+ Procedure LoadFromStream(const str : TStream);
+ Procedure LoadFromFile(const f : String);
+ Procedure SaveToFile(const f : String); virtual;
+ Procedure Assign(const src : TBitmap);
+ property Width : Integer read GetWidth write SetWidth;
+ property Height : Integer read GetHeight write SetHeight;
+ property PixelFormat : TPixelFormat read GetPixelFormat write SetPixelFormat;
+ property ScanLine[Line : Integer] : Pointer read GetScanLine;
+ property Canvas : TCanvas read FCanvas;
+ end;
+
+implementation
+
+{ TBitmap }
+
+type
+ TRealRGB = packed record
+ rgbRed: Byte;
+ rgbGreen: Byte;
+ rgbBlue: Byte;
+ rgbReserved: Byte;
+ end;
+
+procedure TBitmap.Assign(const src: TBitmap);
+begin
+ FImage.Assign(src.FImage);
+ FCanvas.FImage := FImage;
+end;
+
+constructor TBitmap.Create;
+begin
+ FImage := TFreeBitmap.Create( FIF_BMP, 4, 4, 24);
+ FCanvas := TCanvas.Create(FImage);
+end;
+
+destructor TBitmap.Destroy;
+begin
+ FCanvas.Free;
+ FImage.Free;
+ inherited;
+end;
+
+function TBitmap.GetHeight: Integer;
+begin
+ Result := FImage.GetHeight;
+end;
+
+function TBitmap.GetPixelFormat: TPixelFormat;
+begin
+ Result := pf24bit;
+
+ case FImage.GetBitsPerPixel of
+ 1 : Result := pf1bit;
+ 4 : Result := pf4bit;
+ 8 : Result := pf8bit;
+ 15 : Result := pf15bit;
+ 16 : Result := pf16bit;
+ 24 : Result := pf24bit;
+ 32 : Result := pf32bit;
+ end;
+end;
+
+function TBitmap.GetScanLine(Line: Integer): Pointer;
+begin
+ Result := FImage.GetScanLine(Height-1-Line);
+end;
+
+function TBitmap.GetWidth: Integer;
+begin
+ Result := FImage.GetWidth;
+end;
+
+procedure TBitmap.LoadFromFile(const f: String);
+begin
+ FreeAndNil(FCanvas);
+ FreeAndNil(FImage);
+ FImage := TFreeBitmap.Create;
+ FImage.Load(f);
+ FCanvas := TCanvas.Create(FImage);
+end;
+
+procedure TBitmap.LoadFromStream(const str: TStream);
+begin
+ FreeAndNil(FCanvas);
+ FreeAndNil(FImage);
+ FImage := TFreeBitmap.Create;
+ FImage.LoadFromStream(str);
+ FCanvas := TCanvas.Create(FImage);
+end;
+
+procedure TBitmap.SaveToFile(const f: String);
+begin
+ FImage.Save(f);
+end;
+
+procedure TBitmap.SetHeight(const Value: Integer);
+begin
+ if Value <> Height then begin
+ FImage.Rescale( Width, Value, FILTER_BILINEAR);
+ end;
+end;
+
+procedure TBitmap.SetPixelFormat(const Value: TPixelFormat);
+begin
+ if Value <> PixelFormat then begin
+ case Value of
+ pf4bit : FImage.ConvertTo4Bits;
+ pf8bit : FImage.ConvertTo8Bits;
+ pf15bit : FImage.ConvertTo16Bits555;
+ pf16bit : FImage.ConvertTo16Bits565;
+ pf24bit : FImage.ConvertTo24Bits;
+ pf32bit : FImage.ConvertTo32Bits;
+ end;
+ end;
+end;
+
+procedure TBitmap.SetWidth(const Value: Integer);
+begin
+ if Value <> Width then begin
+ FImage.Rescale( Value, Height, FILTER_BILINEAR);
+ end;
+end;
+
+{ TCanvas }
+
+constructor TCanvas.Create(const bmp: TFreeBitmap);
+begin
+ FImage := bmp;
+end;
+
+function TCanvas.GetPixel(x, y: Integer): TColor;
+var
+ pix : TRGBQuad;
+begin
+ FImage.GetPixelColor( x, FImage.GetHeight-1-y, @pix);
+ Result := TColor(pix);
+end;
+
+procedure TCanvas.SetPixel(x, y: Integer; const Value: TColor);
+var
+ pixRGB : TRealRGB;
+ pixBGR : TRGBQuad;
+begin
+ Move( Value, pixRGB, SizeOf(pixRGB));
+ pixBGR.rgbRed := pixRGB.rgbRed;
+ pixBGR.rgbGreen := pixRGB.rgbGreen;
+ pixBGR.rgbBlue := pixRGB.rgbBlue;
+ pixBGR.rgbReserved := pixRGB.rgbReserved;
+ FImage.SetPixelColor( x, FImage.GetHeight-1-y, @pixBGR);
+end;
+
+end.
|