Browse Source

FlashProgressBar UseTimerThread; ImageManipulation Deleted recreate of Bitmap and Empty; Optimization and code clean; Updated ImageManipulation Demo (tested on gtk2)

FlashProgressBar UseTimerThread;
ImageManipulation Deleted recreate of Bitmap and Empty; Optimization and code clean;
Updated ImageManipulation Demo (tested on gtk2)
Massimo Magnano 10 months ago
parent
commit
55f00b4cfc

+ 1 - 0
bgraflashprogressbar.pas

@@ -875,6 +875,7 @@ begin
   FGraphYLineDigits:= 0;
 
   internalTimer:= TFPTimer.Create(Self);
+  internalTimer.UseTimerThread:= True;
   internalTimer.Enabled:= False;
   internalTimer.Interval:= MARQUEE_TIMER_MED;
   internalTimer.OnTimer:= TimerOnTimer;

+ 209 - 202
bgraimagemanipulation.pas

@@ -82,6 +82,7 @@ unit BGRAImageManipulation;
                CopyPropertiesToArea and Icons in NewCropAreaDefault
                Updated Component icon
   2025-01    - Added Load/Save and their events
+      -02    - Deleted recreate of Bitmap and Empty; Optimization and code clean
   ============================================================================
 }
 
@@ -196,7 +197,7 @@ type
     procedure setName(AValue: String);
     procedure setIcons(AValue: TCropAreaIcons);
 
-    procedure Render_Refresh;
+    procedure Render_Invalidate;
 
     procedure GetImageResolution(var resX, resY:Single; var resUnit:TResolutionUnit);
     procedure CalculateScaledAreaFromArea;
@@ -419,7 +420,6 @@ type
     rOnBitmapLoadAfter: TBGRAIMBitmapLoadAfter;
     rOnContextPopup: TBGRAIMContextPopupEvent;
     rEmptyImage: TBGRAEmptyImage;
-    rLoading: Boolean;
     rOpacity: Byte;
 
     function ApplyDimRestriction(Coords: TCoord; Direction: TDirection; Bounds: TRect; AKeepAspectRatio:Boolean): TCoord;
@@ -434,11 +434,14 @@ type
     procedure CreateEmptyImage;
     procedure CreateResampledBitmap;
 
+    class function GetControlClassDefaultSize: TSize; override;
+    procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean); override;
     procedure Loaded; override;
     procedure Paint; override;
-    procedure RepaintBackground;
-    procedure Resize; override;
+    procedure DoOnResize; override;
+    procedure RenderBackground;
     procedure Render;
+    procedure Render_Invalidate;
 
     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
     procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
@@ -537,7 +540,9 @@ procedure PixelXResolutionUnitConvert(var resX, resY:Single; fromRes, toRes:TRes
 
 implementation
 
-uses Math, ExtCtrls, BGRAUTF8, UniversalDrawer, BGRAWritePNG, FPWritePNM;
+uses
+  {$ifopt D+}LazLogger,{$endif}
+  Math, ExtCtrls, BGRAUTF8, UniversalDrawer, BGRAWritePNG, FPWritePNM;
 
 resourcestring
   SAnchorSizeIsTooLarge =
@@ -665,12 +670,19 @@ end;
 
 { TCropArea }
 
-procedure TCropArea.Render_Refresh;
+procedure TCropArea.Render_Invalidate;
 begin
   if not(fOwner.rCropAreas.loading) then
   begin
-    fOwner.Render;
-    fOwner.Refresh;
+    {$ifopt D+}
+     DebugLn('  CropArea Render_Invalidate');
+    {$endif}
+
+    fOwner.Render_Invalidate;
+
+    {$ifopt D+}
+     DebugLn('  CropArea Render_Invalidate done');
+    {$endif}
   end;
 end;
 
@@ -712,7 +724,7 @@ procedure TCropArea.setIcons(AValue: TCropAreaIcons);
 begin
   if rIcons=AValue then Exit;
   rIcons:=AValue;
-  Render_Refresh;
+  Render_Invalidate;
 end;
 
 function TCropArea.getTop: Single;
@@ -1081,7 +1093,7 @@ begin
 
             fOwner.ApplyRatioToArea(Self);
 
-            Render_Refresh;
+            Render_Invalidate;
          end;
       end;
 end;
@@ -1103,7 +1115,7 @@ begin
        then fOwner.ApplyRatioToArea(Self);
 
 
-  Render_Refresh;
+  Render_Invalidate;
 end;
 
 procedure TCropArea.setArea(AValue: TRectF);
@@ -1158,7 +1170,7 @@ begin
 
          CalculateScaledAreaFromArea;
 
-         Render_Refresh;
+         Render_Invalidate;
        end;
 
   if assigned(fOwner.rOnCropAreaChanged)
@@ -1304,7 +1316,7 @@ begin
 
          CalculateAreaFromScaledArea;
 
-         Render_Refresh;
+         Render_Invalidate;
        end;
 
   if assigned(fOwner.rOnCropAreaChanged)
@@ -1676,8 +1688,7 @@ begin
    finally
      loading :=False;
 
-     fOwner.Render;
-     fOwner.Refresh;
+     fOwner.Render_Invalidate;
    end;
 end;
 
@@ -2699,8 +2710,8 @@ end;
 
 procedure TBGRAImageManipulation.CreateEmptyImage;
 begin
-  fImageBitmap.Free;
-  fImageBitmap :=TBGRABitmap.Create(EmptyImage.Width, EmptyImage.Height);
+  fImageBitmap.SetSize(EmptyImage.Width, EmptyImage.Height);
+  fImageBitmap.FillTransparent;
   fImageBitmap.ResolutionUnit :=ruPixelsPerInch;
   fImageBitmap.ResolutionX :=Self.PixelsPerInch;
   fImageBitmap.ResolutionY :=fImageBitmap.ResolutionX;
@@ -2709,7 +2720,7 @@ end;
 procedure TBGRAImageManipulation.CreateResampledBitmap;
 var
   DestinationRect: TRect;
-  ResampledBitmap: TBGRACustomBitmap;
+  tempBitmap: TBGRACustomBitmap;
 
 begin
   // Get the resampled dimensions to scale image for draw in component
@@ -2717,19 +2728,35 @@ begin
 
   // Recreate resampled bitmap
   try
-    fResampledBitmap.Free;
-    fResampledBitmap := TBGRABitmap.Create(DestinationRect.Right - DestinationRect.Left,
-                                           DestinationRect.Bottom - DestinationRect.Top);
-    ResampledBitmap  := fImageBitmap.Resample(DestinationRect.Right - DestinationRect.Left,
-                                              DestinationRect.Bottom - DestinationRect.Top, rmFineResample);
-    fResampledBitmap.BlendImage(0, 0, ResampledBitmap, boLinearBlend);
+    fResampledBitmap.SetSize(DestinationRect.Right - DestinationRect.Left,
+                             DestinationRect.Bottom - DestinationRect.Top);
+    tempBitmap  := fImageBitmap.Resample(DestinationRect.Right - DestinationRect.Left,
+                                         DestinationRect.Bottom - DestinationRect.Top, rmFineResample);
+    fResampledBitmap.BlendImage(0, 0, tempBitmap, boLinearBlend);
   finally
-    ResampledBitmap.Free;
+    tempBitmap.Free;
   end;
 end;
 
+class function TBGRAImageManipulation.GetControlClassDefaultSize: TSize;
+begin
+  Result.CX := 320;
+  Result.CY := 240;
+end;
+
+procedure TBGRAImageManipulation.CalculatePreferredSize(var PreferredWidth,
+  PreferredHeight: integer; WithThemeSpace: boolean);
+begin
+  PreferredWidth  := 320;
+  PreferredHeight := 240;
+end;
+
 procedure TBGRAImageManipulation.Loaded;
 begin
+  {$ifopt D+}
+   DebugLn('Loaded '+BoolToStr(csLoading in ComponentState, True));
+  {$endif}
+
   inherited Loaded;
 
   if Self.Empty then
@@ -2738,11 +2765,13 @@ begin
     CreateResampledBitmap;
   end;
 
-  rLoading:=False;
-
   // Force Render Struct
-  RepaintBackground;
-  Render;
+//  RenderBackground;
+//  Render;
+
+  {$ifopt D+}
+   DebugLn('Loaded done');
+  {$endif}
 end;
 
  { ============================================================================ }
@@ -2754,14 +2783,14 @@ var
    fGCD     :integer;
 
 begin
-  inherited Create(AOwner);
+  {$ifopt D+}
+   DebugLn('Create');
+  {$endif}
 
-  //MaxM: csLoading in ComponentState does not work?
-  rLoading :=True;
+  inherited Create(AOwner);
 
   // Set default component values
-  inherited Width := 320;
-  inherited Height := 240;
+  with GetControlClassDefaultSize do SetInitialBounds(0, 0, CX, CY);
 
   // Default property values
   fAnchorSize := 5;
@@ -2812,6 +2841,10 @@ begin
   rSelectedCropArea :=Nil;
 
   fMouseCaught := False;
+
+  {$ifopt D+}
+   DebugLn('Create done');
+  {$endif}
 end;
 
 destructor TBGRAImageManipulation.Destroy;
@@ -2829,20 +2862,41 @@ end;
 
 procedure TBGRAImageManipulation.Invalidate;
 begin
+  {$ifopt D+}
+   DebugLn('Invalidate');
+  {$endif}
+
   inherited Invalidate;
+
+  {$ifopt D+}
+   DebugLn('Invalidate done');
+  {$endif}
 end;
 
 procedure TBGRAImageManipulation.Paint;
 begin
+  {$ifopt D+}
+   DebugLn('Paint');
+  {$endif}
+
   inherited Paint;
+
+  {$ifopt D+}
+   DebugLn('Paint inherited done '+BoolToStr(fVirtualScreen<>nil, True)+' '+BoolToStr(Canvas<>nil, True));
+  {$endif}
+
   fVirtualScreen.Draw(Canvas, 0, 0, True);
+
+  {$ifopt D+}
+   DebugLn('Paint done');
+  {$endif}
 end;
 
 { This function repaint the background only when necessary to avoid unnecessary
   redraws. Contain a function called DrawCheckers that draws the Background like
   checkers game. Also included was a function that draws 3D effects changed to
   allow color changes. }
-procedure TBGRAImageManipulation.RepaintBackground;
+procedure TBGRAImageManipulation.RenderBackground;
 
   procedure DrawCheckers(bmp: TBGRABitmap; ARect: TRect);
   const
@@ -2878,8 +2932,9 @@ var
   Border: TRect;
   Grad: TBGRAGradientScanner;
 begin
-  // Resize background
-  fBackground.SetSize(fVirtualScreen.Width, fVirtualScreen.Height);
+  {$ifopt D+}
+   DebugLn('RenderBackground');
+  {$endif}
 
   // Draw the outer bevel
   Border := Rect(0, 0, fVirtualScreen.Width, fVirtualScreen.Height);
@@ -2909,10 +2964,14 @@ begin
     cl3DLight, clBtnShadow);
 
   DrawCheckers(fBackground, Border);
