ADD: Patch that adding rotate image command to Viewer by Rustem (with some optimizations)

This commit is contained in:
Alexander Koblov 2010-04-06 18:10:24 +00:00
commit 558d9b1242
3 changed files with 173 additions and 61 deletions

View file

@ -1,13 +1,13 @@
object frmViewer: TfrmViewer
Left = 120
Height = 600
Top = 120
Left = 404
Height = 583
Top = 119
Width = 856
HorzScrollBar.Page = 951
VertScrollBar.Page = 491
ActiveControl = pnlLister
Caption = 'Viewer'
ClientHeight = 570
ClientHeight = 563
ClientWidth = 856
Constraints.MinHeight = 100
Constraints.MinWidth = 200
@ -63,7 +63,7 @@ object frmViewer: TfrmViewer
LCLVersion = '0.9.29'
object pnlLister: TPanel
Left = 0
Height = 548
Height = 540
Top = 0
Width = 856
Align = alClient
@ -73,8 +73,8 @@ object frmViewer: TfrmViewer
end
object Status: TStatusBar
Left = 0
Height = 22
Top = 548
Height = 23
Top = 540
Width = 856
Panels = <
item
@ -96,17 +96,17 @@ object frmViewer: TfrmViewer
end
object pnlText: TPanel
Left = 0
Height = 548
Height = 540
Top = 0
Width = 856
Align = alClient
BevelOuter = bvNone
ClientHeight = 548
ClientHeight = 540
ClientWidth = 856
TabOrder = 2
object ViewerControl: TViewerControl
Left = 0
Height = 548
Height = 540
Top = 0
Width = 856
OnPositionChanged = ViewerPositionChanged
@ -116,30 +116,32 @@ object frmViewer: TfrmViewer
end
object pnlImage: TPanel
Left = 0
Height = 548
Height = 540
Top = 0
Width = 856
Align = alClient
BevelOuter = bvNone
ClientHeight = 548
ClientHeight = 540
ClientWidth = 856
TabOrder = 3
object sboxImage: TScrollBox
Left = 0
Height = 548
Height = 540
Top = 0
Width = 856
Align = alClient
ClientHeight = 526
ClientWidth = 852
ClientHeight = 519
ClientWidth = 835
Color = clBlack
ParentColor = False
TabOrder = 0
TabStop = True
OnResize = sboxImageResize
object Image: TImage
Left = 0
Height = 464
Height = 553
Top = 0
Width = 946
Width = 852
AutoSize = True
Center = True
Proportional = True
@ -271,6 +273,25 @@ object frmViewer: TfrmViewer
Caption = 'Stretch'
OnClick = miStretchClick
end
object miRotate: TMenuItem
Caption = 'Rotate'
object mi90: TMenuItem
Caption = '+ 90'
OnClick = miRotateClick
end
object mi180: TMenuItem
Caption = '+ 180'
OnClick = miRotateClick
end
object mi270: TMenuItem
Caption = '- 90'
OnClick = miRotateClick
end
object miMirror: TMenuItem
Caption = 'Mirror'
OnClick = miRotateClick
end
end
end
object miAbout: TMenuItem
Caption = 'About'
@ -281,7 +302,7 @@ object frmViewer: TfrmViewer
end
end
object pmEditMenu: TPopupMenu
left = 126
left = 160
top = 8
object pmiCopy: TMenuItem
Caption = 'Copy To Clipboard'

View file

