jvcllaz: Simplified image transformations in TJvThumbImage. Add button to save transformed image to thumbnail demo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6337 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-04-22 11:30:20 +00:00
parent f21e681c30
commit 9c6eade58b
4 changed files with 217 additions and 183 deletions

View File

@ -31,14 +31,14 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
Cursor = crVSplit Cursor = crVSplit
Left = 0 Left = 0
Height = 3 Height = 3
Top = 124 Top = 149
Width = 238 Width = 238
Align = alTop Align = alTop
ResizeAnchor = akTop ResizeAnchor = akTop
end end
object ShellTreeView: TShellTreeView object ShellTreeView: TShellTreeView
Left = 4 Left = 4
Height = 120 Height = 145
Top = 4 Top = 4
Width = 230 Width = 230
Align = alTop Align = alTop
@ -60,8 +60,8 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
end end
object ShellListView: TShellListView object ShellListView: TShellListView
Left = 4 Left = 4
Height = 216 Height = 191
Top = 150 Top = 175
Width = 230 Width = 230
Align = alClient Align = alClient
BorderSpacing.Left = 4 BorderSpacing.Left = 4
@ -244,15 +244,14 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
AnchorSideLeft.Control = Panel8 AnchorSideLeft.Control = Panel8
AnchorSideTop.Control = ContrastBar AnchorSideTop.Control = ContrastBar
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel8 AnchorSideRight.Control = CenterBevel
AnchorSideRight.Side = asrBottom
Left = 4 Left = 4
Height = 25 Height = 25
Top = 205 Top = 205
Width = 225 Width = 107
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 4 BorderSpacing.Left = 4
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 4
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
Caption = 'APPLY' Caption = 'APPLY'
OnClick = BtnApplyClick OnClick = BtnApplyClick
@ -288,11 +287,27 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
Width = 16 Width = 16
Shape = bsSpacer Shape = bsSpacer
end end
object BtnSave: TButton
AnchorSideLeft.Control = CenterBevel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = BtnApply
AnchorSideRight.Control = Panel8
AnchorSideRight.Side = asrBottom
Left = 127
Height = 25
Top = 205
Width = 107
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Right = 4
Caption = 'SAVE'
OnClick = BtnSaveClick
TabOrder = 6
end
end end
object Panel10: TPanel object Panel10: TPanel
Left = 4 Left = 4
Height = 23 Height = 23
Top = 127 Top = 152
Width = 230 Width = 230
Align = alTop Align = alTop
AutoSize = True AutoSize = True
@ -346,17 +361,16 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
AnchorSideLeft.Control = Panel1 AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel5 AnchorSideTop.Control = Panel5
AnchorSideRight.Control = GbAngle
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 431 Left = 431
Height = 82 Height = 117
Top = 0 Top = 0
Width = 131 Width = 131
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Left = 8 BorderSpacing.Left = 8
Caption = 'THUMBIMAGE' Caption = 'THUMBIMAGE'
ClientHeight = 62 ClientHeight = 97
ClientWidth = 127 ClientWidth = 127
TabOrder = 0 TabOrder = 0
object BtnInvert: TButton object BtnInvert: TButton
@ -394,44 +408,33 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
OnClick = BtnGrayScaleClick OnClick = BtnGrayScaleClick
TabOrder = 1 TabOrder = 1
end end
end object CbTransform: TComboBox
object GbAngle: TRadioGroup AnchorSideLeft.Control = BtnInvert
AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = BtnGrayScale
AnchorSideLeft.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideTop.Control = GbThumbImage AnchorSideRight.Control = BtnInvert
AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideRight.Side = asrBottom Left = 8
AnchorSideBottom.Control = Panel1 Height = 23
AnchorSideBottom.Side = asrBottom Top = 62
Left = 431 Width = 111
Height = 81 Anchors = [akTop, akLeft, akRight]
Top = 94 BorderSpacing.Bottom = 12
Width = 131 ItemHeight = 15
Anchors = [akTop, akLeft, akBottom] ItemIndex = 0
AutoFill = True Items.Strings = (
AutoSize = True 'Rotate by 0°'
BorderSpacing.Left = 8 'Rotate by 90°'
BorderSpacing.Top = 12 'Rotate by 180°'
BorderSpacing.Right = 8 'Rotate by 270°'
Caption = ' ThumbImage Angle ' 'Mirror horizontally'
ChildSizing.LeftRightSpacing = 16 'Mirror vertically'
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize )
ChildSizing.EnlargeVertical = crsHomogenousChildResize OnChange = CbTransformChange
ChildSizing.ShrinkHorizontal = crsScaleChilds Style = csDropDownList
ChildSizing.ShrinkVertical = crsScaleChilds TabOrder = 2
ChildSizing.Layout = cclLeftToRightThenTopToBottom Text = 'Rotate by 0°'
ChildSizing.ControlsPerLine = 2 end
ClientHeight = 61
ClientWidth = 127
Columns = 2
Items.Strings = (
'0'
'90'
'180'
'270'
)
OnClick = GbAngleClick
TabOrder = 1
end end
object ThumbNail: TJvThumbnail object ThumbNail: TJvThumbnail
AnchorSideLeft.Control = Panel5 AnchorSideLeft.Control = Panel5
@ -448,7 +451,7 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
ClientHeight = 175 ClientHeight = 175
ClientWidth = 152 ClientWidth = 152
Constraints.MinWidth = 152 Constraints.MinWidth = 152
TabOrder = 2 TabOrder = 1
OnClick = ThumbNailClick OnClick = ThumbNailClick
ShadowColor = clSilver ShadowColor = clSilver
TitleColor = clBtnFace TitleColor = clBtnFace
@ -468,7 +471,7 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
BevelOuter = bvLowered BevelOuter = bvLowered
ClientHeight = 175 ClientHeight = 175
ClientWidth = 261 ClientWidth = 261
TabOrder = 3 TabOrder = 2
object CbAsButton: TCheckBox object CbAsButton: TCheckBox
AnchorSideLeft.Control = Panel1 AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1 AnchorSideTop.Control = Panel1
@ -597,23 +600,36 @@ object JvThumbnailChildForm: TJvThumbnailChildForm
Height = 15 Height = 15
Hint = 'You can set the thumbnails title to what ever you want it to be ' Hint = 'You can set the thumbnails title to what ever you want it to be '
Top = 123 Top = 123
Width = 89 Width = 84
BorderSpacing.Top = 9 BorderSpacing.Top = 9
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
Caption = 'Thumbnails Title' Caption = 'Thumbnail Title'
ParentColor = False ParentColor = False
end end
object SpinEdit1: TSpinEdit object SpinEdit1: TSpinEdit
AnchorSideLeft.Control = LblMargin
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = BtnExit
AnchorSideTop.Side = asrCenter
Left = 60
Height = 23
Top = 90
Width = 60
BorderSpacing.Left = 12
OnChange = SpinEdit1Change
TabOrder = 6
end
object LblMargin: TLabel
AnchorSideLeft.Control = Panel1 AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = BtnExit AnchorSideTop.Control = BtnExit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 10 Left = 10
Height = 23 Height = 15
Top = 90 Top = 94
Width = 86 Width = 38
BorderSpacing.Left = 8 BorderSpacing.Left = 8
OnChange = SpinEdit1Change Caption = 'Margin'
TabOrder = 6 ParentColor = False
end end
end end
end end

