* Updated Vampyre Imaging Lib
* Fixed heContrs compilation * Fixed region editing in frmLargeScaleCommand and frmRegionControl * Fixed control alignment in frmMain
This commit is contained in:
+143
-143
@@ -1866,142 +1866,142 @@ var
|
||||
OldFmt: TImageFormat;
|
||||
|
||||
procedure XShear(var Src, Dst: TImageData; Row, Offset, Weight, Bpp: Integer);
|
||||
var
|
||||
I, J, XPos: Integer;
|
||||
PixSrc, PixLeft, PixOldLeft: TColor32Rec;
|
||||
LineDst: PByteArray;
|
||||
SrcPtr: PColor32;
|
||||
begin
|
||||
SrcPtr := @PByteArray(Src.Bits)[Row * Src.Width * Bpp];
|
||||
LineDst := @PByteArray(Dst.Bits)[Row * Dst.Width * Bpp];
|
||||
PixOldLeft.Color := 0;
|
||||
|
||||
for I := 0 to Src.Width - 1 do
|
||||
begin
|
||||
CopyPixel(SrcPtr, @PixSrc, Bpp);
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixLeft.Channels[J] := MulDiv(PixSrc.Channels[J], Weight, 256);
|
||||
|
||||
XPos := I + Offset;
|
||||
if (XPos >= 0) and (XPos < Dst.Width) then
|
||||
begin
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixSrc.Channels[J] := PixSrc.Channels[J] - (PixLeft.Channels[J] - PixOldLeft.Channels[J]);
|
||||
CopyPixel(@PixSrc, @LineDst[XPos * Bpp], Bpp);
|
||||
end;
|
||||
PixOldLeft := PixLeft;
|
||||
Inc(PByte(SrcPtr), Bpp);
|
||||
end;
|
||||
|
||||
XPos := Src.Width + Offset;
|
||||
if XPos < Dst.Width then
|
||||
CopyPixel(@PixOldLeft, @LineDst[XPos * Bpp], Bpp);
|
||||
end;
|
||||
|
||||
procedure YShear(var Src, Dst: TImageData; Col, Offset, Weight, Bpp: Integer);
|
||||
var
|
||||
I, J, YPos: Integer;
|
||||
PixSrc, PixLeft, PixOldLeft: TColor32Rec;
|
||||
SrcPtr: PByte;
|
||||
begin
|
||||
SrcPtr := @PByteArray(Src.Bits)[Col * Bpp];
|
||||
PixOldLeft.Color := 0;
|
||||
|
||||
for I := 0 to Src.Height - 1 do
|
||||
begin
|
||||
CopyPixel(SrcPtr, @PixSrc, Bpp);
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixLeft.Channels[J] := MulDiv(PixSrc.Channels[J], Weight, 256);
|
||||
|
||||
YPos := I + Offset;
|
||||
if (YPos >= 0) and (YPos < Dst.Height) then
|
||||
begin
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixSrc.Channels[J] := PixSrc.Channels[J] - (PixLeft.Channels[J] - PixOldLeft.Channels[J]);
|
||||
CopyPixel(@PixSrc, @PByteArray(Dst.Bits)[(YPos * Dst.Width + Col) * Bpp], Bpp);
|
||||
end;
|
||||
PixOldLeft := PixLeft;
|
||||
Inc(SrcPtr, Src.Width * Bpp);
|
||||
end;
|
||||
|
||||
YPos := Src.Height + Offset;
|
||||
if YPos < Dst.Height then
|
||||
CopyPixel(@PixOldLeft, @PByteArray(Dst.Bits)[(YPos * Dst.Width + Col) * Bpp], Bpp);
|
||||
end;
|
||||
|
||||
procedure Rotate45(var Image: TImageData; Angle: Single);
|
||||
var
|
||||
TempImage1, TempImage2: TImageData;
|
||||
AngleRad, AngleTan, AngleSin, AngleCos, Shear: Single;
|
||||
I, DstWidth, DstHeight, SrcWidth, SrcHeight, Bpp: Integer;
|
||||
SrcFmt, TempFormat: TImageFormat;
|
||||
Info: TImageFormatInfo;
|
||||
begin
|
||||
AngleRad := Angle * Pi / 180;
|
||||
AngleSin := Sin(AngleRad);
|
||||
AngleCos := Cos(AngleRad);
|
||||
AngleTan := Sin(AngleRad / 2) / Cos(AngleRad / 2);
|
||||
SrcWidth := Image.Width;
|
||||
SrcHeight := Image.Height;
|
||||
SrcFmt := Image.Format;
|
||||
|
||||
if not (SrcFmt in [ifR8G8B8..ifX8R8G8B8, ifGray8..ifGray32, ifA16Gray16]) then
|
||||
ConvertImage(Image, ifA8R8G8B8);
|
||||
|
||||
TempFormat := Image.Format;
|
||||
GetImageFormatInfo(TempFormat, Info);
|
||||
Bpp := Info.BytesPerPixel;
|
||||
|
||||
// 1st shear (horizontal)
|
||||
DstWidth := Trunc(SrcWidth + SrcHeight * Abs(AngleTan) + 0.5);
|
||||
DstHeight := SrcHeight;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, TempImage1);
|
||||
|
||||
for I := 0 to DstHeight - 1 do
|
||||
begin
|
||||
if AngleTan >= 0 then
|
||||
Shear := (I + 0.5) * AngleTan
|
||||
else
|
||||
Shear := (I - DstHeight + 0.5) * AngleTan;
|
||||
XShear(Image, TempImage1, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
end;
|
||||
|
||||
// 2nd shear (vertical)
|
||||
FreeImage(Image);
|
||||
DstHeight := Trunc(SrcWidth * Abs(AngleSin) + SrcHeight * AngleCos + 0.5) + 1;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, TempImage2);
|
||||
|
||||
if AngleSin >= 0 then
|
||||
Shear := (SrcWidth - 1) * AngleSin
|
||||
else
|
||||
Shear := (SrcWidth - DstWidth) * -AngleSin;
|
||||
|
||||
for I := 0 to DstWidth - 1 do
|
||||
begin
|
||||
YShear(TempImage1, TempImage2, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
Shear := Shear - AngleSin;
|
||||
end;
|
||||
|
||||
// 3rd shear (horizontal)
|
||||
FreeImage(TempImage1);
|
||||
DstWidth := Trunc(SrcHeight * Abs(AngleSin) + SrcWidth * AngleCos + 0.5) + 1;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, Image);
|
||||
|
||||
if AngleSin >= 0 then
|
||||
Shear := (SrcWidth - 1) * AngleSin * -AngleTan
|
||||
else
|
||||
Shear := ((SrcWidth - 1) * -AngleSin + (1 - DstHeight)) * AngleTan;
|
||||
|
||||
for I := 0 to DstHeight - 1 do
|
||||
begin
|
||||
XShear(TempImage2, Image, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
Shear := Shear + AngleTan;
|
||||
end;
|
||||
|
||||
FreeImage(TempImage2);
|
||||
if Image.Format <> SrcFmt then
|
||||
ConvertImage(Image, SrcFmt);
|
||||
end;
|
||||
var
|
||||
I, J, XPos: Integer;
|
||||
PixSrc, PixLeft, PixOldLeft: TColor32Rec;
|
||||
LineDst: PByteArray;
|
||||
SrcPtr: PColor32;
|
||||
begin
|
||||
SrcPtr := @PByteArray(Src.Bits)[Row * Src.Width * Bpp];
|
||||
LineDst := @PByteArray(Dst.Bits)[Row * Dst.Width * Bpp];
|
||||
PixOldLeft.Color := 0;
|
||||
|
||||
for I := 0 to Src.Width - 1 do
|
||||
begin
|
||||
CopyPixel(SrcPtr, @PixSrc, Bpp);
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixLeft.Channels[J] := MulDiv(PixSrc.Channels[J], Weight, 256);
|
||||
|
||||
XPos := I + Offset;
|
||||
if (XPos >= 0) and (XPos < Dst.Width) then
|
||||
begin
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixSrc.Channels[J] := PixSrc.Channels[J] - (PixLeft.Channels[J] - PixOldLeft.Channels[J]);
|
||||
CopyPixel(@PixSrc, @LineDst[XPos * Bpp], Bpp);
|
||||
end;
|
||||
PixOldLeft := PixLeft;
|
||||
Inc(PByte(SrcPtr), Bpp);
|
||||
end;
|
||||
|
||||
XPos := Src.Width + Offset;
|
||||
if XPos < Dst.Width then
|
||||
CopyPixel(@PixOldLeft, @LineDst[XPos * Bpp], Bpp);
|
||||
end;
|
||||
|
||||
procedure YShear(var Src, Dst: TImageData; Col, Offset, Weight, Bpp: Integer);
|
||||
var
|
||||
I, J, YPos: Integer;
|
||||
PixSrc, PixLeft, PixOldLeft: TColor32Rec;
|
||||
SrcPtr: PByte;
|
||||
begin
|
||||
SrcPtr := @PByteArray(Src.Bits)[Col * Bpp];
|
||||
PixOldLeft.Color := 0;
|
||||
|
||||
for I := 0 to Src.Height - 1 do
|
||||
begin
|
||||
CopyPixel(SrcPtr, @PixSrc, Bpp);
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixLeft.Channels[J] := MulDiv(PixSrc.Channels[J], Weight, 256);
|
||||
|
||||
YPos := I + Offset;
|
||||
if (YPos >= 0) and (YPos < Dst.Height) then
|
||||
begin
|
||||
for J := 0 to Bpp - 1 do
|
||||
PixSrc.Channels[J] := PixSrc.Channels[J] - (PixLeft.Channels[J] - PixOldLeft.Channels[J]);
|
||||
CopyPixel(@PixSrc, @PByteArray(Dst.Bits)[(YPos * Dst.Width + Col) * Bpp], Bpp);
|
||||
end;
|
||||
PixOldLeft := PixLeft;
|
||||
Inc(SrcPtr, Src.Width * Bpp);
|
||||
end;
|
||||
|
||||
YPos := Src.Height + Offset;
|
||||
if YPos < Dst.Height then
|
||||
CopyPixel(@PixOldLeft, @PByteArray(Dst.Bits)[(YPos * Dst.Width + Col) * Bpp], Bpp);
|
||||
end;
|
||||
|
||||
procedure Rotate45(var Image: TImageData; Angle: Single);
|
||||
var
|
||||
TempImage1, TempImage2: TImageData;
|
||||
AngleRad, AngleTan, AngleSin, AngleCos, Shear: Single;
|
||||
I, DstWidth, DstHeight, SrcWidth, SrcHeight, Bpp: Integer;
|
||||
SrcFmt, TempFormat: TImageFormat;
|
||||
Info: TImageFormatInfo;
|
||||
begin
|
||||
AngleRad := Angle * Pi / 180;
|
||||
AngleSin := Sin(AngleRad);
|
||||
AngleCos := Cos(AngleRad);
|
||||
AngleTan := Sin(AngleRad / 2) / Cos(AngleRad / 2);
|
||||
SrcWidth := Image.Width;
|
||||
SrcHeight := Image.Height;
|
||||
SrcFmt := Image.Format;
|
||||
|
||||
if not (SrcFmt in [ifR8G8B8..ifX8R8G8B8, ifGray8..ifGray32, ifA16Gray16]) then
|
||||
ConvertImage(Image, ifA8R8G8B8);
|
||||
|
||||
TempFormat := Image.Format;
|
||||
GetImageFormatInfo(TempFormat, Info);
|
||||
Bpp := Info.BytesPerPixel;
|
||||
|
||||
// 1st shear (horizontal)
|
||||
DstWidth := Trunc(SrcWidth + SrcHeight * Abs(AngleTan) + 0.5);
|
||||
DstHeight := SrcHeight;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, TempImage1);
|
||||
|
||||
for I := 0 to DstHeight - 1 do
|
||||
begin
|
||||
if AngleTan >= 0 then
|
||||
Shear := (I + 0.5) * AngleTan
|
||||
else
|
||||
Shear := (I - DstHeight + 0.5) * AngleTan;
|
||||
XShear(Image, TempImage1, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
end;
|
||||
|
||||
// 2nd shear (vertical)
|
||||
FreeImage(Image);
|
||||
DstHeight := Trunc(SrcWidth * Abs(AngleSin) + SrcHeight * AngleCos + 0.5) + 1;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, TempImage2);
|
||||
|
||||
if AngleSin >= 0 then
|
||||
Shear := (SrcWidth - 1) * AngleSin
|
||||
else
|
||||
Shear := (SrcWidth - DstWidth) * -AngleSin;
|
||||
|
||||
for I := 0 to DstWidth - 1 do
|
||||
begin
|
||||
YShear(TempImage1, TempImage2, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
Shear := Shear - AngleSin;
|
||||
end;
|
||||
|
||||
// 3rd shear (horizontal)
|
||||
FreeImage(TempImage1);
|
||||
DstWidth := Trunc(SrcHeight * Abs(AngleSin) + SrcWidth * AngleCos + 0.5) + 1;
|
||||
NewImage(DstWidth, DstHeight, TempFormat, Image);
|
||||
|
||||
if AngleSin >= 0 then
|
||||
Shear := (SrcWidth - 1) * AngleSin * -AngleTan
|
||||
else
|
||||
Shear := ((SrcWidth - 1) * -AngleSin + (1 - DstHeight)) * AngleTan;
|
||||
|
||||
for I := 0 to DstHeight - 1 do
|
||||
begin
|
||||
XShear(TempImage2, Image, I, Floor(Shear), Trunc(255 * (Shear - Floor(Shear)) + 1), Bpp);
|
||||
Shear := Shear + AngleTan;
|
||||
end;
|
||||
|
||||
FreeImage(TempImage2);
|
||||
if Image.Format <> SrcFmt then
|
||||
ConvertImage(Image, SrcFmt);
|
||||
end;
|
||||
|
||||
procedure RotateMul90(var Image: TImageData; Angle: Integer);
|
||||
var
|
||||
@@ -2009,7 +2009,7 @@ var
|
||||
X, Y, BytesPerPixel: Integer;
|
||||
RotPix, Pix: PByte;
|
||||
begin
|
||||
InitImage(RotImage);
|
||||
InitImage(RotImage);
|
||||
BytesPerPixel := ImageFormatInfos[Image.Format].BytesPerPixel;
|
||||
|
||||
if ((Angle = 90) or (Angle = 270)) and (Image.Width <> Image.Height) then
|
||||
@@ -2061,9 +2061,9 @@ var
|
||||
|
||||
FreeMemNil(Image.Bits);
|
||||
RotImage.Palette := Image.Palette;
|
||||
Image := RotImage;
|
||||
Image := RotImage;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
@@ -2073,7 +2073,7 @@ begin
|
||||
Angle := Angle - 360;
|
||||
while Angle < 0 do
|
||||
Angle := Angle + 360;
|
||||
|
||||
|
||||
if (Angle = 0) or (Abs(Angle) = 360) then
|
||||
begin
|
||||
Result := True;
|
||||
@@ -2099,9 +2099,9 @@ begin
|
||||
RotateMul90(Image, 270);
|
||||
Angle := Angle - 270;
|
||||
end;
|
||||
|
||||
if Angle <> 0 then
|
||||
Rotate45(Image, Angle);
|
||||
|
||||
if Angle <> 0 then
|
||||
Rotate45(Image, Angle);
|
||||
|
||||
if OldFmt <> Image.Format then
|
||||
ConvertImage(Image, OldFmt);
|
||||
|
||||
Reference in New Issue
Block a user