Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




eeb709c72d33139af3088f6aeba769ef29cdb880
1 Attribute VB_Name = "GrpApi"
2 Option Explicit
4 '  ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2008
5 '  License information for this code is in license.txt
7 '  Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare)
9 Type GRPHEADER
10     nFrames As Integer
11     wMaxWidth As Integer
12     wMaxHeight As Integer
13 End Type
15 Public Const HORIZONTAL_FLIP As Long = &H1& ' Flips the graphic horizontally
16 Public Const VERTICAL_FLIP   As Long = &H2& ' Flips the graphic vertically
17 Public Const SHADOW_COLOR    As Long = &H4& ' Causes the graphic to be drawn in one color
18                                             ' Second byte of flags is the red component of
19                                             ' the shadow's color, third byte is green,
20                                             ' fourth byte is blue; like this:
21                                             ' 'SHADOW_COLOR Or &HBBGGRR00'
22 Public Const ALPHA_BLEND     As Long = &H8& ' Blends the graphic with what it is being drawn over.
23                                             ' The dwAlpha parameter will only be used when this
24                                             ' flag is specified.  dwAlpha is an RGB value
25                                             ' (&HBBGGRR).
26                                             ' Note: Because of the extra calculations required,
27                                             ' alpha blended graphics take longer to draw
28 Public Const USE_INDEX      As Long = &H10& ' Only valid when used with a custom SetPixel function.
29                                             ' This flag cannot be used in combination with
30                                             ' ALPHA_BLEND or SHADOW_COLOR
31                                             ' When this flag is used, the index to a color in the
32                                             ' palette will be passed to your custom SetPixel
33                                             ' function instead of the actual color.
35 ' Palette is an array of 256 Longs.  Pass the first element of the array to these functions,
36 ' rather than the actual array
37 ' For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive
38 ' or a file not in an archive
39 Declare Function LoadPalette Lib "Grpapi.dll" (ByVal lpFileName As String, dwPalette As Long) As Boolean
40 Declare Function LoadGrp Lib "Grpapi.dll" (ByVal lpFileName As String) As Long
41 Declare Function DestroyGrp Lib "Grpapi.dll" (ByVal hGrp As Long) As Boolean
42 Declare Function DrawGrp Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nFrame As Integer, dwPalette As Long, ByVal dwFlags As Long, ByVal dwAlpha As Long) As Boolean
43 Declare Function GetGrpInfo Lib "Grpapi.dll" (ByVal hGrp As Long, GrpInfo As GRPHEADER) As Boolean
44 Declare Function GetGrpFrameInfo Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal nFrame As Integer, ByRef nLeft As Long, ByRef nTop As Long, ByRef nWidth As Long, ByRef nHeight As Long) As Boolean
46 Declare Function GetDC Lib "User32.dll" (ByVal hWnd As Long) As Long
47 Declare Function ReleaseDC Lib "User32.dll" (ByVal hWnd As Long, ByVal hDC As Long) As Long
49 ' An array of the raw image data to encode should be passed to lpImageData.  To do this,
50 ' pass the first byte of the array to the function.  The size of the buffer containing
51 ' the data should be nFrames * wMaxWidth * wMaxHeight * 2
52 ' and the values should be arranged row by row of the frame, with the top row first.
53 ' After all the rows of a frame have been put into the buffer, the rows of the next frame
54 ' go after it.  For transparent pixels, they should be set to -1.  All other pixels should
55 ' have the high order byte set to zero, meaning that they should not be negative and the
56 ' values should not exceed 255 (&HFF).  The values used for the colors are indexes into the
57 ' color palette.
58 ' Pass True to bNoCompress if you need an uncompressed GRP.
59 ' Pass a variable to nGrpSize to receive the size in bytes of the resulting encoded GRP.
60 ' The return value of this function is actually a pointer to the GRP data.  This is what your
61 ' program should save to a file.  The size of this buffer is the value received by nGrpSize.
62 ' When your program is done with the returned buffer, it should call DestroyGrp on the
63 ' buffer that was returned by this function to free up the memory from it.
64 ' The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo.
65 Declare Function CreateGrp Lib "Grpapi.dll" (ByRef lpImageData As Integer, ByVal nFrames As Integer, ByVal wMaxWidth As Integer, ByVal wMaxHeight As Integer, ByVal bNoCompress As Boolean, ByRef nGrpSize As Long) As Long
67 ' Use this function to make a copy the memory at the location returned by CreateGrp.
68 ' Pass the address ByVal to Source.  Pass either a byte array or a string to Destination.
69 ' The size of the array or string must be at least the size of the GRP data before
70 ' attempting to copy it to the array or string.
71 ' To pass a byte array, pass the first byte of the array ByRef.  To pass a string,
72 ' pass the string ByVal.
73 Declare Sub CopyMemory Lib "Kernel32.dll" _
74     Alias "RtlMoveMemory" ( _
75     ByRef Destination As Any, _
76     ByRef Source As Any, _
77     ByVal Length As Long)
79 ' Call these to have DrawGrp use custom functions for reading and drawing pixels
80 ' so that you can have it read from and write to a buffer, for example.
81 ' Requires Visual Basic 5 or higher
82 '
83 ' The functions must be in this form:
84 '
85 ' Function GetPixelProc (ByRef value As any_type, ByVal X As Long, ByVal Y As Long) As Long
86 ' Sub SetPixelProc (ByRef value As any_type, ByVal X As Long, ByVal Y As Long, ByVal clrColor As Long)
87 '
88 ' or
89 '
90 ' Function GetPixelProc (ByVal value As any_type, ByVal X As Long, ByVal Y As Long) As Long
91 ' Sub SetPixelProc (ByVal value As any_type, ByVal X As Long, ByVal Y As Long, ByVal clrColor As Long)
92 '
93 ' Replace "any_type" with whatever type you want (but must be 4 bytes long if ByVal).
94 ' This parameter gets the data from DrawGrp's hdcDest parameter.  You can either pass
95 ' a number to DrawGrp and use the "ByVal" versions of the above functions, or you can
96 ' use AddressOf to get a reference to a variable and use it for the "ByRef" versions.
97 ' GetPixelProc should return an RGB color value.
98 Declare Sub SetFunctionGetPixel Lib "Grpapi.dll" (lpGetPixelProc As Long)
99 Declare Sub SetFunctionSetPixel Lib "Grpapi.dll" (lpSetPixelProc As Long)
101 ' Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ).
102 Declare Function SetMpqDll Lib "Grpapi.dll" (ByVal lpDllFileName As String) As Boolean
104 ' These no longer need to be called
105 Declare Function LoadGrpApi Lib "Grpapi.dll" () As Boolean
106 Declare Sub FreeGrpApi Lib "Grpapi.dll" ()