Skip to content

Commit

Permalink
update compatibilidade com linux
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsbejatto committed Apr 12, 2023
1 parent 22a27b7 commit 2bfb1db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
81 changes: 41 additions & 40 deletions Source/Core/ormbr.types.blob.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ interface
SysUtils,
{$IFDEF HAS_FMX}
FMX.Graphics,
{$ELSE}
{$ENDIF}
{$IFDEF HAS_VCL}
// Delphi > 2010 adicionar em:
// Option->Delphi Compiler->Unit scope names, "Vcl", "Vcl.Imaging"
Graphics,
Expand Down Expand Up @@ -66,7 +67,7 @@ TBlob = record
FBase64Bytes: TBytes;
FBlobField: TBlobField;
function StreamToByteArray(AStream: TStream): TBytes;
{$IFNDEF HAS_FMX}
{$IFDEF HAS_VCL}
function FindGraphicClass(const ABuffer; const ABufferSize: Int64;
out AGraphicClass: TGraphicClass): Boolean; overload;
function FindGraphicClass(AStream: TStream;
Expand All @@ -82,10 +83,10 @@ TBlob = record
procedure SetBytes(const Value: TBytes);
procedure LoadFromFile(const AFileName: string; const ACompression: Boolean = False);
procedure SaveToFile(const FileName: string);
{$IFNDEF HAS_FMX}
{$IFDEF HAS_VCL}
procedure ToPicture(APicture: TPicture; const ACompression: Boolean = False);
{$ENDIF}
procedure ToBitmap(ABitmap: TBitmap; const ACompression: Boolean = False);
{$ENDIF}
function ToBytes: TBytes;
function ToBytesString: string; overload;
function ToStringBytes(const AString: string): Boolean; overload;
Expand Down Expand Up @@ -175,7 +176,7 @@ function TBlob.StreamToByteArray(AStream: TStream): TBytes;
SetLength(Result, 0);
end;

{$IFNDEF HAS_FMX}
{$IFDEF HAS_VCL}
procedure TBlob.ToPicture(APicture: TPicture; const ACompression: Boolean);
var
LGraphic: TGraphic;
Expand Down Expand Up @@ -220,14 +221,48 @@ procedure TBlob.ToPicture(APicture: TPicture; const ACompression: Boolean);
LGraphic.Free;
end;
end;

procedure TBlob.ToBitmap(ABitmap: TBitmap; const ACompression: Boolean);
var
LSourceStream: TMemoryStream;
LTargetStream: TMemoryStream;
begin
LSourceStream := TMemoryStream.Create;
try
if Length(FBase64Bytes) = 0 then
begin
ABitmap.Assign(nil);
Exit;
end;
LSourceStream.Write(FBase64Bytes, ToSize);
if ACompression then
begin
LTargetStream := TMemoryStream.Create;
try
DecompressStream(LSourceStream, LTargetStream);
LTargetStream.Position := 0;
ABitmap.LoadFromStream(LTargetStream);
finally
LTargetStream.Free;
end;
end
else
begin
LSourceStream.Position := 0;
ABitmap.LoadFromStream(LSourceStream);
end;
finally
LSourceStream.Free;
end;
end;
{$ENDIF}

function TBlob.ToSize: Integer;
begin
Result := Length(FBase64Bytes);
end;

{$IFNDEF HAS_FMX}
{$IFDEF HAS_VCL}
function TBlob.FindGraphicClass(const ABuffer; const ABufferSize: Int64;
out AGraphicClass: TGraphicClass): Boolean;
var
Expand Down Expand Up @@ -320,40 +355,6 @@ procedure TBlob.LoadFromFile(const AFileName: string;
end
end;

procedure TBlob.ToBitmap(ABitmap: TBitmap; const ACompression: Boolean);
var
LSourceStream: TMemoryStream;
LTargetStream: TMemoryStream;
begin
LSourceStream := TMemoryStream.Create;
try
if Length(FBase64Bytes) = 0 then
begin
ABitmap.Assign(nil);
Exit;
end;
LSourceStream.Write(FBase64Bytes, ToSize);
if ACompression then
begin
LTargetStream := TMemoryStream.Create;
try
DecompressStream(LSourceStream, LTargetStream);
LTargetStream.Position := 0;
ABitmap.LoadFromStream(LTargetStream);
finally
LTargetStream.Free;
end;
end
else
begin
LSourceStream.Position := 0;
ABitmap.LoadFromStream(LSourceStream);
end;
finally
LSourceStream.Free;
end;
end;

function TBlob.ToBytes: TBytes;
begin
Result := FBase64Bytes;
Expand Down
3 changes: 2 additions & 1 deletion Source/ormbr.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@

{$IFDEF FMX}
{$DEFINE HAS_FMX}
{$ELSE}
{$ENDIF}
{$IFDEF VCL}
{$DEFINE HAS_VCL}
{$ENDIF}

Expand Down

0 comments on commit 2bfb1db

Please sign in to comment.