View File

@ -40,7 +40,10 @@ type
{ TJvThumbnailChildForm } { TJvThumbnailChildForm }
TJvThumbnailChildForm = class(TForm) TJvThumbnailChildForm = class(TForm)
BtnSave: TButton;
CenterBevel: TBevel; CenterBevel: TBevel;
CbTransform: TComboBox;
LblMargin: TLabel;
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
SpinEdit1: TSpinEdit; SpinEdit1: TSpinEdit;
@ -75,18 +78,18 @@ type
LblLightness: TLabel; LblLightness: TLabel;
LightnessBar: TTrackBar; LightnessBar: TTrackBar;
BtnExit: TButton; BtnExit: TButton;
GbAngle: TRadioGroup;
ThumbNail: TJVThumbNail; ThumbNail: TJVThumbNail;
ThumbImage: TJvThumbImage; ThumbImage: TJvThumbImage;
procedure BtnApplyClick(Sender: TObject); procedure BtnApplyClick(Sender: TObject);
procedure BtnInvertClick(Sender: TObject); procedure BtnInvertClick(Sender: TObject);
procedure BtnGrayScaleClick(Sender: TObject); procedure BtnGrayScaleClick(Sender: TObject);
procedure BtnSaveClick(Sender: TObject);
procedure CbAsButtonClick(Sender: TObject); procedure CbAsButtonClick(Sender: TObject);
procedure CbAutoLoadClick(Sender: TObject); procedure CbAutoLoadClick(Sender: TObject);
procedure CbMinimizeMemClick(Sender: TObject); procedure CbMinimizeMemClick(Sender: TObject);
procedure CbTransformChange(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure GbAngleClick(Sender: TObject);
procedure GbTitlePlacementClick(Sender: TObject); procedure GbTitlePlacementClick(Sender: TObject);
procedure Panel10Resize(Sender: TObject); procedure Panel10Resize(Sender: TObject);
procedure Panel2Resize(Sender: TObject); procedure Panel2Resize(Sender: TObject);
@ -130,6 +133,7 @@ begin
BlueBar.Position := 0; BlueBar.Position := 0;
ContrastBar.Position := 0; ContrastBar.Position := 0;
LightnessBar.Position := 0; LightnessBar.Position := 0;
BtnSave.Enabled := true;
end; end;
procedure TJvThumbnailChildForm.LoadFile(const AFileName: String); procedure TJvThumbnailChildForm.LoadFile(const AFileName: String);
@ -241,6 +245,25 @@ begin
ThumbNail.MinimizeMemory := CbMinimizeMem.Checked; ThumbNail.MinimizeMemory := CbMinimizeMem.Checked;
end; end;
procedure TJvThumbnailChildForm.CbTransformChange(Sender: TObject);
var
w, h: Integer;
begin
w := ThumbImage.Picture.Width;
h := ThumbImage.Picture.Height;
case CbTransform.ItemIndex of
0: ThumbImage.Angle := AT0;
1: ThumbImage.Angle := AT90;
2: ThumbImage.Angle := AT180;
3: ThumbImage.Angle := AT270;
4: ThumbImage.Mirror(mtHorizontal);
5: ThumbImage.Mirror(mtVertical);
end;
if (w <> ThumbImage.Picture.Width) or (h <> ThumbImage.Picture.Height) then
with ThumbImage do SetBounds(0, 0, Picture.Width, Picture.Height);
BtnSave.Enabled := true;
end;
procedure TJvThumbnailChildForm.FormCreate(Sender: TObject); procedure TJvThumbnailChildForm.FormCreate(Sender: TObject);
begin begin
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
@ -249,6 +272,7 @@ begin
{$ENDIF} {$ENDIF}
FilterCombobox.ItemIndex := 0; FilterCombobox.ItemIndex := 0;
ShellListView.Mask := FilterCombobox.Mask; ShellListView.Mask := FilterCombobox.Mask;
BtnSave.Enabled := false;
end; end;
procedure TJvThumbnailChildForm.GbTitlePlacementClick(Sender: TObject); procedure TJvThumbnailChildForm.GbTitlePlacementClick(Sender: TObject);
@ -264,11 +288,23 @@ end;
procedure TJvThumbnailChildForm.BtnInvertClick(Sender: TObject); procedure TJvThumbnailChildForm.BtnInvertClick(Sender: TObject);
begin begin
ThumbImage.Invert; ThumbImage.Invert;
BtnSave.Enabled := true;
end; end;
procedure TJvThumbnailChildForm.BtnGrayScaleClick(Sender: TObject); procedure TJvThumbnailChildForm.BtnGrayScaleClick(Sender: TObject);
begin begin
ThumbImage.GrayScale; ThumbImage.GrayScale;
BtnSave.Enabled := true;
end;
procedure TJvThumbnailChildForm.BtnSaveClick(Sender: TObject);
var
fn: String;
begin
if ThumbImage.Modified then begin
fn := ChangeFileExt(ThumbImage.FileName, '') + '_modified' + ExtractFileExt(ThumbImage.FileName);
ThumbImage.SaveToFile(fn);
end;
end; end;
procedure TJvThumbnailChildForm.ThumbNailClick(Sender: TObject); procedure TJvThumbnailChildForm.ThumbNailClick(Sender: TObject);
@ -299,23 +335,11 @@ end;
procedure TJvThumbnailChildForm.FormShow(Sender: TObject); procedure TJvThumbnailChildForm.FormShow(Sender: TObject);
begin begin
//ThumbImage.Picture.Free;
GbTitlePlacement.ItemIndex := integer(ThumbNail.titlePlacement); GbTitlePlacement.ItemIndex := integer(ThumbNail.titlePlacement);
GbAngle.ItemIndex := integer(ThumbImage.angle); CbTransform.ItemIndex := 0;
SpinEdit1.Value := Thumbnail.Margin; SpinEdit1.Value := Thumbnail.Margin;
end; end;
procedure TJvThumbnailChildForm.GbAngleClick(Sender: TObject);
var
w, h: Integer;
begin
w := ThumbImage.Picture.Width;
h := ThumbImage.Picture.Height;
ThumbImage.Angle := TAngle(GbAngle.ItemIndex);
if (w <> ThumbImage.Picture.Width) or (h <> ThumbImage.Picture.Height) then
with ThumbImage do SetBounds(0, 0, Picture.Width, Picture.Height);
end;
function TJvThumbnailChildForm.GetfileName: String; function TJvThumbnailChildForm.GetfileName: String;
begin begin
Result := ShellListView.GetPathFromItem(ShellListView.Selected); Result := ShellListView.GetPathFromItem(ShellListView.Selected);

View File

@ -137,6 +137,8 @@ type
private private
FIgnoreMouse: Boolean; FIgnoreMouse: Boolean;
protected protected
procedure Click; override;
procedure DblClick; override;
{ wp removed { wp removed
function HitTest(X, Y: Integer): Boolean; override; } function HitTest(X, Y: Integer): Boolean; override; }
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
@ -144,8 +146,6 @@ type
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override; X, Y: Integer); override;
procedure Click; override;
procedure DblClick; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
published published