+
+  {$ifopt D+}
+   DebugLn('RenderBackground done');
+  {$endif}
 end;
 
 { Resize the component, recalculating the proportions }
-procedure TBGRAImageManipulation.Resize;
+procedure TBGRAImageManipulation.DoOnResize;
 
   function min(const Value: integer; const MinValue: integer): integer;
   begin
@@ -2927,10 +2986,9 @@ var
   curCropArea    :TCropArea;
 
 begin
-  inherited Resize;
-
-  //MaxM: Maybe csLoading in ComponentState but it does not work
-  //if rLoading then exit;
+  {$ifopt D+}
+   DebugLn('DoOnResize '+BoolToStr(fVirtualScreen<>nil, True));
+  {$endif}
 
   if (fVirtualScreen <> nil) then
   begin
@@ -2938,8 +2996,10 @@ begin
       min(Self.Height, (fBorderSize * 2 + fAnchorSize + fMinHeight)));
     fVirtualScreen.InvalidateBitmap;
 
-    if Self.Empty
-    then CreateEmptyImage;
+    // Resize background
+    fBackground.SetSize(fVirtualScreen.Width, fVirtualScreen.Height);
+
+    if Self.Empty then CreateEmptyImage;
 
     CreateResampledBitmap;
 
@@ -2956,11 +3016,15 @@ begin
     end;
 
     // Force Render Struct
-    RepaintBackground;
+    RenderBackground;
     Render;
   end;
 
