GDIPlus v1.1 usage

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
UEZ
Posts: 994
Joined: May 05, 2017 19:59
Location: Germany

GDIPlus v1.1 usage

Post by UEZ »

Hi,

as I'm more or less new to Freebasic I'm wondering how to use the functions from the GDIPlus v1.1 lib available on Vista+ operating systems.

For example I want to use GdipInitializePalette function but it is not defined in win\gdiplus.bi.

How can I use those functions in GDIPlus v1.1?

Thx.
Last edited by UEZ on May 07, 2017 16:36, edited 1 time in total.
St_W
Posts: 1627
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: GDIPlus v1.1 usage

Post by St_W »

To my knowledge FreeBasic's Windows headers are (or at least were) based on the ones from MinGW. Often newer API functions are missing from those headers. To use those APIs you would have to declare the according function yourself and link the according library. If more than a few methods are missing you can try to translate newer gdiplus headers (e.g. from MinGW) using fbfrog or similar tools. If you do so please share your work and contribute to the FreeBasic project by submitting a patch (pull request) on GitHub or share your updated headers here on the forums. Maybe someone else has done that already? (but I can't remember any such question recently)
UEZ
Posts: 994
Joined: May 05, 2017 19:59
Location: Germany

Re: GDIPlus v1.1 usage

Post by UEZ »

Thanks for your reply St_W, I'm not an experienced FB user yet but let me try to understand how those libs working within FB.

Before I posted this question I already searched for GDI+ v1.1 but didn't find anything about it. I'm just wondering that I'm the first one who is asking about it.

GDI+ is slow but easy to use and the results are not that bad.
St_W
Posts: 1627
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: GDIPlus v1.1 usage

Post by St_W »

UEZ wrote:Thanks for your reply St_W, I'm not an experienced FB user yet but let me try to understand how those libs working within FB.

Before I posted this question I already searched for GDI+ v1.1 but didn't find anything about it. I'm just wondering that I'm the first one who is asking about it.

GDI+ is slow but easy to use and the results are not that bad.
I had a quick look for the function you've mentioned and it should be already declared by the headers shipped in recent FreeBasic packages. So it shouldn't be necessary to define it yourself. It is defined in /inc/win/gdiplus-c.bi.

Yet here comes the strange thing: that file is only included for 64-bit builds of FreeBasic, 32-bit builds seem to use the older GDI headers which don't seem to contain the function you've mentioned.

Unfortunately I haven't used GDI+ yet - neither with FreeBasic nor any other language, so I can't tell the difference right now without having a deeper look into the headers. Maybe dkl can comment on that?

You could try to use the following instead of including win/gdiplus.bi, but I can't tell whether that would work. Yet worth a try:

Code: Select all

#inclib "gdiplus"
namespace Gdiplus
#include "win/gdiplus-c.bi"
end namespace
UEZ
Posts: 994
Joined: May 05, 2017 19:59
Location: Germany

Re: GDIPlus v1.1 usage

Post by UEZ »

I just found also that function is in gdiplus-c.bi but when I try

Code: Select all

#inclib "gdiplus"
namespace Gdiplus
#include "win/gdiplus-c.bi"
end namespace
I get a lot of errors in winuser.bi, for example (2 lines picked):
...FreeBASIC\inc\win\winuser.bi(79) error 58: Illegal specification, at parameter 1 in 'type WNDPROC as function(byval as HWND, byval as UINT, byval as WPARAM, byval as LPARAM) as LRESULT'
...\FreeBASIC\inc\win\winuser.bi(80) error 58: Illegal specification, at parameter 1 in 'type DLGPROC as function(byval as HWND, byval as UINT, byval as WPARAM, byval as LPARAM) as INT_PTR
...'
St_W
Posts: 1627
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: GDIPlus v1.1 usage

Post by St_W »

make sure to include "windows.bi" before

Code: Select all

#Include "windows.bi"

#inclib "gdiplus"
namespace Gdiplus
#include "win/gdiplus-c.bi"
end Namespace
But as I've already said I've no clue whether that works and if/which declarations are missing compared to the old headers used for the 32-bit compiler only. There must some difference as the old headers would have been dropped otherwise. dkl did add the new ones, so he's the person who can tell for sure.
UEZ
Posts: 994
Joined: May 05, 2017 19:59
Location: Germany

Re: GDIPlus v1.1 usage

Post by UEZ »

Nope, same issue.

Then let's wait dkl's answer. :)
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: GDIPlus v1.1 usage

Post by Josep Roca »

The following functions aren't declared in the 32 bit headers and probably not exported by the current library for FB 32 bit:

Code: Select all

GdipFindFirstImageItem
GdipFindNextImageItem
GdipGetImageItemData
GdipInitializePalette
GdipBitmapConvertFormat
GdipBitmapGetHistogram
GdipBitmapGetHistogramSize
The following ones are declared in both headers, but apparently not exported by the current library for FB 64 bit (the linker fails if you try to use them):

Code: Select all

GdipGetMetafileHeaderFromWmf
GdipMeasureCharacterRanges
There are differences in the definitions, e.g.:

Code: Select all

