瀏覽代碼

revs: 34146,34465,34692,34693

git-svn-id: branches/fixes_3_0@36004 -
marco 8 年之前
父節點
當前提交
604228e495
共有 3 個文件被更改,包括 29 次插入11 次删除
  1. 14 6
      packages/fcl-image/examples/drawing.pp
  2. 1 1
      packages/fcl-image/src/fpreadjpeg.pas
  3. 14 4
      packages/fcl-image/src/fpwritejpeg.pas

+ 14 - 6
packages/fcl-image/examples/drawing.pp

@@ -15,6 +15,7 @@ var canvas : TFPcustomCAnvas;
     reader : TFPCustomImageReader;
     f : TFreeTypeFont;
 begin
+  f:=Nil;
   image := TFPMemoryImage.Create (100,100);
   ci := TFPMemoryImage.Create (20,20);
   Canvas := TFPImageCanvas.Create (image);
@@ -31,6 +32,8 @@ begin
 //    ci.LoadFromFile ('test.png', reader);
     with Canvas as TFPImageCanvas do
       begin
+      brush.FPcolor:=colwhite;
+      brush.style:=bsSolid;
       pen.mode := pmCopy;
       pen.style := psSolid;
       pen.width := 1;
@@ -73,19 +76,24 @@ begin
 
       InitEngine;
       F:=TFreeTypeFont.Create;
-      F.Angle:=0.15;
+      F.Angle:=StrToFloatDef(ParamStr(1),0);
       Font:=F;
-//      Font.Name:='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
-      Font.Name:='/home/michael/Documents/arial.ttf';
+{$IFDEF UNIX}      
+      Font.Name:='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
+{$ELSE}      
+      // On windows, this should be present
+      Font.Name:='arial.ttf';
+{$ENDIF}
       Font.Size:=10;
       Font.FPColor:=colWhite;
-//      Font.Orientation:=900;
+//      Font.Orientation:=StrToIntDef(ParamStr(1),0);
       
-      Canvas.TextOut(10,90,'o');
+      Canvas.TextOut(10,90,'abc');
       end;
-      writeln ('Saving to inspect !');
+      writeln ('Saving to "DrawTest.png" for inspection !');
     image.SaveToFile ('DrawTest.png', writer);
   finally
+    F.Free;
     Canvas.Free;
     image.Free;
     writer.Free;

+ 1 - 1
packages/fcl-image/src/fpreadjpeg.pas

@@ -211,7 +211,7 @@ var
     if (FInfo.out_color_space = JCS_GRAYSCALE) then 
       begin
       FInfo.quantize_colors := True;
-      FInfo.desired_number_of_colors := 236;
+      FInfo.desired_number_of_colors := 256;
       end;
 
     if FPerformance = jpBestSpeed then 

+ 14 - 4
packages/fcl-image/src/fpwritejpeg.pas

@@ -44,7 +44,7 @@ type
     destructor Destroy; override;
     property CompressionQuality: TFPJPEGCompressionQuality read FQuality write FQuality;
     property ProgressiveEncoding: boolean read FProgressiveEncoding write FProgressiveEncoding;
-    property GrayScale: boolean read FGrayscale;
+    property GrayScale: boolean read FGrayscale write FGrayScale;
   end;
 
 implementation
@@ -125,10 +125,16 @@ var
   begin
     FInfo.image_width := Img.Width;
     FInfo.image_height := Img.Height;
-    FInfo.input_components := 3; // RGB has 3 components
-    FInfo.in_color_space := JCS_RGB;
     if FGrayscale then
-      jpeg_set_colorspace(@FInfo, JCS_GRAYSCALE);
+    begin
+      FInfo.input_components := 1;
+      FInfo.in_color_space := JCS_GRAYSCALE;
+    end
+    else
+    begin
+      FInfo.input_components := 3; // RGB has 3 components
+      FInfo.in_color_space := JCS_RGB;
+    end;
 
     jpeg_set_defaults(@FInfo);
     jpeg_set_quality(@FInfo, FQuality, True);
@@ -157,6 +163,10 @@ var
     try
       y:=0;
       while (FInfo.next_scanline < FInfo.image_height) do begin
+        if FGrayscale then
+        for x:=0 to FInfo.image_width-1 do
+          SampRow^[x]:=CalculateGray(Img.Colors[x,y]) shr 8
+        else
         for x:=0 to FInfo.image_width-1 do begin
           Color:=Img.Colors[x,y];
           SampRow^[x*3+0]:=Color.Red shr 8;