-  Invalidate;
+  inherited DoOnResize;
+
+  {$ifopt D+}
+   DebugLn('DoOnResize done');
+  {$endif}
 end;
 
 { Function responsible for rendering the content of the component, including
@@ -2978,6 +3042,10 @@ var
   TextS:TTextStyle;
 
 begin
+  {$ifopt D+}
+   DebugLn('Render');
+  {$endif}
+
   // This procedure render main feature of engine
 
   // Render background
@@ -3155,6 +3223,16 @@ begin
     fVirtualScreen.BlendImage(WorkRect.Left, WorkRect.Top, Mask, boLinearBlend);
     Mask.Free;
   end;
+
+  {$ifopt D+}
+   DebugLn('Render done');
+  {$endif}
+end;
+
+procedure TBGRAImageManipulation.Render_Invalidate;
+begin
+  Render;
+  Invalidate;
 end;
 
  { ============================================================================ }
@@ -3180,38 +3258,18 @@ const
 begin
   if (Value <> getAnchorSize) then
   begin
-    if (Value < MinSize) then
-    begin
-      raise ERangeError.CreateFmt(SAnchorSizeIsTooSmall,
-        [Value, MinSize, MaxSize]);
-    end
-    else
-    begin
-      if (Value > MaxSize) then
-      begin
-        raise ERangeError.CreateFmt(SAnchorSizeIsTooLarge,
-          [Value, MinSize, MaxSize]);
-      end
-      else
-      begin
-        if ((Value mod 2) = 0) then
-        begin
-          raise EInvalidArgument.CreateFmt(SAnchorSizeIsNotOdd, [Value]);
-        end
-        else
-        begin
-          fAnchorSize := (Value div 2);
-          Render;
-          Refresh;
-        end;
-      end;
-    end;
+    if (Value < MinSize) then raise ERangeError.CreateFmt(SAnchorSizeIsTooSmall, [Value, MinSize, MaxSize]);
+    if (Value > MaxSize) then raise ERangeError.CreateFmt(SAnchorSizeIsTooLarge, [Value, MinSize, MaxSize]);
+    if ((Value mod 2) = 0) then raise EInvalidArgument.CreateFmt(SAnchorSizeIsNotOdd, [Value]);
+
+    fAnchorSize:= (Value div 2);
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
 function TBGRAImageManipulation.getEmpty: boolean;
 begin
-  Result := fImageBitmap.Empty or (fImageBitmap.Width = 0) or (fImageBitmap.Height = 0);
+  Result:= fImageBitmap.Empty or (fImageBitmap.Width = 0) or (fImageBitmap.Height = 0);
 end;
 
 function TBGRAImageManipulation.getResampledBitmap(ACropArea :TCropArea = Nil; ACopyProperties: Boolean=False): TBGRABitmap;
@@ -3219,10 +3277,8 @@ begin
   Result := fImageBitmap;
   if not (fImageBitmap.Empty) then
   begin
-      if (ACropArea = Nil)
-      then ACropArea := Self.SelectedCropArea;
-      if (ACropArea <> Nil)
-      then Result :=ACropArea.getResampledBitmap(ACopyProperties);
+    if (ACropArea = Nil) then ACropArea:= Self.SelectedCropArea;
+    if (ACropArea <> Nil) then Result:= ACropArea.getResampledBitmap(ACopyProperties);
   end;
 end;
 
@@ -3231,10 +3287,8 @@ begin
   Result := fImageBitmap;
   if not (fImageBitmap.Empty) then
   begin
-      if (ACropArea = Nil)
-      then ACropArea := Self.SelectedCropArea;
-      if (ACropArea <> Nil)
-      then Result :=ACropArea.getBitmap(ACopyProperties);
+    if (ACropArea = Nil) then ACropArea:= Self.SelectedCropArea;
+    if (ACropArea <> Nil) then Result :=ACropArea.getBitmap(ACopyProperties);
   end;
 end;
 
@@ -3244,18 +3298,10 @@ var
   i: Integer;
 
 begin
-  if (Value <> fImageBitmap) then
-  begin
     try
       if Value.Empty or (Value.Width = 0) or (Value.Height = 0)
       then CreateEmptyImage
-      else begin
-             // Clear actual image
-             fImageBitmap.Free;
-             fImageBitmap :=TBGRABitmap.Create(Value.Width, Value.Height);
-
-             fImageBitmap.Assign(Value, True); // Associate the new bitmap
-           end;
+      else fImageBitmap.Assign(Value, True); // Associate the new bitmap
 
       CreateResampledBitmap;
 
@@ -3270,12 +3316,10 @@ begin
           //CalcMaxSelection(curCropArea);
         end;
       end;
+
     finally
-      // Force Render Struct
-      Render;
-      inherited Invalidate;
+      if not(csLoading in ComponentState) then Render_Invalidate;
     end;
-  end;
 end;
 
 procedure TBGRAImageManipulation.rotateLeft(ACopyProperties: Boolean=False);
@@ -3307,10 +3351,9 @@ begin
         //CalcMaxSelection(curCropArea);
       end;
     end;
+
   finally
-    // Force Render Struct
-    Render;
-    inherited Invalidate;
+    Render_Invalidate;
     TempBitmap.Free;
   end;
 end;
@@ -3344,10 +3387,9 @@ begin
         //CalcMaxSelection(curCropArea);
       end;
     end;
+
   finally
-    // Force Render Struct
-    Render;
-    inherited Invalidate;
+    Render_Invalidate;
     TempBitmap.Free;
   end;
 end;
@@ -3373,33 +3415,28 @@ begin
 
      rCropAreas.add(newCropArea);
 
-     if (rSelectedCropArea = nil)
-     then rSelectedCropArea :=newCropArea;
+     if (rSelectedCropArea = nil) then rSelectedCropArea :=newCropArea;
 
      newCropArea.CalculateScaledAreaFromArea;
 
      Result :=newCropArea;
   except
-     if (newCropArea <> Nil)
-     then newCropArea.Free;
+     if (newCropArea <> Nil) then newCropArea.Free;
 
      Result :=Nil;
   end;
 
-  Render;
-  Invalidate;
+  Render_Invalidate;
 end;
 
 function TBGRAImageManipulation.addScaledCropArea(AArea: TRect; AUserData: Integer): TCropArea;
 begin
-     Result :=Self.addCropArea(RectF(0,0,0,0), rNewCropAreaDefault.rResolutionUnit, AUserData);
-     Result.ScaledArea :=AArea;
+  Result :=Self.addCropArea(RectF(0,0,0,0), rNewCropAreaDefault.rResolutionUnit, AUserData);
+  Result.ScaledArea :=AArea;
 
-     if (fMouseCaught)
-     then Result.CalculateAreaFromScaledArea;
+  if (fMouseCaught) then Result.CalculateAreaFromScaledArea;
 
-     Render;
-     Invalidate;
+  Render_Invalidate;
 end;
 
 procedure TBGRAImageManipulation.delCropArea(ACropArea: TCropArea);
@@ -3426,16 +3463,14 @@ begin
 
     rCropAreas.Delete(curIndex);
 
-    Render;
-    Invalidate;
+    Render_Invalidate;
   end;
 end;
 
 procedure TBGRAImageManipulation.clearCropAreas;
 begin
   rCropAreas.Clear;
-  Render;
-  Invalidate;
+  Render_Invalidate;
 end;
 
 procedure TBGRAImageManipulation.getAllResampledBitmaps(ACallBack: TgetAllBitmapsCallback; AUserData:Integer; ACopyProperties: Boolean=False);
@@ -3444,15 +3479,15 @@ var
    curBitmap :TBGRABitmap;
 
 begin
-     //Get Resampled Bitmap of each CropArea and pass it to CallBack
-     for i:=0 to rCropAreas.Count-1 do
-     try
-        curBitmap :=rCropAreas[i].getResampledBitmap(ACopyProperties);
-        ACallBack(curBitmap, rCropAreas[i], AUserData);
-      finally
-        if (curBitmap<>nil)
-        then curBitmap.Free;
-     end;
+  //Get Resampled Bitmap of each CropArea and pass it to CallBack
+  for i:=0 to rCropAreas.Count-1 do
+  try
+     curBitmap :=rCropAreas[i].getResampledBitmap(ACopyProperties);
+     ACallBack(curBitmap, rCropAreas[i], AUserData);
+
+  finally
+    if (curBitmap<>nil) then curBitmap.Free;
+  end;
 end;
 
 procedure TBGRAImageManipulation.getAllBitmaps(ACallBack: TgetAllBitmapsCallback; AUserData:Integer; ACopyProperties: Boolean=False);
@@ -3461,15 +3496,15 @@ var
    curBitmap :TBGRABitmap;
 
 begin
-     //Get Bitmap of each CropArea and pass it to CallBack
-     for i:=0 to rCropAreas.Count-1 do
-     try
-        curBitmap :=rCropAreas[i].getBitmap(ACopyProperties);
-        ACallBack(curBitmap, rCropAreas[i], AUserData);
-      finally
-        if (curBitmap<>nil)
-        then curBitmap.Free;
-     end;
+  //Get Bitmap of each CropArea and pass it to CallBack
+  for i:=0 to rCropAreas.Count-1 do
+  try
+     curBitmap :=rCropAreas[i].getBitmap(ACopyProperties);
+     ACallBack(curBitmap, rCropAreas[i], AUserData);
+
+  finally
+    if (curBitmap<>nil) then curBitmap.Free;
+  end;
 end;
 
 procedure TBGRAImageManipulation.SetEmptyImageSizeToCropAreas(ReduceLarger: Boolean);
@@ -3562,6 +3597,7 @@ begin
      if Assigned(rOnBitmapLoadBefore) then rOnBitmapLoadBefore(Self, AStream, AFormat, AHandler, AOptions);
 
      fImageBitmap.LoadFromStream(AStream, AHandler, AOptions);
+     setBitmap(fImageBitmap);
 
      if Assigned(rOnBitmapLoadAfter) then rOnBitmapLoadAfter(Self, AStream, AFormat, AHandler, AOptions);
 
@@ -3615,6 +3651,7 @@ begin
   if Assigned(rOnBitmapLoadBefore) then rOnBitmapLoadBefore(Self, AStream, AFormat, AHandler, AOptions);
 
   fImageBitmap.LoadFromStream(AStream, AHandler, AOptions);
+  setBitmap(fImageBitmap);
 
   if Assigned(rOnBitmapLoadAfter) then rOnBitmapLoadAfter(Self, AStream, AFormat, AHandler, AOptions);
 end;
@@ -3640,6 +3677,7 @@ begin
   try
     writer:= TUniversalDrawer.CreateBGRAImageWriter(fImageBitmap, AFilenameUTF8, format);
     SaveToFileUTF8(AFilenameUTF8, format, writer);
+
   finally
     writer.free;
   end;
@@ -3688,25 +3726,12 @@ const
 begin
   if (Value <> fBorderSize) then
   begin
-    if (Value < MinSize) then
-    begin
-      raise ERangeError.CreateFmt(SBorderSizeIsTooSmall,
-        [Value, MinSize, MaxSize]);
-    end
-    else
-    begin
-      if (Value > MaxSize) then
-      begin
-        raise ERangeError.CreateFmt(SBorderSizeIsTooLarge,
-          [Value, MinSize, MaxSize]);
-      end
-      else
-      begin
-        fBorderSize := Value;
+    if (Value < MinSize) then raise ERangeError.CreateFmt(SBorderSizeIsTooSmall, [Value, MinSize, MaxSize]);
+    if (Value > MaxSize) then raise ERangeError.CreateFmt(SBorderSizeIsTooLarge, [Value, MinSize, MaxSize]);
 
-        Resize;
-      end;
-    end;
+    fBorderSize := Value;
+
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
@@ -3738,13 +3763,10 @@ begin
     end;
   end;
 
-  if imgPresent
-  then Render;
-  Invalidate;
+  if not(csLoading in ComponentState) then Render_Invalidate;
 end;
 
-function TBGRAImageManipulation.getAspectRatioFromImage(
-  const Value: TBGRABitmap): string;
+function TBGRAImageManipulation.getAspectRatioFromImage(const Value: TBGRABitmap): string;
 var
   GCD: integer;
 begin
@@ -3812,10 +3834,7 @@ begin
       end;
     end;
 
-    if imgPresent
-    then Render;
-
-    Invalidate;
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
@@ -3828,21 +3847,13 @@ procedure TBGRAImageManipulation.setMinHeight(const Value: integer);
 begin
   if (Value <> fMinHeight) then
   begin
-    if (Value < fSizeLimits.minHeight) then
-    begin
-      fMinHeight := fSizeLimits.minHeight;
-    end
-    else
-    begin
-      if (Value > fSizeLimits.maxHeight) then
-      begin
-        fMinHeight := fSizeLimits.maxHeight;
-      end
-      else
-      begin
-        fMinHeight := Value;
-      end;
-    end;
+    if (Value < fSizeLimits.minHeight)
+    then fMinHeight := fSizeLimits.minHeight
+    else begin
+           if (Value > fSizeLimits.maxHeight)
+           then fMinHeight := fSizeLimits.maxHeight
+           else fMinHeight := Value;
+         end;
 
     if (fKeepAspectRatio) then
     begin
@@ -3850,8 +3861,7 @@ begin
       fMinWidth := Trunc(fMinHeight * (fRatio.Horizontal / fRatio.Vertical));
     end;
 
-    Render;
-    Invalidate;
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
@@ -3859,21 +3869,13 @@ procedure TBGRAImageManipulation.setMinWidth(const Value: integer);
 begin
   if (Value <> fMinWidth) then
   begin
-    if (Value < fSizeLimits.minWidth) then
-    begin
-      fMinWidth := fSizeLimits.minWidth;
-    end
-    else
-    begin
-      if (Value > fSizeLimits.maxWidth) then
-      begin
-        fMinWidth := fSizeLimits.maxWidth;
-      end
-      else
-      begin
-        fMinWidth := Value;
-      end;
-    end;
+    if (Value < fSizeLimits.minWidth)
+    then fMinWidth := fSizeLimits.minWidth
+    else begin
+           if (Value > fSizeLimits.maxWidth)
+           then fMinWidth := fSizeLimits.maxWidth
+           else fMinWidth := Value;
+         end;
 
     if (fKeepAspectRatio) then
     begin
@@ -3881,8 +3883,7 @@ begin
       fMinHeight := Trunc(fMinWidth * (fRatio.Vertical / fRatio.Horizontal));
     end;
 
-    Render;
-    Invalidate;
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
@@ -3891,8 +3892,8 @@ begin
   if (rOpacity <> AValue) then
   begin
     rOpacity:= AValue;
-    Render;
-    Invalidate;
+
+    if not(csLoading in ComponentState) then Render_Invalidate;
   end;
 end;
 
@@ -3905,8 +3906,7 @@ begin
   oldSelected :=rSelectedCropArea;
   rSelectedCropArea:=AValue;
 
-  Render;
-  Invalidate;
+  Render_Invalidate;
 
   if assigned(rOnSelectedCropAreaChanged)
   then rOnSelectedCropAreaChanged(Self, oldSelected);
@@ -3917,7 +3917,6 @@ end;
  { =====[ Event Control ]====================================================== }
  { ============================================================================ }
 
- //Controllare tutte e 3
 procedure TBGRAImageManipulation.MouseDown(Button: TMouseButton;
   Shift: TShiftState; X, Y: integer);
 var
@@ -4124,6 +4123,10 @@ var
   end;
 
 begin
+  {$ifopt D+}
+   DebugLn('MouseMove');
+  {$endif}
+
   // Call the inherited MouseMove() procedure
   inherited MouseMove(Shift, X, Y);
 
@@ -4164,7 +4167,7 @@ begin
 
            // Invalidate the control for repainting
            Render;
-           Refresh;
+           Invalidate;//Refresh;
          end;
        end
   else begin
@@ -4183,6 +4186,10 @@ begin
            Cursor :=ACursor;
          end;
        end;
+
+  {$ifopt D+}
+   DebugLn('MouseMove done');
+  {$endif}
 end;
 
 procedure TBGRAImageManipulation.MouseUp(Button: TMouseButton;
@@ -4255,7 +4262,7 @@ begin
 
       // Invalidate the control for repainting
       Render;
-      Refresh;
+      Invalidate;//Refresh;
     end;
   end;
  end;

+ 0 - 0
test/test_bgraimagemanipulation/ProjectBGRAImageManipulationDemo.ico → test/test_bgraimagemanipulation/BGRAImageManipulationDemo.ico


+ 6 - 11
test/test_bgraimagemanipulation/ProjectBGRAImageManipulationDemo.lpi → test/test_bgraimagemanipulation/BGRAImageManipulationDemo.lpi

@@ -7,6 +7,7 @@
         <CompatibilityMode Value="True"/>
       </Flags>
       <SessionStorage Value="InProjectDir"/>
+      <Title Value="BGRAImageManipulationDemo"/>
       <Scaled Value="True"/>
       <ResourceType Value="res"/>
       <UseXPManifest Value="True"/>
@@ -28,7 +29,7 @@
         <CompilerOptions>
           <Version Value="11"/>
           <Target>
-            <Filename Value="ProjectBGRAImageManipulationDemo"/>
+            <Filename Value="bin/$(TargetCPU)-$(TargetOS)/BGRAImageManipulationDemo"/>
           </Target>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
@@ -60,16 +61,9 @@
       <Version Value="2"/>
     </PublishOptions>
     <RunParams>
-      <local>
-        <LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
-      </local>
       <FormatVersion Value="2"/>
       <Modes Count="1">
-        <Mode0 Name="default">
-          <local>
-            <LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
-          </local>
-        </Mode0>
+        <Mode0 Name="default"/>
       </Modes>
     </RunParams>
     <RequiredPackages Count="2">
@@ -82,7 +76,7 @@
     </RequiredPackages>
     <Units Count="2">
       <Unit0>
-        <Filename Value="ProjectBGRAImageManipulationDemo.lpr"/>
+        <Filename Value="BGRAImageManipulationDemo.lpr"/>
         <IsPartOfProject Value="True"/>
       </Unit0>
       <Unit1>
@@ -98,7 +92,7 @@
   <CompilerOptions>
     <Version Value="11"/>
     <Target>
-      <Filename Value="ProjectBGRAImageManipulationDemo"/>
+      <Filename Value="bin/$(TargetCPU)-$(TargetOS)/BGRAImageManipulationDemo-dbg"/>
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
@@ -117,6 +111,7 @@
         <StackChecks Value="True"/>
       </Checks>
       <Optimizations>
+        <OptimizationLevel Value="0"/>
         <VariablesInRegisters Value="True"/>
       </Optimizations>
     </CodeGeneration>

+ 1 - 2
test/test_bgraimagemanipulation/ProjectBGRAImageManipulationDemo.lpr → test/test_bgraimagemanipulation/BGRAImageManipulationDemo.lpr

@@ -1,4 +1,4 @@
-program ProjectBGRAImageManipulationDemo;
+program BGRAImageManipulationDemo;
 
 {$mode objfpc}{$H+}
 
@@ -13,7 +13,6 @@ uses
 
 begin
   Application.Scaled:=True;
-  Application.Title:='';
   Application.Initialize;
   Application.CreateForm(TFormBGRAImageManipulationDemo, FormBGRAImageManipulationDemo);
   Application.Run;

+ 271 - 270
test/test_bgraimagemanipulation/unitbgraimagemanipulationdemo.lfm

@@ -1,19 +1,20 @@
 object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
   Left = 262
-  Height = 543
+  Height = 679
   Top = 84
-  Width = 926
+  Width = 1158
   Caption = 'Demonstration of TBGRAImageManipulation'
-  ClientHeight = 543
-  ClientWidth = 926
+  ClientHeight = 679
+  ClientWidth = 1158
+  DesignTimePPI = 120
   ShowHint = True
   OnCloseQuery = FormCloseQuery
   OnCreate = FormCreate
   object Background: TBCPanel
-    Left = 678
-    Height = 543
+    Left = 848
+    Height = 679
     Top = 0
-    Width = 248
+    Width = 310
     Align = alRight
     Background.Color = clSilver
     Background.Gradient1.StartColor = clWhite
@@ -48,19 +49,19 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     Rounding.RoundY = 1
     TabOrder = 0
     object RateCompression: TTrackBar
-      Left = 40
-      Height = 24
-      Top = 336
-      Width = 180
+      Left = 50
+      Height = 47
+      Top = 420
+      Width = 225
       Max = 100
       Position = 80
       TabOrder = 0
     end
     object KeepAspectRatio: TCheckBox
-      Left = 25
-      Height = 19
-      Top = 176
-      Width = 115
+      Left = 31
+      Height = 25
+      Top = 220
+      Width = 168
       Caption = 'Keep aspect ratio'
       Checked = True
       Color = clWhite
@@ -73,10 +74,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       OnClick = KeepAspectRatioClick
     end
     object lbOptions: TLabel
-      Left = 10
-      Height = 15
-      Top = 72
-      Width = 87
+      Left = 12
+      Height = 23
+      Top = 80
+      Width = 131
       Caption = 'Image Options :'
       Color = clBlack
       Font.Color = clWhite
@@ -86,10 +87,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       Transparent = False
     end
     object lbCompression: TLabel
-      Left = 25
-      Height = 15
-      Top = 320
-      Width = 77
+      Left = 31
+      Height = 23
+      Top = 400
+      Width = 116
       Caption = 'Compression :'
       Font.Color = clWhite
       Font.Style = [fsBold]
@@ -97,18 +98,18 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       ParentFont = False
     end
     object edAspectRatio: TEdit
-      Left = 123
-      Height = 23
-      Top = 204
-      Width = 44
+      Left = 154
+      Height = 35
+      Top = 255
+      Width = 55
       TabOrder = 2
       Text = '3:4'
     end
     object lbAspectRatio: TLabel
-      Left = 25
-      Height = 15
-      Top = 208
-      Width = 76
+      Left = 31
+      Height = 23
+      Top = 260
+      Width = 113
       Caption = 'Aspect Ratio :'
       Color = clBlack
       Font.Color = clWhite
@@ -118,10 +119,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       Transparent = False
     end
     object btnOpenPicture: TBCButton
-      Left = 10
-      Height = 40
-      Top = 8
-      Width = 134
+      Left = 12
+      Height = 50
+      Top = 10
+      Width = 168
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -285,10 +286,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnSavePicture: TBCButton
-      Left = 15
-      Height = 40
-      Top = 440
-      Width = 200
+      Left = 19
+      Height = 50
+      Top = 550
+      Width = 250
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -452,11 +453,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnSetAspectRatio: TBCButton
-      Left = 175
-      Height = 28
+      Left = 219
+      Height = 35
       Hint = 'Apply new aspect ratio'
-      Top = 204
-      Width = 40
+      Top = 255
+      Width = 50
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -619,11 +620,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnGetAspectRatioFromImage: TBCButton
-      Left = 25
-      Height = 30
+      Left = 31
+      Height = 38
       Hint = 'Get aspect ratio from image'
-      Top = 240
-      Width = 30
+      Top = 300
+      Width = 38
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -786,11 +787,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnRotateLeft: TBCButton
-      Left = 69
-      Height = 30
+      Left = 86
+      Height = 38
       Hint = 'Rotate Left'
-      Top = 240
-      Width = 30
+      Top = 300
+      Width = 38
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -953,11 +954,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnRotateRight: TBCButton
-      Left = 105
-      Height = 30
+      Left = 131
+      Height = 38
       Hint = 'Rotate Right'
-      Top = 240
-      Width = 30
+      Top = 300
+      Width = 38
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -1120,10 +1121,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnShape: TBCButton
-      Left = 32
-      Height = 24
-      Top = 336
-      Width = 200
+      Left = 40
+      Height = 30
+      Top = 420
+      Width = 250
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -1210,10 +1211,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object btnSavePictureAll: TBCButton
-      Left = 15
-      Height = 40
-      Top = 392
-      Width = 200
+      Left = 19
+      Height = 50
+      Top = 490
+      Width = 250
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -1377,10 +1378,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object chkFullSize: TCheckBox
-      Left = 15
-      Height = 19
-      Top = 480
-      Width = 83
+      Left = 19
+      Height = 25
+      Top = 600
+      Width = 117
       Caption = 'Original Size'
       Checked = True
       State = cbChecked
@@ -1388,16 +1389,16 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     end
     object lbResolution: TLabel
       Left = 0
-      Height = 15
-      Top = 95
-      Width = 65
+      Height = 23
+      Top = 100
+      Width = 93
       Caption = 'Resolution : '
     end
     object BCLabel7: TBCLabel
-      Left = 11
-      Height = 15
-      Top = 296
-      Width = 44
+      Left = 14
+      Height = 23
+      Top = 370
+      Width = 63
       Background.Gradient1.StartColor = clWhite
       Background.Gradient1.EndColor = clBlack
       Background.Gradient1.GradientType = gtLinear
@@ -1427,29 +1428,29 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       Rounding.RoundY = 1
     end
     object cbSaveFormat: TComboBox
-      Left = 60
-      Height = 23
-      Top = 288
-      Width = 180
-      ItemHeight = 15
+      Left = 75
+      Height = 39
+      Top = 360
+      Width = 225
+      ItemHeight = 0
       Style = csDropDownList
       TabOrder = 4
     end
     object SpeedButton1: TSpeedButton
-      Left = 208
-      Height = 25
-      Top = 56
-      Width = 38
+      Left = 260
+      Height = 33
+      Top = 70
+      Width = 53
       AutoSize = True
       Caption = ':Tests'
       OnClick = SpeedButton1Click
     end
     object btnEmptyImage: TBCButton
-      Left = 152
-      Height = 40
+      Left = 190
+      Height = 50
       Hint = 'Get aspect ratio from image'
-      Top = 8
-      Width = 88
+      Top = 10
+      Width = 110
       StateClicked.Background.Gradient1.StartColor = 8404992
       StateClicked.Background.Gradient1.EndColor = 4194304
       StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -1602,10 +1603,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       MemoryUsage = bmuHigh
     end
     object chkCopyProperties: TCheckBox
-      Left = 105
-      Height = 19
-      Top = 480
-      Width = 102
+      Left = 146
+      Height = 25
+      Top = 600
+      Width = 144
       Caption = 'Copy Properties'
       Checked = True
       State = cbChecked
@@ -1613,22 +1614,22 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     end
     object lbFormat: TLabel
       Left = 0
-      Height = 15
-      Top = 160
-      Width = 47
+      Height = 23
+      Top = 192
+      Width = 67
       Caption = 'Format : '
     end
   end
   object BGRAImageManipulation: TBGRAImageManipulation
-    Left = 198
-    Height = 543
+    Left = 248
+    Height = 679
     Top = 0
-    Width = 480
+    Width = 600
     Align = alClient
     AnchorSize = 9
     AspectRatio = '3:4'
-    MinHeight = 40
-    MinWidth = 30
+    MinHeight = 0
+    MinWidth = 0
     EmptyImage.ResolutionWidth = 21
     EmptyImage.ResolutionHeight = 29.7000007629395
     EmptyImage.ShowBorder = True
@@ -1643,9 +1644,9 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
   end
   object BCPanelCropAreas: TBCPanel
     Left = 0
-    Height = 543
+    Height = 679
     Top = 0
-    Width = 198
+    Width = 248
     Align = alLeft
     Background.Color = clSilver
     Background.ColorOpacity = 35
@@ -1682,20 +1683,20 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     TabOrder = 1
     object cbBoxList: TComboBox
       Left = 0
-      Height = 23
-      Top = 20
-      Width = 125
-      ItemHeight = 15
+      Height = 39
+      Top = 25
+      Width = 156
+      ItemHeight = 0
       Style = csDropDownList
       TabOrder = 0
       OnChange = cbBoxListChange
     end
     object btBox_Add: TBGRASpeedButton
-      Left = 126
-      Height = 22
+      Left = 158
+      Height = 28
       Hint = 'Add a Box'
-      Top = 21
-      Width = 23
+      Top = 26
+      Width = 29
       Caption = '+'
       Flat = True
       ShowHint = True
@@ -1703,11 +1704,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       OnClick = btBox_AddClick
     end
     object btBox_Del: TBGRASpeedButton
-      Left = 149
-      Height = 22
+      Left = 186
+      Height = 28
       Hint = 'Remove this Box'
-      Top = 21
-      Width = 23
+      Top = 26
+      Width = 29
       Caption = '-'
       Flat = True
       ShowHint = True
@@ -1716,9 +1717,9 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     end
     object lbOptions1: TLabel
       Left = 0
-      Height = 15
+      Height = 23
       Top = 0
-      Width = 66
+      Width = 99
       Caption = 'Crop Areas :'
       Color = clBlack
       Font.Color = clWhite
@@ -1729,9 +1730,9 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     end
     object BCPanelCropAreaLoad: TBCPanel
       Left = 1
-      Height = 106
-      Top = 436
-      Width = 196
+      Height = 132
+      Top = 546
+      Width = 246
       Align = alBottom
       Background.Color = clBtnFace
       Background.Gradient1.StartColor = clWhite
@@ -1766,10 +1767,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       Rounding.RoundY = 1
       TabOrder = 1
       object btnLoadCropList: TBCButton
-        Left = 8
-        Height = 40
-        Top = 8
-        Width = 150
+        Left = 10
+        Height = 50
+        Top = 10
+        Width = 188
         StateClicked.Background.Gradient1.StartColor = 8404992
         StateClicked.Background.Gradient1.EndColor = 4194304
         StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -1989,10 +1990,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         MemoryUsage = bmuHigh
       end
       object btnSaveCropList: TBCButton
-        Left = 7
-        Height = 40
-        Top = 56
-        Width = 150
+        Left = 9
+        Height = 50
+        Top = 70
+        Width = 188
         StateClicked.Background.Gradient1.StartColor = 8404992
         StateClicked.Background.Gradient1.EndColor = 4194304
         StateClicked.Background.Gradient1.GradientType = gtRadial
@@ -2214,9 +2215,9 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
     end
     object BCPanelCropArea: TBCPanel
       Left = 0
-      Height = 384
-      Top = 48
-      Width = 186
+      Height = 480
+      Top = 60
+      Width = 232
       Background.Color = clBtnFace
       Background.Gradient1.StartColor = clWhite
       Background.Gradient1.EndColor = clBlack
@@ -2251,10 +2252,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
       Rounding.RoundY = 1
       TabOrder = 2
       object BCLabel1: TBCLabel
-        Left = 20
-        Height = 15
-        Top = 67
-        Width = 26
+        Left = 25
+        Height = 23
+        Top = 84
+        Width = 36
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2284,10 +2285,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object BCLabel2: TBCLabel
-        Left = 20
-        Height = 15
-        Top = 95
-        Width = 25
+        Left = 25
+        Height = 23
+        Top = 119
+        Width = 36
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2317,10 +2318,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object BCLabel3: TBCLabel
-        Left = 8
-        Height = 15
-        Top = 123
-        Width = 38
+        Left = 10
+        Height = 23
+        Top = 154
+        Width = 53
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2350,10 +2351,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object BCLabel4: TBCLabel
-        Left = 4
-        Height = 15
-        Top = 151
-        Width = 42
+        Left = 5
+        Height = 23
+        Top = 189
+        Width = 59
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2383,12 +2384,12 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object edUnit_Type: TComboBox
-        Left = 56
-        Height = 23
-        Top = 36
-        Width = 103
+        Left = 70
+        Height = 29
+        Top = 45
+        Width = 129
         AutoSize = False
-        ItemHeight = 15
+        ItemHeight = 0
         ItemIndex = 0
         Items.Strings = (
           'pixels'
@@ -2401,10 +2402,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = edUnit_TypeChange
       end
       object BCLabel5: TBCLabel
-        Left = 18
-        Height = 15
-        Top = 39
-        Width = 28
+        Left = 22
+        Height = 23
+        Top = 49
+        Width = 39
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2434,10 +2435,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object BCLabel6: TBCLabel
-        Left = 8
-        Height = 15
-        Top = 12
-        Width = 38
+        Left = 10
+        Height = 23
+        Top = 15
+        Width = 53
         Background.Gradient1.StartColor = clWhite
         Background.Gradient1.EndColor = clBlack
         Background.Gradient1.GradientType = gtLinear
@@ -2467,27 +2468,27 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         Rounding.RoundY = 1
       end
       object edName: TEdit
-        Left = 56
-        Height = 23
-        Top = 8
-        Width = 103
+        Left = 70
+        Height = 29
+        Top = 10
+        Width = 129
         AutoSize = False
         TabOrder = 1
         OnEditingDone = edNameChange
       end
       object edAspectPersonal: TEdit
-        Left = 45
-        Height = 23
-        Top = 330
-        Width = 87
+        Left = 56
+        Height = 29
+        Top = 412
+        Width = 109
         AutoSize = False
         TabOrder = 2
       end
       object rgAspect: TRadioGroup
-        Left = 20
-        Height = 68
-        Top = 256
-        Width = 137
+        Left = 25
+        Height = 85
+        Top = 320
+        Width = 171
         AutoFill = True
         Caption = 'Aspect Ratio'
         ChildSizing.LeftRightSpacing = 6
@@ -2497,8 +2498,8 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         ChildSizing.ShrinkVertical = crsScaleChilds
         ChildSizing.Layout = cclLeftToRightThenTopToBottom
         ChildSizing.ControlsPerLine = 1
-        ClientHeight = 48
-        ClientWidth = 133
+        ClientHeight = 61
+        ClientWidth = 169
         Items.Strings = (
           'Parent'
           'Free'
@@ -2508,10 +2509,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnSelectionChanged = rgAspectSelectionChanged
       end
       object btApplyAspectRatio: TSpeedButton
-        Left = 133
-        Height = 22
-        Top = 331
-        Width = 23
+        Left = 166
+        Height = 28
+        Top = 414
+        Width = 29
         Glyph.Data = {
           C6070000424DC607000000000000360000002800000016000000160000000100
           2000000000009007000064000000640000000000000000000000000000000000
@@ -2580,10 +2581,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btApplyAspectRatioClick
       end
       object edLeft: TFloatSpinEdit
-        Left = 56
-        Height = 23
-        Top = 64
-        Width = 103
+        Left = 70
+        Height = 30
+        Top = 80
+        Width = 129
         DecimalPlaces = 3
         Font.Color = clWindowText
         Font.Name = 'Arial'
@@ -2594,10 +2595,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = edLeftChange
       end
       object edTop: TFloatSpinEdit
-        Left = 56
-        Height = 23
-        Top = 92
-        Width = 103
+        Left = 70
+        Height = 30
+        Top = 115
+        Width = 129
         DecimalPlaces = 3
         Font.Color = clWindowText
         Font.Name = 'Arial'
@@ -2608,10 +2609,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = edTopChange
       end
       object edWidth: TFloatSpinEdit
-        Left = 56
-        Height = 23
-        Top = 120
-        Width = 103
+        Left = 70
+        Height = 30
+        Top = 150
+        Width = 129
         DecimalPlaces = 3
         Font.Color = clWindowText
         Font.Name = 'Arial'
@@ -2622,10 +2623,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = edWidthChange
       end
       object edHeight: TFloatSpinEdit
-        Left = 56
-        Height = 23
-        Top = 148
-        Width = 103
+        Left = 70
+        Height = 30
+        Top = 185
+        Width = 129
         DecimalPlaces = 3
         Font.Color = clWindowText
         Font.Name = 'Arial'
@@ -2636,18 +2637,18 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = edHeightChange
       end
       object Label1: TLabel
-        Left = 7
-        Height = 15
-        Top = 224
-        Width = 46
+        Left = 9
+        Height = 23
+        Top = 280
+        Width = 65
         Caption = 'Z Order :'
       end
       object btZFront: TSpeedButton
-        Left = 57
-        Height = 22
+        Left = 71
+        Height = 28
         Hint = 'To Front'
-        Top = 224
-        Width = 23
+        Top = 280
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2687,11 +2688,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btZFrontClick
       end
       object btZBack: TSpeedButton
-        Left = 81
-        Height = 22
+        Left = 101
+        Height = 28
         Hint = 'To Back'
-        Top = 224
-        Width = 23
+        Top = 280
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2731,11 +2732,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btZBackClick
       end
       object btZDown: TSpeedButton
-        Left = 134
-        Height = 22
+        Left = 168
+        Height = 28
         Hint = 'Down'
-        Top = 224
-        Width = 23
+        Top = 280
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2775,11 +2776,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btZDownClick
       end
       object btZUp: TSpeedButton
-        Left = 110
-        Height = 22
+        Left = 138
+        Height = 28
         Hint = 'Up'
-        Top = 224
-        Width = 23
+        Top = 280
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2819,18 +2820,18 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btZUpClick
       end
       object Label2: TLabel
-        Left = 14
-        Height = 15
-        Top = 176
-        Width = 40
+        Left = 18
+        Height = 23
+        Top = 220
+        Width = 58
         Caption = 'Rotate :'
       end
       object btCRotateLeft: TSpeedButton
-        Left = 58
-        Height = 22
+        Left = 72
+        Height = 28
         Hint = 'Rotate Left'
-        Top = 176
-        Width = 23
+        Top = 220
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000000000000000
@@ -2870,11 +2871,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCRotateLeftClick
       end
       object btCRotateRight: TSpeedButton
-        Left = 82
-        Height = 22
+        Left = 102
+        Height = 28
         Hint = 'Rotate Right'
-        Top = 176
-        Width = 23
+        Top = 220
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2914,18 +2915,18 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCRotateRightClick
       end
       object Label3: TLabel
-        Left = 28
-        Height = 15
-        Top = 200
-        Width = 25
+        Left = 35
+        Height = 23
+        Top = 250
+        Width = 34
         Caption = 'Flip :'
       end
       object btCFlipVUp: TSpeedButton
-        Left = 58
-        Height = 22
+        Left = 72
+        Height = 28
         Hint = 'Flip Vertical Up'
-        Top = 200
-        Width = 23
+        Top = 250
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -2965,11 +2966,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCFlipVUpClick
       end
       object btCFlipVDown: TSpeedButton
-        Left = 82
-        Height = 22
+        Left = 102
+        Height = 28
         Hint = 'Flip Vertical Down'
-        Top = 200
-        Width = 23
+        Top = 250
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -3009,11 +3010,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCFlipVDownClick
       end
       object btCFlipHLeft: TSpeedButton
-        Left = 111
-        Height = 22
+        Left = 139
+        Height = 28
         Hint = 'Flip Horizzontal Left'
-        Top = 200
-        Width = 23
+        Top = 250
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -3053,11 +3054,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCFlipHLeftClick
       end
       object btCFlipHRight: TSpeedButton
-        Left = 134
-        Height = 22
+        Left = 168
+        Height = 28
         Hint = 'Flip Horizzontal Right'
-        Top = 200
-        Width = 23
+        Top = 250
+        Width = 29
         Glyph.Data = {
           36040000424D3604000000000000360000002800000010000000100000000100
           2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
@@ -3097,11 +3098,11 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnClick = btCFlipHRightClick
       end
       object btCropDuplicateOp: TSpeedButton
-        Left = 161
-        Height = 22
+        Left = 201
+        Height = 28
         Hint = 'Duplicate when Rotate/Flip'
-        Top = 192
-        Width = 23
+        Top = 240
+        Width = 29
         AllowAllUp = True
         Flat = True
         Glyph.Data = {
@@ -3143,10 +3144,10 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         GroupIndex = 1
       end
       object cbIconIndex: TCheckBox
-        Left = 48
-        Height = 19
-        Top = 359
-        Width = 47
+        Left = 60
+        Height = 25
+        Top = 449
+        Width = 66
         Caption = 'Index'
         Checked = True
         State = cbChecked
@@ -3154,19 +3155,19 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
         OnChange = cbIconIndexChange
       end
       object Label4: TLabel
-        Left = 7
-        Height = 15
-        Top = 359
-        Width = 34
+        Left = 9
+        Height = 23
+        Top = 449
+        Width = 49
         Caption = 'Icons :'
       end
     end
     object btCropDuplicate: TSpeedButton
-      Left = 172
-      Height = 22
+      Left = 215
+      Height = 28
       Hint = 'Duplicate this Area'
-      Top = 20
-      Width = 23
+      Top = 25
+      Width = 29
       Flat = True
       Glyph.Data = {
         36040000424D3604000000000000360000002800000010000000100000000100
@@ -3209,31 +3210,31 @@ object FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo
   end
   object OpenPictureDialog: TOpenPictureDialog
     Title = 'Open an existing image'
-    Left = 400
-    Top = 16
+    Left = 500
+    Top = 20
   end
   object SavePictureDialog: TSavePictureDialog
     Title = 'Save image as'
     DefaultExt = '.jpg'
-    Left = 312
-    Top = 16
+    Left = 390
+    Top = 20
   end
   object SelectDirectoryDialog1: TSelectDirectoryDialog
-    Left = 312
-    Top = 74
+    Left = 390
+    Top = 93
   end
   object SaveCropList: TSaveDialog
     DefaultExt = '.clf'
     Filter = 'Crop List File (*.clf)|*.clf|All Files (*.*)|*.*'
     FilterIndex = 0
-    Left = 191
-    Top = 368
+    Left = 239
+    Top = 460
   end
   object OpenCropList: TOpenDialog
     DefaultExt = '.clf'
     Filter = 'Crop List File (*.clf)|*.clf|All Files (*.*)|*.*'
     FilterIndex = 0
-    Left = 192
-    Top = 418
+    Left = 240
+    Top = 523
   end
 end

+ 32 - 5
test/test_bgraimagemanipulation/unitbgraimagemanipulationdemo.pas

@@ -205,7 +205,11 @@ implementation
 
 {$R *.lfm}
 
-uses UniversalDrawer, BGRAReadJpeg, BGRAWriteJpeg;
+uses
+  {$ifopt D+}
+   LazLogger,
+  {$endif}
+  UniversalDrawer, BGRAReadJpeg, BGRAWriteJpeg;
 
 const
   ResUnitStr :array[TResolutionUnit] of String = ('ruNone', 'ruPixelsPerInch', 'ruPixelsPerCentimeter');
@@ -850,21 +854,32 @@ var
   curIndex :Integer;
 
 begin
-   curIndex :=BGRAImageManipulation.CropAreas.IndexOf(CropArea);
+  {$ifopt D+}
+   DebugLn('AddedCrop');
+  {$endif}
+
+  curIndex :=BGRAImageManipulation.CropAreas.IndexOf(CropArea);
 
-   if (CropArea.Name='')
-   then CropArea.Name:='Name '+IntToStr(curIndex);
+   if (CropArea.Name='') then CropArea.Name:='Name '+IntToStr(curIndex);
 
    cbBoxList.AddItem(CropArea.Name, CropArea);
    cbBoxList.ItemIndex:=cbBoxList.Items.IndexOfObject(CropArea);
    //CropArea.AreaUnit:=BGRAImageManipulation.Bitmap.ResolutionUnit;
    FillBoxUI(CropArea);
+
+   {$ifopt D+}
+    DebugLn('AddedCrop done');
+   {$endif}
 end;
 
 procedure TFormBGRAImageManipulationDemo.DeletedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
 var
    delIndex :Integer;
 begin
+  {$ifopt D+}
+   DebugLn('DeletedCrop');
+  {$endif}
+
   try
     if not(closing) then
     begin
@@ -876,11 +891,19 @@ begin
   except
   end;
   //MessageDlg('Deleting Crop Area', 'Deleting '+CropArea.Name, mtInformation, [mbOk], 0);
+
+  {$ifopt D+}
+   DebugLn('DeletedCrop done');
+  {$endif}
 end;
 
 procedure TFormBGRAImageManipulationDemo.ChangedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
 begin
-  if (cbBoxList.Items.Objects[cbBoxList.ItemIndex] = CropArea) then
+  {$ifopt D+}
+   DebugLn('ChangedCrop');
+  {$endif}
+
+  if (cbBoxList.ItemIndex > -1) and (cbBoxList.Items.Objects[cbBoxList.ItemIndex] = CropArea) then
   begin
     FillBoxUI(CropArea);
 
@@ -888,6 +911,10 @@ begin
     if (CropArea.Name<>cbBoxList.Items.Strings[cbBoxList.ItemIndex])
     then cbBoxList.Items.Strings[cbBoxList.ItemIndex] :=CropArea.Name;
   end;
+
+  {$ifopt D+}
+   DebugLn('ChangedCrop done');
+  {$endif}
 end;
 
 procedure TFormBGRAImageManipulationDemo.SelectedChangedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);