View File

@ -63,7 +63,10 @@ type
TFilterEmpty = function: Byte; TFilterEmpty = function: Byte;
TFilterArray = array [1..9] of Byte; TFilterArray = array [1..9] of Byte;
TJvTransformProc = procedure (ASourceIntfImage, ADestIntfImage: TLazIntfImage; TJvTransformProc = procedure (AIntfImage: TLazIntfImage;
ARedData, AGreenData, ABlueData: Pointer);
TJvTransformProc2 = procedure (ASourceIntfImage, ADestIntfImage: TLazIntfImage;
ARedData, AGreenData, ABlueData: Pointer); ARedData, AGreenData, ABlueData: Pointer);
{ TJvThumbImage } { TJvThumbImage }
@ -78,8 +81,6 @@ type
FFileName: string; FFileName: string;
FClass: TGraphicClass; FClass: TGraphicClass;
FOnInvalidImage: TInvalidImageEvent; FOnInvalidImage: TInvalidImageEvent;
// procedure Rotate90;
// procedure Rotate270;
procedure SetAngle(AAngle: TAngle); procedure SetAngle(AAngle: TAngle);
function GetModify: Boolean; function GetModify: Boolean;
public public
@ -95,7 +96,9 @@ type
procedure SaveToFile(AFile: string); procedure SaveToFile(AFile: string);
procedure Save; procedure Save;
procedure Transform(TransformProc: TJvTransformProc; ARedData: Pointer = nil; procedure Transform(TransformProc: TJvTransformProc; ARedData: Pointer = nil;
AGreenData: Pointer = nil; ABlueData: Pointer = nil); AGreenData: Pointer = nil; ABlueData: Pointer = nil); overload;
procedure Transform(TransformProc: TJvTransformProc2; ARedData: Pointer = nil;
AGreenData: Pointer = nil; ABlueData: Pointer = nil); overload;
procedure BitmapNeeded; procedure BitmapNeeded;
// Procedure FilterFactory(Filter: TFilterArray; Divider: Byte); // Procedure FilterFactory(Filter: TFilterArray; Divider: Byte);
procedure Invert; procedure Invert;
@ -104,6 +107,7 @@ type
procedure Grayscale; procedure Grayscale;
procedure Rotate(AAngle: TAngle); procedure Rotate(AAngle: TAngle);
function GetFilter: string; function GetFilter: string;
property FileName: String read FFileName;
//property JpegScale: TJPegScale read vJPegScale write vJpegScale; //property JpegScale: TJPegScale read vJPegScale write vJpegScale;
published published
property Angle: TAngle read FAngle write SetAngle; property Angle: TAngle read FAngle write SetAngle;
@ -124,64 +128,66 @@ uses
FPImage, FPImage,
JvThumbnails, JvTypes, JvResources; JvThumbnails, JvTypes, JvResources;
procedure GrayScaleProc(ASrcImg, ADestImg: TLazIntfImage; procedure GrayScaleProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer);
var var
r, c: Integer; r, c: Integer;
clr: TColor; clr: TColor;
col: TFPColor; col: TFPColor;
intens: Integer; intens: Integer;
begin begin
for r := 0 to ASrcImg.Height - 1 do for r := 0 to AImg.Height - 1 do
for c := 0 to ASrcImg.Width - 1 do begin for c := 0 to AImg.Width - 1 do begin
col := ASrcImg.Colors[c, r]; col := AImg.Colors[c, r];
intens := (integer(col.Red) + col.Green + col.Blue) div 3; intens := (integer(col.Red) + col.Green + col.Blue) div 3;
ADestImg.Colors[c, r] := FPColor(intens, intens, intens, col.Alpha); AImg.Colors[c, r] := FPColor(intens, intens, intens, col.Alpha);
end; end;
end; end;
procedure InvertProc(ASrcImg, ADestImg: TLazIntfImage; procedure InvertProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer); const
MX: word = $FFFF;
var var
r, c: Integer; r, c: Integer;
col: TFPColor; col: TFPColor;
a: Word; a: Word;
begin begin
for r := 0 to ASrcImg.Height - 1 do for r := 0 to AImg.Height - 1 do
for c := 0 to ASrcImg.Width - 1 do begin for c := 0 to AImg.Width - 1 do begin
col := ASrcImg.Colors[c, r]; col := AImg.Colors[c, r];
a := col.Alpha; a := col.Alpha;
ADestImg.Colors[c, r] := FPColor(word(-col.Red), word(-col.Green), word(-col.Blue), a); AImg.Colors[c, r] := FPColor(MX-col.Red, MX-col.Green, MX-col.Blue, a);
end; end;
end; end;
procedure MirrorHorProc(ASrcImg, ADestImg: TLazIntfImage; procedure MirrorHorProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer);
var var
r, c, w, h: Integer; r, c, w, h: Integer;
col: TFPColor; col1, col2: TFPColor;
begin begin
w := ASrcImg.Width; w := AImg.Width;
h := ASrcImg.Height; h := AImg.Height;
for r := 0 to h - 1 do for r := 0 to h - 1 do
for c := 0 to w - 1 do begin for c := 0 to w div 2 do begin
col := ASrcImg.Colors[c, r]; col1 := AImg.Colors[c, r];
ADestImg.Colors[w-1-c, r] := col; col2 := AImg.Colors[w-1-c, r];
AImg.Colors[c, r] := col2;
AImg.Colors[w-1-c, r] := col1;
end; end;
end; end;
procedure MirrorVertProc(ASrcImg, ADestImg: TLazIntfImage; procedure MirrorVertProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer);
var var
r, c, w, h: Integer; r, c, w, h: Integer;
col: TFPColor; col1, col2: TFPColor;
begin begin
w := ASrcImg.Width; w := AImg.Width;
h := ASrcImg.Height; h := AImg.Height;
for r := 0 to h - 1 do for c := 0 to w - 1 do
for c := 0 to w - 1 do begin for r := 0 to h div 2 do begin
col := ASrcImg.Colors[c, r]; col1 := AImg.Colors[c, r];
ADestImg.Colors[c, h-1-r] := col; col2 := AImg.Colors[c, h-1-r];
AImg.Colors[c, r] := col2;
AImg.Colors[c, h-1-r] := col1;
end; end;
end; end;
@ -209,7 +215,6 @@ var
begin begin
w := ASrcImg.Width; w := ASrcImg.Width;
h := ASrcImg.Height; h := ASrcImg.Height;
ADestImg.SetSize(h, w);
for r := 0 to h - 1 do for r := 0 to h - 1 do
for c := 0 to w - 1 do begin for c := 0 to w - 1 do begin
col := ASrcImg.Colors[c, r]; col := ASrcImg.Colors[c, r];
@ -233,8 +238,7 @@ begin
end; end;
end; end;
procedure RGBProc(ASrcImg, ADestImg: TLazIntfImage; procedure RGBProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer);
var var
r, c: Integer; r, c: Integer;
clr: TColor; clr: TColor;
@ -246,21 +250,19 @@ begin
deltaR := PtrUInt(ARedData); deltaR := PtrUInt(ARedData);
deltaG := PtrUInt(AGreenData); deltaG := PtrUInt(AGreenData);
deltaB := PtrUInt(ABlueData); deltaB := PtrUInt(ABlueData);
for r := 0 to ASrcImg.Height - 1 do for r := 0 to AImg.Height - 1 do
for c := 0 to ASrcImg.Width - 1 do begin for c := 0 to AImg.Width - 1 do begin
a := ASrcImg.Colors[c, r].Alpha; a := AImg.Colors[c, r].Alpha;
clr := ASrcImg.TColors[c, r]; clr := AImg.TColors[c, r];
rVal := BoundByte(0, 255, GetBValue(clr) + deltaR); rVal := BoundByte(0, 255, GetBValue(clr) + deltaR);
gVal := BoundByte(0, 255, GetGValue(clr) + deltaG); gVal := BoundByte(0, 255, GetGValue(clr) + deltaG);
bVal := BoundByte(0, 255, GetBValue(clr) + deltaB); bVal := BoundByte(0, 255, GetBValue(clr) + deltaB);
col := FPColor(rval shl 8, gval shl 8, bval shl 8, a); col := FPColor(rval shl 8, gval shl 8, bval shl 8, a);
ADestImg.Colors[c, r] := col; AImg.Colors[c, r] := col;
// ADestImg.TColors[c, r] := RGBToColor(rVal, gVal, bVal);
end; end;
end; end;
procedure RGBCurveProc(ASrcImg, ADestImg: TLazIntfImage; procedure RGBCurveProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer);
ARedData, AGreenData, ABlueData: Pointer);
var var
r, c: Integer; r, c: Integer;
clr: TColor; clr: TColor;
@ -268,16 +270,15 @@ var
a: Word; a: Word;
col: TFPColor; col: TFPColor;
begin begin
for r := 0 to ASrcImg.Height - 1 do for r := 0 to AImg.Height - 1 do
for c := 0 to ASrcImg.Width - 1 do begin for c := 0 to AImg.Width - 1 do begin
a := ASrcImg.Colors[c, r].Alpha; a := AImg.Colors[c, r].Alpha;
clr := ASrcImg.TColors[c, r]; clr := AImg.TColors[c, r];
rVal := TCurveArray(ARedData^)[GetRValue(clr)]; rVal := TCurveArray(ARedData^)[GetRValue(clr)];
gVal := TCurveArray(AGreenData^)[GetGValue(clr)]; gVal := TCurveArray(AGreenData^)[GetGValue(clr)];
bVal := TCurveArray(ABlueData^)[GetBValue(clr)]; bVal := TCurveArray(ABlueData^)[GetBValue(clr)];
col := FPColor(rVal shl 8, gVal shl 8, bVal shl 8, a); col := FPColor(rVal shl 8, gVal shl 8, bVal shl 8, a);
ADestImg.Colors[c, r] := col; AImg.Colors[c, r] := col;
//ADestImg.TColors[c, r] := RGBToColor(rVal, gVal, bVal);
end; end;
end; end;
@ -552,13 +553,14 @@ var
Ext: string; Ext: string;
Jpg: TJpegImage; Jpg: TJpegImage;
Bmp: TBitmap; Bmp: TBitmap;
png: TPortableNetworkGraphic;
{*************** NOT CONVERTED *** {*************** NOT CONVERTED ***
Wmf: TMetafile; Wmf: TMetafile;
********************************} ********************************}
begin begin
// (rom) enforcing a file extension is bad style // (rom) enforcing a file extension is bad style
Ext := UpperCase(ExtractFileExt(AFile)); Ext := LowerCase(ExtractFileExt(AFile));
if (Ext = '.JPG') or (Ext = '.JPEG') then if (Ext = '.jpg') or (Ext = '.jpeg') then
try try
Jpg := TJpegImage.Create; Jpg := TJpegImage.Create;
Jpg.Assign(Picture.Graphic); Jpg.Assign(Picture.Graphic);
@ -568,18 +570,28 @@ begin
**********************************} **********************************}
Jpg.SaveToFile(AFile); Jpg.SaveToFile(AFile);
finally finally
FreeAndNil(Jpg); Jpg.Free;
end end
else else
if Ext = '.BMP' then if Ext = '.bmp' then
try try
Bmp := Graphics.TBitmap.Create; Bmp := Graphics.TBitmap.Create;
Bmp.Assign(Picture.Graphic); Bmp.Assign(Picture.Graphic);
Bmp.Canvas.Draw(0, 0, Picture.Graphic); Bmp.Canvas.Draw(0, 0, Picture.Graphic);
Bmp.SaveToFile(AFile); Bmp.SaveToFile(AFile);
finally finally
FreeAndNil(Bmp); Bmp.Free;
end end
else
if Ext = '.png' then
try
png := TPortableNetworkGraphic.Create;
png.Assign(Picture.Graphic);
png.Canvas.Draw(0, 0, Picture.Graphic);
png.SaveToFile(AFile);
finally
png.Free;
end
{ ********************** NOT CONVERTED *** { ********************** NOT CONVERTED ***
else else
if Ext = '.WMF' then if Ext = '.WMF' then
@ -783,61 +795,43 @@ end;
procedure TJvThumbImage.Transform(TransformProc: TJvTransformProc; procedure TJvThumbImage.Transform(TransformProc: TJvTransformProc;
ARedData: Pointer = nil; AGreenData: Pointer = nil; ABlueData: Pointer = nil); ARedData: Pointer = nil; AGreenData: Pointer = nil; ABlueData: Pointer = nil);
var var
Bmp: TBitmap; IntfImg: TLazIntfImage;
ImgHandle, ImgMaskHandle: HBitmap;
begin
if Assigned(Picture.Graphic) and CanModify then begin
IntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage;
try
TransformProc(IntfImg, ARedData, AGreenData, ABlueData);
IntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle);
Picture.Bitmap.LoadFromIntfImage(IntfImg);
FModified := true;
finally
IntfImg.Free;
end;
end;
end;
{ General bitmap transformation method using LazIntfImages. The operation is
specified by the procedure pointer TransformProc. }
procedure TJvThumbImage.Transform(TransformProc: TJvTransformProc2;
ARedData: Pointer = nil; AGreenData: Pointer = nil; ABlueData: Pointer = nil);
var
SrcIntfImg, DestIntfImg: TLazIntfImage; SrcIntfImg, DestIntfImg: TLazIntfImage;
DestImgHandle, DestImgMaskHandle: HBitmap; DestImgHandle, DestImgMaskHandle: HBitmap;
w, h: Integer;
begin begin
if Assigned(Picture.Graphic) then if Assigned(Picture.Graphic) and CanModify then begin
if CanModify then SrcIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage;
begin DestIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage;
w := Picture.Width; try
h := Picture.Height; TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData);
SrcIntfImg := TLazIntfImage.Create(0, 0); DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle);
DestIntfImg := TLazIntfImage.Create(0, 0); Picture.Bitmap.LoadFromIntfImage(DestIntfImg);
if Picture.Graphic is TPortableNetworkGraphic then FModified := true;
begin finally
SrcIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; DestIntfImg.Free;
DestIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; SrcIntfImg.Free;
TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData);
DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle);
bmp := TBitmap.Create;
bmp.SetSize(DestIntfImg.Width, DestIntfImg.Height);
bmp.Canvas.Brush.Color := clWhite;
bmp.Canvas.FillRect(0, 0, 1, 1);
bmp.Handle := DestImgHandle;
bmp.MaskHandle := DestImgMaskHandle;
Picture.Graphic.Clear;
TPortableNetworkGraphic(Picture.Graphic).Assign(bmp);
Invalidate;
bmp.Free;
DestIntfImg.Free;
SrcIntfImg.Free;
end else
begin
Bmp := TBitmap.Create;
Bmp.PixelFormat := pf32bit;
Bmp.SetSize(w, h);
Bmp.Canvas.Brush.Color := clWhite;
Bmp.Canvas.FillRect(0, 0, w, h);
Bmp.Assign(Picture.Graphic);
SrcIntfImg.LoadFromBitmap(Bmp.Handle, Bmp.MaskHandle);
DestIntfImg.LoadFromBitmap(Bmp.Handle, Bmp.MaskHandle);
TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData);
DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle);
Bmp.Handle := DestImgHandle;
Bmp.MaskHandle := DestImgMaskHandle;
Picture.Graphic.Clear;
if Picture.Graphic is TJpegImage then
TJpegImage(Picture.Graphic).Assign(Bmp)
else if Picture.Graphic is Graphics.TBitmap then
Picture.Bitmap.Assign(Bmp);
Invalidate;
Bmp.Free;
SrcIntfImg.Free;
DestIntfImg.Free;
end;
end; end;
end;
end; end;
{ Procedure to actually decide what should be the rotation in conjuction with the { Procedure to actually decide what should be the rotation in conjuction with the