Hello,

Is there a technical reason why in packages/fcl-image/src/fpreadjpeg.pas the scale option is commented / not implemented?

I've changed that unit for my purpose (see attachment. I hope the patch is valid, I don't have a svn fpc, so it's hand edited).

I have to create thumbnail images and found, that pre-scaling via fpreadjpeg.pas makes loading the images a lot faster.
Of course resampling to the final size is faster too.

The idea of the attached code is, to set MinWidth/MinHeight to the size of the desired thumbnail. The image is pre-shrunk this way (still always bigger than thumbnail) and can be resampled afterwards via stretch draw.

Any problems to expect?

Thank you
Best regards
Theo
Index: packages/fcl-image/src/fpreadjpeg.pas
===================================================================
--- packages/fcl-image/src/fpreadjpeg.pas	(Revision 13963)
+++ packages/fcl-image/src/fpreadjpeg.pas	(Arbeitskopie)
@@ -48,6 +51,8 @@
   TFPReaderJPEG = class(TFPCustomImageReader)
   private
     FSmoothing: boolean;
+    FMinHeight:integer;
+    FMinWidth:integer;
     FWidth: Integer;
     FHeight: Integer;
     FGrayscale: boolean;
@@ -69,6 +74,9 @@
     property ProgressiveEncoding: boolean read FProgressiveEncoding;
     property Smoothing: boolean read FSmoothing write SetSmoothing;
     property Performance: TJPEGReadPerformance read FPerformance write SetPerformance;
+    property  Scale: TJPEGScale read FScale write FScale;
+    property MinWidth:integer read FMinWidth write FMinWidth;
+    property MinHeight:integer read FMinHeight write FMinHeight;
   end;
 
 implementation
@@ -177,9 +185,28 @@
   end;
 
   procedure InitReadingPixels;
+  var d1,d2:integer;
+
+    function DToScale(inp:integer):TJPEGScale;
+    begin
+      if inp>7 then Result:=jsEighth else
+      if inp>3 then Result:=jsQuarter else
+      if inp>1 then Result:=jsHalf else
+      Result:=jsFullSize;
+    end;
+
   begin
     FInfo.scale_num := 1;
-    FInfo.scale_denom := 1;// shl Byte(FScale);
+
+    if (FMinWidth>0) and (FMinHeight>0) then
+    if (FInfo.image_width>FMinWidth) or (FInfo.image_height>FMinHeight) then
+    begin
+     d1:=Round((FInfo.image_width / FMinWidth)-0.5);
+     d2:=Round((FInfo.image_height /  FMinHeight)-0.5);
+     if d1>d2 then fScale:=DToScale(d2) else fScale:=DtoScale(d1);
+    end;
+
+    FInfo.scale_denom :=1 shl Byte(FScale); //1
     FInfo.do_block_smoothing := FSmoothing;
 
     if FGrayscale then FInfo.out_color_space := JCS_GRAYSCALE;
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to