@ -1,31 +1,36 @@
TFRMVIEWER.CAPTION=Viewer
TFRMVIEWER.MIFILE.CAPTION=&File
TFRMVIEWER.MIPREV.CAPTION=&Previous
TFRMVIEWER.MINEXT.CAPTION=&Next
TFRMVIEWER.MIPRINT.CAPTION=Print...
TFRMVIEWER.MISEPARATOR.CAPTION=-
TFRMVIEWER.MIEXIT.CAPTION=E&xit
TFRMVIEWER.MIEDIT.CAPTION=&Edit
TFRMVIEWER.MICOPYTOCLIPBOARD.CAPTION=Copy To Clipboard
TFRMVIEWER.MISELECTALL.CAPTION=Select All
TFRMVIEWER.MIDIV3.CAPTION=-
TFRMVIEWER.MISEARCH.CAPTION=Search
TFRMVIEWER.MISEARCHNEXT.CAPTION=Search next
TFRMVIEWER.MISEARCHPREV.CAPTION=Search prev
TFRMVIEWER.MIVIEW.CAPTION=&View
TFRMVIEWER.MITEXT.CAPTION=Show as &Text
TFRMVIEWER.MIBIN.CAPTION=Show as &Bin
TFRMVIEWER.MIHEX.CAPTION=Show as &Hex
TFRMVIEWER.MIWRAPTEXT.CAPTION=Show as &Wrap text
TFRMVIEWER.MIDIV2.CAPTION=-
TFRMVIEWER.MIGRAPHICS.CAPTION=Graphics
TFRMVIEWER.MIDIV1.CAPTION=-
TFRMVIEWER.MIPLUGINS.CAPTION=Plugins
TFRMVIEWER.MIENCODING.CAPTION=En&coding
TFRMVIEWER.MIIMAGE.CAPTION=&Image
TFRMVIEWER.MISTRETCH.CAPTION=Stretch
TFRMVIEWER.MIABOUT.CAPTION=About
TFRMVIEWER.MIABOUT2.CAPTION=About Viewer...
TFRMVIEWER.PMICOPY.CAPTION=Copy To Clipboard
TFRMVIEWER.MIDIV5.CAPTION=-
TFRMVIEWER.PMISELECTALL.CAPTION=Select All
TFRMVIEWER.CAPTION=Viewer
TFRMVIEWER.MIFILE.CAPTION=&File
TFRMVIEWER.MIPREV.CAPTION=&Previous
TFRMVIEWER.MINEXT.CAPTION=&Next
TFRMVIEWER.MIPRINT.CAPTION=Print...
TFRMVIEWER.MISEPARATOR.CAPTION=-
TFRMVIEWER.MIEXIT.CAPTION=E&xit
TFRMVIEWER.MIEDIT.CAPTION=&Edit
TFRMVIEWER.MICOPYTOCLIPBOARD.CAPTION=Copy To Clipboard
TFRMVIEWER.MISELECTALL.CAPTION=Select All
TFRMVIEWER.MIDIV3.CAPTION=-
TFRMVIEWER.MISEARCH.CAPTION=Search
TFRMVIEWER.MISEARCHNEXT.CAPTION=Search next
TFRMVIEWER.MISEARCHPREV.CAPTION=Search prev
TFRMVIEWER.MIVIEW.CAPTION=&View
TFRMVIEWER.MITEXT.CAPTION=Show as &Text
TFRMVIEWER.MIBIN.CAPTION=Show as &Bin
TFRMVIEWER.MIHEX.CAPTION=Show as &Hex
TFRMVIEWER.MIWRAPTEXT.CAPTION=Show as &Wrap text
TFRMVIEWER.MIDIV2.CAPTION=-
TFRMVIEWER.MIGRAPHICS.CAPTION=Graphics
TFRMVIEWER.MIDIV1.CAPTION=-
TFRMVIEWER.MIPLUGINS.CAPTION=Plugins
TFRMVIEWER.MIENCODING.CAPTION=En&coding
TFRMVIEWER.MIIMAGE.CAPTION=&Image
TFRMVIEWER.MISTRETCH.CAPTION=Stretch
TFRMVIEWER.MIROTATE.CAPTION=Rotate
TFRMVIEWER.MI90.CAPTION=+ 90
TFRMVIEWER.MI180.CAPTION=+ 180
TFRMVIEWER.MI270.CAPTION=- 90
TFRMVIEWER.MIMIRROR.CAPTION=Mirror
TFRMVIEWER.MIABOUT.CAPTION=About
TFRMVIEWER.MIABOUT2.CAPTION=About Viewer...
TFRMVIEWER.PMICOPY.CAPTION=Copy To Clipboard
TFRMVIEWER.MIDIV5.CAPTION=-
TFRMVIEWER.PMISELECTALL.CAPTION=Select All

View file

