2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFImage;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-02-05 20:56:46 +01:00
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-02-19 13:35:01 +01:00
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows,{$ENDIF}
|
2017-02-05 20:56:46 +01:00
|
|
|
{$ELSE}
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF}
|
2017-02-05 20:56:46 +01:00
|
|
|
{$ENDIF}
|
2017-03-16 19:09:42 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefImageRef = class(TCefBaseRefCountedRef, ICefImage)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
|
|
|
function IsEmpty: Boolean;
|
|
|
|
function IsSame(const that: ICefImage): Boolean;
|
2018-03-29 20:02:04 +02:00
|
|
|
function AddBitmap(scaleFactor: Single; pixelWidth, pixelHeight: Integer; colorType: TCefColorType; alphaType: TCefAlphaType; const pixelData: Pointer; pixelDataSize: NativeUInt): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
function AddPng(scaleFactor: Single; const pngData: Pointer; pngDataSize: NativeUInt): Boolean;
|
|
|
|
function AddJpeg(scaleFactor: Single; const jpegData: Pointer; jpegDataSize: NativeUInt): Boolean;
|
|
|
|
function GetWidth: NativeUInt;
|
|
|
|
function GetHeight: NativeUInt;
|
|
|
|
function HasRepresentation(scaleFactor: Single): Boolean;
|
|
|
|
function RemoveRepresentation(scaleFactor: Single): Boolean;
|
2019-05-11 15:40:19 +02:00
|
|
|
function GetRepresentationInfo(scaleFactor: Single; var actualScaleFactor: Single; var pixelWidth, pixelHeight: Integer): Boolean;
|
|
|
|
function GetAsBitmap(scaleFactor: Single; colorType: TCefColorType; alphaType: TCefAlphaType; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
|
|
|
function GetAsPng(scaleFactor: Single; withTransparency: Boolean; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
|
|
|
function GetAsJpeg(scaleFactor: Single; quality: Integer; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
2017-01-27 16:37:51 +01:00
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefImage;
|
|
|
|
class function New: ICefImage;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBinaryValue;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefImageRef.AddBitmap(scaleFactor : Single;
|
|
|
|
pixelWidth : Integer;
|
|
|
|
pixelHeight : Integer;
|
|
|
|
colorType : TCefColorType;
|
|
|
|
alphaType : TCefAlphaType;
|
|
|
|
const pixelData : Pointer;
|
|
|
|
pixelDataSize : NativeUInt): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.add_bitmap(FData, scaleFactor, pixelWidth, pixelHeight, colorType, alphaType, pixelData, pixelDataSize) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefImageRef.AddJpeg(scaleFactor: Single; const jpegData: Pointer; jpegDataSize: NativeUInt): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.add_jpeg(FData, scaleFactor, jpegData, jpegDataSize) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefImageRef.AddPng(scaleFactor: Single; const pngData: Pointer; pngDataSize: NativeUInt): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.add_png(FData, scaleFactor, pngData, pngDataSize) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2019-05-11 15:40:19 +02:00
|
|
|
function TCefImageRef.GetAsBitmap(scaleFactor: Single; colorType: TCefColorType; alphaType: TCefAlphaType; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2019-05-11 15:40:19 +02:00
|
|
|
Result := TCefBinaryValueRef.UnWrap(PCefImage(FData)^.get_as_bitmap(FData, scaleFactor, colorType, alphaType, @pixelWidth, @pixelHeight));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2019-05-11 15:40:19 +02:00
|
|
|
function TCefImageRef.GetAsJpeg(scaleFactor: Single; quality: Integer; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2019-05-11 15:40:19 +02:00
|
|
|
Result := TCefBinaryValueRef.UnWrap(PCefImage(FData)^.get_as_jpeg(FData, scaleFactor, quality, @pixelWidth, @pixelHeight));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2019-05-11 15:40:19 +02:00
|
|
|
function TCefImageRef.GetAsPng(scaleFactor: Single; withTransparency: Boolean; var pixelWidth, pixelHeight: Integer): ICefBinaryValue;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2019-05-11 15:40:19 +02:00
|
|
|
Result := TCefBinaryValueRef.UnWrap(PCefImage(FData)^.get_as_png(FData, scaleFactor, Ord(withTransparency), @pixelWidth, @pixelHeight));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.GetHeight: NativeUInt;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.get_height(FData);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2019-05-11 15:40:19 +02:00
|
|
|
function TCefImageRef.GetRepresentationInfo(scaleFactor: Single; var actualScaleFactor: Single; var pixelWidth, pixelHeight: Integer): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2019-05-11 15:40:19 +02:00
|
|
|
Result := PCefImage(FData)^.get_representation_info(FData, scaleFactor, @actualScaleFactor, @pixelWidth, @pixelHeight) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.GetWidth: NativeUInt;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.get_width(FData);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.HasRepresentation(scaleFactor: Single): Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.has_representation(FData, scaleFactor) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.IsEmpty: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.is_empty(FData) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.IsSame(const that: ICefImage): Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.is_same(FData, CefGetData(that)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefImageRef.New: ICefImage;
|
|
|
|
begin
|
|
|
|
Result := UnWrap(cef_image_create());
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefImageRef.RemoveRepresentation(scaleFactor: Single): Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefImage(FData)^.remove_representation(FData, scaleFactor) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefImageRef.UnWrap(data: Pointer): ICefImage;
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefImage
|
|
|
|
else
|
2017-01-27 16:37:51 +01:00
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|