diff options
-rw-r--r-- | examples/gui/utfdemo/utfdemo.lpi | 5 | ||||
-rw-r--r-- | examples/gui/utfdemo/utfdemo.lpr | 8 | ||||
-rw-r--r-- | examples/img/disp_bmp/disp_bmp.pas | 51 | ||||
-rw-r--r-- | gui/style.inc | 7 | ||||
-rw-r--r-- | gui/stylemanager.pas | 17 | ||||
-rw-r--r-- | img/bmpreader.pas | 102 | ||||
-rw-r--r-- | img/fpimg.pas | 12 | ||||
-rw-r--r-- | img/imageio.pas | 79 |
8 files changed, 151 insertions, 130 deletions
diff --git a/examples/gui/utfdemo/utfdemo.lpi b/examples/gui/utfdemo/utfdemo.lpi index aa97adce..7ead4030 100644 --- a/examples/gui/utfdemo/utfdemo.lpi +++ b/examples/gui/utfdemo/utfdemo.lpi @@ -25,7 +25,7 @@ </RunParams> <RequiredPackages Count="1"> <Item1> - <PackageName Value="fpGUI_laz"/> + <PackageName Value="fpguipackage"/> <MinVersion Minor="3" Valid="True"/> </Item1> </RequiredPackages> @@ -39,6 +39,9 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> + <SearchPaths> + <OtherUnitFiles Value="../../../gui/"/> + </SearchPaths> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/examples/gui/utfdemo/utfdemo.lpr b/examples/gui/utfdemo/utfdemo.lpr index 3d047bec..d6594687 100644 --- a/examples/gui/utfdemo/utfdemo.lpr +++ b/examples/gui/utfdemo/utfdemo.lpr @@ -8,7 +8,8 @@ uses {$ENDIF}{$ENDIF} Classes, gfxbase, - fpgui, fpGUI_laz; + fpGFX, + fpgui; type @@ -59,10 +60,11 @@ end; var MainForm: TMainForm; begin - MainForm := TMainForm.Create(Application); + GFApplication.Initialize; + MainForm := TMainForm.Create(GFApplication); try MainForm.Show; - Application.Run; + GFApplication.Run; finally MainForm.Free; end; diff --git a/examples/img/disp_bmp/disp_bmp.pas b/examples/img/disp_bmp/disp_bmp.pas index a33bf9be..553041c0 100644 --- a/examples/img/disp_bmp/disp_bmp.pas +++ b/examples/img/disp_bmp/disp_bmp.pas @@ -1,14 +1,13 @@ { - $Id: disp_bmp.pp,v 1.6 2001/02/14 23:08:59 sg Exp $ + fpGUI - Free Pascal GUI Library - fpImg - Free Pascal Imaging Library - Copyright (C) 2000 - 2001 by - Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org + Example: Display BMP file using the fpImg - Free Pascal Imaging Library - Example: Display BMP file + Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + distribution, for details of the copyright. - See the file COPYING, included in this distribution, - for details about the copyright. + See the file COPYING.modifiedLGPL, included in this distribution, + for details about redistributing fpGUI. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,7 +17,14 @@ program Disp_BMP; -uses Classes, GFXBase, GFXImpl, fpImg, BMPReader; +uses + Classes + ,GFXBase + ,GFXImpl + ,fpImg + ,BMPReader + ,fpgfxpackage + ; type TMainWindow = class @@ -29,17 +35,17 @@ type Image: TGfxImage; public constructor Create(ADisplay: TDefDisplay); - destructor Destroy; override; + destructor Destroy; override; end; constructor TMainWindow.Create(ADisplay: TDefDisplay); begin inherited Create; - Display := ADisplay; - Image := CreateImageFromFile(Display.DefaultScreen, TBMPReader, ParamStr(1)); - Window := ADisplay.DefaultScreen.CreateWindow; - Window.Title := 'fpImg Bitmap Test'; - Window.OnPaint := @Paint; + Display := ADisplay; + Image := CreateImageFromFile(Display.DefaultScreen, TBMPReader, ParamStr(1)); + Window := ADisplay.DefaultScreen.CreateWindow; + Window.Title := 'fpImg Bitmap Test'; + Window.OnPaint := @Paint; Window.SetFixedClientSize(Size(Image.Width, Image.Height)); Window.Show; end; @@ -68,23 +74,10 @@ begin Halt(2); end; - Display := TDefDisplay.Create; - MainWindow := TMainWindow.Create(Display); + Display := TDefDisplay.Create; + MainWindow := TMainWindow.Create(Display); Display.Run; MainWindow.Free; Display.Free; end. - -{ - $Log: disp_bmp.pp,v $ - Revision 1.6 2001/02/14 23:08:59 sg - * Adapted to changes in fpGFX interface - - Revision 1.5 2001/02/09 20:49:03 sg - * Adapted to recent improvements in fpGFX interfaces - - Revision 1.4 2001/01/11 23:21:53 sg - *** empty log message *** - -} diff --git a/gui/style.inc b/gui/style.inc index c8700536..e66469f3 100644 --- a/gui/style.inc +++ b/gui/style.inc @@ -308,8 +308,7 @@ begin // Palette := ADisplay.DefaultScreen.CreatePalette(8, @PalData); - {$Note All data image formats was PixelFormatPal4, is 8bit going to work? } - Image := TFBitmap.Create(60, 12, PixelFormatPal8); + Image := TFBitmap.Create(60, 12, PixelFormatPal4); Image.Palette := Palette; Image.SetPixelsFromData(@RadioBitmapData, 30); ImageCanvas.DrawImage(Image, Point(0, 0)); @@ -320,13 +319,13 @@ begin MaskCanvas.DrawImage(Image, Point(0, 0)); Image.Free; - Image := TFBitmap.Create(66, 13, PixelFormatPal8); {!!!: width is 65, but fpGFX emulayer has a problem with odd widths} + Image := TFBitmap.Create(66, 13, PixelFormatPal4); {!!!: width is 65, but fpGFX emulayer has a problem with odd widths} Image.Palette := Palette; Image.SetPixelsFromData(@CheckBoxBitmapData, 33); ImageCanvas.DrawImage(Image, Point(0, 12)); Image.Free; - Image := TFBitmap.Create(64, 8, PixelFormatPal8); + Image := TFBitmap.Create(64, 8, PixelFormatPal4); Image.Palette := Palette; Image.SetPixelsFromData(@ArrowBitmapData, 32); ImageCanvas.DrawImage(Image, Point(0, 25)); diff --git a/gui/stylemanager.pas b/gui/stylemanager.pas index fab17479..c128d7d3 100644 --- a/gui/stylemanager.pas +++ b/gui/stylemanager.pas @@ -32,6 +32,8 @@ type FUserStyle: TStyle; function GetDefaultStyle: TStyle; public + constructor Create; + destructor Destroy;override; property DefaultStyle: TStyle read GetDefaultStyle; procedure SetStyle(pNewStyle: TStyle); end; @@ -72,6 +74,21 @@ begin end; end; +constructor TStyleManager.Create; +begin + FUserStyle := nil; + FDefaultStyle := nil; +end; + +destructor TStyleManager.Destroy; +begin + if FUserStyle <> nil then + FUserStyle.Free; + if FDefaultStyle <> nil then + FDefaultStyle.Free; + inherited Destroy; +end; + procedure TStyleManager.SetStyle(pNewStyle: TStyle); begin if Assigned(FUserStyle) then diff --git a/img/bmpreader.pas b/img/bmpreader.pas index 9d03bafb..c2693792 100644 --- a/img/bmpreader.pas +++ b/img/bmpreader.pas @@ -23,12 +23,17 @@ unit BMPReader; interface -uses Classes, GFXBase, ImageIO; +uses + Classes + ,GFXBase + ,ImageIO + ; type DWORD = LongWord; LONG = LongInt; + TBitmapFileHeader = packed record bfType: WORD; bfSize: DWORD; @@ -37,6 +42,7 @@ type bfOffBits: DWORD; end; + TBitmapInfoHeader = packed record biSize: DWORD; biWidth: LONG; @@ -51,6 +57,7 @@ type biClrImportant: DWORD; end; + PRGBQuad = ^TRGBQuad; TRGBQuad = packed record rgbBlue, rgbGreen, rgbRed, rgbReserved: BYTE; @@ -63,26 +70,23 @@ type FInfoHeader: TBitmapInfoHeader; FBMPPalette: PRGBQuad; FFileStride: LongWord; - HeaderBytesRead, PalBytesRead: Integer; ScanlinesLeft: Integer; ThisSegmentHeight: Integer; ScanlinesLeftInSegment: Integer; ScanlineBytesDone: LongWord; CurScanline: Pointer; - - procedure DoProcessHeaderData(AStream: TStream); override; - function DoGetImageSegmentStartY(ASegmentHeight: Integer): Integer; - override; - procedure InitImageReading; override; - procedure InitSegmentReading; - procedure DoProcessImageData(AStream: TStream); override; + procedure DoProcessHeaderData(AStream: TStream); override; + function DoGetImageSegmentStartY(ASegmentHeight: Integer): Integer; override; + procedure InitImageReading; override; + procedure InitSegmentReading; + procedure DoProcessImageData(AStream: TStream); override; public - destructor Destroy; override; - property FileHeader: TBitmapFileHeader read FFileHeader; - property InfoHeader: TBitmapInfoHeader read FInfoHeader; - property BMPPalette: PRGBQuad read FBMPPalette; - property FileStride: LongWord read FFileStride; + destructor Destroy; override; + property FileHeader: TBitmapFileHeader read FFileHeader; + property InfoHeader: TBitmapInfoHeader read FInfoHeader; + property BMPPalette: PRGBQuad read FBMPPalette; + property FileStride: LongWord read FFileStride; end; @@ -113,7 +117,8 @@ begin raise EImgOutOfData.Create; Inc(HeaderBytesRead, HaveRead); IsFirstRead := False; - end else + end + else IsFirstRead := True; if HeaderBytesRead < SizeOf(FileHeader) + SizeOf(InfoHeader) then @@ -154,10 +159,10 @@ begin BytesToSkip := SizeOf(SkipBuffer); HaveRead := AStream.Read(SkipBuffer, BytesToSkip); if HaveRead = 0 then - if IsFirstRead then - raise EImgOutOfData.Create - else - exit; + if IsFirstRead then + raise EImgOutOfData.Create + else + exit; //==> IsFirstRead := False; Inc(HeaderBytesRead, HaveRead); if PalBytesRead < PaletteSize * SizeOf(TGfxPixel) then @@ -165,7 +170,7 @@ begin Move(SkipBuffer, PByte(FBMPPalette)[PalBytesRead], HaveRead); Inc(PalBytesRead, HaveRead); end; - end; + end; { if } if HeaderBytesRead = DataOffset then begin @@ -174,41 +179,41 @@ begin if PaletteSize > 0 then for i := 0 to PaletteSize - 1 do - begin - Palette[i].Red := BMPPalette[i].rgbRed * 257; - Palette[i].Green := BMPPalette[i].rgbGreen * 257; - Palette[i].Blue := BMPPalette[i].rgbBlue * 257; - Palette[i].Alpha := 0; - end; + begin + Palette[i].Red := BMPPalette[i].rgbRed * 257; + Palette[i].Green := BMPPalette[i].rgbGreen * 257; + Palette[i].Blue := BMPPalette[i].rgbBlue * 257; + Palette[i].Alpha := 0; + end; case InfoHeader.biBitCount of - 1: + 1: begin - FFileStride := ((Width + 31) shr 3) and not 3; - FPixelFormat.FormatType := ftMono; - end; - 4: + FFileStride := ((Width + 31) shr 3) and not 3; + FPixelFormat.FormatType := ftMono; + end; + 4: begin - FFileStride := ((Width + 7) shr 1) and not 3; - FPixelFormat.FormatType := ftPal4; - end; - 8: + FFileStride := ((Width + 7) shr 1) and not 3; + FPixelFormat.FormatType := ftPal4; + end; + 8: begin - FFileStride := (Width + 3) and not 3; - FPixelFormat.FormatType := ftPal8; - end; + FFileStride := (Width + 3) and not 3; + FPixelFormat.FormatType := ftPal8; + end; 24: begin FFileStride := (Width * 3 + 3) and not 3; - FPixelFormat := PixelFormatBGR24; + FPixelFormat := PixelFormatBGR24; end; else raise EImgUnsupportedPixelFormat.Create; - end; - end; + end; { case } + end; { if } HeaderFinished; - end; + end; { if } end; function TBMPReader.DoGetImageSegmentStartY(ASegmentHeight: Integer): Integer; @@ -248,7 +253,8 @@ procedure TBMPReader.DoProcessImageData(AStream: TStream); ImageFinished else InitSegmentReading; - end else + end + else Dec(CurScanline, SegmentStride); end; @@ -269,13 +275,15 @@ begin begin ScanlineBytesDone := 0; ScanlineDone - end else + end + else begin Inc(ScanlineBytesDone, HaveRead); exit; end; ReadMayFail := True; - end else + end + else ReadMayFail := False; while ScanlinesLeft > 0 do @@ -288,7 +296,7 @@ begin if HaveRead = 0 then if ReadMayFail then - exit + exit //==> else raise EImgOutOfData.Create; @@ -303,7 +311,7 @@ begin AStream.Position := AStream.Position + FileStride - ToRead; ReadMayFail := True; ScanlineDone; - end; + end; { while } end; end. diff --git a/img/fpimg.pas b/img/fpimg.pas index 87707a97..9c782a04 100644 --- a/img/fpimg.pas +++ b/img/fpimg.pas @@ -24,7 +24,11 @@ unit fpImg; interface -uses Classes, GFXBase, ImageIO; +uses + Classes + ,GFXBase + ,ImageIO + ; function CreateImageFromFile(AScreen: TGfxScreen; AReader: TImageReaderClass; @@ -63,12 +67,10 @@ begin Reader := AReader.Create; try Reader.ProcessHeaderData(AStream); - Result := AScreen.Display.CreateImage(Reader.Width, Reader.Height, - Reader.PixelFormat); + Result := AScreen.Display.CreateImage(Reader.Width, Reader.Height, Reader.PixelFormat); if Reader.PaletteSize > 0 then begin - Palette := AScreen.CreatePalette(Reader.PaletteSize, - Reader.Palette); + Palette := AScreen.CreatePalette(Reader.PaletteSize, Reader.Palette); try Result.Palette := Palette; finally diff --git a/img/imageio.pas b/img/imageio.pas index ffe79cc8..d28c9267 100644 --- a/img/imageio.pas +++ b/img/imageio.pas @@ -23,7 +23,11 @@ unit ImageIO; interface -uses SysUtils, Classes, GFXBase; +uses + SysUtils + ,Classes + ,GFXBase + ; resourcestring SImgOutOfData = 'No more data available for image'; @@ -56,7 +60,6 @@ type TImageReader = class private FState: TImageReaderState; - { Needed for reading of image data. These values must be initialized by the user via SetImageSegmentBuffer } FSegmentData: Pointer; @@ -69,48 +72,43 @@ type FOnImage: TNotifyEvent; protected // Image properties, only available after OnHeaderRead event - FWidth, FHeight: Integer; + FWidth: Integer; + FHeight: Integer; FPixelFormat: TGfxPixelFormat; FPaletteSize: Integer; FPalette: PGfxColor; - - procedure HeaderFinished; - procedure SegmentFinished(AStartY, AHeight: Integer); - procedure ImageFinished; - - procedure DoProcessHeaderData(AStream: TStream); virtual; abstract; - function DoGetImageSegmentStartY(ASegmentHeight: Integer): Integer; - virtual; abstract; - procedure InitImageReading; virtual; - procedure DoProcessImageData(AStream: TStream); virtual; abstract; - + procedure HeaderFinished; + procedure SegmentFinished(AStartY, AHeight: Integer); + procedure ImageFinished; + procedure DoProcessHeaderData(AStream: TStream); virtual; abstract; + function DoGetImageSegmentStartY(ASegmentHeight: Integer): Integer; virtual; abstract; + procedure InitImageReading; virtual; + procedure DoProcessImageData(AStream: TStream); virtual; abstract; public constructor Create; virtual; - procedure ProcessHeaderData(AStream: TStream); - function GetImageSegmentStartY(ASegmentHeight: Integer): Integer; - procedure SetImageSegmentBuffer(AData: Pointer; AStride: LongWord; - ASegmentHeight: Integer); - procedure ProcessImageData(AStream: TStream); - - property State: TImageReaderState read FState; - property Width: Integer read FWidth; - property Height: Integer read FHeight; - property PixelFormat: TGfxPixelFormat read FPixelFormat; - property PaletteSize: Integer read FPaletteSize; - property Palette: PGfxColor read FPalette; - property SegmentData: Pointer read FSegmentData; - property SegmentStride: LongWord read FSegmentStride; - property SegmentHeight: Integer read FSegmentHeight; - property SegmentSize: LongWord read FSegmentSize; - - property OnHeader: TNotifyEvent read FOnHeader write FOnHeader; - property OnSegment: TSegmentEvent read FOnSegment write FOnSegment; - property OnImage: TNotifyEvent read FOnImage write FOnImage; + procedure ProcessHeaderData(AStream: TStream); + function GetImageSegmentStartY(ASegmentHeight: Integer): Integer; + procedure SetImageSegmentBuffer(AData: Pointer; AStride: LongWord; ASegmentHeight: Integer); + procedure ProcessImageData(AStream: TStream); + property State: TImageReaderState read FState; + property Width: Integer read FWidth; + property Height: Integer read FHeight; + property PixelFormat: TGfxPixelFormat read FPixelFormat; + property PaletteSize: Integer read FPaletteSize; + property Palette: PGfxColor read FPalette; + property SegmentData: Pointer read FSegmentData; + property SegmentStride: LongWord read FSegmentStride; + property SegmentHeight: Integer read FSegmentHeight; + property SegmentSize: LongWord read FSegmentSize; + property OnHeader: TNotifyEvent read FOnHeader write FOnHeader; + property OnSegment: TSegmentEvent read FOnSegment write FOnSegment; + property OnImage: TNotifyEvent read FOnImage write FOnImage; end; implementation + constructor EImgOutOfData.Create; begin inherited Create(SImgOutOfData); @@ -121,8 +119,7 @@ begin inherited Create(SImgUnsupportedPixelFormat); end; - -// TImageReader +{ TImageReader } constructor TImageReader.Create; begin @@ -147,10 +144,10 @@ procedure TImageReader.SetImageSegmentBuffer(AData: Pointer; AStride: LongWord; ASegmentHeight: Integer); begin ASSERT(State in [irsHeaderRead, irsInImage]); - FSegmentData := AData; - FSegmentStride := AStride; - FSegmentHeight := ASegmentHeight; - FSegmentSize := SegmentStride * SegmentHeight; + FSegmentData := AData; + FSegmentStride := AStride; + FSegmentHeight := ASegmentHeight; + FSegmentSize := SegmentStride * SegmentHeight; end; procedure TImageReader.ProcessImageData(AStream: TStream); @@ -196,5 +193,5 @@ begin // Do nothing end; - end. + |