View Issue Details

IDProjectCategoryView StatusLast Update
0001132Double CommanderGraphical user interfacepublic2020-11-30 07:44
ReporterJesusR Assigned ToAlexx2000  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
ProjectionnoneETAnone 
Platformi386OSOS XOS VersionYosemite 10.10.3
Product Version0.7.0 (trunk) 
Target Version0.8.0Fixed in Version0.8.0 
Summary0001132: [Patch] Most icons doesn't look right on Mac OS X
DescriptionSome icons didn't look right in carbon version 0.5.10, qt version 0.5.10 looks fine
but it become worse in trunk version.

Take a look at the screenshots.

Attached there is a patch for fixin this
TagsNo tags attached.
Attached Files
before.png (168,443 bytes)   
before.png (168,443 bytes)   
after.png (167,266 bytes)   
after.png (167,266 bytes)   
iconsfix.diff (3,820 bytes)   
Index: uresample.pas
===================================================================
--- uresample.pas	(revision 6102)
+++ uresample.pas	(working copy)
@@ -391,7 +391,11 @@
     else
       SrcIntfImage := TLazIntfImage.Create(Src.RawImage, False);
     DstIntfImage := TLazIntfImage.Create(Dst.RawImage, False);
+    {$IFDEF Darwin}
+    ImgFormatDescription.Init_BPP32_A8R8G8B8_BIO_TTB(DstWidth, DstHeight);
+    {$ELSE}
     ImgFormatDescription.Init_BPP32_B8G8R8A8_BIO_TTB(DstWidth, DstHeight);
+    {$ENDIF}
     DstIntfImage.DataDescription := ImgFormatDescription;
 {++++++++++++++++++++}
 
Index: platform/upixmapmanager.pas
===================================================================
--- platform/upixmapmanager.pas	(revision 6102)
+++ platform/upixmapmanager.pas	(working copy)
@@ -1068,6 +1068,8 @@
   Result:= GetMimeIcon(FileType, gIconsSize);
 end;
 
+//{$DEFINE USE_TIFF}  // ... when it's fixed in lazarus/fpc
+{$DEFINE USE_BMP}
 function TPixMapManager.GetMimeIcon(AFileExt: String; AIconSize: Integer): PtrInt;
 var
   I: Integer;
@@ -1076,26 +1078,67 @@
   nRepresentations: NSArray;
   nImageRep: NSImageRep;
   WorkStream: TBlobStream;
-  tfBitmap: TTiffImage;
+  tfBitmap: TFPImageBitmap;
   bmBitmap: TBitmap;
+  bmpRep: NSBitmapImageRep;
+  bestRect: NSRect;
+  aImage, cImage: NSImage;
 begin
   Result:= -1;
   if not FUseSystemTheme then Exit;
   nImage:= NSWorkspace.sharedWorkspace.iconForFileType(NSSTR(PChar(AFileExt)));
-  nRepresentations:= nImage.Representations;
   if AIconSize = 22 then AIconSize:= 32;
-  for I:= nRepresentations.Count - 1 downto 0 do
-  begin
-    nImageRep:= NSImageRep(nRepresentations.objectAtIndex(I));
-    if (AIconSize <> nImageRep.Size.Width) then
-      nImage.removeRepresentation(nImageRep);
-  end;
-  if nImage.Representations.Count = 0 then Exit;
-  nData:= nImage.TIFFRepresentation;
+
+  // try to find best representation for requested icon size
+  bestRect.origin.x:= 0;
+  bestRect.origin.y:= 0;
+  bestRect.size.width:= AIconSize;
+  bestRect.size.height:= AIconSize;
+  nImageRep:= nImage.bestRepresentationForRect_context_hints(bestRect, nil, nil);
+  if nImageRep<>nil then
+    begin
+      cImage:= NSImage.Alloc.InitWithSize(nImageRep.Size);
+      cImage.AddRepresentation(nImageRep);
+      aImage:= cImage;
+    end
+  else
+    begin
+      // try old method
+      cImage:= nil;
+      nRepresentations:= nImage.Representations;
+      for I:= nRepresentations.Count - 1 downto 0 do
+      begin
+        nImageRep:= NSImageRep(nRepresentations.objectAtIndex(I));
+        if (AIconSize <> nImageRep.Size.Width) then
+          nImage.removeRepresentation(nImageRep);
+      end;
+      if nImage.Representations.Count = 0 then Exit;
+      aImage:= nImage;
+    end;
+
+  nData:= aImage.TIFFRepresentation;
+  {$IFDEF USE_BMP}
+  bmpRep:= NSBitmapImageRep.imageRepWithData(nData);
+  nData:= bmpRep.representationUsingType_properties(NSBMPFileType, nil);
+  tfBitmap:= TBitmap.Create;
+  {$ENDIF}
+  {$IFDEF USE_TIFF}
   tfBitmap:= TTiffImage.Create;
