[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] TortoiseIDiff optionally using FreeImage.dll for image loading

From: Stefan Küng <tortoisesvn_at_gmail.com>
Date: 2006-09-26 18:15:24 CEST

Will Wilson wrote:
> Hi All,
>
> I’ve concocted a quick & dirty patch to use the
> FreeImage library from within TortoiseIDiff. The key thing is that it
> only uses the FreeImage.dll functionality if the DLL is available,
> otherwise it just uses the existing code-path (GDI+).
>

Thanks for the patch. See my comments below.

> It’s taken a bit of work to do the dynamic linking (function pointer
> syntax is always ugly), but hopefully it’s a nice compromise between
> binary bloat & supporting loads of image formats - including DDS.

That's a good idea. We could just point users to the download page of
the dll and keep our installer small.

> To try it out simply compile a patched TortoiseIDiff.exe, drop the
> FreeImage.dll (see http://freeimage.sourceforge.net/download.html) next
> to it & run the app.

Did that, but crashed immediately :)

> Although the code isn’t pretty (& it could use a little more error
> checking); it should do the job.

Some comments about the code:

+#ifdef UNICODE
+
+typedef int (__stdcall *FreeImage_GetFileType_t)(const wchar_t
*filename, int size);
+typedef int (__stdcall *FreeImage_GetFIFFromFilename_t)(const wchar_t
*filename);
+typedef void* (__stdcall *FreeImage_Load_t)(int format, const wchar_t
*filename, int flags);
+
+#else // !UNICODE
+
+typedef int (__stdcall *FreeImage_GetFileType_t)(const char
*filename, int size);
+typedef int (__stdcall *FreeImage_GetFIFFromFilename_t)(const char
*filename);
+typedef void* (__stdcall *FreeImage_Load_t)(int format, const char
*filename, int flags);
+
+#endif

Here, you could just use TCHAR instead of the #ifdef and using wchar_t*
and char*.

- HMODULE hLib = LoadLibrary(_T("gdiplus.dll"));
- if (hLib)
          {
- // we have gdiplus, so try loading the picture with that one
- if (GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL )==Ok)
- {
+ HMODULE hFreeImageLib = LoadLibrary(_T("FreeImage.dll"));
+ FreeImage_GetVersion_t FreeImage_GetVersion = NULL;

You must not remove those lines. The FreeImage lib also uses GDI+ and
therefore needs the GdiplusStartup() call to work. That's also why it
crashed on me when I first tried it.

You've also removed our custom handling of icons. Since GDI+ only loads
the first icon in an icon file, we have to handle icons ourselves to get
all the sizes and formats.

Stefan

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.net
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Tue Sep 26 18:15:32 2006

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.