@ -41,6 +41,11 @@ type
TfrmViewer = class(TForm)
Image: TImage;
miRotate: TMenuItem;
miMirror: TMenuItem;
mi270: TMenuItem;
mi180: TMenuItem;
mi90: TMenuItem;
miSearchPrev: TMenuItem;
miPrint: TMenuItem;
miSearchNext: TMenuItem;
@ -109,6 +114,7 @@ type
procedure miSelectAllClick(Sender: TObject);
procedure miChangeEncodingClick(Sender:TObject);
procedure ViewerPositionChanged(Sender:TObject);
procedure miRotateClick(Sender: TObject);
private
FileList: TStringList;
iActiveFile:Integer;
@ -147,7 +153,7 @@ procedure ShowViewer(const FilesToView:TStringList; const aFileSource: IFileSour
implementation
uses
uLng, uShowMsg, uGlobs, LCLType, LConvEncoding, uClassesEx, uFindMmap, uDCUtils;
IntfGraphics, uLng, uShowMsg, uGlobs, LCLType, LConvEncoding, uClassesEx, uFindMmap, uDCUtils;
const
// Status bar panels indexes.
@ -641,25 +647,105 @@ var
iScale: Integer;
begin
if Image.Stretch then
begin
Image.Width:= sboxImage.ClientWidth;
Image.Height:= sboxImage.ClientHeight;
// show image resolution and scale
sResolution:= IntToStr(Image.ClientWidth) + 'x' + IntToStr(Image.ClientHeight);
iScale:= (Image.ClientWidth * 100) div Image.Picture.Width;
Status.Panels[sbpCurrentResolution].Text:= Format(fmtImageInfo, [sResolution, IntToStr(iScale)]);
sResolution:= IntToStr(Image.Picture.Width) + 'x' + IntToStr(Image.Picture.Height);
Status.Panels[sbpFullResolution].Text:= Format(fmtImageInfo, [sResolution, '100']);
end
begin
Image.AutoSize := true;
if (Image.Picture.Width > sboxImage.ClientWidth) or (Image.Picture.Height > sboxImage.ClientHeight) then
begin
Image.Left:= 0;
Image.Top:= 0;
Image.AutoSize := false;
Image.Width:= sboxImage.ClientWidth;
Image.Height:= sboxImage.ClientHeight;
// show image resolution and scale
sResolution:= IntToStr(Image.ClientWidth) + 'x' + IntToStr(Image.ClientHeight);
iScale:= ((Image.ClientWidth * 100) div Image.Picture.Width+(Image.ClientHeight * 100) div Image.Picture.Height) div 2;
Status.Panels[sbpCurrentResolution].Text:= Format(fmtImageInfo, [sResolution, IntToStr(iScale)]);
sResolution:= IntToStr(Image.Picture.Width) + 'x' + IntToStr(Image.Picture.Height);
Status.Panels[sbpFullResolution].Text:= Format(fmtImageInfo, [sResolution, '100']);
end
else
begin
Image.Left:= (sboxImage.ClientWidth-Image.Picture.Width) div 2; //move image to center
Image.Top:= (sboxImage.ClientHeight-Image.Picture.Height) div 2;
sResolution:= IntToStr(Image.Picture.Width) + 'x' + IntToStr(Image.Picture.Height);
Status.Panels[sbpCurrentResolution].Text:= Format(fmtImageInfo, [sResolution, '100']);
Status.Panels[sbpFullResolution].Text:= Status.Panels[2].Text;
end;
end
else
begin
// show image resolution and scale
Image.Left:= 0;
Image.Top:= 0;
sResolution:= IntToStr(Image.Picture.Width) + 'x' + IntToStr(Image.Picture.Height);
Status.Panels[sbpCurrentResolution].Text:= Format(fmtImageInfo, [sResolution, '100']);
Status.Panels[sbpFullResolution].Text:= Status.Panels[2].Text;
end;
end;
// Try to rotate image
procedure TfrmViewer.miRotateClick(Sender: TObject);
var
x, y: Integer;
xWidth,
yHeight: Integer;
SourceImg: TLazIntfImage = nil;
TargetImg: TLazIntfImage = nil;
begin
TargetImg:= TLazIntfImage.Create(0, 0);
SourceImg:= Image.Picture.Bitmap.CreateIntfImage;
TargetImg.DataDescription:= SourceImg.DataDescription; // use the same image format
xWidth:= Image.Picture.Bitmap.Width - 1;
yHeight:= Image.Picture.Bitmap.Height - 1;
if Sender = mi180 then
begin
TargetImg.SetSize(xWidth + 1, yHeight + 1);
for y:= 0 to yHeight do
begin
for x:= 0 to xWidth do
begin
TargetImg.Colors[x, y]:= SourceImg.Colors[xWidth - x, yHeight - y];
end;
end;
end;
if Sender = mi270 then
begin
TargetImg.SetSize(yHeight + 1, xWidth + 1);
for y:= 0 to xWidth do
begin
for x:= 0 to yHeight do
begin
TargetImg.Colors[x, y]:= SourceImg.Colors[xWidth - y, x];
end;
end;
end;
if Sender = mi90 then
begin
TargetImg.SetSize(yHeight + 1, xWidth + 1);
for y:= 0 to xWidth do
begin
for x:= 0 to yHeight do
begin
TargetImg.Colors[x, y]:= SourceImg.Colors[y, yHeight - x];
end;
end;
end;
if Sender = miMirror then
begin
TargetImg.SetSize(xWidth + 1, yHeight + 1);
for y:= 0 to yHeight do
begin
for x:= 0 to xWidth do
begin
TargetImg.Colors[x, y]:= SourceImg.Colors[xWidth - x, y];
end;
end;
end;
Image.Picture.Bitmap.LoadFromIntfImage(TargetImg);
FreeThenNil(SourceImg);
FreeThenNil(TargetImg);
end;
procedure TfrmViewer.LoadGraphics(const sFileName:String);
var
sExt: String;
@ -852,4 +938,4 @@ end;
initialization
{$I fviewer.lrs}
end.
end.