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
 TImageEnProc.CalcImageNumColors Issue
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

934 Posts

Posted - Apr 28 2024 :  07:08:30  Show Profile  Reply
The attached small test project demonstrates an issue with TImageEnProc.CalcImageNumColors

attach/PeterPanino/202442865416_IssueCalcNumColors.zip
77.11 KB

ImageEnView1.Proc.CalcImageNumColors();
creates an error if a non-image-layer exists:



To prevent this error, a current layer must explicitly be declared:

procedure TForm1.ButtonCalcNumColorsClick(Sender: TObject);
begin
  // This is required to avoid an error if a non-image-layer exists:
  ImageEnView1.LayersCurrent := 0;
  // Suggestion: This should be done automatically in ImageEnView1.Proc.CalcImageNumColors()
  // Or at least, there should be a Layer parameter that defaults to 0:
  // TImageEnProc.CalcImageNumColors(ALayer: Integer = 0)

  var n := ImageEnView1.Proc.CalcImageNumColors();
  Self.Caption := IntToStr(n) + ' Colors';
end;


My suggestion: When attached to a TImageEnView, TImageEnProc.CalcImageNumColors should act on layer 0 per default.

Alternatively, there should be a Layer parameter that defaults to 0:

TImageEnProc.CalcImageNumColors(ALayer: Integer = 0)


What do you think?

xequte

38654 Posts

Posted - Apr 28 2024 :  20:00:20  Show Profile  Reply
Hi Peter

This will occur with any TImageEnProc method that requires a bitmap.

The question is what should TImageEnProc do when a method is called when there is not an active bitmap layer. I don't think we should presume what the user wants in this situation.

Maybe they do want a count of layers in the background image, or maybe they want a count of images in the current layer (unaware that the operation is not available for non-image layers).

I think it is better to return an error so that the developer knows the code is not working as they anticipated, rather than silently return a result that *seems valid*, but is not (developer does not know the count returned is for layer 0, rather than the current layer).

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