【HSP3】Mem_Picload Ver 1.01

GDI+ を使用してメモリから画像を表示する Mem_Picload の Ver 1.01 です。解放されないバグを修正しました。

GDI+ を使用してメモリから画像を表示する Mem_Picload の Ver 1.01 です。解放されないバグを修正しました。

/***************************************************************
[ Mem_Picload ] Version 1.01
- BMP, GIF, JPEG, PNG, TIFF GDI+
※ Windows XP GDI+gdiplus.dll
HSP3
: ( http://homepage2.nifty.com/MJHS/ )
OK
***************************************************************/
#module _mem_pic_
#define IID_IStream "{0000000C-0000-0000-C000-000000000046}"
#define CLSID_Stream "{00000320-0000-0000-C000-000000000046}"
#usecom IStream IID_IStream CLSID_Stream
#uselib "kernel32"
#cfunc GlobalAlloc "GlobalAlloc" int,int
#cfunc GlobalLock "GlobalLock" int
#func GlobalUnlock "GlobalUnlock"int
#func GlobalFree "GlobalFree"int
#uselib "ole32"
#cfunc CreateStreamOnHGlobal "CreateStreamOnHGlobal" int,int,var
#uselib "gdiplus"
#func GdiplusStartup "GdiplusStartup" var,var,int
#func GdipCreateFromHDC "GdipCreateFromHDC" int,var
#func GdipDeleteGraphics "GdipDeleteGraphics" var
#func GdipGetImageWidth "GdipGetImageWidth" int,int
#func GdipGetImageHeight "GdipGetImageHeight" int,int
#func GdipDrawImage "GdipDrawImageI" var,var,int,int
#func GdipDrawImage2 "GdipDrawImage" var,var,int,int
#func GdipDrawImageR "GdipDrawImageRectI" var,var,int,int,int,int
#func GdipDisposeImage "GdipDisposeImage" var
#func GdiplusShutdown "GdiplusShutdown" var
#func GdipLoadImageFromStream "GdipLoadImageFromStream" comobj,var
#deffunc mem_picinit int _cbuf
cbuf = _cbuf
if cbuf = 0 : cbuf = 32
dimtype pstm, vartype("comobj"), cbuf
dim _id, cbuf
dim token, cbuf
dim hGlobal, cbuf
dim ppstm, cbuf
dim ppImg, cbuf
pGraphics = 0
return
#deffunc mem_picload int id, var data, int size
if _id(id) != 0 : return -2 // ID使
if size <= 0 : return -3 //
if id >= cbuf : return -4 // 0 cbuf
//
dim GdiplusStartupInput, 4
GdiplusStartupInput = 1, 0, 0, 0
GdiplusStartup token(id), GdiplusStartupInput, 0
hGlobal(id) = GlobalAlloc(2, size+1)
dupptr tmp, GlobalLock(hGlobal.id), size, 2
memcpy tmp, data, size
GlobalUnLock hGlobal(id)
if CreateStreamOnHGlobal(hGlobal(id), 1, ppstm(id)) = 0{
newcom pstm(id), IStream, -1, ppstm(id)
GdipLoadImageFromStream pstm(id), ppImg(id)
}
_id(id) = 1
return
#deffunc mem_picgetsize int id, var x, var y
if _id(id) = 0 : return -1 // ID
dupptr pImg, ppImg(id), 4
GdipGetImageWidth ppImg(id), varptr(x)
GdipGetImageHeight ppImg(id), varptr(y)
return
#deffunc mem_picrectscreen int id, int x1, int y1, int x2, int y2
if _id(id) = 0 : return -1 //ID
dupptr pImg, ppImg(id), 4
GdipCreateFromHDC hdc, pGraphics
dupptr Graphics, pGraphics, 4
GdipDrawImageR Graphics, pImg, x1, y1, x2, y2
GdipDeleteGraphics Graphics
redraw 1
return
#deffunc mem_pictoscreen int id, int x1, int y1
if _id(id) = 0 : return -1 //ID
dupptr pImg, ppImg(id), 4
GdipCreateFromHDC hdc, pGraphics
dupptr Graphics, pGraphics, 4
GdipDrawImage Graphics, pImg, x1, y1
GdipDeleteGraphics Graphics
redraw 1
return
#deffunc mem_picfree int id
if _id(id) = 0 : return -1 //ID
dupptr pImg,ppImg(id), 4
GdipDisposeImage pImg
GlobalFree hGlobal(id)
GdiplusShutdown token(id)
delcom pstm(id)
_id(id) = 0
return
#deffunc picload_ex str fname, var x, var y
exist fname
if strsize = -1 : return -1
if varptr(GdiplusStartup) = 0 : return -2 // GDI+使
size = strsize
mem_picinit 1
notesel buf
noteload fname
mem_picload 0, buf, size
mem_picgetsize 0, x, y
mem_picrectscreen 0, 0, 0, x, y
mem_picfree 0
sdim buf, 64
return
#deffunc picload_ex2 str fname,int _x1, int _y1,int _x2, int _y2, var x, var y
exist fname
if strsize = -1 : return -1
if varptr(GdiplusStartup) = 0 : return -2 // GDI+使
size = strsize
mem_picinit 1
notesel buf
noteload fname
mem_picload 0, buf, size
mem_picgetsize 0, x, y
mem_picrectscreen 0, _x1, _y1, _x2, _y2
mem_picfree 0
sdim buf, 64
return
#global
/*
------------------------------------------------------------------------
mem_picinit p1(32)
mem_
p1 ID
32
------------------------------------------------------------------------
mem_picload p1,p2,p3
BMP, GIF, JPEG, PNG, TIFF
p1 ID
p2
p3 ()
------------------------------------------------------------------------
mem_picgetsize p1,p2,p3
()
p1 mem_picloadID
p2 X
p3 Y
------------------------------------------------------------------------
mem_pictoscreen p1,p2,p3
HSP
p1 mem_picloadID
p2 ( X )
p3 ( Y )
------------------------------------------------------------------------
mem_picrectscreen p1,p2,p3,p4,p5
HSP
p1 mem_picloadID
p2 ( X )
p3 ( Y )
p4 X
p5 Y
------------------------------------------------------------------------
mem_picfree p1
使
p1 mem_picloadID
------------------------------------------------------------------------
stat = 2 : ? ( GDI+ API )
stat = -1 : ID
stat = -2 : ID使
stat = -3 :
stat = -4 : ID
------------------------------------------------------------------------
*/
//
#if 0 //1
//
fname = "testpic.png" //
exist fname : ret = strsize //(使)
sdim data, ret //
bload fname, data //(使)
mem_picinit //
mem_picload 0, data, ret // (ID = 0)
mem_picgetsize 0, x, y //
mem_picrectscreen 0, 0, 0, x, y // HSP 0,0 x,y
width x, y // picload ,0
mem_picfree 0 // 使
#endif
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX