Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.48k stars 170 forks source link

cuda_tab_icons: low res icons (and low quality upscaling). #4579

Closed veksha closed 1 year ago

veksha commented 1 year ago

I learned from cuda_tab_icons code (not from "readme") that I can make tab icons bigger by just specifying size in icon_theme like this: (why no separate option, btw?)

image

as you can see, @Alexey-T. icons are low res, and upscaling quality is also bad. compare upscaling quality by the browser (more smooth):

image

also you can see from screenshot that hi res icons are available on the internet, so you can consider to update them to 48x48. (and lexer icons too ??)

look how clock icon will look if I swap it with hi res icon 48x48 (from here https://github.com/os-js/osjs-gnome-icons/)

image

veksha commented 1 year ago

on screenshots lexer icons are actually 16x16 upscaled. I need to explicitly set "icon_theme" to "vscode_material_24x24" and plugin will use higher quality icons for lexers.

image (on screenshot - "icon_theme": "vscode_material_24x24")

but what if I want to upscale it to 32x32? I can't do that. (it will upscale 16x16 to 32x32, not 24x24 to 32x32!)

image (on screenshot - "icon_theme": "vscode_material_32x32")

I suggest to make separate option for icons size and use it instead of guessing from folder name (theme name). and plugin must know where to look for largest icons and use only them.

veksha commented 1 year ago

I also tried to remove "vscode_16x16" theme by removing the folder with icons (hoping that plugin will use 24x24 only) but I get error:

Traceback (most recent call last):
  File "F:\MySSDPrograms\cudatext\py\cuda_tab_icons\__init__.py", line 53, in __init__
    self.icon_json_dict = json.loads(open(self.icon_json).read())
FileNotFoundError: [Errno 2] No such file or directory: 'F:\\MySSDPrograms\\cudatext\\data\\filetypeicons\\vscode_16x16\\icons.json'
veksha commented 1 year ago

forced plugin to use 24x24 and upscale to 32x32 by copying folder:

cudatext_FmVjtv20ia

as you can see upscaling from 24 to 32 looks better, but pixelated still. (can different upscale algorithm be selected in Lazarus?)

Alexey-T commented 1 year ago

(can different upscale algorithm be selected in Lazarus?)

IDK, seems no...

Alexey-T commented 1 year ago

the proper way is installing new filetypeicons from addons, and settings the new name. IDK how we can support upscaling.

veksha commented 1 year ago

IDK how we can support upscaling.

Can you use resample filtering that is implemented in bgrabitmap? see test proj: "bgrabitmap\test\bgraaggtest\image_filters2.lpi"

the proper way is installing new filetypeicons from addons, and settings the new name.

yes. but now i see only one filetypeicon in addons.

Alexey-T commented 1 year ago

but now i see only one filetypeicon in addons.

you can add another addon (publish it here).

Alexey-T commented 1 year ago

Can you use resample filtering that is implemented in bgrabitmap?

not sure it is easy.

current code just makes bitmap.LoadFromFile(png_filename). then Laz resizes it to current ImgList sizes.

Alexey-T commented 1 year ago

you may play with it

Screenshot from 2022-11-15 09-56-09

veksha commented 1 year ago

this is a place where it is loaded, but where is it painted?

Alexey-T commented 1 year ago

Screenshot from 2022-11-15 10-23-21

veksha commented 1 year ago

added BGRABitmap to "uses":

attabs.pas(40,3) Error: Cannot find BGRABitmap used by attabs. Check if package BGRABitmapPack is in the dependencies of package atflatcontrols_package.

veksha commented 1 year ago

this draft patch will scale all images on loading to 48x48 just to show that it is possible to achieve better quality with BGRAbitmap resampling. But in this place (proc_miscutils.pas) we can't know what icons are for tabs only and what size they will be. so this is wrong. all other application icons will be resized and look a bit blurry.

before: cudatext_XTkfRf5Zjw

after: cudatext_mQVLpaAfO1

diff --git a/app/proc_miscutils.pas b/app/proc_miscutils.pas
index 2302c098e..a043694dc 100644
--- a/app/proc_miscutils.pas
+++ b/app/proc_miscutils.pas
@@ -35,7 +35,8 @@ uses
   ec_syntax_format,
   proc_globdata,
   proc_py_const,
-  proc_colors;
+  proc_colors,
+  BGRABitmap;

 function FormPosGetAsString(Form: TForm; AOnlySize: boolean): string;
 procedure FormPosSetFromString(Form: TForm; const S: string; AOnlySize: boolean);
@@ -265,6 +266,7 @@ end;
 function UpdateImagelistWithIconFromFile(AList: TCustomImagelist; const AFilename, ACallerAPI: string): integer;
 var
   bmp: TCustomBitmap;
+  bgra: TBGRABitmap;
   ext: string;
 begin
   Result:= -1;
@@ -280,13 +282,14 @@ begin
   try
     if ext='.png' then
     begin
-      bmp:= TPortableNetworkGraphic.Create;
+      bgra := TBGRABitmap.Create(AFilename);
+      bgra := bgra.Resample(48, 48);
       try
-        bmp.LoadFromFile(AFilename);
-        bmp.Transparent:= true;
-        AList.Add(bmp, nil);
+        //bmp.LoadFromFile(AFilename);
+        //bmp.Transparent:= true;
+        AList.Add(bgra.Bitmap, nil);
       finally
-        FreeAndNil(bmp);
+        FreeAndNil(bgra);
       end;
     end
     else
veksha commented 1 year ago

attabs.pas file seems bad place too, because it must include BGRAbitmap and depend on it.

veksha commented 1 year ago

maybe there is a place where we can prepare icons only for tabs, load and resample them with BGRABitmap (using known height of tab) and then give ready icons to attabs component?

Alexey-T commented 1 year ago

merged this idea. added the param to func - and set it to True only for API loading of iccons. result is bad on linux:

ic

see Cud branch 'icon_resample'.

veksha commented 1 year ago

i see error. change bgra.Resample(AList.Width, AList.Height); to bgra := bgra.Resample(AList.Width, AList.Height);

Alexey-T commented 1 year ago

yes. fixed. looks good now.