|
@@ -30,7 +30,8 @@ type
|
|
function SmartZoom3: boolean;
|
|
function SmartZoom3: boolean;
|
|
procedure Undo;
|
|
procedure Undo;
|
|
procedure Redo;
|
|
procedure Redo;
|
|
- procedure SetCurrentBitmap(bmp: TBGRABitmap; AUndoable: boolean);
|
|
|
|
|
|
+ procedure SetCurrentBitmap(bmp: TBGRABitmap; AUndoable: boolean;
|
|
|
|
+ ACaption: string = ''; AOpacity: byte = 255);
|
|
procedure CropToSelectionAndLayer;
|
|
procedure CropToSelectionAndLayer;
|
|
procedure CropToSelection;
|
|
procedure CropToSelection;
|
|
procedure HorizontalFlip(AOption: TFlipOption);
|
|
procedure HorizontalFlip(AOption: TFlipOption);
|
|
@@ -388,7 +389,7 @@ begin
|
|
end;
|
|
end;
|
|
FInstance.ShowTopmost(top);
|
|
FInstance.ShowTopmost(top);
|
|
end;
|
|
end;
|
|
- SetCurrentBitmap(partial,true);
|
|
|
|
|
|
+ SetCurrentBitmap(partial,true,image.LayerName[image.CurrentLayerIndex],image.LayerOpacity[image.CurrentLayerIndex]);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
partial.Free;
|
|
partial.Free;
|
|
@@ -401,15 +402,14 @@ end;
|
|
|
|
|
|
procedure TImageActions.CropToSelection;
|
|
procedure TImageActions.CropToSelection;
|
|
var cropped: TLayeredBitmapAndSelection;
|
|
var cropped: TLayeredBitmapAndSelection;
|
|
- r: TRect;
|
|
|
|
|
|
+ r, subBounds: TRect;
|
|
i,selectedLayer: integer;
|
|
i,selectedLayer: integer;
|
|
|
|
+ ofs: TPoint;
|
|
|
|
+ tempLayer, flattened: TBGRABitmap;
|
|
|
|
+ selectionIsRect: Boolean;
|
|
|
|
+ top: TTopMostInfo;
|
|
begin
|
|
begin
|
|
if not image.CheckNoAction then exit;
|
|
if not image.CheckNoAction then exit;
|
|
- if image.NbLayers = 1 then
|
|
|
|
- begin
|
|
|
|
- CropToSelectionAndLayer;
|
|
|
|
- exit;
|
|
|
|
- end;
|
|
|
|
try
|
|
try
|
|
if image.SelectionMaskEmpty then
|
|
if image.SelectionMaskEmpty then
|
|
begin
|
|
begin
|
|
@@ -421,15 +421,68 @@ begin
|
|
r := image.SelectionMaskBounds;
|
|
r := image.SelectionMaskBounds;
|
|
if (r.left = 0) and (r.Top = 0) and (r.right = image.width) and (r.Bottom =image.height) then exit;
|
|
if (r.left = 0) and (r.Top = 0) and (r.right = image.width) and (r.Bottom =image.height) then exit;
|
|
cropped := image.MakeLayeredBitmapAndSelectionCopy;
|
|
cropped := image.MakeLayeredBitmapAndSelectionCopy;
|
|
|
|
+ BGRAReplace(cropped.selection,cropped.selection.GetPart(r));
|
|
|
|
+ selectionIsRect := cropped.selection.Equals(BGRAWhite);
|
|
|
|
+ if cropped.selectionLayer <> nil then BGRAReplace(cropped.selectionLayer,cropped.selectionLayer.GetPart(r));
|
|
selectedLayer := image.CurrentLayerIndex;
|
|
selectedLayer := image.CurrentLayerIndex;
|
|
for i := 0 to cropped.layeredBitmap.NbLayers-1 do
|
|
for i := 0 to cropped.layeredBitmap.NbLayers-1 do
|
|
begin
|
|
begin
|
|
- cropped.layeredBitmap.LayerBitmap[i].ApplyMask(cropped.selection);
|
|
|
|
- cropped.layeredBitmap.SetLayerBitmap(i, cropped.layeredBitmap.LayerBitmap[i].GetPart(r) as TBGRABitmap, true);
|
|
|
|
|
|
+ tempLayer := TBGRABitmap.Create(r.Width,r.Height);
|
|
|
|
+ if selectionIsRect and (cropped.layeredBitmap.LayerOriginalGuid[i]<>GUID_NULL) and
|
|
|
|
+ cropped.layeredBitmap.LayerOriginalKnown[i] then
|
|
|
|
+ begin
|
|
|
|
+ ofs := cropped.layeredBitmap.LayerOffset[i];
|
|
|
|
+ cropped.layeredBitmap.LayerOriginalMatrix[i] :=
|
|
|
|
+ AffineMatrixTranslation(-r.Left, -r.Top)*
|
|
|
|
+ cropped.layeredBitmap.LayerOriginalMatrix[i];
|
|
|
|
+ cropped.layeredBitmap.RenderLayerFromOriginal(i);
|
|
|
|
+ end else
|
|
|
|
+ begin
|
|
|
|
+ ofs := cropped.layeredBitmap.LayerOffset[i];
|
|
|
|
+ tempLayer.PutImage(ofs.x-r.Left,ofs.y-r.Top, cropped.layeredBitmap.LayerBitmap[i], dmSet);
|
|
|
|
+ tempLayer.ApplyMask(cropped.selection);
|
|
|
|
+ cropped.layeredBitmap.SetLayerBitmap(i, tempLayer, true);
|
|
|
|
+ cropped.layeredBitmap.LayerOffset[i] := Point(0,0);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ if cropped.selectionLayer = nil then
|
|
|
|
+ begin
|
|
|
|
+ FreeAndNil(cropped.selection);
|
|
|
|
+ if (CurrentTool in [ptMoveSelection,ptRotateSelection]) then
|
|
|
|
+ ChooseTool(ptHand);
|
|
end;
|
|
end;
|
|
cropped.layeredBitmap.SetSize(r.right-r.left,r.Bottom-r.top);
|
|
cropped.layeredBitmap.SetSize(r.right-r.left,r.Bottom-r.top);
|
|
- BGRAReplace(cropped.selection,cropped.selection.GetPart(r));
|
|
|
|
- if cropped.selectionLayer <> nil then BGRAReplace(cropped.selectionLayer,cropped.selectionLayer.GetPart(r));
|
|
|
|
|
|
+ cropped.layeredBitmap.RemoveUnusedOriginals;
|
|
|
|
+ flattened := cropped.layeredBitmap.ComputeFlatImage;
|
|
|
|
+ subBounds := flattened.GetImageBounds;
|
|
|
|
+ flattened.Free;
|
|
|
|
+ if cropped.selectionLayer<>nil then
|
|
|
|
+ subBounds := RectUnion(subBounds, cropped.selectionLayer.GetImageBounds);
|
|
|
|
+ if (subBounds.Left > 0) or (subBounds.Top > 0) or
|
|
|
|
+ (subBounds.Right < cropped.layeredBitmap.Width) or (subBounds.Bottom < cropped.layeredBitmap.Height) then
|
|
|
|
+ begin
|
|
|
|
+ top := FInstance.HideTopmost;
|
|
|
|
+ case MessageDlg(rsCrop,rsKeepEmptySpace,mtConfirmation,mbYesNo,0) of
|
|
|
|
+ mrNo: begin
|
|
|
|
+ for i := 0 to cropped.layeredBitmap.NbLayers-1 do
|
|
|
|
+ begin
|
|
|
|
+ if cropped.layeredBitmap.LayerOriginalGuid[i]=GUID_NULL then
|
|
|
|
+ begin
|
|
|
|
+ ofs := cropped.layeredBitmap.LayerOffset[i];
|
|
|
|
+ cropped.layeredBitmap.LayerOffset[i] := Point(ofs.x-subBounds.Left,ofs.y-subBounds.Top);
|
|
|
|
+ end else
|
|
|
|
+ begin
|
|
|
|
+ cropped.layeredBitmap.LayerOriginalMatrix[i] :=
|
|
|
|
+ AffineMatrixTranslation(-subBounds.Left,-subBounds.Top)*
|
|
|
|
+ cropped.layeredBitmap.LayerOriginalMatrix[i];
|
|
|
|
+ cropped.layeredBitmap.RenderLayerFromOriginal(i);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ cropped.layeredBitmap.SetSize(subBounds.Width, subBounds.Height);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ FInstance.ShowTopmost(top);
|
|
|
|
+ end;
|
|
image.Assign(cropped,true,true);
|
|
image.Assign(cropped,true,true);
|
|
image.SetCurrentLayerByIndex(selectedLayer);
|
|
image.SetCurrentLayerByIndex(selectedLayer);
|
|
end;
|
|
end;
|
|
@@ -439,11 +492,12 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TImageActions.SetCurrentBitmap(bmp: TBGRABitmap; AUndoable : boolean);
|
|
|
|
|
|
+procedure TImageActions.SetCurrentBitmap(bmp: TBGRABitmap; AUndoable : boolean;
|
|
|
|
+ ACaption: string; AOpacity: byte);
|
|
begin
|
|
begin
|
|
ToolManager.ToolCloseDontReopen;
|
|
ToolManager.ToolCloseDontReopen;
|
|
try
|
|
try
|
|
- image.Assign(bmp,True,AUndoable);
|
|
|
|
|
|
+ image.Assign(bmp,True,AUndoable, ACaption,AOpacity);
|
|
finally
|
|
finally
|
|
ToolManager.ToolOpen;
|
|
ToolManager.ToolOpen;
|
|
end;
|
|
end;
|