ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Is Known Image File By Content?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

864 Posts

Posted - Feb 12 2023 :  04:46:48  Show Profile  Reply
I wrote this function to save me from trying in vain to load false DICOM files with the *.DIC extension, as this extension is also a popular extension for DICTIONARY files:

function IsKnownImageFileByContent(const AFile: string): Boolean;
{ checks the CONTENT of the passed file, if it is really a known image file }
begin
  Result := False;
  var ThisContentFormat := iexBitmaps.FindFileFormat(AFile, ffContentOnly);
  if ThisContentFormat <> hyieutils.ioUnknown then
    Result := True;
end;


Question: is there a better (i.e., more efficient or shorter) function for this purpose in the ImageEn library?

xequte

38222 Posts

Posted - Feb 12 2023 :  14:45:30  Show Profile  Reply
Hi Peter

ImageEn has "Try" methods for all formats, where it attempts to recognize the format based on factors, such as the Magic String. For DICOM files, this is "DICM". So ImageEn can quickly recognize any file that starts with DICM as a dicom file.

Unfortunately not all DICOM files include this magic string ("Implicit Dicom"), so even though ImageEn can load them (e.g. using ImageEnView1.IO.LoadFromFileDicom) it cannot recognize them as dicom other than by the file extension.

So, I find the best method is to use ImageEnView1.IO.LoadFromFile(); with the bCheckUnknown parameter as true (which is the default).
With this, the file extension will be used to determine the file type and it will be loaded. If loading fails because the extension is unknown or incorrect, then the content is examined to guess its format. This gives the fastest loading, while still coping the few files with invalid extensions.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

864 Posts

Posted - Feb 12 2023 :  15:23:13  Show Profile  Reply
Meanwhile, I use the IsKnownImageFileByContent function for all kinds of image file formats inside a complex search procedure where several thousand files are checked with this function to avoid false positives, so I declared it as inline to make it faster. It is still amazingly fast, even when processing thousands of files.

Can I consider this function as "rock-solid" and reliable for ALL types of image file formats recognized by ImageEn?
Go to Top of Page

xequte

38222 Posts

Posted - Feb 13 2023 :  16:32:28  Show Profile  Reply
Hi Peter

If if returns true, then that format is almost certainly supported (assuming the file is not corrupt), but if it returns False, it still might be a supported format, but it is not clear from its content (we won't know for sure unless loading by explicitly passing a file type or using the file extension). These types are generally DICOM or RAW.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: