для загрузки Jpega. Я предпочитаю работать непосредственно с RGB
данными, поэтому реализация такая для выходного потока.
Где:
lfile AS STRING строка буфера с загрженным Jpegoм (open for binary)
BYVAL VARPIX0 AS LONG, адрес буфера где будут находится распакованные RGB данные
BYREF XO_0 AS LONG, полученный размер по Х
BYREF YO_0 AS LONG, полученный размер по Y
BYVAL LFLAG AS LONG ' по желанию, для разных форматов на выходе
----------
- Код: Выделить всё
%HIMETRIC_INCH = 2540&
'____________________________________________________________
'
DECLARE FUNCTION OleInitialize LIB "ole32.dll" ALIAS "OleInitialize" _
(pvReserved AS DWORD) AS LONG
DECLARE FUNCTION CreateStreamOnHGlobal LIB "ole32.dll" _
ALIAS "CreateStreamOnHGlobal" (BYVAL hGlobal AS DWORD, BYVAL _
fDeleteOnRelease AS DWORD, JpgStream AS DWORD) AS LONG
DECLARE FUNCTION OleLoadPicture LIB "oleaut32.dll" _
ALIAS "OleLoadPicture" (BYVAL pStream AS DWORD, BYVAL lSize AS _
DWORD, BYVAL fRunmode AS DWORD, riid AS STRING * 16, pvObj AS _
DWORD) AS LONG
DECLARE SUB OleUninitialize LIB "ole32.dll" ALIAS "OleUninitialize"
DECLARE FUNCTION LoadJPEG (lfile AS STRING,BYVAL VARPIX0 AS _
LONG,BYREF XO_0 AS LONG,BYREF YO_0 AS LONG, BYVAL LOAD_FLAG _
AS LONG) AS LONG
'____________________________________________________________
'
$IID_IPicture = GUID$("{7BF80980-BF32-101A-8BBB-00AA00300CAB}")
%DDIQueryInterface = 0& ' QueryInterface method
%DDIAddRef = 4& 'AddRef method
%DDIRelease = 8& 'Release method
%DDIGetparamWidth = 24&
%DDIGetparamHeight = 28&
%DDIRender = 32&
'____________________________________________________________
'
FUNCTION M_CALL CDECL (BYVAL ObjectPtr AS DWORD, BYVAL MethodName AS DWORD,_
OPTIONAL BYVAL v1 AS DWORD, OPTIONAL BYVAL v2 AS DWORD, _
OPTIONAL BYVAL v3 AS DWORD, OPTIONAL BYVAL v4 AS DWORD, _
OPTIONAL BYVAL v5 AS DWORD, OPTIONAL BYVAL v6 AS DWORD, _
OPTIONAL BYVAL v7 AS DWORD, OPTIONAL BYVAL v8 AS DWORD, _
OPTIONAL BYVAL v9 AS DWORD, OPTIONAL BYVAL v10 AS DWORD, _
OPTIONAL BYVAL v11 AS DWORD, OPTIONAL BYVAL v12 AS DWORD, _
OPTIONAL BYVAL v13 AS DWORD, OPTIONAL BYVAL v14 AS DWORD, _
OPTIONAL BYVAL v15 AS DWORD, OPTIONAL BYVAL v16 AS DWORD, _
OPTIONAL BYVAL v17 AS DWORD, OPTIONAL BYVAL v18 AS DWORD) AS LONG
'function takes
' ObjectPtr - pointer to the direct draw object
' MethodName - the method to perform
' v1 - v18 - optional variables that may be used in the call
'
'function returns
' long - %DD_OK on success or error code on error
'
'notes: method calls to dx go through here
! push v18 ' push v1 - v18 onto stack
! push v17
! push v16
! push v15
! push v14
! push v13
! push v12
! push v11
! push v10
! push v9
! push v8
! push v7
! push v6
! push v5
! push v4
! push v3
! push v2
! push v1
! mov eax, ObjectPtr ' move pointer to dx object into eax
! mov ecx, MethodName ' move method to execute into ecx
! push eax
! mov eax, [eax]
! CALL DWORD PTR [eax+ecx]
! mov FUNCTION, eax
END FUNCTION
'____________________________________________________________________
'
FUNCTION LoadJPEG (lfile AS STRING,BYVAL VARPIX0 AS LONG,BYREF _
XO_0 AS LONG,BYREF YO_0 AS LONG,BYVAL LFLAG AS LONG) AS LONG
#REGISTER NONE
LOCAL lSize AS DWORD
LOCAL pvData AS DWORD
LOCAL hGlobal AS DWORD
LOCAL JpgStream AS DWORD PTR ' IStream_Interface Ptr
LOCAL Ipicture AS DWORD PTR
LOCAL IID_IPicture AS STRING * 16
LOCAL pPTR AS DWORD PTR
LOCAL mWidth AS DWORD
LOCAL mHeight AS DWORD
LOCAL hDC AS LONG
LOCAL newDC AS LONG
LOCAL hbmp AS LONG
LOCAL holdbmp AS LONG
LOCAL bmi AS BITMAPINFO
STATIC proc AS LONG
CALL OleInitialize (BYVAL %NULL)
lsize = LEN(lfile)
hGlobal = GlobalAlloc (%GMEM_MOVEABLE, lsize)
pvData = GlobalLock (hGlobal)
POKE$ pvData,lfile
CALL GlobalUnlock (hGlobal)
IF CreateStreamOnHGlobal (hGlobal,1&,JpgStream)<>%S_OK THEN
EXIT FUNCTION
END IF
IID_IPicture = $IID_IPicture
OleLoadPicture JpgStream, lsize, %FALSE, IID_IPicture, proc
IPicture = proc
IF IPicture = 0& THEN EXIT FUNCTION
CALL M_CALL (JpgStream, %DDIRELEASE)
! mov JpgStream,0&
CALL GlobalFree (hGlobal)
CALL M_CALL (Ipicture, %DDIGetparamWidth, VARPTR(mWidth))
CALL M_CALL (Ipicture, %DDIGetparamHeight, VARPTR(mHeight))
HDC = GetDC(%NULL)
XO_0 = MulDiv (mWidth, GetDeviceCaps (hdc, %LOGPIXELSX), %HIMETRIC_INCH)
YO_0 = MulDiv (mHeight, GetDeviceCaps (hdc, %LOGPIXELSY), %HIMETRIC_INCH)
newDC = CreateCompatibleDC(HDC)
'-------------------------------------------------------------
bmi.bmiHeader.biSize = SIZEOF(bmi.bmiHeader)
bmi.bmiHeader.biWidth = XO_0
IF LFLAG = 0& THEN
bmi.bmiHeader.biHeight = YO_0
bmi.bmiHeader.biBitCount = 32
ELSE
bmi.bmiHeader.biHeight =-YO_0
bmi.bmiHeader.biBitCount = 24
END IF
bmi.bmiHeader.biPlanes = 1
bmi.bmiHeader.biCompression = %BI_RGB
hBmp = CreateDIBSection( HDC, bmi, %DIB_RGB_COLORS, 0&, 0&, 0& )
'-------------------------------------------------------------
hOldBmp = SelectObject(newDC, hBmp)
CALL M_CALL (Ipicture, %DDIRender, newDC,0&,0&,XO_0,YO_0,_
0&, mHeight, mWidth,-mHeight, %NULL)
CALL SelectObject (newDC,hOldBmp)
CALL GetDIBits(newDC, hbmp, 0& , YO_0, BYVAL VARPIX0, bmi ,%DIB_RGB_COLORS)
DeleteDC newDC
DeleteObject hOldBmp
DeleteObject hBmp
CALL ReleaseDC (0&, HDC)
CALL M_CALL (Ipicture, %DDIRELEASE)
! mov Ipicture, 0&
CALL OleUnInitialize
END FUNCTION