From 136d9963744d669e9434bc198acc0b475af51222 Mon Sep 17 00:00:00 2001 From: ondrej Date: Thu, 26 Apr 2018 07:42:31 +0000 Subject: [PATCH] LCL: imglist: fix source rect handling, add slice helper functions git-svn-id: trunk@57716 - --- lcl/imglist.pp | 3 ++ lcl/include/imglist.inc | 66 ++++++++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/lcl/imglist.pp b/lcl/imglist.pp index 2120034a80..8b969b25c6 100644 --- a/lcl/imglist.pp +++ b/lcl/imglist.pp @@ -336,6 +336,7 @@ type function AddMultipleResolutions(Images: array of TCustomBitmap): Integer; // always pass sorted array from smallest to biggest function AddSliced(Image: TCustomBitmap; AHorizontalCount, AVerticalCount: Integer): Integer; function AddSlice(Image: TCustomBitmap; AImageRect: TRect): Integer; + function AddSliceCentered(Image: TCustomBitmap): Integer; function AddIcon(Image: TCustomIcon): Integer; procedure AddImages(AValue: TCustomImageList); function AddMasked(Image: TBitmap; MaskColor: TColor): Integer; @@ -376,6 +377,8 @@ type procedure Overlay(AIndex: Integer; Overlay: TOverlay); property HasOverlays: boolean read fHasOverlays; procedure Replace(AIndex: Integer; AImage, AMask: TCustomBitmap; const AllResolutions: Boolean = True); + procedure ReplaceSlice(AIndex: Integer; Image: TCustomBitmap; AImageRect: TRect; const AllResolutions: Boolean = True); + procedure ReplaceSliceCentered(AIndex, AImageWidth: Integer; Image: TCustomBitmap; const AllResolutions: Boolean = True); procedure ReplaceIcon(AIndex: Integer; AIcon: TCustomIcon); procedure ReplaceMasked(Index: Integer; NewImage: TCustomBitmap; MaskColor: TColor; const AllResolutions: Boolean = True); procedure RegisterChanges(Value: TChangeLink); diff --git a/lcl/include/imglist.inc b/lcl/include/imglist.inc index 3dd7f9d89f..be5783a27c 100644 --- a/lcl/include/imglist.inc +++ b/lcl/include/imglist.inc @@ -780,7 +780,7 @@ var if not Res then raise EInvalidGraphicOperation.Create('TCustomImageList.CreateImagesFromRawImage Create bitmaps'); - TCustomImageList.ScaleImage(ImgHandle, MaskHandle, Rect(0, 0, Width-1, Height-1), Width, Height, ImgData); + TCustomImageList.ScaleImage(ImgHandle, MaskHandle, Rect(0, 0, Width, Height), Width, Height, ImgData); InternalInsert(Count, @ImgData[0]); DeleteObject(ImgHandle); DeleteObject(MaskHandle); @@ -1340,6 +1340,15 @@ begin end; end; +function TCustomImageList.AddSliceCentered(Image: TCustomBitmap): Integer; +var + ImageRect: TRect; +begin + ImageRect := Rect(0, 0, Width, Height); + OffsetRect(ImageRect, (Image.Width-Width) div 2, (Image.Height-Height) div 2); + Result := AddSlice(Image, ImageRect); +end; + function TCustomImageList.AddSliced(Image: TCustomBitmap; AHorizontalCount, AVerticalCount: Integer): Integer; var @@ -1360,7 +1369,7 @@ begin for L := 0 to AVerticalCount-1 do for I := 0 to AHorizontalCount-1 do begin - Rc := Rect(I*W, L*H, (I+1)*W-1, (L+1)*H-1); + Rc := Rect(I*W, L*H, (I+1)*W, (L+1)*H); for R in Resolutions do begin ScaleImage(Image, nil, Rc, R.Width, R.Height, ScBmp); @@ -1972,7 +1981,7 @@ begin else msk := 0; ScaleImage(SortedIcon.BitmapHandle, msk, - Rect(0, 0, SortedIcon.Width-1, SortedIcon.Height-1), R.Width, R.Height, ScBmp); + Rect(0, 0, SortedIcon.Width, SortedIcon.Height), R.Width, R.Height, ScBmp); R.InternalInsert(AIndex, @ScBmp[0]); end; finally @@ -2009,7 +2018,7 @@ begin CreateDefaultResolution; for R in Resolutions do begin - ScaleImage(MaskedImage.BitmapHandle, MaskedImage.MaskHandle, Rect(0, 0, MaskedImage.Width-1, MaskedImage.Height-1), R.Width, R.Height, ScBmp); + ScaleImage(MaskedImage.BitmapHandle, MaskedImage.MaskHandle, Rect(0, 0, MaskedImage.Width, MaskedImage.Height), R.Width, R.Height, ScBmp); R.InternalInsert(Index, @ScBmp[0]); end; finally @@ -2021,7 +2030,7 @@ class procedure TCustomImageList.ScaleImage(const ABitmap, AMask: TCustomBitmap; TargetWidth, TargetHeight: Integer; var AData: TRGBAQuadArray); begin - ScaleImage(ABitmap, AMask, Rect(0, 0, ABitmap.Width-1, ABitmap.Height-1), TargetWidth, TargetHeight, AData); + ScaleImage(ABitmap, AMask, Rect(0, 0, ABitmap.Width, ABitmap.Height), TargetWidth, TargetHeight, AData); end; {------------------------------------------------------------------------------ @@ -2202,10 +2211,10 @@ begin try II.LoadFromBitmap(ABitmap, AMask); - FI := TFPCompactImgRGBA8Bit.Create(SourceRect.Right-SourceRect.Left+1, SourceRect.Bottom-SourceRect.Top+1); + FI := TFPCompactImgRGBA8Bit.Create(SourceRect.Right-SourceRect.Left, SourceRect.Bottom-SourceRect.Top); - for X := SourceRect.Left to SourceRect.Right do - for Y := SourceRect.Top to SourceRect.Bottom do + for X := SourceRect.Left to SourceRect.Right-1 do + for Y := SourceRect.Top to SourceRect.Bottom-1 do begin if (X>=0) and (X=0) and (Y