#include Once "window9.bi"

Function Load_imagea(Byref sFileName As String) As Any Ptr
	
	Dim As Any Ptr im , imNew
	
	Dim As Long iWidthIm, iHeightIm
	
	Dim As HDC cr
	
	Dim As Gerror Ptr err_
	
	Dim As cairo_surface_t Ptr surf
	
	im = gdk_pixbuf_new_from_file(sFileName , @err_)
	
	If im = 0 Then Return 0
	
	iWidthIm = gdk_pixbuf_get_width(im)
	
	iHeightIm = gdk_pixbuf_get_height(im)	
	
	If 	iWidthIm = 0 Orelse iHeightIm = 0 Then Return 0
	
	imNew =  gdk_pixbuf_new (GDK_COLORSPACE_RGB, True, 8 , iWidthIm, iHeightIm)
	
	gdk_pixbuf_fill(imNew , &hFFFFFF00)
	
	surf = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(imNew),CAIRO_FORMAT_ARGB32,iWidthIm,iHeightIm,gdk_pixbuf_get_rowstride(imNew))
	
	cr = cairo_create (surf)
	
	gdk_cairo_set_source_pixbuf(cr, im, 0, 0)
	
	cairo_paint(cr)
	
	cairo_destroy (cr)
	
	cairo_surface_destroy(surf)	
	
	g_object_unref(im)
	
	Dim As Ubyte Ptr pPixels = gdk_pixbuf_get_pixels(imNew)
	
	Dim As Integer iStride = gdk_pixbuf_get_rowstride(imNew)	
	
	For y As Long = 0 To iHeightIm  -1
		
		Dim As Long Ptr row = Cast(Any Ptr,pPixels)
		
		For x As Long = 0 To iWidthIm-1
			
			row[x] = (row[x] And &hFF00FF00) Or ((row[x] And &h00FF0000) Shr 16) Or ((row[x] And &h000000FF) Shl 16)
			
		Next
		
		pPixels += iStride
		
	Next	
	
	Return imNew
	
End Function