Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (10 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgralayers.pas

    r452 r472  
    1414  TBGRALayeredBitmap = class;
    1515  TBGRALayeredBitmapClass = class of TBGRALayeredBitmap;
     16
     17  TBGRALayeredBitmapSaveToStreamProc = procedure(AStream: TStream; ALayers: TBGRACustomLayeredBitmap);
     18  TBGRALayeredBitmapLoadFromStreamProc = function(AStream: TStream): TBGRALayeredBitmap;
    1619
    1720  { TBGRACustomLayeredBitmap }
     
    3639    function GetLayerName(layer: integer): string; virtual;
    3740    function GetLayerOffset(layer: integer): TPoint; virtual;
    38     function GetLayerBitmapDirectly(layer: integer): TBGRABitmap; virtual;
    3941    function GetLayerFrozenRange(layer: integer): integer;
    4042    function GetLayerFrozen(layer: integer): boolean; virtual;
     43    function GetLayerUniqueId(layer: integer): integer; virtual;
    4144    procedure SetLayerFrozen(layer: integer; AValue: boolean); virtual;
    4245    function RangeIntersect(first1,last1,first2,last2: integer): boolean;
     
    5053
    5154  public
    52     procedure SaveToFile(const filename: string); override;
     55    procedure SaveToFile(const filenameUTF8: string); override;
    5356    procedure SaveToStream(Stream: TStream); override;
    5457    constructor Create; override;
    5558    destructor Destroy; override;
    5659    function ToString: ansistring; override;
     60    function GetLayerBitmapDirectly(layer: integer): TBGRABitmap; virtual;
    5761    function GetLayerBitmapCopy(layer: integer): TBGRABitmap; virtual; abstract;
    5862    function ComputeFlatImage: TBGRABitmap; overload;
     
    8084    property LayerOffset[layer: integer]: TPoint read GetLayerOffset;
    8185    property LayerFrozen[layer: integer]: boolean read GetLayerFrozen;
     86    property LayerUniqueId[layer: integer]: integer read GetLayerUniqueId;
    8287    property LinearBlend: boolean read GetLinearBlend write SetLinearBlend; //use linear blending unless specified
    8388    property DefaultBlendingOperation: TBlendOperation read GetDefaultBlendingOperation;
     
    103108    FLayers: array of TBGRALayerInfo;
    104109    FWidth,FHeight: integer;
    105     function GetLayerUniqueId(layer: integer): integer;
    106     procedure SetLayerUniqueId(layer: integer; AValue: integer);
    107110
    108111  protected
     
    122125    procedure SetLayerName(layer: integer; AValue: string);
    123126    procedure SetLayerFrozen(layer: integer; AValue: boolean); override;
    124     function GetLayerBitmapDirectly(layer: integer): TBGRABitmap; override;
     127    function GetLayerUniqueId(layer: integer): integer; override;
     128    procedure SetLayerUniqueId(layer: integer; AValue: integer);
    125129
    126130  public
    127     procedure LoadFromFile(const filename: string); override;
     131    procedure LoadFromFile(const filenameUTF8: string); override;
    128132    procedure LoadFromStream(stream: TStream); override;
    129133    procedure SetSize(AWidth, AHeight: integer); virtual;
     
    155159    function AddOwnedLayer(ABitmap: TBGRABitmap; BlendOp: TBlendOperation; Opacity: byte = 255): integer; overload;
    156160    destructor Destroy; override;
    157     constructor Create; override;
    158     constructor Create(AWidth, AHeight: integer);
     161    constructor Create; override; overload;
     162    constructor Create(AWidth, AHeight: integer); virtual; overload;
     163    function GetLayerBitmapDirectly(layer: integer): TBGRABitmap; override;
    159164    function GetLayerBitmapCopy(layer: integer): TBGRABitmap; override;
    160165    function GetLayerIndexFromId(AIdentifier: integer): integer;
    161166    function Duplicate(ASharedLayerIds: boolean = false): TBGRALayeredBitmap;
     167    function ProduceLayerUniqueId: integer;
    162168
    163169    procedure RotateCW;
     
    180186  end;
    181187
    182 procedure RegisterLayeredBitmapWriter(AExtension: string; AWriter: TBGRALayeredBitmapClass);
    183 procedure RegisterLayeredBitmapReader(AExtension: string; AReader: TBGRACustomLayeredBitmapClass);
     188procedure RegisterLayeredBitmapWriter(AExtensionUTF8: string; AWriter: TBGRALayeredBitmapClass);
     189procedure RegisterLayeredBitmapReader(AExtensionUTF8: string; AReader: TBGRACustomLayeredBitmapClass);
     190
     191var
     192  LayeredBitmapSaveToStreamProc : TBGRALayeredBitmapSaveToStreamProc;
     193  LayeredBitmapLoadFromStreamProc : TBGRALayeredBitmapLoadFromStreamProc;
     194
     195type
     196  TOnLayeredBitmapLoadStartProc = procedure(AFilenameUTF8: string) of object;
     197  TOnLayeredBitmapLoadProgressProc = procedure(APercentage: integer) of object;
     198  TOnLayeredBitmapLoadedProc = procedure() of object;
     199
     200procedure OnLayeredBitmapLoadFromStreamStart;
     201procedure OnLayeredBitmapLoadStart(AFilenameUTF8: string);
     202procedure OnLayeredBitmapLoadProgress(APercentage: integer);
     203procedure OnLayeredBitmapLoaded();
     204procedure RegisterLoadingHandler(AStart: TOnLayeredBitmapLoadStartProc; AProgress: TOnLayeredBitmapLoadProgressProc;
     205     ADone: TOnLayeredBitmapLoadedProc);
     206procedure UnregisterLoadingHandler(AStart: TOnLayeredBitmapLoadStartProc; AProgress: TOnLayeredBitmapLoadProgressProc;
     207     ADone: TOnLayeredBitmapLoadedProc);
    184208
    185209implementation
     210
     211uses LCLProc;
     212
     213var
     214  OnLayeredBitmapLoadStartProc: TOnLayeredBitmapLoadStartProc;
     215  OnLayeredBitmapLoadProgressProc: TOnLayeredBitmapLoadProgressProc;
     216  OnLayeredBitmapLoadedProc: TOnLayeredBitmapLoadedProc;
    186217
    187218var
     
    380411end;
    381412
    382 procedure TBGRALayeredBitmap.LoadFromFile(const filename: string);
     413procedure TBGRALayeredBitmap.LoadFromFile(const filenameUTF8: string);
    383414var bmp: TBGRABitmap;
    384415    index: integer;
     
    387418    i: integer;
    388419begin
    389   ext := lowercase(ExtractFileExt(filename));
     420  ext := UTF8LowerCase(ExtractFileExt(filenameUTF8));
    390421  for i := 0 to high(LayeredBitmapReaders) do
    391422    if '.'+LayeredBitmapReaders[i].extension = ext then
     
    393424      temp := LayeredBitmapReaders[i].theClass.Create;
    394425      try
    395         temp.LoadFromFile(filename);
     426        temp.LoadFromFile(filenameUTF8);
    396427        Assign(temp);
    397428      finally
     
    401432    end;
    402433
    403   bmp := TBGRABitmap.Create(filename);
     434  bmp := TBGRABitmap.Create(filenameUTF8, True);
    404435  Clear;
    405436  SetSize(bmp.Width,bmp.Height);
     
    411442var bmp: TBGRABitmap;
    412443   index: integer;
    413 begin
     444   temp: TBGRALayeredBitmap;
     445begin
     446  if Assigned(LayeredBitmapLoadFromStreamProc) then
     447  begin
     448    temp := LayeredBitmapLoadFromStreamProc(Stream);
     449    if temp <> nil then
     450    begin
     451      Assign(temp);
     452      temp.Free;
     453      exit;
     454    end;
     455  end;
    414456  bmp := TBGRABitmap.Create(stream);
    415457  Clear;
     
    538580  FLayers[FNbLayers].Visible := true;
    539581  FLayers[FNbLayers].Frozen := false;
    540   FLayers[FNbLayers].UniqueId := InterLockedIncrement(NextLayerUniqueId);
     582  FLayers[FNbLayers].UniqueId := ProduceLayerUniqueId;
    541583  if Shared then
    542584  begin
     
    694736  result := TBGRALayeredBitmap.Create;
    695737  result.Assign(self, ASharedLayerIds);
     738end;
     739
     740function TBGRALayeredBitmap.ProduceLayerUniqueId: integer;
     741begin
     742  result := InterLockedIncrement(NextLayerUniqueId);
    696743end;
    697744
     
    841888    end;
    842889  result := false;
     890end;
     891
     892function TBGRACustomLayeredBitmap.GetLayerUniqueId(layer: integer): integer;
     893begin
     894  result := layer;
    843895end;
    844896
     
    903955end;
    904956
    905 procedure TBGRACustomLayeredBitmap.SaveToFile(const filename: string);
     957procedure TBGRACustomLayeredBitmap.SaveToFile(const filenameUTF8: string);
    906958var bmp: TBGRABitmap;
    907959    ext: string;
     
    909961    i: integer;
    910962begin
    911   ext := lowercase(ExtractFileExt(filename));
     963  ext := UTF8LowerCase(ExtractFileExt(filenameUTF8));
    912964  for i := 0 to high(LayeredBitmapWriters) do
    913965    if '.'+LayeredBitmapWriters[i].extension = ext then
     
    916968      try
    917969        temp.Assign(self);
    918         temp.SaveToFile(filename);
     970        temp.SaveToFile(filenameUTF8);
    919971      finally
    920972        temp.Free;
     
    925977  bmp := ComputeFlatImage;
    926978  try
    927     bmp.SaveToFile(filename);
     979    bmp.SaveToFileUTF8(filenameUTF8);
    928980  finally
    929981    bmp.Free;
     
    933985procedure TBGRACustomLayeredBitmap.SaveToStream(Stream: TStream);
    934986begin
    935   raise exception.Create('Not implemented');
     987  if Assigned(LayeredBitmapSaveToStreamProc) then
     988    LayeredBitmapSaveToStreamProc(Stream, self)
     989  else
     990    raise exception.Create('Call BGRAStreamLayers.RegisterStreamLayers first');
    936991end;
    937992
     
    11881243  linear := false; //to avoid hint
    11891244  for j := firstlayer to lastLayer do
    1190   if (BlendOperation[j] in [boTransparent,boLinearBlend]) or (start= 0) then
     1245  if (BlendOperation[j] in [boTransparent,boLinearBlend]) or (start = 0) or ((firstlayer= 0) and (j=0)) then
    11911246  begin
    11921247    nextLinear := (BlendOperation[j] = boLinearBlend) or self.LinearBlend;
     
    12391294end;
    12401295
    1241 procedure RegisterLayeredBitmapReader(AExtension: string; AReader: TBGRACustomLayeredBitmapClass);
     1296procedure RegisterLayeredBitmapReader(AExtensionUTF8: string; AReader: TBGRACustomLayeredBitmapClass);
    12421297begin
    12431298  setlength(LayeredBitmapReaders,length(LayeredBitmapReaders)+1);
    12441299  with LayeredBitmapReaders[high(LayeredBitmapReaders)] do
    12451300  begin
    1246     extension:= AExtension;
     1301    extension:= UTF8LowerCase(AExtensionUTF8);
    12471302    theClass := AReader;
    12481303  end;
    12491304end;
    12501305
    1251 procedure RegisterLayeredBitmapWriter(AExtension: string; AWriter: TBGRALayeredBitmapClass);
    1252 begin
     1306procedure OnLayeredBitmapLoadFromStreamStart;
     1307begin
     1308  OnLayeredBitmapLoadStart('<Stream>');
     1309end;
     1310
     1311procedure OnLayeredBitmapLoadStart(AFilenameUTF8: string);
     1312begin
     1313  if Assigned(OnLayeredBitmapLoadStartProc) then
     1314    OnLayeredBitmapLoadStartProc(AFilenameUTF8);
     1315end;
     1316
     1317procedure OnLayeredBitmapLoadProgress(APercentage: integer);
     1318begin
     1319  if Assigned(OnLayeredBitmapLoadProgressProc) then
     1320    OnLayeredBitmapLoadProgressProc(APercentage);
     1321end;
     1322
     1323procedure OnLayeredBitmapLoaded;
     1324begin
     1325  if Assigned(OnLayeredBitmapLoadedProc) then
     1326    OnLayeredBitmapLoadedProc();
     1327end;
     1328
     1329procedure RegisterLoadingHandler(AStart: TOnLayeredBitmapLoadStartProc;
     1330  AProgress: TOnLayeredBitmapLoadProgressProc; ADone: TOnLayeredBitmapLoadedProc
     1331  );
     1332begin
     1333  OnLayeredBitmapLoadProgressProc:= AProgress;
     1334  OnLayeredBitmapLoadStartProc := AStart;
     1335  OnLayeredBitmapLoadedProc:= ADone;
     1336end;
     1337
     1338procedure UnregisterLoadingHandler(AStart: TOnLayeredBitmapLoadStartProc;
     1339  AProgress: TOnLayeredBitmapLoadProgressProc; ADone: TOnLayeredBitmapLoadedProc);
     1340begin
     1341  if OnLayeredBitmapLoadProgressProc = AProgress then OnLayeredBitmapLoadProgressProc := nil;
     1342  if OnLayeredBitmapLoadStartProc = AStart then OnLayeredBitmapLoadStartProc := nil;
     1343  if OnLayeredBitmapLoadedProc = ADone then OnLayeredBitmapLoadedProc := nil;
     1344end;
     1345
     1346procedure RegisterLayeredBitmapWriter(AExtensionUTF8: string; AWriter: TBGRALayeredBitmapClass);
     1347begin
     1348  while (length(AExtensionUTF8)>0) and (AExtensionUTF8[1]='.') do delete(AExtensionUTF8,1,1);
    12531349  setlength(LayeredBitmapWriters,length(LayeredBitmapWriters)+1);
    12541350  with LayeredBitmapWriters[high(LayeredBitmapWriters)] do
    12551351  begin
    1256     extension:= AExtension;
     1352    extension:= UTF8LowerCase(AExtensionUTF8);
    12571353    theClass := AWriter;
    12581354  end;
Note: See TracChangeset for help on using the changeset viewer.