View Issue Details

IDProjectCategoryView StatusLast Update
0030386FPCPatchpublic2016-07-18 20:33
ReporterNur Cholif MurtadhoAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.1.1Product Build 
Target Version4.0.0Fixed in Version3.1.1 
Summary0030386: Fix writing grayscale jpeg with TFPWriterJPEG
DescriptionThis patch should fix writing grayscale jpeg with TFPWriterJPEG
TagsNo tags attached.
Fixed in Revision34146
FPCOldBugId
FPCTarget
Attached Files
  • fpwritejpeg.pas.patch (1,599 bytes)
    Index: packages/fcl-image/src/fpwritejpeg.pas
    ===================================================================
    --- packages/fcl-image/src/fpwritejpeg.pas	(revision 34145)
    +++ packages/fcl-image/src/fpwritejpeg.pas	(working copy)
    @@ -44,7 +44,7 @@
         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 @@
       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 @@
         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;
    
    fpwritejpeg.pas.patch (1,599 bytes)

Activities

Nur Cholif Murtadho

2016-07-18 19:35

reporter  

fpwritejpeg.pas.patch (1,599 bytes)
Index: packages/fcl-image/src/fpwritejpeg.pas
===================================================================
--- packages/fcl-image/src/fpwritejpeg.pas	(revision 34145)
+++ packages/fcl-image/src/fpwritejpeg.pas	(working copy)
@@ -44,7 +44,7 @@
     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 @@
   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 @@
     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;
fpwritejpeg.pas.patch (1,599 bytes)

Michael Van Canneyt

2016-07-18 20:33

administrator   ~0093761

Applied the patch, thank you very much!

Issue History

Date Modified Username Field Change
2016-07-18 19:35 Nur Cholif Murtadho New Issue
2016-07-18 19:35 Nur Cholif Murtadho File Added: fpwritejpeg.pas.patch
2016-07-18 20:30 Michael Van Canneyt Assigned To => Michael Van Canneyt
2016-07-18 20:30 Michael Van Canneyt Status new => assigned
2016-07-18 20:33 Michael Van Canneyt Fixed in Revision => 34146
2016-07-18 20:33 Michael Van Canneyt Note Added: 0093761
2016-07-18 20:33 Michael Van Canneyt Status assigned => resolved
2016-07-18 20:33 Michael Van Canneyt Fixed in Version => 3.1.1
2016-07-18 20:33 Michael Van Canneyt Resolution open => fixed
2016-07-18 20:33 Michael Van Canneyt Target Version => 4.0.0