Advertisement
Guest User

Image Plugin for all Formats like bmp,png,tga,dds,gif,jpg,..

a guest
Feb 12th, 2013
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; The following formats are supported:(maybe a few more ;) )
  2. ; bmp,dib,ico,emf,jpg,gif,png,tga,dds,ppm,tif,wmf and hdr  
  3. ;
  4. ; All functions return the handle of a device independant bitmap (dibsection), except  
  5. ; if you use _OLE_LoadFromMem() or _OLE_LoadFromFile() to load a ico or cur file, then it returns a handle To a device dependant bitmap.
  6. ; NOTE:
  7. ; You need to call CoInitialize_(0) to use _IMGCTX_LoadFromFile(),_OLE_LoadFromMem() and _OLE_LoadFromFile().
  8.  
  9. EnableExplicit
  10. ; Interfaces:
  11. Interface IImgCtx Extends IUnknown
  12.   Load(pszUrl.p-bstr, dwFlags.l)
  13.   SelectChanges(ulChgOn.l, ulChgOff.l, fSignal.l)
  14.   SetCallback(pfnCB.l, pvPrivateData)
  15.   Disconnect()
  16.   GetUpdateRects(*prc.rect, *prcImg.rect, *pcrc)
  17.   GetStateInfo(*pulState, *psize.size, fClearChanges.l)
  18.   GetPalette(phpal.l)
  19.   Draw(hDC.l, *prcBounds.rect)
  20.   Tile(hDC.l, *pptBackOrg.point, *prcClip.rect,*psize.size)
  21.   StretchBlt(hDCDest.l, nXDest.l, nYDest.l, nWidthDest.l, nHeightDest.l, nXSrc.l, nYSrc.l, nWidthSrc.l, nHeightSrc.l, dwRop.l)
  22. EndInterface
  23.  
  24. ; Constants:
  25. #IMGCHG_SIZE       = $1
  26. #IMGCHG_VIEW       = $2
  27. #IMGCHG_COMPLETE   = $4
  28. #IMGCHG_ANIMATE    = $8
  29. #IMGCHG_MASK       = $F
  30.  
  31. #IMGLOAD_NOTLOADED = $100000  ; Image has not yet been loaded
  32. #IMGLOAD_LOADING   = $200000  ; Image in the process of being loaded
  33. #IMGLOAD_STOPPED   = $400000  ; Imaged aborted
  34. #IMGLOAD_ERROR     = $800000  ; Error loading Image
  35. #IMGLOAD_COMPLETE  = $1000000 ; Image loaded
  36. #IMGLOAD_MASK      = $1F00000
  37.  
  38. #IMGBITS_NONE      = $2000000
  39. #IMGBITS_PARTIAL   = $4000000
  40. #IMGBITS_TOTAL     = $8000000
  41. #IMGBITS_MASK      = $E000000
  42.  
  43. #IMGANIM_ANIMATED  = $10000000
  44. #IMGANIM_MASK      = $10000000
  45.  
  46. #IMGTRANS_OPAQUE   = $20000000
  47. #IMGTRANS_MASK     = $20000000
  48.  
  49. #DWN_COLORMODE     = $3F  ; Explicit color mode requested
  50. #DWN_DOWNLOADONLY  = $40  ; Download data only, don't decode
  51. #DWN_FORCEDITHER   = $80  ; Override automatic dithering
  52. #DWN_RAWIMAGE      = $100 ; Disable dithering
  53. #DWN_MIRRORIMAGE   = $200 ; Mirror the image
  54.  
  55. #CLSCTX_ALL  = $17
  56.  
  57. Interface nIDXSurfaceFactory
  58.   QueryInterface(a, b)
  59.   AddRef()
  60.   Release()
  61.   CreateSurface(a, b, c, d, e, f, g, h)
  62.   CreateFromDDSurface(a, b, c, d, e, f)
  63.   LoadImage(a.p-bstr, b, c, d, e, f)
  64.   LoadImageFromStream(a, b, c, d, e, f)
  65.   CopySurfaceToNewFormat(a, b, c, d, e)
  66.   CreateD3DRMTexture(a, b, c, d, e)
  67.   BitBlt(a, b, c, d, e)
  68. EndInterface
  69.  
  70. #DXLOCKF_READ=0
  71. #CLSCTX_INPROC_SERVER=1
  72.  
  73. DataSection
  74.   CLSID_DXTransformFactory:
  75.   Data.l $D1FE6762
  76.   Data.w $FC48,$11D0
  77.   Data.b $88,$3A,$3C,$8B,$00,$C1,$00,$00
  78.  
  79.   IID_IDXTransformFactory:
  80.   Data.l $6A950B2B
  81.   Data.w $A971,$11D1
  82.   Data.b $81,$C8,$00,$00,$F8,$75,$57,$DB
  83.  
  84.   IID_IDXSurfaceFactory:
  85.   Data.l $144946F5
  86.   Data.w $C4D4,$11D1
  87.   Data.b $81,$D1,$00,$00,$F8,$75,$57,$DB
  88.  
  89.   IID_IDXSurface:
  90.   Data.l $B39FD73F
  91.   Data.w $E139,$11D1
  92.   Data.b $90,$65,$00,$C0,$4F,$D9,$18,$9D
  93. EndDataSection
  94.  
  95.  
  96. Interface ID3DX8
  97.   QueryInterface(a.l,b.l)
  98.   AddRef()
  99.   Release()
  100.   CreateFont(Device.l,hFont.l,retFont.l)
  101.   DrawText(d3dFont.l,color.l,TextString.p-bstr,RECT.l,Format.l)
  102.   GetFVFVertexSize(FVF.l,Size.l)
  103.   AssembleShaderFromFile(SrcFile.p-bstr,flags.l,ErrLog.l,Constants.l,ppVertexShader.l)
  104.   AssembleShader(SrcData.p-bstr,flags.l,Constants.l,ErrLog.l,ppVertexShader.l)
  105.   GetErrorString(hr.l,retStr.l)
  106.   LoadSurfaceFromFile(DestSurface.l,DestPalette.l,DestRect.l,SrcFile.p-bstr,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
  107.   LoadSurfaceFromFileInMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,LengthInBytes.l,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
  108.   LoadSurfaceFromSurface(DestSurface.l,DestPalette.l,DestRect.l,SrcSurface.l,SrcPalette.l,SrcRect.l,Filter.l,ColorKey.l)
  109.   LoadSurfaceFromMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,formatSrc.l,SrcPitch.l,SrcPalette.l,SrcRect.l,Filter.l,ColorKey.l)
  110.   CheckTextureRequirements(Device.l,Width.l,Height.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
  111.   CreateTexture(Device.l,Width.l,Height.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppTexture.l)
  112.   CreateTextureFromResource(Device.l,hModule.l,SrcResource.p-bstr,ppTexture.l)
  113.   CreateTextureFromFile(Device.l,SrcFile.p-bstr,ppTexture.l)
  114.   CreateTextureFromFileEx(Device.l,SrcFile.p-bstr,Width.l,Height.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,Filter.l,MipFilter.l,ColorKey.l,SrcInfo.l,Palette.l,ppTexture.l)
  115.   CreateTextureFromFileInMemory(Device.l,SrcData.l,LengthInBytes.l,ppTexture.l)
  116.   CreateTextureFromFileInMemoryEx(Device.l,SrcData.l,LengthInBytes.l,Width.l,Height.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,Filter.l,MipFilter.l,ColorKey.l,SrcInfo.l,Palette.l,ppTexture.l)
  117.   FilterTexture(texture.l,Palette.l,SrcLevel.l,Filter.l)
  118.   CheckCubeTextureRequirements(Device.l,Size.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
  119.   CreateCubeTexture(pDevice.l,Size.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppCubeTexture.l)
  120.   CreateCubeTextureFromFile(Device.l,SrcFile.p-bstr,ppCubeTexture.l)
  121.   CreateCubeTextureFromFileEx(Device.l,SrcFile.p-bstr,TextureSize.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,Filter.l,MipFilter.l,ColorKey.l,SrcInfo.l,Palette.l,ppTexture.l)
  122.   CreateCubeTextureFromFileInMemory(Device.l,SrcData.l,LengthInBytes.l,ppTexture.l)
  123.   CreateCubeTextureFromFileInMemoryEx(Device.l,SrcData.l,LengthInBytes.l,TextureSize.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,Filter.l,MipFilter.l,ColorKey.l,SrcInfo.l,Palette.l,ppTexture.l)
  124.   FilterCubeTexture(CubeTexture.l,Palette.l,SrcLevel.l,Filter.l)
  125.   CheckVolumeTextureRequirements(Device.l,Width.l,Height.l,Depth.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
  126.   CreateTextureFromResourceEx(Device.l,hSrcModule.l,SrcResource.p-bstr,Width.l,Height.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,Filter.l,MipFilter.l,ColorKey.l,SrcInfo.l,Palette.l,retTexture.l)
  127.   CreateVolumeTexture(Device.l,Width.l,Height.l,Depth.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppVolumeTexture.l)
  128.   FilterVolumeTexture(VolumeTexture.l,Palette.l,SrcLevel.l,Filter.l)
  129.   LoadSurfaceFromResource(DestSurface.l,DestPalette.l,DestRect.l,hSrcModule.l,SrcResource.p-bstr,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
  130.   LoadVolumeFromVolume(DestVolume.l,DestPalette.l,DestBox.l,SrcVolume.l,SrcPalette.l,SrcBox.l,Filter.l,ColorKey.l)
  131.   LoadVolumeFromMemory(DestVolume.l,DestPalette.l,DestBox.l,SrcMemory.l,SrcFormat.l,SrcRowPitch.l,SrcSlicePitch.l,SrcPalette.l,SrcBox.l,Filter.l,ColorKey.l)
  132.   CreateMesh(numFaces.l,NumVertices.l,options.l,Declaration.l,pD3D.l,ppMesh.l)
  133.   CreateMeshFVF(numFaces.l,NumVertices.l,options.l,FVF.l,pD3D.l,ppMesh.l)
  134.   CreateSPMesh(pMesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,ppSMesh.l)
  135.   GeneratePMesh(Mesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,minValue.l,options.l,ppPMesh.l)
  136.   SimplifyMesh(Mesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,minValue.l,options.l,ppMesh.l)
  137.   ComputeBoundingSphere(PointsFVF.l,NumVertices.l,FVF.l,Centers.l,RadiusArray.l)
  138.   ComputeBoundingBox(PointsFVF.l,NumVertices.l,FVF.l,MinVert.l,MaxVert.l)
  139.   ComputeNormals(pMesh.l)
  140.   DeclaratorFromFVF(FVF.l,Declarator.l)
  141.   FVFFromDeclarator(Declarator.l,FVF.l)
  142.   CreateBuffer(numBytes.l,ppBuffer.l)
  143.   LoadMeshFromX(filename.p-bstr,options.l,D3DDevice.l,retAdjacency.l,retMaterials.l,retMaterialCount.l,retMesh.l)
  144.   SaveMeshToX(filename.p-bstr,Mesh.l,AdjacencyArray.l,MaterialArray.l,MaterialCount.l,xFormat.l)
  145.   LoadMeshFromXof(*xofobjMesh.IUnknown,options.l,D3DDevice.l,retBufAdjacency.l,retMaterials.l,retMaterialCount.l,retMesh.l)
  146.   TessellateNPatches(MeshIn.l,adjacencyIn.l,NumSegs.f,QuadraticInterpNormals.w,adjacencyOut.l,MeshOut.l)
  147.   BufferGetMaterial(MaterialBuffer.l,index.l,mat.l)
  148.   BufferGetTextureName(MaterialBuffer.l,index.l,retName.l)
  149.   BufferGetData(Buffer.l,index.l,typesize.l,typecount.l,Data_.l)
  150.   BufferSetData(Buffer.l,index.l,typesize.l,typecount.l,Data_.l)
  151.   Intersect(MeshIn.l,RayPos.l,RayDir.l,retHit.l,retFaceIndex.l,U.l,v.l,retDist.l,countHits.l,AllHits.l)
  152.   SphereBoundProbe(Center.l,Radius.f,RayPosition.l,Raydirection.l,retHit.l)
  153.   ComputeBoundingSphereFromMesh(MeshIn.l,Centers.l,RadiusArray.l)
  154.   ComputeBoundingBoxFromMesh(MeshIn.l,MinArray.l,MaxArray.l)
  155.   CreateSkinMesh(numFaces.l,NumVertices.l,numBones.l,options.l,Declaration.l,D3DDevice.l,SkinMesh.l)
  156.   CreateSkinMeshFVF(numFaces.l,NumVertices.l,numBones.l,options.l,FVF.l,D3DDevice.l,ppSkinMesh.l)
  157.   CreateSkinMeshFromMesh(Mesh.l,numBones.l,ppSkinMesh.l)
  158.   LoadSkinMeshFromXof(*xofobjMesh.IUnknown,options.l,D3DDevice.l,adjacencyOut.l,MaterialsOut.l,NumMatOut.l,BoneNamesOut.l,BoneTransformsOut.l,ppMesh.l)
  159.   CreatePolygon(D3DDevice.l,Length.f,Sides.l,retAdjacency.l,retMesh.l)
  160.   CreateBox(D3DDevice.l,Width.f,Height.f,Depth.f,retAdjacency.l,retMesh.l)
  161.   CreateCylinder(D3DDevice.l,Radius1.f,Radius2.f,Length.f,Slices.l,Stacks.l,retAdjacency.l,retMesh.l)
  162.   CreateSphere(D3DDevice.l,Radius.f,Slices.l,Stacks.l,retAdjacency.l,retMesh.l)
  163.   CreateTorus(D3DDevice.l,InnerRadius.f,OuterRadius.f,Sides.l,Rings.l,retAdjacency.l,retMesh.l)
  164.   CreateTeapot(D3DDevice.l,retAdjacency.l,retMesh.l)
  165.   CreateText(D3DDevice.l,hDC.l,Text.p-bstr,Deviation.f,Extrusion.f,retMesh.l,adjacencyOut.l,GlyphMetrics.l)
  166.   BufferGetBoneName(BoneNameBuffer.l,index.l,retName.l)
  167.   CreateSprite(D3DDevice.l,retSprite.l)
  168.   CreateRenderToSurface(D3DDevice.l,Width.l,Height.l,Format.l,DepthStencil.l,DepthStencilFormat.l,RetRenderToSurface.l)
  169.   CleanMesh(MeshIn.l,Adjacency.l,ErrLog.l,adjacencyOut.l,MeshOut.l)
  170.   ValidMesh(MeshIn.l,Adjacency.l,ErrLog.l,ret.l)
  171.   BoxBoundProbe(MinVert.l,MaxVert.l,RayPosition.l,Raydirection.l,ret.l)
  172.   SavePMeshToFile(filename.p-bstr,Mesh.l,MaterialArray.l,MaterialCount.l)
  173.   LoadPMeshFromFile(filename.p-bstr,options.l,D3DDevice.l,retMaterials.l,RetNumMaterials.l,RetPMesh.l)
  174.   BufferGetBoneCombo(BoneComboBuffer.l,index.l,boneCombo.l)
  175.   BufferGetBoneComboBoneIds(BoneComboBuffer.l,index.l,paletteSize.l,BoneIds.l)
  176.   SaveSurfaceToFile(DestFile.p-bstr,DestFormat.l,SrcSurface.l,SrcPalette.l,SrcRect.l)
  177.   SaveVolumeToFile(DestFile.p-bstr,DestFormat.l,SrcVolume.l,SrcPalette.l,SrcBox.l)
  178.   SaveTextureToFile(DestFile.p-bstr,DestFormat.l,SrcTexture.l,SrcPalette.l)
  179. EndInterface
  180.  
  181. Prototype.l D3DX9LoadSurfaceFromFile(DestSurface.l,DestPalette.l,DestRect.l,SrcFile.s,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
  182. Prototype.l D3DX9LoadSurfaceFromFileInMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,LengthInBytes.l,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
  183. Prototype.l D3DX9GetImageInfoFromFile(pSrcFile.l,pSrcInfo.l)
  184. Prototype.l D3DX9GetImageInfoFromFileInMemory(pSrcData.l,SrcDataSize.l,pSrcInfo.l)
  185.  
  186. Structure GdiplusStartupInput
  187.   GdiplusVersion.l
  188.   DebugEventCallback.l
  189.   SuppressBackgroundThread.l
  190.   SuppressExternalCodecs.l
  191. EndStructure
  192.  
  193. Prototype.l GdiplusStartup(a.l,b.l,c.l)
  194. Prototype.l GdiplusShutdown(a.l)
  195. Prototype.l GdipGetImageWidth(a.l,b.l)
  196. Prototype.l GdipGetImageHeight(a.l,b.l)
  197. Prototype.l GdipCreateFromHDC(a.l,b.l)
  198. Prototype.l GdipDrawImageI(a.l,b.l,c.l,d.l)
  199. Prototype.l GdipDisposeImage(a.l)
  200. Prototype.l GdipDeleteGraphics(a.l)
  201. Prototype.l GdipAlloc(a.l)
  202. Prototype.l GdipFree(a.l)
  203. Prototype.l GdipCreateBitmapFromFile(a.l,b.l)
  204. Prototype.l GdipCreateBitmapFromStream(a.l,b.l)
  205.  
  206. #CLSCTX_INPROC_SERVER=1
  207.  
  208. Structure D3DSURFACE_DESC
  209.   Format.l
  210.   Type.l
  211.   Usage.l
  212.   Pool.l
  213.   Size.l
  214.   MultiSampleType.l
  215.   Width.l
  216.   Height.l
  217. EndStructure
  218.  
  219. Structure D3DSURFACE9_DESC
  220.   Format.l
  221.   Type.l
  222.   Usage.l
  223.   Pool.l
  224.   MultiSampleType.l
  225.   MultiSampleQuality.l
  226.   Width.l
  227.   Height.l
  228. EndStructure
  229.  
  230. Structure D3DLOCKED_RECT
  231.   Pitch.l
  232.   pBits.l
  233. EndStructure
  234.  
  235. Structure D3DXIMAGE_INFO
  236.   Width.l
  237.   Height.l
  238.   Depth.l
  239.   MipLevels.l
  240.   Format.l
  241.   ResourceType.l
  242.   ImageFileFormat.l
  243. EndStructure
  244.  
  245. Structure MyD3DSURFACE
  246.   VTable.l
  247.   Width.l
  248.   Height.l
  249.   Pitch.l
  250.   pBits.l
  251.   BufferData.l
  252. EndStructure
  253.  
  254. #D3DFMT_A8R8G8B8=21
  255. #D3DFMT_X8R8G8B8=22
  256.  
  257. #D3DRTYPE_SURFACE=1
  258.  
  259. #D3DPOOL_SYSTEMMEM=2
  260. #D3DPOOL_SCRATCH=3
  261.  
  262.  
  263. Interface IWICBitmapDecoder Extends IUnknown
  264.   QueryCapability( *pIStream.IStream, *pdwCapabilities.l )
  265.   Initialize(  *pIStream, cacheOptions.i)
  266.   GetContainerFormat( *pguidContainerFormat.GUID )
  267.   GetDecoderInfo(*ptr_pIDecoderInfo )
  268.   CopyPalette ( *pIPalette );
  269.   GetMetadataQueryReader ( *ppIMetadataQueryReader);
  270.   GetPreview ( *ptr_ppIPreview );
  271.   GetColorContexts(cCount, *ppIColorContexts, *ptr_pcActualCount )
  272.   GetThumbnail (*ptr_ppIThumbnail );
  273.   GetFrameCount(*pCount.integer)
  274.   GetFrame(index.i,*ptr_ppIBitmapFrame )
  275. EndInterface
  276.  
  277.  
  278. Interface IWICBitmapEncoder Extends IUnknown
  279.   Initialize (  *pIStream.IStream, cacheOption )
  280.   GetContainerFormat (*pguidContainerFormat.GUID )
  281.   GetEncoderInfo ( *ptr_pIEncoderInfo )
  282.   SetColorContexts ( cCount, *_ptr_ppIColorContext );
  283.   SetPalette ( *pIPalette);
  284.   SetThumbnail (*pIThumbnail );
  285.   SetPreview (*pIPreview );
  286.   CreateNewFrame (*ptr_ppIFrameEncode, *ptr_ppIEncoderOptions )
  287.   Commit()
  288.   GetMetadataQueryWriter ( *ptr_ppIMetadataQueryWriter );
  289. EndInterface
  290.  
  291.  
  292. Interface IWICBitmapSource Extends IUnknown
  293.   GetSize ( *puiWidth,*puiHeight )
  294.   GetPixelFormat (*pPixelFormat );
  295.   GetResolution ( *pDpiX.double, *pDpiY.double)
  296.   CopyPalette ( *pIPalette );
  297.   CopyPixels ( *prc,cbStride, cbBufferSize, *pbBuffer.b );
  298. EndInterface
  299.  
  300. Interface IWICBitmapFrameDecode Extends IWICBitmapSource
  301.   GetMetadataQueryReader ( *ptr_pIMetadataQueryReader )
  302.   GetColorContexts ( cCount,  *ptr_ppIColorContexts,  *pcActualCount )
  303.   GetThumbnail ( *ptr_ppIThumbnail );
  304. EndInterface
  305.  
  306. Interface IWICBitmapFrameEncode Extends IUnknown
  307.   Initialize ( *pIEncoderOptions );
  308.   SetSize ( width,  height );
  309.   SetResolution ( dpiX.d,  dpiY.d );
  310.   SetPixelFormat (*pPixelFormat);
  311.   SetColorContexts ( cCount, *ptr_ppIColorContext );
  312.   SetPalette (*pIPalette )
  313.   SetThumbnail ( *pIThumbnail )
  314.   WritePixels ( lineCount,  cbStride, cbBufferSize, *pbPixels.byte )
  315.   WriteSource (  *pIWICBitmapSource,  *prc );
  316.   Commit()
  317.   GetMetadataQueryWriter ( *ptr_ppIMetadataQueryWriter );
  318. EndInterface
  319.  
  320.  
  321. Macro DEF_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
  322.   Global name.GUID
  323.   name\Data1 = l
  324.   name\Data2 = w1
  325.   name\Data3 = w2
  326.   name\Data4[0] = b1
  327.   name\Data4[1] = b2
  328.   name\Data4[2] = b3
  329.   name\Data4[3] = b4
  330.   name\Data4[4] = b5
  331.   name\Data4[5] = b6
  332.   name\Data4[6] = b7
  333.   name\Data4[7] = b8
  334. EndMacro
  335.  
  336.  
  337. DEF_GUID(CLSID_WICBmpEncoder,   $69be8bb4, $d66d, $47c8, $86, $5a, $ed, $15, $89, $43, $37, $82)
  338. DEF_GUID(CLSID_WICPngEncoder,   $27949969, $876a, $41d7, $94, $47, $56, $8f, $6a, $35, $a4, $dc)
  339. DEF_GUID(CLSID_WICJpegEncoder,  $1a34f5c1, $4a5a, $46dc, $b6, $44, $1f, $45, $67, $e7, $a6, $76)
  340. DEF_GUID(CLSID_WICGifEncoder,   $114f5598, $b22, $40a0, $86, $a1, $c8, $3e, $a4, $95, $ad, $bd)
  341. DEF_GUID(CLSID_WICTiffEncoder,  $0131be10, $2001, $4c5f, $a9, $b0, $cc, $88, $fa, $b6, $4c, $e8)
  342. DEF_GUID(CLSID_WICWmpEncoder,   $ac4ce3cb, $e1c1, $44cd, $82, $15, $5a, $16, $65, $50, $9e, $c2)
  343.  
  344. DEF_GUID(CLSID_WICBmpDecoder,   $6b462062, $7cbf, $400d, $9f, $db, $81, $3d, $d1, $f, $27, $78)
  345. DEF_GUID(CLSID_WICPngDecoder,   $389ea17b, $5078, $4cde, $b6, $ef, $25, $c1, $51, $75, $c7, $51)
  346. DEF_GUID(CLSID_WICIcoDecoder,   $c61bfcdf, $2e0f, $4aad, $a8, $d7, $e0, $6b, $af, $eb, $cd, $fe)
  347. DEF_GUID(CLSID_WICJpegDecoder,  $9456a480, $e88b, $43ea, $9e, $73, $b, $2d, $9b, $71, $b1, $ca)
  348. DEF_GUID(CLSID_WICGifDecoder,   $381dda3c, $9ce9, $4834, $a2, $3e, $1f, $98, $f8, $fc, $52, $be)
  349. DEF_GUID(CLSID_WICTiffDecoder,  $b54e85d9, $fe23, $499f, $8b, $88, $6a, $ce, $a7, $13, $75, $2b)
  350. DEF_GUID(CLSID_WICWmpDecoder,   $a26cec36, $234c, $4950, $ae, $16, $e3, $4a, $ac, $e7, $1d, $0d)
  351.  
  352. DEF_GUID(IID_IWICBitmapDecoder,$9EDDE9E7,$8DEE,$47ea,$99,$DF,$E6,$FA,$F2,$ED,$44,$BF);
  353. DEF_GUID(IID_IWICBitmapEncoder, $00000103,$a8f2,$4877,$ba,$0a,$fd,$2b,$66,$45,$fb,$94)
  354.  
  355. DEF_GUID(WICPixelFormat24bppRGB, $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$0d)
  356. DEF_GUID(WICPixelFormat24bppBGR, $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$0c)
  357. DEF_GUID(WICPixelFormat32bppBGRA, $6fddc324, $4e03, $4bfe, $b1, $85, $3d, $77, $76, $8d, $c9, $0f);
  358.  
  359. #WICDecodeMetadataCacheOnDemand   = 0
  360. #WICDecodeMetadataCacheOnLoad     = 1
  361.  
  362. #WICBitmapEncoderCacheInMemory  = 0
  363. #WICBitmapEncoderCacheTempFile  = 1
  364. #WICBitmapEncoderNoCache    = 2
  365.  
  366. ;WICPixelFormatGUID is eqaul to GUID
  367.  
  368. #STGM_READ=$00000000
  369. #STGM_WRITE=$00000001
  370. #STGM_READWRITE=$00000002
  371. #STGM_SHARE_DENY_NONE=$00000040
  372. #STGM_SHARE_DENY_READ=$00000030
  373. #STGM_SHARE_DENY_WRITE=$00000020
  374. #STGM_SHARE_EXCLUSIVE=$00000010
  375. #STGM_PRIORITY=$00040000
  376. #STGM_CREATE=$00001000
  377. #STGM_CONVERT=$00020000
  378. #STGM_FAILIFTHERE=$00000000
  379. #STGM_DIRECT=$00000000
  380. #STGM_TRANSACTED=$00010000
  381. #STGM_NOSCRATCH=$00100000
  382. #STGM_NOSNAPSHOT=$00200000
  383. #STGM_SIMPLE=$08000000
  384. #STGM_DIRECT_SWMR=$00400000
  385. #STGM_DELETEONRELEASE=$04000000
  386.  
  387. Structure STATSTG  
  388.   pwcsName.l
  389.   type.l
  390.   cbSize.ULARGE_INTEGER
  391.   mtime.FILETIME
  392.   ctime.FILETIME
  393.   atime.FILETIME
  394.   grfMode.f
  395.   grfLocksSupported.l
  396.   clsid.GUID
  397.   grfStateBits.l
  398.   reserved.l
  399. EndStructure
  400.  
  401.  
  402. Procedure __MyD3D8SurfaceGetDesc(*this.MyD3DSURFACE,*desc.D3DSURFACE_DESC)
  403.   *desc\Format=#D3DFMT_A8R8G8B8
  404.   *desc\Pool=#D3DPOOL_SYSTEMMEM
  405.   *desc\Type=#D3DRTYPE_SURFACE
  406.   *desc\Width=*this\Width
  407.   *desc\Height=*this\Height
  408.   *desc\Size=*this\Pitch * *this\Height
  409.   ; must be set zu zero
  410.   *desc\MultiSampleType=0
  411.   *desc\Usage=0
  412. EndProcedure
  413.  
  414. Procedure __MyD3D9SurfaceGetDesc(*this.MyD3DSURFACE,*desc.D3DSURFACE9_DESC)
  415.   *desc\Format=#D3DFMT_A8R8G8B8
  416.   *desc\Pool=#D3DPOOL_SCRATCH
  417.   *desc\Type=#D3DRTYPE_SURFACE
  418.   *desc\Width=*this\Width
  419.   *desc\Height=*this\Height
  420.   ; must be set zu zero
  421.   *desc\MultiSampleType=0
  422.   *desc\MultiSampleQuality=0
  423.   *desc\Usage=0
  424. EndProcedure
  425.  
  426. Procedure __MyD3DSurfaceLock(*this.MyD3DSURFACE,*lockinf.D3DLOCKED_RECT,*re.rect,Flags)
  427.   *lockinf\pBits=*this\pBits
  428.   *lockinf\Pitch=*this\Pitch
  429. EndProcedure
  430.  
  431. Procedure __MyD3DSurfaceUnLock(*this.MyD3DSURFACE)
  432. EndProcedure
  433.  
  434. Procedure __MyD3DSurfaceAddRef(*this.MyD3DSURFACE)
  435. EndProcedure
  436. Procedure __MyD3DSurfaceRelease(*this.MyD3DSURFACE)
  437. EndProcedure
  438.  
  439. DataSection
  440.   IID_IUnknown:
  441.   Data.l 0
  442.   Data.l $0
  443.   Data.l $C0
  444.   Data.l $46000000
  445.  
  446.   CLSID_D3DX8:
  447.   Data.l 1479896157
  448.   Data.l 1223494653
  449.   Data.l 1391773075
  450.   Data.l -567057909
  451.  
  452.   MyD3D8_SurfaceVTable:
  453.   Data.l 0,0,0,0,0,0,0,0,@__MyD3D8SurfaceGetDesc(),@__MyD3DSurfaceLock(),@__MyD3DSurfaceUnLock()
  454.  
  455.   MyD3D9_SurfaceVTable:
  456.   Data.l 0,@__MyD3DSurfaceAddRef(),@__MyD3DSurfaceRelease(),0,0,0,0,0,0,0,0,0,@__MyD3D9SurfaceGetDesc(),@__MyD3DSurfaceLock(),@__MyD3DSurfaceUnLock()
  457. EndDataSection
  458.  
  459.  
  460. ; Uses IImgCtx from mshtml.dll to load bmp,dib,ico,wmf,emf,jpg,png and gif files, so we don't need huge plugins.
  461. ; However it's not guaranteed that this function works everywhere.(but it should work very well almost everywhere ;) )
  462. Procedure _IMGCTX_LoadFromFile(File.s)
  463.   Protected *ImgCtx.IImgCtx, lState.i, sz.size, BmInf.BitmapInfo, hBmp =#Null, OldhBmp = #Null, MemDC = #Null
  464.   Protected Path.s
  465.   If FileSize(File) < 1
  466.     ProcedureReturn #Null
  467.   EndIf  
  468.  
  469.   CoCreateInstance_(?CLSID_IImgCtx,0,#CLSCTX_ALL,?IID_IImgCtx,@*ImgCtx.IImgCtx)
  470.   If *ImgCtx=#Null:ProcedureReturn #Null:EndIf
  471.  
  472.   If FindString(File,":",1)=0 ; it's a relative path  
  473.     Path.s=Space(#MAX_PATH)
  474.     GetCurrentDirectory_(Len(Path),Path)
  475.     *ImgCtx\Load("file:///"+ReplaceString(Path+"\"+File,"\","/"),0)
  476.   Else
  477.     *ImgCtx\Load("file:///"+ReplaceString(File,"\","/"),0)
  478.   EndIf
  479.  
  480.   Repeat ; needed, because ImgCtx works asynchronous (we must wait till it's loaded completely)
  481.     Sleep_(1)
  482.     *ImgCtx\GetStateInfo(@lState,sz.size, 1)
  483.   Until lState&#IMGLOAD_COMPLETE Or lState&#IMGLOAD_STOPPED Or lState&#IMGLOAD_ERROR
  484.    
  485.   If lState&#IMGLOAD_STOPPED Or lState&#IMGLOAD_ERROR
  486.     ;Error  
  487.   Else  
  488.     If sz\cx > 0 And sz\cy > 0
  489.       BmInf\BmiHeader\biBitCount = 24
  490.       BmInf\BmiHeader\biCompression=#BI_RGB
  491.       BmInf\BmiHeader\biPlanes = 1
  492.       BmInf\BmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
  493.       BmInf\BmiHeader\biWidth = sz\cx
  494.       BmInf\BmiHeader\biHeight = sz\cy
  495.       hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  496.       If hBmp
  497.         MemDC=CreateCompatibleDC_(0)
  498.         If MemDC
  499.           OldhBmp=SelectObject_(MemDC,hBmp)  
  500.           ;--crash with zip
  501.           *ImgCtx\StretchBlt(MemDC,0,0,sz\cx,sz\cy,0,0,sz\cx,sz\cy,#SRCCOPY)
  502.           SelectObject_(MemDC,OldhBmp)
  503.           DeleteDC_(MemDC)
  504.         Else
  505.           DeleteObject_(hBmp)
  506.           hBmp = #Null
  507.         EndIf
  508.       EndIf
  509.     EndIf
  510.   EndIf
  511.   *ImgCtx\Release()
  512.   ProcedureReturn hBmp  
  513.    
  514.   DataSection  ; only include it, if it's needed.
  515.     IID_IImgCtx:
  516.     Data.l $3050f3d7
  517.     Data.w $98b5,$11cf
  518.     Data.b $bb,$82,$0,$aa,$0,$bd,$ce,$0b
  519.    
  520.     CLSID_IImgCtx:
  521.     Data.l $3050f3d6
  522.     Data.w $98b5,$11cf
  523.     Data.b $bb,$82,$0,$aa,$0,$bd,$ce,$0b
  524.   EndDataSection  
  525. EndProcedure
  526.  
  527. ; Uses OLE to load bmp,dib,ico,cur,emf,jpg and gif files, so we don't need huge plugins.
  528. ; However the support of jpg and gif is not guaranteed.
  529. Procedure _OLE_LoadFromMem(Addr, Size)
  530.   Protected BmInf.BitmapInfo, Mem, *ptr, *Stream.IStream, GDIObject, Bmp.BITMAP
  531.   Protected hBmp, DestMemDC, DestOldhBmp, MemDC, OldDC, re.rect, icoinf.ICONINFO, Result      
  532.   Protected *OlePict.IPicture, emh.ENHMETAHEADER
  533.  
  534.   BmInf\BmiHeader\biBitCount=24
  535.   BmInf\BmiHeader\biCompression=#BI_RGB
  536.   BmInf\BmiHeader\biPlanes=1
  537.   BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  538.  
  539.   If Addr <> #Null And Size > 0 ; we can only use OLE, if the size is known and the address is valid.
  540.    
  541.     Mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)  
  542.     *ptr=GlobalLock_(Mem)
  543.    
  544.     If *ptr=0 ; if GlobalAlloc or GlobalLock failed
  545.       GlobalFree_(Mem)
  546.       ProcedureReturn 0
  547.     EndIf
  548.    
  549.     RtlMoveMemory_(*ptr,Addr,Size)
  550.     GlobalUnlock_(Mem)
  551.    
  552.     CreateStreamOnHGlobal_(Mem,1,@*Stream)
  553.    
  554.     If *Stream=0
  555.       GlobalFree_(Mem)
  556.       ProcedureReturn 0
  557.     EndIf
  558.    
  559.     OleLoadPicture_(*Stream,0,0,?IID_IPicture,@*OlePict.IPicture)
  560.     *Stream\Release() ; the stream should free Mem too
  561.    
  562.     If *OlePict=0:ProcedureReturn 0:EndIf
  563.    
  564.     *OlePict\Get_Handle(@GDIObject)
  565.    
  566.    
  567.     Select GetObjectType_(GDIObject) ; convert gdi-object into a DIBSECTION
  568.        
  569.       Case #OBJ_BITMAP
  570.        
  571.         GetObject_(GDIObject,SizeOf(BITMAP),Bmp.BITMAP)
  572.        
  573.         BmInf\BmiHeader\biWidth=Bmp\bmWidth
  574.         BmInf\BmiHeader\biHeight=Bmp\bmHeight
  575.        
  576.         hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  577.        
  578.         If hBmp
  579.           DestMemDC=CreateCompatibleDC_(0)  
  580.           DestOldhBmp=SelectObject_(DestMemDC,hBmp)
  581.          
  582.           MemDC=CreateCompatibleDC_(0)
  583.           *OlePict\SelectPicture(MemDC,@OldDC,0)
  584.          
  585.           Result=BitBlt_(DestMemDC,0,0,Bmp\bmWidth,Bmp\bmHeight,MemDC,0,0,#SRCCOPY)
  586.          
  587.           *OlePict\SelectPicture(OldDC,0,0)
  588.           SelectObject_(DestMemDC,DestOldhBmp)
  589.           DeleteDC_(MemDC)
  590.           DeleteDC_(DestMemDC)
  591.         EndIf
  592.        
  593.       Case #OBJ_METAFILE,#OBJ_ENHMETAFILE  
  594.         GetEnhMetaFileHeader_(GDIObject,SizeOf(ENHMETAHEADER),emh.ENHMETAHEADER)
  595.        
  596.         ;correct ?
  597.         re.rect\right=emh\rclBounds\right-emh\rclBounds\left
  598.         re\bottom=emh\rclBounds\bottom-emh\rclBounds\top
  599.        
  600.         BmInf\BmiHeader\biWidth=re\right
  601.         BmInf\BmiHeader\biHeight=re\bottom
  602.         hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  603.        
  604.         If hBmp              
  605.           DestMemDC=CreateCompatibleDC_(0)
  606.           DestOldhBmp=SelectObject_(DestMemDC,hBmp)
  607.          
  608.           Result=PlayEnhMetaFile_(DestMemDC,GDIObject,re.rect)
  609.          
  610.           SelectObject_(DestMemDC,DestOldhBmp)
  611.           DeleteDC_(DestMemDC)
  612.         EndIf
  613.        
  614.     EndSelect
  615.    
  616.     If GetIconInfo_(GDIObject,icoinf.ICONINFO)
  617.       Result=1
  618.       ;The calling application must manage these bitmaps And delete them when they are no longer necessary.
  619.       DeleteObject_(icoinf\hbmMask) ; we don't need the mask
  620.       hBmp=icoinf\hbmColor ; no dibsection, but at least a bitmap
  621.     EndIf
  622.    
  623.     *OlePict\Release()
  624.   EndIf      
  625.  
  626.   If Result=0:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
  627.   ProcedureReturn hBmp
  628.  
  629.   DataSection ; only include it, if it's needed.
  630.     IID_IPicture:
  631.     Data.l $7BF80980
  632.     Data.w $BF32,$101A
  633.     Data.b $8B,$BB,$0,$AA,$0,$30,$0C,$AB
  634.   EndDataSection
  635. EndProcedure
  636.  
  637. ; Uses OLE to load bmp,dib,ico,cur,emf,jpg and gif files, so we don't need huge plugins.
  638. ; However the support of jpg and gif is not guaranteed.
  639. Procedure _OLE_LoadFromFile(File.s)
  640.   Protected Handle, sz.LARGE_INTEGER, *ptr, Result = #Null
  641.   Protected readbytes
  642.  
  643.   Handle=CreateFile_(File,#GENERIC_READ,#FILE_SHARE_READ,0,#OPEN_EXISTING,#FILE_ATTRIBUTE_NORMAL,0)
  644.   If Handle=#Null:ProcedureReturn 0:EndIf
  645.  
  646.   GetFileSizeEx_(Handle,sz.LARGE_INTEGER)
  647.  
  648.   If sz\lowpart<=0 Or sz\highpart ; if the size of the file is zero, or more than 4 GB
  649.     CloseHandle_(Handle)
  650.     ProcedureReturn 0
  651.   EndIf
  652.  
  653.   *ptr=GlobalAlloc_(#GMEM_FIXED,sz\lowpart)
  654.   If *ptr=#Null ; the memory can be allocated
  655.     CloseHandle_(Handle)
  656.     ProcedureReturn 0
  657.   EndIf
  658.  
  659.   ReadFile_(Handle,*ptr,sz\lowpart,@readbytes,0)
  660.   CloseHandle_(Handle)
  661.   If readbytes = sz\lowpart
  662.     Result=_OLE_LoadFromMem(*ptr,sz\lowpart)
  663.   EndIf  
  664.   GlobalFree_(*ptr)
  665.   ProcedureReturn Result
  666. EndProcedure
  667.  
  668. ; Loads bmp And dib files from memory.
  669. Procedure _DIB_LoadFromMem(Addr.l)  
  670.   Protected *bmfh.BITMAPFILEHEADER, *bminf.BitmapInfo, hBmp = #Null, MemDC = #Null, OldhBmp = #Null, Result = #False
  671.   If Addr <> #Null
  672.     *bmfh.BITMAPFILEHEADER=Addr
  673.     If *bmfh\bfType='MB' ;  seems to be a bitmap (*.bmp or *.dib), so we don't need the size
  674.       ; load bmp or dib from memory, really short ;)
  675.       *bminf.BitmapInfo=*bmfh+SizeOf(BITMAPFILEHEADER)
  676.       hBmp=CreateDIBSection_(0,*bminf,#DIB_RGB_COLORS,0,0,0)
  677.       If hBmp=0:ProcedureReturn 0:EndIf    
  678.       MemDC=CreateCompatibleDC_(0)
  679.       If MemDC
  680.         OldhBmp=SelectObject_(MemDC,hBmp)
  681.         Result=SetDIBitsToDevice_(MemDC,0,0,*bminf\BmiHeader\biWidth,*bminf\BmiHeader\biHeight,0,0,0,*bminf\BmiHeader\biHeight,*bmfh\bfOffBits+*bmfh,*bminf,#DIB_RGB_COLORS)
  682.         SelectObject_(MemDC,OldhBmp)
  683.         DeleteDC_(MemDC)
  684.       EndIf
  685.       If Result=#False:DeleteObject_(MemDC):ProcedureReturn 0:EndIf
  686.     EndIf
  687.   EndIf
  688.   ProcedureReturn hBmp
  689. EndProcedure
  690.  
  691. ; Loads bmp And dib files from file.
  692. Procedure _DIB_LoadFromFile(File.s)
  693.   ProcedureReturn LoadImage_(0,File.s,#IMAGE_BITMAP,0,0,#LR_LOADFROMFILE|#LR_CREATEDIBSECTION)
  694. EndProcedure
  695.  
  696. Procedure _ICOCUR_LoadFromFile(sFile.s, *width.integer, *height.integer)
  697.   Protected hIcon = #Null, file, head.ICONHEADER,currentWidth.i, currentHeight.i, biggestWidth = 0, biggestHeight = 0
  698.   Protected reserved.i, type.i, count.i,i.i
  699.   file = ReadFile(#PB_Any, sFile)
  700.   If file
  701.     reserved = ReadWord(file)
  702.     If reserved = 0
  703.       type = ReadWord(file)
  704.      
  705.       If type = 1 Or type = 2
  706.         count = ReadWord(file)
  707.        
  708.         If count > 0 And count < 1000
  709.          
  710.           For i = 1 To count
  711.             ReadData(file, head, SizeOf(ICONHEADER))
  712.             currentWidth =  head\bWidth & 255
  713.             If currentWidth = 0:currentWidth = 256:EndIf
  714.             currentHeight =  head\bHeight & 255
  715.             If currentHeight = 0:currentHeight = 256:EndIf
  716.            
  717.             If currentWidth > biggestWidth
  718.               biggestWidth = currentWidth
  719.               biggestHeight = currentHeight
  720.             EndIf      
  721.           Next  
  722.          
  723.           If *width
  724.             *width\i = biggestWidth
  725.           EndIf
  726.           If *height
  727.             *height\i = biggestHeight
  728.           EndIf  
  729.          
  730.           If type = 1
  731.             hIcon = LoadImage_(0,sFile.s,#IMAGE_ICON,biggestWidth, biggestHeight,#LR_LOADFROMFILE)
  732.           EndIf
  733.          
  734.           If type = 2
  735.             hIcon = LoadImage_(0,sFile.s,#IMAGE_CURSOR,biggestWidth, biggestHeight,#LR_LOADFROMFILE)            
  736.           EndIf  
  737.          
  738.         EndIf
  739.       EndIf  
  740.     EndIf
  741.     CloseFile(file)
  742.   EndIf    
  743.   ProcedureReturn hIcon
  744. EndProcedure
  745.  
  746.  
  747. Procedure _DX8_LoadFromFile(File.s)
  748.   Protected *D3DX8.ID3DX8, Surf.MyD3DSURFACE, re.rect, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp, MemDC, OldhNewBmp
  749.   If FileSize(File) < 1
  750.     ProcedureReturn #Null
  751.   EndIf  
  752.   If OSVersion() > #PB_OS_Windows_Server_2003 ; Normally not supported anymore for Vista and above
  753.     ProcedureReturn #Null
  754.   EndIf  
  755.    
  756.   CoCreateInstance_(?CLSID_D3DX8,0,#CLSCTX_INPROC_SERVER,?IID_IUnknown,@*D3DX8.ID3DX8)
  757.   If *D3DX8=0
  758.     ProcedureReturn #Null
  759.   EndIf
  760.  
  761.   Surf.MyD3DSURFACE
  762.   Surf\VTable=?MyD3D8_SurfaceVTable
  763.   Surf\Width=1
  764.   Surf\Height=1
  765.   Surf\Pitch=4
  766.   Surf\pBits=@Surf\BufferData
  767.  
  768.   ; First get the width and height of the image
  769.   re.rect\right=1
  770.   re\bottom=1
  771.   Result=*D3DX8\LoadSurfaceFromFile(Surf,0,re,File,0,1,0,imginfo.D3DXIMAGE_INFO)
  772.   If Result:*D3DX8\Release():ProcedureReturn #Null:EndIf
  773.  
  774.   ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
  775.   BmInf.BitmapInfo\BmiHeader\biBitCount=32
  776.   BmInf\BmiHeader\biCompression=#BI_RGB
  777.   BmInf\BmiHeader\biPlanes=1
  778.   BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  779.   BmInf\BmiHeader\biWidth=imginfo\Width
  780.   BmInf\BmiHeader\biHeight=imginfo\Height
  781.  
  782.   If imginfo\Width <= 0 Or imginfo\Height <= 0
  783.     *D3DX8\Release()
  784.     ProcedureReturn #Null
  785.   EndIf  
  786.  
  787.   hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  788.   If hBmp=0:*D3DX8\Release():ProcedureReturn #Null:EndIf
  789.  
  790.   GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)    
  791.  
  792.   Surf\Pitch=bmi\dsBm\bmWidthBytes
  793.   Surf\pBits=bmi\dsBm\bmBits
  794.   Surf\Width=imginfo\Width
  795.   Surf\Height=imginfo\Height
  796.   If bmi\dsBm\bmBits = #Null
  797.     *D3DX8\Release()
  798.     DeleteObject_(hBmp)
  799.     ProcedureReturn #Null
  800.   EndIf
  801.  
  802.   bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
  803.  
  804.   ; fill dibsection with the data
  805.   Result=*D3DX8\LoadSurfaceFromFile(Surf,0,0,File,0,1,0,0)
  806.   *D3DX8\Release()
  807.   If Result:DeleteObject_(hBmp):ProcedureReturn #Null:EndIf
  808.  
  809.   hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
  810.  
  811.   If hNewBmp=0
  812.     DeleteObject_(hBmp)
  813.     ProcedureReturn #Null
  814.   EndIf
  815.  
  816.   MemDC=CreateCompatibleDC_(0)
  817.   If MemDC
  818.     OldhNewBmp=SelectObject_(MemDC,hNewBmp)  
  819.     Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)  
  820.     SelectObject_(MemDC,hNewBmp)
  821.     DeleteDC_(MemDC)
  822.   EndIf
  823.   DeleteObject_(hBmp)
  824.  
  825.   If Result=0
  826.     DeleteObject_(hNewBmp)
  827.     ProcedureReturn 0
  828.   EndIf
  829.  
  830.   ProcedureReturn hNewBmp
  831. EndProcedure
  832.  
  833.  
  834. Procedure _DX8_LoadFromMem(SrcData.l,LengthInBytes.l)
  835.   Protected *D3DX8.ID3DX8, Surf.MyD3DSURFACE, re.rect, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp
  836.   Protected MemDC, OldhNewBmp
  837.   If SrcData=#Null Or LengthInBytes<=0
  838.     ProcedureReturn #Null
  839.   EndIf
  840.   If OSVersion() > #PB_OS_Windows_Server_2003 ; Normally not supported anymore for Vista and above
  841.     ProcedureReturn #Null
  842.   EndIf  
  843.  
  844.   CoCreateInstance_(?CLSID_D3DX8,0,#CLSCTX_INPROC_SERVER,?IID_IUnknown,@*D3DX8.ID3DX8)
  845.   If *D3DX8=#Null
  846.     ProcedureReturn #Null
  847.   EndIf
  848.  
  849.   Surf.MyD3DSURFACE
  850.   Surf\VTable=?MyD3D8_SurfaceVTable
  851.   Surf\Width=1
  852.   Surf\Height=1
  853.   Surf\Pitch=4
  854.   Surf\pBits=@Surf\BufferData
  855.  
  856.   ; First get the width and height of the image
  857.   re.rect\right=1
  858.   re\bottom=1
  859.   Result=*D3DX8\LoadSurfaceFromFileInMemory(Surf,0,re,SrcData,LengthInBytes,0,1,0,imginfo.D3DXIMAGE_INFO)
  860.   If Result:*D3DX8\Release():ProcedureReturn #Null:EndIf
  861.  
  862.   ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
  863.   BmInf.BitmapInfo\BmiHeader\biBitCount=32
  864.   BmInf\BmiHeader\biCompression=#BI_RGB
  865.   BmInf\BmiHeader\biPlanes=1
  866.   BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  867.   BmInf\BmiHeader\biWidth=imginfo\Width
  868.   BmInf\BmiHeader\biHeight=imginfo\Height
  869.  
  870.   If imginfo\Width <= 0 Or imginfo\Height <= 0
  871.     *D3DX8\Release()
  872.     ProcedureReturn #Null
  873.   EndIf    
  874.  
  875.   hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  876.   If hBmp=0:*D3DX8\Release():ProcedureReturn 0:EndIf
  877.  
  878.   GetObject_(hBmp,SizeOf(DIBSECTION), bmi.DIBSECTION)    
  879.  
  880.   Surf\Pitch=bmi\dsBm\bmWidthBytes
  881.   Surf\pBits=bmi\dsBm\bmBits
  882.   Surf\Width=imginfo\Width
  883.   Surf\Height=imginfo\Height
  884.  
  885.   If bmi\dsBm\bmBits = #Null
  886.     *D3DX8\Release()
  887.     DeleteObject_(hBmp)
  888.     ProcedureReturn #Null
  889.   EndIf
  890.      
  891.   bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
  892.  
  893.   ; fill dibsection with the data
  894.   Result=*D3DX8\LoadSurfaceFromFileInMemory(Surf,0,0,SrcData,LengthInBytes,0,1,0,0)
  895.   *D3DX8\Release()
  896.   If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
  897.  
  898.   hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
  899.  
  900.   If hNewBmp=0
  901.     DeleteObject_(hBmp)
  902.     ProcedureReturn #Null
  903.   EndIf
  904.  
  905.   MemDC=CreateCompatibleDC_(0)
  906.   If MemDC
  907.     OldhNewBmp=SelectObject_(MemDC,hNewBmp)
  908.     Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
  909.     SelectObject_(MemDC,hNewBmp)
  910.     DeleteDC_(MemDC)
  911.   EndIf
  912.   DeleteObject_(hBmp)
  913.  
  914.   If Result=0
  915.     DeleteObject_(hNewBmp)
  916.     ProcedureReturn #Null
  917.   EndIf
  918.  
  919.   ProcedureReturn hNewBmp
  920. EndProcedure
  921.  
  922. Procedure _DX9_LoadFromFile(File.s)
  923.   Protected D3DXInst, D3DX9LoadSurfaceFromFile.D3DX9LoadSurfaceFromFile, D3DX9GetImageInfoFromFile.D3DX9GetImageInfoFromFile, Result = #False
  924.   Protected imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, Surf.MyD3DSURFACE, hNewBmp, MemDC, OldhNewBmp
  925.  
  926.   If FileSize(File) < 1
  927.     ProcedureReturn #Null
  928.   EndIf  
  929.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_43.dll"):EndIf
  930.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_42.dll"):EndIf
  931.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_41.dll"):EndIf
  932.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_40.dll"):EndIf
  933.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_39.dll"):EndIf
  934.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_38.dll"):EndIf
  935.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_37.dll"):EndIf
  936.  
  937.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_36.dll"):EndIf
  938.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_35.dll"):EndIf  
  939.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_34.dll"):EndIf
  940.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_33.dll"):EndIf  
  941.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_32.dll"):EndIf  
  942.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_31.dll"):EndIf
  943.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_30.dll"):EndIf
  944.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_29.dll"):EndIf
  945.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_28.dll"):EndIf
  946.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_27.dll"):EndIf
  947.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_26.dll"):EndIf
  948.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_25.dll"):EndIf
  949.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_24.dll"):EndIf
  950.    
  951.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_43.dll"):EndIf
  952.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_42.dll"):EndIf
  953.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_41.dll"):EndIf
  954.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_40.dll"):EndIf
  955.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_39.dll"):EndIf
  956.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_38.dll"):EndIf
  957.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_37.dll"):EndIf  
  958.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_36.dll"):EndIf
  959.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_35.dll"):EndIf  
  960.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_34.dll"):EndIf
  961.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_33.dll"):EndIf  
  962.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_32.dll"):EndIf
  963.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_31.dll"):EndIf
  964.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_30.dll"):EndIf
  965.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_29.dll"):EndIf
  966.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_28.dll"):EndIf
  967.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_27.dll"):EndIf
  968.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_26.dll"):EndIf
  969.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_25.dll"):EndIf
  970.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_24.dll"):EndIf
  971.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d.dll"):EndIf
  972.  
  973.   If D3DXInst=0:ProcedureReturn 0:EndIf
  974.  
  975.   D3DX9LoadSurfaceFromFile.D3DX9LoadSurfaceFromFile=GetProcAddress_(D3DXInst,"D3DXLoadSurfaceFromFileA")
  976.   D3DX9GetImageInfoFromFile.D3DX9GetImageInfoFromFile=GetProcAddress_(D3DXInst,"D3DXGetImageInfoFromFileA")
  977.  
  978.   If D3DX9LoadSurfaceFromFile=0 Or D3DX9GetImageInfoFromFile=0
  979.     FreeLibrary_(D3DXInst)
  980.     ProcedureReturn 0
  981.   EndIf
  982.  
  983.   ; First get the width and height of the image
  984.   Result=D3DX9GetImageInfoFromFile(@File,imginfo.D3DXIMAGE_INFO)
  985.   ; Result=D3DX9LoadSurfaceFromFile(Surf,0,re,@File,0,1,0,imginfo.D3DXIMAGE_INFO)
  986.  
  987.   If Result:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
  988.  
  989.   ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
  990.   BmInf.BitmapInfo\BmiHeader\biBitCount=32
  991.   BmInf\BmiHeader\biCompression=#BI_RGB
  992.   BmInf\BmiHeader\biPlanes=1
  993.   BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  994.   BmInf\BmiHeader\biWidth=imginfo\Width
  995.   BmInf\BmiHeader\biHeight=imginfo\Height
  996.  
  997.   If imginfo\Width <= 0 Or imginfo\Height <= 0
  998.     FreeLibrary_(D3DXInst):ProcedureReturn 0
  999.   EndIf  
  1000.  
  1001.   hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  1002.   If hBmp=0:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
  1003.  
  1004.   GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)
  1005.  
  1006.   Surf.MyD3DSURFACE
  1007.   Surf\VTable=?MyD3D9_SurfaceVTable  
  1008.   Surf\Pitch=bmi\dsBm\bmWidthBytes
  1009.   Surf\pBits=bmi\dsBm\bmBits
  1010.   Surf\Width=imginfo\Width
  1011.   Surf\Height=imginfo\Height
  1012.  
  1013.   If bmi\dsBm\bmBits = #Null Or bmi\dsBm\bmWidthBytes = 0
  1014.     DeleteObject_(hBmp)
  1015.     FreeLibrary_(D3DXInst)
  1016.     ProcedureReturn 0
  1017.   EndIf  
  1018.  
  1019.   bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
  1020.  
  1021.   ; fill dibsection with the data
  1022.  
  1023.   Result=D3DX9LoadSurfaceFromFile(Surf,0,0,File,0,1,0,0)  
  1024.   FreeLibrary_(D3DXInst)
  1025.   If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
  1026.  
  1027.   hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
  1028.  
  1029.   If hNewBmp=0
  1030.     DeleteObject_(hBmp)
  1031.     ProcedureReturn 0
  1032.   EndIf
  1033.  
  1034.   MemDC=CreateCompatibleDC_(0)
  1035.   If MemDC
  1036.     OldhNewBmp=SelectObject_(MemDC,hNewBmp)
  1037.     Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
  1038.     SelectObject_(MemDC,hNewBmp)
  1039.     DeleteDC_(MemDC)
  1040.   EndIf
  1041.   DeleteObject_(hBmp)
  1042.  
  1043.   If Result=0
  1044.     DeleteObject_(hNewBmp)
  1045.     ProcedureReturn 0
  1046.   EndIf
  1047.  
  1048.   ProcedureReturn hNewBmp
  1049. EndProcedure
  1050.  
  1051.  
  1052. Procedure _DX9_LoadFromMem(SrcData.l,LengthInBytes.l)
  1053.   Protected D3DXInst, D3DX9LoadSurfaceFromFileInMemory.D3DX9LoadSurfaceFromFileInMemory, D3DX9GetImageInfoFromFileInMemory.D3DX9GetImageInfoFromFileInMemory
  1054.   Protected Surf.MyD3DSURFACE, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp, MemDC, OldhNewBmp
  1055.   If SrcData=#Null Or LengthInBytes<=0
  1056.     ProcedureReturn 0
  1057.   EndIf
  1058.  
  1059.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_43.dll"):EndIf
  1060.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_42.dll"):EndIf
  1061.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_41.dll"):EndIf
  1062.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_40.dll"):EndIf
  1063.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_39.dll"):EndIf
  1064.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_38.dll"):EndIf
  1065.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_37.dll"):EndIf
  1066.  
  1067.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_36.dll"):EndIf
  1068.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_35.dll"):EndIf  
  1069.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_34.dll"):EndIf
  1070.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_33.dll"):EndIf  
  1071.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_32.dll"):EndIf  
  1072.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_31.dll"):EndIf
  1073.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_30.dll"):EndIf
  1074.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_29.dll"):EndIf
  1075.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_28.dll"):EndIf
  1076.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_27.dll"):EndIf
  1077.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_26.dll"):EndIf
  1078.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_25.dll"):EndIf
  1079.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_24.dll"):EndIf
  1080.  
  1081.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_43.dll"):EndIf
  1082.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_42.dll"):EndIf
  1083.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_41.dll"):EndIf
  1084.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_40.dll"):EndIf
  1085.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_39.dll"):EndIf
  1086.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_38.dll"):EndIf  
  1087.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_36.dll"):EndIf
  1088.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_35.dll"):EndIf  
  1089.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_34.dll"):EndIf
  1090.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_33.dll"):EndIf  
  1091.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_32.dll"):EndIf
  1092.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_31.dll"):EndIf
  1093.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_30.dll"):EndIf
  1094.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_29.dll"):EndIf
  1095.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_28.dll"):EndIf
  1096.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_27.dll"):EndIf
  1097.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_26.dll"):EndIf
  1098.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_25.dll"):EndIf
  1099.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_24.dll"):EndIf
  1100.   If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d.dll"):EndIf
  1101.  
  1102.   If D3DXInst=0:ProcedureReturn 0:EndIf  
  1103.  
  1104.   D3DX9LoadSurfaceFromFileInMemory.D3DX9LoadSurfaceFromFileInMemory=GetProcAddress_(D3DXInst,"D3DXLoadSurfaceFromFileInMemory")
  1105.   D3DX9GetImageInfoFromFileInMemory.D3DX9GetImageInfoFromFileInMemory=GetProcAddress_(D3DXInst,"D3DXGetImageInfoFromFileInMemory")
  1106.  
  1107.   If D3DX9GetImageInfoFromFileInMemory=0 Or D3DX9LoadSurfaceFromFileInMemory=0
  1108.     FreeLibrary_(D3DXInst)
  1109.     ProcedureReturn 0
  1110.   EndIf
  1111.  
  1112.   Surf.MyD3DSURFACE
  1113.   Surf\VTable=?MyD3D9_SurfaceVTable
  1114.   ; First get the width and height of the image
  1115.   Result=D3DX9GetImageInfoFromFileInMemory(SrcData.l,LengthInBytes.l,imginfo.D3DXIMAGE_INFO)
  1116.   ; Result=D3DX9LoadSurfaceFromFile(Surf,0,re,@File,0,1,0,imginfo.D3DXIMAGE_INFO)
  1117.  
  1118.   If Result:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
  1119.  
  1120.   ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
  1121.   BmInf.BitmapInfo\BmiHeader\biBitCount=32
  1122.   BmInf\BmiHeader\biCompression=#BI_RGB
  1123.   BmInf\BmiHeader\biPlanes=1
  1124.   BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  1125.   BmInf\BmiHeader\biWidth=imginfo\Width
  1126.   BmInf\BmiHeader\biHeight=imginfo\Height
  1127.  
  1128.   If imginfo\Width <= 0 Or imginfo\Height <= 0
  1129.     FreeLibrary_(D3DXInst):ProcedureReturn 0
  1130.   EndIf  
  1131.  
  1132.   hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  1133.   If hBmp=0:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
  1134.  
  1135.   GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)    
  1136.  
  1137.   Surf\Pitch=bmi\dsBm\bmWidthBytes
  1138.   Surf\pBits=bmi\dsBm\bmBits
  1139.   Surf\Width=imginfo\Width
  1140.   Surf\Height=imginfo\Height
  1141.  
  1142.   If bmi\dsBm\bmBits = #Null Or bmi\dsBm\bmWidthBytes = 0
  1143.     DeleteObject_(hBmp)
  1144.     FreeLibrary_(D3DXInst)
  1145.     ProcedureReturn 0
  1146.   EndIf  
  1147.  
  1148.   bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
  1149.  
  1150.   ; fill dibsection with the data
  1151.   Result=D3DX9LoadSurfaceFromFileInMemory(Surf,0,0,SrcData.l,LengthInBytes.l,0,1,0,0)
  1152.   FreeLibrary_(D3DXInst)
  1153.   If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
  1154.  
  1155.   hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
  1156.  
  1157.   If hNewBmp=0
  1158.     DeleteObject_(hBmp)
  1159.     ProcedureReturn 0
  1160.   EndIf
  1161.  
  1162.   MemDC=CreateCompatibleDC_(0)
  1163.   If MemDC
  1164.     OldhNewBmp=SelectObject_(MemDC,hNewBmp)  
  1165.     Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)  
  1166.     SelectObject_(MemDC,hNewBmp)
  1167.     DeleteDC_(MemDC)
  1168.   EndIf
  1169.   DeleteObject_(hBmp)
  1170.  
  1171.   If Result=0
  1172.     DeleteObject_(hNewBmp)
  1173.     ProcedureReturn 0
  1174.   EndIf
  1175.  
  1176.   ProcedureReturn hNewBmp
  1177. EndProcedure
  1178.  
  1179.  
  1180. Procedure _GDIP_LoadFromFile(sFile.s)
  1181.   Protected gdip, GdiplusStartup.GdiplusStartup, GdiplusShutdown.GdiplusShutdown, GdipAlloc.GdipAlloc, GdipFree.GdipFree
  1182.   Protected GdipCreateFromHDC.GdipCreateFromHDC, GdipDrawImageI.GdipDrawImageI, GdipDeleteGraphics.GdipDeleteGraphics
  1183.   Protected GdipGetImageWidth.GdipGetImageWidth, GdipGetImageHeight.GdipGetImageHeight, GdipDisposeImage.GdipDisposeImage
  1184.   Protected GdipCreateBitmapFromFile.GdipCreateBitmapFromFile, gdpsi.GdiplusStartupInput, gdiptoken, File, Image, lWidth, lHeight
  1185.   Protected BmInf.BitmapInfo, hBmp = #Null, MemDC = #Null, hOldBmp = #Null, GraphObj = #Null, lResult, GrapObj
  1186.  
  1187.   If FileSize(sFile) < 1
  1188.     ProcedureReturn 0
  1189.   EndIf  
  1190.  
  1191.   gdip=LoadLibrary_("gdiplus.dll")
  1192.   If gdip=0:ProcedureReturn #False:EndIf
  1193.  
  1194.   GdiplusStartup.GdiplusStartup=GetProcAddress_(gdip,"GdiplusStartup")
  1195.   GdiplusShutdown.GdiplusShutdown=GetProcAddress_(gdip,"GdiplusShutdown")
  1196.   GdipAlloc.GdipAlloc=GetProcAddress_(gdip,"GdipAlloc")
  1197.   GdipFree.GdipFree=GetProcAddress_(gdip,"GdipFree")
  1198.   If GdiplusStartup=0 Or GdiplusShutdown=0 Or GdipAlloc=0 Or GdipFree=0
  1199.     FreeLibrary_(gdip)
  1200.     ProcedureReturn 0
  1201.   EndIf
  1202.   GdipCreateFromHDC.GdipCreateFromHDC=GetProcAddress_(gdip,"GdipCreateFromHDC")
  1203.   GdipDrawImageI.GdipDrawImageI=GetProcAddress_(gdip,"GdipDrawImageI")
  1204.   GdipDeleteGraphics.GdipDeleteGraphics=GetProcAddress_(gdip,"GdipDeleteGraphics")
  1205.   If GdipCreateFromHDC=0 Or GdipDrawImageI=0 Or GdipDeleteGraphics=0
  1206.     FreeLibrary_(gdip)
  1207.     ProcedureReturn 0
  1208.   EndIf  
  1209.  
  1210.   GdipGetImageWidth.GdipGetImageWidth=GetProcAddress_(gdip,"GdipGetImageWidth")
  1211.   GdipGetImageHeight.GdipGetImageHeight=GetProcAddress_(gdip,"GdipGetImageHeight")
  1212.   GdipDisposeImage.GdipDisposeImage=GetProcAddress_(gdip,"GdipDisposeImage")
  1213.   GdipCreateBitmapFromFile.GdipCreateBitmapFromFile=GetProcAddress_(gdip,"GdipCreateBitmapFromFile")
  1214.   If GdipGetImageHeight=0 Or GdipGetImageWidth=0 Or GdipCreateBitmapFromFile=0 Or GdipDisposeImage=0
  1215.     FreeLibrary_(gdip)
  1216.     ProcedureReturn 0
  1217.   EndIf
  1218.  
  1219.   gdpsi.GdiplusStartupInput\GdiplusVersion=1
  1220.   GdiplusStartup(@gdiptoken,gdpsi,0)
  1221.  
  1222.   If gdiptoken
  1223.    
  1224.     File = GdipAlloc(2 * 2048 + 2);#MAX_PATH*2)
  1225.     If File
  1226.      
  1227.       MultiByteToWideChar_(0,0,sFile, -1,File, 2048)
  1228.       GdipCreateBitmapFromFile(File,@Image)
  1229.       If Image
  1230.        
  1231.         GdipGetImageWidth(Image,@lWidth)
  1232.         GdipGetImageHeight(Image,@lHeight)
  1233.        
  1234.         BmInf.BitmapInfo\BmiHeader\biBitCount=32
  1235.         BmInf\BmiHeader\biCompression=#BI_RGB
  1236.         BmInf\BmiHeader\biPlanes=1
  1237.         BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  1238.         BmInf\BmiHeader\biWidth=lWidth
  1239.         BmInf\BmiHeader\biHeight=lHeight
  1240.         If lWidth > 0 And lHeight > 0
  1241.           hBmp = CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  1242.         EndIf
  1243.        
  1244.         If hBmp
  1245.           MemDC=CreateCompatibleDC_(0)      
  1246.           If MemDC
  1247.             hOldBmp=SelectObject_(MemDC, hBmp)
  1248.             GdipCreateFromHDC(MemDC,@GraphObj)
  1249.             If GraphObj
  1250.               lResult=GdipDrawImageI(GraphObj,Image,0,0)            
  1251.               GdipDeleteGraphics(GrapObj)
  1252.               SelectObject_(MemDC,hOldBmp)      
  1253.             Else
  1254.               lResult=#E_FAIL
  1255.             EndIf
  1256.             DeleteDC_(MemDC)
  1257.           Else
  1258.             lResult=#E_FAIL
  1259.           EndIf    
  1260.         EndIf
  1261.        
  1262.         GdipDisposeImage(image)
  1263.       EndIf
  1264.      
  1265.       GdipFree(File)
  1266.     EndIf
  1267.     GdiplusShutdown(gdiptoken)
  1268.   EndIf
  1269.   FreeLibrary_(gdip)
  1270.  
  1271.   If lResult<>#S_OK:DeleteObject_(hBmp):hBmp=0:EndIf
  1272.  
  1273.   ProcedureReturn hBmp
  1274. EndProcedure
  1275.  
  1276.  
  1277. Procedure _GDIP_LoadFromMem(Addr.l,size.l)
  1278.   Protected gdip, GdiplusStartup.GdiplusStartup, GdiplusShutdown.GdiplusShutdown, GdipAlloc.GdipAlloc
  1279.   Protected GdipCreateFromHDC.GdipCreateFromHDC, GdipFree.GdipFree, GdipDrawImageI.GdipDrawImageI, GdipDeleteGraphics.GdipDeleteGraphics
  1280.   Protected GdipGetImageWidth.GdipGetImageWidth, GdipGetImageHeight.GdipGetImageHeight, GdipDisposeImage.GdipDisposeImage
  1281.   Protected GdipCreateBitmapFromStream.GdipCreateBitmapFromStream, Mem, *ptr, *Stream.IStream, gdpsi.GdiplusStartupInput, gdiptoken
  1282.   Protected Image, lWidth, lHeight, BmInf.BitmapInfo, hBmp, MemDC, hOldBmp, GraphObj, lResult
  1283.   If Addr=#Null Or Size<=0
  1284.     ProcedureReturn 0
  1285.   EndIf
  1286.  
  1287.   gdip=LoadLibrary_("gdiplus.dll")
  1288.   If gdip=0:ProcedureReturn #False:EndIf
  1289.  
  1290.   GdiplusStartup.GdiplusStartup=GetProcAddress_(gdip,"GdiplusStartup")
  1291.   GdiplusShutdown.GdiplusShutdown=GetProcAddress_(gdip,"GdiplusShutdown")
  1292.   GdipAlloc.GdipAlloc=GetProcAddress_(gdip,"GdipAlloc")
  1293.   GdipFree.GdipFree=GetProcAddress_(gdip,"GdipFree")
  1294.   If GdiplusStartup=0 Or GdiplusShutdown=0 Or GdipAlloc=0 Or GdipFree=0
  1295.     FreeLibrary_(gdip)
  1296.     ProcedureReturn 0
  1297.   EndIf
  1298.   GdipCreateFromHDC.GdipCreateFromHDC=GetProcAddress_(gdip,"GdipCreateFromHDC")
  1299.   GdipDrawImageI.GdipDrawImageI=GetProcAddress_(gdip,"GdipDrawImageI")
  1300.   GdipDeleteGraphics.GdipDeleteGraphics=GetProcAddress_(gdip,"GdipDeleteGraphics")
  1301.   If GdipCreateFromHDC=0 Or GdipDrawImageI=0 Or GdipDeleteGraphics=0
  1302.     FreeLibrary_(gdip)
  1303.     ProcedureReturn 0
  1304.   EndIf  
  1305.  
  1306.   GdipGetImageWidth.GdipGetImageWidth=GetProcAddress_(gdip,"GdipGetImageWidth")
  1307.   GdipGetImageHeight.GdipGetImageHeight=GetProcAddress_(gdip,"GdipGetImageHeight")
  1308.   GdipDisposeImage.GdipDisposeImage=GetProcAddress_(gdip,"GdipDisposeImage")
  1309.   GdipCreateBitmapFromStream.GdipCreateBitmapFromStream=GetProcAddress_(gdip,"GdipCreateBitmapFromStream")
  1310.   If GdipGetImageHeight=0 Or GdipGetImageWidth=0 Or GdipCreateBitmapFromStream=0 Or GdipDisposeImage=0
  1311.     FreeLibrary_(gdip)
  1312.     ProcedureReturn 0
  1313.   EndIf
  1314.  
  1315.   Mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)  
  1316.   *ptr=GlobalLock_(Mem)
  1317.  
  1318.   If *ptr=0 ; if GlobalAlloc or GlobalLock failed
  1319.     FreeLibrary_(gdip)
  1320.     GlobalFree_(Mem)
  1321.     ProcedureReturn 0
  1322.   EndIf
  1323.  
  1324.   RtlMoveMemory_(*ptr,Addr,Size)
  1325.   GlobalUnlock_(Mem)
  1326.  
  1327.   CreateStreamOnHGlobal_(Mem, 1, @*Stream.IStream)
  1328.  
  1329.   If *Stream=0
  1330.     FreeLibrary_(gdip)
  1331.     GlobalFree_(Mem)
  1332.     ProcedureReturn 0
  1333.   EndIf
  1334.  
  1335.   gdpsi.GdiplusStartupInput\GdiplusVersion=1
  1336.   GdiplusStartup(@gdiptoken,gdpsi,0)
  1337.  
  1338.   If gdiptoken
  1339.    
  1340.     GdipCreateBitmapFromStream(*Stream,@Image)
  1341.     If image
  1342.       GdipGetImageWidth(Image,@lWidth)
  1343.       GdipGetImageHeight(Image,@lHeight)
  1344.      
  1345.       BmInf.BitmapInfo\BmiHeader\biBitCount=32
  1346.       BmInf\BmiHeader\biCompression=#BI_RGB
  1347.       BmInf\BmiHeader\biPlanes=1
  1348.       BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
  1349.       BmInf\BmiHeader\biWidth=lWidth
  1350.       BmInf\BmiHeader\biHeight=lHeight
  1351.      
  1352.       hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
  1353.      
  1354.       If hBmp
  1355.         MemDC=CreateCompatibleDC_(0)
  1356.          
  1357.         If MemDC
  1358.           hOldBmp=SelectObject_(MemDC,hBmp)
  1359.           GdipCreateFromHDC(MemDC,@GraphObj)
  1360.           If GraphObj
  1361.             lResult=GdipDrawImageI(GraphObj,Image,0,0)            
  1362.             GdipDeleteGraphics(GraphObj)
  1363.             SelectObject_(MemDC,hOldBmp)
  1364.            
  1365.           Else
  1366.             lResult=#E_FAIL
  1367.           EndIf
  1368.           DeleteDC_(MemDC)
  1369.         Else
  1370.           lResult=#E_FAIL
  1371.         EndIf
  1372.        
  1373.       EndIf
  1374.      
  1375.       GdipDisposeImage(image)
  1376.     EndIf
  1377.     GdiplusShutdown(gdiptoken)
  1378.   EndIf
  1379.   FreeLibrary_(gdip)
  1380.   *Stream\Release()
  1381.  
  1382.   If lResult<>#S_OK:DeleteObject_(hBmp):hBmp=0:EndIf
  1383.   ProcedureReturn hBmp
  1384. EndProcedure
  1385.  
  1386.  
  1387. ;LoadImageEx() can load bmp,jpg,png and gif files, so you don't need huge imageplugins to load these formats
  1388. ;LoadImageEx() works only if Internet Explorer 4.x or later is installed
  1389. ;CatchImageEx() can load bmp,dib,jpg,png,wmf and gif files (tif not correctly), so you don't need huge imageplugins to load these formats
  1390. ;CatchImageEx() works only if Internet Explorer 4.x or later is installed
  1391.  
  1392. Procedure __CreateStreamFromMem(Addr.l,Size.l)
  1393.   Protected mem,*ptr,Stream.IStream
  1394.   mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)
  1395.   If mem
  1396.     *ptr=GlobalLock_(mem)
  1397.     If *ptr
  1398.       CopyMemory(Addr,*ptr,Size)
  1399.       CreateStreamOnHGlobal_(mem,#True,@Stream.IStream)
  1400.       GlobalUnlock_(mem)
  1401.     EndIf
  1402.     If Stream=0:GlobalFree_(mem):EndIf
  1403.   EndIf
  1404.   ProcedureReturn Stream
  1405. EndProcedure
  1406. ;
  1407. ;
  1408. Procedure _DXTF_LoadFromMem(Image,Addr,Size,Flags=0)
  1409.   Protected dxtf.IDXTransformFactory, Stream.IStream, DC, lock.IDXDCLock, surf.IDXSurface
  1410.   Protected result, re.rect, DestDC,dxsf.nIDXSurfaceFactory,Success
  1411.   If Addr=#Null Or Size <=0
  1412.     ProcedureReturn #Null
  1413.   EndIf  
  1414.  
  1415.   CoCreateInstance_(?CLSID_DXTransformFactory,0,#CLSCTX_INPROC_SERVER,?IID_IDXTransformFactory,@dxtf.IDXTransformFactory)
  1416.  
  1417.   If dxtf
  1418.     dxtf\QueryService(?IID_IDXSurfaceFactory,?IID_IDXSurfaceFactory,@dxsf.nIDXSurfaceFactory)
  1419.     If dxsf
  1420.      
  1421.       Stream.IStream=__CreateStreamFromMem(Addr,Size)
  1422.      
  1423.       If Stream
  1424.        
  1425.         dxsf\LoadImageFromStream(Stream,0,0,0,?IID_IDXSurface,@surf.IDXSurface)
  1426.         If surf
  1427.          
  1428.           surf\LockSurfaceDC(0,#INFINITE,#DXLOCKF_READ,@lock.IDXDCLock)
  1429.           If lock
  1430.             DC=lock\GetDC()
  1431.            
  1432.             If DC
  1433.               GetClipBox_(DC,re.rect)
  1434.              
  1435.               If Image=#PB_Any
  1436.                 result=CreateImage(#PB_Any,re\right,re\bottom,Flags)
  1437.                 Image=result
  1438.               Else
  1439.                 result=CreateImage(Image,re\right,re\bottom,Flags)
  1440.               EndIf
  1441.              
  1442.               If result
  1443.                
  1444.                 DestDC=StartDrawing(ImageOutput(Image))  
  1445.                 If DestDC
  1446.                   Success=BitBlt_(DestDC,0,0,re\right,re\bottom,DC,0,0,#SRCCOPY)
  1447.                   StopDrawing()        
  1448.                 EndIf
  1449.                
  1450.                 If Success=#False:FreeImage(Image):EndIf
  1451.               EndIf
  1452.             EndIf
  1453.            
  1454.             Lock\Release()    
  1455.           EndIf
  1456.          
  1457.           surf\Release()
  1458.         EndIf
  1459.        
  1460.         dxsf\Release()
  1461.       EndIf
  1462.      
  1463.       Stream\Release()
  1464.     EndIf
  1465.    
  1466.     dxtf\Release()
  1467.   EndIf
  1468.  
  1469.   If Success:ProcedureReturn result:EndIf
  1470.   ProcedureReturn #False
  1471. EndProcedure
  1472.  
  1473.  
  1474. Procedure _DXTF_LoadFromFile(Image,FileName.s,Flags=0)
  1475.   Protected dxtf.IDXTransformFactory, Stream.IStream, DC, lock.IDXDCLock, surf.IDXSurface
  1476.   Protected result, re.rect, DestDC,dxsf.nIDXSurfaceFactory,Success  
  1477.   If FileSize(Filename) < 1 ; do not allow URL
  1478.     ProcedureReturn #Null
  1479.   EndIf  
  1480.  
  1481.   CoCreateInstance_(?CLSID_DXTransformFactory,0,#CLSCTX_INPROC_SERVER,?IID_IDXTransformFactory,@dxtf.IDXTransformFactory)
  1482.  
  1483.   If dxtf
  1484.     dxtf\QueryService(?IID_IDXSurfaceFactory,?IID_IDXSurfaceFactory,@dxsf.nIDXSurfaceFactory)
  1485.     If dxsf
  1486.       dxsf\LoadImage(FileName,0,0,0,?IID_IDXSurface,@surf.IDXSurface)
  1487.       If surf
  1488.        
  1489.         surf\LockSurfaceDC(0,#INFINITE,#DXLOCKF_READ,@lock.IDXDCLock)
  1490.         If lock
  1491.           DC=lock\GetDC()
  1492.          
  1493.           If DC
  1494.             GetClipBox_(DC,re.rect)
  1495.            
  1496.             If Image=#PB_Any
  1497.               result=CreateImage(#PB_Any,re\right,re\bottom,Flags)
  1498.               Image=result
  1499.             Else
  1500.               result=CreateImage(Image,re\right,re\bottom,Flags)
  1501.             EndIf
  1502.            
  1503.             If result
  1504.              
  1505.               DestDC=StartDrawing(ImageOutput(Image))  
  1506.               If DestDC
  1507.                 Success=BitBlt_(DestDC,0,0,re\right,re\bottom,DC,0,0,#SRCCOPY)
  1508.                 StopDrawing()        
  1509.               EndIf
  1510.              
  1511.               If Success=#False:FreeImage(Image):EndIf
  1512.             EndIf
  1513.           EndIf
  1514.          
  1515.           Lock\Release()    
  1516.         EndIf
  1517.        
  1518.         surf\Release()
  1519.       EndIf
  1520.      
  1521.       dxsf\Release()
  1522.     EndIf
  1523.    
  1524.     dxtf\Release()
  1525.   EndIf
  1526.   If Success:ProcedureReturn result:EndIf
  1527.   ProcedureReturn #False
  1528. EndProcedure
  1529.  
  1530.  
  1531.  
  1532. Procedure __WIC_ConvertStream(*in_stream.IStream, *out_stream.IStream, *src_CLSID, *dst_CLSID, *dst_Format)
  1533.   Protected *src.IWICBitmapFrameDecode = #Null
  1534.   Protected *dst.IWICBitmapFrameEncode = #Null
  1535.   Protected *pDec.IWICBitmapDecoder = #Null
  1536.   Protected *pEnc.IWICBitmapEncoder = #Null
  1537.   Protected width.i, height.i, bResult = #False
  1538.  
  1539.   If *in_stream <> #Null And *out_stream <> #Null
  1540.     CoCreateInstance_(*src_CLSID, #Null, #CLSCTX_INPROC_SERVER, @IID_IWICBitmapDecoder, @*pDec)
  1541.     CoCreateInstance_(*dst_CLSID, #Null, #CLSCTX_INPROC_SERVER, @IID_IWICBitmapEncoder, @*pEnc)
  1542.    
  1543.     If *pDec And *pEnc
  1544.       If *pDec\Initialize(*in_stream, #WICDecodeMetadataCacheOnDemand) = #S_OK
  1545.         If *pDec\GetFrame(0, @*src) = #S_OK
  1546.           If *src\GetSize(@width, @height) = #S_OK  
  1547.             If *pEnc\Initialize(*out_stream, #WICBitmapEncoderNoCache) = #S_OK
  1548.               If *pEnc\CreateNewFrame(@*dst, #Null) = #S_OK
  1549.                
  1550.                 If *dst\Initialize(#Null) = #S_OK
  1551.                   If *dst\SetSize(width, height) = #S_OK
  1552.                     If *dst\SetPixelFormat(*dst_Format) = #S_OK
  1553.                       If *dst\WriteSource(*src, #Null) = #S_OK
  1554.                         *dst\Commit()
  1555.                         *pEnc\Commit()
  1556.                         bResult = #True
  1557.                       EndIf
  1558.                     EndIf
  1559.                   EndIf
  1560.                 EndIf
  1561.               EndIf
  1562.             EndIf
  1563.           EndIf
  1564.         EndIf
  1565.       EndIf
  1566.     EndIf
  1567.   EndIf
  1568.  
  1569.   If *src
  1570.     *src\Release()  
  1571.   EndIf
  1572.   If *dst
  1573.     *dst\Release()
  1574.   EndIf  
  1575.   If *pDec
  1576.     *pDec\Release()
  1577.   EndIf  
  1578.   If *pEnc
  1579.     *pEnc\Release()
  1580.   EndIf  
  1581.   ProcedureReturn bResult
  1582. EndProcedure
  1583.  
  1584.  
  1585. Procedure _WIC_LoadFrom(sFile.s, *addr = #Null, size = 0)
  1586.   Protected *in_stream.IStream, *out_stream.IStream
  1587.   Protected hGlobal, *ptr, image = #Null, bResult.i
  1588.  
  1589.   If sFile <> ""
  1590.     SHCreateStreamOnFile_(sFile,#STGM_READ,@*in_stream.IStream)
  1591.   Else
  1592.     CreateStreamOnHGlobal_(#Null, #True, @*in_stream.IStream)
  1593.     If *in_stream <> #Null
  1594.       *in_stream\Write(*addr, size, #Null)
  1595.     EndIf  
  1596.   EndIf  
  1597.   CreateStreamOnHGlobal_(#Null, #True, @*out_stream.IStream)      
  1598.  
  1599.   ;Note: PNG,BMP make no sense, because, we are expecting here a PNG and BMP decoder!!
  1600.   bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICWmpDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)
  1601.   If bResult = #False
  1602.     bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICGifDecoder, @CLSID_WICPngEncoder, @WICPixelFormat32bppBGRA)  
  1603.   EndIf  
  1604.   If bResult = #False
  1605.     bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICIcoDecoder, @CLSID_WICPngEncoder, @WICPixelFormat32bppBGRA)  
  1606.   EndIf      
  1607.   If bResult = #False
  1608.     bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICJpegDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)  
  1609.   EndIf  
  1610.   ;If bResult = #False
  1611.   ;  bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICPngDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)  
  1612.   ;EndIf
  1613.   If bResult = #False
  1614.     bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICTiffDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)  
  1615.   EndIf  
  1616.  
  1617.   If bResult And *out_stream<> #Null
  1618.     GetHGlobalFromStream_(*out_stream, @hGlobal)
  1619.     If hGlobal
  1620.       *ptr = GlobalLock_(hGlobal)
  1621.       If *ptr
  1622.         image = CatchImage(#PB_Any, *ptr, GlobalSize_(hGlobal))  
  1623.         GlobalUnlock_(hGlobal)
  1624.       EndIf  
  1625.     EndIf  
  1626.   EndIf
  1627.  
  1628.   If *in_stream
  1629.     *in_stream\Release()
  1630.   EndIf
  1631.   If *out_stream
  1632.     *out_stream\Release()
  1633.   EndIf  
  1634.  
  1635.   ProcedureReturn image
  1636. EndProcedure
  1637.  
  1638.  
  1639. Procedure _WIC_SaveToFile(Image, sFile.s)
  1640.  
  1641. EndProcedure
  1642.  
  1643.  
  1644.  
  1645. Procedure _ImgLoader_Load(File.s) ; returns the ImageID
  1646.   Protected lResult, hBmp
  1647.   hBmp=_DIB_LoadFromFile(File)
  1648.   If hBmp=0
  1649.     hBmp=_DX9_LoadFromFile(File)
  1650.   EndIf
  1651.   If hBmp=0
  1652.     hBmp=_DX8_LoadFromFile(File) ;Only WIN XP/2003 and older
  1653.   EndIf
  1654.   If hBmp=0
  1655.     hBmp=_GDIP_LoadFromFile(File) ;GDIP has alpha channel for ico, gif
  1656.   EndIf  
  1657.   If hBmp=0
  1658.     hBmp=_OLE_LoadFromFile(File)
  1659.   EndIf
  1660.   If hBmp=0
  1661.     hBmp=_IMGCTX_LoadFromFile(File)
  1662.   EndIf
  1663.   ProcedureReturn hBmp
  1664. EndProcedure
  1665.  
  1666. Procedure _ImgLoader_LoadMem(Addr.l,Size.l) ; returns the ImageID
  1667.   Protected lResult, hBmp
  1668.   hBmp=_DIB_LoadFromMem(Addr)
  1669.   If Size
  1670.     If hBmp=0
  1671.       hBmp=_DX9_LoadFromMem(Addr,Size)
  1672.     EndIf
  1673.     If hBmp=0
  1674.       hBmp=_DX8_LoadFromMem(Addr,Size) ;Only WIN XP/2003 and older
  1675.     EndIf      
  1676.     If hBmp=0
  1677.       hBmp=_GDIP_LoadFromMem(Addr,Size) ;GDIP has alpha channel for ico, gif
  1678.     EndIf
  1679.     If hBmp=0
  1680.       hBmp=_OLE_LoadFromMem(Addr,Size)
  1681.     EndIf
  1682.   EndIf
  1683.   ProcedureReturn hBmp
  1684. EndProcedure
  1685.  
  1686. Procedure _GetPBImage(ImageID.i, width, height)
  1687.   Protected Bmp.BITMAP, PBImage, hDC
  1688.   If width <= 0 Or height <=0 ; tricky: so that it works also for icons, using pb api ImageWidth()...
  1689.     GetObject_(ImageID,SizeOf(BITMAP), Bmp.BITMAP)
  1690.     width = Bmp\bmWidth
  1691.     height = Bmp\bmHeight
  1692.   EndIf
  1693.   PBImage = CreateImage(#PB_Any,width,height, 32)
  1694.   If PBImage
  1695.     hDC = StartDrawing(ImageOutput(PBImage))
  1696.     DrawingMode(#PB_2DDrawing_AllChannels) ; Alpha channel for GDIP with ico, gif!
  1697.     DrawImage(ImageID,0,0)
  1698.     StopDrawing()
  1699.   EndIf
  1700.   ProcedureReturn PBImage
  1701. EndProcedure
  1702.  
  1703. Procedure ImagePlugin_Initailize()
  1704.   Protected lResult.i
  1705.   lResult = CoInitialize_(0)
  1706.   UsePNGImageDecoder()
  1707.   UsePNGImageEncoder()
  1708.   UseJPEG2000ImageDecoder()
  1709.   UseJPEG2000ImageEncoder()
  1710.   UseJPEGImageDecoder()
  1711.   UseJPEGImageEncoder()
  1712.   UseTGAImageDecoder()
  1713.   UseTIFFImageDecoder()
  1714.   ;If lResult=#S_OK Or lResult=#S_FALSE:CoUninitialize_():EndIf
  1715. EndProcedure  
  1716.  
  1717. Procedure ImagePlugin_LoadFromFile(sFile.s)
  1718.   Protected Image.i, NewImage, hBitmap.i, hIcon.i, width.i, height.i
  1719.   ;First try to load icon, cursor in full size!
  1720.   hIcon = _ICOCUR_LoadFromFile(sFile, @width, @height)
  1721.   If hIcon
  1722.     Image = _GetPBImage(hIcon, width, height)
  1723.     DestroyIcon_(hIcon)
  1724.   EndIf  
  1725.   If Not IsImage(Image)
  1726.     Image = LoadImage(#PB_Any, sFile)
  1727.     If IsImage(Image)
  1728.       If GetObjectType_(ImageID(Image)) <> #OBJ_BITMAP
  1729.         ;Probably an Icon, however icons should already loaded by _ICOCUR_LoadFromFile(), so just free
  1730.         ;this here, because we need a hBitmap no icon
  1731.         FreeImage(Image)
  1732.         Image = #Null
  1733.       EndIf  
  1734.     EndIf  
  1735.   EndIf
  1736.   If Not IsImage(Image)
  1737.     Image = _WIC_LoadFrom(sFile)
  1738.   EndIf  
  1739.   If Not IsImage(Image)
  1740.     hBitmap = _ImgLoader_Load(sFile)
  1741.     If hBitmap
  1742.       Image = _GetPBImage(hBitmap, 0, 0)
  1743.       DeleteObject_(hBitmap)
  1744.     EndIf  
  1745.   EndIf
  1746.   ProcedureReturn Image
  1747. EndProcedure
  1748.  
  1749. Procedure ImagePlugin_LoadFromMemory(*pointer, iSize.i)
  1750.   Protected Image.i, hBitmap.i
  1751.   Image = CatchImage(#PB_Any, *pointer, iSize)
  1752.   If IsImage(Image)
  1753.     If GetObjectType_(ImageID(Image)) <> #OBJ_BITMAP
  1754.       ;Probably an Icon...
  1755.       ;free this here, because we need a hBitmap no icon
  1756.       FreeImage(Image)
  1757.       Image = #Null
  1758.     EndIf  
  1759.   EndIf    
  1760.   If Not IsImage(Image)
  1761.     Image = _WIC_LoadFrom("", *pointer, iSize)
  1762.   EndIf  
  1763.   If Not IsImage(Image)
  1764.     hBitmap = _ImgLoader_LoadMem(*pointer, iSize)
  1765.     If hBitmap
  1766.       Image = _GetPBImage(hBitmap, 0, 0)
  1767.       DeleteObject_(hBitmap)
  1768.     EndIf  
  1769.   EndIf  
  1770.   ProcedureReturn Image
  1771. EndProcedure
  1772.  
  1773.  
  1774.  
  1775. ;
  1776. ;
  1777. ; Procedure GetShellThumbnail(FileName$, Image, Width, Height, Depth = #PB_Image_DisplayFormat)
  1778. ;   Protected Result = 0, ImageResult
  1779. ;   Protected Desktop.IShellFolder, Folder.IShellFolder
  1780. ;   Protected Extract.IExtractImage
  1781. ;   Protected *pidlFolder.ITEMIDLIST, *pidlFile.ITEMIDLIST  
  1782. ;   Protected Priority, Flags, Bitmap = 0, size.SIZE
  1783. ;   #IEIFLAG_QUALITY = $200
  1784. ;   Flags = #IEIFLAG_QUALITY
  1785. ;  
  1786. ;   If SHGetDesktopFolder_(@Desktop) >= 0
  1787. ;     If Desktop\ParseDisplayName(#Null, #Null, GetPathPart(FileName$), #Null, @*pidlFolder, #Null) = #S_OK
  1788. ;       If Desktop\BindToObject(*pidlFolder, #Null, ?IID_IShellFolder, @Folder) = #S_OK
  1789. ;         If Folder\ParseDisplayName(#Null, #Null, GetFilePart(FileName$) , #Null, @*pidlFile, #Null) = #S_OK
  1790. ;           If Folder\GetUIObjectOf(#Null, 1, @*pidlFile, ?IID_IExtractImage, 0, @Extract) = #S_OK
  1791. ;
  1792. ;             ImageResult = CreateImage(Image, Width, Height, Depth)
  1793. ;             If ImageResult
  1794. ;               If Image = #PB_Any
  1795. ;                 Image = ImageResult
  1796. ;               EndIf  
  1797. ;               If Depth = #PB_Image_DisplayFormat
  1798. ;                 Depth = ImageDepth(Image)
  1799. ;               EndIf
  1800. ;                                  
  1801. ;               size\cx = -1;Width
  1802. ;               size\cy = -1;Height
  1803. ;              
  1804. ;               If Extract\GetLocation(Space(#MAX_PATH), #MAX_PATH, @Priority, @size, Depth, @Flags) >= 0                
  1805. ;                 If Extract\Extract(@Bitmap) >= 0 And Bitmap
  1806. ;                                  
  1807. ;                   If StartDrawing(ImageOutput(Image))
  1808. ;                     DrawingMode(#PB_2DDrawing_AllChannels )
  1809. ;                     DrawImage(Bitmap, 0, 0)
  1810. ;                     StopDrawing()                    
  1811. ;                     Result = ImageResult
  1812. ;                   EndIf
  1813. ;                  
  1814. ;                   DeleteObject_(Bitmap)
  1815. ;                 EndIf
  1816. ;               EndIf                
  1817. ;               Extract\Release()
  1818. ;             EndIf
  1819. ;            
  1820. ;             If Result = 0
  1821. ;               FreeImage(Image)
  1822. ;             EndIf            
  1823. ;           EndIf
  1824. ;                    
  1825. ;           CoTaskMemFree_(*pidlFile)
  1826. ;         EndIf                      
  1827. ;         Folder\Release()
  1828. ;       EndIf    
  1829. ;       CoTaskMemFree_(*pidlFolder)      
  1830. ;     EndIf    
  1831. ;     Desktop\Release()
  1832. ;   EndIf
  1833. ;
  1834. ;   ProcedureReturn Result
  1835. ;  
  1836. ;   DataSection  
  1837. ;     IID_IShellFolder: ; {000214E6-0000-0000-C000-000000000046}
  1838. ;       Data.l $000214E6
  1839. ;       Data.w $0000, $0000
  1840. ;       Data.b $C0, $00, $00, $00, $00, $00, $00, $46
  1841. ;  
  1842. ;     IID_IExtractImage: ; {BB2E617C-0920-11D1-9A0B-00C04FC2D6C1}
  1843. ;       Data.l $BB2E617C
  1844. ;       Data.w $0920, $11D1
  1845. ;       Data.b $9A, $0B, $00, $C0, $4F, $C2, $D6, $C1
  1846. ;   EndDataSection  
  1847. ; EndProcedure
  1848. ;
  1849. ;
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856. ;
  1857. ; OpenWindow(1,0,0,640,480,"CatchImageEx test")
  1858. ;
  1859. ; CatchImageEx(1,?img_begin,?img_end-?img_begin,32)
  1860. ;
  1861. ; Repeat
  1862. ;
  1863. ; StartDrawing(WindowOutput(1))
  1864. ; DrawImage(ImageID(1),0,0)
  1865. ; StopDrawing()
  1866. ;
  1867. ;
  1868. ;
  1869. ; Until WindowEvent()=#PB_Event_CloseWindow
  1870. ;
  1871. ; DataSection
  1872. ; img_begin:
  1873. ; IncludeBinary "C:\mouse.gif"
  1874. ; img_end:
  1875. ; EndDataSection
  1876. ;
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883. ;
  1884. ;
  1885. ;
  1886. ; Procedure SaveImageToMemory(Image, *MemSize, Format = #PB_ImagePlugin_JPEG, Compression = 7)
  1887. ;   Protected *Mem, MemSize, ImageDataPipe
  1888. ;   MemSize = ImageDepth(Image)*ImageHeight(Image)*ImageWidth(Image)
  1889. ;   *Mem = AllocateMemory(MemSize)
  1890. ;   ImageDataPipe = CreateNamedPipe_("\\.\pipe\ImageDataPipe", #PIPE_ACCESS_INBOUND | #FILE_FLAG_OVERLAPPED, #PIPE_TYPE_BYTE | #PIPE_READMODE_BYTE | #PIPE_NOWAIT, 1, MemSize, MemSize, #NMPWAIT_USE_DEFAULT_WAIT, #Null)
  1891. ;   SaveImage(Image, "\\.\pipe\ImageDataPipe", Format, Compression)
  1892. ;   ReadFile_(ImageDataPipe, *Mem, MemSize, *MemSize, #Null)
  1893. ;   CloseHandle_(ImageDataPipe)
  1894. ;   ProcedureReturn *Mem
  1895. ; EndProcedure
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908. ;{ Sample
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914. DisableExplicit
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920. ImagePlugin_Initailize()
  1921.  
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932. If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Image Converter", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  1933.  
  1934.   ImageGadget(0, 0, 28, WindowWidth(0), WindowHeight(0), 0, #PB_Image_Border)
  1935.  
  1936.   CreateToolBar(0, WindowID(0))
  1937.   ToolBarStandardButton(0, #PB_ToolBarIcon_Open)
  1938.   ToolBarStandardButton(1, #PB_ToolBarIcon_Save)
  1939.   DisableToolBarButton(0, 1, 1)    ; disable the save button
  1940.  
  1941.   Repeat
  1942.     EventID = WaitWindowEvent()
  1943.    
  1944.     If EventID = #PB_Event_Menu  ; ToolBar are acting as menu
  1945.      
  1946.       Select EventMenu()
  1947.          
  1948.         Case 0  ; Open
  1949.          
  1950.          
  1951.           Filename$ = OpenFileRequester("Choose a picture", "", "All Images Formats|*.bmp;*.dib;*.jpg;*.jpeg;*.png;*.tif;*.tga;*.ico;*.cur;*.wmf;*.emf;*.gif;*.dds;*.hdr;*.ppm;*.pfm;*.jp2;*.wdp;*.jxr;*.hdp", 0)
  1952.           If Filename$
  1953.            
  1954.             image = ImagePlugin_LoadFromFile(Filename$)
  1955.             If image
  1956.              
  1957.                ResizeImage(image, ImageWidth(image) * 4,ImageHeight(image) * 4)
  1958.              
  1959.               StartDrawing(ImageOutput(image))
  1960.               DrawingMode(#PB_2DDrawing_AllChannels )
  1961.               Box(2,2,8,8,$FFFF0000)
  1962.               StopDrawing()
  1963.              
  1964.               SetGadgetState(0, ImageID(image))  ; change the picture in the gadget
  1965.               DisableToolBarButton(0, 1, 0)    ; enable the save button
  1966.               ResizeWindow(0, #PB_Ignore, #PB_Ignore, ImageWidth(image)+4, ImageHeight(image)+34)
  1967.             EndIf
  1968.            
  1969.           EndIf
  1970.          
  1971.         Case 1  ; Save
  1972.          
  1973.           Filename$ = SaveFileRequester("Save a picture", Left(Filename$, Len(Filename$)-Len(GetExtensionPart(Filename$))-1), "BMP Format|*.bmp|JPEG Format|*.jpg|PNG Format|*.png", 0)
  1974.           If Filename$
  1975.            
  1976.             Select SelectedFilePattern()
  1977.                
  1978.               Case 0  ; BMP
  1979.                 ImageFormat = #PB_ImagePlugin_BMP
  1980.                 Extension$  = "bmp"
  1981.                
  1982.               Case 1  ; JPEG
  1983.                 ImageFormat = #PB_ImagePlugin_JPEG
  1984.                 Extension$  = "jpg"
  1985.                
  1986.               Case 2  ; PNG
  1987.                 ImageFormat = #PB_ImagePlugin_PNG
  1988.                 Extension$  = "png"
  1989.                
  1990.             EndSelect
  1991.            
  1992.             If LCase(GetExtensionPart(Filename$)) <> Extension$
  1993.               Filename$ + "." + Extension$
  1994.             EndIf
  1995.            
  1996.             If SaveImage(image, Filename$, ImageFormat)
  1997.               MessageRequester("Information", "Image saved successfully", 0)
  1998.             EndIf
  1999.            
  2000.           EndIf
  2001.          
  2002.       EndSelect
  2003.      
  2004.     EndIf
  2005.    
  2006.   Until EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
  2007.  
  2008. EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement