Recent

Author Topic: How to get the complete graphic EXT supported?  (Read 1273 times)

jamie

  • Hero Member
  • *****
  • Posts: 6735
How to get the complete graphic EXT supported?
« on: June 08, 2024, 08:53:41 pm »
I would like the complete list supported of all registered file formats for TPicture/TGraphic as a string I can breakup.

I want to display to the user available types.

I know I can request a type but that would mean I then need to specify it, so why bother?

I simply need a complete delimited string of the extensions or descriptions without query each one.

The needed functions are not exposed from the Graphics unit.

I know I have done this before and can't remember how! it's a bitch getting old!  :o
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 1291
Re: How to get the complete graphic EXT supported?
« Reply #1 on: June 09, 2024, 03:17:21 am »
I would like the complete list supported of all registered file formats for TPicture/TGraphic as a string I can breakup.

I want to display to the user available types.

I know I can request a type but that would mean I then need to specify it, so why bother?

I simply need a complete delimited string of the extensions or descriptions without query each one.

Here's a couple of brute force routines:

Code: Pascal  [Select][+][-]
  1. // text prior to '|' is the description
  2. // text after '|' is the file extension list (case-insensitive)
  3. // use AList.DelimitedText to get a Filter-compatible value for dialogs
  4. procedure GetSupportedImages(AList: TStringList);
  5. begin
  6.   if (AList = Nil) then Exit;
  7.  
  8.   if (AList.Count > 0) then AList.Clear;
  9.   Alist.Options := [];
  10.   AList.Delimiter := '|';
  11.   Alist.QuoteChar := ' ';
  12.  
  13.   AList.Add('Cursor (*.cur)|*.cur');
  14.   AList.Add('Bitmap (*.bmp)|*.bmp');
  15.   {$IFDEF Windows}
  16.   AList.Add('Icon [Windows] (*.ico)|*.ico');
  17.   {$endif}
  18.   {$IFDEF Darwin}
  19.   AList.Add('Icon [macOS] (*.icns)|*.icns');
  20.   {$endif}
  21.   AList.Add('Portable Network Graphics (*.png)|*.png');
  22.   AList.Add('Pixmap (*.xpm)|*.xpm');
  23.   {$IFNDEF DisableLCLJPEG}
  24.   AList.Add('JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg');
  25.   {$ENDIF}
  26.   {$IFNDEF DisableLCLTIFF}
  27.   AList.Add('Tagged Image File Format (*.tif;*.tiff)|*.tif;*.tiff');
  28.   {$ENDIF}
  29.   {$IFNDEF DisableLCLGIF}
  30.   AList.Add('Graphics Interchange Format (*.gif)|*.gif');
  31.   {$ENDIF}
  32.   {$IFNDEF DisableLCLPNM}
  33.   AList.Add('Portable AnyMap Graphics (*.pnm)|*.pnm');
  34.   {$ENDIF}
  35. end;
  36.  
  37. // Filter-compatible value for dialogs
  38. function GetSupportedImagesString: String;
  39. begin
  40.   Result := 'Cursor (*.cur)|*.cur|Bitmap (*.bmp)|*.bmp';
  41.   {$IFDEF Windows}
  42.   Result += '|Icon [Windows] (*.ico)|*.ico';
  43.   {$endif}
  44.   {$IFDEF Darwin}
  45.   Result += '|Icon [macOS] (*.icns)|*.icns';
  46.   {$endif}
  47.   Result += '|Portable Network Graphics (*.png)|*.png';
  48.   Result += '|Pixmap (*.xpm)|*.xpm';
  49.   {$IFNDEF DisableLCLJPEG}
  50.   Result += '|JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg';
  51.   {$ENDIF}
  52.   {$IFNDEF DisableLCLTIFF}
  53.   Result += '|Tagged Image File Format (*.tif;*.tiff)|*.tif;*.tiff';
  54.   {$ENDIF}
  55.   {$IFNDEF DisableLCLGIF}
  56.   Result += '|Graphics Interchange Format (*.gif)|*.gif';
  57.   {$ENDIF}
  58.   {$IFNDEF DisableLCLPNM}
  59.   Result += '|Portable AnyMap Graphics (*.pnm)|*.pnm';
  60.   {$ENDIF}
  61. end;
  62.  

The needed functions are not exposed from the Graphics unit.
I know I have done this before and can't remember how! it's a bitch getting old!  :o

Welcome to the club... now get off my lawn. :)
« Last Edit: June 09, 2024, 03:26:13 am by dsiders »
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: How to get the complete graphic EXT supported?
« Reply #2 on: June 09, 2024, 03:06:30 pm »
That does not solve the problem at hand, it just displays the issue at hand.

  There is a function to register a file format, therefor a list of these classes is maintained. However, there is no function to enumerate these classes.

   It would be nice to Enumerate them so a list for the user can be populated because with the classes, you can obtain the needed data.

  A perfect example would be if someone decided to add a image format to the list and all you would need to do is recompile the app and that format will not be present.

 Currently, you need to query for a possible format and if that is the case then it's just a bunch of slop.
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 1291
Re: How to get the complete graphic EXT supported?
« Reply #3 on: June 09, 2024, 09:40:40 pm »
That does not solve the problem at hand, it just displays the issue at hand.

  There is a function to register a file format, therefor a list of these classes is maintained. However, there is no function to enumerate these classes.

   It would be nice to Enumerate them so a list for the user can be populated because with the classes, you can obtain the needed data.

  A perfect example would be if someone decided to add a image format to the list and all you would need to do is recompile the app and that format will not be present.

 Currently, you need to query for a possible format and if that is the case then it's just a bunch of slop.

I think we both missed the forest for the trees.

graphics.pp already has GraphicFilter() and GraphicFileMask() just like the Delphi VCL equivalents. The thing that is not obvious is that they return a complete list for all supported graphic types when the graphic class argument is TGraphic.

Code: Pascal  [Select][+][-]
  1. ShowMessage('Filter = '  + GraphicFilter(TGraphic));
  2. ShowMessage('File Masks = ' + GraphicFileMask(TGraphic));

Curiously, there is no equivalent to get graphic class descriptions alone. It's also missing in Delphi.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: How to get the complete graphic EXT supported?
« Reply #4 on: June 09, 2024, 10:35:46 pm »
ok, Using the TGraphic by itself is good enough.

There really should be a Enumerating Class list that is registered.
Quote
caption := GraphicFilter(TGraphic);

Shows me the complete list which I can work with.
I didn't see that documented that way for some reason?
Thanks.

The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 1291
Re: How to get the complete graphic EXT supported?
« Reply #5 on: June 09, 2024, 10:41:15 pm »
Quote
caption := GraphicFilter(TGraphic);

Shows me the complete list which I can work with.
I didn't see that documented that way for some reason?

No, you did not... and it's been added to my list. :)
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: How to get the complete graphic EXT supported?
« Reply #6 on: June 09, 2024, 11:31:09 pm »
here is a simple test project to show the classes and their extensions.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018