Bad quality with GIF (and GDI+)

Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Fri Oct 30, 2015 7:16 pm

I'm using the new GDI+ function and they work very well with JPGs, TIFs and PNGs but GIFs are rendered with very bad quality.

Someone can confirm?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF

Postby Enrico Maria Giordano » Fri Oct 30, 2015 8:55 pm

This is a sample. Please look at the very bad quality of the result. Any workaround?

Code: Select all  Expand view  RUN
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cSrcImage := "c:\fwh\bitmaps\magic.bmp"
    LOCAL cDstImage := "magic.gif"

    LOCAL oGdi := GDIBmp():New( cSrcImage )

    oGdi:Save( cDstImage )

    oGdi:End()

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sat Oct 31, 2015 6:39 pm

Enrico .
We had a picture of 32 or 24 bits to 8 bits . The maximum number of colors is 256 for gif files.
The problem is that Microsoft gdi+ also uses the halftone palette (compatible 100% web) for gif conversion,which it makes the colors that are not in the table web It is changed to the nearest.
There is no easy solution :-( .
We would have to:
go to gdi1.0 to GDI 1.1 and some operating systems let out (not good).

It could save the original palette but not as we could tell GDI+ to use that instead the halftone palette when save image .
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sat Oct 31, 2015 6:54 pm

So, it would be honest to drop the GIF compatibility. :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sat Oct 31, 2015 6:55 pm

Or to find another way to load a GIF.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sat Oct 31, 2015 11:15 pm

mastintin wrote:go to gdi1.0 to GDI 1.1 and some operating systems let out (not good).


What Windows versions support GDI+ 1.1 natively?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sun Nov 01, 2015 9:48 am

Enrico Maria Giordano wrote:
mastintin wrote:go to gdi1.0 to GDI 1.1 and some operating systems let out (not good).


What Windows versions support GDI+ 1.1 natively?

EMG

Vista and more ...
and some borland compiler not support gdi+1.1 :-(
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sun Nov 01, 2015 10:14 am

Last edited by mastintin on Sun Nov 01, 2015 10:37 am, edited 1 time in total.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sun Nov 01, 2015 10:35 am

mastintin wrote:more news...
https://msdn.microsoft.com/en-us/library/aa479306.aspx
I guess you can adapt the code. When you have a little time I look at you could do.


Do you mean *you* can adapt the code? :-)

Thank you.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sun Nov 01, 2015 10:39 am

here all code in C ++ to use ColorQuantizer.
http://www.codeguru.com/cpp/g-m/gdi/gdi ... ctrees.htm
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sun Nov 01, 2015 10:44 am

Sorry, I cannot be of any help on this subject... :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sun Nov 01, 2015 10:51 am

I just made a test: I replace GDIP_IMAGEFROMFILE() with FILOADIMG() and the result is how is should be. So the problem seems to be located in the loading function GDIP_IMAGEFROMFILE() (and probably in GDIPLUSIMAGELOADCACHEDFILE() too).

I don't know if this can help though.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sun Nov 01, 2015 11:17 am

in c:\fwh\source\winapi\gdiplus.cpp
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby mastintin » Sun Nov 01, 2015 11:44 am

Enrico , provisional solution .....
Change this Method in gdiplus class C:\fwh\source\clases\tgdiplus.prg
Code: Select all  Expand view  RUN


METHOD Save( cFile , nQuality ) CLASS GDIBmp
local cExtension := Upper(cFileExt(cFile))
local cCLSID
local hQuality := nil
local nScan:= aScan( ::aExtEnd, cExtension )
//local cGUI := AnsiToWide("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}" )

local cTempFile

if nScan == 0
    msginfo( "Formato no soportado" )
    Return .f.
endif

if cExtension == "GIF"
   nScan := 1
endif

 cCLSID := ::aCLSID[ nScan ]

 cCLSID = AnsiToWide( cCLSID )
 cFile  = AnsiToWide( cFile )

if cExtension == "GIF"
    cTempFile := cTempFile()
   GdiPlusImageSave( ::hBmp, cTempFile, cCLSID )
   FIConvertImageFile( cTempFile, cFile )
   FErase( cTempFile )
 
else
   if !Empty( nQuality ) .and. cExtension == "JPG"
        GdiPlusImageSaveQuality( ::hBmp, cFile, cCLSID, nQuality )
   else
       GdiPlusImageSave( ::hBmp, cFile, cCLSID )
   endif
endif

Return nil

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Bad quality with GIF (and GDI+)

Postby Enrico Maria Giordano » Sun Nov 01, 2015 12:01 pm

If I read correctly, it uses FreeImage, right? If yes, it's not a useful solution, sorry.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests