View Issue Details

IDProjectCategoryView StatusLast Update
0033955FPCFCLpublic2018-07-09 14:08
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033955: fcl-image: introduce TFPCustomImage.FindHandlerFromStream
DescriptionThe following patch adds 2 methods:
TFPCustomImage.FindHandlerFromStream
TFPCustomImage.FindReaderFromStream

They are equivalents to FindHandlerFromExtension/FindReaderFromExtension but they are used when no filename/extension is known and the image handler has to be determined from the actual stream.
TagsNo tags attached.
Fixed in Revision39416
FPCOldBugId
FPCTarget
Attached Files
  • fpimage-FindHandlerFromStream-01.patch (2,216 bytes)
    Index: packages/fcl-image/src/fpimage.inc
    ===================================================================
    --- packages/fcl-image/src/fpimage.inc	(revision 39414)
    +++ packages/fcl-image/src/fpimage.inc	(working copy)
    @@ -290,6 +290,32 @@
       Result := nil;
     end;
     
    +class function TFPCustomImage.FindHandlerFromStream(Str: TStream): TIHData;
    +var r : integer;
    +    p: Int64;
    +    reader: TFPCustomImageReader;
    +begin
    +  r := ImageHandlers.Count-1;
    +  p := Str.Position;
    +  while (r >= 0) do
    +    begin
    +    Result := ImageHandlers.GetData(r);
    +    if Result.Reader<>nil then
    +      begin
    +      reader := Result.Reader.Create;
    +      try
    +        if reader.CheckContents(Str) then
    +          Exit;
    +      finally
    +        reader.free;
    +        Str.Position := p;
    +      end;
    +      end;
    +    dec (r);
    +    end;
    +  Result := nil;
    +end;
    +
     class function TFPCustomImage.FindReaderFromExtension(const extension: String
       ): TFPCustomImageReaderClass;
     var d : TIHData;
    @@ -307,6 +333,17 @@
       Result := FindReaderFromExtension(ExtractFileExt(filename));
     end;
     
    +class function TFPCustomImage.FindReaderFromStream(
    +  Str: TStream): TFPCustomImageReaderClass;
    +var d : TIHData;
    +begin
    +  d := FindHandlerFromStream(Str);
    +  if d<>nil then
    +    Result := d.FReader
    +  else
    +    Result := nil;
    +end;
    +
     class function TFPCustomImage.FindWriterFromExtension(const extension: String
       ): TFPCustomImageWriterClass;
     var d : TIHData;
    Index: packages/fcl-image/src/fpimage.pp
    ===================================================================
    --- packages/fcl-image/src/fpimage.pp	(revision 39414)
    +++ packages/fcl-image/src/fpimage.pp	(working copy)
    @@ -129,6 +129,8 @@
           destructor destroy; override;
           procedure Assign(Source: TPersistent); override;
           // Image handlers
    +      class function FindHandlerFromStream(Str:TStream): TIHData;
    +      class function FindReaderFromStream(Str:TStream): TFPCustomImageReaderClass;
           class function FindHandlerFromExtension(extension:String): TIHData;
           class function FindReaderFromFileName(const filename:String): TFPCustomImageReaderClass;
           class function FindReaderFromExtension(const extension:String): TFPCustomImageReaderClass;
    

Activities

Ondrej Pokorny

2018-07-08 19:54

developer  

fpimage-FindHandlerFromStream-01.patch (2,216 bytes)
Index: packages/fcl-image/src/fpimage.inc
===================================================================
--- packages/fcl-image/src/fpimage.inc	(revision 39414)
+++ packages/fcl-image/src/fpimage.inc	(working copy)
@@ -290,6 +290,32 @@
   Result := nil;
 end;
 
+class function TFPCustomImage.FindHandlerFromStream(Str: TStream): TIHData;
+var r : integer;
+    p: Int64;
+    reader: TFPCustomImageReader;
+begin
+  r := ImageHandlers.Count-1;
+  p := Str.Position;
+  while (r >= 0) do
+    begin
+    Result := ImageHandlers.GetData(r);
+    if Result.Reader<>nil then
+      begin
+      reader := Result.Reader.Create;
+      try
+        if reader.CheckContents(Str) then
+          Exit;
+      finally
+        reader.free;
+        Str.Position := p;
+      end;
+      end;
+    dec (r);
+    end;
+  Result := nil;
+end;
+
 class function TFPCustomImage.FindReaderFromExtension(const extension: String
   ): TFPCustomImageReaderClass;
 var d : TIHData;
@@ -307,6 +333,17 @@
   Result := FindReaderFromExtension(ExtractFileExt(filename));
 end;
 
+class function TFPCustomImage.FindReaderFromStream(
+  Str: TStream): TFPCustomImageReaderClass;
+var d : TIHData;
+begin
+  d := FindHandlerFromStream(Str);
+  if d<>nil then
+    Result := d.FReader
+  else
+    Result := nil;
+end;
+
 class function TFPCustomImage.FindWriterFromExtension(const extension: String
   ): TFPCustomImageWriterClass;
 var d : TIHData;
Index: packages/fcl-image/src/fpimage.pp
===================================================================
--- packages/fcl-image/src/fpimage.pp	(revision 39414)
+++ packages/fcl-image/src/fpimage.pp	(working copy)
@@ -129,6 +129,8 @@
       destructor destroy; override;
       procedure Assign(Source: TPersistent); override;
       // Image handlers
+      class function FindHandlerFromStream(Str:TStream): TIHData;
+      class function FindReaderFromStream(Str:TStream): TFPCustomImageReaderClass;
       class function FindHandlerFromExtension(extension:String): TIHData;
       class function FindReaderFromFileName(const filename:String): TFPCustomImageReaderClass;
       class function FindReaderFromExtension(const extension:String): TFPCustomImageReaderClass;

Michael Van Canneyt

2018-07-09 13:29

administrator   ~0109311

Applied, thank you very much!

Ondrej Pokorny

2018-07-09 14:08

developer   ~0109314

Thank you!

Issue History

Date Modified Username Field Change
2018-07-08 19:54 Ondrej Pokorny New Issue
2018-07-08 19:54 Ondrej Pokorny File Added: fpimage-FindHandlerFromStream-01.patch
2018-07-08 21:10 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-07-08 21:10 Michael Van Canneyt Status new => assigned
2018-07-09 13:29 Michael Van Canneyt Fixed in Revision => 39416
2018-07-09 13:29 Michael Van Canneyt Note Added: 0109311
2018-07-09 13:29 Michael Van Canneyt Status assigned => resolved
2018-07-09 13:29 Michael Van Canneyt Fixed in Version => 3.1.1
2018-07-09 13:29 Michael Van Canneyt Resolution open => fixed
2018-07-09 13:29 Michael Van Canneyt Target Version => 3.2.0
2018-07-09 14:08 Ondrej Pokorny Note Added: 0109314
2018-07-09 14:08 Ondrej Pokorny Status resolved => closed