|
@@ -119,6 +119,7 @@ type
|
|
|
lbOptions: TLabel;
|
|
lbOptions: TLabel;
|
|
|
lbCompression: TLabel;
|
|
lbCompression: TLabel;
|
|
|
lbOptions1: TLabel;
|
|
lbOptions1: TLabel;
|
|
|
|
|
+ lbFormat: TLabel;
|
|
|
OpenCropList: TOpenDialog;
|
|
OpenCropList: TOpenDialog;
|
|
|
OpenPictureDialog: TOpenPictureDialog;
|
|
OpenPictureDialog: TOpenPictureDialog;
|
|
|
rgAspect: TRadioGroup;
|
|
rgAspect: TRadioGroup;
|
|
@@ -132,6 +133,10 @@ type
|
|
|
btZDown: TSpeedButton;
|
|
btZDown: TSpeedButton;
|
|
|
btZUp: TSpeedButton;
|
|
btZUp: TSpeedButton;
|
|
|
btCropDuplicateOp: TSpeedButton;
|
|
btCropDuplicateOp: TSpeedButton;
|
|
|
|
|
+ procedure BGRAImageManipulationBitmapLoadAfter(Sender: TBGRAImageManipulation; AStream: TStream;
|
|
|
|
|
+ AFormat: TBGRAImageFormat; AHandler: TFPCustomImageReader; AOptions: TBGRALoadingOptions);
|
|
|
|
|
+ procedure BGRAImageManipulationBitmapSaveBefore(Sender: TBGRAImageManipulation; AStream: TStream;
|
|
|
|
|
+ AFormat: TBGRAImageFormat; AHandler: TFPCustomImageWriter);
|
|
|
procedure btCFlipHLeftClick(Sender: TObject);
|
|
procedure btCFlipHLeftClick(Sender: TObject);
|
|
|
procedure btCFlipHRightClick(Sender: TObject);
|
|
procedure btCFlipHRightClick(Sender: TObject);
|
|
|
procedure btCFlipVDownClick(Sender: TObject);
|
|
procedure btCFlipVDownClick(Sender: TObject);
|
|
@@ -180,6 +185,10 @@ type
|
|
|
lastNewBoxNum :Word;
|
|
lastNewBoxNum :Word;
|
|
|
changingAspect, closing,
|
|
changingAspect, closing,
|
|
|
inFillBoxUI :Boolean;
|
|
inFillBoxUI :Boolean;
|
|
|
|
|
+ sourceFormat,
|
|
|
|
|
+ destFormat: TBGRAImageFormat;
|
|
|
|
|
+
|
|
|
|
|
+ jpgGray: Boolean;
|
|
|
|
|
|
|
|
function GetCurrentCropArea: TCropArea;
|
|
function GetCurrentCropArea: TCropArea;
|
|
|
procedure FillBoxUI(ABox :TCropArea);
|
|
procedure FillBoxUI(ABox :TCropArea);
|
|
@@ -196,7 +205,7 @@ implementation
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
-//uses BGRAWriteBMP, BGRAReadWriteConfig;
|
|
|
|
|
|
|
+uses UniversalDrawer, BGRAReadJpeg, BGRAWriteJpeg;
|
|
|
|
|
|
|
|
const
|
|
const
|
|
|
ResUnitStr :array[TResolutionUnit] of String = ('ruNone', 'ruPixelsPerInch', 'ruPixelsPerCentimeter');
|
|
ResUnitStr :array[TResolutionUnit] of String = ('ruNone', 'ruPixelsPerInch', 'ruPixelsPerCentimeter');
|
|
@@ -207,20 +216,14 @@ procedure TFormBGRAImageManipulationDemo.btnOpenPictureClick(Sender: TObject);
|
|
|
var
|
|
var
|
|
|
Bitmap: TBGRABitmap;
|
|
Bitmap: TBGRABitmap;
|
|
|
test:Integer;
|
|
test:Integer;
|
|
|
-// reader:TFPCustomImageReader;
|
|
|
|
|
|
|
+ tt:TPicture;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
|
// To put a new image in the component, you will simply need execute open
|
|
// To put a new image in the component, you will simply need execute open
|
|
|
// picture dialog to locate an image...
|
|
// picture dialog to locate an image...
|
|
|
if OpenPictureDialog.Execute then
|
|
if OpenPictureDialog.Execute then
|
|
|
begin
|
|
begin
|
|
|
-(* // ...and create a new TBGRABitmap and load to it
|
|
|
|
|
- Bitmap := TBGRABitmap.Create;
|
|
|
|
|
- Bitmap.LoadFromFile(OpenPictureDialog.FileName);
|
|
|
|
|
- // Finally, associate the image into component
|
|
|
|
|
- BGRAImageManipulation.Bitmap := Bitmap;
|
|
|
|
|
- Bitmap.Free;
|
|
|
|
|
-*)
|
|
|
|
|
|
|
+ //...and load it
|
|
|
BGRAImageManipulation.LoadFromFile(OpenPictureDialog.FileName);
|
|
BGRAImageManipulation.LoadFromFile(OpenPictureDialog.FileName);
|
|
|
|
|
|
|
|
lbResolution.Caption:='Resolution : '+#13#10+' '+
|
|
lbResolution.Caption:='Resolution : '+#13#10+' '+
|
|
@@ -325,6 +328,49 @@ begin
|
|
|
end;
|
|
end;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
+procedure TFormBGRAImageManipulationDemo.BGRAImageManipulationBitmapLoadAfter(Sender: TBGRAImageManipulation;
|
|
|
|
|
+ AStream: TStream; AFormat: TBGRAImageFormat; AHandler: TFPCustomImageReader; AOptions: TBGRALoadingOptions);
|
|
|
|
|
+var
|
|
|
|
|
+ i: Integer;
|
|
|
|
|
+
|
|
|
|
|
+begin
|
|
|
|
|
+ sourceFormat:= AFormat;
|
|
|
|
|
+ //Store AHandler properties
|
|
|
|
|
+ case sourceFormat of
|
|
|
|
|
+ ifJpeg: begin
|
|
|
|
|
+ if (AHandler is TBGRAReaderJPEG) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ { #todo -oMaxM : only a Test, we should save the reader properties so we can use them in the writer, but how? }
|
|
|
|
|
+ jpgGray:= TBGRAReaderJPEG(AHandler).GrayScale;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+ //Find Loaded Format and select it
|
|
|
|
|
+ i:= cbSaveFormat.Items.IndexOfObject(TObject(PtrUInt(sourceFormat)));
|
|
|
|
|
+ if (i < 0) then i:= cbSaveFormat.Items.IndexOfObject(TObject(PtrUInt(ifJpeg)));
|
|
|
|
|
+
|
|
|
|
|
+ if (i >= 0) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ lbFormat.Caption:= 'Format: '+DefaultBGRAImageTypeNames[TBGRAImageFormat(PtrUint(cbSaveFormat.Items.Objects[i]))];
|
|
|
|
|
+ RateCompression.Enabled:= TBGRAImageFormat(PtrUint(cbSaveFormat.Items.Objects[i])) = ifJpeg;
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+end;
|
|
|
|
|
+
|
|
|
|
|
+procedure TFormBGRAImageManipulationDemo.BGRAImageManipulationBitmapSaveBefore(Sender: TBGRAImageManipulation;
|
|
|
|
|
+ AStream: TStream; AFormat: TBGRAImageFormat; AHandler: TFPCustomImageWriter);
|
|
|
|
|
+begin
|
|
|
|
|
+ if (AFormat = ifJpeg) and (RateCompression.Enabled) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ if (AHandler is TBGRAWriterJPEG) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ TBGRAWriterJPEG(AHandler).CompressionQuality:= RateCompression.Position;
|
|
|
|
|
+ TBGRAWriterJPEG(AHandler).GrayScale:= jpgGray;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+end;
|
|
|
|
|
+
|
|
|
procedure TFormBGRAImageManipulationDemo.btCFlipHRightClick(Sender: TObject);
|
|
procedure TFormBGRAImageManipulationDemo.btCFlipHRightClick(Sender: TObject);
|
|
|
var
|
|
var
|
|
|
CropArea :TCropArea;
|
|
CropArea :TCropArea;
|
|
@@ -410,6 +456,10 @@ end;
|
|
|
procedure TFormBGRAImageManipulationDemo.btnSavePictureClick(Sender: TObject);
|
|
procedure TFormBGRAImageManipulationDemo.btnSavePictureClick(Sender: TObject);
|
|
|
var
|
|
var
|
|
|
curBitmap :TBGRABitmap;
|
|
curBitmap :TBGRABitmap;
|
|
|
|
|
+ ext:String;
|
|
|
|
|
+ i,
|
|
|
|
|
+ selE:Integer;
|
|
|
|
|
+ destHandler: TFPCustomImageWriter;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
|
if SavePictureDialog.Execute then
|
|
if SavePictureDialog.Execute then
|
|
@@ -419,8 +469,37 @@ begin
|
|
|
then curBitmap :=BGRAImageManipulation.getBitmap(Nil, chkCopyProperties.Checked)
|
|
then curBitmap :=BGRAImageManipulation.getBitmap(Nil, chkCopyProperties.Checked)
|
|
|
else curBitmap :=BGRAImageManipulation.getResampledBitmap(Nil, chkCopyProperties.Checked);
|
|
else curBitmap :=BGRAImageManipulation.getResampledBitmap(Nil, chkCopyProperties.Checked);
|
|
|
|
|
|
|
|
- curBitmap.SaveToFile(SavePictureDialog.FileName);
|
|
|
|
|
|
|
+ selE:= cbSaveFormat.ItemIndex;
|
|
|
|
|
+ if (selE = 0)
|
|
|
|
|
+ then begin
|
|
|
|
|
+ //Same format as Input
|
|
|
|
|
+ destFormat:= sourceFormat;
|
|
|
|
|
+ end
|
|
|
|
|
+ else begin
|
|
|
|
|
+ destFormat:= TBGRAImageFormat(PtrUInt(cbSaveFormat.Items.Objects[selE]));
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+ destHandler:= TUniversalDrawer.CreateBGRAImageWriter(curBitmap, destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ if (destFormat = ifJpeg) and (RateCompression.Enabled) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ if (destHandler is TBGRAWriterJPEG) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ TBGRAWriterJPEG(destHandler).CompressionQuality:= RateCompression.Position;
|
|
|
|
|
+ TBGRAWriterJPEG(destHandler).GrayScale:= jpgGray;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+ ext:= SuggestImageExtension(destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ // This Save with Default Properties
|
|
|
|
|
+ //curBitmap.SaveToFile(SavePictureDialog.FileName+'.'+ext, destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ // This save with Stored Properties
|
|
|
|
|
+ curBitmap.SaveToFile(SavePictureDialog.FileName+'.'+ext, destHandler);
|
|
|
|
|
+
|
|
|
finally
|
|
finally
|
|
|
|
|
+ destHandler.Free;
|
|
|
curBitmap.Free;
|
|
curBitmap.Free;
|
|
|
end;
|
|
end;
|
|
|
end;
|
|
end;
|
|
@@ -429,13 +508,50 @@ end;
|
|
|
procedure TFormBGRAImageManipulationDemo.SaveCallBack(Bitmap: TBGRABitmap; CropArea: TCropArea; AUserData: Integer);
|
|
procedure TFormBGRAImageManipulationDemo.SaveCallBack(Bitmap: TBGRABitmap; CropArea: TCropArea; AUserData: Integer);
|
|
|
var
|
|
var
|
|
|
ext:String;
|
|
ext:String;
|
|
|
- i:Integer;
|
|
|
|
|
|
|
+ i,
|
|
|
|
|
+ selE:Integer;
|
|
|
|
|
+ destHandler: TFPCustomImageWriter;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
|
- ext:=ImageHandlers.Extensions[cbSaveFormat.Items[cbSaveFormat.ItemIndex]];
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ selE:= cbSaveFormat.ItemIndex;
|
|
|
|
|
+ if (selE = 0)
|
|
|
|
|
+ then begin
|
|
|
|
|
+ //Same format as Input
|
|
|
|
|
+ destFormat:= sourceFormat;
|
|
|
|
|
+ end
|
|
|
|
|
+ else begin
|
|
|
|
|
+ destFormat:= TBGRAImageFormat(PtrUInt(cbSaveFormat.Items.Objects[selE]));
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+ destHandler:= TUniversalDrawer.CreateBGRAImageWriter(Bitmap, destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ if (destFormat = ifJpeg) and (RateCompression.Enabled) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ if (destHandler is TBGRAWriterJPEG) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ TBGRAWriterJPEG(destHandler).CompressionQuality:= RateCompression.Position;
|
|
|
|
|
+ TBGRAWriterJPEG(destHandler).GrayScale:= jpgGray;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+
|
|
|
|
|
+ ext:= SuggestImageExtension(destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ // This Save with Default Properties
|
|
|
|
|
+ //Bitmap.SaveToFile(SelectDirectoryDialog1.FileName+DirectorySeparator+CropArea.Name+'.'+ext, destFormat);
|
|
|
|
|
+
|
|
|
|
|
+ // This Save with Stored Properties
|
|
|
|
|
+ Bitmap.SaveToFile(SelectDirectoryDialog1.FileName+DirectorySeparator+CropArea.Name+'.'+ext, destHandler);
|
|
|
|
|
+
|
|
|
|
|
+ (* ext:=ImageHandlers.Extensions[cbSaveFormat.Items[selE]];
|
|
|
i :=Pos(';', ext);
|
|
i :=Pos(';', ext);
|
|
|
if (i>0) then ext :=Copy(ext, 1, i-1);
|
|
if (i>0) then ext :=Copy(ext, 1, i-1);
|
|
|
Bitmap.SaveToFile(SelectDirectoryDialog1.FileName+DirectorySeparator+CropArea.Name+'.'+ext);
|
|
Bitmap.SaveToFile(SelectDirectoryDialog1.FileName+DirectorySeparator+CropArea.Name+'.'+ext);
|
|
|
|
|
+*)
|
|
|
|
|
+
|
|
|
|
|
+ finally
|
|
|
|
|
+ destHandler.Free;
|
|
|
|
|
+ end;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
procedure TFormBGRAImageManipulationDemo.UpdateBoxList;
|
|
procedure TFormBGRAImageManipulationDemo.UpdateBoxList;
|
|
@@ -663,6 +779,7 @@ procedure TFormBGRAImageManipulationDemo.FormCreate(Sender: TObject);
|
|
|
var
|
|
var
|
|
|
i,j :Integer;
|
|
i,j :Integer;
|
|
|
t,e:String;
|
|
t,e:String;
|
|
|
|
|
+ iFormat:TBGRAImageFormat;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
|
closing :=False;
|
|
closing :=False;
|
|
@@ -671,6 +788,10 @@ begin
|
|
|
lastNewBoxNum :=0;
|
|
lastNewBoxNum :=0;
|
|
|
TStringList(cbBoxList.Items).OwnsObjects:=False;
|
|
TStringList(cbBoxList.Items).OwnsObjects:=False;
|
|
|
j:=0;
|
|
j:=0;
|
|
|
|
|
+
|
|
|
|
|
+ cbSaveFormat.Items.Add('Same As Input');
|
|
|
|
|
+
|
|
|
|
|
+ (* fpc Formats
|
|
|
for i :=0 to ImageHandlers.Count-1 do
|
|
for i :=0 to ImageHandlers.Count-1 do
|
|
|
begin
|
|
begin
|
|
|
t :=ImageHandlers.TypeNames[i];
|
|
t :=ImageHandlers.TypeNames[i];
|
|
@@ -678,10 +799,23 @@ begin
|
|
|
if (ImageHandlers.ImageWriter[t]<>nil) then
|
|
if (ImageHandlers.ImageWriter[t]<>nil) then
|
|
|
begin
|
|
begin
|
|
|
cbSaveFormat.Items.Add(t);
|
|
cbSaveFormat.Items.Add(t);
|
|
|
- if (Pos('jpg', e)>0) then j:=i;
|
|
|
|
|
|
|
+ if (Pos('jpg', e)>0) then j:=i+1;
|
|
|
|
|
+ end;
|
|
|
|
|
+ end;
|
|
|
|
|
+ *)
|
|
|
|
|
+
|
|
|
|
|
+ //BGRA Formats
|
|
|
|
|
+ for iFormat:= low(TBGRAImageFormat) to high(TBGRAImageFormat) do
|
|
|
|
|
+ begin
|
|
|
|
|
+ if (DefaultBGRAImageWriter[iFormat]<>nil) then
|
|
|
|
|
+ begin
|
|
|
|
|
+ t:= DefaultBGRAImageTypeNames[iFormat];
|
|
|
|
|
+ e:= DefaultBGRAImageTypeExts[iFormat];
|
|
|
|
|
+ i:= cbSaveFormat.Items.AddObject(t+' ('+e+')', TObject(PtrUInt(iFormat)));
|
|
|
|
|
+ if (iFormat = ifJpeg) then j:=i; //if (Pos('jpg', e)>0)
|
|
|
end;
|
|
end;
|
|
|
end;
|
|
end;
|
|
|
- cbSaveFormat.ItemIndex:=j-1;
|
|
|
|
|
|
|
+ cbSaveFormat.ItemIndex:=0;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
procedure TFormBGRAImageManipulationDemo.rgAspectSelectionChanged(Sender: TObject);
|
|
procedure TFormBGRAImageManipulationDemo.rgAspectSelectionChanged(Sender: TObject);
|