Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; The following formats are supported:(maybe a few more ;) )
- ; bmp,dib,ico,emf,jpg,gif,png,tga,dds,ppm,tif,wmf and hdr
- ;
- ; All functions return the handle of a device independant bitmap (dibsection), except
- ; 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.
- ; NOTE:
- ; You need to call CoInitialize_(0) to use _IMGCTX_LoadFromFile(),_OLE_LoadFromMem() and _OLE_LoadFromFile().
- EnableExplicit
- ; Interfaces:
- Interface IImgCtx Extends IUnknown
- Load(pszUrl.p-bstr, dwFlags.l)
- SelectChanges(ulChgOn.l, ulChgOff.l, fSignal.l)
- SetCallback(pfnCB.l, pvPrivateData)
- Disconnect()
- GetUpdateRects(*prc.rect, *prcImg.rect, *pcrc)
- GetStateInfo(*pulState, *psize.size, fClearChanges.l)
- GetPalette(phpal.l)
- Draw(hDC.l, *prcBounds.rect)
- Tile(hDC.l, *pptBackOrg.point, *prcClip.rect,*psize.size)
- StretchBlt(hDCDest.l, nXDest.l, nYDest.l, nWidthDest.l, nHeightDest.l, nXSrc.l, nYSrc.l, nWidthSrc.l, nHeightSrc.l, dwRop.l)
- EndInterface
- ; Constants:
- #IMGCHG_SIZE = $1
- #IMGCHG_VIEW = $2
- #IMGCHG_COMPLETE = $4
- #IMGCHG_ANIMATE = $8
- #IMGCHG_MASK = $F
- #IMGLOAD_NOTLOADED = $100000 ; Image has not yet been loaded
- #IMGLOAD_LOADING = $200000 ; Image in the process of being loaded
- #IMGLOAD_STOPPED = $400000 ; Imaged aborted
- #IMGLOAD_ERROR = $800000 ; Error loading Image
- #IMGLOAD_COMPLETE = $1000000 ; Image loaded
- #IMGLOAD_MASK = $1F00000
- #IMGBITS_NONE = $2000000
- #IMGBITS_PARTIAL = $4000000
- #IMGBITS_TOTAL = $8000000
- #IMGBITS_MASK = $E000000
- #IMGANIM_ANIMATED = $10000000
- #IMGANIM_MASK = $10000000
- #IMGTRANS_OPAQUE = $20000000
- #IMGTRANS_MASK = $20000000
- #DWN_COLORMODE = $3F ; Explicit color mode requested
- #DWN_DOWNLOADONLY = $40 ; Download data only, don't decode
- #DWN_FORCEDITHER = $80 ; Override automatic dithering
- #DWN_RAWIMAGE = $100 ; Disable dithering
- #DWN_MIRRORIMAGE = $200 ; Mirror the image
- #CLSCTX_ALL = $17
- Interface nIDXSurfaceFactory
- QueryInterface(a, b)
- AddRef()
- Release()
- CreateSurface(a, b, c, d, e, f, g, h)
- CreateFromDDSurface(a, b, c, d, e, f)
- LoadImage(a.p-bstr, b, c, d, e, f)
- LoadImageFromStream(a, b, c, d, e, f)
- CopySurfaceToNewFormat(a, b, c, d, e)
- CreateD3DRMTexture(a, b, c, d, e)
- BitBlt(a, b, c, d, e)
- EndInterface
- #DXLOCKF_READ=0
- #CLSCTX_INPROC_SERVER=1
- DataSection
- CLSID_DXTransformFactory:
- Data.l $D1FE6762
- Data.w $FC48,$11D0
- Data.b $88,$3A,$3C,$8B,$00,$C1,$00,$00
- IID_IDXTransformFactory:
- Data.l $6A950B2B
- Data.w $A971,$11D1
- Data.b $81,$C8,$00,$00,$F8,$75,$57,$DB
- IID_IDXSurfaceFactory:
- Data.l $144946F5
- Data.w $C4D4,$11D1
- Data.b $81,$D1,$00,$00,$F8,$75,$57,$DB
- IID_IDXSurface:
- Data.l $B39FD73F
- Data.w $E139,$11D1
- Data.b $90,$65,$00,$C0,$4F,$D9,$18,$9D
- EndDataSection
- Interface ID3DX8
- QueryInterface(a.l,b.l)
- AddRef()
- Release()
- CreateFont(Device.l,hFont.l,retFont.l)
- DrawText(d3dFont.l,color.l,TextString.p-bstr,RECT.l,Format.l)
- GetFVFVertexSize(FVF.l,Size.l)
- AssembleShaderFromFile(SrcFile.p-bstr,flags.l,ErrLog.l,Constants.l,ppVertexShader.l)
- AssembleShader(SrcData.p-bstr,flags.l,Constants.l,ErrLog.l,ppVertexShader.l)
- GetErrorString(hr.l,retStr.l)
- LoadSurfaceFromFile(DestSurface.l,DestPalette.l,DestRect.l,SrcFile.p-bstr,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
- LoadSurfaceFromFileInMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,LengthInBytes.l,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
- LoadSurfaceFromSurface(DestSurface.l,DestPalette.l,DestRect.l,SrcSurface.l,SrcPalette.l,SrcRect.l,Filter.l,ColorKey.l)
- LoadSurfaceFromMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,formatSrc.l,SrcPitch.l,SrcPalette.l,SrcRect.l,Filter.l,ColorKey.l)
- CheckTextureRequirements(Device.l,Width.l,Height.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
- CreateTexture(Device.l,Width.l,Height.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppTexture.l)
- CreateTextureFromResource(Device.l,hModule.l,SrcResource.p-bstr,ppTexture.l)
- CreateTextureFromFile(Device.l,SrcFile.p-bstr,ppTexture.l)
- 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)
- CreateTextureFromFileInMemory(Device.l,SrcData.l,LengthInBytes.l,ppTexture.l)
- 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)
- FilterTexture(texture.l,Palette.l,SrcLevel.l,Filter.l)
- CheckCubeTextureRequirements(Device.l,Size.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
- CreateCubeTexture(pDevice.l,Size.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppCubeTexture.l)
- CreateCubeTextureFromFile(Device.l,SrcFile.p-bstr,ppCubeTexture.l)
- 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)
- CreateCubeTextureFromFileInMemory(Device.l,SrcData.l,LengthInBytes.l,ppTexture.l)
- 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)
- FilterCubeTexture(CubeTexture.l,Palette.l,SrcLevel.l,Filter.l)
- CheckVolumeTextureRequirements(Device.l,Width.l,Height.l,Depth.l,NumMipLevels.l,Usage.l,PixelFormat.l,Pool.l)
- 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)
- CreateVolumeTexture(Device.l,Width.l,Height.l,Depth.l,MipLevels.l,Usage.l,PixelFormat.l,Pool.l,ppVolumeTexture.l)
- FilterVolumeTexture(VolumeTexture.l,Palette.l,SrcLevel.l,Filter.l)
- LoadSurfaceFromResource(DestSurface.l,DestPalette.l,DestRect.l,hSrcModule.l,SrcResource.p-bstr,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
- LoadVolumeFromVolume(DestVolume.l,DestPalette.l,DestBox.l,SrcVolume.l,SrcPalette.l,SrcBox.l,Filter.l,ColorKey.l)
- LoadVolumeFromMemory(DestVolume.l,DestPalette.l,DestBox.l,SrcMemory.l,SrcFormat.l,SrcRowPitch.l,SrcSlicePitch.l,SrcPalette.l,SrcBox.l,Filter.l,ColorKey.l)
- CreateMesh(numFaces.l,NumVertices.l,options.l,Declaration.l,pD3D.l,ppMesh.l)
- CreateMeshFVF(numFaces.l,NumVertices.l,options.l,FVF.l,pD3D.l,ppMesh.l)
- CreateSPMesh(pMesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,ppSMesh.l)
- GeneratePMesh(Mesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,minValue.l,options.l,ppPMesh.l)
- SimplifyMesh(Mesh.l,Adjacency.l,VertexAttributeWeights.l,VertexWeights.l,minValue.l,options.l,ppMesh.l)
- ComputeBoundingSphere(PointsFVF.l,NumVertices.l,FVF.l,Centers.l,RadiusArray.l)
- ComputeBoundingBox(PointsFVF.l,NumVertices.l,FVF.l,MinVert.l,MaxVert.l)
- ComputeNormals(pMesh.l)
- DeclaratorFromFVF(FVF.l,Declarator.l)
- FVFFromDeclarator(Declarator.l,FVF.l)
- CreateBuffer(numBytes.l,ppBuffer.l)
- LoadMeshFromX(filename.p-bstr,options.l,D3DDevice.l,retAdjacency.l,retMaterials.l,retMaterialCount.l,retMesh.l)
- SaveMeshToX(filename.p-bstr,Mesh.l,AdjacencyArray.l,MaterialArray.l,MaterialCount.l,xFormat.l)
- LoadMeshFromXof(*xofobjMesh.IUnknown,options.l,D3DDevice.l,retBufAdjacency.l,retMaterials.l,retMaterialCount.l,retMesh.l)
- TessellateNPatches(MeshIn.l,adjacencyIn.l,NumSegs.f,QuadraticInterpNormals.w,adjacencyOut.l,MeshOut.l)
- BufferGetMaterial(MaterialBuffer.l,index.l,mat.l)
- BufferGetTextureName(MaterialBuffer.l,index.l,retName.l)
- BufferGetData(Buffer.l,index.l,typesize.l,typecount.l,Data_.l)
- BufferSetData(Buffer.l,index.l,typesize.l,typecount.l,Data_.l)
- Intersect(MeshIn.l,RayPos.l,RayDir.l,retHit.l,retFaceIndex.l,U.l,v.l,retDist.l,countHits.l,AllHits.l)
- SphereBoundProbe(Center.l,Radius.f,RayPosition.l,Raydirection.l,retHit.l)
- ComputeBoundingSphereFromMesh(MeshIn.l,Centers.l,RadiusArray.l)
- ComputeBoundingBoxFromMesh(MeshIn.l,MinArray.l,MaxArray.l)
- CreateSkinMesh(numFaces.l,NumVertices.l,numBones.l,options.l,Declaration.l,D3DDevice.l,SkinMesh.l)
- CreateSkinMeshFVF(numFaces.l,NumVertices.l,numBones.l,options.l,FVF.l,D3DDevice.l,ppSkinMesh.l)
- CreateSkinMeshFromMesh(Mesh.l,numBones.l,ppSkinMesh.l)
- LoadSkinMeshFromXof(*xofobjMesh.IUnknown,options.l,D3DDevice.l,adjacencyOut.l,MaterialsOut.l,NumMatOut.l,BoneNamesOut.l,BoneTransformsOut.l,ppMesh.l)
- CreatePolygon(D3DDevice.l,Length.f,Sides.l,retAdjacency.l,retMesh.l)
- CreateBox(D3DDevice.l,Width.f,Height.f,Depth.f,retAdjacency.l,retMesh.l)
- CreateCylinder(D3DDevice.l,Radius1.f,Radius2.f,Length.f,Slices.l,Stacks.l,retAdjacency.l,retMesh.l)
- CreateSphere(D3DDevice.l,Radius.f,Slices.l,Stacks.l,retAdjacency.l,retMesh.l)
- CreateTorus(D3DDevice.l,InnerRadius.f,OuterRadius.f,Sides.l,Rings.l,retAdjacency.l,retMesh.l)
- CreateTeapot(D3DDevice.l,retAdjacency.l,retMesh.l)
- CreateText(D3DDevice.l,hDC.l,Text.p-bstr,Deviation.f,Extrusion.f,retMesh.l,adjacencyOut.l,GlyphMetrics.l)
- BufferGetBoneName(BoneNameBuffer.l,index.l,retName.l)
- CreateSprite(D3DDevice.l,retSprite.l)
- CreateRenderToSurface(D3DDevice.l,Width.l,Height.l,Format.l,DepthStencil.l,DepthStencilFormat.l,RetRenderToSurface.l)
- CleanMesh(MeshIn.l,Adjacency.l,ErrLog.l,adjacencyOut.l,MeshOut.l)
- ValidMesh(MeshIn.l,Adjacency.l,ErrLog.l,ret.l)
- BoxBoundProbe(MinVert.l,MaxVert.l,RayPosition.l,Raydirection.l,ret.l)
- SavePMeshToFile(filename.p-bstr,Mesh.l,MaterialArray.l,MaterialCount.l)
- LoadPMeshFromFile(filename.p-bstr,options.l,D3DDevice.l,retMaterials.l,RetNumMaterials.l,RetPMesh.l)
- BufferGetBoneCombo(BoneComboBuffer.l,index.l,boneCombo.l)
- BufferGetBoneComboBoneIds(BoneComboBuffer.l,index.l,paletteSize.l,BoneIds.l)
- SaveSurfaceToFile(DestFile.p-bstr,DestFormat.l,SrcSurface.l,SrcPalette.l,SrcRect.l)
- SaveVolumeToFile(DestFile.p-bstr,DestFormat.l,SrcVolume.l,SrcPalette.l,SrcBox.l)
- SaveTextureToFile(DestFile.p-bstr,DestFormat.l,SrcTexture.l,SrcPalette.l)
- EndInterface
- Prototype.l D3DX9LoadSurfaceFromFile(DestSurface.l,DestPalette.l,DestRect.l,SrcFile.s,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
- Prototype.l D3DX9LoadSurfaceFromFileInMemory(DestSurface.l,DestPalette.l,DestRect.l,SrcData.l,LengthInBytes.l,SrcRect.l,Filter.l,ColorKey.l,SrcInfo.l)
- Prototype.l D3DX9GetImageInfoFromFile(pSrcFile.l,pSrcInfo.l)
- Prototype.l D3DX9GetImageInfoFromFileInMemory(pSrcData.l,SrcDataSize.l,pSrcInfo.l)
- Structure GdiplusStartupInput
- GdiplusVersion.l
- DebugEventCallback.l
- SuppressBackgroundThread.l
- SuppressExternalCodecs.l
- EndStructure
- Prototype.l GdiplusStartup(a.l,b.l,c.l)
- Prototype.l GdiplusShutdown(a.l)
- Prototype.l GdipGetImageWidth(a.l,b.l)
- Prototype.l GdipGetImageHeight(a.l,b.l)
- Prototype.l GdipCreateFromHDC(a.l,b.l)
- Prototype.l GdipDrawImageI(a.l,b.l,c.l,d.l)
- Prototype.l GdipDisposeImage(a.l)
- Prototype.l GdipDeleteGraphics(a.l)
- Prototype.l GdipAlloc(a.l)
- Prototype.l GdipFree(a.l)
- Prototype.l GdipCreateBitmapFromFile(a.l,b.l)
- Prototype.l GdipCreateBitmapFromStream(a.l,b.l)
- #CLSCTX_INPROC_SERVER=1
- Structure D3DSURFACE_DESC
- Format.l
- Type.l
- Usage.l
- Pool.l
- Size.l
- MultiSampleType.l
- Width.l
- Height.l
- EndStructure
- Structure D3DSURFACE9_DESC
- Format.l
- Type.l
- Usage.l
- Pool.l
- MultiSampleType.l
- MultiSampleQuality.l
- Width.l
- Height.l
- EndStructure
- Structure D3DLOCKED_RECT
- Pitch.l
- pBits.l
- EndStructure
- Structure D3DXIMAGE_INFO
- Width.l
- Height.l
- Depth.l
- MipLevels.l
- Format.l
- ResourceType.l
- ImageFileFormat.l
- EndStructure
- Structure MyD3DSURFACE
- VTable.l
- Width.l
- Height.l
- Pitch.l
- pBits.l
- BufferData.l
- EndStructure
- #D3DFMT_A8R8G8B8=21
- #D3DFMT_X8R8G8B8=22
- #D3DRTYPE_SURFACE=1
- #D3DPOOL_SYSTEMMEM=2
- #D3DPOOL_SCRATCH=3
- Interface IWICBitmapDecoder Extends IUnknown
- QueryCapability( *pIStream.IStream, *pdwCapabilities.l )
- Initialize( *pIStream, cacheOptions.i)
- GetContainerFormat( *pguidContainerFormat.GUID )
- GetDecoderInfo(*ptr_pIDecoderInfo )
- CopyPalette ( *pIPalette );
- GetMetadataQueryReader ( *ppIMetadataQueryReader);
- GetPreview ( *ptr_ppIPreview );
- GetColorContexts(cCount, *ppIColorContexts, *ptr_pcActualCount )
- GetThumbnail (*ptr_ppIThumbnail );
- GetFrameCount(*pCount.integer)
- GetFrame(index.i,*ptr_ppIBitmapFrame )
- EndInterface
- Interface IWICBitmapEncoder Extends IUnknown
- Initialize ( *pIStream.IStream, cacheOption )
- GetContainerFormat (*pguidContainerFormat.GUID )
- GetEncoderInfo ( *ptr_pIEncoderInfo )
- SetColorContexts ( cCount, *_ptr_ppIColorContext );
- SetPalette ( *pIPalette);
- SetThumbnail (*pIThumbnail );
- SetPreview (*pIPreview );
- CreateNewFrame (*ptr_ppIFrameEncode, *ptr_ppIEncoderOptions )
- Commit()
- GetMetadataQueryWriter ( *ptr_ppIMetadataQueryWriter );
- EndInterface
- Interface IWICBitmapSource Extends IUnknown
- GetSize ( *puiWidth,*puiHeight )
- GetPixelFormat (*pPixelFormat );
- GetResolution ( *pDpiX.double, *pDpiY.double)
- CopyPalette ( *pIPalette );
- CopyPixels ( *prc,cbStride, cbBufferSize, *pbBuffer.b );
- EndInterface
- Interface IWICBitmapFrameDecode Extends IWICBitmapSource
- GetMetadataQueryReader ( *ptr_pIMetadataQueryReader )
- GetColorContexts ( cCount, *ptr_ppIColorContexts, *pcActualCount )
- GetThumbnail ( *ptr_ppIThumbnail );
- EndInterface
- Interface IWICBitmapFrameEncode Extends IUnknown
- Initialize ( *pIEncoderOptions );
- SetSize ( width, height );
- SetResolution ( dpiX.d, dpiY.d );
- SetPixelFormat (*pPixelFormat);
- SetColorContexts ( cCount, *ptr_ppIColorContext );
- SetPalette (*pIPalette )
- SetThumbnail ( *pIThumbnail )
- WritePixels ( lineCount, cbStride, cbBufferSize, *pbPixels.byte )
- WriteSource ( *pIWICBitmapSource, *prc );
- Commit()
- GetMetadataQueryWriter ( *ptr_ppIMetadataQueryWriter );
- EndInterface
- Macro DEF_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
- Global name.GUID
- name\Data1 = l
- name\Data2 = w1
- name\Data3 = w2
- name\Data4[0] = b1
- name\Data4[1] = b2
- name\Data4[2] = b3
- name\Data4[3] = b4
- name\Data4[4] = b5
- name\Data4[5] = b6
- name\Data4[6] = b7
- name\Data4[7] = b8
- EndMacro
- DEF_GUID(CLSID_WICBmpEncoder, $69be8bb4, $d66d, $47c8, $86, $5a, $ed, $15, $89, $43, $37, $82)
- DEF_GUID(CLSID_WICPngEncoder, $27949969, $876a, $41d7, $94, $47, $56, $8f, $6a, $35, $a4, $dc)
- DEF_GUID(CLSID_WICJpegEncoder, $1a34f5c1, $4a5a, $46dc, $b6, $44, $1f, $45, $67, $e7, $a6, $76)
- DEF_GUID(CLSID_WICGifEncoder, $114f5598, $b22, $40a0, $86, $a1, $c8, $3e, $a4, $95, $ad, $bd)
- DEF_GUID(CLSID_WICTiffEncoder, $0131be10, $2001, $4c5f, $a9, $b0, $cc, $88, $fa, $b6, $4c, $e8)
- DEF_GUID(CLSID_WICWmpEncoder, $ac4ce3cb, $e1c1, $44cd, $82, $15, $5a, $16, $65, $50, $9e, $c2)
- DEF_GUID(CLSID_WICBmpDecoder, $6b462062, $7cbf, $400d, $9f, $db, $81, $3d, $d1, $f, $27, $78)
- DEF_GUID(CLSID_WICPngDecoder, $389ea17b, $5078, $4cde, $b6, $ef, $25, $c1, $51, $75, $c7, $51)
- DEF_GUID(CLSID_WICIcoDecoder, $c61bfcdf, $2e0f, $4aad, $a8, $d7, $e0, $6b, $af, $eb, $cd, $fe)
- DEF_GUID(CLSID_WICJpegDecoder, $9456a480, $e88b, $43ea, $9e, $73, $b, $2d, $9b, $71, $b1, $ca)
- DEF_GUID(CLSID_WICGifDecoder, $381dda3c, $9ce9, $4834, $a2, $3e, $1f, $98, $f8, $fc, $52, $be)
- DEF_GUID(CLSID_WICTiffDecoder, $b54e85d9, $fe23, $499f, $8b, $88, $6a, $ce, $a7, $13, $75, $2b)
- DEF_GUID(CLSID_WICWmpDecoder, $a26cec36, $234c, $4950, $ae, $16, $e3, $4a, $ac, $e7, $1d, $0d)
- DEF_GUID(IID_IWICBitmapDecoder,$9EDDE9E7,$8DEE,$47ea,$99,$DF,$E6,$FA,$F2,$ED,$44,$BF);
- DEF_GUID(IID_IWICBitmapEncoder, $00000103,$a8f2,$4877,$ba,$0a,$fd,$2b,$66,$45,$fb,$94)
- DEF_GUID(WICPixelFormat24bppRGB, $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$0d)
- DEF_GUID(WICPixelFormat24bppBGR, $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$0c)
- DEF_GUID(WICPixelFormat32bppBGRA, $6fddc324, $4e03, $4bfe, $b1, $85, $3d, $77, $76, $8d, $c9, $0f);
- #WICDecodeMetadataCacheOnDemand = 0
- #WICDecodeMetadataCacheOnLoad = 1
- #WICBitmapEncoderCacheInMemory = 0
- #WICBitmapEncoderCacheTempFile = 1
- #WICBitmapEncoderNoCache = 2
- ;WICPixelFormatGUID is eqaul to GUID
- #STGM_READ=$00000000
- #STGM_WRITE=$00000001
- #STGM_READWRITE=$00000002
- #STGM_SHARE_DENY_NONE=$00000040
- #STGM_SHARE_DENY_READ=$00000030
- #STGM_SHARE_DENY_WRITE=$00000020
- #STGM_SHARE_EXCLUSIVE=$00000010
- #STGM_PRIORITY=$00040000
- #STGM_CREATE=$00001000
- #STGM_CONVERT=$00020000
- #STGM_FAILIFTHERE=$00000000
- #STGM_DIRECT=$00000000
- #STGM_TRANSACTED=$00010000
- #STGM_NOSCRATCH=$00100000
- #STGM_NOSNAPSHOT=$00200000
- #STGM_SIMPLE=$08000000
- #STGM_DIRECT_SWMR=$00400000
- #STGM_DELETEONRELEASE=$04000000
- Structure STATSTG
- pwcsName.l
- type.l
- cbSize.ULARGE_INTEGER
- mtime.FILETIME
- ctime.FILETIME
- atime.FILETIME
- grfMode.f
- grfLocksSupported.l
- clsid.GUID
- grfStateBits.l
- reserved.l
- EndStructure
- Procedure __MyD3D8SurfaceGetDesc(*this.MyD3DSURFACE,*desc.D3DSURFACE_DESC)
- *desc\Format=#D3DFMT_A8R8G8B8
- *desc\Pool=#D3DPOOL_SYSTEMMEM
- *desc\Type=#D3DRTYPE_SURFACE
- *desc\Width=*this\Width
- *desc\Height=*this\Height
- *desc\Size=*this\Pitch * *this\Height
- ; must be set zu zero
- *desc\MultiSampleType=0
- *desc\Usage=0
- EndProcedure
- Procedure __MyD3D9SurfaceGetDesc(*this.MyD3DSURFACE,*desc.D3DSURFACE9_DESC)
- *desc\Format=#D3DFMT_A8R8G8B8
- *desc\Pool=#D3DPOOL_SCRATCH
- *desc\Type=#D3DRTYPE_SURFACE
- *desc\Width=*this\Width
- *desc\Height=*this\Height
- ; must be set zu zero
- *desc\MultiSampleType=0
- *desc\MultiSampleQuality=0
- *desc\Usage=0
- EndProcedure
- Procedure __MyD3DSurfaceLock(*this.MyD3DSURFACE,*lockinf.D3DLOCKED_RECT,*re.rect,Flags)
- *lockinf\pBits=*this\pBits
- *lockinf\Pitch=*this\Pitch
- EndProcedure
- Procedure __MyD3DSurfaceUnLock(*this.MyD3DSURFACE)
- EndProcedure
- Procedure __MyD3DSurfaceAddRef(*this.MyD3DSURFACE)
- EndProcedure
- Procedure __MyD3DSurfaceRelease(*this.MyD3DSURFACE)
- EndProcedure
- DataSection
- IID_IUnknown:
- Data.l 0
- Data.l $0
- Data.l $C0
- Data.l $46000000
- CLSID_D3DX8:
- Data.l 1479896157
- Data.l 1223494653
- Data.l 1391773075
- Data.l -567057909
- MyD3D8_SurfaceVTable:
- Data.l 0,0,0,0,0,0,0,0,@__MyD3D8SurfaceGetDesc(),@__MyD3DSurfaceLock(),@__MyD3DSurfaceUnLock()
- MyD3D9_SurfaceVTable:
- Data.l 0,@__MyD3DSurfaceAddRef(),@__MyD3DSurfaceRelease(),0,0,0,0,0,0,0,0,0,@__MyD3D9SurfaceGetDesc(),@__MyD3DSurfaceLock(),@__MyD3DSurfaceUnLock()
- EndDataSection
- ; Uses IImgCtx from mshtml.dll to load bmp,dib,ico,wmf,emf,jpg,png and gif files, so we don't need huge plugins.
- ; However it's not guaranteed that this function works everywhere.(but it should work very well almost everywhere ;) )
- Procedure _IMGCTX_LoadFromFile(File.s)
- Protected *ImgCtx.IImgCtx, lState.i, sz.size, BmInf.BitmapInfo, hBmp =#Null, OldhBmp = #Null, MemDC = #Null
- Protected Path.s
- If FileSize(File) < 1
- ProcedureReturn #Null
- EndIf
- CoCreateInstance_(?CLSID_IImgCtx,0,#CLSCTX_ALL,?IID_IImgCtx,@*ImgCtx.IImgCtx)
- If *ImgCtx=#Null:ProcedureReturn #Null:EndIf
- If FindString(File,":",1)=0 ; it's a relative path
- Path.s=Space(#MAX_PATH)
- GetCurrentDirectory_(Len(Path),Path)
- *ImgCtx\Load("file:///"+ReplaceString(Path+"\"+File,"\","/"),0)
- Else
- *ImgCtx\Load("file:///"+ReplaceString(File,"\","/"),0)
- EndIf
- Repeat ; needed, because ImgCtx works asynchronous (we must wait till it's loaded completely)
- Sleep_(1)
- *ImgCtx\GetStateInfo(@lState,sz.size, 1)
- Until lState&#IMGLOAD_COMPLETE Or lState&#IMGLOAD_STOPPED Or lState&#IMGLOAD_ERROR
- If lState&#IMGLOAD_STOPPED Or lState&#IMGLOAD_ERROR
- ;Error
- Else
- If sz\cx > 0 And sz\cy > 0
- BmInf\BmiHeader\biBitCount = 24
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes = 1
- BmInf\BmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth = sz\cx
- BmInf\BmiHeader\biHeight = sz\cy
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhBmp=SelectObject_(MemDC,hBmp)
- ;--crash with zip
- *ImgCtx\StretchBlt(MemDC,0,0,sz\cx,sz\cy,0,0,sz\cx,sz\cy,#SRCCOPY)
- SelectObject_(MemDC,OldhBmp)
- DeleteDC_(MemDC)
- Else
- DeleteObject_(hBmp)
- hBmp = #Null
- EndIf
- EndIf
- EndIf
- EndIf
- *ImgCtx\Release()
- ProcedureReturn hBmp
- DataSection ; only include it, if it's needed.
- IID_IImgCtx:
- Data.l $3050f3d7
- Data.w $98b5,$11cf
- Data.b $bb,$82,$0,$aa,$0,$bd,$ce,$0b
- CLSID_IImgCtx:
- Data.l $3050f3d6
- Data.w $98b5,$11cf
- Data.b $bb,$82,$0,$aa,$0,$bd,$ce,$0b
- EndDataSection
- EndProcedure
- ; Uses OLE to load bmp,dib,ico,cur,emf,jpg and gif files, so we don't need huge plugins.
- ; However the support of jpg and gif is not guaranteed.
- Procedure _OLE_LoadFromMem(Addr, Size)
- Protected BmInf.BitmapInfo, Mem, *ptr, *Stream.IStream, GDIObject, Bmp.BITMAP
- Protected hBmp, DestMemDC, DestOldhBmp, MemDC, OldDC, re.rect, icoinf.ICONINFO, Result
- Protected *OlePict.IPicture, emh.ENHMETAHEADER
- BmInf\BmiHeader\biBitCount=24
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- If Addr <> #Null And Size > 0 ; we can only use OLE, if the size is known and the address is valid.
- Mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)
- *ptr=GlobalLock_(Mem)
- If *ptr=0 ; if GlobalAlloc or GlobalLock failed
- GlobalFree_(Mem)
- ProcedureReturn 0
- EndIf
- RtlMoveMemory_(*ptr,Addr,Size)
- GlobalUnlock_(Mem)
- CreateStreamOnHGlobal_(Mem,1,@*Stream)
- If *Stream=0
- GlobalFree_(Mem)
- ProcedureReturn 0
- EndIf
- OleLoadPicture_(*Stream,0,0,?IID_IPicture,@*OlePict.IPicture)
- *Stream\Release() ; the stream should free Mem too
- If *OlePict=0:ProcedureReturn 0:EndIf
- *OlePict\Get_Handle(@GDIObject)
- Select GetObjectType_(GDIObject) ; convert gdi-object into a DIBSECTION
- Case #OBJ_BITMAP
- GetObject_(GDIObject,SizeOf(BITMAP),Bmp.BITMAP)
- BmInf\BmiHeader\biWidth=Bmp\bmWidth
- BmInf\BmiHeader\biHeight=Bmp\bmHeight
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp
- DestMemDC=CreateCompatibleDC_(0)
- DestOldhBmp=SelectObject_(DestMemDC,hBmp)
- MemDC=CreateCompatibleDC_(0)
- *OlePict\SelectPicture(MemDC,@OldDC,0)
- Result=BitBlt_(DestMemDC,0,0,Bmp\bmWidth,Bmp\bmHeight,MemDC,0,0,#SRCCOPY)
- *OlePict\SelectPicture(OldDC,0,0)
- SelectObject_(DestMemDC,DestOldhBmp)
- DeleteDC_(MemDC)
- DeleteDC_(DestMemDC)
- EndIf
- Case #OBJ_METAFILE,#OBJ_ENHMETAFILE
- GetEnhMetaFileHeader_(GDIObject,SizeOf(ENHMETAHEADER),emh.ENHMETAHEADER)
- ;correct ?
- re.rect\right=emh\rclBounds\right-emh\rclBounds\left
- re\bottom=emh\rclBounds\bottom-emh\rclBounds\top
- BmInf\BmiHeader\biWidth=re\right
- BmInf\BmiHeader\biHeight=re\bottom
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp
- DestMemDC=CreateCompatibleDC_(0)
- DestOldhBmp=SelectObject_(DestMemDC,hBmp)
- Result=PlayEnhMetaFile_(DestMemDC,GDIObject,re.rect)
- SelectObject_(DestMemDC,DestOldhBmp)
- DeleteDC_(DestMemDC)
- EndIf
- EndSelect
- If GetIconInfo_(GDIObject,icoinf.ICONINFO)
- Result=1
- ;The calling application must manage these bitmaps And delete them when they are no longer necessary.
- DeleteObject_(icoinf\hbmMask) ; we don't need the mask
- hBmp=icoinf\hbmColor ; no dibsection, but at least a bitmap
- EndIf
- *OlePict\Release()
- EndIf
- If Result=0:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
- ProcedureReturn hBmp
- DataSection ; only include it, if it's needed.
- IID_IPicture:
- Data.l $7BF80980
- Data.w $BF32,$101A
- Data.b $8B,$BB,$0,$AA,$0,$30,$0C,$AB
- EndDataSection
- EndProcedure
- ; Uses OLE to load bmp,dib,ico,cur,emf,jpg and gif files, so we don't need huge plugins.
- ; However the support of jpg and gif is not guaranteed.
- Procedure _OLE_LoadFromFile(File.s)
- Protected Handle, sz.LARGE_INTEGER, *ptr, Result = #Null
- Protected readbytes
- Handle=CreateFile_(File,#GENERIC_READ,#FILE_SHARE_READ,0,#OPEN_EXISTING,#FILE_ATTRIBUTE_NORMAL,0)
- If Handle=#Null:ProcedureReturn 0:EndIf
- GetFileSizeEx_(Handle,sz.LARGE_INTEGER)
- If sz\lowpart<=0 Or sz\highpart ; if the size of the file is zero, or more than 4 GB
- CloseHandle_(Handle)
- ProcedureReturn 0
- EndIf
- *ptr=GlobalAlloc_(#GMEM_FIXED,sz\lowpart)
- If *ptr=#Null ; the memory can be allocated
- CloseHandle_(Handle)
- ProcedureReturn 0
- EndIf
- ReadFile_(Handle,*ptr,sz\lowpart,@readbytes,0)
- CloseHandle_(Handle)
- If readbytes = sz\lowpart
- Result=_OLE_LoadFromMem(*ptr,sz\lowpart)
- EndIf
- GlobalFree_(*ptr)
- ProcedureReturn Result
- EndProcedure
- ; Loads bmp And dib files from memory.
- Procedure _DIB_LoadFromMem(Addr.l)
- Protected *bmfh.BITMAPFILEHEADER, *bminf.BitmapInfo, hBmp = #Null, MemDC = #Null, OldhBmp = #Null, Result = #False
- If Addr <> #Null
- *bmfh.BITMAPFILEHEADER=Addr
- If *bmfh\bfType='MB' ; seems to be a bitmap (*.bmp or *.dib), so we don't need the size
- ; load bmp or dib from memory, really short ;)
- *bminf.BitmapInfo=*bmfh+SizeOf(BITMAPFILEHEADER)
- hBmp=CreateDIBSection_(0,*bminf,#DIB_RGB_COLORS,0,0,0)
- If hBmp=0:ProcedureReturn 0:EndIf
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhBmp=SelectObject_(MemDC,hBmp)
- Result=SetDIBitsToDevice_(MemDC,0,0,*bminf\BmiHeader\biWidth,*bminf\BmiHeader\biHeight,0,0,0,*bminf\BmiHeader\biHeight,*bmfh\bfOffBits+*bmfh,*bminf,#DIB_RGB_COLORS)
- SelectObject_(MemDC,OldhBmp)
- DeleteDC_(MemDC)
- EndIf
- If Result=#False:DeleteObject_(MemDC):ProcedureReturn 0:EndIf
- EndIf
- EndIf
- ProcedureReturn hBmp
- EndProcedure
- ; Loads bmp And dib files from file.
- Procedure _DIB_LoadFromFile(File.s)
- ProcedureReturn LoadImage_(0,File.s,#IMAGE_BITMAP,0,0,#LR_LOADFROMFILE|#LR_CREATEDIBSECTION)
- EndProcedure
- Procedure _ICOCUR_LoadFromFile(sFile.s, *width.integer, *height.integer)
- Protected hIcon = #Null, file, head.ICONHEADER,currentWidth.i, currentHeight.i, biggestWidth = 0, biggestHeight = 0
- Protected reserved.i, type.i, count.i,i.i
- file = ReadFile(#PB_Any, sFile)
- If file
- reserved = ReadWord(file)
- If reserved = 0
- type = ReadWord(file)
- If type = 1 Or type = 2
- count = ReadWord(file)
- If count > 0 And count < 1000
- For i = 1 To count
- ReadData(file, head, SizeOf(ICONHEADER))
- currentWidth = head\bWidth & 255
- If currentWidth = 0:currentWidth = 256:EndIf
- currentHeight = head\bHeight & 255
- If currentHeight = 0:currentHeight = 256:EndIf
- If currentWidth > biggestWidth
- biggestWidth = currentWidth
- biggestHeight = currentHeight
- EndIf
- Next
- If *width
- *width\i = biggestWidth
- EndIf
- If *height
- *height\i = biggestHeight
- EndIf
- If type = 1
- hIcon = LoadImage_(0,sFile.s,#IMAGE_ICON,biggestWidth, biggestHeight,#LR_LOADFROMFILE)
- EndIf
- If type = 2
- hIcon = LoadImage_(0,sFile.s,#IMAGE_CURSOR,biggestWidth, biggestHeight,#LR_LOADFROMFILE)
- EndIf
- EndIf
- EndIf
- EndIf
- CloseFile(file)
- EndIf
- ProcedureReturn hIcon
- EndProcedure
- Procedure _DX8_LoadFromFile(File.s)
- Protected *D3DX8.ID3DX8, Surf.MyD3DSURFACE, re.rect, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp, MemDC, OldhNewBmp
- If FileSize(File) < 1
- ProcedureReturn #Null
- EndIf
- If OSVersion() > #PB_OS_Windows_Server_2003 ; Normally not supported anymore for Vista and above
- ProcedureReturn #Null
- EndIf
- CoCreateInstance_(?CLSID_D3DX8,0,#CLSCTX_INPROC_SERVER,?IID_IUnknown,@*D3DX8.ID3DX8)
- If *D3DX8=0
- ProcedureReturn #Null
- EndIf
- Surf.MyD3DSURFACE
- Surf\VTable=?MyD3D8_SurfaceVTable
- Surf\Width=1
- Surf\Height=1
- Surf\Pitch=4
- Surf\pBits=@Surf\BufferData
- ; First get the width and height of the image
- re.rect\right=1
- re\bottom=1
- Result=*D3DX8\LoadSurfaceFromFile(Surf,0,re,File,0,1,0,imginfo.D3DXIMAGE_INFO)
- If Result:*D3DX8\Release():ProcedureReturn #Null:EndIf
- ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=imginfo\Width
- BmInf\BmiHeader\biHeight=imginfo\Height
- If imginfo\Width <= 0 Or imginfo\Height <= 0
- *D3DX8\Release()
- ProcedureReturn #Null
- EndIf
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp=0:*D3DX8\Release():ProcedureReturn #Null:EndIf
- GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)
- Surf\Pitch=bmi\dsBm\bmWidthBytes
- Surf\pBits=bmi\dsBm\bmBits
- Surf\Width=imginfo\Width
- Surf\Height=imginfo\Height
- If bmi\dsBm\bmBits = #Null
- *D3DX8\Release()
- DeleteObject_(hBmp)
- ProcedureReturn #Null
- EndIf
- bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
- ; fill dibsection with the data
- Result=*D3DX8\LoadSurfaceFromFile(Surf,0,0,File,0,1,0,0)
- *D3DX8\Release()
- If Result:DeleteObject_(hBmp):ProcedureReturn #Null:EndIf
- hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
- If hNewBmp=0
- DeleteObject_(hBmp)
- ProcedureReturn #Null
- EndIf
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhNewBmp=SelectObject_(MemDC,hNewBmp)
- Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
- SelectObject_(MemDC,hNewBmp)
- DeleteDC_(MemDC)
- EndIf
- DeleteObject_(hBmp)
- If Result=0
- DeleteObject_(hNewBmp)
- ProcedureReturn 0
- EndIf
- ProcedureReturn hNewBmp
- EndProcedure
- Procedure _DX8_LoadFromMem(SrcData.l,LengthInBytes.l)
- Protected *D3DX8.ID3DX8, Surf.MyD3DSURFACE, re.rect, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp
- Protected MemDC, OldhNewBmp
- If SrcData=#Null Or LengthInBytes<=0
- ProcedureReturn #Null
- EndIf
- If OSVersion() > #PB_OS_Windows_Server_2003 ; Normally not supported anymore for Vista and above
- ProcedureReturn #Null
- EndIf
- CoCreateInstance_(?CLSID_D3DX8,0,#CLSCTX_INPROC_SERVER,?IID_IUnknown,@*D3DX8.ID3DX8)
- If *D3DX8=#Null
- ProcedureReturn #Null
- EndIf
- Surf.MyD3DSURFACE
- Surf\VTable=?MyD3D8_SurfaceVTable
- Surf\Width=1
- Surf\Height=1
- Surf\Pitch=4
- Surf\pBits=@Surf\BufferData
- ; First get the width and height of the image
- re.rect\right=1
- re\bottom=1
- Result=*D3DX8\LoadSurfaceFromFileInMemory(Surf,0,re,SrcData,LengthInBytes,0,1,0,imginfo.D3DXIMAGE_INFO)
- If Result:*D3DX8\Release():ProcedureReturn #Null:EndIf
- ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=imginfo\Width
- BmInf\BmiHeader\biHeight=imginfo\Height
- If imginfo\Width <= 0 Or imginfo\Height <= 0
- *D3DX8\Release()
- ProcedureReturn #Null
- EndIf
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp=0:*D3DX8\Release():ProcedureReturn 0:EndIf
- GetObject_(hBmp,SizeOf(DIBSECTION), bmi.DIBSECTION)
- Surf\Pitch=bmi\dsBm\bmWidthBytes
- Surf\pBits=bmi\dsBm\bmBits
- Surf\Width=imginfo\Width
- Surf\Height=imginfo\Height
- If bmi\dsBm\bmBits = #Null
- *D3DX8\Release()
- DeleteObject_(hBmp)
- ProcedureReturn #Null
- EndIf
- bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
- ; fill dibsection with the data
- Result=*D3DX8\LoadSurfaceFromFileInMemory(Surf,0,0,SrcData,LengthInBytes,0,1,0,0)
- *D3DX8\Release()
- If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
- hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
- If hNewBmp=0
- DeleteObject_(hBmp)
- ProcedureReturn #Null
- EndIf
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhNewBmp=SelectObject_(MemDC,hNewBmp)
- Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
- SelectObject_(MemDC,hNewBmp)
- DeleteDC_(MemDC)
- EndIf
- DeleteObject_(hBmp)
- If Result=0
- DeleteObject_(hNewBmp)
- ProcedureReturn #Null
- EndIf
- ProcedureReturn hNewBmp
- EndProcedure
- Procedure _DX9_LoadFromFile(File.s)
- Protected D3DXInst, D3DX9LoadSurfaceFromFile.D3DX9LoadSurfaceFromFile, D3DX9GetImageInfoFromFile.D3DX9GetImageInfoFromFile, Result = #False
- Protected imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, Surf.MyD3DSURFACE, hNewBmp, MemDC, OldhNewBmp
- If FileSize(File) < 1
- ProcedureReturn #Null
- EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_43.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_42.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_41.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_40.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_39.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_38.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_37.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_36.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_35.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_34.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_33.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_32.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_31.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_30.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_29.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_28.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_27.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_26.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_25.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_24.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_43.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_42.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_41.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_40.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_39.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_38.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_37.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_36.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_35.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_34.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_33.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_32.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_31.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_30.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_29.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_28.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_27.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_26.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_25.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_24.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d.dll"):EndIf
- If D3DXInst=0:ProcedureReturn 0:EndIf
- D3DX9LoadSurfaceFromFile.D3DX9LoadSurfaceFromFile=GetProcAddress_(D3DXInst,"D3DXLoadSurfaceFromFileA")
- D3DX9GetImageInfoFromFile.D3DX9GetImageInfoFromFile=GetProcAddress_(D3DXInst,"D3DXGetImageInfoFromFileA")
- If D3DX9LoadSurfaceFromFile=0 Or D3DX9GetImageInfoFromFile=0
- FreeLibrary_(D3DXInst)
- ProcedureReturn 0
- EndIf
- ; First get the width and height of the image
- Result=D3DX9GetImageInfoFromFile(@File,imginfo.D3DXIMAGE_INFO)
- ; Result=D3DX9LoadSurfaceFromFile(Surf,0,re,@File,0,1,0,imginfo.D3DXIMAGE_INFO)
- If Result:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
- ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=imginfo\Width
- BmInf\BmiHeader\biHeight=imginfo\Height
- If imginfo\Width <= 0 Or imginfo\Height <= 0
- FreeLibrary_(D3DXInst):ProcedureReturn 0
- EndIf
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp=0:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
- GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)
- Surf.MyD3DSURFACE
- Surf\VTable=?MyD3D9_SurfaceVTable
- Surf\Pitch=bmi\dsBm\bmWidthBytes
- Surf\pBits=bmi\dsBm\bmBits
- Surf\Width=imginfo\Width
- Surf\Height=imginfo\Height
- If bmi\dsBm\bmBits = #Null Or bmi\dsBm\bmWidthBytes = 0
- DeleteObject_(hBmp)
- FreeLibrary_(D3DXInst)
- ProcedureReturn 0
- EndIf
- bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
- ; fill dibsection with the data
- Result=D3DX9LoadSurfaceFromFile(Surf,0,0,File,0,1,0,0)
- FreeLibrary_(D3DXInst)
- If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
- hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
- If hNewBmp=0
- DeleteObject_(hBmp)
- ProcedureReturn 0
- EndIf
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhNewBmp=SelectObject_(MemDC,hNewBmp)
- Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
- SelectObject_(MemDC,hNewBmp)
- DeleteDC_(MemDC)
- EndIf
- DeleteObject_(hBmp)
- If Result=0
- DeleteObject_(hNewBmp)
- ProcedureReturn 0
- EndIf
- ProcedureReturn hNewBmp
- EndProcedure
- Procedure _DX9_LoadFromMem(SrcData.l,LengthInBytes.l)
- Protected D3DXInst, D3DX9LoadSurfaceFromFileInMemory.D3DX9LoadSurfaceFromFileInMemory, D3DX9GetImageInfoFromFileInMemory.D3DX9GetImageInfoFromFileInMemory
- Protected Surf.MyD3DSURFACE, Result = #False, imginfo.D3DXIMAGE_INFO, BmInf.BitmapInfo, hBmp, bmi.DIBSECTION, hNewBmp, MemDC, OldhNewBmp
- If SrcData=#Null Or LengthInBytes<=0
- ProcedureReturn 0
- EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_43.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_42.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_41.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_40.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_39.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_38.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_37.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_36.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_35.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_34.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_33.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_32.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_31.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_30.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_29.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_28.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_27.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_26.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_25.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9_24.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_43.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_42.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_41.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_40.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_39.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_38.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_36.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_35.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_34.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_33.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_32.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_31.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_30.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_29.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_28.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_27.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_26.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_25.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d_24.dll"):EndIf
- If D3DXInst=0:D3DXInst=LoadLibrary_("d3dx9d.dll"):EndIf
- If D3DXInst=0:ProcedureReturn 0:EndIf
- D3DX9LoadSurfaceFromFileInMemory.D3DX9LoadSurfaceFromFileInMemory=GetProcAddress_(D3DXInst,"D3DXLoadSurfaceFromFileInMemory")
- D3DX9GetImageInfoFromFileInMemory.D3DX9GetImageInfoFromFileInMemory=GetProcAddress_(D3DXInst,"D3DXGetImageInfoFromFileInMemory")
- If D3DX9GetImageInfoFromFileInMemory=0 Or D3DX9LoadSurfaceFromFileInMemory=0
- FreeLibrary_(D3DXInst)
- ProcedureReturn 0
- EndIf
- Surf.MyD3DSURFACE
- Surf\VTable=?MyD3D9_SurfaceVTable
- ; First get the width and height of the image
- Result=D3DX9GetImageInfoFromFileInMemory(SrcData.l,LengthInBytes.l,imginfo.D3DXIMAGE_INFO)
- ; Result=D3DX9LoadSurfaceFromFile(Surf,0,re,@File,0,1,0,imginfo.D3DXIMAGE_INFO)
- If Result:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
- ; Then put it into a dibsection. we can't put it directly into the surface, because the pixelfomat isn't always 32 Bit!
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=imginfo\Width
- BmInf\BmiHeader\biHeight=imginfo\Height
- If imginfo\Width <= 0 Or imginfo\Height <= 0
- FreeLibrary_(D3DXInst):ProcedureReturn 0
- EndIf
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp=0:FreeLibrary_(D3DXInst):ProcedureReturn 0:EndIf
- GetObject_(hBmp,SizeOf(DIBSECTION),bmi.DIBSECTION)
- Surf\Pitch=bmi\dsBm\bmWidthBytes
- Surf\pBits=bmi\dsBm\bmBits
- Surf\Width=imginfo\Width
- Surf\Height=imginfo\Height
- If bmi\dsBm\bmBits = #Null Or bmi\dsBm\bmWidthBytes = 0
- DeleteObject_(hBmp)
- FreeLibrary_(D3DXInst)
- ProcedureReturn 0
- EndIf
- bmi\dsBmih\biHeight=-bmi\dsBmih\biHeight ; flip height Height, because the dibsection is top down
- ; fill dibsection with the data
- Result=D3DX9LoadSurfaceFromFileInMemory(Surf,0,0,SrcData.l,LengthInBytes.l,0,1,0,0)
- FreeLibrary_(D3DXInst)
- If Result:DeleteObject_(hBmp):ProcedureReturn 0:EndIf
- hNewBmp=CopyImage_(hBmp,#IMAGE_BITMAP,0,0,#LR_CREATEDIBSECTION)
- If hNewBmp=0
- DeleteObject_(hBmp)
- ProcedureReturn 0
- EndIf
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- OldhNewBmp=SelectObject_(MemDC,hNewBmp)
- Result=SetDIBitsToDevice_(MemDC,0,0,imginfo\Width,imginfo\Height,0,0,0,imginfo\Height,bmi\dsBm\bmBits,bmi\dsBmih,#DIB_RGB_COLORS)
- SelectObject_(MemDC,hNewBmp)
- DeleteDC_(MemDC)
- EndIf
- DeleteObject_(hBmp)
- If Result=0
- DeleteObject_(hNewBmp)
- ProcedureReturn 0
- EndIf
- ProcedureReturn hNewBmp
- EndProcedure
- Procedure _GDIP_LoadFromFile(sFile.s)
- Protected gdip, GdiplusStartup.GdiplusStartup, GdiplusShutdown.GdiplusShutdown, GdipAlloc.GdipAlloc, GdipFree.GdipFree
- Protected GdipCreateFromHDC.GdipCreateFromHDC, GdipDrawImageI.GdipDrawImageI, GdipDeleteGraphics.GdipDeleteGraphics
- Protected GdipGetImageWidth.GdipGetImageWidth, GdipGetImageHeight.GdipGetImageHeight, GdipDisposeImage.GdipDisposeImage
- Protected GdipCreateBitmapFromFile.GdipCreateBitmapFromFile, gdpsi.GdiplusStartupInput, gdiptoken, File, Image, lWidth, lHeight
- Protected BmInf.BitmapInfo, hBmp = #Null, MemDC = #Null, hOldBmp = #Null, GraphObj = #Null, lResult, GrapObj
- If FileSize(sFile) < 1
- ProcedureReturn 0
- EndIf
- gdip=LoadLibrary_("gdiplus.dll")
- If gdip=0:ProcedureReturn #False:EndIf
- GdiplusStartup.GdiplusStartup=GetProcAddress_(gdip,"GdiplusStartup")
- GdiplusShutdown.GdiplusShutdown=GetProcAddress_(gdip,"GdiplusShutdown")
- GdipAlloc.GdipAlloc=GetProcAddress_(gdip,"GdipAlloc")
- GdipFree.GdipFree=GetProcAddress_(gdip,"GdipFree")
- If GdiplusStartup=0 Or GdiplusShutdown=0 Or GdipAlloc=0 Or GdipFree=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- GdipCreateFromHDC.GdipCreateFromHDC=GetProcAddress_(gdip,"GdipCreateFromHDC")
- GdipDrawImageI.GdipDrawImageI=GetProcAddress_(gdip,"GdipDrawImageI")
- GdipDeleteGraphics.GdipDeleteGraphics=GetProcAddress_(gdip,"GdipDeleteGraphics")
- If GdipCreateFromHDC=0 Or GdipDrawImageI=0 Or GdipDeleteGraphics=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- GdipGetImageWidth.GdipGetImageWidth=GetProcAddress_(gdip,"GdipGetImageWidth")
- GdipGetImageHeight.GdipGetImageHeight=GetProcAddress_(gdip,"GdipGetImageHeight")
- GdipDisposeImage.GdipDisposeImage=GetProcAddress_(gdip,"GdipDisposeImage")
- GdipCreateBitmapFromFile.GdipCreateBitmapFromFile=GetProcAddress_(gdip,"GdipCreateBitmapFromFile")
- If GdipGetImageHeight=0 Or GdipGetImageWidth=0 Or GdipCreateBitmapFromFile=0 Or GdipDisposeImage=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- gdpsi.GdiplusStartupInput\GdiplusVersion=1
- GdiplusStartup(@gdiptoken,gdpsi,0)
- If gdiptoken
- File = GdipAlloc(2 * 2048 + 2);#MAX_PATH*2)
- If File
- MultiByteToWideChar_(0,0,sFile, -1,File, 2048)
- GdipCreateBitmapFromFile(File,@Image)
- If Image
- GdipGetImageWidth(Image,@lWidth)
- GdipGetImageHeight(Image,@lHeight)
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=lWidth
- BmInf\BmiHeader\biHeight=lHeight
- If lWidth > 0 And lHeight > 0
- hBmp = CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- EndIf
- If hBmp
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- hOldBmp=SelectObject_(MemDC, hBmp)
- GdipCreateFromHDC(MemDC,@GraphObj)
- If GraphObj
- lResult=GdipDrawImageI(GraphObj,Image,0,0)
- GdipDeleteGraphics(GrapObj)
- SelectObject_(MemDC,hOldBmp)
- Else
- lResult=#E_FAIL
- EndIf
- DeleteDC_(MemDC)
- Else
- lResult=#E_FAIL
- EndIf
- EndIf
- GdipDisposeImage(image)
- EndIf
- GdipFree(File)
- EndIf
- GdiplusShutdown(gdiptoken)
- EndIf
- FreeLibrary_(gdip)
- If lResult<>#S_OK:DeleteObject_(hBmp):hBmp=0:EndIf
- ProcedureReturn hBmp
- EndProcedure
- Procedure _GDIP_LoadFromMem(Addr.l,size.l)
- Protected gdip, GdiplusStartup.GdiplusStartup, GdiplusShutdown.GdiplusShutdown, GdipAlloc.GdipAlloc
- Protected GdipCreateFromHDC.GdipCreateFromHDC, GdipFree.GdipFree, GdipDrawImageI.GdipDrawImageI, GdipDeleteGraphics.GdipDeleteGraphics
- Protected GdipGetImageWidth.GdipGetImageWidth, GdipGetImageHeight.GdipGetImageHeight, GdipDisposeImage.GdipDisposeImage
- Protected GdipCreateBitmapFromStream.GdipCreateBitmapFromStream, Mem, *ptr, *Stream.IStream, gdpsi.GdiplusStartupInput, gdiptoken
- Protected Image, lWidth, lHeight, BmInf.BitmapInfo, hBmp, MemDC, hOldBmp, GraphObj, lResult
- If Addr=#Null Or Size<=0
- ProcedureReturn 0
- EndIf
- gdip=LoadLibrary_("gdiplus.dll")
- If gdip=0:ProcedureReturn #False:EndIf
- GdiplusStartup.GdiplusStartup=GetProcAddress_(gdip,"GdiplusStartup")
- GdiplusShutdown.GdiplusShutdown=GetProcAddress_(gdip,"GdiplusShutdown")
- GdipAlloc.GdipAlloc=GetProcAddress_(gdip,"GdipAlloc")
- GdipFree.GdipFree=GetProcAddress_(gdip,"GdipFree")
- If GdiplusStartup=0 Or GdiplusShutdown=0 Or GdipAlloc=0 Or GdipFree=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- GdipCreateFromHDC.GdipCreateFromHDC=GetProcAddress_(gdip,"GdipCreateFromHDC")
- GdipDrawImageI.GdipDrawImageI=GetProcAddress_(gdip,"GdipDrawImageI")
- GdipDeleteGraphics.GdipDeleteGraphics=GetProcAddress_(gdip,"GdipDeleteGraphics")
- If GdipCreateFromHDC=0 Or GdipDrawImageI=0 Or GdipDeleteGraphics=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- GdipGetImageWidth.GdipGetImageWidth=GetProcAddress_(gdip,"GdipGetImageWidth")
- GdipGetImageHeight.GdipGetImageHeight=GetProcAddress_(gdip,"GdipGetImageHeight")
- GdipDisposeImage.GdipDisposeImage=GetProcAddress_(gdip,"GdipDisposeImage")
- GdipCreateBitmapFromStream.GdipCreateBitmapFromStream=GetProcAddress_(gdip,"GdipCreateBitmapFromStream")
- If GdipGetImageHeight=0 Or GdipGetImageWidth=0 Or GdipCreateBitmapFromStream=0 Or GdipDisposeImage=0
- FreeLibrary_(gdip)
- ProcedureReturn 0
- EndIf
- Mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)
- *ptr=GlobalLock_(Mem)
- If *ptr=0 ; if GlobalAlloc or GlobalLock failed
- FreeLibrary_(gdip)
- GlobalFree_(Mem)
- ProcedureReturn 0
- EndIf
- RtlMoveMemory_(*ptr,Addr,Size)
- GlobalUnlock_(Mem)
- CreateStreamOnHGlobal_(Mem, 1, @*Stream.IStream)
- If *Stream=0
- FreeLibrary_(gdip)
- GlobalFree_(Mem)
- ProcedureReturn 0
- EndIf
- gdpsi.GdiplusStartupInput\GdiplusVersion=1
- GdiplusStartup(@gdiptoken,gdpsi,0)
- If gdiptoken
- GdipCreateBitmapFromStream(*Stream,@Image)
- If image
- GdipGetImageWidth(Image,@lWidth)
- GdipGetImageHeight(Image,@lHeight)
- BmInf.BitmapInfo\BmiHeader\biBitCount=32
- BmInf\BmiHeader\biCompression=#BI_RGB
- BmInf\BmiHeader\biPlanes=1
- BmInf\BmiHeader\biSize=SizeOf(BITMAPINFOHEADER)
- BmInf\BmiHeader\biWidth=lWidth
- BmInf\BmiHeader\biHeight=lHeight
- hBmp=CreateDIBSection_(0,BmInf,#DIB_RGB_COLORS,0,0,0)
- If hBmp
- MemDC=CreateCompatibleDC_(0)
- If MemDC
- hOldBmp=SelectObject_(MemDC,hBmp)
- GdipCreateFromHDC(MemDC,@GraphObj)
- If GraphObj
- lResult=GdipDrawImageI(GraphObj,Image,0,0)
- GdipDeleteGraphics(GraphObj)
- SelectObject_(MemDC,hOldBmp)
- Else
- lResult=#E_FAIL
- EndIf
- DeleteDC_(MemDC)
- Else
- lResult=#E_FAIL
- EndIf
- EndIf
- GdipDisposeImage(image)
- EndIf
- GdiplusShutdown(gdiptoken)
- EndIf
- FreeLibrary_(gdip)
- *Stream\Release()
- If lResult<>#S_OK:DeleteObject_(hBmp):hBmp=0:EndIf
- ProcedureReturn hBmp
- EndProcedure
- ;LoadImageEx() can load bmp,jpg,png and gif files, so you don't need huge imageplugins to load these formats
- ;LoadImageEx() works only if Internet Explorer 4.x or later is installed
- ;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
- ;CatchImageEx() works only if Internet Explorer 4.x or later is installed
- Procedure __CreateStreamFromMem(Addr.l,Size.l)
- Protected mem,*ptr,Stream.IStream
- mem=GlobalAlloc_(#GMEM_MOVEABLE,Size)
- If mem
- *ptr=GlobalLock_(mem)
- If *ptr
- CopyMemory(Addr,*ptr,Size)
- CreateStreamOnHGlobal_(mem,#True,@Stream.IStream)
- GlobalUnlock_(mem)
- EndIf
- If Stream=0:GlobalFree_(mem):EndIf
- EndIf
- ProcedureReturn Stream
- EndProcedure
- ;
- ;
- Procedure _DXTF_LoadFromMem(Image,Addr,Size,Flags=0)
- Protected dxtf.IDXTransformFactory, Stream.IStream, DC, lock.IDXDCLock, surf.IDXSurface
- Protected result, re.rect, DestDC,dxsf.nIDXSurfaceFactory,Success
- If Addr=#Null Or Size <=0
- ProcedureReturn #Null
- EndIf
- CoCreateInstance_(?CLSID_DXTransformFactory,0,#CLSCTX_INPROC_SERVER,?IID_IDXTransformFactory,@dxtf.IDXTransformFactory)
- If dxtf
- dxtf\QueryService(?IID_IDXSurfaceFactory,?IID_IDXSurfaceFactory,@dxsf.nIDXSurfaceFactory)
- If dxsf
- Stream.IStream=__CreateStreamFromMem(Addr,Size)
- If Stream
- dxsf\LoadImageFromStream(Stream,0,0,0,?IID_IDXSurface,@surf.IDXSurface)
- If surf
- surf\LockSurfaceDC(0,#INFINITE,#DXLOCKF_READ,@lock.IDXDCLock)
- If lock
- DC=lock\GetDC()
- If DC
- GetClipBox_(DC,re.rect)
- If Image=#PB_Any
- result=CreateImage(#PB_Any,re\right,re\bottom,Flags)
- Image=result
- Else
- result=CreateImage(Image,re\right,re\bottom,Flags)
- EndIf
- If result
- DestDC=StartDrawing(ImageOutput(Image))
- If DestDC
- Success=BitBlt_(DestDC,0,0,re\right,re\bottom,DC,0,0,#SRCCOPY)
- StopDrawing()
- EndIf
- If Success=#False:FreeImage(Image):EndIf
- EndIf
- EndIf
- Lock\Release()
- EndIf
- surf\Release()
- EndIf
- dxsf\Release()
- EndIf
- Stream\Release()
- EndIf
- dxtf\Release()
- EndIf
- If Success:ProcedureReturn result:EndIf
- ProcedureReturn #False
- EndProcedure
- Procedure _DXTF_LoadFromFile(Image,FileName.s,Flags=0)
- Protected dxtf.IDXTransformFactory, Stream.IStream, DC, lock.IDXDCLock, surf.IDXSurface
- Protected result, re.rect, DestDC,dxsf.nIDXSurfaceFactory,Success
- If FileSize(Filename) < 1 ; do not allow URL
- ProcedureReturn #Null
- EndIf
- CoCreateInstance_(?CLSID_DXTransformFactory,0,#CLSCTX_INPROC_SERVER,?IID_IDXTransformFactory,@dxtf.IDXTransformFactory)
- If dxtf
- dxtf\QueryService(?IID_IDXSurfaceFactory,?IID_IDXSurfaceFactory,@dxsf.nIDXSurfaceFactory)
- If dxsf
- dxsf\LoadImage(FileName,0,0,0,?IID_IDXSurface,@surf.IDXSurface)
- If surf
- surf\LockSurfaceDC(0,#INFINITE,#DXLOCKF_READ,@lock.IDXDCLock)
- If lock
- DC=lock\GetDC()
- If DC
- GetClipBox_(DC,re.rect)
- If Image=#PB_Any
- result=CreateImage(#PB_Any,re\right,re\bottom,Flags)
- Image=result
- Else
- result=CreateImage(Image,re\right,re\bottom,Flags)
- EndIf
- If result
- DestDC=StartDrawing(ImageOutput(Image))
- If DestDC
- Success=BitBlt_(DestDC,0,0,re\right,re\bottom,DC,0,0,#SRCCOPY)
- StopDrawing()
- EndIf
- If Success=#False:FreeImage(Image):EndIf
- EndIf
- EndIf
- Lock\Release()
- EndIf
- surf\Release()
- EndIf
- dxsf\Release()
- EndIf
- dxtf\Release()
- EndIf
- If Success:ProcedureReturn result:EndIf
- ProcedureReturn #False
- EndProcedure
- Procedure __WIC_ConvertStream(*in_stream.IStream, *out_stream.IStream, *src_CLSID, *dst_CLSID, *dst_Format)
- Protected *src.IWICBitmapFrameDecode = #Null
- Protected *dst.IWICBitmapFrameEncode = #Null
- Protected *pDec.IWICBitmapDecoder = #Null
- Protected *pEnc.IWICBitmapEncoder = #Null
- Protected width.i, height.i, bResult = #False
- If *in_stream <> #Null And *out_stream <> #Null
- CoCreateInstance_(*src_CLSID, #Null, #CLSCTX_INPROC_SERVER, @IID_IWICBitmapDecoder, @*pDec)
- CoCreateInstance_(*dst_CLSID, #Null, #CLSCTX_INPROC_SERVER, @IID_IWICBitmapEncoder, @*pEnc)
- If *pDec And *pEnc
- If *pDec\Initialize(*in_stream, #WICDecodeMetadataCacheOnDemand) = #S_OK
- If *pDec\GetFrame(0, @*src) = #S_OK
- If *src\GetSize(@width, @height) = #S_OK
- If *pEnc\Initialize(*out_stream, #WICBitmapEncoderNoCache) = #S_OK
- If *pEnc\CreateNewFrame(@*dst, #Null) = #S_OK
- If *dst\Initialize(#Null) = #S_OK
- If *dst\SetSize(width, height) = #S_OK
- If *dst\SetPixelFormat(*dst_Format) = #S_OK
- If *dst\WriteSource(*src, #Null) = #S_OK
- *dst\Commit()
- *pEnc\Commit()
- bResult = #True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- If *src
- *src\Release()
- EndIf
- If *dst
- *dst\Release()
- EndIf
- If *pDec
- *pDec\Release()
- EndIf
- If *pEnc
- *pEnc\Release()
- EndIf
- ProcedureReturn bResult
- EndProcedure
- Procedure _WIC_LoadFrom(sFile.s, *addr = #Null, size = 0)
- Protected *in_stream.IStream, *out_stream.IStream
- Protected hGlobal, *ptr, image = #Null, bResult.i
- If sFile <> ""
- SHCreateStreamOnFile_(sFile,#STGM_READ,@*in_stream.IStream)
- Else
- CreateStreamOnHGlobal_(#Null, #True, @*in_stream.IStream)
- If *in_stream <> #Null
- *in_stream\Write(*addr, size, #Null)
- EndIf
- EndIf
- CreateStreamOnHGlobal_(#Null, #True, @*out_stream.IStream)
- ;Note: PNG,BMP make no sense, because, we are expecting here a PNG and BMP decoder!!
- bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICWmpDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)
- If bResult = #False
- bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICGifDecoder, @CLSID_WICPngEncoder, @WICPixelFormat32bppBGRA)
- EndIf
- If bResult = #False
- bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICIcoDecoder, @CLSID_WICPngEncoder, @WICPixelFormat32bppBGRA)
- EndIf
- If bResult = #False
- bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICJpegDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)
- EndIf
- ;If bResult = #False
- ; bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICPngDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)
- ;EndIf
- If bResult = #False
- bResult = __WIC_ConvertStream(*in_stream, *out_stream, @CLSID_WICTiffDecoder, @CLSID_WICBmpEncoder, @WICPixelFormat24bppBGR)
- EndIf
- If bResult And *out_stream<> #Null
- GetHGlobalFromStream_(*out_stream, @hGlobal)
- If hGlobal
- *ptr = GlobalLock_(hGlobal)
- If *ptr
- image = CatchImage(#PB_Any, *ptr, GlobalSize_(hGlobal))
- GlobalUnlock_(hGlobal)
- EndIf
- EndIf
- EndIf
- If *in_stream
- *in_stream\Release()
- EndIf
- If *out_stream
- *out_stream\Release()
- EndIf
- ProcedureReturn image
- EndProcedure
- Procedure _WIC_SaveToFile(Image, sFile.s)
- EndProcedure
- Procedure _ImgLoader_Load(File.s) ; returns the ImageID
- Protected lResult, hBmp
- hBmp=_DIB_LoadFromFile(File)
- If hBmp=0
- hBmp=_DX9_LoadFromFile(File)
- EndIf
- If hBmp=0
- hBmp=_DX8_LoadFromFile(File) ;Only WIN XP/2003 and older
- EndIf
- If hBmp=0
- hBmp=_GDIP_LoadFromFile(File) ;GDIP has alpha channel for ico, gif
- EndIf
- If hBmp=0
- hBmp=_OLE_LoadFromFile(File)
- EndIf
- If hBmp=0
- hBmp=_IMGCTX_LoadFromFile(File)
- EndIf
- ProcedureReturn hBmp
- EndProcedure
- Procedure _ImgLoader_LoadMem(Addr.l,Size.l) ; returns the ImageID
- Protected lResult, hBmp
- hBmp=_DIB_LoadFromMem(Addr)
- If Size
- If hBmp=0
- hBmp=_DX9_LoadFromMem(Addr,Size)
- EndIf
- If hBmp=0
- hBmp=_DX8_LoadFromMem(Addr,Size) ;Only WIN XP/2003 and older
- EndIf
- If hBmp=0
- hBmp=_GDIP_LoadFromMem(Addr,Size) ;GDIP has alpha channel for ico, gif
- EndIf
- If hBmp=0
- hBmp=_OLE_LoadFromMem(Addr,Size)
- EndIf
- EndIf
- ProcedureReturn hBmp
- EndProcedure
- Procedure _GetPBImage(ImageID.i, width, height)
- Protected Bmp.BITMAP, PBImage, hDC
- If width <= 0 Or height <=0 ; tricky: so that it works also for icons, using pb api ImageWidth()...
- GetObject_(ImageID,SizeOf(BITMAP), Bmp.BITMAP)
- width = Bmp\bmWidth
- height = Bmp\bmHeight
- EndIf
- PBImage = CreateImage(#PB_Any,width,height, 32)
- If PBImage
- hDC = StartDrawing(ImageOutput(PBImage))
- DrawingMode(#PB_2DDrawing_AllChannels) ; Alpha channel for GDIP with ico, gif!
- DrawImage(ImageID,0,0)
- StopDrawing()
- EndIf
- ProcedureReturn PBImage
- EndProcedure
- Procedure ImagePlugin_Initailize()
- Protected lResult.i
- lResult = CoInitialize_(0)
- UsePNGImageDecoder()
- UsePNGImageEncoder()
- UseJPEG2000ImageDecoder()
- UseJPEG2000ImageEncoder()
- UseJPEGImageDecoder()
- UseJPEGImageEncoder()
- UseTGAImageDecoder()
- UseTIFFImageDecoder()
- ;If lResult=#S_OK Or lResult=#S_FALSE:CoUninitialize_():EndIf
- EndProcedure
- Procedure ImagePlugin_LoadFromFile(sFile.s)
- Protected Image.i, NewImage, hBitmap.i, hIcon.i, width.i, height.i
- ;First try to load icon, cursor in full size!
- hIcon = _ICOCUR_LoadFromFile(sFile, @width, @height)
- If hIcon
- Image = _GetPBImage(hIcon, width, height)
- DestroyIcon_(hIcon)
- EndIf
- If Not IsImage(Image)
- Image = LoadImage(#PB_Any, sFile)
- If IsImage(Image)
- If GetObjectType_(ImageID(Image)) <> #OBJ_BITMAP
- ;Probably an Icon, however icons should already loaded by _ICOCUR_LoadFromFile(), so just free
- ;this here, because we need a hBitmap no icon
- FreeImage(Image)
- Image = #Null
- EndIf
- EndIf
- EndIf
- If Not IsImage(Image)
- Image = _WIC_LoadFrom(sFile)
- EndIf
- If Not IsImage(Image)
- hBitmap = _ImgLoader_Load(sFile)
- If hBitmap
- Image = _GetPBImage(hBitmap, 0, 0)
- DeleteObject_(hBitmap)
- EndIf
- EndIf
- ProcedureReturn Image
- EndProcedure
- Procedure ImagePlugin_LoadFromMemory(*pointer, iSize.i)
- Protected Image.i, hBitmap.i
- Image = CatchImage(#PB_Any, *pointer, iSize)
- If IsImage(Image)
- If GetObjectType_(ImageID(Image)) <> #OBJ_BITMAP
- ;Probably an Icon...
- ;free this here, because we need a hBitmap no icon
- FreeImage(Image)
- Image = #Null
- EndIf
- EndIf
- If Not IsImage(Image)
- Image = _WIC_LoadFrom("", *pointer, iSize)
- EndIf
- If Not IsImage(Image)
- hBitmap = _ImgLoader_LoadMem(*pointer, iSize)
- If hBitmap
- Image = _GetPBImage(hBitmap, 0, 0)
- DeleteObject_(hBitmap)
- EndIf
- EndIf
- ProcedureReturn Image
- EndProcedure
- ;
- ;
- ; Procedure GetShellThumbnail(FileName$, Image, Width, Height, Depth = #PB_Image_DisplayFormat)
- ; Protected Result = 0, ImageResult
- ; Protected Desktop.IShellFolder, Folder.IShellFolder
- ; Protected Extract.IExtractImage
- ; Protected *pidlFolder.ITEMIDLIST, *pidlFile.ITEMIDLIST
- ; Protected Priority, Flags, Bitmap = 0, size.SIZE
- ; #IEIFLAG_QUALITY = $200
- ; Flags = #IEIFLAG_QUALITY
- ;
- ; If SHGetDesktopFolder_(@Desktop) >= 0
- ; If Desktop\ParseDisplayName(#Null, #Null, GetPathPart(FileName$), #Null, @*pidlFolder, #Null) = #S_OK
- ; If Desktop\BindToObject(*pidlFolder, #Null, ?IID_IShellFolder, @Folder) = #S_OK
- ; If Folder\ParseDisplayName(#Null, #Null, GetFilePart(FileName$) , #Null, @*pidlFile, #Null) = #S_OK
- ; If Folder\GetUIObjectOf(#Null, 1, @*pidlFile, ?IID_IExtractImage, 0, @Extract) = #S_OK
- ;
- ; ImageResult = CreateImage(Image, Width, Height, Depth)
- ; If ImageResult
- ; If Image = #PB_Any
- ; Image = ImageResult
- ; EndIf
- ; If Depth = #PB_Image_DisplayFormat
- ; Depth = ImageDepth(Image)
- ; EndIf
- ;
- ; size\cx = -1;Width
- ; size\cy = -1;Height
- ;
- ; If Extract\GetLocation(Space(#MAX_PATH), #MAX_PATH, @Priority, @size, Depth, @Flags) >= 0
- ; If Extract\Extract(@Bitmap) >= 0 And Bitmap
- ;
- ; If StartDrawing(ImageOutput(Image))
- ; DrawingMode(#PB_2DDrawing_AllChannels )
- ; DrawImage(Bitmap, 0, 0)
- ; StopDrawing()
- ; Result = ImageResult
- ; EndIf
- ;
- ; DeleteObject_(Bitmap)
- ; EndIf
- ; EndIf
- ; Extract\Release()
- ; EndIf
- ;
- ; If Result = 0
- ; FreeImage(Image)
- ; EndIf
- ; EndIf
- ;
- ; CoTaskMemFree_(*pidlFile)
- ; EndIf
- ; Folder\Release()
- ; EndIf
- ; CoTaskMemFree_(*pidlFolder)
- ; EndIf
- ; Desktop\Release()
- ; EndIf
- ;
- ; ProcedureReturn Result
- ;
- ; DataSection
- ; IID_IShellFolder: ; {000214E6-0000-0000-C000-000000000046}
- ; Data.l $000214E6
- ; Data.w $0000, $0000
- ; Data.b $C0, $00, $00, $00, $00, $00, $00, $46
- ;
- ; IID_IExtractImage: ; {BB2E617C-0920-11D1-9A0B-00C04FC2D6C1}
- ; Data.l $BB2E617C
- ; Data.w $0920, $11D1
- ; Data.b $9A, $0B, $00, $C0, $4F, $C2, $D6, $C1
- ; EndDataSection
- ; EndProcedure
- ;
- ;
- ;
- ; OpenWindow(1,0,0,640,480,"CatchImageEx test")
- ;
- ; CatchImageEx(1,?img_begin,?img_end-?img_begin,32)
- ;
- ; Repeat
- ;
- ; StartDrawing(WindowOutput(1))
- ; DrawImage(ImageID(1),0,0)
- ; StopDrawing()
- ;
- ;
- ;
- ; Until WindowEvent()=#PB_Event_CloseWindow
- ;
- ; DataSection
- ; img_begin:
- ; IncludeBinary "C:\mouse.gif"
- ; img_end:
- ; EndDataSection
- ;
- ;
- ;
- ;
- ; Procedure SaveImageToMemory(Image, *MemSize, Format = #PB_ImagePlugin_JPEG, Compression = 7)
- ; Protected *Mem, MemSize, ImageDataPipe
- ; MemSize = ImageDepth(Image)*ImageHeight(Image)*ImageWidth(Image)
- ; *Mem = AllocateMemory(MemSize)
- ; 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)
- ; SaveImage(Image, "\\.\pipe\ImageDataPipe", Format, Compression)
- ; ReadFile_(ImageDataPipe, *Mem, MemSize, *MemSize, #Null)
- ; CloseHandle_(ImageDataPipe)
- ; ProcedureReturn *Mem
- ; EndProcedure
- ;{ Sample
- DisableExplicit
- ImagePlugin_Initailize()
- If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Image Converter", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
- ImageGadget(0, 0, 28, WindowWidth(0), WindowHeight(0), 0, #PB_Image_Border)
- CreateToolBar(0, WindowID(0))
- ToolBarStandardButton(0, #PB_ToolBarIcon_Open)
- ToolBarStandardButton(1, #PB_ToolBarIcon_Save)
- DisableToolBarButton(0, 1, 1) ; disable the save button
- Repeat
- EventID = WaitWindowEvent()
- If EventID = #PB_Event_Menu ; ToolBar are acting as menu
- Select EventMenu()
- Case 0 ; Open
- 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)
- If Filename$
- image = ImagePlugin_LoadFromFile(Filename$)
- If image
- ResizeImage(image, ImageWidth(image) * 4,ImageHeight(image) * 4)
- StartDrawing(ImageOutput(image))
- DrawingMode(#PB_2DDrawing_AllChannels )
- Box(2,2,8,8,$FFFF0000)
- StopDrawing()
- SetGadgetState(0, ImageID(image)) ; change the picture in the gadget
- DisableToolBarButton(0, 1, 0) ; enable the save button
- ResizeWindow(0, #PB_Ignore, #PB_Ignore, ImageWidth(image)+4, ImageHeight(image)+34)
- EndIf
- EndIf
- Case 1 ; Save
- Filename$ = SaveFileRequester("Save a picture", Left(Filename$, Len(Filename$)-Len(GetExtensionPart(Filename$))-1), "BMP Format|*.bmp|JPEG Format|*.jpg|PNG Format|*.png", 0)
- If Filename$
- Select SelectedFilePattern()
- Case 0 ; BMP
- ImageFormat = #PB_ImagePlugin_BMP
- Extension$ = "bmp"
- Case 1 ; JPEG
- ImageFormat = #PB_ImagePlugin_JPEG
- Extension$ = "jpg"
- Case 2 ; PNG
- ImageFormat = #PB_ImagePlugin_PNG
- Extension$ = "png"
- EndSelect
- If LCase(GetExtensionPart(Filename$)) <> Extension$
- Filename$ + "." + Extension$
- EndIf
- If SaveImage(image, Filename$, ImageFormat)
- MessageRequester("Information", "Image saved successfully", 0)
- EndIf
- EndIf
- EndSelect
- EndIf
- Until EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
- EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement