#include "windows.bi"
#include once "crt.bi"
#include once "win\gdiplus.bi"
#include once "fbgfx.bi"

using GdiPlus

'declare function GdipGetEncoderClsid(format as wstring ptr, pClsid as CLSID ptr ) as integer
'declare function EnumEncoders() as integer  
'DEFINE_GUID(EncoderQuality,&h1D5BE4B5,&hFA4A,&h452D,&h9C,&hDD,&h5D,&hB3,&h51,&h05,&hE7,&hEB)

CoInitialize(null)

dim as ulong Token
dim as GdiplusStartupInput  tInput = type(1)
dim as GdiplusStartupOutput tOutput
GdiplusStartup(@Token,@tInput,@tOutput)

function GDIP_LoadBitmap(sImageFile as string) as BitmapData
  dim as wstring*MAX_PATH wFile = sImageFile
  dim as gpBitmap ptr poBitmap
  dim as BitmapData tPixels
  if GdipCreateBitmapFromFile(wFile,@poBitmap) then exit function
  GdipBitmapLockBits(poBitmap,0,ImageLockModeRead,PixelFormat32bppARGB,@tPixels)
  tPixels.Reserved = cuint(poBitmap)
  return tPixels
end function
sub GDIP_DestroyBitmap(tImage as BitmapData)
  var poBitmap = cast(gpBitmap ptr,tImage.Reserved)
  GdipBitmapUnlockBits(poBitmap,@tImage)
  cast(istream ptr,poBitmap)->lpvtbl->Release(cast(any ptr,poBitmap))
  delete(poBitmap)
end sub

var tPixels = GDIP_LoadBitmap("TexturePack\7BEF24ECE301F0D2.png") '436DC0DAE62FF406.jpg")
with tPixels
  printf(!"%ix%i %X\n",.Width,.Height,.Scan0)
  screenres .Width,.Height,32
  var pImg = cast(fb.Image ptr,ImageCreate(.Width,.Height))
  screenlock
  var pPix = cast(uinteger ptr,screenptr)
  for Y as integer = 0 to .Height-1
    for X as integer = 0 to .Width-1
      *pPix = (X xor Y) or ((X eqv Y) shl 18): pPix += 1
    next X
  next Y    
  memcpy (pImg+1,.Scan0,abs(.Height*.Stride))
  put(0,0),pImg,alpha
  screenunlock
  GDIP_DestroyBitmap(tPixels)  
end with
sleep
print 