+  {$ENDIF}
+
   WorkStream:= TBlobStream.Create(nData.Bytes, nData.Length);
   try
-    tfBitmap.LoadFromStream(WorkStream);
+    try
+      tfBitmap.LoadFromStream(WorkStream);
+    except
+      // just in case ...
+      tfBitmap.free;
+      tfBitmap:= nil;
+      exit;
+    end;
+    {$IFDEF USE_BMP}
+    Result:= FPixmapList.Add(tfBitmap);
+    {$ELSE}
     bmBitmap:= TBitmap.Create;
     try
       bmBitmap.Assign(tfBitmap);
@@ -1103,8 +1146,13 @@
     except
       bmBitmap.Free;
     end;
+    {$ENDIF}
   finally
+    {$IFNDEF USE_BMP}
     tfBitmap.Free;
+    {$ENDIF}
+    if cImage<>nil then
+      cImage.Release;
     WorkStream.Free;
   end;
 end;
iconsfix.diff (3,820 bytes)   
Fixed in Revision7552-7554, 7755, 7761
Operating systemMacOSX
WidgetsetCarbon
Architecture32-bit

Activities

JesusR

2015-07-08 22:50

reporter   ~0001496

Forgot to say that I'm using Lazarus and FPC Trunk version.

The problem this patch fixes is that TIFF image reader is broken so it nows load the icon from an alternative format.
The other problem is that the resample routine is producing an unsupported format RGBA I changed it to ARGB.

Issue History

Date Modified Username Field Change
2015-07-08 22:36 JesusR New Issue
2015-07-08 22:42 JesusR File Added: before.png
2015-07-08 22:42 JesusR File Added: after.png
2015-07-08 22:44 JesusR File Added: iconsfix.diff
2015-07-08 22:50 JesusR Note Added: 0001496
2016-01-30 13:26 Alexx2000 Target Version => 0.7.0
2016-01-30 13:27 Alexx2000 Status new => acknowledged
2016-03-08 16:11 Alexx2000 Target Version 0.7.0 => 0.7.1
2016-03-26 14:27 Alexx2000 Target Version 0.7.1 => 0.8.0
2017-05-09 16:52 Alexx2000 Fixed in Revision => 7552
2017-05-09 16:58 Alexx2000 Fixed in Revision 7552 => 7552-7553
2017-05-09 17:46 Alexx2000 Fixed in Revision 7552-7553 => 7552-7554
2017-08-22 21:31 Alexx2000 Fixed in Revision 7552-7554 => 7552-7554, 7755
2017-08-22 22:06 Alexx2000 Status acknowledged => resolved
2017-08-22 22:06 Alexx2000 Resolution open => fixed
2017-08-22 22:06 Alexx2000 Assigned To => Alexx2000
2017-08-26 15:19 Alexx2000 Fixed in Revision 7552-7554, 7755 => 7552-7554, 7755, 7761
2017-08-26 15:19 Alexx2000 Fixed in Version => 0.8.0
2020-11-30 07:44 Alexx2000 Status resolved => closed