ColorMap PTR for 32 bit and ColorMap_ PTR for 64 bit
GpPoint is defined as Point in 64 bit and as Point_ in 32 bit.
GpRect is defined as Rect in 64 bit and as Rect_ in 32 bit.
The 32-bit headers include some defines not available in the ones for 64-bit:

Code: Select all

#define GetImageDecoders(numDecoders, size, decoders) cast(GpStatus, GdipGetImageDecoders((numDecoders), (size), (decoders)))
#define GetImageDecodersSize(numDecoders, size) cast(GpStatus, GdipGetImageDecodersSize((numDecoders), (size)))
#define GetImageEncoders(numEncoders, size, encoders) cast(GpStatus, GdipGetImageEncoders((numEncoders), (size), (encoders)))
#define GetImageEncodersSize(numEncoders, size) cast(GpStatus, GdipGetImageEncodersSize((numEncoders), (size)))
There are more problems, like PathData declared both as PathData and as Any.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: GDIPlus v1.1 usage

Post by Josep Roca »

Also, to get it working with both 32 and 64 bit, I have to use:

Code: Select all

#include once "windows.bi"
#ifdef __FB_64BIT__
    #inclib "gdiplus"
    #include once "win/gdiplus-c.bi"
#else
    #include once "win/ddraw.bi"
    #include once "win/gdiplus.bi"
    using gdiplus
#endif
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: GDIPlus v1.1 usage

Post by Josep Roca »

There is also a problem with the ColorMap structure, defined as ColorMap_ in gdiplus-c.bi as

Code: Select all

type ColorMap_
	oldColor as Color
	newColor as Color
end type
to avoid conlifcts with the COLORMAP structure defined in commctrl.bi

Code: Select all

type _COLORMAP
	from as COLORREF
	to as COLORREF
end type

type COLORMAP as _COLORMAP
type LPCOLORMAP as _COLORMAP ptr
but also defined as ColorMap (without the underscore) in GdiPlusColorMatrix.bi

Code: Select all

type ColorMap
	oldColor as Color
	newColor as Color
end type
I have ended using my own union:

Code: Select all

UNION GDIP_COLORMAP
   ' // For compatibility with GDI+
   TYPE
      oldColor AS COLORREF
      newColor AS COLORREF
   END TYPE
   ' // For compatibility with GDI
   TYPE
      from AS COLORREF
      to AS COLORREF
   END TYPE
END UNION
UEZ
Posts: 994
Joined: May 05, 2017 19:59
Location: Germany

Re: GDIPlus v1.1 usage

Post by UEZ »

I found out why the error occured from post #5. It was cause by

Code: Select all

#include Once "win\winuser.bi"
When I use (extract only because whole code is too long!)

Code: Select all

#include once "windows.bi"
#ifdef __FB_64BIT__
    #inclib "gdiplus"
    #include once "win/gdiplus-c.bi"
#else
    #include once "win/ddraw.bi"
    #include once "win/gdiplus.bi"
    using gdiplus
#EndIf

Using GDIPLUS

...
Type ARGB as DWORD

Type ColorPalette
	Flags as UINT
	Count as UINT
	Entries(0 to 0) as ARGB
End Type

Type PaletteType As long
Enum
	PaletteTypeCustom = 0
	PaletteTypeOptimal = 1
	PaletteTypeFixedBW = 2
	PaletteTypeFixedHalftone8 = 3
	PaletteTypeFixedHalftone27 = 4
	PaletteTypeFixedHalftone64 = 5
	PaletteTypeFixedHalftone125 = 6
	PaletteTypeFixedHalftone216 = 7
	PaletteTypeFixedHalftone252 = 8
	PaletteTypeFixedHalftone256 = 9
end Enum

Type DitherType As long
Enum
	DitherTypeNone = 0
	DitherTypeSolid = 1
	DitherTypeOrdered4x4 = 2
	DitherTypeOrdered8x8 = 3
	DitherTypeOrdered16x16 = 4
	DitherTypeOrdered91x91 = 5
	DitherTypeSpiral4x4 = 6
	DitherTypeSpiral8x8 = 7
	DitherTypeDualSpiral4x4 = 8
	DitherTypeDualSpiral8x8 = 9
	DitherTypeErrorDiffusion = 10
End Enum

Declare Function GdipInitializePalette(byval as ColorPalette ptr, byval as PaletteType, byval as INT_, byval as BOOL, byval as GpBitmap ptr) as GpStatus

...

Declare Function _GDIPlus_BitmapApplyFilter_Indexed(ByVal hImage As Any Ptr, iColors As UByte) As Any Ptr

...

Function _GDIPlus_BitmapApplyFilter_Indexed(ByVal hImage As Any Ptr, iColors As UByte) As Any Ptr Export
	Dim tPalette As ColorPalette
	tPalette.Flags = PaletteTypeFixedHalftone256
	tPalette.Count = 256
	GdipInitializePalette(@tPalette, PaletteTypeFixedHalftone256, iColors, FALSE, hImage)
	
End Function
I get the error

Code: Select all

_GDIPlus_BitmapApplyFilter.o:fake:(.text+0xe501): undefined reference to `GdipInitializePalette'
The function _GDIPlus_BitmapApplyFilter_Indexed is of course not working! It needs to be finished when I know how to use GDI+ v1.1. ^^


Seems that the GDI lib is messed up a little bit...
Post Reply