|
@@ -6,7 +6,7 @@ interface
|
|
|
|
|
|
uses
|
|
uses
|
|
Classes, SysUtils, UStateType, BGRABitmap, BGRABitmapTypes, BGRALayers,
|
|
Classes, SysUtils, UStateType, BGRABitmap, BGRABitmapTypes, BGRALayers,
|
|
- BGRALayerOriginal, LCVectorOriginal;
|
|
|
|
|
|
+ BGRALayerOriginal, LCVectorOriginal, UImageState;
|
|
|
|
|
|
function IsInverseImageDiff(ADiff1, ADiff2: TCustomImageDifference): boolean;
|
|
function IsInverseImageDiff(ADiff1, ADiff2: TCustomImageDifference): boolean;
|
|
function TryCombineImageDiff(ANewDiff, APrevDiff: TCustomImageDifference): boolean;
|
|
function TryCombineImageDiff(ANewDiff, APrevDiff: TCustomImageDifference): boolean;
|
|
@@ -55,12 +55,14 @@ type
|
|
function GetIsIdentity: boolean; override;
|
|
function GetIsIdentity: boolean; override;
|
|
function GetChangingBoundsDefined: boolean; override;
|
|
function GetChangingBoundsDefined: boolean; override;
|
|
function GetChangingBounds: TRect; override;
|
|
function GetChangingBounds: TRect; override;
|
|
|
|
+ function GetLayerRect(AState: TImageState; AIndex: integer): TRect;
|
|
|
|
+ procedure EnsureLayerRect(AState: TImageState; AIndex: integer);
|
|
procedure Init(AToState: TState; APreviousImage: TBGRABitmap; APreviousImageChangeRect: TRect;
|
|
procedure Init(AToState: TState; APreviousImage: TBGRABitmap; APreviousImageChangeRect: TRect;
|
|
APreviousSelection: TBGRABitmap; APreviousSelectionChangeRect: TRect;
|
|
APreviousSelection: TBGRABitmap; APreviousSelectionChangeRect: TRect;
|
|
APreviousSelectionLayer: TBGRABitmap; APreviousSelectionLayerChangeRect: TRect);
|
|
APreviousSelectionLayer: TBGRABitmap; APreviousSelectionLayerChangeRect: TRect);
|
|
public
|
|
public
|
|
layerId: integer;
|
|
layerId: integer;
|
|
- imageOfs: TPoint;
|
|
|
|
|
|
+ layerRect: TRect;
|
|
imageDiff, selectionLayerDiff: TImageDiff;
|
|
imageDiff, selectionLayerDiff: TImageDiff;
|
|
selectionMaskDiff: TGrayscaleImageDiff;
|
|
selectionMaskDiff: TGrayscaleImageDiff;
|
|
function TryCompress: boolean; override;
|
|
function TryCompress: boolean; override;
|
|
@@ -165,7 +167,6 @@ type
|
|
useOriginal: boolean;
|
|
useOriginal: boolean;
|
|
previousOriginalRenderStatus: TOriginalRenderStatus;
|
|
previousOriginalRenderStatus: TOriginalRenderStatus;
|
|
layerId: integer;
|
|
layerId: integer;
|
|
- FDestination: TState;
|
|
|
|
previousLayerOffset: TPoint;
|
|
previousLayerOffset: TPoint;
|
|
protected
|
|
protected
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
@@ -292,8 +293,10 @@ type
|
|
FPreviousLayerContent: TStoredLayer;
|
|
FPreviousLayerContent: TStoredLayer;
|
|
FPrevMatrix,FNextMatrix: TAffineMatrix;
|
|
FPrevMatrix,FNextMatrix: TAffineMatrix;
|
|
FSourceBounds: TRect;
|
|
FSourceBounds: TRect;
|
|
|
|
+ FOriginalGuid: TGUID;
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
function CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal; virtual; abstract;
|
|
function CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal; virtual; abstract;
|
|
|
|
+ function ShouldRenderOriginal: boolean; virtual;
|
|
public
|
|
public
|
|
constructor Create(AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
constructor Create(AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
function UsedMemory: int64; override;
|
|
function UsedMemory: int64; override;
|
|
@@ -340,7 +343,23 @@ type
|
|
|
|
|
|
TReplaceLayerByVectorOriginalDifference = class(TReplaceLayerByOriginalDifference)
|
|
TReplaceLayerByVectorOriginalDifference = class(TReplaceLayerByOriginalDifference)
|
|
protected
|
|
protected
|
|
|
|
+ FShouldRenderOriginal: boolean;
|
|
|
|
+ function ShouldRenderOriginal: boolean; override;
|
|
function CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal; override;
|
|
function CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal; override;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ { TReplaceLayerByCustomOriginalDifference }
|
|
|
|
+
|
|
|
|
+ TReplaceLayerByCustomOriginalDifference = class(TReplaceLayerByOriginalDifference)
|
|
|
|
+ protected
|
|
|
|
+ FOriginal: TBGRALayerCustomOriginal;
|
|
|
|
+ function CreateOriginal({%H-}AState: TState; {%H-}ALayerIndex: integer): TBGRALayerCustomOriginal; override;
|
|
|
|
+ function ShouldRenderOriginal: boolean; override;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean; AOriginal: TBGRALayerCustomOriginal);
|
|
|
|
+ destructor Destroy; override;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TAddShapeToVectorOriginalDifference }
|
|
{ TAddShapeToVectorOriginalDifference }
|
|
@@ -349,7 +368,7 @@ type
|
|
private
|
|
private
|
|
FShapeIndex, FShapeId: integer;
|
|
FShapeIndex, FShapeId: integer;
|
|
FLayerId: integer;
|
|
FLayerId: integer;
|
|
- FShapeData: TBGRAMemOriginalStorage;
|
|
|
|
|
|
+ FShapeCopy: TVectorShape;
|
|
FShapeBounds: TRect;
|
|
FShapeBounds: TRect;
|
|
protected
|
|
protected
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
@@ -362,6 +381,26 @@ type
|
|
procedure UnapplyTo(AState: TState); override;
|
|
procedure UnapplyTo(AState: TState); override;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ { TVectorOriginalEmbeddedDifference }
|
|
|
|
+
|
|
|
|
+ TVectorOriginalEmbeddedDifference = class(TCustomImageDifference)
|
|
|
|
+ private
|
|
|
|
+ FDate: TDateTime;
|
|
|
|
+ FOriginalGuid: TGuid;
|
|
|
|
+ FDiff: TBGRAOriginalDiff;
|
|
|
|
+ FBounds: TRect;
|
|
|
|
+ protected
|
|
|
|
+ function GetImageDifferenceKind: TImageDifferenceKind; override;
|
|
|
|
+ function GetChangingBounds: TRect; override;
|
|
|
|
+ function GetChangingBoundsDefined: boolean; override;
|
|
|
|
+ function GetIsIdentity: boolean; override;
|
|
|
|
+ public
|
|
|
|
+ constructor Create({%H-}ADestination: TState; AOriginalGuid: TGuid; ADiff: TBGRAOriginalDiff; ABounds: TRect);
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
+ procedure ApplyTo(AState: TState); override;
|
|
|
|
+ procedure UnapplyTo(AState: TState); override;
|
|
|
|
+ end;
|
|
|
|
+
|
|
{ TDiscardOriginalStateDifference }
|
|
{ TDiscardOriginalStateDifference }
|
|
|
|
|
|
TDiscardOriginalStateDifference = class(TCustomImageDifference)
|
|
TDiscardOriginalStateDifference = class(TCustomImageDifference)
|
|
@@ -451,8 +490,9 @@ type
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
-uses BGRAWriteLzp, BGRAReadLzp, UImageState, BGRAStreamLayers, BGRALzpCommon, ugraph, Types,
|
|
|
|
- BGRATransform, zstream, LCVectorRectShapes, BGRAPen, math;
|
|
|
|
|
|
+uses BGRAWriteLzp, BGRAReadLzp, BGRAStreamLayers, BGRALzpCommon, ugraph, Types,
|
|
|
|
+ BGRATransform, zstream, LCVectorRectShapes, BGRAPen, LCVectorialFill,
|
|
|
|
+ BGRAGradientOriginal;
|
|
|
|
|
|
function IsInverseImageDiff(ADiff1, ADiff2: TCustomImageDifference): boolean;
|
|
function IsInverseImageDiff(ADiff1, ADiff2: TCustomImageDifference): boolean;
|
|
begin
|
|
begin
|
|
@@ -488,6 +528,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
function TryCombineImageDiff(ANewDiff, APrevDiff: TCustomImageDifference): boolean;
|
|
function TryCombineImageDiff(ANewDiff, APrevDiff: TCustomImageDifference): boolean;
|
|
|
|
+const VectorDiffMinTime = 2000/(1000*60*60*24);
|
|
var
|
|
var
|
|
combined: TInversibleAction;
|
|
combined: TInversibleAction;
|
|
begin
|
|
begin
|
|
@@ -572,9 +613,109 @@ begin
|
|
else result := false;
|
|
else result := false;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
|
|
+ if (APrevDiff is TVectorOriginalEmbeddedDifference) and (ANewDiff is TVectorOriginalEmbeddedDifference) then
|
|
|
|
+ begin
|
|
|
|
+ if (TVectorOriginalEmbeddedDifference(ANewDiff).FDate <
|
|
|
|
+ TVectorOriginalEmbeddedDifference(APrevDiff).FDate+VectorDiffMinTime) and
|
|
|
|
+ TVectorOriginalEmbeddedDifference(APrevDiff).FDiff.CanAppend(
|
|
|
|
+ TVectorOriginalEmbeddedDifference(ANewDiff).FDiff) then
|
|
|
|
+ begin
|
|
|
|
+ TVectorOriginalEmbeddedDifference(APrevDiff).FDiff.Append(
|
|
|
|
+ TVectorOriginalEmbeddedDifference(ANewDiff).FDiff);
|
|
|
|
+ result := true;
|
|
|
|
+ end else
|
|
|
|
+ result := false;
|
|
|
|
+ end else
|
|
result := false;
|
|
result := false;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+{ TReplaceLayerByCustomOriginalDifference }
|
|
|
|
+
|
|
|
|
+function TReplaceLayerByCustomOriginalDifference.CreateOriginal(AState: TState;
|
|
|
|
+ ALayerIndex: integer): TBGRALayerCustomOriginal;
|
|
|
|
+begin
|
|
|
|
+ result := FOriginal.Duplicate;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TReplaceLayerByCustomOriginalDifference.ShouldRenderOriginal: boolean;
|
|
|
|
+begin
|
|
|
|
+ result := true;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TReplaceLayerByCustomOriginalDifference.Create(AFromState: TState;
|
|
|
|
+ AIndex: integer; AAlwaysStoreBitmap: boolean; AOriginal: TBGRALayerCustomOriginal);
|
|
|
|
+begin
|
|
|
|
+ FOriginal := AOriginal;
|
|
|
|
+ inherited Create(AFromState,AIndex,AAlwaysStoreBitmap);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TReplaceLayerByCustomOriginalDifference.Destroy;
|
|
|
|
+begin
|
|
|
|
+ FOriginal.Free;
|
|
|
|
+ inherited Destroy;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TVectorOriginalEmbeddedDifference }
|
|
|
|
+
|
|
|
|
+function TVectorOriginalEmbeddedDifference.GetImageDifferenceKind: TImageDifferenceKind;
|
|
|
|
+begin
|
|
|
|
+ Result:= idkChangeImage;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TVectorOriginalEmbeddedDifference.GetChangingBounds: TRect;
|
|
|
|
+begin
|
|
|
|
+ Result:= FBounds;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TVectorOriginalEmbeddedDifference.GetChangingBoundsDefined: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:= true;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TVectorOriginalEmbeddedDifference.GetIsIdentity: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:= FDiff.IsIdentity;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TVectorOriginalEmbeddedDifference.Create(ADestination: TState;
|
|
|
|
+ AOriginalGuid: TGuid; ADiff: TBGRAOriginalDiff; ABounds: TRect);
|
|
|
|
+begin
|
|
|
|
+ FDate := Now;
|
|
|
|
+ FOriginalGuid:= AOriginalGuid;
|
|
|
|
+ FDiff := ADiff;
|
|
|
|
+ FBounds := ABounds;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TVectorOriginalEmbeddedDifference.Destroy;
|
|
|
|
+begin
|
|
|
|
+ FDiff.Free;
|
|
|
|
+ inherited Destroy;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TVectorOriginalEmbeddedDifference.ApplyTo(AState: TState);
|
|
|
|
+var
|
|
|
|
+ img: TImageState;
|
|
|
|
+ idxOrig: Integer;
|
|
|
|
+begin
|
|
|
|
+ inherited ApplyTo(AState);
|
|
|
|
+ img := AState as TImageState;
|
|
|
|
+ idxOrig := img.LayeredBitmap.IndexOfOriginal(FOriginalGuid);
|
|
|
|
+ if idxOrig<>-1 then
|
|
|
|
+ FDiff.Apply(img.LayeredBitmap.Original[idxOrig]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TVectorOriginalEmbeddedDifference.UnapplyTo(AState: TState);
|
|
|
|
+var
|
|
|
|
+ img: TImageState;
|
|
|
|
+ idxOrig: Integer;
|
|
|
|
+begin
|
|
|
|
+ inherited UnapplyTo(AState);
|
|
|
|
+ img := AState as TImageState;
|
|
|
|
+ idxOrig := img.LayeredBitmap.IndexOfOriginal(FOriginalGuid);
|
|
|
|
+ if idxOrig<>-1 then
|
|
|
|
+ FDiff.Unapply(img.LayeredBitmap.Original[idxOrig]);
|
|
|
|
+end;
|
|
|
|
+
|
|
{ TDiscardOriginalDifference }
|
|
{ TDiscardOriginalDifference }
|
|
|
|
|
|
function TDiscardOriginalDifference.GetLayerId: integer;
|
|
function TDiscardOriginalDifference.GetLayerId: integer;
|
|
@@ -692,7 +833,7 @@ constructor TAddShapeToVectorOriginalDifference.Create(ADestination: TState;
|
|
ALayerId: integer; AShape: TVectorShape; AShapeIndex: integer);
|
|
ALayerId: integer; AShape: TVectorShape; AShapeIndex: integer);
|
|
var
|
|
var
|
|
imgState: TImageState;
|
|
imgState: TImageState;
|
|
- layerIdx, idxShapeAdd: Integer;
|
|
|
|
|
|
+ layerIdx: Integer;
|
|
orig: TBGRALayerCustomOriginal;
|
|
orig: TBGRALayerCustomOriginal;
|
|
begin
|
|
begin
|
|
FLayerId := ALayerId;
|
|
FLayerId := ALayerId;
|
|
@@ -706,27 +847,25 @@ begin
|
|
end;
|
|
end;
|
|
if AShapeIndex = -1 then AShapeIndex := TVectorOriginal(orig).ShapeCount;
|
|
if AShapeIndex = -1 then AShapeIndex := TVectorOriginal(orig).ShapeCount;
|
|
FShapeIndex:= AShapeIndex;
|
|
FShapeIndex:= AShapeIndex;
|
|
- FShapeData := TBGRAMemOriginalStorage.Create;
|
|
|
|
- AShape.SaveToStorage(FShapeData);
|
|
|
|
- FShapeData.RawString['class'] := AShape.StorageClassName;
|
|
|
|
|
|
+ FShapeCopy := AShape.Duplicate;
|
|
|
|
|
|
inherited ApplyTo(ADestination);
|
|
inherited ApplyTo(ADestination);
|
|
- idxShapeAdd := TVectorOriginal(orig).AddShape(AShape);
|
|
|
|
- FShapeId := TVectorOriginal(orig).Shape[idxShapeAdd].Id;
|
|
|
|
- TVectorOriginal(orig).MoveShapeToIndex(idxShapeAdd, FShapeIndex);
|
|
|
|
|
|
+ TVectorOriginal(orig).InsertShape(AShape, FShapeIndex);
|
|
|
|
+ FShapeId := TVectorOriginal(orig).Shape[FShapeIndex].Id;
|
|
|
|
+ TVectorOriginal(orig).SelectShape(FShapeIndex);
|
|
FShapeBounds := imgState.LayeredBitmap.RenderOriginalIfNecessary(orig.Guid);
|
|
FShapeBounds := imgState.LayeredBitmap.RenderOriginalIfNecessary(orig.Guid);
|
|
end;
|
|
end;
|
|
|
|
|
|
destructor TAddShapeToVectorOriginalDifference.Destroy;
|
|
destructor TAddShapeToVectorOriginalDifference.Destroy;
|
|
begin
|
|
begin
|
|
- FShapeData.Free;
|
|
|
|
|
|
+ FShapeCopy.Free;
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TAddShapeToVectorOriginalDifference.ApplyTo(AState: TState);
|
|
procedure TAddShapeToVectorOriginalDifference.ApplyTo(AState: TState);
|
|
var
|
|
var
|
|
imgState: TImageState;
|
|
imgState: TImageState;
|
|
- layerIdx, idxShapeAdd: Integer;
|
|
|
|
|
|
+ layerIdx: Integer;
|
|
orig: TBGRALayerCustomOriginal;
|
|
orig: TBGRALayerCustomOriginal;
|
|
shape: TVectorShape;
|
|
shape: TVectorShape;
|
|
begin
|
|
begin
|
|
@@ -737,10 +876,10 @@ begin
|
|
if not (orig is TVectorOriginal) then
|
|
if not (orig is TVectorOriginal) then
|
|
raise exception.Create('Vector original expected');
|
|
raise exception.Create('Vector original expected');
|
|
|
|
|
|
- shape := TVectorShape.CreateFromStorage(FShapeData,nil);
|
|
|
|
- idxShapeAdd := TVectorOriginal(orig).AddShape(shape);
|
|
|
|
- TVectorOriginal(orig).Shape[idxShapeAdd].Id := FShapeId;
|
|
|
|
- TVectorOriginal(orig).MoveShapeToIndex(idxShapeAdd, FShapeIndex);
|
|
|
|
|
|
+ shape := FShapeCopy.Duplicate;
|
|
|
|
+ TVectorOriginal(orig).InsertShape(shape, FShapeIndex);
|
|
|
|
+ TVectorOriginal(orig).Shape[FShapeIndex].Id := FShapeId;
|
|
|
|
+ TVectorOriginal(orig).SelectShape(FShapeIndex);
|
|
imgState.LayeredBitmap.RenderLayerFromOriginal(layerIdx);
|
|
imgState.LayeredBitmap.RenderLayerFromOriginal(layerIdx);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -761,6 +900,11 @@ end;
|
|
|
|
|
|
{ TReplaceLayerByVectorOriginalDifference }
|
|
{ TReplaceLayerByVectorOriginalDifference }
|
|
|
|
|
|
|
|
+function TReplaceLayerByVectorOriginalDifference.ShouldRenderOriginal: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:= FShouldRenderOriginal;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TReplaceLayerByVectorOriginalDifference.CreateOriginal(AState: TState;
|
|
function TReplaceLayerByVectorOriginalDifference.CreateOriginal(AState: TState;
|
|
ALayerIndex: integer): TBGRALayerCustomOriginal;
|
|
ALayerIndex: integer): TBGRALayerCustomOriginal;
|
|
var
|
|
var
|
|
@@ -772,20 +916,42 @@ var
|
|
begin
|
|
begin
|
|
imgState := TImageState(AState);
|
|
imgState := TImageState(AState);
|
|
orig := TVectorOriginal.Create;
|
|
orig := TVectorOriginal.Create;
|
|
- source := imgState.LayeredBitmap.LayerBitmap[ALayerIndex];
|
|
|
|
- if not source.Empty then
|
|
|
|
|
|
+ if imgState.LayeredBitmap.LayerOriginalClass[ALayerIndex]=TBGRALayerGradientOriginal then
|
|
begin
|
|
begin
|
|
shape := TRectShape.Create(orig);
|
|
shape := TRectShape.Create(orig);
|
|
- shape.QuickDefine(PointF(0,0),PointF(FSourceBounds.Width,FSourceBounds.Height));
|
|
|
|
|
|
+ shape.QuickDefine(PointF(-0.5,-0.5),PointF(FSourceBounds.Width-0.5,FSourceBounds.Height-0.5));
|
|
shape.PenStyle := ClearPenStyle;
|
|
shape.PenStyle := ClearPenStyle;
|
|
- temp := source.GetPart(FSourceBounds) as TBGRABitmap;
|
|
|
|
- shape.BackFill.SetTexture(temp,AffineMatrixIdentity);
|
|
|
|
- temp.FreeReference;
|
|
|
|
|
|
+ shape.BackFill.SetGradient(
|
|
|
|
+ imgState.LayeredBitmap.LayerOriginal[ALayerIndex] as TBGRALayerGradientOriginal,false);
|
|
|
|
+ shape.BackFill.Transform(imgState.LayeredBitmap.LayerOriginalMatrix[ALayerIndex]);
|
|
orig.AddShape(shape);
|
|
orig.AddShape(shape);
|
|
|
|
+ end else
|
|
|
|
+ begin
|
|
|
|
+ source := imgState.LayeredBitmap.LayerBitmap[ALayerIndex];
|
|
|
|
+ if not source.Empty then
|
|
|
|
+ begin
|
|
|
|
+ shape := TRectShape.Create(orig);
|
|
|
|
+ shape.QuickDefine(PointF(-0.5,-0.5),PointF(FSourceBounds.Width-0.5,FSourceBounds.Height-0.5));
|
|
|
|
+ shape.PenStyle := ClearPenStyle;
|
|
|
|
+ temp := source.GetPart(FSourceBounds) as TBGRABitmap;
|
|
|
|
+ shape.BackFill.SetTexture(temp,AffineMatrixIdentity,255,trNone);
|
|
|
|
+ temp.FreeReference;
|
|
|
|
+ orig.AddShape(shape);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
result := orig;
|
|
result := orig;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+constructor TReplaceLayerByVectorOriginalDifference.Create(AFromState: TState;
|
|
|
|
+ AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
|
|
+var
|
|
|
|
+ imgState: TImageState;
|
|
|
|
+begin
|
|
|
|
+ imgState := AFromState as TImageState;
|
|
|
|
+ FShouldRenderOriginal:= imgState.LayeredBitmap.LayerOriginalClass[AIndex]=TBGRALayerGradientOriginal;
|
|
|
|
+ inherited Create(AFromState, AIndex, AAlwaysStoreBitmap);
|
|
|
|
+end;
|
|
|
|
+
|
|
{ TReplaceLayerByImageOriginalDifference }
|
|
{ TReplaceLayerByImageOriginalDifference }
|
|
|
|
|
|
function TReplaceLayerByImageOriginalDifference.CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal;
|
|
function TReplaceLayerByImageOriginalDifference.CreateOriginal(AState: TState; ALayerIndex: integer): TBGRALayerCustomOriginal;
|
|
@@ -923,6 +1089,11 @@ begin
|
|
Result:= idkChangeImage;
|
|
Result:= idkChangeImage;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TReplaceLayerByOriginalDifference.ShouldRenderOriginal: boolean;
|
|
|
|
+begin
|
|
|
|
+ result := false;
|
|
|
|
+end;
|
|
|
|
+
|
|
constructor TReplaceLayerByOriginalDifference.Create(
|
|
constructor TReplaceLayerByOriginalDifference.Create(
|
|
AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
AFromState: TState; AIndex: integer; AAlwaysStoreBitmap: boolean);
|
|
var
|
|
var
|
|
@@ -957,10 +1128,12 @@ begin
|
|
imgState := AState as TImageState;
|
|
imgState := AState as TImageState;
|
|
layerIdx := imgState.LayeredBitmap.GetLayerIndexFromId(FPreviousLayerContent.LayerId);
|
|
layerIdx := imgState.LayeredBitmap.GetLayerIndexFromId(FPreviousLayerContent.LayerId);
|
|
orig := CreateOriginal(imgState, layerIdx);
|
|
orig := CreateOriginal(imgState, layerIdx);
|
|
|
|
+ if FOriginalGuid <> GUID_NULL then orig.Guid := FOriginalGuid;
|
|
origIndex := imgState.LayeredBitmap.AddOriginal(orig, true);
|
|
origIndex := imgState.LayeredBitmap.AddOriginal(orig, true);
|
|
|
|
+ if FOriginalGuid = GUID_NULL then FOriginalGuid := orig.Guid;
|
|
imgState.LayeredBitmap.LayerOriginalGuid[layerIdx] := imgState.LayeredBitmap.OriginalGuid[origIndex];
|
|
imgState.LayeredBitmap.LayerOriginalGuid[layerIdx] := imgState.LayeredBitmap.OriginalGuid[origIndex];
|
|
imgState.LayeredBitmap.LayerOriginalMatrix[layerIdx] := FNextMatrix;
|
|
imgState.LayeredBitmap.LayerOriginalMatrix[layerIdx] := FNextMatrix;
|
|
- if FNextMatrix = FPrevMatrix then
|
|
|
|
|
|
+ if (FNextMatrix = FPrevMatrix) and not ShouldRenderOriginal then
|
|
imgState.LayeredBitmap.LayerOriginalRenderStatus[layerIdx] := orsProof
|
|
imgState.LayeredBitmap.LayerOriginalRenderStatus[layerIdx] := orsProof
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
@@ -1327,9 +1500,8 @@ var idx: integer;
|
|
clippedImage: TBGRABitmap;
|
|
clippedImage: TBGRABitmap;
|
|
begin
|
|
begin
|
|
inherited Create(ADestination);
|
|
inherited Create(ADestination);
|
|
- FDestination := ADestination;
|
|
|
|
layerId:= ALayerId;
|
|
layerId:= ALayerId;
|
|
- layers := (FDestination as TImageState).LayeredBitmap;
|
|
|
|
|
|
+ layers := (ADestination as TImageState).LayeredBitmap;
|
|
idx := layers.GetLayerIndexFromId(ALayerId);
|
|
idx := layers.GetLayerIndexFromId(ALayerId);
|
|
if idx = -1 then raise exception.Create('Invalid layer Id');
|
|
if idx = -1 then raise exception.Create('Invalid layer Id');
|
|
nextBounds := rect(0,0,layers.Width,layers.Height);
|
|
nextBounds := rect(0,0,layers.Width,layers.Height);
|
|
@@ -2233,13 +2405,41 @@ begin
|
|
if ChangeImageLayer then
|
|
if ChangeImageLayer then
|
|
begin
|
|
begin
|
|
r := imageDiff.ChangeRect;
|
|
r := imageDiff.ChangeRect;
|
|
- OffsetRect(r, imageOfs.x, imageOfs.y);
|
|
|
|
|
|
+ OffsetRect(r, layerRect.Left, layerRect.Top);
|
|
result := RectUnion(result, r);
|
|
result := RectUnion(result, r);
|
|
end;
|
|
end;
|
|
if ChangeSelectionLayer then result := RectUnion(result, selectionLayerDiff.ChangeRect);
|
|
if ChangeSelectionLayer then result := RectUnion(result, selectionLayerDiff.ChangeRect);
|
|
if ChangeSelectionMask then result := RectUnion(result, selectionMaskDiff.ChangeRect);
|
|
if ChangeSelectionMask then result := RectUnion(result, selectionMaskDiff.ChangeRect);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TImageLayerStateDifference.GetLayerRect(AState: TImageState;
|
|
|
|
+ AIndex: integer): TRect;
|
|
|
|
+begin
|
|
|
|
+ result.TopLeft := AState.LayerOffset[AIndex];
|
|
|
|
+ result.Width:= AState.LayerBitmap[AIndex].Width;
|
|
|
|
+ result.Height:= AState.LayerBitmap[AIndex].Height;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TImageLayerStateDifference.EnsureLayerRect(AState: TImageState;
|
|
|
|
+ AIndex: integer);
|
|
|
|
+var
|
|
|
|
+ curRect: TRect;
|
|
|
|
+ newBmp: TBGRABitmap;
|
|
|
|
+begin
|
|
|
|
+ curRect := GetLayerRect(AState, AIndex);
|
|
|
|
+ if (layerRect.Left<>curRect.Left) or
|
|
|
|
+ (layerRect.Top<>curRect.Top) or
|
|
|
|
+ (layerRect.Width<>curRect.Width) or
|
|
|
|
+ (layerRect.Height<>curRect.Height) then
|
|
|
|
+ begin
|
|
|
|
+ newBmp := TBGRABitmap.Create(layerRect.Width,layerRect.Height);
|
|
|
|
+ newBmp.PutImage(curRect.Left-layerRect.Left,curRect.Top-layerRect.Top,
|
|
|
|
+ AState.LayerBitmap[AIndex], dmSet);
|
|
|
|
+ AState.SetLayerBitmap(AIndex, newBmp, true);
|
|
|
|
+ AState.LayeredBitmap.LayerOffset[AIndex] := layerRect.TopLeft;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TImageLayerStateDifference.Init(AToState: TState; APreviousImage: TBGRABitmap; APreviousImageChangeRect: TRect;
|
|
procedure TImageLayerStateDifference.Init(AToState: TState; APreviousImage: TBGRABitmap; APreviousImageChangeRect: TRect;
|
|
APreviousSelection: TBGRABitmap; APreviousSelectionChangeRect: TRect;
|
|
APreviousSelection: TBGRABitmap; APreviousSelectionChangeRect: TRect;
|
|
APreviousSelectionLayer: TBGRABitmap; APreviousSelectionLayerChangeRect: TRect);
|
|
APreviousSelectionLayer: TBGRABitmap; APreviousSelectionLayerChangeRect: TRect);
|
|
@@ -2250,7 +2450,7 @@ begin
|
|
inherited Create((AToState as TImageState).saved,false);
|
|
inherited Create((AToState as TImageState).saved,false);
|
|
layerId := -1;
|
|
layerId := -1;
|
|
imageDiff := nil;
|
|
imageDiff := nil;
|
|
- imageOfs := Point(0,0);
|
|
|
|
|
|
+ layerRect := EmptyRect;
|
|
selectionMaskDiff := nil;
|
|
selectionMaskDiff := nil;
|
|
selectionLayerDiff := nil;
|
|
selectionLayerDiff := nil;
|
|
|
|
|
|
@@ -2264,7 +2464,7 @@ begin
|
|
if not IsRectEmpty(APreviousImageChangeRect) then
|
|
if not IsRectEmpty(APreviousImageChangeRect) then
|
|
begin
|
|
begin
|
|
imageDiff := TImageDiff.Create(APreviousImage,next.LayerBitmap[curIdx],APreviousImageChangeRect);
|
|
imageDiff := TImageDiff.Create(APreviousImage,next.LayerBitmap[curIdx],APreviousImageChangeRect);
|
|
- imageOfs := next.LayerOffset[curIdx];
|
|
|
|
|
|
+ layerRect := GetLayerRect(next,curIdx);
|
|
end;
|
|
end;
|
|
if not IsRectEmpty(APreviousSelectionChangeRect) then
|
|
if not IsRectEmpty(APreviousSelectionChangeRect) then
|
|
selectionMaskDiff := TGrayscaleImageDiff.Create(APreviousSelection,next.SelectionMask,APreviousSelectionChangeRect);
|
|
selectionMaskDiff := TGrayscaleImageDiff.Create(APreviousSelection,next.SelectionMask,APreviousSelectionChangeRect);
|
|
@@ -2294,7 +2494,11 @@ begin
|
|
idx := lState.LayeredBitmap.GetLayerIndexFromId(layerId);
|
|
idx := lState.LayeredBitmap.GetLayerIndexFromId(layerId);
|
|
if idx = -1 then raise exception.Create('Layer not found');
|
|
if idx = -1 then raise exception.Create('Layer not found');
|
|
if ChangeImageLayer and (lState.LayeredBitmap.LayerOriginalGuid[idx] <> GUID_NULL) then raise exception.Create('Does not apply to originals');
|
|
if ChangeImageLayer and (lState.LayeredBitmap.LayerOriginalGuid[idx] <> GUID_NULL) then raise exception.Create('Does not apply to originals');
|
|
- if ChangeImageLayer then lState.LayeredBitmap.SetLayerBitmap(idx, imageDiff.ApplyCanCreateNew(lState.LayerBitmap[idx],False), True);
|
|
|
|
|
|
+ if ChangeImageLayer then
|
|
|
|
+ begin
|
|
|
|
+ EnsureLayerRect(lState,idx);
|
|
|
|
+ lState.LayeredBitmap.SetLayerBitmap(idx, imageDiff.ApplyCanCreateNew(lState.LayerBitmap[idx],False), True);
|
|
|
|
+ end;
|
|
if ChangeSelectionMask then newSelectionMask := selectionMaskDiff.ApplyCanCreateNew(lState.SelectionMask,False) else newSelectionMask := lState.SelectionMask;
|
|
if ChangeSelectionMask then newSelectionMask := selectionMaskDiff.ApplyCanCreateNew(lState.SelectionMask,False) else newSelectionMask := lState.SelectionMask;
|
|
if ChangeSelectionLayer then newSelectionLayer := selectionLayerDiff.ApplyCanCreateNew(lState.SelectionLayer,False) else newSelectionLayer := lState.SelectionLayer;
|
|
if ChangeSelectionLayer then newSelectionLayer := selectionLayerDiff.ApplyCanCreateNew(lState.SelectionLayer,False) else newSelectionLayer := lState.SelectionLayer;
|
|
lState.ReplaceSelection(newSelectionMask, newSelectionLayer);
|
|
lState.ReplaceSelection(newSelectionMask, newSelectionLayer);
|
|
@@ -2314,7 +2518,11 @@ begin
|
|
idx := lState.LayeredBitmap.GetLayerIndexFromId(layerId);
|
|
idx := lState.LayeredBitmap.GetLayerIndexFromId(layerId);
|
|
if idx = -1 then raise exception.Create('Layer not found');
|
|
if idx = -1 then raise exception.Create('Layer not found');
|
|
if ChangeImageLayer and (lState.LayeredBitmap.LayerOriginalGuid[idx] <> GUID_NULL) then raise exception.Create('Does not apply to originals');
|
|
if ChangeImageLayer and (lState.LayeredBitmap.LayerOriginalGuid[idx] <> GUID_NULL) then raise exception.Create('Does not apply to originals');
|
|
- if ChangeImageLayer then lState.LayeredBitmap.SetLayerBitmap(idx, imageDiff.ApplyCanCreateNew(lState.LayerBitmap[idx],True), True);
|
|
|
|
|
|
+ if ChangeImageLayer then
|
|
|
|
+ begin
|
|
|
|
+ EnsureLayerRect(lState,idx);
|
|
|
|
+ lState.LayeredBitmap.SetLayerBitmap(idx, imageDiff.ApplyCanCreateNew(lState.LayerBitmap[idx],True), True);
|
|
|
|
+ end;
|
|
if ChangeSelectionMask then newSelectionMask := selectionMaskDiff.ApplyCanCreateNew(lState.SelectionMask,True) else newSelectionMask := lState.SelectionMask;
|
|
if ChangeSelectionMask then newSelectionMask := selectionMaskDiff.ApplyCanCreateNew(lState.SelectionMask,True) else newSelectionMask := lState.SelectionMask;
|
|
if ChangeSelectionLayer then newSelectionLayer := selectionLayerDiff.ApplyCanCreateNew(lState.SelectionLayer,True) else newSelectionLayer := lState.SelectionLayer;
|
|
if ChangeSelectionLayer then newSelectionLayer := selectionLayerDiff.ApplyCanCreateNew(lState.SelectionLayer,True) else newSelectionLayer := lState.SelectionLayer;
|
|
lState.ReplaceSelection(newSelectionMask, newSelectionLayer);
|
|
lState.ReplaceSelection(newSelectionMask, newSelectionLayer);
|
|
@@ -2337,7 +2545,7 @@ begin
|
|
inherited Create(AFromState,AToState);
|
|
inherited Create(AFromState,AToState);
|
|
layerId := -1;
|
|
layerId := -1;
|
|
imageDiff := nil;
|
|
imageDiff := nil;
|
|
- imageOfs := Point(0,0);
|
|
|
|
|
|
+ layerRect := EmptyRect;
|
|
selectionMaskDiff := nil;
|
|
selectionMaskDiff := nil;
|
|
selectionLayerDiff := nil;
|
|
selectionLayerDiff := nil;
|
|
|
|
|
|
@@ -2353,7 +2561,7 @@ begin
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
imageDiff := TImageDiff.Create(prev.LayerBitmap[prevIdx],next.LayerBitmap[curIdx]);
|
|
imageDiff := TImageDiff.Create(prev.LayerBitmap[prevIdx],next.LayerBitmap[curIdx]);
|
|
- imageOfs := next.LayerOffset[curIdx];
|
|
|
|
|
|
+ layerRect := GetLayerRect(next,curIdx);
|
|
selectionMaskDiff := TGrayscaleImageDiff.Create(prev.SelectionMask,next.SelectionMask);
|
|
selectionMaskDiff := TGrayscaleImageDiff.Create(prev.SelectionMask,next.SelectionMask);
|
|
selectionLayerDiff := TImageDiff.Create(prev.SelectionLayer,next.SelectionLayer);
|
|
selectionLayerDiff := TImageDiff.Create(prev.SelectionLayer,next.SelectionLayer);
|
|
end;
|
|
end;
|